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");
406 os <<
"========== Global Routing LSA ==========" << std::endl;
410 os <<
" (GlobalRoutingLSA::RouterLSA)";
414 os <<
" (GlobalRoutingLSA::NetworkLSA)";
418 os <<
" (GlobalRoutingLSA::ASExternalLSA)";
422 os <<
"(Unknown LSType)";
426 os <<
"m_linkStateId = " <<
m_linkStateId <<
" (Router ID)" << std::endl;
427 os <<
"m_advertisingRtr = " <<
m_advertisingRtr <<
" (Router ID)" << std::endl;
431 for ( ListOfLinkRecords_t::const_iterator i =
m_linkRecords.begin ();
437 os <<
"---------- RouterLSA Link Record ----------" << std::endl;
441 os <<
" (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
442 os <<
"m_linkId = " << p->
m_linkId << std::endl;
443 os <<
"m_linkData = " << p->
m_linkData << std::endl;
444 os <<
"m_metric = " << p->
m_metric << std::endl;
448 os <<
" (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
449 os <<
"m_linkId = " << p->
m_linkId <<
" (Designated router for network)" << std::endl;
450 os <<
"m_linkData = " << p->
m_linkData <<
" (This router's IP address)" << std::endl;
451 os <<
"m_metric = " << p->
m_metric << std::endl;
455 os <<
" (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
456 os <<
"m_linkId = " << p->
m_linkId <<
" (Network number of attached network)" << std::endl;
457 os <<
"m_linkData = " << p->
m_linkData <<
" (Network mask of attached network)" << std::endl;
458 os <<
"m_metric = " << p->
m_metric << std::endl;
462 os <<
" (Unknown LinkType)" << std::endl;
463 os <<
"m_linkId = " << p->
m_linkId << std::endl;
464 os <<
"m_linkData = " << p->
m_linkData << std::endl;
465 os <<
"m_metric = " << p->
m_metric << std::endl;
467 os <<
"---------- End RouterLSA Link Record ----------" << std::endl;
472 os <<
"---------- NetworkLSA Link Record ----------" << std::endl;
477 os <<
"attachedRouter = " << p << std::endl;
479 os <<
"---------- End NetworkLSA Link Record ----------" << std::endl;
483 os <<
"---------- ASExternalLSA Link Record --------" << std::endl;
491 os <<
"========== End Global Routing LSA ==========" << std::endl;
558 for ( ListOfLSAs_t::iterator i =
m_LSAs.begin ();
592 NS_ABORT_MSG_UNLESS (node,
"GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
610 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
634 for (uint32_t i = 0; i < numDevices; ++i)
648 NS_ABORT_MSG_IF (rc,
"GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
657 bool isForwarding =
false;
670 NS_LOG_LOGIC (
"Net device " << ndLocal <<
"has no IP interface or is not enabled for forwarding, skipping");
696 NS_ASSERT_MSG (0,
"GlobalRouter::DiscoverLSAs (): unknown link type");
709 uint32_t nDesignatedRouters = c.
GetN ();
710 if (nDesignatedRouters > 0)
756 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
768 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
773 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
777 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
781 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
782 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
808 maskLocalAddr.
Set (maskLocal.
Get ());
835 if (desigRtr !=
"255.255.255.255")
840 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
842 if (desigRtr == addrLocal)
863 NS_ASSERT_MSG (nd->
IsBridge (),
"GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
877 NS_ABORT_MSG_UNLESS (bnd,
"GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
888 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
893 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
897 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
901 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
902 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
913 bool areTransitNetwork =
false;
916 for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
927 areTransitNetwork =
true;
942 if (desigRtrTemp !=
"255.255.255.255")
947 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
949 if (desigRtrTemp < desigRtr)
951 desigRtr = desigRtrTemp;
961 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
963 if (areTransitNetwork ==
false)
981 maskLocalAddr.
Set (maskLocal.
Get ());
1002 if (desigRtr == addrLocal)
1035 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1039 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
1043 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1046 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
1047 uint16_t metricLocal = ipv4Local->
GetMetric (interfaceLocal);
1071 "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
1087 Ipv4Address rtrIdRemote = rtrRemote->GetRouterId ();
1088 NS_LOG_LOGIC (
"Working with remote router " << rtrIdRemote);
1096 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
1104 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1108 NS_LOG_LOGIC (
"Working with remote address " << addrRemote);
1116 if (ipv4Remote->
IsUp (interfaceRemote))
1118 NS_LOG_LOGIC (
"Remote side interface " << interfaceRemote <<
" is up-- add a type 1 link");
1121 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1132 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1146 uint32_t nDesignatedRouters = c.
GetN ();
1148 for (uint32_t i = 0; i < nDesignatedRouters; ++i)
1158 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1162 NS_ABORT_MSG_IF (rc ==
false,
"GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
1166 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1172 NS_ABORT_MSG_IF (pLSA == 0,
"GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
1190 for (uint32_t i = 0; i < nDevices; i++)
1210 uint32_t tempInterface = 0;
1215 if (!tempIpv4->
IsUp (tempInterface))
1217 NS_LOG_LOGIC (
"Remote side interface " << tempInterface <<
" not up");
1223 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1250 NS_LOG_LOGIC (
"Looking for designated router off of net device " << ndLocal <<
" on node " <<
1259 for (uint32_t i = 0; i < nDevices; i++)
1266 NS_LOG_LOGIC (
"Examine channel device " << i <<
" on node " << nodeOther->
GetId ());
1274 NS_LOG_LOGIC (
"checking to see if the device is bridged");
1278 NS_LOG_LOGIC (
"Device is bridged by BridgeNetDevice " << bnd);
1289 NS_LOG_LOGIC (
"Checking for router on bridge net device " << bnd);
1298 NS_LOG_LOGIC (
"Found router on bridge net device " << bnd);
1299 if (!ipv4->IsUp (interfaceOther))
1301 NS_LOG_LOGIC (
"Remote side interface " << interfaceOther <<
" not up");
1304 if (ipv4->GetNAddresses (interfaceOther) > 1)
1306 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1308 Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
1309 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1314 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bnd);
1315 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1318 NS_LOG_LOGIC (
"Examining bridge port " << j <<
" device " << ndBridged);
1319 if (ndBridged == ndOther)
1321 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
1327 NS_LOG_LOGIC (
"Recursively looking for routers down bridge port " << ndBridged);
1329 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1352 if (!ipv4->IsUp (interfaceOther))
1354 NS_LOG_LOGIC (
"Remote side interface " << interfaceOther <<
" not up");
1357 NS_LOG_LOGIC (
"Found router on net device " << ndOther);
1358 if (ipv4->GetNAddresses (interfaceOther) > 1)
1360 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1362 Ipv4Address addrOther = ipv4->GetAddress (interfaceOther, 0).GetLocal ();
1363 desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1398 for (uint32_t i = 0; i < nDevices; i++)
1424 NS_LOG_LOGIC (
"Device is bridged by net device " << bnd);
1425 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bnd);
1426 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1429 NS_LOG_LOGIC (
"Examining bridge port " << j <<
" device " << ndBridged);
1430 if (ndBridged == ndOther)
1438 NS_LOG_LOGIC (
"Recursively looking for routers on bridge port " << ndBridged);
1441 NS_LOG_LOGIC (
"Found routers on bridge port, return true");
1446 NS_LOG_LOGIC (
"No routers on bridged net device, return false");
1457 NS_LOG_LOGIC (
"Found GlobalRouter interface, return true");
1462 NS_LOG_LOGIC (
"No GlobalRouter interface on device, continue search");
1489 ListOfLSAs_t::const_iterator i =
m_LSAs.begin ();
1492 for (; i !=
m_LSAs.end (); i++, j++)
1573 if ((*i)->GetDestNetwork () == network && (*i)->GetDestNetworkMask () == networkMask)
1575 NS_LOG_LOGIC (
"Withdrawing route to network/mask " << network <<
"/" << networkMask);
1615 "GlobalRouter::GetAdjacent (): Wrong or confused channel?");
1640 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); ++i )
1642 if (ipv4->GetNetDevice (i) == nd)
1644 NS_LOG_LOGIC (
"Device " << nd <<
" has associated ipv4 index " << i);
1650 NS_LOG_LOGIC (
"Device " << nd <<
" has no associated ipv4 index");
1671 for (uint32_t i = 0; i < nDevices; ++i)
1674 NS_LOG_LOGIC (
"Examine device " << i <<
" " << ndTest);
1678 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
1680 NS_ABORT_MSG_UNLESS (bnd,
"GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1682 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1684 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
1685 if (bnd->GetBridgePort (j) == nd)
1687 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
1693 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");