32 #include "ns3/simulator.h"
48 m_ackTimer (
Timer::CANCEL_ON_DESTROY),
49 m_validSeqNo (vSeqNo), m_seqNo (seqNo), m_hops (hops),
51 m_reqCount (0), m_blackListState (false), m_blackListTimeout (
Simulator::
Now ())
81 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
98 std::vector<Ipv4Address>::iterator i = std::remove (
m_precursorList.begin (),
132 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
136 for (std::vector<Ipv4Address>::const_iterator j = prec.begin (); j
183 *os << std::setiosflags (std::ios::fixed) <<
184 std::setiosflags (std::ios::left) << std::setprecision (2) <<
186 *os <<
"\t" <<
m_hops <<
"\n";
194 m_badLinkLifetime (t)
205 NS_LOG_LOGIC (
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
208 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
240 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" successful");
243 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" not successful");
254 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
256 return result.second;
263 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
274 i->second.SetRreqCnt (0);
283 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
287 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
" fails; not found");
290 i->second.SetFlag (state);
291 i->second.SetRreqCnt (0);
292 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
": new state is " << state);
301 unreachable.clear ();
302 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
305 if (i->second.GetNextHop () == nextHop)
307 NS_LOG_LOGIC (
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo ());
308 unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ()));
318 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
321 for (std::map<Ipv4Address, uint32_t>::const_iterator j =
322 unreachable.begin (); j != unreachable.end (); ++j)
324 if ((i->first == j->first) && (i->second.GetFlag () ==
VALID))
326 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
339 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
342 if (i->second.GetInterface () == iface)
344 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
359 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
362 if (i->second.GetLifeTime () < Seconds (0))
364 if (i->second.GetFlag () ==
INVALID)
366 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
370 else if (i->second.GetFlag () ==
VALID)
372 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
392 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
393 table.begin (); i != table.end ();)
395 if (i->second.GetLifeTime () < Seconds (0))
397 if (i->second.GetFlag () ==
INVALID)
399 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
403 else if (i->second.GetFlag () ==
VALID)
405 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
423 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
427 NS_LOG_LOGIC (
"Mark link unidirectional to " << neighbor <<
" fails; not found");
430 i->second.SetUnidirectional (
true);
431 i->second.SetBalcklistTimeout (blacklistTimeout);
432 i->second.SetRreqCnt (0);
433 NS_LOG_LOGIC (
"Set link to " << neighbor <<
" to unidirectional");
442 *stream->
GetStream () <<
"\nAODV Routing table\n"
443 <<
"Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n";
444 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
445 table.begin (); i != table.end (); ++i)
447 i->second.Print (stream);
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destinations as follows:
keep track of time values and allow control of 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)
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.
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
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
void SetRreqCnt(uint8_t n)
RREP_ACK timer.
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)
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 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 a...
Ipv4Address GetDestination(void) const
Ipv4 addresses are stored in host order in this class.
NS_LOG_COMPONENT_DEFINE("AodvRoutingTable")
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)
Add routing table entry if it doesn't yet exist in routing table.
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)
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
RREP_ACK timer.
Ipv4Address GetDestination() const
RREP_ACK timer.
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