24 #include "ns3/boolean.h"
26 #include "ns3/names.h"
27 #include "ns3/net-device.h"
29 #include "ns3/object.h"
30 #include "ns3/packet.h"
31 #include "ns3/simulator.h"
47 TypeId(
"ns3::Ipv4GlobalRouting")
49 .SetGroupName(
"Internet")
50 .AddAttribute(
"RandomEcmpRouting",
51 "Set to true if packets are randomly routed among ECMP; set to false for "
52 "using only one route consistently",
56 .AddAttribute(
"RespondToInterfaceEvents",
57 "Set to true if you want to dynamically recompute the global routes upon "
58 "Interface notification events (up/down, or add/remove address)",
66 : m_randomEcmpRouting(false),
67 m_respondToInterfaceEvents(false)
71 m_rand = CreateObject<UniformRandomVariable>();
103 NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
124 NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
134 NS_LOG_LOGIC(
"Looking for route for destination " << dest);
137 typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
138 RouteVec_t allRoutes;
144 if ((*i)->GetDest() == dest)
148 if (oif !=
m_ipv4->GetNetDevice((*i)->GetInterface()))
154 allRoutes.push_back(*i);
155 NS_LOG_LOGIC(allRoutes.size() <<
"Found global host route" << *i);
158 if (allRoutes.empty())
163 Ipv4Mask mask = (*j)->GetDestNetworkMask();
169 if (oif !=
m_ipv4->GetNetDevice((*j)->GetInterface()))
175 allRoutes.push_back(*j);
176 NS_LOG_LOGIC(allRoutes.size() <<
"Found global network route" << *j);
180 if (allRoutes.empty())
184 Ipv4Mask mask = (*k)->GetDestNetworkMask();
191 if (oif !=
m_ipv4->GetNetDevice((*k)->GetInterface()))
197 allRoutes.push_back(*
k);
202 if (!allRoutes.empty())
207 uint32_t selectIndex;
218 rtentry = Create<Ipv4Route>();
219 rtentry->SetDestination(route->
GetDest());
224 rtentry->SetOutputDevice(
m_ipv4->GetNetDevice(interfaceIdx));
303 << index <<
"; host route remaining size = " <<
m_hostRoutes.size());
319 << index <<
"; network route remaining size = " <<
m_networkRoutes.size());
334 << index <<
"; network route remaining size = " <<
m_networkRoutes.size());
378 std::ios oldState(
nullptr);
379 oldState.copyfmt(*os);
381 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
383 *os <<
"Node: " <<
m_ipv4->GetObject<
Node>()->GetId() <<
", Time: " <<
Now().
As(unit)
384 <<
", Local time: " <<
m_ipv4->GetObject<
Node>()->GetLocalTime().As(unit)
385 <<
", Ipv4GlobalRouting table" << std::endl;
389 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface"
393 std::ostringstream dest;
394 std::ostringstream gw;
395 std::ostringstream mask;
396 std::ostringstream flags;
399 *os << std::setw(16) << dest.str();
401 *os << std::setw(16) << gw.str();
403 *os << std::setw(16) << mask.str();
413 *os << std::setw(6) << flags.str();
436 (*os).copyfmt(oldState);
452 NS_LOG_LOGIC(
"Multicast destination-- returning false");
484 uint32_t iif =
m_ipv4->GetInterfaceForDevice(idev);
506 if (!
m_ipv4->IsForwarding(iif))
513 NS_LOG_LOGIC(
"Unicast destination- looking up global route");
517 NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
518 ucb(rtentry, p, header);
523 NS_LOG_LOGIC(
"Did not find unicast destination- returning false");
bool IsNull() const
Check for null implementation.
static void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
static void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
static void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
Ipv4 addresses are stored in host order in this class.
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Add a host route to the global routing table.
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
void AddASExternalRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add an external route to the global routing table.
Ipv4RoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Destructor implementation.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< UniformRandomVariable > m_rand
A uniform random number generator for randomly routing packets among ECMP.
void RemoveRoute(uint32_t i)
Remove a route from the global unicast routing table.
void NotifyInterfaceDown(uint32_t interface) override
void NotifyInterfaceUp(uint32_t interface) override
void SetIpv4(Ptr< Ipv4 > ipv4) override
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
uint32_t GetNRoutes() const
Get the number of individual unicast routes that have been added to the routing table.
Ipv4GlobalRouting()
Construct an empty Ipv4GlobalRouting routing protocol,.
~Ipv4GlobalRouting() override
Ptr< Ipv4 > m_ipv4
associated IPv4 instance
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add a network route to the global routing table.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
ASExternalRoutes m_ASexternalRoutes
External routes imported.
HostRoutes m_hostRoutes
Routes to hosts.
bool m_respondToInterfaceEvents
Set to true if this interface should respond to interface events by globallly recomputing routes.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
bool m_randomEcmpRouting
Set to true if packets are randomly routed among ECMP; set to false for using only one route consiste...
NetworkRoutes m_networkRoutes
Routes to networks.
Ptr< Ipv4Route > LookupGlobal(Ipv4Address dest, Ptr< NetDevice > oif=nullptr)
Lookup in the forwarding table for destination.
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
bool IsMatch(Ipv4Address a, Ipv4Address b) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
uint32_t GetInterface() const
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Ipv4Mask GetDestNetworkMask() const
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
A base class which provides memory management and object aggregation.
virtual void DoDispose()
Destructor implementation.
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static Time Now()
Return the current simulation virtual time.
SocketErrno
Enumeration of the possible errors returned by a socket.
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 unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#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 ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)