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"
38 : m_linkId(
"0.0.0.0"),
39 m_linkData(
"0.0.0.0"),
127 m_linkStateId(
"0.0.0.0"),
128 m_advertisingRtr(
"0.0.0.0"),
130 m_networkLSANetworkMask(
"0.0.0.0"),
145 m_networkLSANetworkMask(
"0.0.0.0"),
154 : m_lsType(
lsa.m_lsType),
155 m_linkStateId(
lsa.m_linkStateId),
156 m_advertisingRtr(
lsa.m_advertisingRtr),
157 m_networkLSANetworkMask(
lsa.m_networkLSANetworkMask),
158 m_status(
lsa.m_status),
159 m_node_id(
lsa.m_node_id)
162 NS_ASSERT_MSG(
IsEmpty(),
"GlobalRoutingLSA::GlobalRoutingLSA (): Non-empty LSA in constructor");
185 for (
auto i =
lsa.m_linkRecords.begin();
i !=
lsa.m_linkRecords.end();
i++)
192 pDst->SetLinkData(
pSrc->GetLinkData());
253 NS_ASSERT_MSG(
false,
"GlobalRoutingLSA::GetLinkRecord (): invalid index");
354 NS_ASSERT_MSG(
false,
"GlobalRoutingLSA::GetAttachedRouter (): invalid index");
384 os <<
"========== Global Routing LSA ==========" << std::endl;
388 os <<
" (GlobalRoutingLSA::RouterLSA)";
392 os <<
" (GlobalRoutingLSA::NetworkLSA)";
396 os <<
" (GlobalRoutingLSA::ASExternalLSA)";
400 os <<
"(Unknown LSType)";
404 os <<
"m_linkStateId = " <<
m_linkStateId <<
" (Router ID)" << std::endl;
405 os <<
"m_advertisingRtr = " <<
m_advertisingRtr <<
" (Router ID)" << std::endl;
413 os <<
"---------- RouterLSA Link Record ----------" << std::endl;
417 os <<
" (GlobalRoutingLinkRecord::PointToPoint)" << std::endl;
418 os <<
"m_linkId = " << p->
m_linkId << std::endl;
419 os <<
"m_linkData = " << p->
m_linkData << std::endl;
420 os <<
"m_metric = " << p->
m_metric << std::endl;
424 os <<
" (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
425 os <<
"m_linkId = " << p->
m_linkId <<
" (Designated router for network)"
427 os <<
"m_linkData = " << p->
m_linkData <<
" (This router's IP address)"
429 os <<
"m_metric = " << p->
m_metric << std::endl;
433 os <<
" (GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
434 os <<
"m_linkId = " << p->
m_linkId <<
" (Network number of attached network)"
436 os <<
"m_linkData = " << p->
m_linkData <<
" (Network mask of attached network)"
438 os <<
"m_metric = " << p->
m_metric << std::endl;
442 os <<
" (Unknown LinkType)" << 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;
447 os <<
"---------- End RouterLSA Link Record ----------" << std::endl;
452 os <<
"---------- NetworkLSA Link Record ----------" << std::endl;
457 os <<
"attachedRouter = " << p << std::endl;
459 os <<
"---------- End NetworkLSA Link Record ----------" << std::endl;
463 os <<
"---------- ASExternalLSA Link Record --------" << std::endl;
471 os <<
"========== End Global Routing LSA ==========" << std::endl;
573 "GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
592 "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
635 "GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
650 <<
"has no IP interface or is not enabled for forwarding, skipping");
669 else if (
ndLocal->IsPointToPoint())
676 NS_ASSERT_MSG(0,
"GlobalRouter::DiscoverLSAs (): unknown link type");
680 NS_LOG_LOGIC(
"========== LSA for node " << node->GetId() <<
" ==========");
704 pLSA->SetLinkStateId((*i)->GetDestNetwork());
706 pLSA->SetNetworkLSANetworkMask((*i)->GetDestNetworkMask());
737 "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
751 "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
756 "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
760 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
827 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion ("
829 <<
"/" <<
maskLocal.GetPrefixLength() <<
")");
834 NS_LOG_LOGIC(
"Node " << node->GetId() <<
" elected a designated router");
855 "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
887 NS_LOG_WARN (
"Warning, interface has multiple IP addresses; using only the primary one");
939 "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion (" <<
955 NS_ABORT_MSG_IF (
plr == 0,
"GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
999 NS_LOG_LOGIC (
"Node " << node->GetId () <<
" elected a designated router");
1031 "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1036 "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
1040 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1069 "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
1094 "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with "
1103 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1121 "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1133 "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
1162 "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
1167 "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
1171 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the primary one");
1178 "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
1185 pLSA->SetNode(node);
1218 <<
" does not have GlobalRouter interface--skipping");
1241 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1252 <<
" does not have IPv4 interface; skipping");
1256 NS_LOG_LOGIC(
"========== LSA for node " << node->GetId() <<
" ==========");
1268 for (std::size_t
i = 0;
i <
ch->GetNDevices();
i++)
1271 NS_LOG_LOGIC(
"checking to see if the device " <<
nd <<
" is bridged");
1276 <<
bnd <<
" with " <<
bnd->GetNBridgePorts() <<
" ports");
1318 <<
ndLocal->GetNode()->GetId());
1341 NS_LOG_LOGIC(
"checking to see if the device is bridged");
1381 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1403 NS_LOG_LOGIC(
"Looking through bridge ports of bridge net device " <<
bnd);
1410 NS_LOG_LOGIC(
"That bridge port is me, don't walk backward");
1445 NS_LOG_WARN(
"Warning, interface has multiple IP addresses; using only the "
1478 NS_LOG_LOGIC(
"Looking for routers off of net device " <<
nd <<
" on node "
1479 <<
nd->GetNode()->GetId());
1526 NS_LOG_LOGIC(
"Looking through bridge ports of bridge net device " <<
bnd);
1540 NS_LOG_LOGIC(
"Found routers on bridge port, return true");
1544 NS_LOG_LOGIC(
"No routers on bridged net device, return false");
1555 NS_LOG_LOGIC(
"Found GlobalRouter interface, return true");
1560 NS_LOG_LOGIC(
"No GlobalRouter interface on device, continue search");
1581 NS_ASSERT_MSG(
lsa.IsEmpty(),
"GlobalRouter::GetLSA (): Must pass empty LSA");
1668 if ((*i)->GetDestNetwork() == network && (*i)->GetDestNetworkMask() ==
networkMask)
1688 "GlobalRouter::GetAdjacent (): Channel with other than two devices");
1709 NS_ASSERT_MSG(
false,
"GlobalRouter::GetAdjacent (): Wrong or confused channel?");
1742 "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1747 if (
bnd->GetBridgePort(
j) ==
nd)
a virtual net device that bridges multiple LAN segments
static uint32_t AllocateRouterId()
Allocate a 32-bit router ID from monotonically increasing counter.
An interface aggregated to a node to provide global routing info.
Ipv4Address FindDesignatedRouterForLink(Ptr< NetDevice > ndLocal) const
Finds a designated router.
void MarkBridgeAsVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, mark a given device as having been visited.
Ptr< Ipv4GlobalRouting > m_routingProtocol
the Ipv4GlobalRouting in use
bool GetLSA(uint32_t n, GlobalRoutingLSA &lsa) const
Get a Global Routing Link State Advertisements that this router has said that it can export.
void ProcessSingleBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a single broadcast link.
bool WithdrawRoute(Ipv4Address network, Ipv4Mask networkMask)
Withdraw a route from the global unicast routing table.
NetDeviceContainer FindAllNonBridgedDevicesOnLink(Ptr< Channel > ch) const
Return a container of all non-bridged NetDevices on a link.
bool BridgeHasAlreadyBeenVisited(Ptr< BridgeNetDevice > device) const
When recursively checking for devices on the link, check whether a given device has already been visi...
InjectedRoutes m_injectedRoutes
Routes we are exporting.
void ClearBridgesVisited() const
Clear the list of bridges visited on the link.
void InjectRoute(Ipv4Address network, Ipv4Mask networkMask)
Inject a route to be circulated to other routers as an external route.
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Decide whether or not a given net device is being bridged by a BridgeNetDevice.
Ipv4Address GetRouterId() const
Get the Router ID associated with this Global Router.
uint32_t GetNumLSAs() const
Get the Number of Global Routing Link State Advertisements that this router can export.
ListOfLSAs_t m_LSAs
database of GlobalRoutingLSAs
void ProcessBridgedBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a bridged broadcast link.
GlobalRouter()
Create a Global Router class.
Ipv4RoutingTableEntry * GetInjectedRoute(uint32_t i)
Return the injected route indexed by i.
void ClearLSAs()
Clear list of LSAs.
static TypeId GetTypeId()
Get the type ID.
Ptr< Ipv4GlobalRouting > GetRoutingProtocol()
Get the specific Global Routing Protocol used.
Ipv4Address m_routerId
router ID (its IPv4 address)
void RemoveInjectedRoute(uint32_t i)
Withdraw a route from the global unicast routing table.
bool AnotherRouterOnLink(Ptr< NetDevice > nd) const
Checks for the presence of another router on the NetDevice.
void SetRoutingProtocol(Ptr< Ipv4GlobalRouting > routing)
Set the specific Global Routing Protocol to be used.
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.
std::vector< Ptr< BridgeNetDevice > > m_bridgesVisited
Container of bridges visited.
void ProcessPointToPointLink(Ptr< NetDevice > ndLocal, GlobalRoutingLSA *pLSA)
Process a point to point link.
uint32_t DiscoverLSAs()
Walk the connected channels, discover the adjacent routers and build the associated number of Global ...
void DoDispose() override
Destructor implementation.
void ProcessBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a generic broadcast link.
uint32_t GetNInjectedRoutes()
Get the number of injected routes that have been added to the routing table.
void BuildNetworkLSAs(NetDeviceContainer c)
Build one NetworkLSA for each net device talking to a network that we are the designated router for.
a Link State Advertisement (LSA) for a router, used in global routing.
Ipv4Address GetAdvertisingRouter() const
Get the Advertising Router as defined by the OSPF spec.
void SetStatus(SPFStatus status)
Set the SPF status of the advertisement.
uint32_t m_node_id
node ID
void Print(std::ostream &os) const
Print the contents of the Global Routing Link State Advertisement and any Global Routing Link Records...
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.
uint32_t GetNAttachedRouters() const
Return the number of attached routers listed in the NetworkLSA.
Ptr< Node > GetNode() const
Get the Node pointer of the node that originated this LSA.
uint32_t AddLinkRecord(GlobalRoutingLinkRecord *lr)
Add a given Global Routing Link Record to the LSA.
LSType
corresponds to LS type field of RFC 2328 OSPF LSA header
SPFStatus GetStatus() const
Get the SPF status of the advertisement.
Ipv4Address m_linkStateId
The Link State ID is defined by the OSPF spec.
bool IsEmpty() const
Check to see if the list of Global Routing Link Records present in the Global Routing Link State Adve...
Ipv4Mask GetNetworkLSANetworkMask() const
For a Network LSA, get the Network Mask field that precedes the list of attached routers.
GlobalRoutingLSA()
Create a blank Global Routing Link State Advertisement.
ListOfLinkRecords_t m_linkRecords
Each Link State Advertisement contains a number of Link Records that describe the kinds of links that...
Ipv4Address GetAttachedRouter(uint32_t n) const
Return an Ipv4Address corresponding to the specified attached router.
void SetNode(Ptr< Node > node)
Set the Node pointer of the node that originated this LSA.
LSType GetLSType() const
Return the LSType field of the LSA.
uint32_t AddAttachedRouter(Ipv4Address addr)
Add an attached router to the list in the NetworkLSA.
uint32_t GetNLinkRecords() const
Return the number of Global Routing Link Records in the LSA.
~GlobalRoutingLSA()
Destroy an existing Global Routing Link State Advertisement.
Ipv4Address 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...
void SetAdvertisingRouter(Ipv4Address rtr)
Set the Advertising Router as defined by the OSPF spec.
SPFStatus m_status
This is a tristate flag used internally in the SPF computation to mark if an SPFVertex (a data struct...
LSType m_lsType
The type of the LSA.
ListOfAttachedRouters_t m_attachedRouters
Each Network LSA contains a list of attached routers.
GlobalRoutingLinkRecord * GetLinkRecord(uint32_t n) const
Return a pointer to the specified Global Routing Link Record.
void SetNetworkLSANetworkMask(Ipv4Mask mask)
For a Network LSA, set the Network Mask field that precedes the list of attached routers.
Ipv4Mask m_networkLSANetworkMask
Each Network LSA contains the network mask of the attached network.
void CopyLinkRecords(const GlobalRoutingLSA &lsa)
Copy any Global Routing Link Records in a given Global Routing Link State Advertisement to the curren...
void SetLinkStateId(Ipv4Address addr)
Set the Link State ID is defined by the OSPF spec.
GlobalRoutingLSA & operator=(const GlobalRoutingLSA &lsa)
Assignment operator for a Global Routing Link State Advertisement.
Ipv4Address GetLinkStateId() const
Get the Link State ID as defined by the OSPF spec.
A single link record for a link state advertisement.
LinkType m_linkType
The type of the Global Routing Link Record.
LinkType GetLinkType() const
Get the Link Type field of the Global Routing Link Record.
void SetMetric(uint16_t metric)
Set the Metric Data field of the Global Routing Link Record.
void SetLinkId(Ipv4Address addr)
Set the Link ID field of the Global Routing Link Record.
Ipv4Address m_linkId
m_linkId and m_linkData are defined by OSPF to have different meanings depending on the type of link ...
Ipv4Address GetLinkId() const
Get the Link ID field of the Global Routing Link Record.
Ipv4Address m_linkData
m_linkId and m_linkData are defined by OSPF to have different meanings depending on the type of link ...
uint16_t GetMetric() const
Get the Metric Data field of the Global Routing Link Record.
void SetLinkData(Ipv4Address addr)
Set the Link Data field of the Global Routing Link Record.
Ipv4Address GetLinkData() const
Get the Link Data field of the Global Routing Link Record.
LinkType
Enumeration of the possible types of Global Routing Link Records.
@ StubNetwork
Record represents a leaf node network.
@ PointToPoint
Record representing a point to point channel.
@ TransitNetwork
Unused – for future OSPF compatibility
uint16_t m_metric
The metric for a given link.
GlobalRoutingLinkRecord()
Construct an empty ("uninitialized") Global Routing Link Record.
void SetLinkType(LinkType linkType)
Set the Link Type field of the Global Routing Link Record.
~GlobalRoutingLinkRecord()
Destroy a Global Routing Link Record.
Ipv4 addresses are stored in host order in this class.
void Set(uint32_t address)
input address is in host order.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to represent an Ipv4 address mask
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
holds a vector of ns3::NetDevice pointers
static Ptr< Node > GetNode(uint32_t n)
A base class which provides memory management and object aggregation.
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_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)