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

(-)a/src/internet-stack/ipv4-l3-protocol.cc (-3 / +12 lines)
 Lines 522-529   Ipv4L3Protocol::Receive( Ptr<NetDevice> Link Here 
522
      ipv4Interface = *i;
522
      ipv4Interface = *i;
523
      if (ipv4Interface->GetDevice () == device)
523
      if (ipv4Interface->GetDevice () == device)
524
        {
524
        {
525
          m_rxTrace (packet, index);
525
          if (ipv4Interface->IsUp ())
526
          break;
526
            {
527
              m_rxTrace (packet, index);
528
              break;
529
            } 
530
          else
531
            {
532
              NS_LOG_LOGIC ("Dropping received packet-- interface is down");
533
              m_dropTrace (packet);
534
              return;
535
            }
527
        }
536
        }
528
      index++;
537
      index++;
529
    }
538
    }
 Lines 1075-1081   Ipv4L3Protocol::SetDown (uint32_t ifaceI Link Here 
1075
  Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
1084
  Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
1076
  interface->SetDown ();
1085
  interface->SetDown ();
1077
1086
1078
  // Remove all routes that are going through this interface
1087
  // Remove all static routes that are going through this interface
1079
  bool modified = true;
1088
  bool modified = true;
1080
  while (modified)
1089
  while (modified)
1081
    {
1090
    {
(-)a/src/internet-stack/wscript (+2 lines)
 Lines 131-136   def build(bld): Link Here 
131
        'ipv4-interface.cc',
131
        'ipv4-interface.cc',
132
        'ipv4-l3-protocol.cc',
132
        'ipv4-l3-protocol.cc',
133
        'ipv4-static-routing.cc',
133
        'ipv4-static-routing.cc',
134
        'ipv4-global-routing.cc',
134
        'ipv4-end-point.cc',
135
        'ipv4-end-point.cc',
135
        'udp-l4-protocol.cc',
136
        'udp-l4-protocol.cc',
136
        'tcp-l4-protocol.cc',
137
        'tcp-l4-protocol.cc',
 Lines 164-169   def build(bld): Link Here 
164
        'ipv4-interface.h',
165
        'ipv4-interface.h',
165
        'ipv4-l3-protocol.h',
166
        'ipv4-l3-protocol.h',
166
        'ipv4-static-routing.h',
167
        'ipv4-static-routing.h',
168
        'ipv4-global-routing.h',
167
        'icmpv4.h',
169
        'icmpv4.h',
168
        ]
170
        ]
169
171
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-4 / +92 lines)
 Lines 30-35    Link Here 
30
#include "ns3/log.h"
30
#include "ns3/log.h"
31
#include "ns3/node-list.h"
31
#include "ns3/node-list.h"
32
#include "ns3/ipv4.h"
32
#include "ns3/ipv4.h"
33
#include "ns3/ipv4-global-routing.h"
33
#include "global-router-interface.h"
34
#include "global-router-interface.h"
34
#include "global-route-manager-impl.h"
35
#include "global-route-manager-impl.h"
35
#include "candidate-queue.h"
36
#include "candidate-queue.h"
 Lines 349-354   GlobalRouteManagerImpl::DebugUseLsdb (Gl Link Here 
349
  m_lsdb = lsdb;
350
  m_lsdb = lsdb;
350
}
351
}
351
352
353
  void
354
GlobalRouteManagerImpl::DeleteGlobalRoutes ()
355
{
356
  NS_LOG_FUNCTION_NOARGS ();
357
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
358
    {
359
      Ptr<Node> node = *i;
360
      Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
361
      uint32_t j = 0;
362
      uint32_t nRoutes = gr->GetNRoutes ();
363
      NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ());
364
      // Each time we delete route 0, the route index shifts downward
365
      // We can delete all routes if we delete the route numbered 0
366
      // nRoutes times
367
      for (j = 0; j < nRoutes; j++)
368
        {
369
          NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ());
370
          gr->RemoveRoute (0);        
371
        }
372
      NS_LOG_LOGIC ("Deleted " << j << " global routes from node "<< node->GetId ());
373
    }
374
  if (m_lsdb)
375
    {
376
      NS_LOG_LOGIC ("Deleting LSDB, creating new one");
377
      delete m_lsdb;
378
      m_lsdb = new GlobalRouteManagerLSDB ();
379
    }
380
}
381
352
//
382
//
353
// In order to build the routing database, we need at least one of the nodes
383
// In order to build the routing database, we need at least one of the nodes
354
// to participate as a router.  This is a convenience function that makes
384
// to participate as a router.  This is a convenience function that makes
 Lines 362-372   GlobalRouteManagerImpl::SelectRouterNode Link Here 
362
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
392
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
363
    {
393
    {
364
      Ptr<Node> node = *i;
394
      Ptr<Node> node = *i;
365
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
395
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ());
366
        node->GetId ());
367
396
368
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
397
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
369
      node->AggregateObject (globalRouter);
398
      node->AggregateObject (globalRouter);
