|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
32 #include "ns3/simulator.h"
47 : m_ackTimer (
Timer::CANCEL_ON_DESTROY),
48 m_validSeqNo (vSeqNo),
55 m_blackListState (false),
88 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
105 std::vector<Ipv4Address>::iterator i = std::remove (
m_precursorList.begin (),
141 for (std::vector<Ipv4Address>::const_iterator i =
m_precursorList.begin (); i
145 for (std::vector<Ipv4Address>::const_iterator j = prec.begin (); j
178 std::ios oldState (
nullptr);
179 oldState.copyfmt (*os);
181 *os << std::resetiosflags (std::ios::adjustfield) << std::setiosflags (std::ios::left);
183 std::ostringstream dest, gw, iface, expire;
188 *os << std::setw (16) << dest.str();
189 *os << std::setw (16) << gw.str();
190 *os << std::setw (16) << iface.str();
191 *os << std::setw (16);
211 *os << std::setw (16) << expire.str();
212 *os <<
m_hops << std::endl;
214 (*os).copyfmt (oldState);
222 : m_badLinkLifetime (t)
233 NS_LOG_LOGIC (
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
236 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
268 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" successful");
271 NS_LOG_LOGIC (
"Route deletion to " << dst <<
" not successful");
284 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
286 return result.second;
293 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
304 i->second.SetRreqCnt (0);
313 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
317 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
" fails; not found");
320 i->second.SetFlag (state);
321 i->second.SetRreqCnt (0);
322 NS_LOG_LOGIC (
"Route set entry state to " <<
id <<
": new state is " << state);
331 unreachable.clear ();
332 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
335 if (i->second.GetNextHop () == nextHop)
337 NS_LOG_LOGIC (
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo ());
338 unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ()));
348 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
351 for (std::map<Ipv4Address, uint32_t>::const_iterator j =
352 unreachable.begin (); j != unreachable.end (); ++j)
354 if ((i->first == j->first) && (i->second.GetFlag () ==
VALID))
356 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
371 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
374 if (i->second.GetInterface () == iface)
376 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
395 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
398 if (i->second.GetLifeTime () <
Seconds (0))
400 if (i->second.GetFlag () ==
INVALID)
402 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
406 else if (i->second.GetFlag () ==
VALID)
408 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
432 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
433 table.begin (); i != table.end (); )
435 if (i->second.GetLifeTime () <
Seconds (0))
437 if (i->second.GetFlag () ==
INVALID)
439 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
443 else if (i->second.GetFlag () ==
VALID)
445 NS_LOG_LOGIC (
"Invalidate route with destination address " << i->first);
465 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
469 NS_LOG_LOGIC (
"Mark link unidirectional to " << neighbor <<
" fails; not found");
472 i->second.SetUnidirectional (
true);
473 i->second.SetBlacklistTimeout (blacklistTimeout);
474 i->second.SetRreqCnt (0);
475 NS_LOG_LOGIC (
"Set link to " << neighbor <<
" to unidirectional");
486 std::ios oldState (
nullptr);
487 oldState.copyfmt (*os);
489 *os << std::resetiosflags (std::ios::adjustfield) << std::setiosflags (std::ios::left);
490 *os <<
"\nAODV Routing table\n";
491 *os << std::setw (16) <<
"Destination";
492 *os << std::setw (16) <<
"Gateway";
493 *os << std::setw (16) <<
"Interface";
494 *os << std::setw (16) <<
"Flag";
495 *os << std::setw (16) <<
"Expire";
496 *os <<
"Hops" << std::endl;
497 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
498 table.begin (); i != table.end (); ++i)
500 i->second.Print (stream, unit);
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destination as follows:
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
RoutingTableEntry(Ptr< NetDevice > dev=0, 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
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
The routing table.
bool Update(RoutingTableEntry &rt)
Update routing table.
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Ipv4 addresses are stored in host order in this class.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
RoutingTable(Time t)
constructor
A simple virtual Timer class.
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
a class to store IPv4 address information on an interface
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Simulation virtual time values and global simulation resolution.
RouteFlags
Route record states.
uint8_t m_reqCount
Number of route requests.
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Time m_badLinkLifetime
Deletion time for invalid routes.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
std::vector< Ipv4Address > m_precursorList
List of precursors.
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 MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Time Seconds(double value)
Construct a Time in the indicated unit.
Control the scheduling of simulation events.
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role: for an ...
RouteFlags GetFlag() const
Get the route flags.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Ipv4Address GetLocal(void) const
Get the local address.
void DeleteAllPrecursors()
Delete all precursors.
Ipv4Address GetDestination() const
Get destination address function.
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
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 packet to trace file.
Ipv4InterfaceAddress m_iface
Output interface address.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Unit
The unit to use to interpret a number representing time.