From 7ce874f5d00abfaedb18311a4dded46473480fa3 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 9 Jul 2007 22:03:41 -0700 Subject: [PATCH 1/2] checkpoint --- SConstruct | 2 +- src/routing/static-router.cc | 84 ++++++++++++++++++++++++++---------- src/routing/static-router.h | 1 + 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/SConstruct b/SConstruct index 5fcd7d29b..00a799f90 100644 --- a/SConstruct +++ b/SConstruct @@ -334,8 +334,8 @@ inode.add_headers ([ 'ipv4-end-point-demux.h', 'ipv4-end-point.h', 'ipv4-header.h', - 'udp-header.h', 'ipv4-interface.h', + 'udp-header.h', 'sgi-hashmap.h', 'udp-impl.h', ]) diff --git a/src/routing/static-router.cc b/src/routing/static-router.cc index 6c8f0fc28..94f393357 100644 --- a/src/routing/static-router.cc +++ b/src/routing/static-router.cc @@ -20,6 +20,7 @@ #include "ns3/net-device.h" #include "ns3/internet-node.h" #include "ns3/ipv4.h" +#include "ns3/ipv4-interface.h" #include "static-router.h" NS_DEBUG_COMPONENT_DEFINE ("StaticRouter"); @@ -90,8 +91,8 @@ StaticRouter::GetNumLSAs (void) // Ipv4 interface. This is where the information regarding the attached // interfaces lives. // - Ptr ipv4 = m_node->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG(ipv4, "QI for interface failed"); + Ptr ipv4Local = m_node->QueryInterface (Ipv4::iid); + NS_ASSERT_MSG(ipv4Local, "QI for interface failed"); // // Now, we need to ask Ipv4 for the number of interfaces attached to this // node. This isn't necessarily equal to the number of links to adjacent @@ -104,23 +105,40 @@ StaticRouter::GetNumLSAs (void) // number if we discover a link that's not actually connected to another // router. // - m_numLSAs = ipv4->GetNInterfaces(); - - NS_DEBUG("StaticRouter::GetNumLSAs (): m_numLSAs = " << m_numLSAs); - - for (uint32_t i = 0; i < m_numLSAs; ++i) + m_numLSAs = 0; + uint32_t numDevices = m_node->GetNDevices(); + NS_DEBUG("StaticRouter::GetNumLSAs (): numDevices = " << numDevices); +// +// Loop through the devices looking for those connected to a point-to-point +// channel. These are the ones that are used to route packets. +// + for (uint32_t i = 0; i < numDevices; ++i) { - Ptr nd = ipv4->GetNetDevice(i); - Ptr ch = nd->GetChannel(); + Ptr nd = m_node->GetDevice(i); if (!nd->IsPointToPoint ()) { NS_DEBUG("StaticRouter::GetNumLSAs (): non-point-to-point device"); - --m_numLSAs; continue; } - NS_DEBUG("StaticRouter::GetNumLSAs (): point-to-point device"); + NS_DEBUG("StaticRouter::GetNumLSAs (): Point-to-point device"); +// +// Now, we have to find the Ipv4 interface whose netdevice is the one we +// just found. This is the IP on the local side of the channel. There is +// a function to do this used down in the guts of the stack, but its not +// exported so we had to whip up an equivalent. +// + uint32_t ifIndexLocal = FindIfIndexForDevice(m_node, nd); +// +// Now that we have the Ipv4 interface index, we can get the address and mask +// we need. +// + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); + NS_DEBUG("Working with local address " << addrLocal); + + Ptr ch = nd->GetChannel(); // // Find the net device on the other end of the point-to-point channel. This // is where our adjacent router is running. The adjacent net device is @@ -129,20 +147,23 @@ StaticRouter::GetNumLSAs (void) // address. To do this, we have to get the interface index associated with // that net device in order to find the correct interface on the adjacent node. // - Ptr ndAdjacent = GetAdjacent(nd, ch); - uint32_t ifIndexAdjacent = ndAdjacent->GetIfIndex(); - Ptr nodeAdjacent = ndAdjacent->GetNode(); - Ptr ipv4Adjacent = nodeAdjacent->QueryInterface (Ipv4::iid); - NS_ASSERT_MSG(ipv4Adjacent, "QI for adjacent interface failed"); + Ptr ndRemote = GetAdjacent(nd, ch); + Ptr nodeRemote = ndRemote->GetNode(); + Ptr ipv4Remote = nodeRemote->QueryInterface (Ipv4::iid); + NS_ASSERT_MSG(ipv4Remote, "QI for remote interface failed"); // -// Okay, all of the preliminaries are done. We can get the IP address and -// net mask for the adjacent router. +// Now, just like we did above, we need to get the IP interface index for the +// net device on the other end of the point-to-point channel. // - Ipv4Address addrAdjacent = ipv4Adjacent->GetAddress(ifIndexAdjacent); - Ipv4Mask maskAdjacent = ipv4->GetNetworkMask(ifIndexAdjacent); - - NS_DEBUG("StaticRouter::GetNumLSAs (): Adjacent to " << addrAdjacent << - " & " << maskAdjacent); + uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote); +// +// Now that we have the Ipv4 interface, we can get the address and mask we +// need. +// + Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote); + Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote); + NS_DEBUG("Working with remote address " << addrRemote); + ++m_numLSAs; } return m_numLSAs; @@ -191,4 +212,21 @@ StaticRouter::GetAdjacent(Ptr nd, Ptr ch) } } + uint32_t +StaticRouter::FindIfIndexForDevice(Ptr node, Ptr nd) +{ + Ptr ipv4 = node->QueryInterface (Ipv4::iid); + NS_ASSERT_MSG(ipv4, "QI for interface failed"); + for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) + { + if (ipv4->GetNetDevice(i) == nd) + { + return i; + } + } + + NS_ASSERT_MSG(0, "Cannot find interface for device"); + return 0; +} + } // namespace ns3 diff --git a/src/routing/static-router.h b/src/routing/static-router.h index 9d2b4cc6a..a3d56001e 100644 --- a/src/routing/static-router.h +++ b/src/routing/static-router.h @@ -106,6 +106,7 @@ protected: uint32_t m_numLSAs; Ptr GetAdjacent(Ptr nd, Ptr ch); + uint32_t FindIfIndexForDevice(Ptr node, Ptr nd); private: }; From 5487c20beb541a80073f1313d57e80f91892d192 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 9 Jul 2007 22:12:58 -0700 Subject: [PATCH 2/2] forgot to remove a header include --- src/routing/static-router.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/routing/static-router.cc b/src/routing/static-router.cc index 94f393357..b76565b9f 100644 --- a/src/routing/static-router.cc +++ b/src/routing/static-router.cc @@ -20,7 +20,6 @@ #include "ns3/net-device.h" #include "ns3/internet-node.h" #include "ns3/ipv4.h" -#include "ns3/ipv4-interface.h" #include "static-router.h" NS_DEBUG_COMPONENT_DEFINE ("StaticRouter"); @@ -137,17 +136,17 @@ StaticRouter::GetNumLSAs (void) Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); NS_DEBUG("Working with local address " << addrLocal); - +// +// Now, we're going to link to the remote net device on the other end of the +// point-to-point channel we know we have. This is where our adjacent router +// (to use OSPF lingo) is running. +// Ptr ch = nd->GetChannel(); -// -// Find the net device on the other end of the point-to-point channel. This -// is where our adjacent router is running. The adjacent net device is -// aggregated to a node. We need to ask that net device for its node, then -// ask that node for its Ipv4 interface and then ask the Ipv4 for the IP -// address. To do this, we have to get the interface index associated with -// that net device in order to find the correct interface on the adjacent node. -// Ptr ndRemote = GetAdjacent(nd, ch); +// +// The adjacent net device is aggregated to a node. We need to ask that net +// device for its node, then ask that node for its Ipv4 interface. +// Ptr nodeRemote = ndRemote->GetNode(); Ptr ipv4Remote = nodeRemote->QueryInterface (Ipv4::iid); NS_ASSERT_MSG(ipv4Remote, "QI for remote interface failed"); @@ -157,8 +156,8 @@ StaticRouter::GetNumLSAs (void) // uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote); // -// Now that we have the Ipv4 interface, we can get the address and mask we -// need. +// Now that we have the Ipv4 interface, we can get the (remote) address and +// mask we need. // Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote); Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);