13#include "ns3/boolean.h"
16#include "ns3/net-device.h"
18#include "ns3/object.h"
19#include "ns3/packet.h"
20#include "ns3/simulator.h"
36 TypeId(
"ns3::Ipv4GlobalRouting")
38 .SetGroupName(
"Internet")
39 .AddAttribute(
"RandomEcmpRouting",
40 "Set to true if packets are randomly routed among ECMP; set to false for "
41 "using only one route consistently",
45 .AddAttribute(
"RespondToInterfaceEvents",
46 "Set to true if you want to dynamically recompute the global routes upon "
47 "Interface notification events (up/down, or add/remove address)",
55 : m_randomEcmpRouting(false),
56 m_respondToInterfaceEvents(false)
92 NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
113 NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
123 NS_LOG_LOGIC(
"Looking for route for destination " << dest);
126 typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
127 RouteVec_t allRoutes;
133 if ((*i)->GetDest() == dest)
143 allRoutes.push_back(*i);
144 NS_LOG_LOGIC(allRoutes.size() <<
"Found global host route" << *i);
147 if (allRoutes.empty())
152 Ipv4Mask mask = (*j)->GetDestNetworkMask();
164 allRoutes.push_back(*j);
165 NS_LOG_LOGIC(allRoutes.size() <<
"Found global network route" << *j);
169 if (allRoutes.empty())
173 Ipv4Mask mask = (*k)->GetDestNetworkMask();
186 allRoutes.push_back(*k);
191 if (!allRoutes.empty())
199 selectIndex =
m_rand->GetInteger(0, allRoutes.size() - 1);
208 rtentry->SetDestination(route->
GetDest());
292 << index <<
"; host route remaining size = " <<
m_hostRoutes.size());
308 << index <<
"; network route remaining size = " <<
m_networkRoutes.size());
323 << index <<
"; network route remaining size = " <<
m_networkRoutes.size());
335 m_rand->SetStream(stream);
365 std::ostream* os = stream->GetStream();
367 std::ios oldState(
nullptr);
368 oldState.copyfmt(*os);
370 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
374 <<
", Ipv4GlobalRouting table" << std::endl;
378 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface"
382 std::ostringstream dest;
383 std::ostringstream gw;
384 std::ostringstream mask;
385 std::ostringstream flags;
388 *os << std::setw(16) << dest.str();
390 *os << std::setw(16) << gw.str();
392 *os << std::setw(16) << mask.str();
402 *os << std::setw(6) << flags.str();
425 (*os).copyfmt(oldState);
441 NS_LOG_LOGIC(
"Multicast destination-- returning false");
502 NS_LOG_LOGIC(
"Unicast destination- looking up global route");
506 NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
507 ucb(rtentry, p, header);
512 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 globally 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.
virtual bool IsForwarding(uint32_t interface) const =0
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const =0
Determine whether address and interface corresponding to received packet can be accepted for local de...
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
a class to store IPv4 address information on an interface
Ipv4Address GetLocal() const
Get the local address.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)