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

(-)a/src/routing/global-routing/global-route-manager-impl.cc (-3 / +202 lines)
 Lines 243-248   SPFVertex::IsVertexProcessed (void) cons Link Here 
243
  return m_vertexProcessed;
243
  return m_vertexProcessed;
244
}
244
}
245
245
246
void
247
SPFVertex::ClearVertexProcessed (void)
248
{
249
  for (uint32_t i = 0; i < this->GetNChildren (); i++)
250
  {
251
    this->GetChild (i)->ClearVertexProcessed ();
252
  }
253
  this->SetVertexProcessed (false);
254
}
246
255
247
// ---------------------------------------------------------------------------
256
// ---------------------------------------------------------------------------
248
//
257
//
 Lines 252-258   SPFVertex::IsVertexProcessed (void) cons Link Here 
252
261
253
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()
262
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()
254
:
263
:
255
  m_database ()
264
  m_database (),
265
  m_extdatabase ()
256
{
266
{
257
  NS_LOG_FUNCTION_NOARGS ();
267
  NS_LOG_FUNCTION_NOARGS ();
258
}
268
}
 Lines 265-270   GlobalRouteManagerLSDB::~GlobalRouteMana Link Here 
265
    {
275
    {
266
      NS_LOG_LOGIC ("free LSA");
276
      NS_LOG_LOGIC ("free LSA");
267
      GlobalRoutingLSA* temp = i->second;
277
      GlobalRoutingLSA* temp = i->second;
278
      delete temp;
279
    }
280
  for (uint32_t j=0; j<m_extdatabase.size (); j++)
281
    {
282
      NS_LOG_LOGIC ("free ASexternalLSA");
283
      GlobalRoutingLSA* temp = m_extdatabase.at (j);
268
      delete temp;
284
      delete temp;
269
    }
285
    }
270
  NS_LOG_LOGIC ("clear map");
286
  NS_LOG_LOGIC ("clear map");
 Lines 287-293   GlobalRouteManagerLSDB::Insert (Ipv4Addr Link Here 
287
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
303
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
288
{
304
{
289
  NS_LOG_FUNCTION (addr << lsa);
305
  NS_LOG_FUNCTION (addr << lsa);
290
  m_database.insert (LSDBPair_t (addr, lsa));
306
  if (lsa->GetLSType() == GlobalRoutingLSA::ASExternalLSAs) {
307
    m_extdatabase.push_back (lsa);
308
  } else
309
  {
310
    m_database.insert (LSDBPair_t (addr, lsa));
311
  }
312
}
313
314
  GlobalRoutingLSA*
315
GlobalRouteManagerLSDB::GetExtLSA (uint32_t index) const
316
{
317
  return m_extdatabase.at (index);
318
}
319
320
  uint32_t
321
GlobalRouteManagerLSDB::GetNumExtLSAs () const
322
{
323
  return m_extdatabase.size  ();
291
}
324
}
292
325
293
  GlobalRoutingLSA*
326
  GlobalRoutingLSA*
 Lines 438-443   GlobalRouteManagerImpl::BuildGlobalRouti Link Here 
438
// DiscoverLSAs () will get zero as the number since no routes have been 
471
// DiscoverLSAs () will get zero as the number since no routes have been 
439
// found.
472
// found.
440
//
473
//
474
      Ptr<Ipv4GlobalRouting> grouting = rtr->GetRoutingProtocol ();
441
      uint32_t numLSAs = rtr->DiscoverLSAs ();
475
      uint32_t numLSAs = rtr->DiscoverLSAs ();
442
      NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
476
      NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
443
477
 Lines 824-830   GlobalRouteManagerImpl::SPFNexthopCalcul Link Here 
824
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
858
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
825
            " with distance " << distance);
859
            " with distance " << distance);
826
        }  // end W is a router vertes
860
        }  // end W is a router vertes
827
      else 
861
      else
828
        {
862
        {
829
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork);
863
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork);
830
// W is a directly connected network; no next hop is required
864
// W is a directly connected network; no next hop is required
 Lines 1237-1242   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1237
1271
1238
// Second stage of SPF calculation procedure  
1272
// Second stage of SPF calculation procedure  
1239
  SPFProcessStubs (m_spfroot);
1273
  SPFProcessStubs (m_spfroot);
