00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ns3/log.h"
00022 #include "ns3/assert.h"
00023 #include "ns3/abort.h"
00024 #include "ns3/channel.h"
00025 #include "ns3/net-device.h"
00026 #include "ns3/node.h"
00027 #include "ns3/ipv4.h"
00028 #include "ns3/bridge-net-device.h"
00029 #include "ns3/net-device-container.h"
00030 #include "global-router-interface.h"
00031 #include <vector>
00032
00033 NS_LOG_COMPONENT_DEFINE ("GlobalRouter");
00034
00035 namespace ns3 {
00036
00037
00038
00039
00040
00041
00042
00043 GlobalRoutingLinkRecord::GlobalRoutingLinkRecord ()
00044 :
00045 m_linkId ("0.0.0.0"),
00046 m_linkData ("0.0.0.0"),
00047 m_linkType (Unknown),
00048 m_metric (0)
00049 {
00050 NS_LOG_FUNCTION_NOARGS ();
00051 }
00052
00053 GlobalRoutingLinkRecord::GlobalRoutingLinkRecord (
00054 LinkType linkType,
00055 Ipv4Address linkId,
00056 Ipv4Address linkData,
00057 uint16_t metric)
00058 :
00059 m_linkId (linkId),
00060 m_linkData (linkData),
00061 m_linkType (linkType),
00062 m_metric (metric)
00063 {
00064 NS_LOG_FUNCTION (this << linkType << linkId << linkData << metric);
00065 }
00066
00067 GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord ()
00068 {
00069 NS_LOG_FUNCTION_NOARGS ();
00070 }
00071
00072 Ipv4Address
00073 GlobalRoutingLinkRecord::GetLinkId (void) const
00074 {
00075 NS_LOG_FUNCTION_NOARGS ();
00076 return m_linkId;
00077 }
00078
00079 void
00080 GlobalRoutingLinkRecord::SetLinkId (Ipv4Address addr)
00081 {
00082 NS_LOG_FUNCTION_NOARGS ();
00083 m_linkId = addr;
00084 }
00085
00086 Ipv4Address
00087 GlobalRoutingLinkRecord::GetLinkData (void) const
00088 {
00089 NS_LOG_FUNCTION_NOARGS ();
00090 return m_linkData;
00091 }
00092
00093 void
00094 GlobalRoutingLinkRecord::SetLinkData (Ipv4Address addr)
00095 {
00096 NS_LOG_FUNCTION_NOARGS ();
00097 m_linkData = addr;
00098 }
00099
00100 GlobalRoutingLinkRecord::LinkType
00101 GlobalRoutingLinkRecord::GetLinkType (void) const
00102 {
00103 NS_LOG_FUNCTION_NOARGS ();
00104 return m_linkType;
00105 }
00106
00107 void
00108 GlobalRoutingLinkRecord::SetLinkType (
00109 GlobalRoutingLinkRecord::LinkType linkType)
00110 {
00111 NS_LOG_FUNCTION_NOARGS ();
00112 m_linkType = linkType;
00113 }
00114
00115 uint16_t
00116 GlobalRoutingLinkRecord::GetMetric (void) const
00117 {
00118 NS_LOG_FUNCTION_NOARGS ();
00119 return m_metric;
00120 }
00121
00122 void
00123 GlobalRoutingLinkRecord::SetMetric (uint16_t metric)
00124 {
00125 NS_LOG_FUNCTION_NOARGS ();
00126 m_metric = metric;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 GlobalRoutingLSA::GlobalRoutingLSA()
00136 :
00137 m_lsType (GlobalRoutingLSA::Unknown),
00138 m_linkStateId("0.0.0.0"),
00139 m_advertisingRtr("0.0.0.0"),
00140 m_linkRecords(),
00141 m_networkLSANetworkMask("0.0.0.0"),
00142 m_attachedRouters(),
00143 m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
00144 {
00145 NS_LOG_FUNCTION_NOARGS ();
00146 }
00147
00148 GlobalRoutingLSA::GlobalRoutingLSA (
00149 GlobalRoutingLSA::SPFStatus status,
00150 Ipv4Address linkStateId,
00151 Ipv4Address advertisingRtr)
00152 :
00153 m_lsType (GlobalRoutingLSA::Unknown),
00154 m_linkStateId(linkStateId),
00155 m_advertisingRtr(advertisingRtr),
00156 m_linkRecords(),
00157 m_networkLSANetworkMask("0.0.0.0"),
00158 m_attachedRouters(),
00159 m_status(status)
00160 {
00161 NS_LOG_FUNCTION (this << status << linkStateId << advertisingRtr);
00162 }
00163
00164 GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa)
00165 : m_lsType(lsa.m_lsType), m_linkStateId(lsa.m_linkStateId),
00166 m_advertisingRtr(lsa.m_advertisingRtr),
00167 m_networkLSANetworkMask(lsa.m_networkLSANetworkMask),
00168 m_status(lsa.m_status)
00169 {
00170 NS_LOG_FUNCTION_NOARGS ();
00171 NS_ASSERT_MSG(IsEmpty(),
00172 "GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor");
00173 CopyLinkRecords (lsa);
00174 }
00175
00176 GlobalRoutingLSA&
00177 GlobalRoutingLSA::operator= (const GlobalRoutingLSA& lsa)
00178 {
00179 NS_LOG_FUNCTION_NOARGS ();
00180 m_lsType = lsa.m_lsType;
00181 m_linkStateId = lsa.m_linkStateId;
00182 m_advertisingRtr = lsa.m_advertisingRtr;
00183 m_networkLSANetworkMask = lsa.m_networkLSANetworkMask,
00184 m_status = lsa.m_status;
00185
00186 ClearLinkRecords ();
00187 CopyLinkRecords (lsa);
00188 return *this;
00189 }
00190
00191 void
00192 GlobalRoutingLSA::CopyLinkRecords (const GlobalRoutingLSA& lsa)
00193 {
00194 NS_LOG_FUNCTION_NOARGS ();
00195 for (ListOfLinkRecords_t::const_iterator i = lsa.m_linkRecords.begin ();
00196 i != lsa.m_linkRecords.end ();
00197 i++)
00198 {
00199 GlobalRoutingLinkRecord *pSrc = *i;
00200 GlobalRoutingLinkRecord *pDst = new GlobalRoutingLinkRecord;
00201
00202 pDst->SetLinkType (pSrc->GetLinkType ());
00203 pDst->SetLinkId (pSrc->GetLinkId ());
00204 pDst->SetLinkData (pSrc->GetLinkData ());
00205 pDst->SetMetric (pSrc->GetMetric ());
00206
00207 m_linkRecords.push_back(pDst);
00208 pDst = 0;
00209 }
00210
00211 m_attachedRouters = lsa.m_attachedRouters;
00212 }
00213
00214 GlobalRoutingLSA::~GlobalRoutingLSA()
00215 {
00216 NS_LOG_FUNCTION_NOARGS ();
00217 ClearLinkRecords ();
00218 }
00219
00220 void
00221 GlobalRoutingLSA::ClearLinkRecords(void)
00222 {
00223 NS_LOG_FUNCTION_NOARGS ();
00224 for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
00225 i != m_linkRecords.end ();
00226 i++)
00227 {
00228 NS_LOG_LOGIC ("Free link record");
00229
00230 GlobalRoutingLinkRecord *p = *i;
00231 delete p;
00232 p = 0;
00233
00234 *i = 0;
00235 }
00236 NS_LOG_LOGIC ("Clear list");
00237 m_linkRecords.clear();
00238 }
00239
00240 uint32_t
00241 GlobalRoutingLSA::AddLinkRecord (GlobalRoutingLinkRecord* lr)
00242 {
00243 NS_LOG_FUNCTION_NOARGS ();
00244 m_linkRecords.push_back (lr);
00245 return m_linkRecords.size ();
00246 }
00247
00248 uint32_t
00249 GlobalRoutingLSA::GetNLinkRecords (void) const
00250 {
00251 NS_LOG_FUNCTION_NOARGS ();
00252 return m_linkRecords.size ();
00253 }
00254
00255 GlobalRoutingLinkRecord *
00256 GlobalRoutingLSA::GetLinkRecord (uint32_t n) const
00257 {
00258 NS_LOG_FUNCTION_NOARGS ();
00259 uint32_t j = 0;
00260 for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin ();
00261 i != m_linkRecords.end ();
00262 i++, j++)
00263 {
00264 if (j == n)
00265 {
00266 return *i;
00267 }
00268 }
00269 NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetLinkRecord (): invalid index");
00270 return 0;
00271 }
00272
00273 bool
00274 GlobalRoutingLSA::IsEmpty (void) const
00275 {
00276 NS_LOG_FUNCTION_NOARGS ();
00277 return m_linkRecords.size () == 0;
00278 }
00279
00280 GlobalRoutingLSA::LSType
00281 GlobalRoutingLSA::GetLSType (void) const
00282 {
00283 NS_LOG_FUNCTION_NOARGS ();
00284 return m_lsType;
00285 }
00286
00287 void
00288 GlobalRoutingLSA::SetLSType (GlobalRoutingLSA::LSType typ)
00289 {
00290 NS_LOG_FUNCTION_NOARGS ();
00291 m_lsType = typ;
00292 }
00293
00294 Ipv4Address
00295 GlobalRoutingLSA::GetLinkStateId (void) const
00296 {
00297 NS_LOG_FUNCTION_NOARGS ();
00298 return m_linkStateId;
00299 }
00300
00301 void
00302 GlobalRoutingLSA::SetLinkStateId (Ipv4Address addr)
00303 {
00304 NS_LOG_FUNCTION_NOARGS ();
00305 m_linkStateId = addr;
00306 }
00307
00308 Ipv4Address
00309 GlobalRoutingLSA::GetAdvertisingRouter (void) const
00310 {
00311 NS_LOG_FUNCTION_NOARGS ();
00312 return m_advertisingRtr;
00313 }
00314
00315 void
00316 GlobalRoutingLSA::SetAdvertisingRouter (Ipv4Address addr)
00317 {
00318 NS_LOG_FUNCTION_NOARGS ();
00319 m_advertisingRtr = addr;
00320 }
00321
00322 void
00323 GlobalRoutingLSA::SetNetworkLSANetworkMask (Ipv4Mask mask)
00324 {
00325 NS_LOG_FUNCTION_NOARGS ();
00326 m_networkLSANetworkMask = mask;
00327 }
00328
00329 Ipv4Mask
00330 GlobalRoutingLSA::GetNetworkLSANetworkMask (void) const
00331 {
00332 NS_LOG_FUNCTION_NOARGS ();
00333 return m_networkLSANetworkMask;
00334 }
00335
00336 GlobalRoutingLSA::SPFStatus
00337 GlobalRoutingLSA::GetStatus (void) const
00338 {
00339 NS_LOG_FUNCTION_NOARGS ();
00340 return m_status;
00341 }
00342
00343 uint32_t
00344 GlobalRoutingLSA::AddAttachedRouter (Ipv4Address addr)
00345 {
00346 NS_LOG_FUNCTION_NOARGS ();
00347 m_attachedRouters.push_back (addr);
00348 return m_attachedRouters.size ();
00349 }
00350
00351 uint32_t
00352 GlobalRoutingLSA::GetNAttachedRouters (void) const
00353 {
00354 NS_LOG_FUNCTION_NOARGS ();
00355 return m_attachedRouters.size ();
00356 }
00357
00358 Ipv4Address
00359 GlobalRoutingLSA::GetAttachedRouter (uint32_t n) const
00360 {
00361 NS_LOG_FUNCTION_NOARGS ();
00362 uint32_t j = 0;
00363 for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin ();
00364 i != m_attachedRouters.end ();
00365 i++, j++)
00366 {
00367 if (j == n)
00368 {
00369 return *i;
00370 }
00371 }
00372 NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
00373 return Ipv4Address("0.0.0.0");
00374 }
00375
00376 void
00377 GlobalRoutingLSA::SetStatus (GlobalRoutingLSA::SPFStatus status)
00378 {
00379 NS_LOG_FUNCTION_NOARGS ();
00380 m_status = status;
00381 }
00382
00383 void
00384 GlobalRoutingLSA::Print (std::ostream &os) const
00385 {
00386 os << std::endl;
00387 os << "========== Global Routing LSA ==========" << std::endl;
00388 os << "m_lsType = " << m_lsType;
00389 if (m_lsType == GlobalRoutingLSA::RouterLSA)
00390 {
00391 os << " (GlobalRoutingLSA::RouterLSA)";
00392 }
00393 else if (m_lsType == GlobalRoutingLSA::NetworkLSA)
00394 {
00395 os << " (GlobalRoutingLSA::NetworkLSA)";
00396 }
00397 else
00398 {
00399 os << "(Unknown LSType)";
00400 }
00401 os << std::endl;
00402
00403 os << "m_linkStateId = " << m_linkStateId << " (Router ID)" << std::endl;
00404 os << "m_advertisingRtr = " << m_advertisingRtr << " (Router ID)" << std::endl;
00405
00406 if (m_lsType == GlobalRoutingLSA::RouterLSA)
00407 {
00408 for ( ListOfLinkRecords_t::const_iterator i = m_linkRecords.begin ();
00409 i != m_linkRecords.end ();
00410 i++)
00411 {
00412 GlobalRoutingLinkRecord *p = *i;
00413
00414 os << "---------- RouterLSA Link Record ----------" << std::endl;
00415 os << "m_linkType = " << p->m_linkType;
00416 if (p->m_linkType == GlobalRoutingLinkRecord::PointToPoint)
00417 {
00418 os << " (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
00419 os << "m_linkId = " << p->m_linkId << std::endl;
00420 os << "m_linkData = " << p->m_linkData << std::endl;
00421 os << "m_metric = " << p->m_metric << std::endl;
00422 }
00423 else if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork)
00424 {
00425 os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
00426 os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl;
00427 os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl;
00428 os << "m_metric = " << p->m_metric << std::endl;
00429 }
00430 else if (p->m_linkType == GlobalRoutingLinkRecord::StubNetwork)
00431 {
00432 os << " (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
00433 os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl;
00434 os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl;
00435 os << "m_metric = " << p->m_metric << std::endl;
00436 }
00437 else
00438 {
00439 os << " (Unknown LinkType)" << std::endl;
00440 os << "m_linkId = " << p->m_linkId << std::endl;
00441 os << "m_linkData = " << p->m_linkData << std::endl;
00442 os << "m_metric = " << p->m_metric << std::endl;
00443 }
00444 os << "---------- End RouterLSA Link Record ----------" << std::endl;
00445 }
00446 }
00447 else if (m_lsType == GlobalRoutingLSA::NetworkLSA)
00448 {
00449 os << "---------- NetworkLSA Link Record ----------" << std::endl;
00450 os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl;
00451 for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); i != m_attachedRouters.end (); i++)
00452 {
00453 Ipv4Address p = *i;
00454 os << "attachedRouter = " << p << std::endl;
00455 }
00456 os << "---------- End NetworkLSA Link Record ----------" << std::endl;
00457 }
00458 else
00459 {
00460 NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
00461 }
00462 os << "========== End Global Routing LSA ==========" << std::endl;
00463 }
00464
00465 std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa)
00466 {
00467 lsa.Print (os);
00468 return os;
00469 }
00470
00471
00472
00473
00474
00475
00476
00477 NS_OBJECT_ENSURE_REGISTERED (GlobalRouter);
00478
00479 TypeId
00480 GlobalRouter::GetTypeId (void)
00481 {
00482 static TypeId tid = TypeId ("ns3::GlobalRouter")
00483 .SetParent<Object> ();
00484 return tid;
00485 }
00486
00487 GlobalRouter::GlobalRouter ()
00488 : m_LSAs()
00489 {
00490 NS_LOG_FUNCTION_NOARGS ();
00491 m_routerId.Set(GlobalRouteManager::AllocateRouterId ());
00492 }
00493
00494 GlobalRouter::~GlobalRouter ()
00495 {
00496 NS_LOG_FUNCTION_NOARGS ();
00497 ClearLSAs();
00498 }
00499
00500 void
00501 GlobalRouter::DoDispose ()
00502 {
00503 NS_LOG_FUNCTION_NOARGS ();
00504 Object::DoDispose ();
00505 }
00506
00507 void
00508 GlobalRouter::ClearLSAs ()
00509 {
00510 NS_LOG_FUNCTION_NOARGS ();
00511 for ( ListOfLSAs_t::iterator i = m_LSAs.begin ();
00512 i != m_LSAs.end ();
00513 i++)
00514 {
00515 NS_LOG_LOGIC ("Free LSA");
00516
00517 GlobalRoutingLSA *p = *i;
00518 delete p;
00519 p = 0;
00520
00521 *i = 0;
00522 }
00523 NS_LOG_LOGIC ("Clear list of LSAs");
00524 m_LSAs.clear();
00525 }
00526
00527 Ipv4Address
00528 GlobalRouter::GetRouterId (void) const
00529 {
00530 NS_LOG_FUNCTION_NOARGS ();
00531 return m_routerId;
00532 }
00533
00534
00535
00536
00537
00538
00539
00540 uint32_t
00541 GlobalRouter::DiscoverLSAs (void)
00542 {
00543 NS_LOG_FUNCTION_NOARGS ();
00544 Ptr<Node> node = GetObject<Node> ();
00545 NS_ABORT_MSG_UNLESS (node, "GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
00546 NS_LOG_LOGIC ("For node " << node->GetId () );
00547
00548 ClearLSAs ();
00549
00550
00551
00552
00553
00554
00555 NetDeviceContainer c;
00556
00557
00558
00559
00560
00561
00562 Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
00563 NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
00564
00565
00566
00567
00568 GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
00569 pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
00570 pLSA->SetLinkStateId (m_routerId);
00571 pLSA->SetAdvertisingRouter (m_routerId);
00572 pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
00573
00574
00575
00576
00577
00578
00579
00580 uint32_t numDevices = node->GetNDevices();
00581
00582
00583
00584
00585
00586 for (uint32_t i = 0; i < numDevices; ++i)
00587 {
00588 Ptr<NetDevice> ndLocal = node->GetDevice(i);
00589
00590
00591
00592
00593
00594
00595 if (NetDeviceIsBridged (ndLocal))
00596 {
00597 uint32_t ifIndexBridge;
00598 bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexBridge);
00599 NS_ABORT_MSG_IF (rc, "GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
00600 }
00601
00602
00603
00604
00605
00606
00607
00608 bool isIp = false;
00609 for (uint32_t j = 0; j < ipv4Local->GetNInterfaces (); ++j )
00610 {
00611 if (ipv4Local->GetNetDevice (j) == ndLocal && ipv4Local->IsUp (j))
00612 {
00613 isIp = true;
00614 break;
00615 }
00616 }
00617
00618 if (!isIp)
00619 {
00620 NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface, skipping");
00621 continue;
00622 }
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633 if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
00634 {
00635 NS_LOG_LOGIC ("Broadcast link");
00636 ProcessBroadcastLink (ndLocal, pLSA, c);
00637 }
00638 else if (ndLocal->IsPointToPoint () )
00639 {
00640 NS_LOG_LOGIC ("Point=to-point link");
00641 ProcessPointToPointLink (ndLocal, pLSA);
00642 }
00643 else
00644 {
00645 NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
00646 }
00647 }
00648
00649 NS_LOG_LOGIC ("========== LSA for node " << node->GetId () << " ==========");
00650 NS_LOG_LOGIC (*pLSA);
00651 m_LSAs.push_back (pLSA);
00652 pLSA = 0;
00653
00654
00655
00656
00657
00658 uint32_t nDesignatedRouters = c.GetN ();
00659 if (nDesignatedRouters > 0)
00660 {
00661 NS_LOG_LOGIC ("Build Network LSAs");
00662 BuildNetworkLSAs (c);
00663 }
00664
00665 return m_LSAs.size ();
00666 }
00667
00668 void
00669 GlobalRouter::ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
00670 {
00671 NS_LOG_FUNCTION (nd << pLSA << &c);
00672
00673 if (nd->IsBridge ())
00674 {
00675 ProcessBridgedBroadcastLink (nd, pLSA, c);
00676 }
00677 else
00678 {
00679 ProcessSingleBroadcastLink (nd, pLSA, c);
00680 }
00681 }
00682
00683 void
00684 GlobalRouter::ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
00685 {
00686 NS_LOG_FUNCTION (nd << pLSA << &c);
00687
00688 GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
00689 NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
00690
00691
00692
00693
00694
00695
00696
00697
00698 Ptr<Node> node = nd->GetNode ();
00699
00700 uint32_t ifIndexLocal;
00701 bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
00702 NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
00703
00704 Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
00705 NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
00706
00707 Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
00708 Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
00709 NS_LOG_LOGIC ("Working with local address " << addrLocal);
00710 uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
00711
00712
00713
00714
00715
00716
00717
00718 if (AnotherRouterOnLink (nd, true) == false)
00719 {
00720
00721
00722
00723 NS_LOG_LOGIC("Router-LSA Stub Network");
00724 plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
00725
00726
00727
00728
00729
00730 plr->SetLinkId (addrLocal.CombineMask(maskLocal));
00731
00732
00733
00734
00735 Ipv4Address maskLocalAddr;
00736 maskLocalAddr.Set(maskLocal.Get ());
00737 plr->SetLinkData (maskLocalAddr);
00738 plr->SetMetric (metricLocal);
00739 pLSA->AddLinkRecord(plr);
00740 plr = 0;
00741 }
00742 else
00743 {
00744
00745
00746
00747
00748 NS_LOG_LOGIC ("Router-LSA Transit Network");
00749 plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
00750
00751
00752
00753
00754
00755
00756
00757 Ipv4Address desigRtr = FindDesignatedRouterForLink (nd, true);
00758
00759
00760
00761
00762
00763 if (desigRtr != "255.255.255.255")
00764 {
00765 Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
00766 Ipv4Address networkThere = desigRtr.CombineMask (maskLocal);
00767 NS_ABORT_MSG_UNLESS (networkHere == networkThere,
00768 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
00769 }
00770 if (desigRtr == addrLocal)
00771 {
00772 c.Add (nd);
00773 NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
00774 }
00775 plr->SetLinkId (desigRtr);
00776
00777
00778
00779
00780 plr->SetLinkData (addrLocal);
00781 plr->SetMetric (metricLocal);
00782 pLSA->AddLinkRecord (plr);
00783 plr = 0;
00784 }
00785 }
00786
00787 void
00788 GlobalRouter::ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
00789 {
00790 NS_LOG_FUNCTION (nd << pLSA << &c);
00791 NS_ASSERT_MSG (nd->IsBridge (), "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
00792
00793 #if 0
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
00805 NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
00806
00807
00808
00809
00810
00811
00812
00813
00814 Ptr<Node> node = nd->GetNode ();
00815
00816 uint32_t ifIndexLocal;
00817 bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
00818 NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
00819
00820 Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
00821 NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
00822
00823 Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
00824 Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
00825 NS_LOG_LOGIC ("Working with local address " << addrLocal);
00826 uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837 bool areTransitNetwork = false;
00838 Ipv4Address desigRtr ("255.255.255.255");
00839
00840 for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
00841 {
00842 Ptr<NetDevice> ndTemp = bnd->GetBridgePort (i);
00843
00844
00845
00846
00847
00848
00849 if (AnotherRouterOnLink (ndTemp, true))
00850 {
00851 areTransitNetwork = true;
00852
00853
00854
00855
00856
00857
00858
00859
00860 Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp, true);
00861
00862
00863
00864
00865
00866 if (desigRtrTemp != "255.255.255.255")
00867 {
00868 Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
00869 Ipv4Address networkThere = desigRtrTemp.CombineMask (maskLocal);
00870 NS_ABORT_MSG_UNLESS (networkHere == networkThere,
00871 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
00872 }
00873 if (desigRtrTemp < desigRtr)
00874 {
00875 desigRtr = desigRtrTemp;
00876 }
00877 }
00878 }
00879
00880
00881
00882
00883
00884 GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
00885 NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
00886
00887 if (areTransitNetwork == false)
00888 {
00889
00890
00891
00892 NS_LOG_LOGIC("Router-LSA Stub Network");
00893 plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
00894
00895
00896
00897
00898
00899 plr->SetLinkId (addrLocal.CombineMask(maskLocal));
00900
00901
00902
00903
00904 Ipv4Address maskLocalAddr;
00905 maskLocalAddr.Set(maskLocal.Get ());
00906 plr->SetLinkData (maskLocalAddr);
00907 plr->SetMetric (metricLocal);
00908 pLSA->AddLinkRecord(plr);
00909 plr = 0;
00910 }
00911 else
00912 {
00913
00914
00915
00916
00917 NS_LOG_LOGIC ("Router-LSA Transit Network");
00918 plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
00919
00920
00921
00922
00923
00924
00925
00926 if (desigRtr == addrLocal)
00927 {
00928 c.Add (nd);
00929 NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
00930 }
00931 plr->SetLinkId (desigRtr);
00932
00933
00934
00935
00936 plr->SetLinkData (addrLocal);
00937 plr->SetMetric (metricLocal);
00938 pLSA->AddLinkRecord (plr);
00939 plr = 0;
00940 }
00941 #endif
00942 }
00943
00944 void
00945 GlobalRouter::ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA)
00946 {
00947 NS_LOG_FUNCTION (ndLocal << pLSA);
00948
00949
00950
00951
00952
00953
00954
00955
00956 Ptr<Node> nodeLocal = ndLocal->GetNode ();
00957
00958 uint32_t ifIndexLocal;
00959 bool rc = FindIfIndexForDevice(nodeLocal, ndLocal, ifIndexLocal);
00960 NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
00961
00962 Ptr<Ipv4> ipv4Local = nodeLocal->GetObject<Ipv4> ();
00963 NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
00964
00965 Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
00966 Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
00967 NS_LOG_LOGIC ("Working with local address " << addrLocal);
00968 uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
00969
00970
00971
00972
00973
00974
00975 Ptr<Channel> ch = ndLocal->GetChannel();
00976
00977
00978
00979
00980 Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
00981
00982
00983
00984
00985
00986
00987
00988
00989 Ptr<Node> nodeRemote = ndRemote->GetNode();
00990 Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
00991 NS_ABORT_MSG_UNLESS (ipv4Remote,
00992 "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
00993
00994
00995
00996
00997
00998
00999 Ptr<GlobalRouter> rtrRemote = nodeRemote->GetObject<GlobalRouter> ();
01000 NS_ABORT_MSG_UNLESS(rtrRemote,
01001 "GlobalRouter::ProcessPointToPointLinks(): GetObject for remote <GlobalRouter> failed");
01002
01003
01004
01005
01006 Ipv4Address rtrIdRemote = rtrRemote->GetRouterId();
01007 NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
01008
01009
01010
01011
01012
01013 uint32_t ifIndexRemote;
01014 rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
01015 NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
01016
01017
01018
01019
01020
01021 Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
01022 Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
01023 NS_LOG_LOGIC ("Working with remote address " << addrRemote);
01024
01025
01026
01027
01028
01029
01030 GlobalRoutingLinkRecord *plr;
01031 if (ipv4Remote->IsUp (ifIndexRemote))
01032 {
01033 NS_LOG_LOGIC ("Remote side interface " << ifIndexRemote << " is up-- add a type 1 link");
01034
01035 plr = new GlobalRoutingLinkRecord;
01036 NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
01037 plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
01038 plr->SetLinkId (rtrIdRemote);
01039 plr->SetLinkData (addrLocal);
01040 plr->SetMetric (metricLocal);
01041 pLSA->AddLinkRecord (plr);
01042 plr = 0;
01043 }
01044
01045
01046 plr = new GlobalRoutingLinkRecord;
01047 NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
01048 plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
01049 plr->SetLinkId (addrRemote);
01050 plr->SetLinkData (Ipv4Address(maskRemote.Get()));
01051 plr->SetMetric (metricLocal);
01052 pLSA->AddLinkRecord (plr);
01053 plr = 0;
01054 }
01055
01056 void
01057 GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c)
01058 {
01059 NS_LOG_FUNCTION (&c);
01060
01061 uint32_t nDesignatedRouters = c.GetN ();
01062
01063 for (uint32_t i = 0; i < nDesignatedRouters; ++i)
01064 {
01065
01066
01067
01068
01069 Ptr<NetDevice> ndLocal = c.Get (i);
01070 Ptr<Node> node = ndLocal->GetNode ();
01071
01072 uint32_t ifIndexLocal;
01073 bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
01074 NS_ABORT_MSG_IF (rc == false, "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
01075
01076 Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
01077 NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
01078
01079 Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
01080 Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
01081
01082 GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
01083 NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
01084
01085 pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA);
01086 pLSA->SetLinkStateId (addrLocal);
01087 pLSA->SetAdvertisingRouter (m_routerId);
01088 pLSA->SetNetworkLSANetworkMask (maskLocal);
01089 pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
01090
01091
01092
01093
01094
01095
01096 Ptr<Channel> ch = ndLocal->GetChannel();
01097 uint32_t nDevices = ch->GetNDevices();
01098 NS_ASSERT (nDevices);
01099
01100 for (uint32_t i = 0; i < nDevices; i++)
01101 {
01102 Ptr<NetDevice> tempNd = ch->GetDevice (i);
01103 NS_ASSERT (tempNd);
01104 Ptr<Node> tempNode = tempNd->GetNode ();
01105
01106
01107
01108
01109
01110 Ptr<GlobalRouter> rtr = tempNode->GetObject<GlobalRouter> ();
01111 if (rtr == 0)
01112 {
01113 continue;
01114 }
01115
01116
01117
01118
01119
01120 uint32_t tempIfIndex;
01121 if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
01122 {
01123 Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
01124 NS_ASSERT (tempIpv4);
01125 if (!tempIpv4->IsUp (tempIfIndex))
01126 {
01127 NS_LOG_LOGIC ("Remote side interface " << tempIfIndex << " not up");
01128 }
01129 else
01130 {
01131 Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
01132 pLSA->AddAttachedRouter (tempAddr);
01133 }
01134 }
01135 }
01136 m_LSAs.push_back (pLSA);
01137 pLSA = 0;
01138 }
01139 }
01140
01141
01142
01143
01144
01145
01146
01147 Ipv4Address
01148 GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const
01149 {
01150 NS_LOG_FUNCTION (ndLocal << allowRecursion);
01151
01152 Ptr<Channel> ch = ndLocal->GetChannel();
01153 uint32_t nDevices = ch->GetNDevices();
01154 NS_ASSERT (nDevices);
01155
01156 NS_LOG_LOGIC ("Looking for designated router off of net device " << ndLocal << " on node " <<
01157 ndLocal->GetNode ()->GetId ());
01158
01159 Ipv4Address desigRtr ("255.255.255.255");
01160
01161
01162
01163
01164
01165 for (uint32_t i = 0; i < nDevices; i++)
01166 {
01167 Ptr<NetDevice> ndOther = ch->GetDevice (i);
01168 NS_ASSERT (ndOther);
01169
01170 Ptr<Node> nodeOther = ndOther->GetNode ();
01171
01172 NS_LOG_LOGIC ("Examine channel device " << i << " on node " << nodeOther->GetId ());
01173
01174
01175
01176
01177
01178
01179
01180 NS_LOG_LOGIC ("checking to see if the device is bridged");
01181 Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
01182 if (bnd)
01183 {
01184 NS_LOG_LOGIC ("Device is bridged by BridgeNetDevice " << bnd);
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195 NS_LOG_LOGIC ("Checking for router on bridge net device " << bnd);
01196 Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
01197 Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
01198 if (rtr && ipv4)
01199 {
01200 uint32_t ifIndexOther;
01201 if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
01202 {
01203 NS_LOG_LOGIC ("Found router on bridge net device " << bnd);
01204 if (!ipv4->IsUp (ifIndexOther))
01205 {
01206 NS_LOG_LOGIC ("Remote side interface " << ifIndexOther << " not up");
01207 continue;
01208 }
01209 Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
01210 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
01211 NS_LOG_LOGIC ("designated router now " << desigRtr);
01212 }
01213 }
01214
01215 NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
01216 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
01217 {
01218 Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
01219 NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
01220 if (ndBridged == ndOther)
01221 {
01222 NS_LOG_LOGIC ("That bridge port is me, don't walk backward");
01223 continue;
01224 }
01225
01226 if (allowRecursion)
01227 {
01228 NS_LOG_LOGIC ("Recursively looking for routers down bridge port " << ndBridged);
01229 Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false);
01230 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
01231 NS_LOG_LOGIC ("designated router now " << desigRtr);
01232 }
01233 }
01234 }
01235 else
01236 {
01237 NS_LOG_LOGIC ("This device is not bridged");
01238 Ptr<Node> nodeOther = ndOther->GetNode ();
01239 NS_ASSERT (nodeOther);
01240
01241
01242
01243
01244
01245 Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
01246 Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
01247 if (rtr && ipv4)
01248 {
01249 uint32_t ifIndexOther;
01250 if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
01251 {
01252 if (!ipv4->IsUp (ifIndexOther))
01253 {
01254 NS_LOG_LOGIC ("Remote side interface " << ifIndexOther << " not up");
01255 continue;
01256 }
01257 NS_LOG_LOGIC ("Found router on net device " << ndOther);
01258 Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
01259 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
01260 NS_LOG_LOGIC ("designated router now " << desigRtr);
01261 }
01262 }
01263 }
01264 }
01265 return desigRtr;
01266 }
01267
01268
01269
01270
01271
01272
01273
01274 bool
01275 GlobalRouter::AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const
01276 {
01277 NS_LOG_FUNCTION (nd << allowRecursion);
01278
01279 Ptr<Channel> ch = nd->GetChannel();
01280 if (!ch)
01281 {
01282
01283 return false;
01284 }
01285 uint32_t nDevices = ch->GetNDevices();
01286 NS_ASSERT (nDevices);
01287
01288 NS_LOG_LOGIC ("Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ());
01289
01290
01291
01292
01293
01294 for (uint32_t i = 0; i < nDevices; i++)
01295 {
01296 Ptr<NetDevice> ndOther = ch->GetDevice (i);
01297 NS_ASSERT (ndOther);
01298
01299 NS_LOG_LOGIC ("Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ());
01300
01301
01302
01303
01304 if (ndOther == nd)
01305 {
01306 NS_LOG_LOGIC ("Myself, skip");
01307 continue;
01308 }
01309
01310
01311
01312
01313
01314
01315
01316 NS_LOG_LOGIC ("checking to see if device is bridged");
01317 Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
01318 if (bnd)
01319 {
01320 NS_LOG_LOGIC ("Device is bridged by net device " << bnd);
01321 NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
01322 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
01323 {
01324 Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
01325 NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
01326 if (ndBridged == ndOther)
01327 {
01328 NS_LOG_LOGIC ("That bridge port is me, skip");
01329 continue;
01330 }
01331
01332 if (allowRecursion)
01333 {
01334 NS_LOG_LOGIC ("Recursively looking for routers on bridge port " << ndBridged);
01335 if (AnotherRouterOnLink (ndBridged, false))
01336 {
01337 NS_LOG_LOGIC ("Found routers on bridge port, return true");
01338 return true;
01339 }
01340 }
01341 }
01342 NS_LOG_LOGIC ("No routers on bridged net device, return false");
01343 return false;
01344 }
01345
01346 NS_LOG_LOGIC ("This device is not bridged");
01347 Ptr<Node> nodeTemp = ndOther->GetNode ();
01348 NS_ASSERT (nodeTemp);
01349
01350 Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
01351 if (rtr)
01352 {
01353 NS_LOG_LOGIC ("Found GlobalRouter interface, return true");
01354 return true;
01355 }
01356 else
01357 {
01358 NS_LOG_LOGIC ("No GlobalRouter interface on device, continue search");
01359 }
01360 }
01361 NS_LOG_LOGIC ("No routers found, return false");
01362 return false;
01363 }
01364
01365 uint32_t
01366 GlobalRouter::GetNumLSAs (void) const
01367 {
01368 NS_LOG_FUNCTION_NOARGS ();
01369 return m_LSAs.size ();
01370 }
01371
01372
01373
01374
01375 bool
01376 GlobalRouter::GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const
01377 {
01378 NS_LOG_FUNCTION_NOARGS ();
01379 NS_ASSERT_MSG(lsa.IsEmpty(), "GlobalRouter::GetLSA (): Must pass empty LSA");
01380
01381
01382
01383
01384
01385 ListOfLSAs_t::const_iterator i = m_LSAs.begin ();
01386 uint32_t j = 0;
01387
01388 for (; i != m_LSAs.end (); i++, j++)
01389 {
01390 if (j == n)
01391 {
01392 GlobalRoutingLSA *p = *i;
01393 lsa = *p;
01394 return true;
01395 }
01396 }
01397
01398 return false;
01399 }
01400
01401
01402
01403
01404
01405 Ptr<NetDevice>
01406 GlobalRouter::GetAdjacent (Ptr<NetDevice> nd, Ptr<Channel> ch) const
01407 {
01408 NS_LOG_FUNCTION_NOARGS ();
01409 NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices");
01410
01411
01412
01413 Ptr<NetDevice> nd1 = ch->GetDevice(0);
01414 Ptr<NetDevice> nd2 = ch->GetDevice(1);
01415
01416
01417
01418
01419
01420 if (nd1 == nd)
01421 {
01422 return nd2;
01423 }
01424 else if (nd2 == nd)
01425 {
01426 return nd1;
01427 }
01428 else
01429 {
01430 NS_ASSERT_MSG(false,
01431 "GlobalRouter::GetAdjacent (): Wrong or confused channel?");
01432 return 0;
01433 }
01434 }
01435
01436
01437
01438
01439
01440
01441
01442
01443 bool
01444 GlobalRouter::FindIfIndexForDevice (Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const
01445 {
01446 NS_LOG_FUNCTION_NOARGS ();
01447 NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd );
01448
01449 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
01450 if (ipv4 == 0)
01451 {
01452 NS_LOG_LOGIC ("No Ipv4 interface on node " << node->GetId ());
01453 return false;
01454 }
01455
01456 for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
01457 {
01458 if (ipv4->GetNetDevice(i) == nd)
01459 {
01460 NS_LOG_LOGIC ("Device " << nd << " has associated ipv4 index " << i);
01461 index = i;
01462 return true;
01463 }
01464 }
01465
01466 NS_LOG_LOGIC ("Device " << nd << " has no associated ipv4 index");
01467 return false;
01468 }
01469
01470
01471
01472
01473 Ptr<BridgeNetDevice>
01474 GlobalRouter::NetDeviceIsBridged (Ptr<NetDevice> nd) const
01475 {
01476 NS_LOG_FUNCTION (nd);
01477
01478 Ptr<Node> node = nd->GetNode ();
01479 uint32_t nDevices = node->GetNDevices();
01480
01481
01482
01483
01484
01485
01486
01487 for (uint32_t i = 0; i < nDevices; ++i)
01488 {
01489 Ptr<NetDevice> ndTest = node->GetDevice(i);
01490 NS_LOG_LOGIC ("Examine device " << i << " " << ndTest);
01491
01492 if (ndTest->IsBridge ())
01493 {
01494 NS_LOG_LOGIC ("device " << i << " is a bridge net device");
01495 Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> ();
01496 NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
01497
01498 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
01499 {
01500 NS_LOG_LOGIC ("Examine bridge port " << j << " " << bnd->GetBridgePort (j));
01501 if (bnd->GetBridgePort (j) == nd)
01502 {
01503 NS_LOG_LOGIC ("Net device " << nd << " is bridged by " << bnd);
01504 return bnd;
01505 }
01506 }
01507 }
01508 }
01509 NS_LOG_LOGIC ("Net device " << nd << " is not bridged");
01510 return 0;
01511 }
01512
01513 }