399
400
      NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
401
      Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
402
      // This is the object that will keep the global routes.  We insert it
403
      // at slightly higher priority than static routing (which is at zero).
404
      // This means that global routes (e.g. host routes) will be consulted
405
      // before static routes
406
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
407
      NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
408
        "GetObject for <Ipv4> interface failed");
409
      // XXX make the below  priority value an attribute
410
      ipv4->AddRoutingProtocol (globalRouting, 3);  
411
      // Locally cache the globalRouting pointer; we'll need it later
412
      // when we add routes
413
      AddGlobalRoutingProtocol (node->GetId (), globalRouting);
370
    }
414
    }
371
}
415
}
372
416
 Lines 382-387   GlobalRouteManagerImpl::SelectRouterNode Link Here 
382
426
383
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
427
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
384
      node->AggregateObject (globalRouter);
428
      node->AggregateObject (globalRouter);
429
430
      NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
431
      Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
432
      // This is the object that will keep the global routes.  We insert it
433
      // at slightly higher priority than static routing (which is at zero).
434
      // This means that global routes (e.g. host routes) will be consulted
435
      // before static routes
436
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
437
      NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
438
        "GetObject for <Ipv4> interface failed");
439
      // XXX make the below  priority value an attribute
440
      ipv4->AddRoutingProtocol (globalRouting, 3);  
441
      // Locally cache the globalRouting pointer; we'll need it later
442
      // when we add routes
443
      AddGlobalRoutingProtocol (node->GetId (), globalRouting);
385
    }
444
    }
386
}
445
}
387
446
 Lines 1289-1294   GlobalRouteManagerImpl::SPFIntraAddRoute Link Here 
1289
// the local side of the point-to-point links found on the node described by
1348
// the local side of the point-to-point links found on the node described by
1290
// the vertex <v>.
1349
// the vertex <v>.
1291
//
1350
//
1351
          NS_LOG_LOGIC (" Node " << node->GetId () <<
1352
             " found " << nLinkRecords << " link records in LSA " << lsa << "with LinkStateId "<< lsa->GetLinkStateId ());
1292
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1353
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1293
            {
1354
            {
1294
//
1355
//
 Lines 1317-1323   GlobalRouteManagerImpl::SPFIntraAddRoute Link Here 
1317
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1378
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1318
// which the packets should be send for forwarding.
1379
// which the packets should be send for forwarding.
1319
//
1380
//
1320
              ipv4->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
1381
              Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
1382
              NS_ASSERT (gr);
1383
              gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
1321
                v->GetOutgoingTypeId ());
1384
                v->GetOutgoingTypeId ());
1322
            }
1385
            }
1323
//
1386
//
 Lines 1399-1405   GlobalRouteManagerImpl::SPFIntraAddTrans Link Here 
1399
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
1462
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
1400
          Ipv4Address tempip = lsa->GetLinkStateId ();
1463
          Ipv4Address tempip = lsa->GetLinkStateId ();
1401
          tempip = tempip.CombineMask (tempmask);
1464
          tempip = tempip.CombineMask (tempmask);
1402
          ipv4->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
1465
          Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
1466
          NS_ASSERT (gr);
1467
          gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
1403
            v->GetOutgoingTypeId ());
1468
            v->GetOutgoingTypeId ());
1404
          NS_LOG_LOGIC ("Node " << node->GetId () <<
1469
          NS_LOG_LOGIC ("Node " << node->GetId () <<
1405
            " add network route to " << tempip <<
1470
            " add network route to " << tempip <<
 Lines 1426-1431   GlobalRouteManagerImpl::SPFVertexAddPare Link Here 
1426
  NS_LOG_FUNCTION (v);
1491
  NS_LOG_FUNCTION (v);
1427
  v->GetParent ()->AddChild (v);
1492
  v->GetParent ()->AddChild (v);
1428
}
1493
}
1494
1495
  void 
1496
GlobalRouteManagerImpl::AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto)
1497
{
1498
  NS_LOG_FUNCTION (nodeId);
1499
  m_routingProtocols.push_back
1500
    (std::pair<uint32_t, Ptr<Ipv4GlobalRouting> > (nodeId, proto));
1501
  m_routingProtocols.sort ();
1502
}
1503
1504
  Ptr<Ipv4GlobalRouting>
1505
GlobalRouteManagerImpl::GetGlobalRoutingProtocol (uint32_t nodeId)
1506
{
1507
  for (Ipv4GlobalRoutingList::const_iterator rprotoIter = m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end (); rprotoIter++)
1508
    {
1509
      if ((*rprotoIter).first == nodeId)
1510
        {
1511
          return (*rprotoIter).second;
1512
        }
1513
    }
1514
  return 0;
1515
}
1516
1429
1517
1430
} // namespace ns3
1518
} // namespace ns3
1431
1519
(-)a/src/routing/global-routing/global-route-manager-impl.h (+17 lines)
 Lines 37-42   const uint32_t SPF_INFINITY = 0xffffffff Link Here 