1274
  for (uint32_t i = 0;i<m_lsdb->GetNumExtLSAs ();i++)
1275
  {
1276
    m_spfroot->ClearVertexProcessed ();
1277
    GlobalRoutingLSA *extlsa = m_lsdb->GetExtLSA (i);
1278
    NS_LOG_LOGIC ("Processing External LSA with id " << extlsa->GetLinkStateId ());
1279
    ProcessASExternals (m_spfroot, extlsa);
1280
  }
1281
1240
//
1282
//
1241
// We're all done setting the routing information for the node at the root of
1283
// We're all done setting the routing information for the node at the root of
1242
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
1284
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
 Lines 1245-1250   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1245
  delete m_spfroot;
1287
  delete m_spfroot;
1246
  m_spfroot = 0;
1288
  m_spfroot = 0;
1247
}
1289
}
1290
1291
void
1292
GlobalRouteManagerImpl::ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa)
1293
{
1294
  NS_LOG_FUNCTION_NOARGS ();
1295
  NS_LOG_LOGIC ("Processing external for destination " << 
1296
      extlsa->GetLinkStateId () <<
1297
      ", for router "  << v->GetVertexId () << 
1298
      ", advertised by " << extlsa->GetAdvertisingRouter ());
1299
  if (v->GetVertexType () == SPFVertex::VertexRouter)
1300
  {
1301
    GlobalRoutingLSA *rlsa = v->GetLSA ();
1302
    NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ());
1303
      if ((rlsa->GetLinkStateId ()) == (extlsa->GetAdvertisingRouter ()))
1304
      {
1305
        NS_LOG_LOGIC ("Found advertising router to destination");
1306
        SPFAddASExternal(extlsa,v);
1307
      }
1308
  }
1309
  for (uint32_t i = 0; i < v->GetNChildren (); i++)
1310
  {
1311
    if (!v->GetChild (i)->IsVertexProcessed ())
1312
    {
1313
      NS_LOG_LOGIC ("Vertex's child " << i << " not yet processed, processing...");
1314
      ProcessASExternals (v->GetChild (i), extlsa);
1315
      v->GetChild (i)->SetVertexProcessed (true);
1316
    }
1317
  }
