22 #include "ns3/assert.h"
23 #include "ns3/abort.h"
24 #include "ns3/channel.h"
25 #include "ns3/net-device.h"
27 #include "ns3/node-list.h"
29 #include "ns3/bridge-net-device.h"
47 m_linkData (
"0.0.0.0"),
61 m_linkData (linkData),
62 m_linkType (linkType),
139 m_linkStateId (
"0.0.0.0"),
140 m_advertisingRtr (
"0.0.0.0"),
142 m_networkLSANetworkMask (
"0.0.0.0"),
143 m_attachedRouters (),
156 m_linkStateId (linkStateId),
157 m_advertisingRtr (advertisingRtr),
159 m_networkLSANetworkMask (
"0.0.0.0"),
160 m_attachedRouters (),
168 : m_lsType (lsa.m_lsType), m_linkStateId (lsa.m_linkStateId),
169 m_advertisingRtr (lsa.m_advertisingRtr),
170 m_networkLSANetworkMask (lsa.m_networkLSANetworkMask),
171 m_status (lsa.m_status),
172 m_node_id (lsa.m_node_id)
176 "GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor");
200 for (ListOfLinkRecords_t::const_iterator i = lsa.
m_linkRecords.begin ();
229 for ( ListOfLinkRecords_t::iterator i =
m_linkRecords.begin ();
265 for ( ListOfLinkRecords_t::const_iterator i =
m_linkRecords.begin ();
274 NS_ASSERT_MSG (
false,
"GlobalRoutingLSA::GetLinkRecord (): invalid index");
377 NS_ASSERT_MSG (
false,
"GlobalRoutingLSA::GetAttachedRouter (): invalid index");
407 os <<
"========== Global Routing LSA ==========" << std::endl;
411 os <<
" (GlobalRoutingLSA::RouterLSA)";
415 os <<
" (GlobalRoutingLSA::NetworkLSA)";
419 os <<
" (GlobalRoutingLSA::ASExternalLSA)";
423 os <<
"(Unknown LSType)";
427 os <<
"m_linkStateId = " <<
m_linkStateId <<
" (Router ID)" << std::endl;
428 os <<
"m_advertisingRtr = " <<
m_advertisingRtr <<
" (Router ID)" << std::endl;
432 for ( ListOfLinkRecords_t::const_iterator i =
m_linkRecords.begin ();
438 os <<
"---------- RouterLSA Link Record ----------" << std::endl;
442 os <<
" (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
443 os <<
"m_linkId = " << p->
m_linkId << std::endl;
444 os <<
"m_linkData = " << p->
m_linkData << std::endl;
445 os <<
"m_metric = " << p->
m_metric << std::endl;
449 os <<
" (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
450 os <<
"m_linkId = " << p->
m_linkId <<
" (Designated router for network)" << std::endl;
451 os <<
"m_linkData = " << p->
m_linkData <<
" (This router's IP address)" << std::endl;
452 os <<
"m_metric = " << p->
m_metric << std::endl;
456 os <<
" (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
457 os <<
"m_linkId = " << p->
m_linkId <<
" (Network number of attached network)" << std::endl;
458 os <<
"m_linkData = " << p->
m_linkData <<
" (Network mask of attached network)" << std::endl;
459 os <<
"m_metric = " << p->
m_metric << std::endl;
463 os <<
" (Unknown LinkType)" << std::endl;
464 os <<
"m_linkId = " << p->
m_linkId << std::endl;
465 os <<
"m_linkData = " << p->
m_linkData << std::endl;
466 os <<
"m_metric = " << p->
m_metric << std::endl;
468 os <<
"---------- End RouterLSA Link Record ----------" << std::endl;
473 os <<
"---------- NetworkLSA Link Record ----------" << std::endl;
478 os <<
"attachedRouter = " << p << std::endl;
480 os <<
"---------- End NetworkLSA Link Record ----------" << std::endl;
484 os <<
"---------- ASExternalLSA Link Record --------" << std::endl;
492 os <<
"========== End Global Routing LSA ==========" << std::endl;
561 for ( ListOfLSAs_t::iterator i =
m_LSAs.begin ();
595 NS_ABORT_MSG_UNLESS (node,
"GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
613 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
637 for (uint32_t i = 0; i < numDevices; ++i)
651 NS_ABORT_MSG_IF (rc,
"GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
660 bool isForwarding =
false;
673 NS_LOG_LOGIC (
"Net device " << ndLocal <<
"has no IP interface or is not enabled for forwarding, skipping");
699 NS_ASSERT_MSG (0,
"GlobalRouter::DiscoverLSAs (): unknown link type");
712 uint32_t nDesignatedRouters = c.
GetN ();
713 if (nDesignatedRouters > 0)
759 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
771 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
776 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
780 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
784 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
785 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
811 maskLocalAddr.
Set (maskLocal.
Get ());
838 if (desigRtr !=
"255.255.255.255")
843 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
845 if (desigRtr == addrLocal)
866 NS_ASSERT_MSG (nd->
IsBridge (),
"GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
880 NS_ABORT_MSG_UNLESS (bnd,
"GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
891 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
896 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
900 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
904 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
905 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
916 bool areTransitNetwork =
false;
919 for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
930 areTransitNetwork =
true;
945 if (desigRtrTemp !=
"255.255.255.255")
950 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
952 if (desigRtrTemp < desigRtr)
954 desigRtr = desigRtrTemp;
964 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
966 if (areTransitNetwork ==
false)
984 maskLocalAddr.
Set (maskLocal.
Get ());
1005 if (desigRtr == addrLocal)
1038 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1042 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
1046 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1049 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
1050 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
1074 "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
1090 Ipv4Address rtrIdRemote = rtrRemote->GetRouterId ();
1091 NS_LOG_LOGIC (
"Working with remote router " << rtrIdRemote);
1099 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1107 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1111 NS_LOG_LOGIC (
"Working with remote address " << addrRemote);
1119 if (ipv4Remote->
IsUp (interfaceRemote))
1121 NS_LOG_LOGIC (
"Remote side interface " << interfaceRemote <<
" is up-- add a type 1 link");
1124 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1135 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1149 uint32_t nDesignatedRouters = c.
GetN ();
1151 for (uint32_t i = 0; i < nDesignatedRouters; ++i)
1161 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1165 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
1169 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1175 NS_ABORT_MSG_IF (pLSA == 0,
"GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
1193 for (uint32_t i = 0; i < nDevices; i++)
1213 uint32_t tempInterface = 0;
1218 if (!tempIpv4->
IsUp (tempInterface))
1220 NS_LOG_LOGIC (
"Remote side interface " << tempInterface <<
" not up");
1226 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1253 NS_LOG_LOGIC (
"Looking for designated router off of net device " << ndLocal <<
" on node " <<
1262 for (uint32_t i = 0; i < nDevices; i++)
1269 NS_LOG_LOGIC (
"Examine channel device " << i <<
" on node " << nodeOther->
GetId ());
1277 NS_LOG_LOGIC (
"checking to see if the device is bridged");
1281 NS_LOG_LOGIC (
"Device is bridged by BridgeNetDevice " << bnd);
1292 NS_LOG_LOGIC (
"Checking for router on bridge net device " << bnd);
1301 NS_LOG_LOGIC (
"Found router on bridge net device " << bnd);
1302 if (!ipv4->IsUp (interfaceOther))
1304 NS_LOG_LOGIC (
"Remote side interface " << interfaceOther <<
" not up");
1307 if (ipv4->GetNAddresses (interfaceOther) > 1)
1309 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1311 Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
1312 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1317 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bnd);
1318 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1321 NS_LOG_LOGIC (
"Examining bridge port " << j <<
" device " << ndBridged);
1322 if (ndBridged == ndOther)
1324 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
1330 NS_LOG_LOGIC (
"Recursively looking for routers down bridge port " << ndBridged);
1332 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1355 if (!ipv4->IsUp (interfaceOther))
1357 NS_LOG_LOGIC (
"Remote side interface " << interfaceOther <<
" not up");
1360 NS_LOG_LOGIC (
"Found router on net device " << ndOther);
1361 if (ipv4->GetNAddresses (interfaceOther) > 1)
1363 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1365 Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
1366 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1401 for (uint32_t i = 0; i < nDevices; i++)
1427 NS_LOG_LOGIC (
"Device is bridged by net device " << bnd);
1428 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bnd);
1429 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1432 NS_LOG_LOGIC (
"Examining bridge port " << j <<
" device " << ndBridged);
1433 if (ndBridged == ndOther)
1441 NS_LOG_LOGIC (
"Recursively looking for routers on bridge port " << ndBridged);
1444 NS_LOG_LOGIC (
"Found routers on bridge port, return true");
1449 NS_LOG_LOGIC (
"No routers on bridged net device, return false");
1460 NS_LOG_LOGIC (
"Found GlobalRouter interface, return true");
1465 NS_LOG_LOGIC (
"No GlobalRouter interface on device, continue search");
1492 ListOfLSAs_t::const_iterator i =
m_LSAs.begin ();
1495 for (; i !=
m_LSAs.end (); i++, j++)
1577 if ((*i)->GetDestNetwork () == network && (*i)->GetDestNetworkMask () == networkMask)
1579 NS_LOG_LOGIC (
"Withdrawing route to network/mask " << network <<
"/" << networkMask);
1619 "GlobalRouter::GetAdjacent (): Wrong or confused channel?");
1644 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); ++i )
1646 if (ipv4->GetNetDevice (i) == nd)
1648 NS_LOG_LOGIC (
"Device " << nd <<
" has associated ipv4 index " << i);
1654 NS_LOG_LOGIC (
"Device " << nd <<
" has no associated ipv4 index");
1675 for (uint32_t i = 0; i < nDevices; ++i)
1678 NS_LOG_LOGIC (
"Examine device " << i <<
" " << ndTest);
1682 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
1684 NS_ABORT_MSG_UNLESS (bnd,
"GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1686 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1688 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
1689 if (bnd->GetBridgePort (j) == nd)
1691 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
1697 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");