21 #include "ns3/names.h"
23 #include "ns3/simulator.h"
24 #include "ns3/object.h"
25 #include "ns3/packet.h"
26 #include "ns3/net-device.h"
27 #include "ns3/ipv4-route.h"
28 #include "ns3/ipv4-routing-table-entry.h"
29 #include "ns3/boolean.h"
45 .SetGroupName (
"Internet")
46 .AddAttribute (
"RandomEcmpRouting",
47 "Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently",
51 .AddAttribute (
"RespondToInterfaceEvents",
52 "Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)",
61 : m_randomEcmpRouting (false),
62 m_respondToInterfaceEvents (false)
66 m_rand = CreateObject<UniformRandomVariable> ();
101 NS_LOG_FUNCTION (
this << network << networkMask << nextHop << interface);
129 NS_LOG_FUNCTION (
this << network << networkMask << nextHop << interface);
143 NS_LOG_LOGIC (
"Looking for route for destination " << dest);
146 typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
147 RouteVec_t allRoutes;
155 if ((*i)->GetDest () == dest)
159 if (oif !=
m_ipv4->GetNetDevice ((*i)->GetInterface ()))
165 allRoutes.push_back (*i);
166 NS_LOG_LOGIC (allRoutes.size () <<
"Found global host route" << *i);
169 if (allRoutes.size () == 0)
176 Ipv4Mask mask = (*j)->GetDestNetworkMask ();
178 if (mask.
IsMatch (dest, entry))
182 if (oif !=
m_ipv4->GetNetDevice ((*j)->GetInterface ()))
188 allRoutes.push_back (*j);
189 NS_LOG_LOGIC (allRoutes.size () <<
"Found global network route" << *j);
193 if (allRoutes.size () == 0)
199 Ipv4Mask mask = (*k)->GetDestNetworkMask ();
201 if (mask.
IsMatch (dest, entry))
206 if (oif !=
m_ipv4->GetNetDevice ((*k)->GetInterface ()))
212 allRoutes.push_back (*
k);
217 if (allRoutes.size () > 0 )
222 uint32_t selectIndex;
233 rtentry = Create<Ipv4Route> ();
234 rtentry->SetDestination (route->
GetDest ());
239 rtentry->SetOutputDevice (
m_ipv4->GetNetDevice (interfaceIdx));
406 std::ios oldState (
nullptr);
407 oldState.copyfmt (*os);
409 *os << std::resetiosflags (std::ios::adjustfield) << std::setiosflags (std::ios::left);
411 *os <<
"Node: " <<
m_ipv4->GetObject<
Node> ()->GetId ()
412 <<
", Time: " <<
Now().
As (unit)
413 <<
", Local time: " <<
m_ipv4->GetObject<
Node> ()->GetLocalTime ().As (unit)
414 <<
", Ipv4GlobalRouting table" << std::endl;
418 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
421 std::ostringstream dest, gw, mask, flags;
424 *os << std::setw (16) << dest.str ();
426 *os << std::setw (16) << gw.str ();
428 *os << std::setw (16) << mask.str ();
438 *os << std::setw (6) << flags.str ();
458 (*os).copyfmt (oldState);
471 NS_LOG_LOGIC (
"Multicast destination-- returning false");
497 uint32_t iif =
m_ipv4->GetInterfaceForDevice (idev);
504 lcb (p, header, iif);
519 if (
m_ipv4->IsForwarding (iif) ==
false)
521 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
526 NS_LOG_LOGIC (
"Unicast destination- looking up global route");
530 NS_LOG_LOGIC (
"Found unicast destination- calling unicast callback");
531 ucb (rtentry, p, header);
536 NS_LOG_LOGIC (
"Did not find unicast destination- returning false");
AttributeValue implementation for Boolean.
bool IsNull(void) 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.
bool IsMulticast(void) const
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Add a host route to the global routing table.
virtual void NotifyInterfaceDown(uint32_t interface)
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.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
std::list< Ipv4RoutingTableEntry * >::iterator ASExternalRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to external AS)
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
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 DoDispose(void)
Destructor implementation.
void RemoveRoute(uint32_t i)
Remove a route from the global unicast routing table.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
std::list< Ipv4RoutingTableEntry * >::iterator HostRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to hosts)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
std::list< Ipv4RoutingTableEntry * >::iterator NetworkRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to networks)
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
Ptr< Ipv4Route > LookupGlobal(Ipv4Address dest, Ptr< NetDevice > oif=0)
Lookup in the forwarding table for destination.
Ipv4GlobalRouting()
Construct an empty Ipv4GlobalRouting routing protocol,.
Ptr< Ipv4 > m_ipv4
associated IPv4 instance
std::list< Ipv4RoutingTableEntry * >::const_iterator NetworkRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to networks)
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add a network route to the global routing table.
std::list< Ipv4RoutingTableEntry * >::const_iterator ASExternalRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to external AS)
std::list< Ipv4RoutingTableEntry * >::const_iterator HostRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to hosts)
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
virtual ~Ipv4GlobalRouting()
ASExternalRoutes m_ASexternalRoutes
External routes imported.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
HostRoutes m_hostRoutes
Routes to hosts.
static TypeId GetTypeId(void)
Get the type ID.
bool m_respondToInterfaceEvents
Set to true if this interface should respond to interface events by globallly recomputing routes.
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.
virtual void NotifyInterfaceUp(uint32_t interface)
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.
uint32_t GetInterface(void) const
bool IsGateway(void) const
Ipv4Address GetDest(void) const
Ipv4Mask GetDestNetworkMask(void) const
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Ipv4Address GetGateway(void) 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(void)
Destructor implementation.
std::ostream * GetStream(void)
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(void)
Return the current simulation virtual time.
SocketErrno
Enumeration of the possible errors returned by a socket.
Unit
The unit to use to interpret a number representing time.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
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(void)
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 ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.