1318
}
1319
1320
//
1321
// Adding external routes to routing table - modeled after
1322
// SPFAddIntraAddStub()
1323
//
1324
1325
void
1326
GlobalRouteManagerImpl::SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v)
1327
{
1328
  NS_LOG_FUNCTION_NOARGS ();
1329
1330
  NS_ASSERT_MSG (m_spfroot, 
1331
                 "GlobalRouteManagerImpl::SPFAddASExternal (): Root pointer not set");
1332
  // Two cases to consider: We are advertising the external ourselves
1333
  // => No need to add anything
1334
  // OR find best path to the advertising router
1335
  if (v->GetVertexId () == m_spfroot->GetVertexId ())
1336
  {
1337
    NS_LOG_LOGIC ("External is on local host: " 
1338
      << v->GetVertexId () << "; returning");
1339
    return;
1340
  }
1341
  NS_LOG_LOGIC ("External is on remote host: " 
1342
    << extlsa->GetAdvertisingRouter () << "; installing");
1343
  
1344
  Ipv4Address routerId = m_spfroot->GetVertexId ();
1345
1346
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1347
  //
1348
// We need to walk the list of nodes looking for the one that has the router
1349
// ID corresponding to the root vertex.  This is the one we're going to write
1350
// the routing information to.
1351
//
1352
  NodeList::Iterator i = NodeList::Begin (); 
1353
  for (; i != NodeList::End (); i++)
1354
  {
1355
    Ptr<Node> node = *i;
1356
//
1357
// The router ID is accessible through the GlobalRouter interface, so we need
1358
// to QI for that interface.  If there's no GlobalRouter interface, the node
1359
// in question cannot be the router we want, so we continue.
1360
// 
1361
    Ptr<GlobalRouter> rtr = 
1362
        node->GetObject<GlobalRouter> ();
1363
1364
    if (rtr == 0)
1365
    {
1366
      NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
1367
          node->GetId ());
1368
      continue;
1369
    }
1370
//
1371
// If the router ID of the current node is equal to the router ID of the 
1372
// root of the SPF tree, then this node is the one for which we need to 
1373
// write the routing tables.
1374
//
1375
    NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1376
1377
    if (rtr->GetRouterId () == routerId)
1378
    {
1379
      NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
1380
//
1381
// Routing information is updated using the Ipv4 interface.  We need to QI
1382
// for that interface.  If the node is acting as an IP version 4 router, it
1383
// should absolutely have an Ipv4 interface.
1384
//
1385
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1386
      NS_ASSERT_MSG (ipv4, 
1387
                     "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
1388
                         "QI for <Ipv4> interface failed");
1389
//
1390
// Get the Global Router Link State Advertisement from the vertex we're
1391
// adding the routes to.  The LSA will have a number of attached Global Router
1392
// Link Records corresponding to links off of that vertex / node.  We're going
1393
// to be interested in the records corresponding to point-to-point links.
1394
//
1395
      NS_ASSERT_MSG (v->GetLSA (), 
1396
                     "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
1397
                         "Expected valid LSA in SPFVertex* v");
1398
      Ipv4Mask tempmask = extlsa->GetNetworkLSANetworkMask();
1399
      Ipv4Address tempip = extlsa->GetLinkStateId ();
1400
      tempip = tempip.CombineMask (tempmask);
1401
1402
      NS_LOG_LOGIC (" Node " << node->GetId () <<
1403
          " add route to " << tempip <<
1404
          " with mask " << tempmask <<
1405
          " using next hop " << v->GetNextHop () <<
1406
          " via interface " << v->GetOutgoingInterfaceId ());
1407
//
1408
// Here's why we did all of that work.  We're going to add a host route to the
1409
// host address found in the m_linkData field of the point-to-point link
1410
// record.  In the case of a point-to-point link, this is the local IP address
1411
// of the node connected to the link.  Each of these point-to-point links
1412
// will correspond to a local interface that has an IP address to which
1413
// the node at the root of the SPF tree can send packets.  The vertex <v> 
1414
// (corresponding to the node that has these links and interfaces) has 
1415
// an m_nextHop address precalculated for us that is the address to which the
1416
// root node should send packets to be forwarded to these IP addresses.
1417
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1418
// which the packets should be send for forwarding.
1419
//
1420
      Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
1421
      if (router == 0)
1422
      {
1423
        continue;
1424
      }
1425
      Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
1426
      NS_ASSERT (gr);
1427
      if (v->GetOutgoingInterfaceId () >= 0)
1428
      {
1429
        gr->AddASExternalRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ());
1430
        NS_LOG_LOGIC ("Node " << node->GetId () <<
1431
            " add network route to " << tempip <<
1432
            " using next hop " << v->GetNextHop () <<
1433
            " via interface " << v->GetOutgoingInterfaceId ());
1434
      }
1435
      else
1436
      {
1437
        NS_LOG_LOGIC ("Node " << node->GetId () <<
1438
            " NOT able to add network route to " << tempip <<
1439
            " using next hop " << v->GetNextHop () <<
1440
            " since outgoing interface id is negative");
1441
      }
1442
      return;
1443
    } // if
1444
  } // for
1445
}
1446
1248
1447
1249
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
1448
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
1250
// stub link records will exist for point-to-point interfaces and for
1449
// stub link records will exist for point-to-point interfaces and for
(-)a/src/routing/global-routing/global-route-manager-impl.h (-1 / +13 lines)
 Lines 26-31    Link Here 
26
#include <list>
26
#include <list>
27
#include <queue>
27
#include <queue>
28
#include <map>
28
#include <map>
29
#include <vector>
29
#include "ns3/object.h"
30
#include "ns3/object.h"
30
#include "ns3/ptr.h"
31
#include "ns3/ptr.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/ipv4-address.h"
 Lines 76-82   public: Link Here 
76
  enum VertexType {
77
  enum VertexType {
77
    VertexUnknown = 0,  /**< Uninitialized Link Record */
78
    VertexUnknown = 0,  /**< Uninitialized Link Record */
78
    VertexRouter,       /**< Vertex representing a router in the topology */
79
    VertexRouter,       /**< Vertex representing a router in the topology */
79
    VertexNetwork       /**< Vertex representing a network in the topology */
80
    VertexNetwork      /**< Vertex representing a network in the topology */
80
  };
81
  };
81
82
82
/**
83
/**
 Lines 563-568   public: Link Here 
563
   * @returns value of underlying flag
564
   * @returns value of underlying flag
564
   */ 
