31 #include "ns3/simulator.h"
56 : m_ackTimer(
Timer::CANCEL_ON_DESTROY),
64 m_blackListState(false),
151 for (
auto j = prec.begin(); j != prec.end(); ++j)
184 std::ios oldState(
nullptr);
185 oldState.copyfmt(*os);
187 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
189 std::ostringstream dest;
190 std::ostringstream gw;
191 std::ostringstream iface;
192 std::ostringstream expire;
197 *os << std::setw(16) << dest.str();
198 *os << std::setw(16) << gw.str();
199 *os << std::setw(16) << iface.str();
200 *os << std::setw(16);
217 *os << std::setw(16) << expire.str();
218 *os <<
m_hops << std::endl;
220 (*os).copyfmt(oldState);
228 : m_badLinkLifetime(t)
239 NS_LOG_LOGIC(
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
274 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" successful");
277 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" not successful");
291 return result.second;
308 i->second.SetRreqCnt(0);
320 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
" fails; not found");
323 i->second.SetFlag(state);
324 i->second.SetRreqCnt(0);
325 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
": new state is " << state);
331 std::map<Ipv4Address, uint32_t>& unreachable)
338 if (i->second.GetNextHop() == nextHop)
340 NS_LOG_LOGIC(
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo());
341 unreachable.insert(std::make_pair(i->first, i->second.GetSeqNo()));
353 for (
auto j = unreachable.begin(); j != unreachable.end(); ++j)
355 if ((i->first == j->first) && (i->second.GetFlag() ==
VALID))
357 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
374 if (i->second.GetInterface() == iface)
397 if (i->second.GetLifeTime() <
Seconds(0))
399 if (i->second.GetFlag() ==
INVALID)
405 else if (i->second.GetFlag() ==
VALID)
407 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
431 for (
auto i = table.begin(); i != table.end();)
433 if (i->second.GetLifeTime() <
Seconds(0))
435 if (i->second.GetFlag() ==
INVALID)
441 else if (i->second.GetFlag() ==
VALID)
443 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
466 NS_LOG_LOGIC(
"Mark link unidirectional to " << neighbor <<
" fails; not found");
469 i->second.SetUnidirectional(
true);
470 i->second.SetBlacklistTimeout(blacklistTimeout);
471 i->second.SetRreqCnt(0);
472 NS_LOG_LOGIC(
"Set link to " << neighbor <<
" to unidirectional");
483 std::ios oldState(
nullptr);
484 oldState.copyfmt(*os);
486 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
487 *os <<
"\nAODV Routing table\n";
488 *os << std::setw(16) <<
"Destination";
489 *os << std::setw(16) <<
"Gateway";
490 *os << std::setw(16) <<
"Interface";
491 *os << std::setw(16) <<
"Flag";
492 *os << std::setw(16) <<
"Expire";
493 *os <<
"Hops" << std::endl;
494 for (
auto i = table.begin(); i != table.end(); ++i)
496 i->second.Print(stream, unit);
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.
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
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.