32 #include "ns3/simulator.h"
49 m_ackTimer (
Timer::CANCEL_ON_DESTROY),
50 m_validSeqNo (vSeqNo), m_seqNo (seqNo), m_hops (hops),
52 m_reqCount (0), m_blackListState (false), m_blackListTimeout (
Simulator::
Now ())
82 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
99 std::vector<Ipv4Address>::iterator i = std::remove (
m_precursorList.begin (),
133 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
137 for (std::vector<Ipv4Address>::const_iterator j = prec.begin (); j
184 *os << std::setiosflags (std::ios::fixed) <<
185 std::setiosflags (std::ios::left) << std::setprecision (2) <<
187 *os <<
"\t" <<
m_hops <<
"\n";
195 m_badLinkLifetime (t)
206 NS_LOG_LOGIC (
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
209 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
241 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" successful");
244 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" not successful");
255 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
257 return result.second;
264 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
275 i->second.SetRreqCnt (0);
284 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
288 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
" fails; not found");
291 i->second.SetFlag (state);
292 i->second.SetRreqCnt (0);
293 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
": new state is " << state);
302 unreachable.clear ();
303 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
306 if (i->second.GetNextHop () == nextHop)
308 NS_LOG_LOGIC (
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo ());
309 unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ()));
319 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
322 for (std::map<Ipv4Address, uint32_t>::const_iterator j =
323 unreachable.begin (); j != unreachable.end (); ++j)
325 if ((i->first == j->first) && (i->second.GetFlag () ==
VALID))
327 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
340 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
343 if (i->second.GetInterface () == iface)
345 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
360 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
363 if (i->second.GetLifeTime () <
Seconds (0))
365 if (i->second.GetFlag () ==
INVALID)
367 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
371 else if (i->second.GetFlag () ==
VALID)
373 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
393 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
394 table.begin (); i != table.end ();)
396 if (i->second.GetLifeTime () <
Seconds (0))
398 if (i->second.GetFlag () ==
INVALID)
400 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
404 else if (i->second.GetFlag () ==
VALID)
406 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
424 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
428 NS_LOG_LOGIC (
"Mark link unidirectional to " << neighbor <<
" fails; not found");
431 i->second.SetUnidirectional (
true);
432 i->second.SetBalcklistTimeout (blacklistTimeout);
433 i->second.SetRreqCnt (0);
434 NS_LOG_LOGIC (
"Set link to " << neighbor <<
" to unidirectional");
443 *stream->
GetStream () <<
"\nAODV Routing table\n"
444 <<
"Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n";
445 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
446 table.begin (); i != table.end (); ++i)
448 i->second.Print (stream);
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destinations as follows:
Simulation virtual time values and global simulation resolution.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Control the scheduling of simulation events.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Ipv4Address GetLocal(void) const
Get the local address.
bool Update(RoutingTableEntry &rt)
Update routing table.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in vector prec if they does not yet exist in vector.
void SetSource(Ipv4Address src)
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
void SetRreqCnt(uint8_t n)
bool IsPrecursorListEmpty() const
Check that precursor list empty.
RouteFlags m_flag
Routing flags: valid, invalid or in search.
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
void SetGateway(Ipv4Address gw)
uint8_t m_reqCount
Number of route requests.
Time m_badLinkLifetime
Deletion time for invalid routes.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
std::vector< Ipv4Address > m_precursorList
List of precursors.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void DeleteAllPrecursors()
Delete all precursors.
Ipv4Address GetGateway(void) const
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
static Time Now(void)
Return the current simulation virtual time.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Ipv4InterfaceAddress m_iface
Output interface address.
RoutingTable(Time t)
c-tor
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for an...
Ipv4Address GetDestination(void) const
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Time Seconds(double value)
Construct a Time in the indicated unit.
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
RouteFlags GetFlag() const
Ipv4Address GetDestination() const
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void SetDestination(Ipv4Address dest)
void Print(Ptr< OutputStreamWrapper > stream) const
RouteFlags
Route record states.
RoutingTableEntry(Ptr< NetDevice > dev=0, Ipv4Address dst=Ipv4Address(), bool vSeqNo=false, uint32_t m_seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint16_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now())
c-to