37
const uint32_t SPF_INFINITY = 0xffffffff;
37
const uint32_t SPF_INFINITY = 0xffffffff;
38
38
39
class CandidateQueue;
39
class CandidateQueue;
40
class Ipv4GlobalRouting;
40
41
41
/**
42
/**
42
 * @brief Vertex used in shortest path first (SPF) computations. See RFC 2328,
43
 * @brief Vertex used in shortest path first (SPF) computations. See RFC 2328,
 Lines 701-706   public: Link Here 
701
  GlobalRouteManagerImpl ();
702
  GlobalRouteManagerImpl ();
702
  virtual ~GlobalRouteManagerImpl ();
703
  virtual ~GlobalRouteManagerImpl ();
703
/**
704
/**
705
 * @brief Delete all static routes on all nodes that have a
706
 * GlobalRouterInterface
707
 *
708
 * TODO:  separate manually assigned static routes from static routes that
709
 * the global routing code injects, and only delete the latter
710
 * @internal
711
 *
712
 */
713
  virtual void DeleteGlobalRoutes ();
714
/**
704
 * @brief Select which nodes in the system are to be router nodes and 
715
 * @brief Select which nodes in the system are to be router nodes and 
705
 * aggregate the appropriate interfaces onto those nodes.
716
 * aggregate the appropriate interfaces onto those nodes.
706
 * @internal
717
 * @internal
 Lines 770-775   private: Link Here 
770
  void SPFIntraAddTransit (SPFVertex* v);
781
  void SPFIntraAddTransit (SPFVertex* v);
771
  uint32_t FindOutgoingTypeId (Ipv4Address a, 
782
  uint32_t FindOutgoingTypeId (Ipv4Address a, 
772
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
783
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
784
785
  // Local cache of the Ipv4GlobalRouting objects, indexed by nodeId
786
  typedef std::list< std::pair< uint32_t, Ptr<Ipv4GlobalRouting> > > Ipv4GlobalRoutingList;
787
  void AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto);
788
  Ptr<Ipv4GlobalRouting> GetGlobalRoutingProtocol (uint32_t nodeId);
789
  Ipv4GlobalRoutingList m_routingProtocols;
773
};
790
};
774
791
775
} // namespace ns3
792
} // namespace ns3
(-)a/src/routing/global-routing/global-route-manager.cc (+15 lines)
 Lines 50-55   GlobalRouteManager::PopulateRoutingTable Link Here 
50
}
50
}
51
51
52
  void
52
  void
53
GlobalRouteManager::RecomputeRoutingTables ()
54
{
55
  DeleteGlobalRoutes ();
56
  BuildGlobalRoutingDatabase ();
57
  InitializeRoutes ();
58
}
59
60
  void
61
GlobalRouteManager::DeleteGlobalRoutes ()
62
{
63
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
64
    DeleteGlobalRoutes ();
65
}
66
67
  void
53
GlobalRouteManager::SelectRouterNodes (void) 
68
GlobalRouteManager::SelectRouterNodes (void) 
54
{
69
{
55
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
70
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
(-)a/src/routing/global-routing/global-route-manager.h (-1 / +31 lines)
 Lines 45-57   public: Link Here 
45
 * the nodes in the simulation.  Makes all nodes in the simulation into
45
 * the nodes in the simulation.  Makes all nodes in the simulation into
46
 * routers.
46
 * routers.
47
 *
47
 *
48
 * All this function does is call  BuildGlobalRoutingDatabase () and
48
 * All this function does is call the three private functions
49
 * SelectRouterNodes (), BuildGlobalRoutingDatabase (), and
49
 * InitializeRoutes ().
50
 * InitializeRoutes ().
50
 *
51
 *
52
 * @see SelectRouterNodes ();
51
 * @see BuildGlobalRoutingDatabase ();
53
 * @see BuildGlobalRoutingDatabase ();
52
 * @see InitializeRoutes ();
54
 * @see InitializeRoutes ();
53
 */
55
 */
54
  static void PopulateRoutingTables ();
56
  static void PopulateRoutingTables ();
57
58
 /**
59
  *@brief Remove all routes that were previously installed in a prior call
60
 * to either PopulateRoutingTables() or RecomputeRoutingTables(), and 
61
 * add a new set of routes.  
62
 * 
63
 * This method does not change the set of nodes
64
 * over which GlobalRouting is being used, but it will dynamically update
65
 * its representation of the global topology before recomputing routes.
66
 * Users must first call PopulateRoutingTables() and then may subsequently
67
 * call RecomputeRoutingTables() at any later time in the simulation.
68
 *
69
 * @see DeleteGlobalRoutes ();
70
 * @see BuildGlobalRoutingDatabase ();
71
 * @see InitializeRoutes ();
72
 */
73
 static void RecomputeRoutingTables ();