565
   */ 
565
  bool IsVertexProcessed (void) const;
566
  bool IsVertexProcessed (void) const;
567
  
568
  void ClearVertexProcessed (void);
569
      
566
private:
570
private:
567
  VertexType m_vertexType;
571
  VertexType m_vertexType;
568
  Ipv4Address m_vertexId;
572
  Ipv4Address m_vertexId;
 Lines 683-694   public: Link Here 
683
 * @see SPFVertex
687
 * @see SPFVertex
684
 */
688
 */
685
  void Initialize ();
689
  void Initialize ();
690
  
691
  GlobalRoutingLSA* GetExtLSA (uint32_t index) const;
692
  uint32_t GetNumExtLSAs () const;
693
      
686
694
687
private:
695
private:
688
  typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t;
696
  typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t;
689
  typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t;
697
  typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t;
690
698
691
  LSDBMap_t m_database;
699
  LSDBMap_t m_database;
700
  std::vector<GlobalRoutingLSA*> m_extdatabase;
701
  
692
/**
702
/**
693
 * @brief GlobalRouteManagerLSDB copy construction is disallowed.  There's no 
703
 * @brief GlobalRouteManagerLSDB copy construction is disallowed.  There's no 
694
 * need for it and a compiler provided shallow copy would be wrong.
704
 * need for it and a compiler provided shallow copy would be wrong.
 Lines 775-780   private: Link Here 
775
  bool CheckForStubNode (Ipv4Address root);
785
  bool CheckForStubNode (Ipv4Address root);
776
  void SPFCalculate (Ipv4Address root);
786
  void SPFCalculate (Ipv4Address root);
777
  void SPFProcessStubs (SPFVertex* v);
787
  void SPFProcessStubs (SPFVertex* v);
788
  void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa);
778
  void SPFNext (SPFVertex*, CandidateQueue&);
789
  void SPFNext (SPFVertex*, CandidateQueue&);
779
  int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, 
790
  int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w, 
780
    GlobalRoutingLinkRecord* l, uint32_t distance);
791
    GlobalRoutingLinkRecord* l, uint32_t distance);
 Lines 784-789   private: Link Here 
784
  void SPFIntraAddRouter (SPFVertex* v);
795
  void SPFIntraAddRouter (SPFVertex* v);
785
  void SPFIntraAddTransit (SPFVertex* v);
796
  void SPFIntraAddTransit (SPFVertex* v);
786
  void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v);
797
  void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v);
798
  void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v);
787
  int32_t FindOutgoingInterfaceId (Ipv4Address a, 
799
  int32_t FindOutgoingInterfaceId (Ipv4Address a, 
788
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
800
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
789
};
801
};
(-)a/src/routing/global-routing/global-router-interface.cc (-2 / +114 lines)
 Lines 413-418   GlobalRoutingLSA::Print (std::ostream &o Link Here 
413
    {
413
    {
414
      os << " (GlobalRoutingLSA::NetworkLSA)";
414
      os << " (GlobalRoutingLSA::NetworkLSA)";
415
    }
415
    }
416
  else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs)
417
    {
418
      os << " (GlobalRoutingLSA::ASExternalLSA)";
419
    }
416
  else
420
  else
417
    {
421
    {
418
      os << "(Unknown LSType)";
422
      os << "(Unknown LSType)";
 Lines 474-479   GlobalRoutingLSA::Print (std::ostream &o Link Here 
474
        }
478
        }
475
      os << "---------- End NetworkLSA Link Record ----------" << std::endl;
479
      os << "---------- End NetworkLSA Link Record ----------" << std::endl;
476
    }
480
    }
481
  else if (m_lsType == GlobalRoutingLSA::ASExternalLSAs)
482
    {
483
      os << "---------- ASExternalLSA Link Record --------" << std::endl;
484
      os << "m_linkStateId = " << m_linkStateId << std::endl;
485
      os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl;
486
    }
477
  else 
487
  else 
478
    {
488
    {
479
      NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
489
      NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
 Lines 532-537   GlobalRouter::DoDispose () Link Here 
532
{
542
{
533
  NS_LOG_FUNCTION_NOARGS ();
543
  NS_LOG_FUNCTION_NOARGS ();
534
  m_routingProtocol = 0;
544
  m_routingProtocol = 0;
545
  for (InjectedRoutesI k = m_injectedRoutes.begin ();
546
         k != m_injectedRoutes.end ();
547
         k = m_injectedRoutes.erase (k))
548
    {
549
      delete (*k);
550
    }
535
  Object::DoDispose ();
551
  Object::DoDispose ();
536
}
552
}
537
553
 Lines 568-575   GlobalRouter::GetRouterId (void) const Link Here 
568
// and build the Link State Advertisements that reflect them and their associated
584
// and build the Link State Advertisements that reflect them and their associated
569
// networks.
585
// networks.
570
// 
586
// 
571
  uint32_t 
587
uint32_t 
572
GlobalRouter::DiscoverLSAs (void)
588
GlobalRouter::DiscoverLSAs ()
573
{
589
{
574
  NS_LOG_FUNCTION_NOARGS ();
590
  NS_LOG_FUNCTION_NOARGS ();
575
  Ptr<Node> node = GetObject<Node> ();
591
  Ptr<Node> node = GetObject<Node> ();
 Lines 696-701   GlobalRouter::DiscoverLSAs (void) Link Here 
696
      BuildNetworkLSAs (c);
712
      BuildNetworkLSAs (c);
697
    }
713
    }
698
714
715
  //
716
  // Build injected route LSAs as external routes
717
  // RFC 2328, section 12.4.4
718
  //
719
  for (InjectedRoutesCI i = m_injectedRoutes.begin();
720
       i != m_injectedRoutes.end();
721
       i++)
722
    {
723
      GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
724
      pLSA->SetLSType (GlobalRoutingLSA::ASExternalLSAs);
725
      pLSA->SetLinkStateId ((*i)->GetDestNetwork ());
726
      pLSA->SetAdvertisingRouter (m_routerId);
727
      pLSA->SetNetworkLSANetworkMask ((*i)->GetDestNetworkMask ());
728
      pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
729
      m_LSAs.push_back (pLSA); 
730
    }
699
  return m_LSAs.size ();
731
  return m_LSAs.size ();
700
}
732
}
701
733
 Lines 1467-1472   GlobalRouter::GetLSA (uint32_t n, Global Link Here 
1467
  return false;
1499
  return false;
1468
}
1500
}
1469
1501
1502
void
1503
GlobalRouter::InjectRoute (Ipv4Address network, Ipv4Mask networkMask)
1504
{
1505
  NS_LOG_FUNCTION (network << networkMask);
1506
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
1507
//
1508
// Interface number does not matter here, using 1.
1509
//
1510
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
1511
      networkMask,
1512
      1);
1513
  m_injectedRoutes.push_back (route);
1514
}
1515
1516
Ipv4RoutingTableEntry *
1517
GlobalRouter::GetInjectedRoute (uint32_t index)
1518
{
1519
  NS_LOG_FUNCTION (index);
1520
  if (index < m_injectedRoutes.size ())
1521
    {
1522
      uint32_t tmp = 0;
1523
      for (InjectedRoutesCI i = m_injectedRoutes.begin ();
1524
           i != m_injectedRoutes.end ();
1525
           i++)
1526
        {
1527
          if (tmp  == index)
1528
            {
1529
              return *i;
1530
            }
1531
          tmp++;
1532
        }
1533
     }
1534
  NS_ASSERT (false);
1535
  // quiet compiler.
1536
  return 0;
1537
}
1538
1539
uint32_t
1540
GlobalRouter::GetNInjectedRoutes ()
1541
{
1542
  return m_injectedRoutes.size ();
1543
}
1544
1545
void
1546
GlobalRouter::RemoveInjectedRoute (uint32_t index)
1547
{
1548
  NS_LOG_FUNCTION (index);
1549
  NS_ASSERT (index < m_injectedRoutes.size ());
1550
  uint32_t tmp = 0;
1551
  for (InjectedRoutesI i = m_injectedRoutes.begin (); i != m_injectedRoutes.end (); i++)
1552
    {
1553
      if (tmp  == index)
1554
        {
1555
          NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_injectedRoutes.size());
1556
          delete *i;
1557
          m_injectedRoutes.erase (i);
1558
          return;
1559
        }
1560
      tmp++;
1561
    }
1562
}
1563
1564
bool
1565
GlobalRouter::WithdrawRoute (Ipv4Address network, Ipv4Mask networkMask)
1566
{
1567
  NS_LOG_FUNCTION (index);
1568
  for (InjectedRoutesI i = m_injectedRoutes.begin (); i != m_injectedRoutes.end (); i++)
1569
    {
1570
      if ((*i)->GetDestNetwork () == network && (*i)->GetDestNetworkMask () == networkMask)
1571
        {
1572
          NS_LOG_LOGIC ("Withdrawing route to network/mask " << network << "/" << networkMask);
1573
          delete *i;
1574
          m_injectedRoutes.erase (i);
1575
          return true;
1576
        }
1577
    }
1578
  return false;
1579
}
1580
1581
1470
//
1582
//
1471
// Link through the given channel and find the net device that's on the
1583
// Link through the given channel and find the net device that's on the
1472
// other end.  This only makes sense with a point-to-point channel.
1584
// other end.  This only makes sense with a point-to-point channel.
(-)a/src/routing/global-routing/global-router-interface.h (+65 lines)
 Lines 32-37    Link Here 
32
#include "ns3/net-device-container.h"
32
#include "ns3/net-device-container.h"
33
#include "ns3/bridge-net-device.h"
33
#include "ns3/bridge-net-device.h"
34
#include "ns3/global-route-manager.h"
34
#include "ns3/global-route-manager.h"
35
#include "ns3/ipv4-routing-table-entry.h"
35
36
36
namespace ns3 {
37
namespace ns3 {
37
38
 Lines 614-619   public: Link Here 
614
 * advertisements after a network topology change by calling DiscoverLSAs 
615
 * advertisements after a network topology change by calling DiscoverLSAs 
615
 * and then by reading those advertisements.
616
 * and then by reading those advertisements.
616
 *
617
 *
618
 * \param List of routing table entries of external routes to be injected.
619
 *
617
 * @see GlobalRoutingLSA
620
 * @see GlobalRoutingLSA
618
 * @see GlobalRouter::GetLSA ()
621
 * @see GlobalRouter::GetLSA ()
619
 * @returns The number of Global Routing Link State Advertisements.
622
 * @returns The number of Global Routing Link State Advertisements.
 Lines 657-662   public: Link Here 
657
 */
