33#include "ns3/simulator.h"
58 m_settlingTime(settlingTime),
59 m_entriesChanged(areChanged)
83 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.find(
id);
99 std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.find(
id);
104 if (forRouteInput &&
id == i->second.GetInterface().GetBroadcast())
127 std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator,
bool> result =
129 return result.second;
135 std::map<Ipv4Address, RoutingTableEntry>::iterator i =
152 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
155 if (i->second.GetInterface() == iface)
157 std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
171 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
175 if (i->second.GetDestination() !=
Ipv4Address(
"127.0.0.1") && i->second.GetFlag() ==
VALID)
177 allRoutes.insert(std::make_pair(i->first, i->second));
184 std::map<Ipv4Address, RoutingTableEntry>& unreachable)
187 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.begin();
191 if (i->second.GetNextHop() == nextHop)
193 unreachable.insert(std::make_pair(i->first, i->second));
201 std::ostream* os = stream->GetStream();
203 std::ios oldState(
nullptr);
204 oldState.copyfmt(*os);
206 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
208 std::ostringstream dest;
209 std::ostringstream gw;
210 std::ostringstream iface;
211 std::ostringstream ltime;
212 std::ostringstream stime;
219 *os << std::setw(16) << dest.str();
220 *os << std::setw(16) << gw.str();
221 *os << std::setw(16) << iface.str();
222 *os << std::setw(16) <<
m_hops;
223 *os << std::setw(16) <<
m_seqNo;
224 *os << std::setw(16) << ltime.str();
225 *os << stime.str() << std::endl;
227 (*os).copyfmt(oldState);
237 for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
m_ipv4AddressEntry.begin();
240 std::map<Ipv4Address, RoutingTableEntry>::iterator itmp = i;
241 if (i->second.GetLifeTime() >
m_holddownTime && (i->second.GetHop() > 0))
243 for (std::map<Ipv4Address, RoutingTableEntry>::iterator j =
m_ipv4AddressEntry.begin();
246 if ((j->second.GetNextHop() == i->second.GetDestination()) &&
247 (i->second.GetHop() != j->second.GetHop()))
249 std::map<Ipv4Address, RoutingTableEntry>::iterator jtmp = j;
250 removedAddresses.insert(std::make_pair(j->first, j->second));
259 removedAddresses.insert(std::make_pair(i->first, i->second));
279 std::ostream* os = stream->GetStream();
281 std::ios oldState(
nullptr);
282 oldState.copyfmt(*os);
284 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
286 *os <<
"\nDSDV Routing table\n";
287 *os << std::setw(16) <<
"Destination";
288 *os << std::setw(16) <<
"Gateway";
289 *os << std::setw(16) <<
"Interface";
290 *os << std::setw(16) <<
"HopCount";
291 *os << std::setw(16) <<
"SeqNum";
292 *os << std::setw(16) <<
"LifeTime";
293 *os <<
"SettlingTime" << std::endl;
294 for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
m_ipv4AddressEntry.begin();
298 i->second.Print(stream, unit);
302 (*os).copyfmt(oldState);
308 std::pair<std::map<Ipv4Address, EventId>::iterator,
bool> result =
310 return result.second;
317 std::map<Ipv4Address, EventId>::const_iterator i =
m_ipv4Events.find(address);
327 return event.IsRunning();
334 std::map<Ipv4Address, EventId>::const_iterator i =
m_ipv4Events.find(address);
349 std::map<Ipv4Address, EventId>::const_iterator i =
m_ipv4Events.find(address);
375 std::map<Ipv4Address, EventId>::const_iterator i =
m_ipv4Events.find(address);
An identifier for simulation events.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
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.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
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.
uint32_t m_seqNo
Destination Sequence Number.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table entry.
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for an...
Ipv4Address GetDestination() const
Get destination IP address.
Ipv4InterfaceAddress m_iface
Output interface address.
RoutingTableEntry(Ptr< NetDevice > dev=nullptr, Ipv4Address dst=Ipv4Address(), uint32_t seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint32_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now(), Time settlingTime=Simulator::Now(), bool changedEntries=false)
c-tor
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Time m_settlingTime
Time for which the node retains an update with changed metric before broadcasting it.
uint32_t m_hops
Hop Count (number of hops needed to reach destination)
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Time m_holddownTime
hold down time of an expired route
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
bool ForceDeleteIpv4Event(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
an entry in the routing table.
void GetListOfDestinationWithNextHop(Ipv4Address nxtHp, std::map< Ipv4Address, RoutingTableEntry > &dstList)
Lookup list of addresses for which nxtHp is the next Hop address.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
EventId GetEventId(Ipv4Address address)
Get the EventId associated with that address.
bool AddIpv4Event(Ipv4Address address, EventId id)
Add an event for a destination address so that the update to for that destination is sent after the e...
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
std::map< Ipv4Address, EventId > m_ipv4Events
an entry in the event table.
bool AnyRunningEvent(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Every class exported by the ns3 library is enclosed in the ns3 namespace.