55
74
56
/**
75
/**
57
 * @brief Build a routing database and initialize the routing tables of
76
 * @brief Build a routing database and initialize the routing tables of
 Lines 72-77   public: Link Here 
72
  static uint32_t AllocateRouterId ();
91
  static uint32_t AllocateRouterId ();
73
92
74
private:
93
private:
94
95
/**
96
 * @brief Delete all static routes on all nodes that have a 
97
 * GlobalRouterInterface
98
 *
99
 * TODO:  separate manually assigned static routes from static routes that
100
 * the global routing code injects, and only delete the latter
101
 * @internal
102
 */
103
  static void DeleteGlobalRoutes ();
104
75
/**
105
/**
76
 * @brief Select which nodes in the system are to be router nodes and 
106
 * @brief Select which nodes in the system are to be router nodes and 
77
 * aggregate the appropriate interfaces onto those nodes.
107
 * aggregate the appropriate interfaces onto those nodes.
(-)a/src/routing/global-routing/global-router-interface.cc (-5 / +28 lines)
 Lines 513-519   GlobalRouter::ClearLSAs () Link Here 
513
513
514
      *i = 0;
514
      *i = 0;
515
    }
515
    }
516
  NS_LOG_LOGIC ("Clear list");
516
  NS_LOG_LOGIC ("Clear list of LSAs");
517
  m_LSAs.clear();
517
  m_LSAs.clear();
518
}
518
}
519
519
 Lines 599-607   GlobalRouter::DiscoverLSAs (void) Link Here 
599
      // IP addresses in routing.
599
      // IP addresses in routing.
600
      //
600
      //
601
      bool isIp = false;
601
      bool isIp = false;
602
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
602
      for (uint32_t j = 0; j < ipv4Local->GetNInterfaces (); ++j )
603
        {
603
        {
604
          if (ipv4Local->GetNetDevice (i) == ndLocal) 
604
          if (ipv4Local->GetNetDevice (j) == ndLocal && ipv4Local->IsUp (j)) 
605
            {
605
            {
606
              isIp = true;
606
              isIp = true;
607
              break;
607
              break;
 Lines 1007-1012   GlobalRouter::ProcessPointToPointLink (P Link Here 
1007
  rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
1007
  rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
1008
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1008
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1009
1009
1010
  if (!ipv4Remote->IsUp (ifIndexRemote))
1011
    {
1012
      NS_LOG_LOGIC ("Remote side interface " << ifIndexRemote << " not up");
1013
      return;
1014
    }
1015
 
1010
  //
1016
  //
1011
  // Now that we have the Ipv4 interface, we can get the (remote) address and
1017
  // Now that we have the Ipv4 interface, we can get the (remote) address and
1012
  // mask we need.
1018
  // mask we need.
 Lines 1108-1115   GlobalRouter::BuildNetworkLSAs (NetDevic Link Here 
1108
            {
1114
            {
1109
              Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
1115
              Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
1110
              NS_ASSERT (tempIpv4);
1116
              NS_ASSERT (tempIpv4);
1111
              Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
1117
              if (!tempIpv4->IsUp (tempIfIndex))
1112
              pLSA->AddAttachedRouter (tempAddr);
1118
                {
1119
                  NS_LOG_LOGIC ("Remote side interface " << tempIfIndex << " not up");
1120
                }
1121
              else 
1122
                {
1123
                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
1124
                  pLSA->AddAttachedRouter (tempAddr);
1125
                }
1113
            }
1126
            }
1114
        }
1127
        }
1115
      m_LSAs.push_back (pLSA);
1128
      m_LSAs.push_back (pLSA);
 Lines 1180-1185   GlobalRouter::FindDesignatedRouterForLin Link Here 
1180
              if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
1193
              if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
1181
                {
1194
                {
1182
                  NS_LOG_LOGIC ("Found router on bridge net device " << bnd);
1195
                  NS_LOG_LOGIC ("Found router on bridge net device " << bnd);
1196
                  if (!ipv4->IsUp (ifIndexOther))
1197
                    {
1198
                      NS_LOG_LOGIC ("Remote side interface " << ifIndexOther << " not up");
1199
                      continue;
1200
                    }
1183
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1201
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1184
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1202
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1185
                  NS_LOG_LOGIC ("designated router now " << desigRtr);
1203
                  NS_LOG_LOGIC ("designated router now " << desigRtr);
 Lines 1223-1228   GlobalRouter::FindDesignatedRouterForLin Link Here 
1223
              uint32_t ifIndexOther;
1241
              uint32_t ifIndexOther;
1224
              if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
1242
              if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
1225
                {
1243
                {
1244
                  if (!ipv4->IsUp (ifIndexOther))
1245
                    {
1246
                      NS_LOG_LOGIC ("Remote side interface " << ifIndexOther << " not up");
1247
                      continue;
1248
                    }
1226
                  NS_LOG_LOGIC ("Found router on net device " << ndOther);
1249
                  NS_LOG_LOGIC ("Found router on net device " << ndOther);
1227
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1250
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1228
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1251
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-7 / +171 lines)
 Lines 53-59   SPFVertex::SPFVertex () : Link Here 
53
  m_rootOif (SPF_INFINITY),
53
  m_rootOif (SPF_INFINITY),
54
  m_nextHop ("0.0.0.0"),
54
  m_nextHop ("0.0.0.0"),
55
  m_parent (0),
55
  m_parent (0),
56
  m_children ()
56
  m_children (),
57
  m_vertexProcessed (false)
57
{
58
{
58
  NS_LOG_FUNCTION_NOARGS ();
59
  NS_LOG_FUNCTION_NOARGS ();
59
}
60
}
 Lines 65-71   SPFVertex::SPFVertex (GlobalRoutingLSA* Link Here 
65
  m_rootOif (SPF_INFINITY),
66
  m_rootOif (SPF_INFINITY),
66
  m_nextHop ("0.0.0.0"),
67
  m_nextHop ("0.0.0.0"),
67
  m_parent (0),
68
  m_parent (0),
68
  m_children ()
69
  m_children (),
70
  m_vertexProcessed (false)
69
{
71
{
70
  NS_LOG_FUNCTION_NOARGS ();
72
  NS_LOG_FUNCTION_NOARGS ();
71
  if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) 
73
  if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) 
 Lines 226-231   SPFVertex::AddChild (SPFVertex* child) Link Here 
226
  m_children.push_back (child);
228
  m_children.push_back (child);
227
  return m_children.size ();
229
  return m_children.size ();
228
}
230
}
231
232
void 
233
SPFVertex::SetVertexProcessed (bool value)
234
{
235
  m_vertexProcessed = value;
236
}
237
238
bool 
239
SPFVertex::IsVertexProcessed (void) const
240
{
241
  return m_vertexProcessed;
242
}
243
229
244
230
// ---------------------------------------------------------------------------
245
// ---------------------------------------------------------------------------
231
//
246
//
 Lines 1174-1184   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1174
//
1189
//
1175
// Iterate the algorithm by returning to Step 2 until there are no more
1190
// Iterate the algorithm by returning to Step 2 until there are no more
1176
// candidate vertices.
1191
// candidate vertices.
1177
//
1192
1178
    }
1193
    }  // end for loop
1179
//
1194
1180
// Second stage of SPF calculation procedure's  
1195
// Second stage of SPF calculation procedure  
1181
// NOTYET:  ospf_spf_process_stubs (area, area->spf, new_table);
1196
  SPFProcessStubs (m_spfroot);
1182
//
1197
//
1183
// We're all done setting the routing information for the node at the root of
1198
// We're all done setting the routing information for the node at the root of
1184
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
1199
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
 Lines 1186-1191   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1186
//
1201
//
1187
  delete m_spfroot;
1202
  delete m_spfroot;
1188
  m_spfroot = 0;
1203
  m_spfroot = 0;
1204
}
1205
1206
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
1207
// stub link records will exist for point-to-point interfaces and for
1208
// broadcast interfaces for which no neighboring router can be found
1209
void
1210
GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v)
1211
{
1212
  NS_LOG_FUNCTION_NOARGS ();
1213
  NS_LOG_LOGIC ("Processing stubs for " << v->GetVertexId ());
1214
  if (v->GetVertexType () == SPFVertex::VertexRouter)
1215
    {
1216
      GlobalRoutingLSA *rlsa = v->GetLSA ();
1217
      NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ());
1218
      for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++)
1219
        {
1220
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
1221
            v->GetVertexId () << "'s " <<
1222
            v->GetLSA ()->GetNLinkRecords () << " link records");
1223
          GlobalRoutingLinkRecord *l = v->GetLSA ()->GetLinkRecord (i);
1224
          if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
1225
            {
1226
              NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
1227
              SPFIntraAddStub (l, v);
1228
              continue;
1229
            }
1230
        }
1231
    }
1232
    for (uint32_t i = 0; i < v->GetNChildren (); i++)
1233
      {
1234
        if (!v->GetChild (i)->IsVertexProcessed ())
1235
          {
1236
            SPFProcessStubs (v->GetChild (i));
1237
            v->GetChild (i)->SetVertexProcessed (true);
1238
          }
1239
      }
1240
}
1241
1242
// RFC2328 16.1. second stage. 
1243
void
1244
GlobalRouteManagerImpl::SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v)
1245
{
1246
  NS_LOG_FUNCTION_NOARGS ();
1247
1248
  NS_ASSERT_MSG (m_spfroot, 
1249
    "GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set");
1250
1251
  // XXX simplifed logic for the moment.  There are two cases to consider:
1252
  // 1) the stub network is on this router; do nothing for now
1253
  //    (already handled above)
1254
  // 2) the stub network is on a remote router, so I should use the
1255
  // same next hop that I use to get to vertex v
1256
  if (v->GetVertexId () == m_spfroot->GetVertexId ())
1257
    {
1258
      NS_LOG_LOGIC ("Stub is on local host: " << v->GetVertexId () << "; returning");
1259
      return;
1260
    }
1261
      NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing");
1262
//
1263
// The root of the Shortest Path First tree is the router to which we are 
1264
// going to write the actual routing table entries.  The vertex corresponding
1265
// to this router has a vertex ID which is the router ID of that node.  We're
1266
// going to use this ID to discover which node it is that we're actually going
1267
// to update.
1268
//
1269
  Ipv4Address routerId = m_spfroot->GetVertexId ();
1270
1271
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1272
//
1273
// We need to walk the list of nodes looking for the one that has the router
1274
// ID corresponding to the root vertex.  This is the one we're going to write
1275
// the routing information to.
1276
//
1277
  NodeList::Iterator i = NodeList::Begin (); 
1278
  for (; i != NodeList::End (); i++)
1279
    {
1280
      Ptr<Node> node = *i;
1281
//
1282
// The router ID is accessible through the GlobalRouter interface, so we need
1283
// to QI for that interface.  If there's no GlobalRouter interface, the node
1284
// in question cannot be the router we want, so we continue.
1285
// 
1286
      Ptr<GlobalRouter> rtr = 
1287
        node->GetObject<GlobalRouter> ();
1288
1289
      if (rtr == 0)
1290
        {
1291
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
1292
            node->GetId ());
1293
          continue;
1294
        }
1295
//
1296
// If the router ID of the current node is equal to the router ID of the 
1297
// root of the SPF tree, then this node is the one for which we need to 
1298
// write the routing tables.
1299
//
1300
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1301
1302
      if (rtr->GetRouterId () == routerId)
1303
        {
1304
          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
1305
//
1306
// Routing information is updated using the Ipv4 interface.  We need to QI
1307
// for that interface.  If the node is acting as an IP version 4 router, it
1308
// should absolutely have an Ipv4 interface.
1309
//
1310
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1311
          NS_ASSERT_MSG (ipv4, 
1312
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
1313
            "QI for <Ipv4> interface failed");
1314
//
1315
// Get the Global Router Link State Advertisement from the vertex we're
1316
// adding the routes to.  The LSA will have a number of attached Global Router
1317
// Link Records corresponding to links off of that vertex / node.  We're going
1318
// to be interested in the records corresponding to point-to-point links.
1319
//
1320
          GlobalRoutingLSA *lsa = v->GetLSA ();
1321
          NS_ASSERT_MSG (lsa, 
1322
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
1323
            "Expected valid LSA in SPFVertex* v");
1324
          //Address tempaddr = Address (l->GetLinkData);
1325
          Ipv4Mask tempmask ("255.255.255.0");
1326
          Ipv4Address tempip = l->GetLinkId ();
1327
          tempip = tempip.CombineMask (tempmask);
1328
1329
          NS_LOG_LOGIC (" Node " << node->GetId () <<
1330
            " add route to " << tempip <<
1331
            " with mask " << tempmask <<
1332
            " using next hop " << v->GetNextHop () <<
1333
            " via interface " << v->GetOutgoingTypeId ());
1334
//
1335
// Here's why we did all of that work.  We're going to add a host route to the
1336
// host address found in the m_linkData field of the point-to-point link
1337
// record.  In the case of a point-to-point link, this is the local IP address
1338
// of the node connected to the link.  Each of these point-to-point links
1339
// will correspond to a local interface that has an IP address to which
1340
// the node at the root of the SPF tree can send packets.  The vertex <v> 
1341
// (corresponding to the node that has these links and interfaces) has 
1342
// an m_nextHop address precalculated for us that is the address to which the
1343
// root node should send packets to be forwarded to these IP addresses.
1344
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1345
// which the packets should be send for forwarding.
1346
//
1347
          Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
1348
          NS_ASSERT (gr);
1349
          gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingTypeId ());
1350
          return;
1351
        } // if
1352
    } // for
1189
}
1353
}
1190
1354
1191
//
1355
//
(-)a/src/routing/global-routing/global-route-manager-impl.h (+20 lines)
 Lines 547-552   public: Link Here 
547
 */