660
 */
658
  bool GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const;
661
  bool GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const;
659
662
663
/**
664
 * @brief Inject a route to be circulated to other routers as an external
665
 * route
666
 *
667
 * Most of the public API for Ipv4GlobalRouting is for adding or deleting
668
 * routes that will be installed on this node.  However, this class also
669
 * stores routes that are intended to be propagated as AS-external-LSAs.
670
 *
671
 * @param network The Network to inject
672
 * @param networkMask The Network Mask to inject
673
 */
674
  void InjectRoute (Ipv4Address network, Ipv4Mask networkMask);
675
676
/**
677
 * @brief Get the number of injected routes that have been added
678
 * to the routing table.
679
 * @return number of injected routes
680
 */
681
  uint32_t GetNInjectedRoutes (void);
682
683
/**
684
 * @brief Return the injected route indexed by i
685
 * @param i the index of the route
686
 * @return a pointer to that Ipv4RoutingTableEntry is returned
687
 *
688
 */
689
  Ipv4RoutingTableEntry *GetInjectedRoute (uint32_t i);
690
691
/**
692
 * @brief Withdraw a route from the global unicast routing table.
693
 *
694
 * Calling this function will cause all indexed routes numbered above
695
 * index i to have their index decremented.  For instance, it is possible to
696
 * remove N injected routes by calling RemoveInjectedRoute (0) N times.
697
 *
698
 * @param i The index (into the injected routing list) of the route to remove.  
699
 *
700
 * @see GlobalRouter::WithdrawRoute ()
701
 */
