16#include "ns3/assert.h"
17#include "ns3/bridge-net-device.h"
18#include "ns3/channel.h"
20#include "ns3/net-device.h"
21#include "ns3/node-list.h"
23#include "ns3/object-base.h"
189 m_linkStateId(linkStateId),
190 m_advertisingRtr(advertisingRtr),
210 NS_ASSERT_MSG(
IsEmpty(),
"GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor");
226 CopyLinkRecords(lsa);
246 m_linkRecords.push_back(pDst);
276 m_linkRecords.clear();
309 NS_ASSERT_MSG(
false,
"GlobalRoutingLSA::GetLinkRecord (): invalid index");
423 NS_ASSERT_MSG(
false,
"GlobalRoutingLSA::GetAttachedRouter (): invalid index");
424 return IpAddress::GetZero();
457 os <<
"========== Global Routing LSA ==========" << std::endl;
461 os <<
" (GlobalRoutingLSA::RouterLSA)";
465 os <<
" (GlobalRoutingLSA::NetworkLSA)";
469 os <<
" (GlobalRoutingLSA::ASExternalLSA)";
473 os <<
"(Unknown LSType)";
477 os <<
"m_linkStateId = " <<
m_linkStateId <<
" (Router ID)" << std::endl;
478 os <<
"m_advertisingRtr = " <<
m_advertisingRtr <<
" (Router ID)" << std::endl;
486 os <<
"---------- RouterLSA Link Record ----------" << std::endl;
490 os <<
" (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
491 os <<
"m_linkId = " << p->
m_linkId << std::endl;
492 os <<
"m_linkData = " << p->
m_linkData << std::endl;
493 os <<
"m_metric = " << p->
m_metric << std::endl;
497 os <<
" (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
498 os <<
"m_linkId = " << p->
m_linkId <<
" (Designated router for network)"
500 os <<
"m_linkData = " << p->
m_linkData <<
" (This router's IP address)"
502 os <<
"m_metric = " << p->
m_metric << std::endl;
506 os <<
" (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
507 os <<
"m_linkId = " << p->
m_linkId <<
" (Network number of attached network)"
509 os <<
"m_linkData = " << p->
m_linkData <<
" (Network mask of attached network)"
511 os <<
"m_metric = " << p->
m_metric << std::endl;
515 os <<
" (Unknown LinkType)" << std::endl;
516 os <<
"m_linkId = " << p->
m_linkId << std::endl;
517 os <<
"m_linkData = " << p->
m_linkData << std::endl;
520 os <<
"---------- End RouterLSA Link Record ----------" << std::endl;
525 os <<
"---------- NetworkLSA Link Record ----------" << std::endl;
526 os <<
"m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl;
529 os <<
"attachedRouter = " << *i << std::endl;
531 os <<
"---------- End NetworkLSA Link Record ----------" << std::endl;
535 os <<
"---------- ASExternalLSA Link Record --------" << std::endl;
536 os <<
"m_linkStateId = " << m_linkStateId << std::endl;
543 os <<
"========== End Global Routing LSA ==========" << std::endl;
573 static TypeId tid =
TypeId(
"ns3::" + name +
"GlobalRouter")
575 .SetGroupName(
"GlobalRouter")
576 .template AddConstructor<GlobalRouter<T>>();
675 "GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
694 "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
712 uint32_t numDevices = node->GetNDevices();
718 for (
uint32_t i = 0; i < numDevices; ++i)
734 int32_t ifIndex = ipLocal->GetInterfaceForDevice(ndLocal);
737 "GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
746 int32_t interfaceNumber = ipLocal->GetInterfaceForDevice(ndLocal);
747 if (interfaceNumber == -1 ||
748 !(ipLocal->IsUp(interfaceNumber) && ipLocal->IsForwarding(interfaceNumber)))
752 <<
"has no IP interface or is not enabled for forwarding, skipping");
766 if (ndLocal->IsBroadcast() && !ndLocal->IsPointToPoint())
771 else if (ndLocal->IsPointToPoint())
778 NS_ASSERT_MSG(0,
"GlobalRouter::DiscoverLSAs (): unknown link type");
782 NS_LOG_LOGIC(
"========== LSA for node " << node->GetId() <<
" ==========");
792 if (nDesignatedRouters > 0)
806 pLSA->SetLinkStateId((*i)->GetDestNetwork());
810 pLSA->SetNetworkLSANetworkMask((*i)->GetDestNetworkMask());
814 pLSA->SetNetworkLSANetworkMask((*i)->GetDestNetworkPrefix());
850 "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
864 "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
866 int32_t interfaceLocal = ipLocal->GetInterfaceForDevice(nd);
868 interfaceLocal == -1,
869 "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
871 if (ipLocal->GetNAddresses(interfaceLocal) > 1)
873 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
879 addrLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
883 addrLinkLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
884 addrLocal = ipLocal->GetAddress(interfaceLocal, 1).GetAddress();
890 maskLocal = ipLocal->GetAddress(interfaceLocal, 0).GetMask();
894 maskLocal = ipLocal->GetAddress(interfaceLocal, 1).GetPrefix();
896 NS_LOG_LOGIC(
"Working with local address " << addrLocal);
897 uint16_t metricLocal = ipLocal->GetMetric(interfaceLocal);
920 plr->SetLinkId(addrLocal.CombineMask(maskLocal));
924 plr->SetLinkId(addrLocal.CombinePrefix(maskLocal));
933 maskLocalAddr.Set(maskLocal.Get());
938 maskLocal.GetBytes(buf);
939 maskLocalAddr.Set(buf);
941 plr->SetLinkData(maskLocalAddr);
942 plr->SetMetric(metricLocal);
969 bool isRtrAllOnes =
false;
972 if (designatedRtr.IsBroadcast())
991 networkHere = addrLocal.CombineMask(maskLocal);
992 networkThere = designatedRtr.CombineMask(maskLocal);
996 networkHere = addrLocal.CombinePrefix(maskLocal);
997 networkThere = designatedRtr.CombinePrefix(maskLocal);
1000 networkHere == networkThere,
1001 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion ("
1002 << addrLocal <<
"/" << maskLocal.GetPrefixLength() <<
", " << designatedRtr
1003 <<
"/" << maskLocal.GetPrefixLength() <<
")");
1005 if (designatedRtr == addrLocal)
1008 NS_LOG_LOGIC(
"Node " << node->GetId() <<
" elected a designated router");
1010 plr->SetLinkId(designatedRtr);
1015 plr->SetLinkData(addrLocal);
1016 plr->SetLinkLocData(addrLinkLocal);
1017 plr->SetMetric(metricLocal);
1023template <
typename T>
1031 "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
1045 NS_ABORT_MSG_UNLESS (bnd,
"GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1055 Ptr<Ip> ipLocal = node->GetObject<
Ip> ();
1056 NS_ABORT_MSG_UNLESS (ipv4Local,
"GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
1058 int32_t interfaceLocal = ipLocal->GetInterfaceForDevice (nd);
1059 NS_ABORT_MSG_IF (interfaceLocal == -1,
"GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
1061 if (ipLocal->GetNAddresses (interfaceLocal) > 1)
1063 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
1069 addrLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
1073 addrLinkLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
1074 addrLocal = ipLocal->GetAddress(interfaceLocal, 1).GetAddress();
1080 maskLocal = ipLocal->GetAddress(interfaceLocal, 0).GetMask();
1084 maskLocal = ipLocal->GetAddress(interfaceLocal, 1).GetPrefix();
1086 NS_LOG_LOGIC (
"Working with local address " << addrLocal);
1087 uint16_t metricLocal = ipv4Local->GetMetric (interfaceLocal);
1098 bool areTransitNetwork =
false;
1101 for (
uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
1113 areTransitNetwork =
true;
1129 bool isRtrAllOnes =
false;
1132 if (designatedRtrTemp.IsBroadcast())
1134 isRtrAllOnes =
true;
1141 isRtrAllOnes =
true;
1151 networkHere = addrLocal.CombineMask(maskLocal);
1152 networkThere = designatedRtrTemp.CombineMask(maskLocal);
1156 networkHere = addrLocal.CombinePrefix(maskLocal);
1157 networkThere = designatedRtrTemp.CombinePrefix(maskLocal);
1160 networkHere == networkThere,
1161 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion ("
1162 << addrLocal <<
"/" << maskLocal.GetPrefixLength() <<
", " << designatedRtr
1163 <<
"/" << maskLocal.GetPrefixLength() <<
")");
1165 if (designatedRtrTemp < designatedRtr)
1167 designatedRtr = designatedRtrTemp;
1177 NS_ABORT_MSG_IF (plr == 0,
"GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
1179 if (areTransitNetwork ==
false)
1193 plr->
SetLinkId(addrLocal.CombineMask(maskLocal));
1197 plr->
SetLinkId(addrLocal.CombinePrefix(maskLocal));
1205 maskLocalAddr.Set(maskLocal.Get());
1210 maskLocal.GetBytes(buf);
1211 maskLocalAddr.Set(buf);
1233 if (designatedRtr == addrLocal)
1236 NS_LOG_LOGIC (
"Node " << node->GetId () <<
" elected a designated router");
1252template <
typename T>
1265 Ptr<Node> nodeLocal = ndLocal->GetNode();
1267 Ptr<Ip> ipLocal = nodeLocal->GetObject<
Ip>();
1270 "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1272 int32_t interfaceLocal = ipLocal->GetInterfaceForDevice(ndLocal);
1274 interfaceLocal == -1,
1275 "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
1277 if ((ipLocal->GetNAddresses(interfaceLocal) == 0))
1279 NS_LOG_LOGIC(
"Local interface " << interfaceLocal <<
" has no address");
1287 if (ipLocal->GetNAddresses(interfaceLocal) > 1)
1289 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1291 addrLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
1295 addrLinkLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
1296 if (ipLocal->GetNAddresses(interfaceLocal) >
1299 addrLocal = ipLocal->GetAddress(interfaceLocal, 1).GetAddress();
1305 maskLocal = ipLocal->GetAddress(interfaceLocal, 0).GetMask();
1309 if (ipLocal->GetNAddresses(interfaceLocal) >
1312 maskLocal = ipLocal->GetAddress(interfaceLocal, 1).GetPrefix();
1315 NS_LOG_LOGIC(
"Working with local address " << addrLocal);
1316 uint16_t metricLocal = ipLocal->GetMetric(interfaceLocal);
1337 Ptr<Node> nodeRemote = ndRemote->GetNode();
1338 Ptr<Ip> ipRemote = nodeRemote->GetObject<
Ip>();
1341 "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
1357 IpAddress rtrIdRemote = rtrRemote->GetRouterId();
1358 NS_LOG_LOGIC(
"Working with remote router " << rtrIdRemote);
1364 int32_t interfaceRemote = ipRemote->GetInterfaceForDevice(ndRemote);
1366 "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with "
1369 if ((ipRemote->GetNAddresses(interfaceRemote) == 0))
1371 NS_LOG_LOGIC(
"Remote interface " << interfaceRemote <<
" has no address");
1381 if (ipRemote->GetNAddresses(interfaceRemote) > 1)
1383 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1385 addrRemote = ipRemote->GetAddress(interfaceRemote, 0).GetAddress();
1389 if (ipRemote->GetNAddresses(interfaceRemote) >
1392 addrRemote = ipRemote->GetAddress(interfaceRemote, 1).GetAddress();
1398 maskRemote = ipRemote->GetAddress(interfaceRemote, 0).GetMask();
1402 if (ipRemote->GetNAddresses(interfaceRemote) >
1405 maskRemote = ipRemote->GetAddress(interfaceRemote, 1).GetPrefix();
1408 NS_LOG_LOGIC(
"Working with remote address " << addrRemote);
1417 if (ipRemote->IsUp(interfaceRemote))
1419 NS_LOG_LOGIC(
"Remote side interface " << interfaceRemote <<
" is up-- add a type 1 link");
1423 "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1438 if (ipRemote->GetNAddresses(interfaceRemote) == 1 &&
1439 ipRemote->GetAddress(interfaceRemote, 0).GetAddress().IsLinkLocal())
1441 NS_LOG_LOGIC(
"The remote interface only has a link local address, not adding a type 3 "
1449 "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1459 maskRemote.GetBytes(buf);
1467template <
typename T>
1474 NS_LOG_DEBUG(
"Number of designated routers: " << nDesignatedRouters);
1476 for (
uint32_t i = 0; i < nDesignatedRouters; ++i)
1485 Ptr<Ip> ipLocal = node->GetObject<
Ip>();
1488 "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1490 int32_t interfaceLocal = ipLocal->GetInterfaceForDevice(ndLocal);
1492 interfaceLocal == -1,
1493 "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
1495 if (ipLocal->GetNAddresses(interfaceLocal) > 1)
1497 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1502 addrLocal = ipLocal->GetAddress(interfaceLocal, 0).GetAddress();
1506 addrLocal = ipLocal->GetAddress(interfaceLocal, 1).GetAddress();
1511 maskLocal = ipLocal->GetAddress(interfaceLocal, 0).GetMask();
1515 maskLocal = ipLocal->GetAddress(interfaceLocal, 1).GetPrefix();
1520 "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
1523 pLSA->SetLinkStateId(addrLocal);
1525 pLSA->SetNetworkLSANetworkMask(maskLocal);
1527 pLSA->SetNode(node);
1536 std::size_t nDevices = ch->GetNDevices();
1539 NS_LOG_LOGIC(
"Found " << deviceList.
GetN() <<
" non-bridged devices on channel");
1545 if (tempNd == ndLocal)
1547 NS_LOG_LOGIC(
"Adding " << addrLocal <<
" to Network LSA");
1548 pLSA->AddAttachedRouter(addrLocal);
1560 <<
" does not have GlobalRouter interface--skipping");
1568 Ptr<Ip> tempIp = tempNode->GetObject<
Ip>();
1569 int32_t tempInterface = tempIp->GetInterfaceForDevice(tempNd);
1571 if (tempInterface != -1)
1573 Ptr<Ip> tempIp = tempNode->GetObject<
Ip>();
1575 if (!tempIp->IsUp(tempInterface))
1577 NS_LOG_LOGIC(
"Remote side interface " << tempInterface <<
" not up");
1581 if (tempIp->GetNAddresses(tempInterface) > 1)
1583 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1589 tempAddr = tempIp->GetAddress(tempInterface, 0).GetAddress();
1593 tempAddr = tempIp->GetAddress(tempInterface, 1).GetAddress();
1595 NS_LOG_LOGIC(
"Adding " << tempAddr <<
" to Network LSA");
1596 pLSA->AddAttachedRouter(tempAddr);
1601 NS_LOG_LOGIC(
"Node " << tempNode->GetId() <<
" device " << tempNd
1602 <<
" does not have IPv4 interface; skipping");
1606 NS_LOG_LOGIC(
"========== LSA for node " << node->GetId() <<
" ==========");
1612template <
typename T>
1619 for (std::size_t i = 0; i < ch->GetNDevices(); i++)
1622 NS_LOG_LOGIC(
"checking to see if the device " << nd <<
" is bridged");
1627 << bnd <<
" with " << bnd->GetNBridgePorts() <<
" ports");
1631 for (
uint32_t j = 0; j < bnd->GetNBridgePorts(); j++)
1634 if (bridgedDevice->GetChannel() == ch)
1639 NS_LOG_LOGIC(
"Calling on channel " << bridgedDevice->GetChannel());
1659template <
typename T>
1666 uint32_t nDevices = ch->GetNDevices();
1669 NS_LOG_LOGIC(
"Looking for designated router off of net device " << ndLocal <<
" on node "
1670 << ndLocal->GetNode()->GetId());
1686 for (
uint32_t i = 0; i < nDevices; i++)
1691 Ptr<Node> nodeOther = ndOther->GetNode();
1693 NS_LOG_LOGIC(
"Examine channel device " << i <<
" on node " << nodeOther->GetId());
1701 NS_LOG_LOGIC(
"checking to see if the device is bridged");
1705 NS_LOG_LOGIC(
"Device is bridged by BridgeNetDevice " << bnd);
1710 if (ndLocal == ndOther)
1725 NS_LOG_LOGIC(
"Checking for router on bridge net device " << bnd);
1727 Ptr<Ip> ip = nodeOther->GetObject<
Ip>();
1730 int32_t interfaceOther = ip->GetInterfaceForDevice(bnd);
1731 if (interfaceOther != -1)
1733 NS_LOG_LOGIC(
"Found router on bridge net device " << bnd);
1734 if (!ip->IsUp(interfaceOther))
1736 NS_LOG_LOGIC(
"Remote side interface " << interfaceOther <<
" not up");
1739 if (ip->GetNAddresses(interfaceOther) > 1)
1741 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1747 addrOther = ip->GetAddress(interfaceOther, 0).GetAddress();
1751 addrOther = ip->GetAddress(interfaceOther, 1).GetAddress();
1753 designatedRtr = addrOther < designatedRtr ? addrOther : designatedRtr;
1754 NS_LOG_LOGIC(
"designated router now " << designatedRtr);
1771 NS_LOG_LOGIC(
"Looking through bridge ports of bridge net device " << bnd);
1772 for (
uint32_t j = 0; j < bnd->GetNBridgePorts(); ++j)
1775 NS_LOG_LOGIC(
"Examining bridge port " << j <<
" device " << ndBridged);
1776 if (ndBridged == ndOther)
1778 NS_LOG_LOGIC(
"That bridge port is me, don't walk backward");
1782 NS_LOG_LOGIC(
"Recursively looking for routers down bridge port " << ndBridged);
1784 designatedRtr = addrOther < designatedRtr ? addrOther : designatedRtr;
1785 NS_LOG_LOGIC(
"designated router now " << designatedRtr);
1791 Ptr<Node> nodeOther = ndOther->GetNode();
1799 Ptr<Ip> ip = nodeOther->GetObject<
Ip>();
1802 int32_t interfaceOther = ip->GetInterfaceForDevice(ndOther);
1803 if (interfaceOther != -1)
1805 if (!ip->IsUp(interfaceOther))
1807 NS_LOG_LOGIC(
"Remote side interface " << interfaceOther <<
" not up");
1810 NS_LOG_LOGIC(
"Found router on net device " << ndOther);
1811 if (ip->GetNAddresses(interfaceOther) > 1)
1813 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1819 addrOther = ip->GetAddress(interfaceOther, 0).GetAddress();
1823 addrOther = ip->GetAddress(interfaceOther, 1).GetAddress();
1825 designatedRtr = addrOther < designatedRtr ? addrOther : designatedRtr;
1826 NS_LOG_LOGIC(
"designated router now " << designatedRtr);
1831 return designatedRtr;
1840template <
typename T>
1852 uint32_t nDevices = ch->GetNDevices();
1855 NS_LOG_LOGIC(
"Looking for routers off of net device " << nd <<
" on node "
1856 << nd->GetNode()->GetId());
1862 for (
uint32_t i = 0; i < nDevices; i++)
1867 NS_LOG_LOGIC(
"Examine channel device " << i <<
" on node " << ndOther->GetNode()->GetId());
1888 NS_LOG_LOGIC(
"Device is bridged by net device " << bnd);
1903 NS_LOG_LOGIC(
"Looking through bridge ports of bridge net device " << bnd);
1904 for (
uint32_t j = 0; j < bnd->GetNBridgePorts(); ++j)
1907 NS_LOG_LOGIC(
"Examining bridge port " << j <<
" device " << ndBridged);
1908 if (ndBridged == ndOther)
1914 NS_LOG_LOGIC(
"Recursively looking for routers on bridge port " << ndBridged);
1917 NS_LOG_LOGIC(
"Found routers on bridge port, return true");
1921 NS_LOG_LOGIC(
"No routers on bridged net device, return false");
1926 Ptr<Node> nodeTemp = ndOther->GetNode();
1932 NS_LOG_LOGIC(
"Found GlobalRouter interface, return true");
1937 NS_LOG_LOGIC(
"No GlobalRouter interface on device, continue search");
1944template <
typename T>
1955template <
typename T>
1969 for (; i !=
m_LSAs.end(); i++, j++)
1982template <
typename T>
1991 *route = IpRoutingTableEntry::CreateNetworkRouteTo(network, networkMask, 1);
1995template <
typename T>
2017template <
typename T>
2025template <
typename T>
2045template <
typename T>
2054 if ((*i)->GetDestNetwork() == network && (*i)->GetDestNetworkMask() == networkMask)
2056 NS_LOG_LOGIC(
"Withdrawing route to network/mask " << network <<
"/" << networkMask);
2064 if ((*i)->GetDestNetwork() == network && (*i)->GetDestNetworkPrefix() == networkMask)
2066 NS_LOG_LOGIC(
"Withdrawing route to network/mask " << network <<
"/" << networkMask);
2080template <
typename T>
2086 "GlobalRouter::GetAdjacent (): Channel with other than two devices");
2107 NS_ASSERT_MSG(
false,
"GlobalRouter::GetAdjacent (): Wrong or confused channel?");
2115template <
typename T>
2122 uint32_t nDevices = node->GetNDevices();
2130 for (
uint32_t i = 0; i < nDevices; ++i)
2135 if (ndTest->IsBridge())
2137 NS_LOG_LOGIC(
"device " << i <<
" is a bridge net device");
2141 "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
2143 for (
uint32_t j = 0; j < bnd->GetNBridgePorts(); ++j)
2145 NS_LOG_LOGIC(
"Examine bridge port " << j <<
" " << bnd->GetBridgePort(j));
2146 if (bnd->GetBridgePort(j) == nd)
2148 NS_LOG_LOGIC(
"Net device " << nd <<
" is bridged by " << bnd);
2154 NS_LOG_LOGIC(
"Net device " << nd <<
" is not bridged");
2161template <
typename T>
2171template <
typename T>
2177 if (bridgeNetDevice == *iter)
2179 NS_LOG_LOGIC(
"Bridge " << bridgeNetDevice <<
" has been visited.");
2189template <
typename T>
a virtual net device that bridges multiple LAN segments
static uint32_t AllocateRouterId()
An interface aggregated to a node to provide global routing info.
uint32_t DiscoverLSAs()
Walk the connected channels, discover the adjacent routers and build the associated number of Global ...
Ptr< GlobalRouting< IpRoutingProtocol > > m_routingProtocol
the Ipv4GlobalRouting in use
ListOfLSAs_t m_LSAs
database of GlobalRoutingLSAs
Ptr< NetDevice > GetAdjacent(Ptr< NetDevice > nd, Ptr< Channel > ch) const
Link through the given channel and find the net device that's on the other end.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
IpRoutingTableEntry * GetInjectedRoute(uint32_t i)
Return the injected route indexed by i.
std::vector< Ptr< BridgeNetDevice > > m_bridgesVisited
Container of bridges visited.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
void ProcessSingleBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a single broadcast link.
bool BridgeHasAlreadyBeenVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, check whether a given device has already been visi...
bool WithdrawRoute(IpAddress network, IpMaskOrPrefix networkMask)
Withdraw a route from the global unicast routing table.
uint32_t GetNumLSAs() const
Get the Number of Global Routing Link State Advertisements that this router can export.
GlobalRouter()
Create a Global Router class.
void ProcessBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a generic broadcast link.
bool AnotherRouterOnLink(Ptr< NetDevice > nd) const
Checks for the presence of another router on the NetDevice.
void ProcessBridgedBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA< T > *pLSA, NetDeviceContainer &c)
Process a bridged broadcast link.
uint32_t GetNInjectedRoutes()
Get the number of injected routes that have been added to the routing table.
InjectedRoutes m_injectedRoutes
Routes we are exporting.
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Decide whether or not a given net device is being bridged by a BridgeNetDevice.
void ClearBridgesVisited() const
Clear the list of bridges visited on the link.
NetDeviceContainer FindAllNonBridgedDevicesOnLink(Ptr< Channel > ch) const
Return a container of all non-bridged NetDevices on a link.
IpAddress FindDesignatedRouterForLink(Ptr< NetDevice > ndLocal) const
Finds a designated router.
bool GetLSA(uint32_t n, GlobalRoutingLSA< T > &lsa) const
Get a Global Routing Link State Advertisements that this router has said that it can export.
void BuildNetworkLSAs(NetDeviceContainer c)
Build one NetworkLSA for each net device talking to a network that we are the designated router for.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void ClearLSAs()
Clear list of LSAs.
void InjectRoute(IpAddress network, IpMaskOrPrefix networkMask)
Inject a route to be circulated to other routers as an external route.
static TypeId GetTypeId()
Get the type ID.
Ptr< GlobalRouting< IpRoutingProtocol > > GetRoutingProtocol()
Get the specific Global Routing Protocol used.
void SetRoutingProtocol(Ptr< GlobalRouting< IpRoutingProtocol > > routing)
Set the specific Global Routing Protocol to be used.
IpAddress GetRouterId() const
Get the Router ID associated with this Global Router.
void DoDispose() override
Destructor implementation.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
void RemoveInjectedRoute(uint32_t i)
Withdraw a route from the global unicast routing table.
void MarkBridgeAsVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, mark a given device as having been visited.
IpAddress m_routerId
router ID (its IPv4 address)
void ProcessPointToPointLink(Ptr< NetDevice > ndLocal, GlobalRoutingLSA< T > *pLSA)
Process a point to point link.
Global routing protocol for IPv4 stacks.
a Link State Advertisement (LSA) for a router, used in global routing.
GlobalRoutingLinkRecord< T > * GetLinkRecord(uint32_t n) const
Return a pointer to the specified Global Routing Link Record.
SPFStatus
Enumeration of the possible values of the status flag in the Routing Link State Advertisements.
@ LSA_SPF_NOT_EXPLORED
New vertex not yet considered.
IpAddress m_advertisingRtr
The Advertising Router is defined by the OSPF spec.
void SetLSType(LSType typ)
Set the LS type field of the LSA.
void ClearLinkRecords()
Release all of the Global Routing Link Records present in the Global Routing Link State Advertisement...
SPFStatus GetStatus() const
Get the SPF status of the advertisement.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
LSType
corresponds to LS type field of RFC 2328 OSPF LSA header
@ Unknown
Uninitialized Type.
void SetNetworkLSANetworkMask(IpMaskOrPrefix mask)
For a Network LSA, set the Network Mask field that precedes the list of attached routers.
void SetAdvertisingRouter(IpAddress rtr)
Set the Advertising Router as defined by the OSPF spec.
uint32_t GetNLinkRecords() const
Return the number of Global Routing Link Records in the LSA.
ListOfLinkRecords_t m_linkRecords
Each Link State Advertisement contains a number of Link Records that describe the kinds of links that...
uint32_t AddLinkRecord(GlobalRoutingLinkRecord< T > *lr)
Add a given Global Routing Link Record to the LSA.
IpAddress GetLinkStateId() const
Get the Link State ID as defined by the OSPF spec.
void SetLinkStateId(IpAddress addr)
Set the Link State ID is defined by the OSPF spec.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
Ptr< Node > GetNode() const
Get the Node pointer of the node that originated this LSA.
void Print(std::ostream &os) const
Print the contents of the Global Routing Link State Advertisement and any Global Routing Link Records...
GlobalRoutingLSA & operator=(const GlobalRoutingLSA &lsa)
Assignment operator for a Global Routing Link State Advertisement.
IpMaskOrPrefix m_networkLSANetworkMask
Each Network LSA contains the network mask of the attached network.
LSType GetLSType() const
Return the LSType field of the LSA.
GlobalRoutingLSA()
Create a blank Global Routing Link State Advertisement.
IpAddress GetAdvertisingRouter() const
Get the Advertising Router as defined by the OSPF spec.
uint32_t GetNAttachedRouters() const
Return the number of attached routers listed in the NetworkLSA.
SPFStatus m_status
This is a tristate flag used internally in the SPF computation to mark if an SPFVertex (a data struct...
IpAddress m_linkStateId
The Link State ID is defined by the OSPF spec.
static constexpr bool IsIpv4
void SetStatus(SPFStatus status)
Set the SPF status of the advertisement.
ListOfAttachedRouters_t m_attachedRouters
Each Network LSA contains a list of attached routers.
bool IsEmpty() const
Check to see if the list of Global Routing Link Records present in the Global Routing Link State Adve...
~GlobalRoutingLSA()
Destroy an existing Global Routing Link State Advertisement.
void CopyLinkRecords(const GlobalRoutingLSA &lsa)
Copy any Global Routing Link Records in a given Global Routing Link State Advertisement to the curren...
void SetNode(Ptr< Node > node)
Set the Node pointer of the node that originated this LSA.
IpMaskOrPrefix GetNetworkLSANetworkMask() const
For a Network LSA, get the Network Mask field that precedes the list of attached routers.
IpAddress GetAttachedRouter(uint32_t n) const
Return an Ipv4Address corresponding to the specified attached router.
uint32_t AddAttachedRouter(IpAddress addr)
Add an attached router to the list in the NetworkLSA.
LSType m_lsType
The type of the LSA.
uint32_t m_node_id
node ID
A single link record for a link state advertisement.
void SetLinkId(IpAddress addr)
Set the Link ID field of the Global Routing Link Record.
void SetLinkData(IpAddress addr)
Set the Link Data field of the Global Routing Link Record.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
IpAddress m_linkId
m_linkId and m_linkData are defined by OSPF to have different meanings depending on the type of link ...
IpAddress GetLinkId() const
Get the Link ID field of the Global Routing Link Record.
~GlobalRoutingLinkRecord()
Destroy a Global Routing Link Record.
uint16_t GetMetric() const
Get the Metric Data field of the Global Routing Link Record.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
LinkType
Enumeration of the possible types of Global Routing Link Records.
@ StubNetwork
Record represents a leaf node network.
@ Unknown
Uninitialized Link Record.
@ PointToPoint
Record representing a point to point channel.
@ TransitNetwork
Unused – for future OSPF compatibility.
IpAddress m_linkData
m_linkId and m_linkData are defined by OSPF to have different meanings depending on the type of link ...
LinkType m_linkType
The type of the Global Routing Link Record.
void SetMetric(uint16_t metric)
Set the Metric Data field of the Global Routing Link Record.
IpAddress GetLinkData() const
Get the Link Data field of the Global Routing Link Record.
uint16_t m_metric
The metric for a given link.
GlobalRoutingLinkRecord()
Construct an empty ("uninitialized") Global Routing Link Record.
IpAddress GetLinkLocData()
Set the Link Local Data field of the Global Routing Link Record.
void SetLinkType(LinkType linkType)
Set the Link Type field of the Global Routing Link Record.
void SetLinkLocData(IpAddress addr)
Set the Link Local Data field of the Global Routing Link Record.
friend class GlobalRoutingLSA
IpAddress m_linkLocData
m_linkLocData is not defined by the OSPF spec.
LinkType GetLinkType() const
Get the Link Type field of the Global Routing Link Record.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetBroadcast()
Describes an IPv6 address.
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static Ptr< Node > GetNode(uint32_t n)
A base class which provides memory management and object aggregation.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param)
Explicitly instantiate a template class with one template parameter and register the resulting instan...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
template std::ostream & operator<<< Ipv4Manager >(std::ostream &, GlobalRoutingLSA< Ipv4Manager > &)
Explicit initialize the template classes.
template std::ostream & operator<<< Ipv6Manager >(std::ostream &, GlobalRoutingLSA< Ipv6Manager > &)
Stream insertion operator.
Empty struct used as a template parameter.
Empty struct used as a template parameter.