View | Details | Raw Unified | Return to bug 702
Collapse All | Expand All

(-)a/doc/manual/routing.texi (+10 lines)
 Lines 147-152    Link Here 
147
    &Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
147
    &Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
148
@end verbatim
148
@end verbatim
149
149
150
There are two attributes that govern the behavior.  The first is 
151
Ipv4GlobalRouting::RandomEcmpRouting.  If set to true, packets are randomly
152
routed across equal-cost multipath routes.  If set to false (default), 
153
only one route is consistently used.  The second is 
154
Ipv4GlobalRouting::RespondToInterfaceEvents.  If set to true, dynamically 
155
recompute the global routes upon Interface notification events (up/down, 
156
or add/remove address).  If set to false (default), routing may break
157
unless the user manually calls RecomputeRoutingTables() after such events.
158
The default is set to false to preserve legacy ns-3 program behavior.
159
150
@subsection Global Routing Implementation
160
@subsection Global Routing Implementation
151
161
152
This section is for those readers who care about how this is implemented.
162
This section is for those readers who care about how this is implemented.
(-)a/examples/routing/dynamic-global-routing.cc (-26 / +14 lines)
 Lines 18-24    Link Here 
18
18
19
19
20
// This script exercises global routing code in a mixed point-to-point
20
// This script exercises global routing code in a mixed point-to-point
21
// and csma/cd environment
21
// and csma/cd environment.  We bring up and down interfaces and observe
22
// the effect on global routing.  We explicitly enable the attribute
23
// to respond to interface events, so that routes are recomputed
24
// automatically.
22
//
25
//
23
// Network topology
26
// Network topology
24
//
27
//
 Lines 41-73    Link Here 
41
//  n1 to n6 is via the direct point-to-point link
44
//  n1 to n6 is via the direct point-to-point link
42
//  At time 1s, start CBR traffic flow from n1 to n6
45
//  At time 1s, start CBR traffic flow from n1 to n6
43
//  At time 2s, set the n1 point-to-point interface to down.  Packets
46
//  At time 2s, set the n1 point-to-point interface to down.  Packets
44
//    will start to be dropped 
47
//    will be diverted to the n1-n2-n5-n6 path
45
//  At time 3s, call RecomputeRoutingTables() and traffic will
48
//  At time 4s, re-enable the n1/n6 interface to up.  n1-n6 route restored.
46
//    start flowing again on the alternate path
47
//  At time 4s, re-enable the n1/n6 interface to up.  Will not change routing
48
//  At time 5s, call RecomputeRoutingTables() and traffic will start flowing 
49
//    again on the original path
50
//  At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this
49
//  At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this
51
//    keeps the point-to-point link "up" from n1's perspective).  Packets
50
//    keeps the point-to-point link "up" from n1's perspective).  Traffic will
52
//    will traverse the link and be dropped at n6 upon receipt.  These drops
51
//    flow through the path n1-n2-n5-n6
53
//    are not visible in the pcap trace but in the ascii trace.
52
//  At time 8s, bring the interface back up.  Path n1-n6 is restored
54
//  At time 7s, call RecomputeRoutingTables() and traffic will flow again
55
//    through the path n1-n2-n5-n6
56
//  At time 8s, bring the interface back up.
57
//  At time 9s, call RecomputeRoutingTables() and traffic will flow again
58
//    through the path n1-n6
59
//  At time 10s, stop the first flow.  
53
//  At time 10s, stop the first flow.  
60
//  At time 11s, start a new flow, but to n6's other IP address (the one
54
//  At time 11s, start a new flow, but to n6's other IP address (the one
61
//    on the n1/n6 p2p link)
55
//    on the n1/n6 p2p link)
62
//  At time 12s, bring the n1 interface down between n1 and n6.  Packets
56
//  At time 12s, bring the n1 interface down between n1 and n6.  Packets
63
//    will start to be dropped 
57
//    will be diverted to the alternate path
64
//  At time 13s, call RecomputeRoutingTables() and traffic will
65
//    start flowing again on the alternate path
66
//  At time 14s, re-enable the n1/n6 interface to up.  This will change 
58
//  At time 14s, re-enable the n1/n6 interface to up.  This will change 
67
//    routing back to n1-n6 since the interface up notification will cause
59
//    routing back to n1-n6 since the interface up notification will cause
68
//    a new local interface route, at higher priority than global routing
60
//    a new local interface route, at higher priority than global routing
69
//  At time 15s, call RecomputeRoutingTables(), but there is no effect
70
//    since global routing is lower in priority than static routing
71
//  At time 16s, stop the second flow.  
61
//  At time 16s, stop the second flow.  
72
62
73
// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr"
63
// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr"
 Lines 89-94    Link Here 