702
  void RemoveInjectedRoute (uint32_t i);
703
704
/**
705
 * @brief Withdraw a route from the global unicast routing table.
706
 *
707
 * Calling this function will cause all indexed routes numbered above
708
 * index i to have their index decremented.  For instance, it is possible to
709
 * remove N injected routes by calling RemoveInjectedRoute (0) N times.
710
 *
711
 * @param i The index (into the injected routing list) of the route to remove.  
712
 * @param network The Network to inject
713
 * @param networkMask The Network Mask to inject
714
 * @return whether the operation succeeded (will return false if no such route)
715
 *
716
 * @see GlobalRouter::RemoveInjectedRoute ()
717
 */
718
  bool WithdrawRoute (Ipv4Address network, Ipv4Mask networkMask);
719
660
private:
720
private:
661
  virtual ~GlobalRouter ();
721
  virtual ~GlobalRouter ();
662
  void ClearLSAs (void);
722
  void ClearLSAs (void);
 Lines 679-684   private: Link Here 
679
739
680
  Ipv4Address m_routerId;
740
  Ipv4Address m_routerId;
681
  Ptr<Ipv4GlobalRouting> m_routingProtocol;
741
  Ptr<Ipv4GlobalRouting> m_routingProtocol;
742
743
  typedef std::list<Ipv4RoutingTableEntry *> InjectedRoutes;
