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)",
 
 
   76        if (*routePointer == *route)
 
 
   94        if (*routePointer == *route)
 
 
  110    NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
 
  115        if (*routePointer == *route)
 
 
  133        if (*routePointer == *route)
 
 
  149    NS_LOG_FUNCTION(
this << network << networkMask << nextHop << interface);
 
  154        if (*routePointer == *route)
 
 
  168    NS_LOG_LOGIC(
"Looking for route for destination " << dest);
 
  171    typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
 
  172    RouteVec_t allRoutes;
 
  178        if ((*i)->GetDest() == dest)
 
  182                if (oif != 
m_ipv4->GetNetDevice((*i)->GetInterface()))
 
  188            allRoutes.push_back(*i);
 
  189            NS_LOG_LOGIC(allRoutes.size() << 
"Found global host route" << *i);
 
  192    if (allRoutes.empty()) 
 
  196        uint16_t longest_mask = 0;
 
  199            Ipv4Mask mask = (*j)->GetDestNetworkMask();
 
  207                    if (oif != 
m_ipv4->GetNetDevice((*j)->GetInterface()))
 
  213                NS_LOG_LOGIC(allRoutes.size() << 
"Found global network route" << *j);
 
  214                if (masklen < longest_mask) 
 
  219                else if (masklen == longest_mask)
 
  221                    NS_LOG_LOGIC(
"Equal mask length, adding this to the list");
 
  222                    allRoutes.push_back(*j);
 
  226                    NS_LOG_LOGIC(
"Longer mask length found, clearing the list and adding");
 
  228                    allRoutes.push_back(*j);
 
  233    if (allRoutes.empty()) 
 
  237            Ipv4Mask mask = (*k)->GetDestNetworkMask();
 
  244                    if (oif != 
m_ipv4->GetNetDevice((*k)->GetInterface()))
 
  250                allRoutes.push_back(*k);
 
  255    if (!allRoutes.empty()) 
 
  263            selectIndex = 
m_rand->GetInteger(0, allRoutes.size() - 1);
 
  272        rtentry->SetDestination(route->
GetDest());
 
  277        rtentry->SetOutputDevice(
m_ipv4->GetNetDevice(interfaceIdx));
 
 
  356                             << index << 
"; host route remaining size = " << 
m_hostRoutes.size());
 
  372                         << index << 
"; network route remaining size = " << 
m_networkRoutes.size());
 
  387                         << index << 
"; network route remaining size = " << 
m_networkRoutes.size());
 
 
  399    m_rand->SetStream(stream);
 
 
  429    std::ostream* os = stream->GetStream();
 
  431    std::ios oldState(
nullptr);
 
  432    oldState.copyfmt(*os);
 
  434    *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
 
  436    *os << 
"Node: " << 
m_ipv4->GetObject<
Node>()->GetId() << 
", Time: " << 
Now().
As(unit)
 
  437        << 
", Local time: " << 
m_ipv4->GetObject<
Node>()->GetLocalTime().As(unit)
 
  438        << 
", Ipv4GlobalRouting table" << std::endl;
 
  442        *os << 
"Destination     Gateway         Genmask         Flags Metric Ref    Use Iface" 
  446            std::ostringstream dest;
 
  447            std::ostringstream gw;
 
  448            std::ostringstream mask;
 
  449            std::ostringstream flags;
 
  452            *os << std::setw(16) << dest.str();
 
  454            *os << std::setw(16) << gw.str();
 
  456            *os << std::setw(16) << mask.str();
 
  466            *os << std::setw(6) << flags.str();
 
  489    (*os).copyfmt(oldState);
 
 
  505        NS_LOG_LOGIC(
"Multicast destination-- returning false");
 
 
  559    if (!
m_ipv4->IsForwarding(iif))
 
  566    NS_LOG_LOGIC(
"Unicast destination- looking up global route");
 
  570        NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
 
  571        ucb(rtentry, p, header);
 
  576        NS_LOG_LOGIC(
"Did not find unicast destination- returning false");
 
 
AttributeValue implementation for Boolean.
 
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.
 
Global routing protocol for IPv4 stacks.
 
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.
 
a class to store IPv4 address information on an interface
 
a class to represent an Ipv4 address mask
 
uint16_t GetPrefixLength() const
 
bool IsMatch(Ipv4Address a, Ipv4Address b) const
 
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const Ipv4Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
 
Callback< void, Ptr< const Packet >, const Ipv4Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
 
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
 
Callback< void, Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
 
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.
 
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,...
 
Ptr< const AttributeChecker > MakeBooleanChecker()
 
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
 
#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.