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"
44 .SetGroupName (
"Internet")
45 .AddAttribute (
"RandomEcmpRouting",
46 "Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently",
50 .AddAttribute (
"RespondToInterfaceEvents",
51 "Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)",
60 : m_randomEcmpRouting (false),
61 m_respondToInterfaceEvents (false)
65 m_rand = CreateObject<UniformRandomVariable> ();
100 NS_LOG_FUNCTION (
this << network << networkMask << nextHop << interface);
128 NS_LOG_FUNCTION (
this << network << networkMask << nextHop << interface);
142 NS_LOG_LOGIC (
"Looking for route for destination " << dest);
145 typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
146 RouteVec_t allRoutes;
154 if ((*i)->GetDest ().IsEqual (dest))
158 if (oif !=
m_ipv4->GetNetDevice ((*i)->GetInterface ()))
164 allRoutes.push_back (*i);
165 NS_LOG_LOGIC (allRoutes.size () <<
"Found global host route" << *i);
168 if (allRoutes.size () == 0)
175 Ipv4Mask mask = (*j)->GetDestNetworkMask ();
177 if (mask.
IsMatch (dest, entry))
181 if (oif !=
m_ipv4->GetNetDevice ((*j)->GetInterface ()))
187 allRoutes.push_back (*j);
188 NS_LOG_LOGIC (allRoutes.size () <<
"Found global network route" << *j);
192 if (allRoutes.size () == 0)
198 Ipv4Mask mask = (*k)->GetDestNetworkMask ();
200 if (mask.
IsMatch (dest, entry))
205 if (oif !=
m_ipv4->GetNetDevice ((*k)->GetInterface ()))
211 allRoutes.push_back (*k);
216 if (allRoutes.size () > 0 )
221 uint32_t selectIndex;
232 rtentry = Create<Ipv4Route> ();
406 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
409 std::ostringstream dest, gw, mask, flags;
412 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
414 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
416 *os << std::setiosflags (std::ios::left) << std::setw (16) << mask.str ();
426 *os << std::setiosflags (std::ios::left) << std::setw (6) << flags.str ();
456 NS_LOG_LOGIC (
"Multicast destination-- returning false");
482 uint32_t iif =
m_ipv4->GetInterfaceForDevice (idev);
486 NS_LOG_LOGIC (
"Multicast destination-- returning false");
503 for (uint32_t j = 0; j <
m_ipv4->GetNInterfaces (); j++)
505 for (uint32_t i = 0; i <
m_ipv4->GetNAddresses (j); i++)
513 NS_LOG_LOGIC (
"For me (destination " << addr <<
" match)");
519 lcb (p, header, iif);
525 lcb (p, header, iif);
532 if (
m_ipv4->IsForwarding (iif) ==
false)
534 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
539 NS_LOG_LOGIC (
"Unicast destination- looking up global route");
543 NS_LOG_LOGIC (
"Found unicast destination- calling unicast callback");
544 ucb (rtentry, p, header);
549 NS_LOG_LOGIC (
"Did not find unicast destination- returning false");
std::list< Ipv4RoutingTableEntry * >::iterator HostRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to hosts)
virtual void NotifyInterfaceUp(uint32_t interface)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
static void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
SocketErrno
Enumeration of the possible errors returned by a socket.
AttributeValue implementation for Boolean.
void DoDispose(void)
Destructor implementation.
Ipv4GlobalRouting()
Construct an empty Ipv4GlobalRouting routing protocol,.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
bool IsMatch(Ipv4Address a, Ipv4Address b) const
Ipv4Address GetLocal(void) const
Get the local address.
a class to represent an Ipv4 address mask
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_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.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
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)
bool IsMulticast(void) const
virtual void NotifyInterfaceDown(uint32_t interface)
virtual void DoDispose(void)
Destructor implementation.
void RemoveRoute(uint32_t i)
Remove a route from the global unicast routing table.
Ipv4RoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
std::list< Ipv4RoutingTableEntry * >::const_iterator ASExternalRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to external AS)
ASExternalRoutes m_ASexternalRoutes
External routes imported.
void SetSource(Ipv4Address src)
uint32_t GetInterface(void) const
HostRoutes m_hostRoutes
Routes to hosts.
Ptr< UniformRandomVariable > m_rand
A uniform random number generator for randomly routing packets among ECMP.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
bool IsGateway(void) const
static Ipv4RoutingTableEntry CreateHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Ptr< Ipv4 > m_ipv4
associated IPv4 instance
void SetGateway(Ipv4Address gw)
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
bool m_respondToInterfaceEvents
Set to true if this interface should respond to interface events by globallly recomputing routes...
bool IsBroadcast(void) const
static void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
std::list< Ipv4RoutingTableEntry * >::const_iterator NetworkRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to networks)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
bool m_randomEcmpRouting
Set to true if packets are randomly routed among ECMP; set to false for using only one route consiste...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Ptr< Ipv4Route > LookupGlobal(Ipv4Address dest, Ptr< NetDevice > oif=0)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsEqual(const Ipv4Address &other) const
Comparison operation between two Ipv4Addresses.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual ~Ipv4GlobalRouting()
static void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
Ipv4Address GetDest(void) const
std::list< Ipv4RoutingTableEntry * >::const_iterator HostRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to hosts)
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.
static Time Now(void)
Return the current simulation virtual time.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
std::list< Ipv4RoutingTableEntry * >::iterator ASExternalRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to external AS)
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add a network route to the global routing table.
Ipv4 addresses are stored in host order in this class.
std::list< Ipv4RoutingTableEntry * >::iterator NetworkRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to networks)
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
a class to store IPv4 address information on an interface
Ipv4Address GetGateway(void) const
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
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...
NetworkRoutes m_networkRoutes
Routes to networks.
A base class which provides memory management and object aggregation.
static TypeId GetTypeId(void)
Get the type ID.
Ipv4Mask GetDestNetworkMask(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
void SetDestination(Ipv4Address dest)
void AddASExternalRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add an external route to the global routing table.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Add a host route to the global routing table.