bug 702: make global routing robust to link/device events

This commit is contained in:
Tom Henderson
2010-05-24 10:52:58 -07:00
parent a6a2797a69
commit d5624122d1
7 changed files with 96 additions and 40 deletions

View File

@@ -33,22 +33,28 @@
* The model assumes that all nodes on an ns-3 channel are reachable to
* one another, regardless of whether the nodes can use the channel
* successfully (in the case of wireless). Therefore, this model
* should typically be used only on wired topologies. API does not
* yet exist to control the subset of a topology to which this global
* static routing is applied.
* should typically be used only on wired topologies. Layer-2 bridge
* devices are supported. API does not yet exist to control the subset
* of a topology to which this global static routing is applied.
*
* This model also does not yet deal with the possible presence of
* layer-2 relays such as switches, bridges, and hubs, although ns-3 does
* not have such devices yet.
* If the topology changes during the simulation, by default, routing
* will not adjust. There are two ways to make it adjust.
* - Set the attribute Ipv4GlobalRouting::RespondToInterfaceEvents to true
* - Manually call the sequence of GlobalRouteManager methods to delte global
* routes, build global routing database, and initialize routes.
* There is a helper method that encapsulates this
* (Ipv4GlobalRoutingHelper::RecomputeRoutingTables())
*
* \section api API and Usage
*
* Users must include ns3/global-route-manager.h header file. After the
* IPv4 topology has been built and addresses assigned, users call
* ns3::GlobalRouteManager::PopulateRoutingTables (), prior to the
* ns3::Simulator::Run() call. There are no other attributes or
* public methods that are typically called, or ways to parameterize
* the behavior.
* ns3::Simulator::Run() call.
*
* There are two attributes of Ipv4GlobalRouting that govern behavior.
* - Ipv4GlobalRouting::RandomEcmpRouting
* - Ipv4GlobalRouting::RespondToInterfaceEvents
*
* \section impl Implementation
*

View File

@@ -17,6 +17,7 @@
//
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/object.h"
#include "ns3/packet.h"
#include "ns3/net-device.h"
@@ -24,6 +25,7 @@
#include "ns3/ipv4-routing-table-entry.h"
#include "ns3/boolean.h"
#include "ipv4-global-routing.h"
#include "global-route-manager.h"
#include <vector>
NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
@@ -42,12 +44,18 @@ Ipv4GlobalRouting::GetTypeId (void)
BooleanValue(false),
MakeBooleanAccessor (&Ipv4GlobalRouting::m_randomEcmpRouting),
MakeBooleanChecker ())
.AddAttribute ("RespondToInterfaceEvents",
"Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)",
BooleanValue(false),
MakeBooleanAccessor (&Ipv4GlobalRouting::m_respondToInterfaceEvents),
MakeBooleanChecker ())
;
return tid;
}
Ipv4GlobalRouting::Ipv4GlobalRouting ()
: m_randomEcmpRouting (false)
: m_randomEcmpRouting (false),
m_respondToInterfaceEvents (false)
{
NS_LOG_FUNCTION_NOARGS ();
}
@@ -485,16 +493,52 @@ Ipv4GlobalRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, P
}
void
Ipv4GlobalRouting::NotifyInterfaceUp (uint32_t i)
{}
{
NS_LOG_FUNCTION (this << i);
if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0) // avoid startup events
{
GlobalRouteManager::DeleteGlobalRoutes ();
GlobalRouteManager::BuildGlobalRoutingDatabase ();
GlobalRouteManager::InitializeRoutes ();
}
}
void
Ipv4GlobalRouting::NotifyInterfaceDown (uint32_t i)
{}
{
NS_LOG_FUNCTION (this << i);
if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0) // avoid startup events
{
GlobalRouteManager::DeleteGlobalRoutes ();
GlobalRouteManager::BuildGlobalRoutingDatabase ();
GlobalRouteManager::InitializeRoutes ();
}
}
void
Ipv4GlobalRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
{}
{
NS_LOG_FUNCTION (this << interface << address);
if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0) // avoid startup events
{
GlobalRouteManager::DeleteGlobalRoutes ();
GlobalRouteManager::BuildGlobalRoutingDatabase ();
GlobalRouteManager::InitializeRoutes ();
}
}
void
Ipv4GlobalRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
{}
{
NS_LOG_FUNCTION (this << interface << address);
if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0) // avoid startup events
{
GlobalRouteManager::DeleteGlobalRoutes ();
GlobalRouteManager::BuildGlobalRoutingDatabase ();
GlobalRouteManager::InitializeRoutes ();
}
}
void
Ipv4GlobalRouting::SetIpv4 (Ptr<Ipv4> ipv4)
{

View File

@@ -81,6 +81,7 @@ public:
Ipv4GlobalRouting ();
virtual ~Ipv4GlobalRouting ();
// These methods inherited from base class
virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
@@ -215,6 +216,8 @@ protected:
private:
/// Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently
bool m_randomEcmpRouting;
/// Set to true if this interface should respond to interface events by globallly recomputing routes
bool m_respondToInterfaceEvents;
/// A uniform random number generator for randomly routing packets among ECMP
UniformVariable m_rand;