89
int 
79
int 
90
main (int argc, char *argv[])
80
main (int argc, char *argv[])
91
{
81
{
82
  // The below value configures the default behavior of global routing.
83
  // By default, it is disabled.  To respond to interface events, set to true
84
  Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (false));
85
92
  // Allow the user to override any of the defaults and the above
86
  // Allow the user to override any of the defaults and the above
93
  // Bind ()s at run-time, via command-line arguments
87
  // Bind ()s at run-time, via command-line arguments
94
  CommandLine cmd;
88
  CommandLine cmd;
 Lines 206-214    Link Here 
206
  uint32_t ipv4ifIndex1 = 2;
200
  uint32_t ipv4ifIndex1 = 2;
207
201
208
  Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
202
  Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
209
  Simulator::Schedule (Seconds (3),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
210
  Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
203
  Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
211
  Simulator::Schedule (Seconds (5),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
212
204
213
  Ptr<Node> n6 = c.Get (6);
205
  Ptr<Node> n6 = c.Get (6);
214
  Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
206
  Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
 Lines 216-229    Link Here 
216
  // then the next p2p is numbered 2
208
  // then the next p2p is numbered 2
217
  uint32_t ipv4ifIndex6 = 2;
209
  uint32_t ipv4ifIndex6 = 2;
218
  Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
210
  Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
219
  Simulator::Schedule (Seconds (7),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
220
  Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
211
  Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
221
  Simulator::Schedule (Seconds (9),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
222
212
223
  Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
213
  Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
224
  Simulator::Schedule (Seconds (13),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
225
  Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
214
  Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
226
  Simulator::Schedule (Seconds (15),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
227
215
228
  NS_LOG_INFO ("Run Simulation.");
216
  NS_LOG_INFO ("Run Simulation.");
229
  Simulator::Run ();
217
  Simulator::Run ();
(-)a/src/routing/global-routing/global-routing.h (-9 / +15 lines)
 Lines 33-54    Link Here 
33
 * The model assumes that all nodes on an ns-3 channel are reachable to
33
 * The model assumes that all nodes on an ns-3 channel are reachable to
34
 * one another, regardless of whether the nodes can use the channel
34
 * one another, regardless of whether the nodes can use the channel
35
 * successfully (in the case of wireless).  Therefore, this model
35
 * successfully (in the case of wireless).  Therefore, this model
36
 * should typically be used only on wired topologies.  API does not
36
 * should typically be used only on wired topologies.  Layer-2 bridge
37
 * yet exist to control the subset of a topology to which this global
37
 * devices are supported.  API does not yet exist to control the subset 
38
 * static routing is applied.
38
 * of a topology to which this global static routing is applied.
39
 * 
39
 * 
40
 * This model also does not yet deal with the possible presence of
40
 * If the topology changes during the simulation, by default, routing
41
 * layer-2 relays such as switches, bridges, and hubs, although ns-3 does
41
 * will not adjust.  There are two ways to make it adjust.
42
 * not have such devices yet.
42
 * - Set the attribute Ipv4GlobalRouting::RespondToInterfaceEvents to true 
43
 * - Manually call the sequence of GlobalRouteManager methods to delte global
44
 *   routes, build global routing database, and initialize routes.
45
 *   There is a helper method that encapsulates this 
46
 *   (Ipv4GlobalRoutingHelper::RecomputeRoutingTables())
43
 * 
47
 * 
44
 * \section api API and Usage
48
 * \section api API and Usage
45
 * 
49
 * 
46
 * Users must include ns3/global-route-manager.h header file.  After the
50
 * Users must include ns3/global-route-manager.h header file.  After the
47
 * IPv4 topology has been built and addresses assigned, users call
51
 * IPv4 topology has been built and addresses assigned, users call
48
 * ns3::GlobalRouteManager::PopulateRoutingTables (), prior to the 
52
 * ns3::GlobalRouteManager::PopulateRoutingTables (), prior to the 
49
 * ns3::Simulator::Run() call.  There are no other attributes or
53
 * ns3::Simulator::Run() call.  
50
 * public methods that are typically called, or ways to parameterize
54
 *
51
 * the behavior.
55
 * There are two attributes of Ipv4GlobalRouting that govern behavior.
56
 * - Ipv4GlobalRouting::RandomEcmpRouting
57
 * - Ipv4GlobalRouting::RespondToInterfaceEvents  
52
 *
58
 *
53
 * \section impl Implementation
59
 * \section impl Implementation
54
 *
60
 *
(-)a/src/routing/global-routing/ipv4-global-routing.cc (-5 / +49 lines)
 Lines 17-22    Link Here 
17
//
17
//
18
18
19
#include "ns3/log.h"
19
#include "ns3/log.h"
20
#include "ns3/simulator.h"
20
#include "ns3/object.h"
21
#include "ns3/object.h"
21
#include "ns3/packet.h"
22
#include "ns3/packet.h"
22
#include "ns3/net-device.h"
23
#include "ns3/net-device.h"
 Lines 24-29    Link Here 
24
#include "ns3/ipv4-routing-table-entry.h"
25
#include "ns3/ipv4-routing-table-entry.h"
25
#include "ns3/boolean.h"
26
#include "ns3/boolean.h"
26
#include "ipv4-global-routing.h"
27
#include "ipv4-global-routing.h"
28
#include "global-route-manager.h"
27
#include <vector>
29
#include <vector>
28
30
29
NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
31
NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
 Lines 42-53    Link Here 
42
                   BooleanValue(false),
44
                   BooleanValue(false),
43
                   MakeBooleanAccessor (&Ipv4GlobalRouting::m_randomEcmpRouting),
45
                   MakeBooleanAccessor (&Ipv4GlobalRouting::m_randomEcmpRouting),
44
                   MakeBooleanChecker ())
46
                   MakeBooleanChecker ())
47
    .AddAttribute ("RespondToInterfaceEvents",
48
                   "Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)",
49
                   BooleanValue(false),
50
                   MakeBooleanAccessor (&Ipv4GlobalRouting::m_respondToInterfaceEvents),
51
                   MakeBooleanChecker ())
45
    ;
52
    ;
46
  return tid;
53
  return tid;
47
}
54
}
48
55
49
Ipv4GlobalRouting::Ipv4GlobalRouting () 
56
Ipv4GlobalRouting::Ipv4GlobalRouting () 
50
: m_randomEcmpRouting (false) 
57
: m_randomEcmpRouting (false),
58
  m_respondToInterfaceEvents (false) 
51
{
59
{
52
  NS_LOG_FUNCTION_NOARGS ();
60
  NS_LOG_FUNCTION_NOARGS ();
53
}
61
}
 Lines 486-501    Link Here 
486
}
494
}
487
void 
495
void 
488
Ipv4GlobalRouting::NotifyInterfaceUp (uint32_t i)
496
Ipv4GlobalRouting::NotifyInterfaceUp (uint32_t i)
489
{}
497
{
498
  NS_LOG_FUNCTION (this << i);
499
  if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0)  // avoid startup events
500
    {
501
      GlobalRouteManager::DeleteGlobalRoutes ();
502
      GlobalRouteManager::BuildGlobalRoutingDatabase ();
503
      GlobalRouteManager::InitializeRoutes ();
504
    }
505
}
506
490
void 
507
void 
491
Ipv4GlobalRouting::NotifyInterfaceDown (uint32_t i)
508
Ipv4GlobalRouting::NotifyInterfaceDown (uint32_t i)
492
{}
509
{
510
  NS_LOG_FUNCTION (this << i);
511
  if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0)  // avoid startup events