547
 */
548
  uint32_t AddChild (SPFVertex* child);
548
  uint32_t AddChild (SPFVertex* child);
549
549
550
  /**
551
   * @brief Set the value of the VertexProcessed flag
552
   *
553
   * Flag to note whether vertex has been processed in stage two of 
554
   * SPF computation
555
   * @param value boolean value to set the flag
556
   */ 
557
  void SetVertexProcessed (bool value);
558
559
  /**
560
   * @brief Check the value of the VertexProcessed flag
561
   *
562
   * Flag to note whether vertex has been processed in stage two of 
563
   * SPF computation
564
   * @returns value of underlying flag
565
   */ 
566
  bool IsVertexProcessed (void) const;
550
private:
567
private:
551
  VertexType m_vertexType;
568
  VertexType m_vertexType;
552
  Ipv4Address m_vertexId;
569
  Ipv4Address m_vertexId;
 Lines 557-562   private: Link Here 
557
  SPFVertex* m_parent;
574
  SPFVertex* m_parent;
558
  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
575
  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
559
  ListOfSPFVertex_t m_children;
576
  ListOfSPFVertex_t m_children;
577
  bool m_vertexProcessed; 
560
578
561
/**
579
/**
562
 * @brief The SPFVertex copy construction is disallowed.  There's no need for
580
 * @brief The SPFVertex copy construction is disallowed.  There's no need for
 Lines 771-776   private: Link Here 
771
  SPFVertex* m_spfroot;
789
  SPFVertex* m_spfroot;
772
  GlobalRouteManagerLSDB* m_lsdb;
790
  GlobalRouteManagerLSDB* m_lsdb;
773
  void SPFCalculate (Ipv4Address root);
791
  void SPFCalculate (Ipv4Address root);
792
  void SPFProcessStubs (SPFVertex* v);
774
  void SPFNext (SPFVertex*, CandidateQueue&);
793
  void SPFNext (SPFVertex*, CandidateQueue&);
775
  int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, 
794
  int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, 
776
    GlobalRoutingLinkRecord* l, uint32_t distance);
795
    GlobalRoutingLinkRecord* l, uint32_t distance);
 Lines 779-784   private: Link Here 
779
    GlobalRoutingLinkRecord* prev_link);
798
    GlobalRoutingLinkRecord* prev_link);
780
  void SPFIntraAddRouter (SPFVertex* v);
799
  void SPFIntraAddRouter (SPFVertex* v);
781
  void SPFIntraAddTransit (SPFVertex* v);
800
  void SPFIntraAddTransit (SPFVertex* v);
801
  void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v);
782
  uint32_t FindOutgoingTypeId (Ipv4Address a, 
802
  uint32_t FindOutgoingTypeId (Ipv4Address a, 
783
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
803
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
784
804
(-)a/src/routing/global-routing/global-route-manager.h (-24 / +23 lines)
 Lines 45-51   public: Link Here 
45
 * the nodes in the simulation.  Makes all nodes in the simulation into
45
 * the nodes in the simulation.  Makes all nodes in the simulation into
46
 * routers.
46
 * routers.
47
 *
47
 *
48
 * All this function does is call the three private functions
48
 * All this function does is call the three functions
49
 * SelectRouterNodes (), BuildGlobalRoutingDatabase (), and
49
 * SelectRouterNodes (), BuildGlobalRoutingDatabase (), and
50
 * InitializeRoutes ().
50
 * InitializeRoutes ().
51
 *
51
 *
 Lines 54-59   public: Link Here 
54
 * @see InitializeRoutes ();
54
 * @see InitializeRoutes ();
55
 */
