29 #include "aodv-rtable.h"
32 #include "ns3/simulator.h"
48 Time lifetime, uint16_t channelNo) :
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 ()),
62 RoutingTableEntry::~RoutingTableEntry ()
83 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
100 std::vector<Ipv4Address>::iterator i = std::remove (
m_precursorList.begin (),
134 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
138 for (std::vector<Ipv4Address>::const_iterator j = prec.begin (); j
165 <<
"\t" <<
m_iface.GetLocal () <<
"\t";
185 *os << std::setiosflags (std::ios::fixed) <<
186 std::setiosflags (std::ios::left) << std::setprecision (2) <<
188 *os <<
"\t" <<
m_hops <<
"\n";
196 m_badLinkLifetime (t)
205 if (m_ipv4AddressEntry.empty ())
207 NS_LOG_LOGIC (
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
210 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
211 m_ipv4AddressEntry.find (
id);
212 if (i == m_ipv4AddressEntry.end ())
231 NS_LOG_LOGIC (
"Route to " <<
id <<
" flag is " << ((rt.GetFlag () ==
VALID) ?
"valid" :
"not valid"));
232 return (rt.GetFlag () ==
VALID);
240 if (m_ipv4AddressEntry.erase (dst) != 0)
242 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" successful");
245 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" not successful");
256 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
257 m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt));
258 return result.second;
265 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
266 m_ipv4AddressEntry.find (rt.GetDestination ());
267 if (i == m_ipv4AddressEntry.end ())
269 NS_LOG_LOGIC (
"Route update to " << rt.GetDestination () <<
" fails; not found");
275 NS_LOG_LOGIC (
"Route update to " << rt.GetDestination () <<
" set RreqCnt to 0");
276 i->second.SetRreqCnt (0);
285 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
286 m_ipv4AddressEntry.find (
id);
287 if (i == m_ipv4AddressEntry.end ())
289 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
" fails; not found");
292 i->second.SetFlag (state);
293 i->second.SetRreqCnt (0);
294 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
": new state is " << state);
303 unreachable.clear ();
304 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
305 m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i)
307 if (i->second.GetNextHop () == nextHop)
309 NS_LOG_LOGIC (
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo ());
310 unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ()));
320 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
321 m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i)
323 for (std::map<Ipv4Address, uint32_t>::const_iterator j =
324 unreachable.begin (); j != unreachable.end (); ++j)
326 if ((i->first == j->first) && (i->second.GetFlag () ==
VALID))
328 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
339 if (m_ipv4AddressEntry.empty ())
341 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
342 m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();)
344 if (i->second.GetInterface () == iface)
346 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
348 m_ipv4AddressEntry.erase (tmp);
359 if (m_ipv4AddressEntry.empty ())
361 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
362 m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end ();)
364 if (i->second.GetLifeTime () <
Seconds (0))
366 if (i->second.GetFlag () ==
INVALID)
368 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
370 m_ipv4AddressEntry.erase (tmp);
372 else if (i->second.GetFlag () ==
VALID)
374 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
394 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
395 table.begin (); i != table.end ();)
397 if (i->second.GetLifeTime () <
Seconds (0))
399 if (i->second.GetFlag () ==
INVALID)
401 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
405 else if (i->second.GetFlag () ==
VALID)
407 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
425 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
426 m_ipv4AddressEntry.find (neighbor);
427 if (i == m_ipv4AddressEntry.end ())
429 NS_LOG_LOGIC (
"Mark link unidirectional to " << neighbor <<
" fails; not found");
432 i->second.SetUnidirectional (
true);
433 i->second.SetBalcklistTimeout (blacklistTimeout);
434 i->second.SetRreqCnt (0);
435 NS_LOG_LOGIC (
"Set link to " << neighbor <<
" to unidirectional");
442 std::map<Ipv4Address, RoutingTableEntry> table = m_ipv4AddressEntry;
444 *stream->
GetStream () <<
"\nAODV Routing table\n"
445 <<
"Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n";
446 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
447 table.begin (); i != table.end (); ++i)
449 i->second.Print (stream);
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Control the scheduling of simulation events.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
bool Update(RoutingTableEntry &rt)
Update routing table.
#define NS_LOG_COMPONENT_DEFINE(name)
void GetPrecursors(std::vector< Ipv4Address > &prec) const
void SetSource(Ipv4Address src)
bool InsertPrecursor(Ipv4Address id)
double GetSeconds(void) const
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
bool IsPrecursorListEmpty() const
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)
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
std::vector< Ipv4Address > m_precursorList
List of precursors.
#define NS_LOG_LOGIC(msg)
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.
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(), uint16_t channelNo=1)
c-to
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
void SetOutputDevice(Ptr< NetDevice > outputDevice)
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.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
a class to store IPv4 address information on an interface
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
bool AddRoute(RoutingTableEntry &r)
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
bool DeleteRoute(Ipv4Address dst)
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
std::ostream * GetStream(void)
void SetDestination(Ipv4Address dest)
RouteFlags
Route record states.