744
  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator InjectedRoutesCI;
745
  typedef std::list<Ipv4RoutingTableEntry *>::iterator InjectedRoutesI;
746
  InjectedRoutes m_injectedRoutes; // Routes we are exporting
682
747
683
  // inherited from Object
748
  // inherited from Object
684
  virtual void DoDispose (void);
749
  virtual void DoDispose (void);
(-)a/src/routing/global-routing/ipv4-global-routing.cc (-6 / +79 lines)
 Lines 98-107   Ipv4GlobalRouting::AddNetworkRouteTo (Ip Link Here 
98
  m_networkRoutes.push_back (route);
98
  m_networkRoutes.push_back (route);
99
}
99
}
100
100
101
void 
102
Ipv4GlobalRouting::AddASExternalRouteTo (Ipv4Address network, 
103
                                         Ipv4Mask networkMask,
104
                                         Ipv4Address nextHop,
105
                                         uint32_t interface)
106
{
107
  NS_LOG_FUNCTION (network << networkMask << nextHop);
108
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
109
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
110
      networkMask,
111
      nextHop,
112
      interface);
113
  m_ASexternalRoutes.push_back (route);
114
}
115
116
101
Ptr<Ipv4Route>
117
Ptr<Ipv4Route>
102
Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
118
Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
103
{
119
{
104
  NS_LOG_FUNCTION_NOARGS ();
120
  NS_LOG_FUNCTION_NOARGS ();
121
  NS_LOG_LOGIC ("Looking for route for destination " << dest);
105
  Ptr<Ipv4Route> rtentry = 0;
122
  Ptr<Ipv4Route> rtentry = 0;
106
  bool found = false;
123
  bool found = false;
107
  Ipv4RoutingTableEntry* route = 0;
124
  Ipv4RoutingTableEntry* route = 0;
 Lines 137-142   Ipv4GlobalRouting::LookupGlobal (Ipv4Add Link Here 
137
            }
154
            }
138
        }
155
        }
139
    }
156
    }
157
  if (found == false)
158
    {
159
      for (ASExternalRoutesI k = m_ASexternalRoutes.begin ();
160
           k != m_ASexternalRoutes.end ();
161
           k++)
162
        {
163
          Ipv4Mask mask = (*k)->GetDestNetworkMask ();
164
          Ipv4Address entry = (*k)->GetDestNetwork ();
165
          if (mask.IsMatch (dest, entry))
166
            {
167
              NS_LOG_LOGIC ("Found external route" << *k);
168
              route = (*k);
169
              found = true;
170
              break;
171
            }
172
        }
173
    }
140
  if (found == true)
174
  if (found == true)
141
    {
175
    {
142
      rtentry = Create<Ipv4Route> ();
176
      rtentry = Create<Ipv4Route> ();
 Lines 161-166   Ipv4GlobalRouting::GetNRoutes (void) Link Here 
161
  uint32_t n = 0;
195
  uint32_t n = 0;
162
  n += m_hostRoutes.size ();
196
  n += m_hostRoutes.size ();
163
  n += m_networkRoutes.size ();
197
  n += m_networkRoutes.size ();
198
  n += m_ASexternalRoutes.size ();
164
  return n;
199
  return n;
165
}
200
}
166
201
 Lines 184-199   Ipv4GlobalRouting::GetRoute (uint32_t in Link Here 
184
    }
219
    }
185
  index -= m_hostRoutes.size ();
220
  index -= m_hostRoutes.size ();
186
  uint32_t tmp = 0;
221
  uint32_t tmp = 0;
