00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <utility>
00026 #include <vector>
00027 #include <queue>
00028 #include "ns3/assert.h"
00029 #include "ns3/fatal-error.h"
00030 #include "ns3/log.h"
00031 #include "ns3/node-list.h"
00032 #include "ns3/ipv4.h"
00033 #include "ns3/ipv4-global-routing.h"
00034 #include "global-router-interface.h"
00035 #include "global-route-manager-impl.h"
00036 #include "candidate-queue.h"
00037
00038 NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");
00039
00040 namespace ns3 {
00041
00042
00043
00044
00045
00046
00047
00048 SPFVertex::SPFVertex () :
00049 m_vertexType (VertexUnknown),
00050 m_vertexId ("255.255.255.255"),
00051 m_lsa (0),
00052 m_distanceFromRoot (SPF_INFINITY),
00053 m_rootOif (SPF_INFINITY),
00054 m_nextHop ("0.0.0.0"),
00055 m_parent (0),
00056 m_children (),
00057 m_vertexProcessed (false)
00058 {
00059 NS_LOG_FUNCTION_NOARGS ();
00060 }
00061
00062 SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) :
00063 m_vertexId (lsa->GetLinkStateId ()),
00064 m_lsa (lsa),
00065 m_distanceFromRoot (SPF_INFINITY),
00066 m_rootOif (SPF_INFINITY),
00067 m_nextHop ("0.0.0.0"),
00068 m_parent (0),
00069 m_children (),
00070 m_vertexProcessed (false)
00071 {
00072 NS_LOG_FUNCTION_NOARGS ();
00073 if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA)
00074 {
00075 NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter");
00076 m_vertexType = SPFVertex::VertexRouter;
00077 }
00078 else if (lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA)
00079 {
00080 NS_LOG_LOGIC ("Setting m_vertexType to VertexNetwork");
00081 m_vertexType = SPFVertex::VertexNetwork;
00082 }
00083 }
00084
00085 SPFVertex::~SPFVertex ()
00086 {
00087 NS_LOG_FUNCTION_NOARGS ();
00088 for ( ListOfSPFVertex_t::iterator i = m_children.begin ();
00089 i != m_children.end ();
00090 i++)
00091 {
00092 SPFVertex *p = *i;
00093 delete p;
00094 p = 0;
00095 *i = 0;
00096 }
00097 m_children.clear ();
00098 }
00099
00100 void
00101 SPFVertex::SetVertexType (SPFVertex::VertexType type)
00102 {
00103 NS_LOG_FUNCTION (type);
00104 m_vertexType = type;
00105 }
00106
00107 SPFVertex::VertexType
00108 SPFVertex::GetVertexType (void) const
00109 {
00110 NS_LOG_FUNCTION_NOARGS ();
00111 return m_vertexType;
00112 }
00113
00114 void
00115 SPFVertex::SetVertexId (Ipv4Address id)
00116 {
00117 NS_LOG_FUNCTION (id);
00118 m_vertexId = id;
00119 }
00120
00121 Ipv4Address
00122 SPFVertex::GetVertexId (void) const
00123 {
00124 NS_LOG_FUNCTION_NOARGS ();
00125 return m_vertexId;
00126 }
00127
00128 void
00129 SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
00130 {
00131 NS_LOG_FUNCTION (lsa);
00132 m_lsa = lsa;
00133 }
00134
00135 GlobalRoutingLSA*
00136 SPFVertex::GetLSA (void) const
00137 {
00138 NS_LOG_FUNCTION_NOARGS ();
00139 return m_lsa;
00140 }
00141
00142 void
00143 SPFVertex::SetDistanceFromRoot (uint32_t distance)
00144 {
00145 NS_LOG_FUNCTION (distance);
00146 m_distanceFromRoot = distance;
00147 }
00148
00149 uint32_t
00150 SPFVertex::GetDistanceFromRoot (void) const
00151 {
00152 NS_LOG_FUNCTION_NOARGS ();
00153 return m_distanceFromRoot;
00154 }
00155
00156 void
00157 SPFVertex::SetOutgoingTypeId (uint32_t id)
00158 {
00159 NS_LOG_FUNCTION (id);
00160 m_rootOif = id;
00161 }
00162
00163 uint32_t
00164 SPFVertex::GetOutgoingTypeId (void) const
00165 {
00166 NS_LOG_FUNCTION_NOARGS ();
00167 return m_rootOif;
00168 }
00169
00170 void
00171 SPFVertex::SetNextHop (Ipv4Address nextHop)
00172 {
00173 NS_LOG_FUNCTION (nextHop);
00174 m_nextHop = nextHop;
00175 }
00176
00177 Ipv4Address
00178 SPFVertex::GetNextHop (void) const
00179 {
00180 NS_LOG_FUNCTION_NOARGS ();
00181 return m_nextHop;
00182 }
00183
00184 void
00185 SPFVertex::SetParent (SPFVertex* parent)
00186 {
00187 NS_LOG_FUNCTION (parent);
00188 m_parent = parent;
00189 }
00190
00191 SPFVertex*
00192 SPFVertex::GetParent (void) const
00193 {
00194 NS_LOG_FUNCTION_NOARGS ();
00195 return m_parent;
00196 }
00197
00198 uint32_t
00199 SPFVertex::GetNChildren (void) const
00200 {
00201 NS_LOG_FUNCTION_NOARGS ();
00202 return m_children.size ();
00203 }
00204
00205 SPFVertex*
00206 SPFVertex::GetChild (uint32_t n) const
00207 {
00208 NS_LOG_FUNCTION (n);
00209 uint32_t j = 0;
00210
00211 for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
00212 i != m_children.end ();
00213 i++, j++)
00214 {
00215 if (j == n)
00216 {
00217 return *i;
00218 }
00219 }
00220 NS_ASSERT_MSG (false, "Index <n> out of range.");
00221 return 0;
00222 }
00223
00224 uint32_t
00225 SPFVertex::AddChild (SPFVertex* child)
00226 {
00227 NS_LOG_FUNCTION (child);
00228 m_children.push_back (child);
00229 return m_children.size ();
00230 }
00231
00232 void
00233 SPFVertex::SetVertexProcessed (bool value)
00234 {
00235 m_vertexProcessed = value;
00236 }
00237
00238 bool
00239 SPFVertex::IsVertexProcessed (void) const
00240 {
00241 return m_vertexProcessed;
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251 GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()
00252 :
00253 m_database ()
00254 {
00255 NS_LOG_FUNCTION_NOARGS ();
00256 }
00257
00258 GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ()
00259 {
00260 NS_LOG_FUNCTION_NOARGS ();
00261 LSDBMap_t::iterator i;
00262 for (i= m_database.begin (); i!= m_database.end (); i++)
00263 {
00264 NS_LOG_LOGIC ("free LSA");
00265 GlobalRoutingLSA* temp = i->second;
00266 delete temp;
00267 }
00268 NS_LOG_LOGIC ("clear map");
00269 m_database.clear ();
00270 }
00271
00272 void
00273 GlobalRouteManagerLSDB::Initialize ()
00274 {
00275 NS_LOG_FUNCTION_NOARGS ();
00276 LSDBMap_t::iterator i;
00277 for (i= m_database.begin (); i!= m_database.end (); i++)
00278 {
00279 GlobalRoutingLSA* temp = i->second;
00280 temp->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
00281 }
00282 }
00283
00284 void
00285 GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
00286 {
00287 NS_LOG_FUNCTION (addr << lsa);
00288 m_database.insert (LSDBPair_t (addr, lsa));
00289 }
00290
00291 GlobalRoutingLSA*
00292 GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
00293 {
00294 NS_LOG_FUNCTION (addr);
00295
00296
00297
00298 LSDBMap_t::const_iterator i;
00299 for (i= m_database.begin (); i!= m_database.end (); i++)
00300 {
00301 if (i->first == addr)
00302 {
00303 return i->second;
00304 }
00305 }
00306 return 0;
00307 }
00308
00309 GlobalRoutingLSA*
00310 GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
00311 {
00312 NS_LOG_FUNCTION (addr);
00313
00314
00315
00316 LSDBMap_t::const_iterator i;
00317 for (i= m_database.begin (); i!= m_database.end (); i++)
00318 {
00319 GlobalRoutingLSA* temp = i->second;
00320
00321 for (uint32_t j = 0; j < temp->GetNLinkRecords (); j++)
00322 {
00323 GlobalRoutingLinkRecord *lr = temp->GetLinkRecord (j);
00324 if ( lr->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork &&
00325 lr->GetLinkData () == addr)
00326 {
00327 return temp;
00328 }
00329 }
00330 }
00331 return 0;
00332 }
00333
00334
00335
00336
00337
00338
00339
00340 GlobalRouteManagerImpl::GlobalRouteManagerImpl ()
00341 :
00342 m_spfroot (0)
00343 {
00344 NS_LOG_FUNCTION_NOARGS ();
00345 m_lsdb = new GlobalRouteManagerLSDB ();
00346 }
00347
00348 GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()
00349 {
00350 NS_LOG_FUNCTION_NOARGS ();
00351 if (m_lsdb)
00352 {
00353 delete m_lsdb;
00354 }
00355 }
00356
00357 void
00358 GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
00359 {
00360 NS_LOG_FUNCTION (lsdb);
00361 if (m_lsdb)
00362 {
00363 delete m_lsdb;
00364 }
00365 m_lsdb = lsdb;
00366 }
00367
00368 void
00369 GlobalRouteManagerImpl::DeleteGlobalRoutes ()
00370 {
00371 NS_LOG_FUNCTION_NOARGS ();
00372 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
00373 {
00374 Ptr<Node> node = *i;
00375 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
00376 uint32_t j = 0;
00377 uint32_t nRoutes = gr->GetNRoutes ();
00378 NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ());
00379
00380
00381
00382 for (j = 0; j < nRoutes; j++)
00383 {
00384 NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ());
00385 gr->RemoveRoute (0);
00386 }
00387 NS_LOG_LOGIC ("Deleted " << j << " global routes from node "<< node->GetId ());
00388 }
00389 if (m_lsdb)
00390 {
00391 NS_LOG_LOGIC ("Deleting LSDB, creating new one");
00392 delete m_lsdb;
00393 m_lsdb = new GlobalRouteManagerLSDB ();
00394 }
00395 }
00396
00397
00398
00399
00400
00401
00402
00403 void
00404 GlobalRouteManagerImpl::SelectRouterNodes ()
00405 {
00406 NS_LOG_FUNCTION_NOARGS ();
00407 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
00408 {
00409 Ptr<Node> node = *i;
00410 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ());
00411
00412 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
00413 node->AggregateObject (globalRouter);
00414
00415 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
00416 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
00417
00418
00419
00420
00421 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
00422 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
00423 "GetObject for <Ipv4> interface failed");
00424
00425 ipv4->AddRoutingProtocol (globalRouting, 3);
00426
00427
00428 AddGlobalRoutingProtocol (node->GetId (), globalRouting);
00429 }
00430 }
00431
00432 void
00433 GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c)
00434 {
00435 NS_LOG_FUNCTION (&c);
00436 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
00437 {
00438 Ptr<Node> node = *i;
00439 NS_LOG_LOGIC ("Adding GlobalRouter interface to node " <<
00440 node->GetId ());
00441
00442 Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
00443 node->AggregateObject (globalRouter);
00444
00445 NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
00446 Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
00447
00448
00449
00450
00451 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
00452 NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
00453 "GetObject for <Ipv4> interface failed");
00454
00455 ipv4->AddRoutingProtocol (globalRouting, 3);
00456
00457
00458 AddGlobalRoutingProtocol (node->GetId (), globalRouting);
00459 }
00460 }
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 void
00472 GlobalRouteManagerImpl::BuildGlobalRoutingDatabase ()
00473 {
00474 NS_LOG_FUNCTION_NOARGS ();
00475
00476
00477
00478
00479 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
00480 {
00481 Ptr<Node> node = *i;
00482
00483 Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
00484
00485
00486
00487 if (!rtr)
00488 {
00489 continue;
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499 uint32_t numLSAs = rtr->DiscoverLSAs ();
00500 NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
00501
00502 for (uint32_t j = 0; j < numLSAs; ++j)
00503 {
00504 GlobalRoutingLSA* lsa = new GlobalRoutingLSA ();
00505
00506
00507
00508
00509 rtr->GetLSA (j, *lsa);
00510 NS_LOG_LOGIC (*lsa);
00511
00512
00513
00514 m_lsdb->Insert (lsa->GetLinkStateId (), lsa);
00515 }
00516 }
00517 }
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 void
00553 GlobalRouteManagerImpl::InitializeRoutes ()
00554 {
00555 NS_LOG_FUNCTION_NOARGS ();
00556
00557
00558
00559 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
00560 {
00561 Ptr<Node> node = *i;
00562
00563
00564
00565
00566 Ptr<GlobalRouter> rtr =
00567 node->GetObject<GlobalRouter> ();
00568
00569
00570
00571
00572 if (rtr && rtr->GetNumLSAs () )
00573 {
00574 SPFCalculate (rtr->GetRouterId ());
00575 }
00576 }
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 void
00593 GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
00594 {
00595 NS_LOG_FUNCTION (v << &candidate);
00596
00597 SPFVertex* w = 0;
00598 GlobalRoutingLSA* w_lsa = 0;
00599 GlobalRoutingLinkRecord *l = 0;
00600 uint32_t distance = 0;
00601 uint32_t numRecordsInVertex = 0;
00602
00603
00604
00605
00606 if (v->GetVertexType () == SPFVertex::VertexRouter)
00607 {
00608 numRecordsInVertex = v->GetLSA ()->GetNLinkRecords ();
00609 }
00610 if (v->GetVertexType () == SPFVertex::VertexNetwork)
00611 {
00612 numRecordsInVertex = v->GetLSA ()->GetNAttachedRouters ();
00613 }
00614
00615 for (uint32_t i = 0; i < numRecordsInVertex; i++)
00616 {
00617
00618 if (v->GetVertexType () == SPFVertex::VertexRouter)
00619 {
00620 NS_LOG_LOGIC ("Examining link " << i << " of " <<
00621 v->GetVertexId () << "'s " <<
00622 v->GetLSA ()->GetNLinkRecords () << " link records");
00623
00624
00625
00626
00627
00628 l = v->GetLSA ()->GetLinkRecord (i);
00629 if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
00630 {
00631 NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
00632 continue;
00633 }
00634
00635
00636
00637
00638
00639 if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
00640 {
00641
00642
00643
00644
00645 w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
00646 NS_ASSERT (w_lsa);
00647 NS_LOG_LOGIC ("Found a P2P record from " <<
00648 v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
00649 }
00650 else if (l->GetLinkType () ==
00651 GlobalRoutingLinkRecord::TransitNetwork)
00652 {
00653 w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
00654 NS_ASSERT (w_lsa);
00655 NS_LOG_LOGIC ("Found a Transit record from " <<
00656 v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
00657 }
00658 else
00659 {
00660 NS_ASSERT_MSG (0, "illegal Link Type");
00661 }
00662 }
00663
00664 if (v->GetVertexType () == SPFVertex::VertexNetwork)
00665 {
00666 w_lsa = m_lsdb->GetLSAByLinkData
00667 (v->GetLSA ()->GetAttachedRouter (i));
00668 if (!w_lsa)
00669 {
00670 continue;
00671 }
00672 NS_LOG_LOGIC ("Found a Network LSA from " <<
00673 v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
00674 }
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_IN_SPFTREE)
00685 {
00686 NS_LOG_LOGIC ("Skipping -> LSA "<<
00687 w_lsa->GetLinkStateId () << " already in SPF tree");
00688 continue;
00689 }
00690
00691
00692
00693
00694
00695
00696 if (v->GetLSA ()->GetLSType () == GlobalRoutingLSA::RouterLSA)
00697 {
00698 distance = v->GetDistanceFromRoot () + l->GetMetric ();
00699 }
00700 else
00701 {
00702 distance = v->GetDistanceFromRoot ();
00703 }
00704
00705 NS_LOG_LOGIC ("Considering w_lsa " << w_lsa->GetLinkStateId ());
00706
00707
00708 if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
00709 {
00710
00711
00712 w = new SPFVertex (w_lsa);
00713
00714
00715
00716
00717
00718
00719 if (SPFNexthopCalculation (v, w, l, distance))
00720 {
00721 w_lsa->SetStatus (GlobalRoutingLSA::LSA_SPF_CANDIDATE);
00722
00723
00724
00725
00726 candidate.Push (w);
00727 NS_LOG_LOGIC ("Pushing " <<
00728 w->GetVertexId () << ", parent vertexId: " <<
00729 v->GetVertexId () << ", distance: " <<
00730 w->GetDistanceFromRoot ());
00731 }
00732 }
00733 else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE)
00734 {
00735
00736
00737
00738
00739
00740
00741
00742 w = candidate.Find (w_lsa->GetLinkStateId ());
00743 if (w->GetDistanceFromRoot () < distance)
00744 {
00745
00746
00747
00748 continue;
00749 }
00750 else if (w->GetDistanceFromRoot () == distance)
00751 {
00752
00753
00754
00755
00756 }
00757 else
00758 {
00759
00760
00761
00762
00763
00764
00765
00766
00767 if (SPFNexthopCalculation (v, w, l, distance))
00768 {
00769
00770
00771
00772
00773 candidate.Reorder ();
00774 }
00775 }
00776 }
00777 }
00778 }
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790 int
00791 GlobalRouteManagerImpl::SPFNexthopCalculation (
00792 SPFVertex* v,
00793 SPFVertex* w,
00794 GlobalRoutingLinkRecord* l,
00795 uint32_t distance)
00796 {
00797 NS_LOG_FUNCTION (v << w << l << distance);
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 if (v == m_spfroot)
00831 {
00832
00833
00834
00835
00836
00837
00838
00839
00840 if (w->GetVertexType () == SPFVertex::VertexRouter)
00841 {
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 NS_ASSERT (l);
00856 GlobalRoutingLinkRecord *linkRemote = 0;
00857 linkRemote = SPFGetNextLink (w, v, linkRemote);
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 w->SetNextHop (linkRemote->GetLinkData ());
00870
00871
00872
00873
00874
00875 w->SetOutgoingTypeId (
00876 FindOutgoingTypeId (l->GetLinkData ()));
00877 w->SetDistanceFromRoot (distance);
00878 w->SetParent (v);
00879 NS_LOG_LOGIC ("Next hop from " <<
00880 v->GetVertexId () << " to " << w->GetVertexId () <<
00881 " goes through next hop " << w->GetNextHop () <<
00882 " via outgoing interface " << w->GetOutgoingTypeId () <<
00883 " with distance " << distance);
00884 }
00885 else
00886 {
00887 NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork);
00888
00889 GlobalRoutingLSA* w_lsa = w->GetLSA ();
00890 NS_ASSERT (w_lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA);
00891
00892 w->SetOutgoingTypeId (
00893 FindOutgoingTypeId (w_lsa->GetLinkStateId (),
00894 w_lsa->GetNetworkLSANetworkMask () ));
00895 w->SetDistanceFromRoot (distance);
00896 w->SetParent (v);
00897 NS_LOG_LOGIC ("Next hop from " <<
00898 v->GetVertexId () << " to network " << w->GetVertexId () <<
00899 " via outgoing interface " << w->GetOutgoingTypeId () <<
00900 " with distance " << distance);
00901 return 1;
00902 }
00903 }
00904 else if (v->GetVertexType () == SPFVertex::VertexNetwork)
00905 {
00906
00907 if (v->GetParent () == m_spfroot)
00908 {
00909
00910
00911
00912
00913 NS_ASSERT (w->GetVertexType () == SPFVertex::VertexRouter);
00914 GlobalRoutingLinkRecord *linkRemote = 0;
00915 while ((linkRemote = SPFGetNextLink (w, v, linkRemote)))
00916 {
00917
00918
00919
00920
00921
00922
00923 w->SetNextHop (linkRemote->GetLinkData ());
00924 w->SetOutgoingTypeId (v->GetOutgoingTypeId ());
00925 NS_LOG_LOGIC ("Next hop from " <<
00926 v->GetVertexId () << " to " << w->GetVertexId () <<
00927 " goes through next hop " << w->GetNextHop () <<
00928 " via outgoing interface " << w->GetOutgoingTypeId ());
00929 }
00930 }
00931 else
00932 {
00933 w->SetNextHop (v->GetNextHop ());
00934 w->SetOutgoingTypeId (v->GetOutgoingTypeId ());
00935 }
00936 }
00937 else
00938 {
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952 w->SetNextHop (v->GetNextHop ());
00953 w->SetOutgoingTypeId (v->GetOutgoingTypeId ());
00954 }
00955
00956
00957
00958 w->SetDistanceFromRoot (distance);
00959 w->SetParent (v);
00960
00961 return 1;
00962 }
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976 GlobalRoutingLinkRecord*
00977 GlobalRouteManagerImpl::SPFGetNextLink (
00978 SPFVertex* v,
00979 SPFVertex* w,
00980 GlobalRoutingLinkRecord* prev_link)
00981 {
00982 NS_LOG_FUNCTION (v << w << prev_link);
00983
00984 bool skip = true;
00985 bool found_prev_link = false;
00986 GlobalRoutingLinkRecord* l;
00987
00988
00989
00990
00991 if (prev_link == 0)
00992 {
00993 skip = false;
00994 found_prev_link = true;
00995 }
00996
00997
00998
00999
01000
01001 for (uint32_t i = 0; i < v->GetLSA ()->GetNLinkRecords (); ++i)
01002 {
01003 l = v->GetLSA ()->GetLinkRecord (i);
01004
01005
01006
01007
01008
01009
01010
01011
01012 if (l->GetLinkId () == w->GetVertexId ())
01013 {
01014 if (!found_prev_link)
01015 {
01016 NS_LOG_LOGIC ("Skipping links before prev_link found");
01017 found_prev_link = true;
01018 continue;
01019 }
01020
01021 NS_LOG_LOGIC ("Found matching link l: linkId = " <<
01022 l->GetLinkId () << " linkData = " << l->GetLinkData ());
01023
01024
01025
01026
01027
01028
01029
01030 if (skip == false)
01031 {
01032 NS_LOG_LOGIC ("Returning the found link");
01033 return l;
01034 }
01035 else
01036 {
01037
01038
01039
01040
01041
01042 NS_LOG_LOGIC ("Skipping the found link");
01043 skip = false;
01044 continue;
01045 }
01046 }
01047 }
01048 return 0;
01049 }
01050
01051
01052
01053
01054 void
01055 GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
01056 {
01057 NS_LOG_FUNCTION (root);
01058 SPFCalculate (root);
01059 }
01060
01061
01062 void
01063 GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
01064 {
01065 NS_LOG_FUNCTION (this << root);
01066
01067 SPFVertex *v;
01068
01069
01070
01071 m_lsdb->Initialize ();
01072
01073
01074
01075
01076
01077 CandidateQueue candidate;
01078 NS_ASSERT (candidate.Size () == 0);
01079
01080
01081
01082
01083
01084 v = new SPFVertex (m_lsdb->GetLSA (root));
01085
01086
01087
01088
01089 m_spfroot= v;
01090 v->SetDistanceFromRoot (0);
01091 v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
01092 NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
01093
01094 for (;;)
01095 {
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110 SPFNext (v, candidate);
01111
01112
01113
01114
01115
01116
01117
01118 if (candidate.Size () == 0)
01119 {
01120 break;
01121 }
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 v = candidate.Pop ();
01132 NS_LOG_LOGIC ("Popped vertex " << v->GetVertexId ());
01133
01134
01135
01136
01137 v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
01138
01139
01140
01141
01142
01143
01144
01145 SPFVertexAddParent (v);
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175 if (v->GetVertexType () == SPFVertex::VertexRouter)
01176 {
01177 SPFIntraAddRouter (v);
01178 }
01179 else if (v->GetVertexType () == SPFVertex::VertexNetwork)
01180 {
01181 SPFIntraAddTransit (v);
01182 }
01183 else
01184 {
01185 NS_ASSERT_MSG (0, "illegal SPFVertex type");
01186 }
01187
01188
01189
01190
01191
01192
01193 }
01194
01195
01196 SPFProcessStubs (m_spfroot);
01197
01198
01199
01200
01201
01202 delete m_spfroot;
01203 m_spfroot = 0;
01204 }
01205
01206
01207
01208
01209 void
01210 GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v)
01211 {
01212 NS_LOG_FUNCTION_NOARGS ();
01213 NS_LOG_LOGIC ("Processing stubs for " << v->GetVertexId ());
01214 if (v->GetVertexType () == SPFVertex::VertexRouter)
01215 {
01216 GlobalRoutingLSA *rlsa = v->GetLSA ();
01217 NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ());
01218 for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++)
01219 {
01220 NS_LOG_LOGIC ("Examining link " << i << " of " <<
01221 v->GetVertexId () << "'s " <<
01222 v->GetLSA ()->GetNLinkRecords () << " link records");
01223 GlobalRoutingLinkRecord *l = v->GetLSA ()->GetLinkRecord (i);
01224 if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
01225 {
01226 NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
01227 SPFIntraAddStub (l, v);
01228 continue;
01229 }
01230 }
01231 }
01232 for (uint32_t i = 0; i < v->GetNChildren (); i++)
01233 {
01234 if (!v->GetChild (i)->IsVertexProcessed ())
01235 {
01236 SPFProcessStubs (v->GetChild (i));
01237 v->GetChild (i)->SetVertexProcessed (true);
01238 }
01239 }
01240 }
01241
01242
01243 void
01244 GlobalRouteManagerImpl::SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v)
01245 {
01246 NS_LOG_FUNCTION_NOARGS ();
01247
01248 NS_ASSERT_MSG (m_spfroot,
01249 "GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set");
01250
01251
01252
01253
01254
01255
01256 if (v->GetVertexId () == m_spfroot->GetVertexId ())
01257 {
01258 NS_LOG_LOGIC ("Stub is on local host: " << v->GetVertexId () << "; returning");
01259 return;
01260 }
01261 NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing");
01262
01263
01264
01265
01266
01267
01268
01269 Ipv4Address routerId = m_spfroot->GetVertexId ();
01270
01271 NS_LOG_LOGIC ("Vertex ID = " << routerId);
01272
01273
01274
01275
01276
01277 NodeList::Iterator i = NodeList::Begin ();
01278 for (; i != NodeList::End (); i++)
01279 {
01280 Ptr<Node> node = *i;
01281
01282
01283
01284
01285
01286 Ptr<GlobalRouter> rtr =
01287 node->GetObject<GlobalRouter> ();
01288
01289 if (rtr == 0)
01290 {
01291 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<
01292 node->GetId ());
01293 continue;
01294 }
01295
01296
01297
01298
01299
01300 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
01301
01302 if (rtr->GetRouterId () == routerId)
01303 {
01304 NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
01305
01306
01307
01308
01309
01310 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
01311 NS_ASSERT_MSG (ipv4,
01312 "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
01313 "QI for <Ipv4> interface failed");
01314
01315
01316
01317
01318
01319
01320 NS_ASSERT_MSG (v->GetLSA (),
01321 "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
01322 "Expected valid LSA in SPFVertex* v");
01323 Ipv4Mask tempmask ("255.255.255.0");
01324 Ipv4Address tempip = l->GetLinkId ();
01325 tempip = tempip.CombineMask (tempmask);
01326
01327 NS_LOG_LOGIC (" Node " << node->GetId () <<
01328 " add route to " << tempip <<
01329 " with mask " << tempmask <<
01330 " using next hop " << v->GetNextHop () <<
01331 " via interface " << v->GetOutgoingTypeId ());
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
01346 NS_ASSERT (gr);
01347 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingTypeId ());
01348 return;
01349 }
01350 }
01351 }
01352
01353
01354
01355
01356
01357
01358 uint32_t
01359 GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask)
01360 {
01361 NS_LOG_FUNCTION (a << amask);
01362
01363
01364
01365
01366
01367
01368
01369
01370 Ipv4Address routerId = m_spfroot->GetVertexId ();
01371
01372
01373
01374
01375
01376 NodeList::Iterator i = NodeList::Begin ();
01377 for (; i != NodeList::End (); i++)
01378 {
01379 Ptr<Node> node = *i;
01380
01381 Ptr<GlobalRouter> rtr =
01382 node->GetObject<GlobalRouter> ();
01383
01384
01385
01386
01387 if (rtr == 0)
01388 {
01389 continue;
01390 }
01391
01392 if (rtr->GetRouterId () == routerId)
01393 {
01394
01395
01396
01397
01398
01399
01400 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
01401 NS_ASSERT_MSG (ipv4,
01402 "GlobalRouteManagerImpl::FindOutgoingTypeId (): "
01403 "QI for <Ipv4> interface failed");
01404
01405
01406
01407
01408
01409 return (ipv4->GetIfIndexByAddress (a, amask) );
01410 }
01411 }
01412
01413
01414
01415 return 0;
01416 }
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434 void
01435 GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
01436 {
01437 NS_LOG_FUNCTION (v);
01438
01439 NS_ASSERT_MSG (m_spfroot,
01440 "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
01441
01442
01443
01444
01445
01446
01447
01448 Ipv4Address routerId = m_spfroot->GetVertexId ();
01449
01450 NS_LOG_LOGIC ("Vertex ID = " << routerId);
01451
01452
01453
01454
01455
01456 NodeList::Iterator i = NodeList::Begin ();
01457 for (; i != NodeList::End (); i++)
01458 {
01459 Ptr<Node> node = *i;
01460
01461
01462
01463
01464
01465 Ptr<GlobalRouter> rtr =
01466 node->GetObject<GlobalRouter> ();
01467
01468 if (rtr == 0)
01469 {
01470 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<
01471 node->GetId ());
01472 continue;
01473 }
01474
01475
01476
01477
01478
01479 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
01480
01481 if (rtr->GetRouterId () == routerId)
01482 {
01483 NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
01484
01485
01486
01487
01488
01489 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
01490 NS_ASSERT_MSG (ipv4,
01491 "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
01492 "QI for <Ipv4> interface failed");
01493
01494
01495
01496
01497
01498
01499 GlobalRoutingLSA *lsa = v->GetLSA ();
01500 NS_ASSERT_MSG (lsa,
01501 "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
01502 "Expected valid LSA in SPFVertex* v");
01503
01504 uint32_t nLinkRecords = lsa->GetNLinkRecords ();
01505
01506
01507
01508
01509
01510
01511
01512
01513 NS_LOG_LOGIC (" Node " << node->GetId () <<
01514 " found " << nLinkRecords << " link records in LSA " << lsa << "with LinkStateId "<< lsa->GetLinkStateId ());
01515 for (uint32_t j = 0; j < nLinkRecords; ++j)
01516 {
01517
01518
01519
01520 GlobalRoutingLinkRecord *lr = lsa->GetLinkRecord (j);
01521 if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint)
01522 {
01523 continue;
01524 }
01525
01526 NS_LOG_LOGIC (" Node " << node->GetId () <<
01527 " add route to " << lr->GetLinkData () <<
01528 " using next hop " << v->GetNextHop () <<
01529 " via interface " << v->GetOutgoingTypeId ());
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
01544 NS_ASSERT (gr);
01545 gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
01546 v->GetOutgoingTypeId ());
01547 }
01548
01549
01550
01551 return;
01552 }
01553 }
01554 }
01555 void
01556 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
01557 {
01558 NS_LOG_FUNCTION (v);
01559
01560 NS_ASSERT_MSG (m_spfroot,
01561 "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
01562
01563
01564
01565
01566
01567
01568
01569 Ipv4Address routerId = m_spfroot->GetVertexId ();
01570
01571 NS_LOG_LOGIC ("Vertex ID = " << routerId);
01572
01573
01574
01575
01576
01577 NodeList::Iterator i = NodeList::Begin ();
01578 for (; i != NodeList::End (); i++)
01579 {
01580 Ptr<Node> node = *i;
01581
01582
01583
01584
01585
01586 Ptr<GlobalRouter> rtr =
01587 node->GetObject<GlobalRouter> ();
01588
01589 if (rtr == 0)
01590 {
01591 NS_LOG_LOGIC ("No GlobalRouter interface on node " <<
01592 node->GetId ());
01593 continue;
01594 }
01595
01596
01597
01598
01599
01600 NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
01601
01602 if (rtr->GetRouterId () == routerId)
01603 {
01604 NS_LOG_LOGIC ("setting routes for node " << node->GetId ());
01605
01606
01607
01608
01609
01610 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
01611 NS_ASSERT_MSG (ipv4,
01612 "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
01613 "QI for <Ipv4> interface failed");
01614
01615
01616
01617
01618
01619
01620 GlobalRoutingLSA *lsa = v->GetLSA ();
01621 NS_ASSERT_MSG (lsa,
01622 "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
01623 "Expected valid LSA in SPFVertex* v");
01624 Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
01625 Ipv4Address tempip = lsa->GetLinkStateId ();
01626 tempip = tempip.CombineMask (tempmask);
01627 Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
01628 NS_ASSERT (gr);
01629 gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
01630 v->GetOutgoingTypeId ());
01631 NS_LOG_LOGIC ("Node " << node->GetId () <<
01632 " add network route to " << tempip <<
01633 " using next hop " << v->GetNextHop () <<
01634 " via interface " << v->GetOutgoingTypeId ());
01635 }
01636 }
01637 }
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650 void
01651 GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
01652 {
01653 NS_LOG_FUNCTION (v);
01654 v->GetParent ()->AddChild (v);
01655 }
01656
01657 void
01658 GlobalRouteManagerImpl::AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto)
01659 {
01660 NS_LOG_FUNCTION (nodeId);
01661 m_routingProtocols.push_back
01662 (std::pair<uint32_t, Ptr<Ipv4GlobalRouting> > (nodeId, proto));
01663 m_routingProtocols.sort ();
01664 }
01665
01666 Ptr<Ipv4GlobalRouting>
01667 GlobalRouteManagerImpl::GetGlobalRoutingProtocol (uint32_t nodeId)
01668 {
01669 for (Ipv4GlobalRoutingList::const_iterator rprotoIter = m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end (); rprotoIter++)
01670 {
01671 if ((*rprotoIter).first == nodeId)
01672 {
01673 return (*rprotoIter).second;
01674 }
01675 }
01676 return 0;
01677 }
01678
01679
01680 }
01681
01682 #ifdef RUN_SELF_TESTS
01683
01684
01685
01686
01687
01688
01689
01690 #include "ns3/test.h"
01691 #include "ns3/simulator.h"
01692 #include <stdlib.h>
01693
01694 namespace ns3 {
01695
01696 class GlobalRouteManagerImplTest : public Test {
01697 public:
01698 GlobalRouteManagerImplTest ();
01699 virtual ~GlobalRouteManagerImplTest ();
01700 virtual bool RunTests (void);
01701 };
01702
01703 GlobalRouteManagerImplTest::GlobalRouteManagerImplTest ()
01704 : Test ("GlobalRouteManagerImpl")
01705 {
01706 }
01707
01708 GlobalRouteManagerImplTest::~GlobalRouteManagerImplTest ()
01709 {}
01710
01711 bool
01712 GlobalRouteManagerImplTest::RunTests (void)
01713 {
01714 bool ok = true;
01715
01716 CandidateQueue candidate;
01717
01718 for (int i = 0; i < 100; ++i)
01719 {
01720 SPFVertex *v = new SPFVertex;
01721 v->SetDistanceFromRoot (rand () % 100);
01722 candidate.Push (v);
01723 }
01724
01725 uint32_t lastDistance = 0;
01726
01727 for (int i = 0; i < 100; ++i)
01728 {
01729 SPFVertex *v = candidate.Pop ();
01730 if (v->GetDistanceFromRoot () < lastDistance)
01731 {
01732 ok = false;
01733 }
01734 lastDistance = v->GetDistanceFromRoot ();
01735 delete v;
01736 v = 0;
01737 }
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755 GlobalRoutingLinkRecord* lr0 = new GlobalRoutingLinkRecord (
01756 GlobalRoutingLinkRecord::PointToPoint,
01757 "0.0.0.2",
01758 "10.1.1.1",
01759 1);
01760
01761 GlobalRoutingLinkRecord* lr1 = new GlobalRoutingLinkRecord (
01762 GlobalRoutingLinkRecord::StubNetwork,
01763 "10.1.1.1",
01764 "255.255.255.252",
01765 1);
01766
01767 GlobalRoutingLSA* lsa0 = new GlobalRoutingLSA ();
01768 lsa0->SetLSType (GlobalRoutingLSA::RouterLSA);
01769 lsa0->SetLinkStateId ("0.0.0.0");
01770 lsa0->SetAdvertisingRouter ("0.0.0.0");
01771 lsa0->AddLinkRecord (lr0);
01772 lsa0->AddLinkRecord (lr1);
01773
01774
01775 GlobalRoutingLinkRecord* lr2 = new GlobalRoutingLinkRecord (
01776 GlobalRoutingLinkRecord::PointToPoint,
01777 "0.0.0.2",
01778 "10.1.2.1",
01779 1);
01780
01781 GlobalRoutingLinkRecord* lr3 = new GlobalRoutingLinkRecord (
01782 GlobalRoutingLinkRecord::StubNetwork,
01783 "10.1.2.1",
01784 "255.255.255.252",
01785 1);
01786
01787 GlobalRoutingLSA* lsa1 = new GlobalRoutingLSA ();
01788 lsa1->SetLSType (GlobalRoutingLSA::RouterLSA);
01789 lsa1->SetLinkStateId ("0.0.0.1");
01790 lsa1->SetAdvertisingRouter ("0.0.0.1");
01791 lsa1->AddLinkRecord (lr2);
01792 lsa1->AddLinkRecord (lr3);
01793
01794
01795 GlobalRoutingLinkRecord* lr4 = new GlobalRoutingLinkRecord (
01796 GlobalRoutingLinkRecord::PointToPoint,
01797 "0.0.0.0",
01798 "10.1.1.2",
01799 1);
01800
01801 GlobalRoutingLinkRecord* lr5 = new GlobalRoutingLinkRecord (
01802 GlobalRoutingLinkRecord::StubNetwork,
01803 "10.1.1.2",
01804 "255.255.255.252",
01805 1);
01806
01807 GlobalRoutingLinkRecord* lr6 = new GlobalRoutingLinkRecord (
01808 GlobalRoutingLinkRecord::PointToPoint,
01809 "0.0.0.1",
01810 "10.1.2.2",
01811 1);
01812
01813 GlobalRoutingLinkRecord* lr7 = new GlobalRoutingLinkRecord (
01814 GlobalRoutingLinkRecord::StubNetwork,
01815 "10.1.2.2",
01816 "255.255.255.252",
01817 1);
01818
01819 GlobalRoutingLinkRecord* lr8 = new GlobalRoutingLinkRecord (
01820 GlobalRoutingLinkRecord::PointToPoint,
01821 "0.0.0.3",
01822 "10.1.3.2",
01823 1);
01824
01825 GlobalRoutingLinkRecord* lr9 = new GlobalRoutingLinkRecord (
01826 GlobalRoutingLinkRecord::StubNetwork,
01827 "10.1.3.2",
01828 "255.255.255.252",
01829 1);
01830
01831 GlobalRoutingLSA* lsa2 = new GlobalRoutingLSA ();
01832 lsa2->SetLSType (GlobalRoutingLSA::RouterLSA);
01833 lsa2->SetLinkStateId ("0.0.0.2");
01834 lsa2->SetAdvertisingRouter ("0.0.0.2");
01835 lsa2->AddLinkRecord (lr4);
01836 lsa2->AddLinkRecord (lr5);
01837 lsa2->AddLinkRecord (lr6);
01838 lsa2->AddLinkRecord (lr7);
01839 lsa2->AddLinkRecord (lr8);
01840 lsa2->AddLinkRecord (lr9);
01841
01842
01843 GlobalRoutingLinkRecord* lr10 = new GlobalRoutingLinkRecord (
01844 GlobalRoutingLinkRecord::PointToPoint,
01845 "0.0.0.2",
01846 "10.1.2.1",
01847 1);
01848
01849 GlobalRoutingLinkRecord* lr11 = new GlobalRoutingLinkRecord (
01850 GlobalRoutingLinkRecord::StubNetwork,
01851 "10.1.2.1",
01852 "255.255.255.252",
01853 1);
01854
01855 GlobalRoutingLSA* lsa3 = new GlobalRoutingLSA ();
01856 lsa3->SetLSType (GlobalRoutingLSA::RouterLSA);
01857 lsa3->SetLinkStateId ("0.0.0.3");
01858 lsa3->SetAdvertisingRouter ("0.0.0.3");
01859 lsa3->AddLinkRecord (lr10);
01860 lsa3->AddLinkRecord (lr11);
01861
01862
01863 GlobalRouteManagerLSDB* srmlsdb = new GlobalRouteManagerLSDB ();
01864 srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0);
01865 srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1);
01866 srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2);
01867 srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3);
01868 NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ()));
01869
01870
01871 GlobalRouteManagerImpl* srm = new GlobalRouteManagerImpl ();
01872 srm->DebugUseLsdb (srmlsdb);
01873
01874
01875 srm->DebugSPFCalculate (lsa0->GetLinkStateId ());
01876
01877 Simulator::Run ();
01878
01879
01880
01881 Simulator::Destroy ();
01882
01883
01884
01885 delete srm;
01886
01887 return ok;
01888 }
01889
01890
01891 static GlobalRouteManagerImplTest g_globalRouteManagerTest;
01892
01893 }
01894
01895 #endif