31#include "ns3/simulator.h"
56 : m_ackTimer(
Timer::CANCEL_ON_DESTROY),
64 m_blackListState(false),
97 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin();
115 std::vector<Ipv4Address>::iterator i =
151 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin();
156 for (std::vector<Ipv4Address>::const_iterator j = prec.begin(); j != prec.end(); ++j)
186 std::ostream* os = stream->GetStream();
188 std::ios oldState(
nullptr);
189 oldState.copyfmt(*os);
191 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
193 std::ostringstream dest;
194 std::ostringstream gw;
195 std::ostringstream iface;
196 std::ostringstream expire;
201 *os << std::setw(16) << dest.str();
202 *os << std::setw(16) << gw.str();
203 *os << std::setw(16) << iface.str();
204 *os << std::setw(16);
221 *os << std::setw(16) << expire.str();
222 *os <<
m_hops << std::endl;
224 (*os).copyfmt(oldState);
232 : m_badLinkLifetime(t)
243 NS_LOG_LOGIC(
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
246 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.find(
id);
278 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" successful");
281 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" not successful");
294 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
296 return result.second;
303 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
314 i->second.SetRreqCnt(0);
326 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
" fails; not found");
329 i->second.SetFlag(state);
330 i->second.SetRreqCnt(0);
331 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
": new state is " << state);
337 std::map<Ipv4Address, uint32_t>& unreachable)
342 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.begin();
346 if (i->second.GetNextHop() == nextHop)
348 NS_LOG_LOGIC(
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo());
349 unreachable.insert(std::make_pair(i->first, i->second.GetSeqNo()));
359 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
363 for (std::map<Ipv4Address, uint32_t>::const_iterator j = unreachable.begin();
364 j != unreachable.end();
367 if ((i->first == j->first) && (i->second.GetFlag() ==
VALID))
369 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
384 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
387 if (i->second.GetInterface() == iface)
389 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
408 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
411 if (i->second.GetLifeTime() <
Seconds(0))
413 if (i->second.GetFlag() ==
INVALID)
415 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
419 else if (i->second.GetFlag() ==
VALID)
421 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
445 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i = table.begin(); i != table.end();)
447 if (i->second.GetLifeTime() <
Seconds(0))
449 if (i->second.GetFlag() ==
INVALID)
451 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
455 else if (i->second.GetFlag() ==
VALID)
457 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
477 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.find(neighbor);
480 NS_LOG_LOGIC(
"Mark link unidirectional to " << neighbor <<
" fails; not found");
483 i->second.SetUnidirectional(
true);
484 i->second.SetBlacklistTimeout(blacklistTimeout);
485 i->second.SetRreqCnt(0);
486 NS_LOG_LOGIC(
"Set link to " << neighbor <<
" to unidirectional");
495 std::ostream* os = stream->GetStream();
497 std::ios oldState(
nullptr);
498 oldState.copyfmt(*os);
500 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
501 *os <<
"\nAODV Routing table\n";
502 *os << std::setw(16) <<
"Destination";
503 *os << std::setw(16) <<
"Gateway";
504 *os << std::setw(16) <<
"Interface";
505 *os << std::setw(16) <<
"Flag";
506 *os << std::setw(16) <<
"Expire";
507 *os <<
"Hops" << std::endl;
508 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = table.begin();
512 i->second.Print(stream, unit);
514 *stream->GetStream() <<
"\n";
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
Ipv4Address GetLocal() const
Get the local address.
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Unit
The unit to use to interpret a number representing time.
A simple virtual Timer class.
void DeleteAllPrecursors()
Delete all precursors.
Ipv4InterfaceAddress m_iface
Output interface address.
std::vector< Ipv4Address > m_precursorList
List of precursors.
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print packet to trace file.
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
RouteFlags GetFlag() const
Get the route flags.
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
void SetRreqCnt(uint8_t n)
Set the RREQ count.
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Ipv4Address GetDestination() const
Get destination address function.
RoutingTableEntry(Ptr< NetDevice > dev=nullptr, Ipv4Address dst=Ipv4Address(), bool vSeqNo=false, uint32_t seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint16_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now())
constructor
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role: for an ...
RouteFlags m_flag
Routing flags: valid, invalid or in search.
uint8_t m_reqCount
Number of route requests.
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
bool Update(RoutingTableEntry &rt)
Update routing table.
Time m_badLinkLifetime
Deletion time for invalid routes.
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
RoutingTable(Time t)
constructor
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
void InvalidateRoutesWithDst(const std::map< Ipv4Address, uint32_t > &unreachable)
Update routing entries with this destination as follows:
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
The routing table.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
RouteFlags
Route record states.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.