187
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
222
  if (index < m_networkRoutes.size())
188
       j != m_networkRoutes.end (); 
189
       j++) 
190
    {
223
    {
191
      if (tmp == index)
224
      for (NetworkRoutesI j = m_networkRoutes.begin (); 
225
          j != m_networkRoutes.end (); 
226
          j++) 
192
        {
227
        {
193
          return *j;
228
          if (tmp == index)
229
            {
230
              return *j;
231
            }
232
          tmp++;
194
        }
233
        }
195
      tmp++;
196
    }
234
    }
235
  index -= m_networkRoutes.size();
236
  tmp = 0;
237
  for (ASExternalRoutesI k = m_ASexternalRoutes.begin (); 
238
       k != m_ASexternalRoutes.end (); 
239
       k++) 
240
  {
241
    if (tmp == index)
242
    {
243
      return *k;
244
    }
245
    tmp++;
246
  }
197
  NS_ASSERT (false);
247
  NS_ASSERT (false);
198
  // quiet compiler.
248
  // quiet compiler.
199
  return 0;
249
  return 0;
 Lines 236-241   Ipv4GlobalRouting::RemoveRoute (uint32_t Link Here 
236
        }
286
        }
237
      tmp++;
287
      tmp++;
238
    }
288
    }
289
  index -= m_networkRoutes.size ();
290
  tmp = 0;
291
  for (ASExternalRoutesI k = m_ASexternalRoutes.begin (); 
292
         k != m_ASexternalRoutes.end (); 
293
         k++) 
294
    {
295
      if (tmp == index)
296
      {
297
        NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_ASexternalRoutes.size());
298
        delete *k;
299
        m_ASexternalRoutes.erase (k);
300
        NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
301
        return;
302
      }
303
      tmp++;
304
    }
239
  NS_ASSERT (false);
305
  NS_ASSERT (false);
240
}
306
}
241
307
 Lines 255-260   Ipv4GlobalRouting::DoDispose (void) Link Here 
255
    {
321
    {
256
      delete (*j);
322
      delete (*j);
257
    }
323
    }
324
  for (ASExternalRoutesI l = m_ASexternalRoutes.begin (); 
325
         l != m_ASexternalRoutes.end (); 
326
         l = m_ASexternalRoutes.erase (l)) 
327
    {
328
      delete (*l);
329
    }
330
258
  Ipv4RoutingProtocol::DoDispose ();
331
  Ipv4RoutingProtocol::DoDispose ();
259
}
332
}
260
333
(-)a/src/routing/global-routing/ipv4-global-routing.h (-1 / +19 lines)
 Lines 147-152   public: Link Here 
147
                          uint32_t interface);
147
                          uint32_t interface);
148
148
149
/**
149
/**
150
 * \brief Add an external route to the global routing table.
151
 *
152
 * \param network The Ipv4Address network for this route.
153
 * \param networkMask The Ipv4Mask to extract the network.
154
 * \param nextHop The next hop Ipv4Address
155
 * \param interface The network interface index used to send packets to the
156
 * destination.
157
 */
158
  void AddASExternalRouteTo (Ipv4Address network,
159
                             Ipv4Mask networkMask,
160
                             Ipv4Address nextHop,
161
                             uint32_t interface);
162
163
/**
150
 * \brief Get the number of individual unicast routes that have been added
164
 * \brief Get the number of individual unicast routes that have been added
151
 * to the routing table.
165
 * to the routing table.
152
 *
166
 *
 Lines 204-215   private: Link Here 
204
  typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
218
  typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
205
  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
219
  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
206
  typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
220
  typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
221
  typedef std::list<Ipv4RoutingTableEntry *> ASExternalRoutes;
222
  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator ASExternalRoutesCI;
223
  typedef std::list<Ipv4RoutingTableEntry *>::iterator ASExternalRoutesI;
207
224
208
  Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
225
  Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
209
226
210
  HostRoutes m_hostRoutes;
227
  HostRoutes m_hostRoutes;
211
  NetworkRoutes m_networkRoutes;
228
  NetworkRoutes m_networkRoutes;
212
229
  ASExternalRoutes m_ASexternalRoutes; // External routes imported
230
  
213
  Ptr<Ipv4> m_ipv4;
231
  Ptr<Ipv4> m_ipv4;
214
};
232
};
215
233

Return to bug 614