55
 */
56
  static void PopulateRoutingTables ();
56
  static void PopulateRoutingTables ();
57
58
/**
59
 * @brief Build a routing database and initialize the routing tables of
60
 * the nodes in the simulation.  Makes the nodes in the provided container
61
 * into routers.
62
 *
63
 * All this function does is call the three functions
64
 * SelectRouterNodes (), BuildGlobalRoutingDatabase (), and
65
 * InitializeRoutes ().
66
 *
67
 * @see SelectRouterNodes (Node Container c);
68
 * @see BuildGlobalRoutingDatabase ();
69
 * @see InitializeRoutes ();
70
 */
71
  static void PopulateRoutingTables (NodeContainer c);
57
72
58
 /**
73
 /**
59
  *@brief Remove all routes that were previously installed in a prior call
74
  *@brief Remove all routes that were previously installed in a prior call
 Lines 73-104   public: Link Here 
73
 static void RecomputeRoutingTables ();
88
 static void RecomputeRoutingTables ();
74
89
75
/**
90
/**
76
 * @brief Build a routing database and initialize the routing tables of
77
 * the nodes in the simulation.  Makes the nodes in the provided container
78
 * into routers.
79
 *
80
 * All this function does is call  BuildGlobalRoutingDatabase () and
81
 * InitializeRoutes ().
82
 *
83
 * @see BuildGlobalRoutingDatabase ();
84
 * @see InitializeRoutes ();
85
 */