512
    {
513
      GlobalRouteManager::DeleteGlobalRoutes ();
514
      GlobalRouteManager::BuildGlobalRoutingDatabase ();
515
      GlobalRouteManager::InitializeRoutes ();
516
    }
517
}
518
493
void 
519
void 
494
Ipv4GlobalRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
520
Ipv4GlobalRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
495
{}
521
{
522
  NS_LOG_FUNCTION (this << interface << address);
523
  if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0)  // avoid startup events
524
    {
525
      GlobalRouteManager::DeleteGlobalRoutes ();
526
      GlobalRouteManager::BuildGlobalRoutingDatabase ();
527
      GlobalRouteManager::InitializeRoutes ();
528
    }
529
}
530
496
void 
531
void 
497
Ipv4GlobalRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
532
Ipv4GlobalRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
498
{}
533
{
534
  NS_LOG_FUNCTION (this << interface << address);
535
  if (m_respondToInterfaceEvents && Simulator::Now ().GetSeconds () > 0)  // avoid startup events
536
    {
537
      GlobalRouteManager::DeleteGlobalRoutes ();
538
      GlobalRouteManager::BuildGlobalRoutingDatabase ();
539
      GlobalRouteManager::InitializeRoutes ();
540
    }
541
}
542
499
void 
543
void 
500
Ipv4GlobalRouting::SetIpv4 (Ptr<Ipv4> ipv4)
544
Ipv4GlobalRouting::SetIpv4 (Ptr<Ipv4> ipv4)
501
{
545
{
(-)a/src/routing/global-routing/ipv4-global-routing.h (+3 lines)
 Lines 81-86    Link Here 
81
  Ipv4GlobalRouting ();
81
  Ipv4GlobalRouting ();
82
  virtual ~Ipv4GlobalRouting ();
82
  virtual ~Ipv4GlobalRouting ();
83
83
84
  // These methods inherited from base class
84
  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
85
  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
85
86
86
  virtual bool RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
87
  virtual bool RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
 Lines 215-220    Link Here 
215
private:
216
private:
216
  /// Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently
217
  /// Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently
217
  bool m_randomEcmpRouting;
218
  bool m_randomEcmpRouting;
219
  /// Set to true if this interface should respond to interface events by globallly recomputing routes 
220
  bool m_respondToInterfaceEvents;
218
  /// A uniform random number generator for randomly routing packets among ECMP 
221
  /// A uniform random number generator for randomly routing packets among ECMP 
219
  UniformVariable m_rand;
222
  UniformVariable m_rand;
220
223

Return to bug 702