20#include "ns3/simulator.h"
45 : m_ackTimer(
Timer::CANCEL_ON_DESTROY),
53 m_blackListState(false),
140 for (
auto j = prec.begin(); j != prec.end(); ++j)
171 std::ostream* os = stream->GetStream();
173 std::ios oldState(
nullptr);
174 oldState.copyfmt(*os);
176 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
178 std::ostringstream dest;
179 std::ostringstream gw;
180 std::ostringstream iface;
181 std::ostringstream expire;
186 *os << std::setw(16) << dest.str();
187 *os << std::setw(16) << gw.str();
188 *os << std::setw(16) << iface.str();
189 *os << std::setw(16);
206 *os << std::setw(16) << expire.str();
207 *os <<
m_hops << std::endl;
209 (*os).copyfmt(oldState);
217 : m_badLinkLifetime(t)
228 NS_LOG_LOGIC(
"Route to " <<
id <<
" not found; m_ipv4AddressEntry is empty");
263 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" successful");
266 NS_LOG_LOGIC(
"Route deletion to " << dst <<
" not successful");
280 return result.second;
297 i->second.SetRreqCnt(0);
309 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
" fails; not found");
312 i->second.SetFlag(state);
313 i->second.SetRreqCnt(0);
314 NS_LOG_LOGIC(
"Route set entry state to " <<
id <<
": new state is " << state);
320 std::map<Ipv4Address, uint32_t>& unreachable)
327 if (i->second.GetNextHop() == nextHop)
329 NS_LOG_LOGIC(
"Unreachable insert " << i->first <<
" " << i->second.GetSeqNo());
330 unreachable.insert(std::make_pair(i->first, i->second.GetSeqNo()));
342 for (
auto j = unreachable.begin(); j != unreachable.end(); ++j)
344 if ((i->first == j->first) && (i->second.GetFlag() ==
VALID))
346 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
363 if (i->second.GetInterface() == iface)
386 if (i->second.GetLifeTime() <
Seconds(0))
388 if (i->second.GetFlag() ==
INVALID)
394 else if (i->second.GetFlag() ==
VALID)
396 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
420 for (
auto i = table.begin(); i != table.end();)
422 if (i->second.GetLifeTime() <
Seconds(0))
424 if (i->second.GetFlag() ==
INVALID)
430 else if (i->second.GetFlag() ==
VALID)
432 NS_LOG_LOGIC(
"Invalidate route with destination address " << i->first);
455 NS_LOG_LOGIC(
"Mark link unidirectional to " << neighbor <<
" fails; not found");
458 i->second.SetUnidirectional(
true);
459 i->second.SetBlacklistTimeout(blacklistTimeout);
460 i->second.SetRreqCnt(0);
461 NS_LOG_LOGIC(
"Set link to " << neighbor <<
" to unidirectional");
470 std::ostream* os = stream->GetStream();
472 std::ios oldState(
nullptr);
473 oldState.copyfmt(*os);
475 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
476 *os <<
"\nAODV Routing table\n";
477 *os << std::setw(16) <<
"Destination";
478 *os << std::setw(16) <<
"Gateway";
479 *os << std::setw(16) <<
"Interface";
480 *os << std::setw(16) <<
"Flag";
481 *os << std::setw(16) <<
"Expire";
482 *os <<
"Hops" << std::endl;
483 for (
auto i = table.begin(); i != table.end(); ++i)
485 i->second.Print(stream, unit);
487 *stream->GetStream() <<
"\n";
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.
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 ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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.