86
  static void PopulateRoutingTables (NodeContainer c);
87
88
/**
89
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
90
 */
91
  static uint32_t AllocateRouterId ();
92
93
private:
94
95
/**
96
 * @brief Delete all static routes on all nodes that have a 
91
 * @brief Delete all static routes on all nodes that have a 
97
 * GlobalRouterInterface
92
 * GlobalRouterInterface
98
 *
93
 *
99
 * TODO:  separate manually assigned static routes from static routes that
100
 * the global routing code injects, and only delete the latter
101
 * @internal
102
 */
94
 */
103
  static void DeleteGlobalRoutes ();
95
  static void DeleteGlobalRoutes ();
104
96
 Lines 117-122   private: Link Here 
117
 *
109
 *
118
 */
110
 */
119
  static void SelectRouterNodes (NodeContainer c);
111
  static void SelectRouterNodes (NodeContainer c);
112
113
/**
114
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
115
 */
116
  static uint32_t AllocateRouterId ();
117
118
private:
120
119
121
/**
120
/**
122
 * @brief Build the routing database by gathering Link State Advertisements
121
 * @brief Build the routing database by gathering Link State Advertisements
(-)a/src/routing/global-routing/global-router-interface.cc (-19 / +27 lines)
 Lines 413-435   GlobalRoutingLSA::Print (std::ostream &o Link Here 
413
413
414
          os << "---------- RouterLSA Link Record ----------" << std::endl;
414
          os << "---------- RouterLSA Link Record ----------" << std::endl;
415
          os << "m_linkType = " << p->m_linkType;
415
          os << "m_linkType = " << p->m_linkType;
416
          if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork)
416
          if (p->m_linkType == GlobalRoutingLinkRecord::PointToPoint)
417
            {
418
              os << " (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
419
              os << "m_linkId = " << p->m_linkId << std::endl;
420
              os << "m_linkData = " << p->m_linkData << std::endl;
421
              os << "m_metric = " << p->m_metric << std::endl;
422
            }
423
          else if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork)
417
            {
424
            {
418
              os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
425
              os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
419
              os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl;
426
              os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl;
420
              os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl;
427
              os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl;
421
              os << "m_metric = " << p->m_metric << std::endl;
428
              os << "m_metric = " << p->m_metric << std::endl;
422
            }
429
            }
423
          else if (p->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
430
          else if (p->m_linkType == GlobalRoutingLinkRecord::StubNetwork)
424
            {
431
            {
425
              os << "(GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
432
              os << " (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
426
              os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl;
433
              os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl;
427
              os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl;
434
              os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl;
428
              os << "m_metric = " << p->m_metric << std::endl;
435
              os << "m_metric = " << p->m_metric << std::endl;
429
            }
436
            }
430
          else
437
          else
431
            {
438
            {
432
              os << "(Unknown LinkType)" << std::endl;
439
              os << " (Unknown LinkType)" << std::endl;
433
              os << "m_linkId = " << p->m_linkId << std::endl;
440
              os << "m_linkId = " << p->m_linkId << std::endl;
434
              os << "m_linkData = " << p->m_linkData << std::endl;
441
              os << "m_linkData = " << p->m_linkData << std::endl;
435
              os << "m_metric = " << p->m_metric << std::endl;
442
              os << "m_metric = " << p->m_metric << std::endl;
 Lines 621-627   GlobalRouter::DiscoverLSAs (void) Link Here 
621
      // the segment.  We add the appropriate link record to the LSA.
628
      // the segment.  We add the appropriate link record to the LSA.
622
      //
629
      //
623
      // If the device is a point to point link, we treat it separately.  In
630
      // If the device is a point to point link, we treat it separately.  In
624
      // that case, there always two link records added.
631
      // that case, there may be one or two link records added.
625
      //
632
      //
626
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
633
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
627
        {
634
        {
 Lines 1007-1018   GlobalRouter::ProcessPointToPointLink (P Link Here 
1007
  rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
1014
  rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
1008
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1015
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1009
1016
1010
  if (!ipv4Remote->IsUp (ifIndexRemote))
1011
    {
1012
      NS_LOG_LOGIC ("Remote side interface " << ifIndexRemote << " not up");
1013
      return;
1014
    }
1015
 
1016
  //
1017
  //
1017
  // Now that we have the Ipv4 interface, we can get the (remote) address and
1018
  // Now that we have the Ipv4 interface, we can get the (remote) address and
1018
  // mask we need.
1019
  // mask we need.
 Lines 1026-1040   GlobalRouter::ProcessPointToPointLink (P Link Here 
1026
  // link records; the first is a point-to-point record describing the link and
1027
  // link records; the first is a point-to-point record describing the link and
1027
  // the second is a stub network record with the network number.
1028
  // the second is a stub network record with the network number.
1028
  //
1029
  //
1029
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
1030
  GlobalRoutingLinkRecord *plr;
1030
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1031
  if (ipv4Remote->IsUp (ifIndexRemote))
1031
  plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
1032
    {
1032
  plr->SetLinkId (rtrIdRemote);
1033
      NS_LOG_LOGIC ("Remote side interface " << ifIndexRemote << " is up-- add a type 1 link");
1033
  plr->SetLinkData (addrLocal);
1034
 
1034
  plr->SetMetric (metricLocal);
1035
      plr  = new GlobalRoutingLinkRecord;
1035
  pLSA->AddLinkRecord (plr);
1036
      NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1036
  plr = 0;
1037
      plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
1038
      plr->SetLinkId (rtrIdRemote);
1039
      plr->SetLinkData (addrLocal);
1040
      plr->SetMetric (metricLocal);
1041
      pLSA->AddLinkRecord (plr);
1042
      plr = 0;
1043
    }
1037
1044
1045
  // Regardless of state of peer, add a type 3 link (RFC 2328: 12.4.1.1)
1038
  plr = new GlobalRoutingLinkRecord;
1046
  plr = new GlobalRoutingLinkRecord;
1039
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1047
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1040
  plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
1048
  plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);

Return to bug 406