comparing with http://code.nsnam.org/ns-3-dev searching for changes changeset: 3870:4b18d1e1e2e5 user: Craig Dowell date: Tue Nov 18 15:46:46 2008 -0800 summary: add bridged routing example diff -r 0edba1e055aa -r 4b18d1e1e2e5 examples/csma-bridge-one-hop.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/csma-bridge-one-hop.cc Tue Nov 18 15:46:46 2008 -0800 @@ -0,0 +1,209 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// Network topology +// +// n0 n1 +// | | +// ----------- +// | bridge1 | +// ----------- +// | +// n2 +// | +// ----------- +// | bridge2 | +// ----------- +// | | +// n3 n4 +// +// This example shows two broadcast domains, each interconnected by a bridge +// with a router node (n2) interconnecting the layer-2 broadcast domains +// +// It is meant to mirror somewhat the csma-bridge example but adds another +// bridged link separated by a router. +// +// - CBR/UDP flows from n0 to n1 and from n3 to n0 +// - DropTail queues +// - Global static routing +// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr" + +#include +#include + +#include "ns3/simulator-module.h" +#include "ns3/node-module.h" +#include "ns3/core-module.h" +#include "ns3/helper-module.h" +#include "ns3/bridge-module.h" +#include "ns3/global-route-manager.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample"); + +int +main (int argc, char *argv[]) +{ + // + // Users may find it convenient to turn on explicit debugging + // for selected modules; the below lines suggest how to do this + // +#if 0 + LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO); +#endif + + // + // Make the random number generators generate reproducible results. + // + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); + + // + // Allow the user to override any of the defaults and the above Bind() at + // run-time, via command-line arguments + // + CommandLine cmd; + cmd.Parse (argc, argv); + + // + // Explicitly create the nodes required by the topology (shown above). + // + NS_LOG_INFO ("Create nodes."); + + Ptr n0 = CreateObject (); + Ptr n1 = CreateObject (); + Ptr n2 = CreateObject (); + Ptr n3 = CreateObject (); + Ptr n4 = CreateObject (); + + Ptr bridge1 = CreateObject (); + Ptr bridge2 = CreateObject (); + + NS_LOG_INFO ("Build Topology"); + CsmaHelper csma; + csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); + csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); + + // Create the csma links, from each terminal to the bridge + // This will create six network devices; we'll keep track separately + // of the devices on and off the bridge respectively, for later configuration + NetDeviceContainer topLanDevices; + NetDeviceContainer topBridgeDevices; + + // It is easier to iterate the nodes in C++ if we put them into a container + NodeContainer topLan (n2, n0, n1); + + for (int i = 0; i < 3; i++) + { + NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1)); + topLanDevices.Add (link.Get (0)); + topBridgeDevices.Add (link.Get (1)); + } + + // Create the bridge netdevice, which will do the packet switching + BridgeHelper bridge; + bridge.Install (bridge1, topBridgeDevices); + + // Add internet stack to the topLan nodes + InternetStackHelper internet; + internet.Install (topLan); + + // Repeat for bottom bridged LAN + NetDeviceContainer bottomLanDevices; + NetDeviceContainer bottomBridgeDevices; + NodeContainer bottomLan (n2, n3, n4); + for (int i = 0; i < 3; i++) + { + NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2)); + bottomLanDevices.Add (link.Get (0)); + bottomBridgeDevices.Add (link.Get (1)); + } + bridge.Install (bridge2, bottomBridgeDevices); + internet.Install (NodeContainer (n3, n4)); + + + // We've got the "hardware" in place. Now we need to add IP addresses. + // + NS_LOG_INFO ("Assign IP Addresses."); + Ipv4AddressHelper ipv4; + ipv4.SetBase ("10.1.1.0", "255.255.255.0"); + ipv4.Assign (topLanDevices); + ipv4.SetBase ("10.1.2.0", "255.255.255.0"); + ipv4.Assign (bottomLanDevices); + + // Create router nodes, initialize routing database and set up the routing + // tables in the nodes. + GlobalRouteManager::PopulateRoutingTables (); + + // + // Create an OnOff application to send UDP datagrams from node zero to node 1. + // + NS_LOG_INFO ("Create Applications."); + uint16_t port = 9; // Discard port (RFC 863) + + OnOffHelper onoff ("ns3::UdpSocketFactory", + Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port))); + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); + + ApplicationContainer app = onoff.Install (n0); + // Start the application + app.Start (Seconds (1.0)); + app.Stop (Seconds (10.0)); + + // Create an optional packet sink to receive these packets + PacketSinkHelper sink ("ns3::UdpSocketFactory", + Address (InetSocketAddress (Ipv4Address::GetAny (), port))); + sink.Install (n1); + + // + // Create a similar flow from n3 to n0, starting at time 1.1 seconds + // + onoff.SetAttribute ("Remote", + AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); + ApplicationContainer app2 = onoff.Install (n3); + + sink.Install (n0); + + app2.Start (Seconds (1.1)); + app2.Stop (Seconds (10.0)); + + // + // Configure tracing of all enqueue, dequeue, and NetDevice receive events. + // Trace output will be sent to the file "csma-bridge-one-hop.tr" + // + NS_LOG_INFO ("Configure Tracing."); + std::ofstream ascii; + ascii.open ("csma-bridge-one-hop.tr"); + CsmaHelper::EnableAsciiAll (ascii); + + // + // Also configure some tcpdump traces; each interface will be traced. + // The output files will be named: + // csma-bridge.pcap-- + // and can be read by the "tcpdump -r" command (use "-tt" option to + // display timestamps correctly) + // + CsmaHelper::EnablePcapAll ("csma-bridge-one-hop"); + + // + // Now, do the actual simulation. + // + NS_LOG_INFO ("Run Simulation."); + Simulator::Run (); + Simulator::Destroy (); + NS_LOG_INFO ("Done."); +} diff -r 0edba1e055aa -r 4b18d1e1e2e5 examples/wscript --- a/examples/wscript Tue Nov 18 23:14:02 2008 +0100 +++ b/examples/wscript Tue Nov 18 15:46:46 2008 -0800 @@ -27,6 +27,10 @@ def build(bld): obj = bld.create_ns3_program('csma-bridge', ['bridge', 'csma', 'internet-stack']) obj.source = 'csma-bridge.cc' + + obj = bld.create_ns3_program('csma-bridge-one-hop', + ['bridge', 'csma', 'internet-stack']) + obj.source = 'csma-bridge-one-hop.cc' obj = bld.create_ns3_program('udp-echo', ['csma', 'internet-stack']) changeset: 3871:e525995ce5dc user: Craig Dowell date: Tue Nov 18 16:23:31 2008 -0800 summary: implement IsBridged for net devices diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/bridge/bridge-net-device.cc --- a/src/devices/bridge/bridge-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/bridge/bridge-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -305,6 +305,12 @@ BridgeNetDevice::IsPointToPoint (void) c return false; } +bool +BridgeNetDevice::IsBridge (void) const +{ + return true; +} + bool BridgeNetDevice::Send (Ptr packet, const Address& dest, uint16_t protocolNumber) diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/bridge/bridge-net-device.h --- a/src/devices/bridge/bridge-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/bridge/bridge-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -98,6 +98,7 @@ public: virtual bool IsMulticast (void) const; virtual Address GetMulticast (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; + virtual bool IsBridge (void) const; virtual bool Send (Ptr packet, const Address& dest, uint16_t protocolNumber); virtual bool SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/csma/csma-net-device.cc --- a/src/devices/csma/csma-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/csma/csma-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -837,6 +837,13 @@ CsmaNetDevice::IsPointToPoint (void) con return false; } + bool +CsmaNetDevice::IsBridge (void) const +{ + NS_LOG_FUNCTION_NOARGS (); + return false; +} + bool CsmaNetDevice::Send (Ptr packet,const Address& dest, uint16_t protocolNumber) { diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/csma/csma-net-device.h --- a/src/devices/csma/csma-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/csma/csma-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -351,6 +351,12 @@ public: virtual bool IsPointToPoint (void) const; /** + * Is this a bridge? + * \returns false. + */ + virtual bool IsBridge (void) const; + + /** * Start sending a packet down the channel. */ virtual bool Send (Ptr packet, const Address& dest, diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/emu/emu-net-device.cc --- a/src/devices/emu/emu-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/emu/emu-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -882,6 +882,12 @@ EmuNetDevice::IsPointToPoint (void) cons return false; } +bool +EmuNetDevice::IsBridge (void) const +{ + return false; +} + void EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb) { diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/emu/emu-net-device.h --- a/src/devices/emu/emu-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/emu/emu-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -164,6 +164,12 @@ public: * \returns false. */ virtual bool IsPointToPoint (void) const; + + /** + * Is this a bridge? + * \returns false. + */ + virtual bool IsBridge (void) const; virtual bool Send(Ptr packet, const Address &dest, uint16_t protocolNumber); diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/point-to-point/point-to-point-net-device.cc --- a/src/devices/point-to-point/point-to-point-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/point-to-point/point-to-point-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -392,6 +392,12 @@ PointToPointNetDevice::IsPointToPoint (v } bool +PointToPointNetDevice::IsBridge (void) const +{ + return false; +} + + bool PointToPointNetDevice::Send( Ptr packet, const Address &dest, diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/point-to-point/point-to-point-net-device.h --- a/src/devices/point-to-point/point-to-point-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/point-to-point/point-to-point-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -252,6 +252,7 @@ public: virtual Address GetMulticast (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; + virtual bool IsBridge (void) const; virtual bool Send(Ptr packet, const Address &dest, uint16_t protocolNumber); virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/wifi/wifi-net-device.cc --- a/src/devices/wifi/wifi-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/wifi/wifi-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -267,6 +267,11 @@ WifiNetDevice::IsPointToPoint (void) con return false; } bool +WifiNetDevice::IsBridge (void) const +{ + return false; +} +bool WifiNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNumber) { NS_ASSERT (Mac48Address::IsMatchingType (dest)); diff -r 4b18d1e1e2e5 -r e525995ce5dc src/devices/wifi/wifi-net-device.h --- a/src/devices/wifi/wifi-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/devices/wifi/wifi-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -94,6 +94,7 @@ public: virtual bool IsMulticast (void) const; virtual Address GetMulticast (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; + virtual bool IsBridge (void) const; virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; virtual void SetNode (Ptr node); diff -r 4b18d1e1e2e5 -r e525995ce5dc src/node/net-device.h --- a/src/node/net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/node/net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -184,6 +184,15 @@ public: virtual Address GetMulticast (Ipv6Address addr) const = 0; /** + * \brief Return true if the net device is acting as a bridge. + * + * \return value of m_isBridge flag + */ + virtual bool IsBridge (void) const = 0; + + /** + * \brief Return true if the net device is on a point-to-point link. + * * \return value of m_isPointToPoint flag */ virtual bool IsPointToPoint (void) const = 0; diff -r 4b18d1e1e2e5 -r e525995ce5dc src/node/simple-net-device.cc --- a/src/node/simple-net-device.cc Tue Nov 18 15:46:46 2008 -0800 +++ b/src/node/simple-net-device.cc Tue Nov 18 16:23:31 2008 -0800 @@ -163,6 +163,13 @@ SimpleNetDevice::IsPointToPoint (void) c { return false; } + +bool +SimpleNetDevice::IsBridge (void) const +{ + return false; +} + bool SimpleNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNumber) { diff -r 4b18d1e1e2e5 -r e525995ce5dc src/node/simple-net-device.h --- a/src/node/simple-net-device.h Tue Nov 18 15:46:46 2008 -0800 +++ b/src/node/simple-net-device.h Tue Nov 18 16:23:31 2008 -0800 @@ -61,6 +61,7 @@ public: virtual bool IsMulticast (void) const; virtual Address GetMulticast (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; + virtual bool IsBridge (void) const; virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber); virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; changeset: 3872:04f9377661b8 user: Craig Dowell date: Wed Nov 19 15:54:12 2008 -0800 summary: convince global routing not to crash in the presence of bridges diff -r e525995ce5dc -r 04f9377661b8 examples/csma-bridge-one-hop.cc --- a/examples/csma-bridge-one-hop.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/examples/csma-bridge-one-hop.cc Wed Nov 19 15:54:12 2008 -0800 @@ -16,21 +16,46 @@ // Network topology // +// bridge1 The node named bridge1 (node 5 in the nodelist) +// ------------------ has three CMSA net devices that are bridged +// CSMA CSMA CSMA together using a BridgeNetDevice. +// | | | +// | | | The bridge node talks over three CSMA channels +// | | | +// CSMA CSMA CSMA to three other CSMA net devices +// ---- ---- ---- +// n0 n1 n2 Node two acts as a router and talks to another +// ---- bridge that connects the remaining nodes. +// CSMA +// | +// n3 n4 | +// ---- ---- | +// CSMA CSMA | +// | | | +// | | | +// | | | +// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist) +// ------------------ has three CMSA net devices that are bridged +// bridge2 together using a BridgeNetDevice. +// +// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes +// with three net devices: +// // n0 n1 // | | // ----------- -// | bridge1 | +// | bridge1 | <- n5 // ----------- // | -// n2 +// router <- n2 // | // ----------- -// | bridge2 | +// | bridge2 | <- n6 // ----------- // | | // n3 n4 // -// This example shows two broadcast domains, each interconnected by a bridge +// So, this example shows two broadcast domains, each interconnected by a bridge // with a router node (n2) interconnecting the layer-2 broadcast domains // // It is meant to mirror somewhat the csma-bridge example but adds another @@ -108,12 +133,17 @@ main (int argc, char *argv[]) for (int i = 0; i < 3; i++) { + // install a csma channel between the ith toplan node and the bridge node NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1)); topLanDevices.Add (link.Get (0)); topBridgeDevices.Add (link.Get (1)); } - // Create the bridge netdevice, which will do the packet switching + // + // Now, Create the bridge netdevice, which will do the packet switching. The + // bridge lives on the node bridge1 and bridges together the topBridgeDevices + // which are the three CSMA net devices on the node in the diagram above. + // BridgeHelper bridge; bridge.Install (bridge1, topBridgeDevices); @@ -132,11 +162,11 @@ main (int argc, char *argv[]) bottomBridgeDevices.Add (link.Get (1)); } bridge.Install (bridge2, bottomBridgeDevices); + + // Add internet stack to the bottomLan nodes internet.Install (NodeContainer (n3, n4)); - // We've got the "hardware" in place. Now we need to add IP addresses. - // NS_LOG_INFO ("Assign IP Addresses."); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); @@ -144,9 +174,12 @@ main (int argc, char *argv[]) ipv4.SetBase ("10.1.2.0", "255.255.255.0"); ipv4.Assign (bottomLanDevices); + // // Create router nodes, initialize routing database and set up the routing // tables in the nodes. - GlobalRouteManager::PopulateRoutingTables (); + // + NodeContainer routerNodes (n0, n1, n2, n3, n4); + GlobalRouteManager::PopulateRoutingTables (routerNodes); // // Create an OnOff application to send UDP datagrams from node zero to node 1. diff -r e525995ce5dc -r 04f9377661b8 src/core/abort.h --- a/src/core/abort.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/core/abort.h Wed Nov 19 15:54:12 2008 -0800 @@ -20,6 +20,16 @@ #define NS3_ABORT_H #include "fatal-error.h" + +#define NS_ABORT_MSG(msg) \ + do { \ + std::cerr << "file=" << __FILE__ << \ + ", line=" << __LINE__ << ", abort, msg=\"" << \ + msg << "\"" << std::endl; \ + int *a = 0; \ + *a = 0; \ + } while (false) + #define NS_ABORT_IF(cond) \ do { \ diff -r e525995ce5dc -r 04f9377661b8 src/devices/bridge/bridge-net-device.cc --- a/src/devices/bridge/bridge-net-device.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/devices/bridge/bridge-net-device.cc Wed Nov 19 15:54:12 2008 -0800 @@ -57,6 +57,7 @@ BridgeNetDevice::BridgeNetDevice () m_ifIndex (0), m_mtu (0xffff) { + NS_LOG_FUNCTION_NOARGS (); m_channel = CreateObject (); } @@ -100,6 +101,7 @@ BridgeNetDevice::ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst) { + NS_LOG_FUNCTION_NOARGS (); NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName () << ", packet=" << packet << ", protocol="< incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst) { + NS_LOG_FUNCTION_NOARGS (); NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName () << ", packet=" << packet << ", protocol="< port) { + NS_LOG_FUNCTION_NOARGS (); if (m_enableLearning) { LearnedState &state = m_learnState[source]; @@ -164,6 +168,7 @@ void BridgeNetDevice::Learn (Mac48Addres Ptr BridgeNetDevice::GetLearnedState (Mac48Address source) { + NS_LOG_FUNCTION_NOARGS (); if (m_enableLearning) { Time now = Simulator::Now (); @@ -185,9 +190,25 @@ Ptr BridgeNetDevice::GetLearn return NULL; } +uint32_t +BridgeNetDevice::GetNBridgePorts (void) const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_ports.size (); +} + + +Ptr +BridgeNetDevice::GetBridgePort (uint32_t n) const +{ + NS_LOG_FUNCTION_NOARGS (); + return m_ports[n]; +} + void BridgeNetDevice::AddBridgePort (Ptr bridgePort) { + NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (bridgePort != this); if (!Mac48Address::IsMatchingType (bridgePort->GetAddress ())) { @@ -212,42 +233,49 @@ void void BridgeNetDevice::SetName(const std::string name) { + NS_LOG_FUNCTION_NOARGS (); m_name = name; } std::string BridgeNetDevice::GetName(void) const { + NS_LOG_FUNCTION_NOARGS (); return m_name; } void BridgeNetDevice::SetIfIndex(const uint32_t index) { + NS_LOG_FUNCTION_NOARGS (); m_ifIndex = index; } uint32_t BridgeNetDevice::GetIfIndex(void) const { + NS_LOG_FUNCTION_NOARGS (); return m_ifIndex; } Ptr BridgeNetDevice::GetChannel (void) const { + NS_LOG_FUNCTION_NOARGS (); return m_channel; } Address BridgeNetDevice::GetAddress (void) const { + NS_LOG_FUNCTION_NOARGS (); return m_address; } bool BridgeNetDevice::SetMtu (const uint16_t mtu) { + NS_LOG_FUNCTION_NOARGS (); m_mtu = mtu; return true; } @@ -255,6 +283,7 @@ uint16_t uint16_t BridgeNetDevice::GetMtu (void) const { + NS_LOG_FUNCTION_NOARGS (); return m_mtu; } @@ -262,6 +291,7 @@ bool bool BridgeNetDevice::IsLinkUp (void) const { + NS_LOG_FUNCTION_NOARGS (); return true; } @@ -274,6 +304,7 @@ bool bool BridgeNetDevice::IsBroadcast (void) const { + NS_LOG_FUNCTION_NOARGS (); return true; } @@ -281,12 +312,14 @@ Address Address BridgeNetDevice::GetBroadcast (void) const { + NS_LOG_FUNCTION_NOARGS (); return Mac48Address ("ff:ff:ff:ff:ff:ff"); } bool BridgeNetDevice::IsMulticast (void) const { + NS_LOG_FUNCTION_NOARGS (); return true; } @@ -302,12 +335,14 @@ bool bool BridgeNetDevice::IsPointToPoint (void) const { + NS_LOG_FUNCTION_NOARGS (); return false; } bool BridgeNetDevice::IsBridge (void) const { + NS_LOG_FUNCTION_NOARGS (); return true; } @@ -315,6 +350,7 @@ bool bool BridgeNetDevice::Send (Ptr packet, const Address& dest, uint16_t protocolNumber) { + NS_LOG_FUNCTION_NOARGS (); for (std::vector< Ptr >::iterator iter = m_ports.begin (); iter != m_ports.end (); iter++) { @@ -328,6 +364,7 @@ bool bool BridgeNetDevice::SendFrom (Ptr packet, const Address& src, const Address& dest, uint16_t protocolNumber) { + NS_LOG_FUNCTION_NOARGS (); for (std::vector< Ptr >::iterator iter = m_ports.begin (); iter != m_ports.end (); iter++) { @@ -342,6 +379,7 @@ Ptr Ptr BridgeNetDevice::GetNode (void) const { + NS_LOG_FUNCTION_NOARGS (); return m_node; } @@ -349,6 +387,7 @@ void void BridgeNetDevice::SetNode (Ptr node) { + NS_LOG_FUNCTION_NOARGS (); m_node = node; } @@ -356,6 +395,7 @@ bool bool BridgeNetDevice::NeedsArp (void) const { + NS_LOG_FUNCTION_NOARGS (); return true; } @@ -363,25 +403,28 @@ void void BridgeNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb) { + NS_LOG_FUNCTION_NOARGS (); m_rxCallback = cb; } void BridgeNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb) { + NS_LOG_FUNCTION_NOARGS (); m_promiscRxCallback = cb; } bool BridgeNetDevice::SupportsSendFrom () const { + NS_LOG_FUNCTION_NOARGS (); return true; } - void BridgeNetDevice::DoDispose (void) { + NS_LOG_FUNCTION_NOARGS (); m_node = 0; NetDevice::DoDispose (); } diff -r e525995ce5dc -r 04f9377661b8 src/devices/bridge/bridge-net-device.h --- a/src/devices/bridge/bridge-net-device.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/devices/bridge/bridge-net-device.h Wed Nov 19 15:54:12 2008 -0800 @@ -82,6 +82,10 @@ public: */ void AddBridgePort (Ptr bridgePort); + uint32_t GetNBridgePorts (void) const; + + Ptr GetBridgePort (uint32_t n) const; + // inherited from NetDevice base class. virtual void SetName(const std::string name); virtual std::string GetName(void) const; diff -r e525995ce5dc -r 04f9377661b8 src/helper/bridge-helper.cc --- a/src/helper/bridge-helper.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/helper/bridge-helper.cc Wed Nov 19 15:54:12 2008 -0800 @@ -1,24 +1,49 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #include "bridge-helper.h" - +#include "ns3/log.h" #include "ns3/bridge-net-device.h" #include "ns3/node.h" + +NS_LOG_COMPONENT_DEFINE ("BridgeHelper"); namespace ns3 { BridgeHelper::BridgeHelper () { + NS_LOG_FUNCTION_NOARGS (); m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice"); } void BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1) { + NS_LOG_FUNCTION_NOARGS (); m_deviceFactory.Set (n1, v1); } NetDeviceContainer BridgeHelper::Install (Ptr node, NetDeviceContainer c) { + NS_LOG_FUNCTION_NOARGS (); + NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ()); + NetDeviceContainer devs; Ptr dev = m_deviceFactory.Create (); devs.Add (dev); @@ -26,6 +51,7 @@ BridgeHelper::Install (Ptr node, N for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i) { + NS_LOG_LOGIC ("**** Add BridgePort "<< *i); dev->AddBridgePort (*i); } return devs; diff -r e525995ce5dc -r 04f9377661b8 src/helper/node-container.cc --- a/src/helper/node-container.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/helper/node-container.cc Wed Nov 19 15:54:12 2008 -0800 @@ -48,6 +48,17 @@ NodeContainer::NodeContainer (const Node Add (b); Add (c); Add (d); +} + +NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, + const NodeContainer &c, const NodeContainer &d, + const NodeContainer &e) +{ + Add (a); + Add (b); + Add (c); + Add (d); + Add (e); } NodeContainer::Iterator diff -r e525995ce5dc -r 04f9377661b8 src/helper/node-container.h --- a/src/helper/node-container.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/helper/node-container.h Wed Nov 19 15:54:12 2008 -0800 @@ -64,6 +64,8 @@ public: NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c); NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d); + NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d, + const NodeContainer &e); /** * \returns an iterator to the start of the vector of node pointers. diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-route-manager-impl.cc --- a/src/routing/global-routing/global-route-manager-impl.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-route-manager-impl.cc Wed Nov 19 15:54:12 2008 -0800 @@ -351,8 +351,7 @@ GlobalRouteManagerImpl::DebugUseLsdb (Gl // // In order to build the routing database, we need at least one of the nodes -// to participate as a router. Eventually we expect to provide a mechanism -// for selecting a subset of the nodes to participate; for now, we just make +// to participate as a router. This is a convenience function that makes // all nodes routers. We do this by walking the list of nodes in the system // and aggregating a Global Router Interface to each of the nodes. // @@ -361,6 +360,21 @@ GlobalRouteManagerImpl::SelectRouterNode { NS_LOG_FUNCTION_NOARGS (); for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) + { + Ptr node = *i; + NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << + node->GetId ()); + + Ptr globalRouter = CreateObject (); + node->AggregateObject (globalRouter); + } +} + + void +GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) +{ + NS_LOG_FUNCTION_NOARGS (); + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) { Ptr node = *i; NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-route-manager-impl.h --- a/src/routing/global-routing/global-route-manager-impl.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-route-manager-impl.h Wed Nov 19 15:54:12 2008 -0800 @@ -29,6 +29,7 @@ #include "ns3/object.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" +#include "ns3/node-container.h" #include "global-router-interface.h" namespace ns3 { @@ -708,6 +709,14 @@ public: virtual void SelectRouterNodes (); /** + * @brief Select which nodes in the system are to be router nodes and + * aggregate the appropriate interfaces onto those nodes. + * @internal + * + */ + virtual void SelectRouterNodes (NodeContainer c); + +/** * @brief Build the routing database by gathering Link State Advertisements * from each node exporting a GlobalRouter interface. * @internal diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-route-manager.cc --- a/src/routing/global-routing/global-route-manager.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-route-manager.cc Wed Nov 19 15:54:12 2008 -0800 @@ -21,6 +21,7 @@ #include "ns3/assert.h" #include "ns3/log.h" #include "ns3/simulation-singleton.h" +#include "ns3/node-container.h" #include "global-route-manager.h" #include "global-route-manager-impl.h" @@ -33,7 +34,7 @@ namespace ns3 { // --------------------------------------------------------------------------- void -GlobalRouteManager::PopulateRoutingTables () +GlobalRouteManager::PopulateRoutingTables (void) { SelectRouterNodes (); BuildGlobalRoutingDatabase (); @@ -41,28 +42,43 @@ GlobalRouteManager::PopulateRoutingTable } void -GlobalRouteManager::SelectRouterNodes () +GlobalRouteManager::PopulateRoutingTables (NodeContainer c) +{ + SelectRouterNodes (c); + BuildGlobalRoutingDatabase (); + InitializeRoutes (); +} + + void +GlobalRouteManager::SelectRouterNodes (void) { SimulationSingleton::Get ()-> SelectRouterNodes (); } void -GlobalRouteManager::BuildGlobalRoutingDatabase () +GlobalRouteManager::SelectRouterNodes (NodeContainer c) +{ + SimulationSingleton::Get ()-> + SelectRouterNodes (c); +} + + void +GlobalRouteManager::BuildGlobalRoutingDatabase (void) { SimulationSingleton::Get ()-> BuildGlobalRoutingDatabase (); } void -GlobalRouteManager::InitializeRoutes () +GlobalRouteManager::InitializeRoutes (void) { SimulationSingleton::Get ()-> InitializeRoutes (); } uint32_t -GlobalRouteManager::AllocateRouterId () +GlobalRouteManager::AllocateRouterId (void) { static uint32_t routerId = 0; return routerId++; diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-route-manager.h --- a/src/routing/global-routing/global-route-manager.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-route-manager.h Wed Nov 19 15:54:12 2008 -0800 @@ -22,6 +22,8 @@ #ifndef GLOBAL_ROUTE_MANAGER_H #define GLOBAL_ROUTE_MANAGER_H +#include "ns3/node-container.h" + namespace ns3 { /** @@ -40,7 +42,8 @@ public: public: /** * @brief Build a routing database and initialize the routing tables of - * the nodes in the simulation. + * the nodes in the simulation. Makes all nodes in the simulation into + * routers. * * All this function does is call BuildGlobalRoutingDatabase () and * InitializeRoutes (). @@ -49,6 +52,19 @@ public: * @see InitializeRoutes (); */ static void PopulateRoutingTables (); + +/** + * @brief Build a routing database and initialize the routing tables of + * the nodes in the simulation. Makes the nodes in the provided container + * into routers. + * + * All this function does is call BuildGlobalRoutingDatabase () and + * InitializeRoutes (). + * + * @see BuildGlobalRoutingDatabase (); + * @see InitializeRoutes (); + */ + static void PopulateRoutingTables (NodeContainer c); /** * @brief Allocate a 32-bit router ID from monotonically increasing counter. @@ -63,6 +79,14 @@ private: * */ static void SelectRouterNodes (); + +/** + * @brief Select which nodes in the system are to be router nodes and + * aggregate the appropriate interfaces onto those nodes. + * @internal + * + */ + static void SelectRouterNodes (NodeContainer c); /** * @brief Build the routing database by gathering Link State Advertisements diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Wed Nov 19 15:54:12 2008 -0800 @@ -20,11 +20,14 @@ #include "ns3/log.h" #include "ns3/assert.h" +#include "ns3/abort.h" #include "ns3/channel.h" #include "ns3/net-device.h" #include "ns3/node.h" #include "ns3/ipv4.h" +#include "ns3/bridge-net-device.h" #include "global-router-interface.h" +#include NS_LOG_COMPONENT_DEFINE ("GlobalRouter"); @@ -365,8 +368,7 @@ GlobalRoutingLSA::GetAttachedRouter (uin return *i; } } - NS_ASSERT_MSG(false, - "GlobalRoutingLSA::GetAttachedRouter (): invalid index"); + NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetAttachedRouter (): invalid index"); return Ipv4Address("0.0.0.0"); } @@ -495,45 +497,108 @@ GlobalRouter::DiscoverLSAs (void) { NS_LOG_FUNCTION_NOARGS (); Ptr node = GetObject (); - NS_LOG_LOGIC("For node " << node->GetId () ); - NS_ASSERT_MSG(node, - "GlobalRouter::DiscoverLSAs (): interface not set"); + NS_ABORT_MSG_UNLESS (node, "GlobalRouter::DiscoverLSAs (): GetObject for interface failed"); + NS_LOG_LOGIC ("For node " << node->GetId () ); ClearLSAs (); - +// // While building the router-LSA, keep a list of those NetDevices for // which I am the designated router and need to later build a NetworkLSA +// std::list > listOfDRInterfaces; // // We're aggregated to a node. We need to ask the node for a pointer to its // Ipv4 interface. This is where the information regarding the attached -// interfaces lives. +// interfaces lives. If we're a router, we had better have an Ipv4 interface. // Ptr ipv4Local = node->GetObject (); - NS_ASSERT_MSG(ipv4Local, - "GlobalRouter::DiscoverLSAs (): QI for interface failed"); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for interface failed"); // -// Each node originates a Router-LSA +// Each node is a router and so originates a Router-LSA // GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; pLSA->SetLSType (GlobalRoutingLSA::RouterLSA); pLSA->SetLinkStateId (m_routerId); pLSA->SetAdvertisingRouter (m_routerId); pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); + // -// We need to ask the node for the number of net devices attached. This isn't -// necessarily equal to the number of links to adjacent nodes (other routers) -// as the number of devices may include those for stub networks (e.g., -// ethernets, etc.). +// Ask the node for the number of net devices attached. This isn't necessarily +// equal to the number of links to adjacent nodes (other routers) as the number +// of devices may include those for stub networks (e.g., ethernets, etc.) and +// bridge devices also take up an "extra" net device. // uint32_t numDevices = node->GetNDevices(); NS_LOG_LOGIC ("numDevices = " << numDevices); + +// +// There are two broad classes of devices: bridges in combination with the +// devices they bridge and everything else. We need to first discover all of +// the "everything else" class of devices. +// +// To do this, we wander through all of the devices on the node looking for +// bridge net devices. We then add any net devices associated to a bridge +// to a list of bridged devices. These devices will not be treated as stand- +// alone devices later. +// + std::vector > bridgedDevices; + + NS_LOG_LOGIC ("*************************"); + + NS_LOG_LOGIC ("numDevices = " << numDevices); + for (uint32_t i = 0; i < numDevices; ++i) + { + Ptr nd = node->GetDevice(i); + if (nd->IsBridge ()) + { + NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge"); + // + // XXX There is only one kind of bridge device so far. We agreed to + // assume that it is Gustavo's learning bridge until there is a need + // to deal with another. At that time, we'll have to break out a + // bridge interface. + // + Ptr bnd = nd->GetObject (); + NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); + + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) + { + NS_LOG_LOGIC ("**** Net device " << bnd << "is a bridged device"); + bridgedDevices.push_back (bnd->GetBridgePort (j)); + } + } + } + + // + // Iterate through the devices on the node and walk the channel to see what's + // on the other side of the standalone devices.. + // for (uint32_t i = 0; i < numDevices; ++i) { Ptr ndLocal = node->GetDevice(i); + // + // If the device in question is on our list of bridged devices, then we + // just ignore it. It will be dealt with correctly when we probe the + // bridge device it belongs to. It is the case that the bridge code + // assumes that bridged devices must not have IP interfaces, and so it + // may actually sufficient to perform the test for IP interface below, + // but that struck me as too indirect a condition. + // + for (uint32_t j = 0; j < bridgedDevices.size (); ++j) + { + if (ndLocal == bridgedDevices[j]) + { + NS_LOG_LOGIC ("**** Skipping Bridged Device"); - // Check if it is an IP interface (could be a pure L2 NetDevice) + continue; + } + } + + // + // Check to see if the net device we just got has a corresponding IP + // interface (could be a pure L2 NetDevice). + // bool isIp = false; for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i ) { @@ -543,26 +608,29 @@ GlobalRouter::DiscoverLSAs (void) break; } } + if (!isIp) { + NS_LOG_LOGIC ("**** Net device " << ndLocal << "has no IP interface, skipping"); continue; } if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () ) { - NS_LOG_LOGIC ("Broadcast link"); + NS_LOG_LOGIC ("**** Broadcast link"); GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; // // We need to determine whether we are on a transit or stub network // If we find at least one more router on this channel, we are a transit -// +// network. If we're the only router, we're on a stub. // // Now, we have to find the Ipv4 interface whose netdevice is the one we -// just found. This is still 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 it's not -// exported so we had to whip up an equivalent. +// just found. This is still the IP on the local side of the channel. // - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); NS_LOG_LOGIC ("Working with local address " << addrLocal); @@ -577,7 +645,7 @@ GlobalRouter::DiscoverLSAs (void) if (nDevices == 1) { // This is a stub broadcast interface - NS_LOG_LOGIC("Router-LSA stub broadcast link"); + NS_LOG_LOGIC("**** Router-LSA stub broadcast link"); // XXX in future, need to consider if >1 includes other routers plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); // Link ID is IP network number of attached network @@ -593,7 +661,7 @@ GlobalRouter::DiscoverLSAs (void) } else { - NS_LOG_LOGIC ("Router-LSA Broadcast link"); + NS_LOG_LOGIC ("**** Router-LSA Broadcast link"); // multiple routers on a broadcast interface // lowest IP address is designated router plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); @@ -616,14 +684,16 @@ GlobalRouter::DiscoverLSAs (void) } else if (ndLocal->IsPointToPoint () ) { - NS_LOG_LOGIC ("Router-LSA Point-to-point device"); + NS_LOG_LOGIC ("**** Router-LSA Point-to-point device"); // // Now, we have to find the Ipv4 interface whose netdevice is the one we // just found. This is still 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 it's not // exported so we had to whip up an equivalent. // - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); // // Now that we have the Ipv4 interface index, we can get the address and mask // we need. @@ -642,30 +712,43 @@ GlobalRouter::DiscoverLSAs (void) { continue; } +// +// Get the net device on the other side of the point-to-point channel. +// Ptr ndRemote = GetAdjacent(ndLocal, 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. +// device for its node, then ask that node for its Ipv4 interface. Note a +// requirement that nodes on either side of a point-to-point link must have +// internet stacks. // Ptr nodeRemote = ndRemote->GetNode(); Ptr ipv4Remote = nodeRemote->GetObject (); - NS_ASSERT_MSG(ipv4Remote, - "GlobalRouter::DiscoverLSAs (): QI for remote failed"); + NS_ABORT_MSG_UNLESS (ipv4Remote, + "GlobalRouter::DiscoverLSAs (): GetObject for remote failed"); // // Per the OSPF spec, we're going to need the remote router ID, so we might as // well get it now. // - Ptr srRemote = - nodeRemote->GetObject (); - NS_ASSERT_MSG(srRemote, - "GlobalRouter::DiscoverLSAs():QI for remote failed"); +// While we're at it, further note the requirement that nodes on either side of +// a point-to-point link must participateg in global routing and therefore have +// a GlobalRouter interface aggregated. +// + Ptr srRemote = nodeRemote->GetObject (); + NS_ABORT_MSG_UNLESS(srRemote, + "GlobalRouter::DiscoverLSAs(): GetObject for remote failed"); + Ipv4Address rtrIdRemote = srRemote->GetRouterId(); NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote); // // 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. +// net device on the other end of the point-to-point channel. We have yet another +// assumption that point to point devices are incompatible with bridges and that +// the remote device must have an associated ip interface. // - uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote); + uint32_t ifIndexRemote; + rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with remote device"); // // Now that we have the Ipv4 interface, we can get the (remote) address and // mask we need. @@ -698,23 +781,38 @@ GlobalRouter::DiscoverLSAs (void) { NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type"); } - } // // The LSA goes on a list of LSAs in case we want to begin exporting other // kinds of advertisements (than Router LSAs). +// m_LSAs.push_back (pLSA); NS_LOG_LOGIC (*pLSA); -// Now, determine whether we need to build a NetworkLSA +// +// Now, determine whether we need to build a NetworkLSA. This is the case if +// we found at least one designated router. +// if (listOfDRInterfaces.size () > 0) { for (std::list >::iterator i = listOfDRInterfaces.begin (); i != listOfDRInterfaces.end (); i++) { +// // Build one NetworkLSA for each interface that is a DR +// Ptr ndLocal = *i; - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); + + // + // We are working with a list of net devices off of the local node + // on which we found a designated router. We assume there must be + // an associated ipv4 interface index. + // + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); @@ -724,7 +822,13 @@ GlobalRouter::DiscoverLSAs (void) pLSA->SetAdvertisingRouter (m_routerId); pLSA->SetNetworkLSANetworkMask (maskLocal); pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); -// Build list of AttachedRouters +// +// XXX Doesn't deal with bridging +// +// Build a list of AttachedRouters by walking the devices in the channel +// and, if we find an IPv4 interface associated with that device, we +// call it an attached router. +// Ptr ch = ndLocal->GetChannel(); uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); @@ -733,11 +837,16 @@ GlobalRouter::DiscoverLSAs (void) Ptr tempNd = ch->GetDevice (i); NS_ASSERT (tempNd); Ptr tempNode = tempNd->GetNode (); - uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd); - Ptr tempIpv4 = tempNode->GetObject (); - NS_ASSERT (tempIpv4); - Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); - pLSA->AddAttachedRouter (tempAddr); + uint32_t tempIfIndex; + if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex)) + { + + Ptr tempIpv4 = tempNode->GetObject (); + NS_ASSERT (tempIpv4); + Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); + pLSA->AddAttachedRouter (tempAddr); + + } } m_LSAs.push_back (pLSA); NS_LOG_LOGIC (*pLSA); @@ -747,33 +856,80 @@ GlobalRouter::DiscoverLSAs (void) return m_LSAs.size (); } +// +// Given a node and an attached net device, we need to walk the channel to which +// the net device is attached and look for the lowest IP address on all of the +// devices attached to that channel. This process is complicated by the fact +// there may be bridge devices associated with any of the net devices attached +// to the channel. +// Ipv4Address -GlobalRouter::FindDesignatedRouterForLink (Ptr node, - Ptr ndLocal) const + GlobalRouter::FindDesignatedRouterForLink (Ptr node, Ptr ndLocal) const { - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal); + NS_LOG_FUNCTION_NOARGS (); + NS_LOG_LOGIC("**** For node " << node->GetId () << " for net device " << ndLocal ); + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); + Ptr ipv4Local = GetObject (); - NS_ASSERT (ipv4Local); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for interface failed" + " on node " << node->GetId ()); + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); Ptr ch = ndLocal->GetChannel(); uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); + + NS_LOG_LOGIC("**** channel " << ch << " has " << nDevices << " net devices"); + + // + // We now have the channel associated with the net device in question. We + // need to iterate over all of the net devices attached to that channel. + // + Ipv4Address lowest = addrLocal; - // iterate all NetDevices and return the lowest numbered IP address + for (uint32_t i = 0; i < nDevices; i++) { - Ptr tempNd = ch->GetDevice (i); - NS_ASSERT (tempNd); - Ptr tempNode = tempNd->GetNode (); - uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd); - Ptr tempIpv4 = tempNode->GetObject (); - NS_ASSERT (tempIpv4); - Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); - if (tempAddr < addrLocal) + Ptr ndTemp = ch->GetDevice (i); + NS_ASSERT_MSG (ndTemp, "GlobalRouter::FindDesignatedRouterForLink(): Null device attached to channel"); + + if (ndTemp == ndLocal) { - addrLocal = tempAddr; + continue; + } + + Ptr nodeTemp = ndTemp->GetNode (); + + NS_LOG_LOGIC("**** channel connects to node " << nodeTemp->GetId () << " with net device " << ndTemp); + + // + // XXX doesn't admit the possibility of a bridge + // + // If the remote device doesn't have an ipv4 interface index associated + // with it, it cannot be a designated router. + // + uint32_t ifIndexTemp; + bool rc = FindIfIndexForDevice(nodeTemp, ndTemp, ifIndexTemp); + if (rc == false) + { + continue; + } + + Ptr ipv4Temp = nodeTemp->GetObject (); + NS_ASSERT_MSG (ipv4Temp, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for interface failed" + " on node " << node->GetId ()); + + Ipv4Address addrTemp = ipv4Temp->GetAddress(ifIndexTemp); + + NS_LOG_LOGIC("**** net device " << ndTemp << " has Ipv4Address " << addrTemp); + if (addrTemp < addrLocal) + { + addrLocal = addrTemp; } } return addrLocal; @@ -852,25 +1008,37 @@ GlobalRouter::GetAdjacent(Ptr } // -// Given a node and a net device, find the IPV4 interface index that -// corresponds to that net device. +// Given a node and a net device, find an IPV4 interface index that corresponds +// to that net device. This function may fail for various reasons. If a node +// does not have an internet stack (for example if it is a bridge) we won't have +// an IPv4 at all. If the node does have a stack, but the net device in question +// is bridged, there will not be an interface associated directly with the device. // - uint32_t -GlobalRouter::FindIfIndexForDevice(Ptr node, Ptr nd) const + bool +GlobalRouter::FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const { NS_LOG_FUNCTION_NOARGS (); + NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd ); + Ptr ipv4 = node->GetObject (); - NS_ASSERT_MSG(ipv4, "QI for interface failed"); + if (ipv4 == 0) + { + NS_LOG_LOGIC ("**** No Ipv4 interface on node " << node->GetId ()); + return false; + } + for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i ) { if (ipv4->GetNetDevice(i) == nd) { - return i; + NS_LOG_LOGIC ("**** Device " << nd << " has associated ipv4 index " << i); + index = i; + return true; } } - NS_ASSERT_MSG(0, "Cannot find interface for device"); - return 0; + NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index"); + return false; } } // namespace ns3 diff -r e525995ce5dc -r 04f9377661b8 src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Tue Nov 18 16:23:31 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Wed Nov 19 15:54:12 2008 -0800 @@ -639,7 +639,7 @@ private: void ClearLSAs (void); Ptr GetAdjacent(Ptr nd, Ptr ch) const; - uint32_t FindIfIndexForDevice(Ptr node, Ptr nd) const; + bool FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const; Ipv4Address FindDesignatedRouterForLink (Ptr node, Ptr ndLocal) const; changeset: 3873:972310213d07 user: Craig Dowell date: Wed Nov 19 18:44:20 2008 -0800 summary: Admit possibility that not all nodes are routers. diff -r 04f9377661b8 -r 972310213d07 examples/csma-bridge-one-hop.cc --- a/examples/csma-bridge-one-hop.cc Wed Nov 19 15:54:12 2008 -0800 +++ b/examples/csma-bridge-one-hop.cc Wed Nov 19 18:44:20 2008 -0800 @@ -176,7 +176,8 @@ main (int argc, char *argv[]) // // Create router nodes, initialize routing database and set up the routing - // tables in the nodes. + // tables in the nodes. We excuse the bridge nodes from having to serve as + // routers, since they don't even have internet stacks on them. // NodeContainer routerNodes (n0, n1, n2, n3, n4); GlobalRouteManager::PopulateRoutingTables (routerNodes); diff -r 04f9377661b8 -r 972310213d07 src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Wed Nov 19 15:54:12 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Wed Nov 19 18:44:20 2008 -0800 @@ -530,6 +530,7 @@ GlobalRouter::DiscoverLSAs (void) // bridge devices also take up an "extra" net device. // uint32_t numDevices = node->GetNDevices(); + NS_LOG_LOGIC ("*************************"); NS_LOG_LOGIC ("numDevices = " << numDevices); // @@ -538,18 +539,16 @@ GlobalRouter::DiscoverLSAs (void) // the "everything else" class of devices. // // To do this, we wander through all of the devices on the node looking for -// bridge net devices. We then add any net devices associated to a bridge -// to a list of bridged devices. These devices will not be treated as stand- -// alone devices later. +// bridge net devices. We then add any net devices associated with each bridge +// to a list of bridged devices. These devices will be treated as a special +// case later. // std::vector > bridgedDevices; - NS_LOG_LOGIC ("*************************"); - - NS_LOG_LOGIC ("numDevices = " << numDevices); for (uint32_t i = 0; i < numDevices; ++i) { Ptr nd = node->GetDevice(i); + if (nd->IsBridge ()) { NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge"); @@ -597,7 +596,7 @@ GlobalRouter::DiscoverLSAs (void) // // Check to see if the net device we just got has a corresponding IP - // interface (could be a pure L2 NetDevice). + // interface (could be a pure L2 NetDevice that is not a bridge). // bool isIp = false; for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i ) @@ -615,6 +614,11 @@ GlobalRouter::DiscoverLSAs (void) continue; } +// +// We have a net device that we need to check out. If it suports broadcast and +// is not a point-point link, then it will be either a stub network or a transit +// network depending on the number of routers. +// if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () ) { NS_LOG_LOGIC ("**** Broadcast link"); @@ -636,21 +640,26 @@ GlobalRouter::DiscoverLSAs (void) NS_LOG_LOGIC ("Working with local address " << addrLocal); uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); // -// Now, we're going to walk over to the remote net device on the other end of -// the point-to-point channel we now know we have. This is where our adjacent -// router (to use OSPF lingo) is running. +// Check to see if the net device is connected to a channel/network that has +// another router on it. If there is no other router on the link (but us) then +// this is a stub network. If we find another router, then what we have here +// is a transit network. // - Ptr ch = ndLocal->GetChannel(); - uint32_t nDevices = ch->GetNDevices(); - if (nDevices == 1) + if (AnotherRouterOnLink (ndLocal) == false) { - // This is a stub broadcast interface - NS_LOG_LOGIC("**** Router-LSA stub broadcast link"); - // XXX in future, need to consider if >1 includes other routers + // + // This is a net device connected to a stub network + // + NS_LOG_LOGIC("**** Router-LSA Stub Network"); plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); - // Link ID is IP network number of attached network + // + // According to OSPF, the Link ID is the IP network number of + // the attached network. + // plr->SetLinkId (addrLocal.CombineMask(maskLocal)); - // Link Data is network mask; convert to Ipv4Address + // + // and the Link Data is the network mask; converted to Ipv4Address + // Ipv4Address maskLocalAddr; maskLocalAddr.Set(maskLocal.Get ()); plr->SetLinkData (maskLocalAddr); @@ -661,20 +670,28 @@ GlobalRouter::DiscoverLSAs (void) } else { - NS_LOG_LOGIC ("**** Router-LSA Broadcast link"); - // multiple routers on a broadcast interface - // lowest IP address is designated router + // + // We have multiple routers on a broadcast interface, so this is + // a transit network. + // + NS_LOG_LOGIC ("**** Router-LSA Transit Network"); plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); - // Link ID is IP interface address of designated router - Ipv4Address desigRtr = - FindDesignatedRouterForLink (node, ndLocal); + // + // By definition, the router with the lowest IP address is the + // designated router for the network. OSPF says that the Link ID + // gets the IP interface address of the designated router in this + // case. + // + Ipv4Address desigRtr = FindDesignatedRouterForLink (ndLocal); if (desigRtr == addrLocal) { listOfDRInterfaces.push_back (ndLocal); NS_LOG_LOGIC (node->GetId () << " is a DR"); } plr->SetLinkId (desigRtr); - // Link Data is router's own IP address + // + // OSPF says that the Link Data is this router's own IP address. + // plr->SetLinkData (addrLocal); plr->SetMetric (metricLocal); pLSA->AddLinkRecord (plr); @@ -787,6 +804,7 @@ GlobalRouter::DiscoverLSAs (void) // kinds of advertisements (than Router LSAs). // m_LSAs.push_back (pLSA); + NS_LOG_LOGIC ("========== Link State Advertisement for node " << node->GetId () << " =========="); NS_LOG_LOGIC (*pLSA); // @@ -795,19 +813,15 @@ GlobalRouter::DiscoverLSAs (void) // if (listOfDRInterfaces.size () > 0) { + NS_LOG_LOGIC ("Build Network LSA"); for (std::list >::iterator i = listOfDRInterfaces.begin (); i != listOfDRInterfaces.end (); i++) { // -// Build one NetworkLSA for each interface that is a DR +// Build one NetworkLSA for each net device talking to a netwok that we are the +// designated router for. // Ptr ndLocal = *i; - - // - // We are working with a list of net devices off of the local node - // on which we found a designated router. We assume there must be - // an associated ipv4 interface index. - // uint32_t ifIndexLocal; bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); @@ -823,11 +837,9 @@ GlobalRouter::DiscoverLSAs (void) pLSA->SetNetworkLSANetworkMask (maskLocal); pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); // -// XXX Doesn't deal with bridging -// // Build a list of AttachedRouters by walking the devices in the channel -// and, if we find an IPv4 interface associated with that device, we -// call it an attached router. +// and, if we find a node with a GlobalRouter interface and an IPv4 +// interface associated with that device, we call it an attached router. // Ptr ch = ndLocal->GetChannel(); uint32_t nDevices = ch->GetNDevices(); @@ -837,15 +849,27 @@ GlobalRouter::DiscoverLSAs (void) Ptr tempNd = ch->GetDevice (i); NS_ASSERT (tempNd); Ptr tempNode = tempNd->GetNode (); +// +// Does the node in question have a GlobalRouter interface? If not it can +// hardly be considered an attached router. +// + Ptr rtr = tempNode->GetObject (); + if (rtr == 0) + { + continue; + } + +// +// Does the attached node have an ipv4 interface for the device we're probing? +// If not, it can't play router. +// uint32_t tempIfIndex; if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex)) { - Ptr tempIpv4 = tempNode->GetObject (); NS_ASSERT (tempIpv4); Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); pLSA->AddAttachedRouter (tempAddr); - } } m_LSAs.push_back (pLSA); @@ -857,82 +881,108 @@ GlobalRouter::DiscoverLSAs (void) } // -// Given a node and an attached net device, we need to walk the channel to which -// the net device is attached and look for the lowest IP address on all of the -// devices attached to that channel. This process is complicated by the fact -// there may be bridge devices associated with any of the net devices attached -// to the channel. +// Given a local net device, we need to walk the channel to which the net device is +// attached and look for nodes with GlobalRouter interfaces on them (one of them +// will be us). Of these, the router with the lowest IP address on the net device +// connecting to the channel becomes the designated router for the link. // Ipv4Address - GlobalRouter::FindDesignatedRouterForLink (Ptr node, Ptr ndLocal) const +GlobalRouter::FindDesignatedRouterForLink (Ptr ndLocal) const { NS_LOG_FUNCTION_NOARGS (); - NS_LOG_LOGIC("**** For node " << node->GetId () << " for net device " << ndLocal ); - - uint32_t ifIndexLocal; - bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); - - Ptr ipv4Local = GetObject (); - NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for interface failed" - " on node " << node->GetId ()); - - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); Ptr ch = ndLocal->GetChannel(); uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); - NS_LOG_LOGIC("**** channel " << ch << " has " << nDevices << " net devices"); + Ipv4Address addr ("255.255.255.255"); + + for (uint32_t i = 0; i < nDevices; i++) + { + Ptr currentNd = ch->GetDevice (i); + NS_ASSERT (currentNd); + + Ptr currentNode = currentNd->GetNode (); + NS_ASSERT (currentNode); + // + // We require a designated router to have a GlobalRouter interface and + // an internet stack that includes the Ipv4 interface. + // + Ptr rtr = currentNode->GetObject (); + Ptr ipv4 = currentNode->GetObject (); + if (rtr == 0 || ipv4 == 0 ) + { + continue; + } + + // + // This node could be a designated router, so we can check and see if + // it has a lower IP address than the one we have. In order to have + // an IP address, it needs to have an interface index. If it doesen't + // have an interface index directly, it's probably part of a bridge + // net device XXX which is not yet handled. + // + uint32_t currentIfIndex; + bool rc = FindIfIndexForDevice(currentNode, currentNd, currentIfIndex); + if (rc == false) + { + continue; + } + + // + // Okay, get the IP address corresponding to the interface we're + // examining and if it's the lowest so far, remember it. + // + Ipv4Address currentAddr = ipv4->GetAddress(currentIfIndex); + + if (currentAddr < addr) + { + addr = currentAddr; + } + } // - // We now have the channel associated with the net device in question. We - // need to iterate over all of the net devices attached to that channel. + // Return the lowest IP address found, which will become the designated router + // for the link. // + NS_ASSERT_MSG (addr.IsBroadcast() == false, "GlobalRouter::FindDesignatedRouterForLink(): Bogus address"); + return addr; +} - Ipv4Address lowest = addrLocal; +// +// Given a node and an attached net device, take a look off in the channel to +// which the net device is attached and look for a node on the other side +// that has a GlobalRouter interface aggregated. +// + bool +GlobalRouter::AnotherRouterOnLink (Ptr nd) const +{ + NS_LOG_FUNCTION_NOARGS (); + + Ptr ch = nd->GetChannel(); + uint32_t nDevices = ch->GetNDevices(); + NS_ASSERT (nDevices); for (uint32_t i = 0; i < nDevices; i++) { Ptr ndTemp = ch->GetDevice (i); - NS_ASSERT_MSG (ndTemp, "GlobalRouter::FindDesignatedRouterForLink(): Null device attached to channel"); + NS_ASSERT (ndTemp); - if (ndTemp == ndLocal) + if (ndTemp == nd) { continue; } Ptr nodeTemp = ndTemp->GetNode (); + NS_ASSERT (nodeTemp); - NS_LOG_LOGIC("**** channel connects to node " << nodeTemp->GetId () << " with net device " << ndTemp); - - // - // XXX doesn't admit the possibility of a bridge - // - // If the remote device doesn't have an ipv4 interface index associated - // with it, it cannot be a designated router. - // - uint32_t ifIndexTemp; - bool rc = FindIfIndexForDevice(nodeTemp, ndTemp, ifIndexTemp); - if (rc == false) + Ptr rtr = nodeTemp->GetObject (); + if (rtr) { - continue; - } - - Ptr ipv4Temp = nodeTemp->GetObject (); - NS_ASSERT_MSG (ipv4Temp, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for interface failed" - " on node " << node->GetId ()); - - Ipv4Address addrTemp = ipv4Temp->GetAddress(ifIndexTemp); - - NS_LOG_LOGIC("**** net device " << ndTemp << " has Ipv4Address " << addrTemp); - if (addrTemp < addrLocal) - { - addrLocal = addrTemp; + return true; } } - return addrLocal; + return false; } uint32_t diff -r 04f9377661b8 -r 972310213d07 src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Wed Nov 19 15:54:12 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Wed Nov 19 18:44:20 2008 -0800 @@ -640,8 +640,8 @@ private: Ptr GetAdjacent(Ptr nd, Ptr ch) const; bool FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const; - Ipv4Address FindDesignatedRouterForLink (Ptr node, - Ptr ndLocal) const; + Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal) const; + bool AnotherRouterOnLink (Ptr nd) const; typedef std::list ListOfLSAs_t; ListOfLSAs_t m_LSAs; changeset: 3874:206f627bd5af user: Craig Dowell date: Wed Nov 19 21:21:14 2008 -0800 summary: factor DiscoverLSAs into understandable modules diff -r 972310213d07 -r 206f627bd5af src/routing/global-routing/global-route-manager-impl.cc --- a/src/routing/global-routing/global-route-manager-impl.cc Wed Nov 19 18:44:20 2008 -0800 +++ b/src/routing/global-routing/global-route-manager-impl.cc Wed Nov 19 21:21:14 2008 -0800 @@ -399,14 +399,14 @@ GlobalRouteManagerImpl::BuildGlobalRouti { NS_LOG_FUNCTION_NOARGS (); // -// Walk the list of nodes looking for the GlobalRouter Interface. +// Walk the list of nodes looking for the GlobalRouter Interface. Nodes with +// global router interfaces are, not too surprisingly, our routers. // for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++) { Ptr node = *i; - Ptr rtr = - node->GetObject (); + Ptr rtr = node->GetObject (); // // Ignore nodes that aren't participating in routing. // diff -r 972310213d07 -r 206f627bd5af src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Wed Nov 19 18:44:20 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Wed Nov 19 21:21:14 2008 -0800 @@ -26,6 +26,7 @@ #include "ns3/node.h" #include "ns3/ipv4.h" #include "ns3/bridge-net-device.h" +#include "ns3/net-device-container.h" #include "global-router-interface.h" #include @@ -489,8 +490,10 @@ GlobalRouter::GetRouterId (void) const } // -// Go out and discover any adjacent routers and build the Link State -// Advertisements that reflect them and their associated networks. +// DiscoverLSAs is called on all nodes in the system that have a GlobalRouter +// interface aggregated. We need to go out and discover any adjacent routers +// and build the Link State Advertisements that reflect them and their associated +// networks. // uint32_t GlobalRouter::DiscoverLSAs (void) @@ -501,73 +504,38 @@ GlobalRouter::DiscoverLSAs (void) NS_LOG_LOGIC ("For node " << node->GetId () ); ClearLSAs (); -// -// While building the router-LSA, keep a list of those NetDevices for -// which I am the designated router and need to later build a NetworkLSA -// - std::list > listOfDRInterfaces; -// -// We're aggregated to a node. We need to ask the node for a pointer to its -// Ipv4 interface. This is where the information regarding the attached -// interfaces lives. If we're a router, we had better have an Ipv4 interface. -// + // + // While building the Router-LSA, keep a list of those NetDevices for + // which the current node is the designated router and we will later build + // a NetworkLSA for. + // + NetDeviceContainer c; + + // + // We're aggregated to a node. We need to ask the node for a pointer to its + // Ipv4 interface. This is where the information regarding the attached + // interfaces lives. If we're a router, we had better have an Ipv4 interface. + // Ptr ipv4Local = node->GetObject (); NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for interface failed"); -// -// Each node is a router and so originates a Router-LSA -// + + // + // Every router node originates a Router-LSA + // GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; pLSA->SetLSType (GlobalRoutingLSA::RouterLSA); pLSA->SetLinkStateId (m_routerId); pLSA->SetAdvertisingRouter (m_routerId); pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); -// -// Ask the node for the number of net devices attached. This isn't necessarily -// equal to the number of links to adjacent nodes (other routers) as the number -// of devices may include those for stub networks (e.g., ethernets, etc.) and -// bridge devices also take up an "extra" net device. -// + // + // Ask the node for the number of net devices attached. This isn't necessarily + // equal to the number of links to adjacent nodes (other routers) as the number + // of devices may include those for stub networks (e.g., ethernets, etc.) and + // bridge devices also take up an "extra" net device. + // uint32_t numDevices = node->GetNDevices(); - NS_LOG_LOGIC ("*************************"); - NS_LOG_LOGIC ("numDevices = " << numDevices); - -// -// There are two broad classes of devices: bridges in combination with the -// devices they bridge and everything else. We need to first discover all of -// the "everything else" class of devices. -// -// To do this, we wander through all of the devices on the node looking for -// bridge net devices. We then add any net devices associated with each bridge -// to a list of bridged devices. These devices will be treated as a special -// case later. -// - std::vector > bridgedDevices; - - for (uint32_t i = 0; i < numDevices; ++i) - { - Ptr nd = node->GetDevice(i); - - if (nd->IsBridge ()) - { - NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge"); - // - // XXX There is only one kind of bridge device so far. We agreed to - // assume that it is Gustavo's learning bridge until there is a need - // to deal with another. At that time, we'll have to break out a - // bridge interface. - // - Ptr bnd = nd->GetObject (); - NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); - - for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) - { - NS_LOG_LOGIC ("**** Net device " << bnd << "is a bridged device"); - bridgedDevices.push_back (bnd->GetBridgePort (j)); - } - } - } // // Iterate through the devices on the node and walk the channel to see what's @@ -576,27 +544,10 @@ GlobalRouter::DiscoverLSAs (void) for (uint32_t i = 0; i < numDevices; ++i) { Ptr ndLocal = node->GetDevice(i); - // - // If the device in question is on our list of bridged devices, then we - // just ignore it. It will be dealt with correctly when we probe the - // bridge device it belongs to. It is the case that the bridge code - // assumes that bridged devices must not have IP interfaces, and so it - // may actually sufficient to perform the test for IP interface below, - // but that struck me as too indirect a condition. - // - for (uint32_t j = 0; j < bridgedDevices.size (); ++j) - { - if (ndLocal == bridgedDevices[j]) - { - NS_LOG_LOGIC ("**** Skipping Bridged Device"); - - continue; - } - } // // Check to see if the net device we just got has a corresponding IP - // interface (could be a pure L2 NetDevice that is not a bridge). + // interface (could be a pure L2 NetDevice). // bool isIp = false; for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i ) @@ -614,270 +565,323 @@ GlobalRouter::DiscoverLSAs (void) continue; } -// -// We have a net device that we need to check out. If it suports broadcast and -// is not a point-point link, then it will be either a stub network or a transit -// network depending on the number of routers. -// + // + // We have a net device that we need to check out. If it suports + // broadcast and is not a point-point link, then it will be either a stub + // network or a transit network depending on the number of routers on + // the segment. We add the appropriate link record to the LSA. + // + // If the device is a point to point link, we treat it separately. In + // that case, there always two link records added. + // if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () ) { NS_LOG_LOGIC ("**** Broadcast link"); - GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; -// -// We need to determine whether we are on a transit or stub network -// If we find at least one more router on this channel, we are a transit -// network. If we're the only router, we're on a stub. -// -// Now, we have to find the Ipv4 interface whose netdevice is the one we -// just found. This is still the IP on the local side of the channel. -// - uint32_t ifIndexLocal; - bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); - - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); - NS_LOG_LOGIC ("Working with local address " << addrLocal); - uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); -// -// Check to see if the net device is connected to a channel/network that has -// another router on it. If there is no other router on the link (but us) then -// this is a stub network. If we find another router, then what we have here -// is a transit network. -// - if (AnotherRouterOnLink (ndLocal) == false) - { - // - // This is a net device connected to a stub network - // - NS_LOG_LOGIC("**** Router-LSA Stub Network"); - plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); - // - // According to OSPF, the Link ID is the IP network number of - // the attached network. - // - plr->SetLinkId (addrLocal.CombineMask(maskLocal)); - // - // and the Link Data is the network mask; converted to Ipv4Address - // - Ipv4Address maskLocalAddr; - maskLocalAddr.Set(maskLocal.Get ()); - plr->SetLinkData (maskLocalAddr); - plr->SetMetric (metricLocal); - pLSA->AddLinkRecord(plr); - plr = 0; - continue; - } - else - { - // - // We have multiple routers on a broadcast interface, so this is - // a transit network. - // - NS_LOG_LOGIC ("**** Router-LSA Transit Network"); - plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); - // - // By definition, the router with the lowest IP address is the - // designated router for the network. OSPF says that the Link ID - // gets the IP interface address of the designated router in this - // case. - // - Ipv4Address desigRtr = FindDesignatedRouterForLink (ndLocal); - if (desigRtr == addrLocal) - { - listOfDRInterfaces.push_back (ndLocal); - NS_LOG_LOGIC (node->GetId () << " is a DR"); - } - plr->SetLinkId (desigRtr); - // - // OSPF says that the Link Data is this router's own IP address. - // - plr->SetLinkData (addrLocal); - plr->SetMetric (metricLocal); - pLSA->AddLinkRecord (plr); - plr = 0; - continue; - } + ProcessBroadcastLink (ndLocal, pLSA, c); } else if (ndLocal->IsPointToPoint () ) { - NS_LOG_LOGIC ("**** Router-LSA Point-to-point device"); -// -// Now, we have to find the Ipv4 interface whose netdevice is the one we -// just found. This is still 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 it's not -// exported so we had to whip up an equivalent. -// - uint32_t ifIndexLocal; - bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); -// -// 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_LOG_LOGIC ("Working with local address " << addrLocal); - uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); -// -// Now, we're going to walk over to the remote net device on the other end of -// the point-to-point channel we now know we have. This is where our adjacent -// router (to use OSPF lingo) is running. -// - Ptr ch = ndLocal->GetChannel(); - if (ch == NULL) - { - continue; - } -// -// Get the net device on the other side of the point-to-point channel. -// - Ptr ndRemote = GetAdjacent(ndLocal, 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. Note a -// requirement that nodes on either side of a point-to-point link must have -// internet stacks. -// - Ptr nodeRemote = ndRemote->GetNode(); - Ptr ipv4Remote = nodeRemote->GetObject (); - NS_ABORT_MSG_UNLESS (ipv4Remote, - "GlobalRouter::DiscoverLSAs (): GetObject for remote failed"); -// -// Per the OSPF spec, we're going to need the remote router ID, so we might as -// well get it now. -// -// While we're at it, further note the requirement that nodes on either side of -// a point-to-point link must participateg in global routing and therefore have -// a GlobalRouter interface aggregated. -// - Ptr srRemote = nodeRemote->GetObject (); - NS_ABORT_MSG_UNLESS(srRemote, - "GlobalRouter::DiscoverLSAs(): GetObject for remote failed"); - - Ipv4Address rtrIdRemote = srRemote->GetRouterId(); - NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote); -// -// 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. We have yet another -// assumption that point to point devices are incompatible with bridges and that -// the remote device must have an associated ip interface. -// - uint32_t ifIndexRemote; - rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with remote device"); -// -// 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); - NS_LOG_LOGIC ("Working with remote address " << addrRemote); -// -// Now we can fill out the link records for this link. There are always two -// link records; the first is a point-to-point record describing the link and -// the second is a stub network record with the network number. -// - GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; - plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint); - plr->SetLinkId (rtrIdRemote); - plr->SetLinkData (addrLocal); - plr->SetMetric (metricLocal); - pLSA->AddLinkRecord (plr); - plr = 0; - - plr = new GlobalRoutingLinkRecord; - plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); - plr->SetLinkId (addrRemote); - plr->SetLinkData (Ipv4Address(maskRemote.Get())); // Frown - plr->SetMetric (metricLocal); - pLSA->AddLinkRecord (plr); - plr = 0; + NS_LOG_LOGIC ("**** Point=to-point link"); + ProcessPointToPointLink (ndLocal, pLSA); } else { NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type"); } } -// -// The LSA goes on a list of LSAs in case we want to begin exporting other -// kinds of advertisements (than Router LSAs). -// + + NS_LOG_LOGIC ("========== LSA for node " << node->GetId () << " =========="); + NS_LOG_LOGIC (*pLSA); m_LSAs.push_back (pLSA); - NS_LOG_LOGIC ("========== Link State Advertisement for node " << node->GetId () << " =========="); - NS_LOG_LOGIC (*pLSA); + pLSA = 0; -// -// Now, determine whether we need to build a NetworkLSA. This is the case if -// we found at least one designated router. -// - if (listOfDRInterfaces.size () > 0) + // + // Now, determine whether we need to build a NetworkLSA. This is the case if + // we found at least one designated router. + // + uint32_t nDesignatedRouters = c.GetN (); + if (nDesignatedRouters > 0) { - NS_LOG_LOGIC ("Build Network LSA"); - for (std::list >::iterator i = listOfDRInterfaces.begin (); - i != listOfDRInterfaces.end (); i++) - { -// -// Build one NetworkLSA for each net device talking to a netwok that we are the -// designated router for. -// - Ptr ndLocal = *i; - - uint32_t ifIndexLocal; - bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device"); - - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); - - GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; - pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA); - pLSA->SetLinkStateId (addrLocal); - pLSA->SetAdvertisingRouter (m_routerId); - pLSA->SetNetworkLSANetworkMask (maskLocal); - pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); -// -// Build a list of AttachedRouters by walking the devices in the channel -// and, if we find a node with a GlobalRouter interface and an IPv4 -// interface associated with that device, we call it an attached router. -// - Ptr ch = ndLocal->GetChannel(); - uint32_t nDevices = ch->GetNDevices(); - NS_ASSERT (nDevices); - for (uint32_t i = 0; i < nDevices; i++) - { - Ptr tempNd = ch->GetDevice (i); - NS_ASSERT (tempNd); - Ptr tempNode = tempNd->GetNode (); -// -// Does the node in question have a GlobalRouter interface? If not it can -// hardly be considered an attached router. -// - Ptr rtr = tempNode->GetObject (); - if (rtr == 0) - { - continue; - } - -// -// Does the attached node have an ipv4 interface for the device we're probing? -// If not, it can't play router. -// - uint32_t tempIfIndex; - if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex)) - { - Ptr tempIpv4 = tempNode->GetObject (); - NS_ASSERT (tempIpv4); - Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); - pLSA->AddAttachedRouter (tempAddr); - } - } - m_LSAs.push_back (pLSA); - NS_LOG_LOGIC (*pLSA); - } + NS_LOG_LOGIC ("Build Network LSAs"); + BuildNetworkLSAs (c); } return m_LSAs.size (); +} + + void +GlobalRouter::ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c) +{ + NS_LOG_FUNCTION (nd << pLSA << &c); + + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBroadcastLink(): Can't alloc link record"); + + // + // We have some preliminaries to do to get enough information to proceed. + // This information we need comes from the internet stack, so notice that + // there is an implied assumption that global routing is only going to + // work with devices attached to the internet stack (have an ipv4 interface + // associated to them. + // + Ptr node = nd->GetNode (); + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBroadcastLink(): No interface index associated with device"); + + Ptr ipv4Local = node->GetObject (); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBroadcastLink (): GetObject for interface failed"); + + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); + NS_LOG_LOGIC ("Working with local address " << addrLocal); + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); + + // + // Check to see if the net device is connected to a channel/network that has + // another router on it. If there is no other router on the link (but us) then + // this is a stub network. If we find another router, then what we have here + // is a transit network. + // + if (AnotherRouterOnLink (nd) == false) + { + // + // This is a net device connected to a stub network + // + NS_LOG_LOGIC("**** Router-LSA Stub Network"); + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); + + // + // According to OSPF, the Link ID is the IP network number of + // the attached network. + // + plr->SetLinkId (addrLocal.CombineMask(maskLocal)); + + // + // and the Link Data is the network mask; converted to Ipv4Address + // + Ipv4Address maskLocalAddr; + maskLocalAddr.Set(maskLocal.Get ()); + plr->SetLinkData (maskLocalAddr); + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord(plr); + plr = 0; + } + else + { + // + // We have multiple routers on a broadcast interface, so this is + // a transit network. + // + NS_LOG_LOGIC ("**** Router-LSA Transit Network"); + plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); + + // + // By definition, the router with the lowest IP address is the + // designated router for the network. OSPF says that the Link ID + // gets the IP interface address of the designated router in this + // case. + // + Ipv4Address desigRtr = FindDesignatedRouterForLink (nd); + if (desigRtr == addrLocal) + { + c.Add (nd); + NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router"); + } + plr->SetLinkId (desigRtr); + + // + // OSPF says that the Link Data is this router's own IP address. + // + plr->SetLinkData (addrLocal); + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord (plr); + plr = 0; + } +} + + void +GlobalRouter::ProcessPointToPointLink (Ptr ndLocal, GlobalRoutingLSA *pLSA) +{ + NS_LOG_FUNCTION (ndLocal << pLSA); + + // + // We have some preliminaries to do to get enough information to proceed. + // This information we need comes from the internet stack, so notice that + // there is an implied assumption that global routing is only going to + // work with devices attached to the internet stack (have an ipv4 interface + // associated to them. + // + Ptr nodeLocal = ndLocal->GetNode (); + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(nodeLocal, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device"); + + Ptr ipv4Local = nodeLocal->GetObject (); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for interface failed"); + + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); + NS_LOG_LOGIC ("Working with local address " << addrLocal); + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); + + // + // Now, we're going to walk over 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 = ndLocal->GetChannel(); + + // + // Get the net device on the other side of the point-to-point channel. + // + Ptr ndRemote = GetAdjacent(ndLocal, 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. Note a + // requirement that nodes on either side of a point-to-point link must have + // internet stacks; and an assumption that point-to-point links are incompatible + // with bridging. + // + Ptr nodeRemote = ndRemote->GetNode(); + Ptr ipv4Remote = nodeRemote->GetObject (); + NS_ABORT_MSG_UNLESS (ipv4Remote, + "GlobalRouter::ProcessPointToPointLink(): GetObject for remote failed"); + + // + // Further note the requirement that nodes on either side of a point-to-point + // link must participate in global routing and therefore have a GlobalRouter + // interface aggregated. + // + Ptr rtrRemote = nodeRemote->GetObject (); + NS_ABORT_MSG_UNLESS(rtrRemote, + "GlobalRouter::ProcessPointToPointLinks(): GetObject for remote failed"); + + // + // We're going to need the remote router ID, so we might as well get it now. + // + Ipv4Address rtrIdRemote = rtrRemote->GetRouterId(); + NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote); + + // + // 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. + // + uint32_t ifIndexRemote; + rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device"); + + // + // 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); + NS_LOG_LOGIC ("Working with remote address " << addrRemote); + + // + // Now we can fill out the link records for this link. There are always two + // link records; the first is a point-to-point record describing the link and + // the second is a stub network record with the network number. + // + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record"); + plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint); + plr->SetLinkId (rtrIdRemote); + plr->SetLinkData (addrLocal); + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord (plr); + plr = 0; + + plr = new GlobalRoutingLinkRecord; + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record"); + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); + plr->SetLinkId (addrRemote); + plr->SetLinkData (Ipv4Address(maskRemote.Get())); // Frown + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord (plr); + plr = 0; +} + + void +GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c) +{ + NS_LOG_FUNCTION (&c); + + uint32_t nDesignatedRouters = c.GetN (); + + for (uint32_t i = 0; i < nDesignatedRouters; ++i) + { + // + // Build one NetworkLSA for each net device talking to a network that we are the + // designated router for. These devices are in the provided container. + // + Ptr ndLocal = c.Get (i); + Ptr node = ndLocal->GetNode (); + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device"); + + Ptr ipv4Local = node->GetObject (); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for interface failed"); + + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); + + GlobalRoutingLSA *pLSA = new GlobalRoutingLSA; + NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record"); + + pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA); + pLSA->SetLinkStateId (addrLocal); + pLSA->SetAdvertisingRouter (m_routerId); + pLSA->SetNetworkLSANetworkMask (maskLocal); + pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED); + + // + // Build a list of AttachedRouters by walking the devices in the channel + // and, if we find a node with a GlobalRouter interface and an IPv4 + // interface associated with that device, we call it an attached router. + // + Ptr ch = ndLocal->GetChannel(); + uint32_t nDevices = ch->GetNDevices(); + NS_ASSERT (nDevices); + + for (uint32_t i = 0; i < nDevices; i++) + { + Ptr tempNd = ch->GetDevice (i); + NS_ASSERT (tempNd); + Ptr tempNode = tempNd->GetNode (); + + // + // Does the node in question have a GlobalRouter interface? If not it can + // hardly be considered an attached router. + // + Ptr rtr = tempNode->GetObject (); + if (rtr == 0) + { + continue; + } + + // + // Does the attached node have an ipv4 interface for the device we're probing? + // If not, it can't play router. + // + uint32_t tempIfIndex; + if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex)) + { + Ptr tempIpv4 = tempNode->GetObject (); + NS_ASSERT (tempIpv4); + Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex); + pLSA->AddAttachedRouter (tempAddr); + } + } + m_LSAs.push_back (pLSA); + pLSA = 0; + } } // @@ -1026,11 +1030,10 @@ GlobalRouter::GetLSA (uint32_t n, Global // other end. This only makes sense with a point-to-point channel. // Ptr -GlobalRouter::GetAdjacent(Ptr nd, Ptr ch) const +GlobalRouter::GetAdjacent (Ptr nd, Ptr ch) const { NS_LOG_FUNCTION_NOARGS (); - NS_ASSERT_MSG(ch->GetNDevices() == 2, - "GlobalRouter::GetAdjacent (): Channel with other than two devices"); + NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices"); // // This is a point to point channel with two endpoints. Get both of them. // @@ -1065,7 +1068,7 @@ GlobalRouter::GetAdjacent(Ptr // is bridged, there will not be an interface associated directly with the device. // bool -GlobalRouter::FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const +GlobalRouter::FindIfIndexForDevice (Ptr node, Ptr nd, uint32_t &index) const { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd ); @@ -1087,7 +1090,43 @@ GlobalRouter::FindIfIndexForDevice(Ptr nd) const +{ + Ptr node = nd->GetNode (); + uint32_t nDevices = node->GetNDevices(); + + // + // There is no bit on a net device that says it is being bridged, so we have + // to look for bridges on the node to which the device is attached. If we + // find a bridge, we need to look through its bridge ports (the devices it + // bridges) to see if we find the device in question. + // + for (uint32_t i = 0; i < nDevices; ++i) + { + Ptr nd = node->GetDevice(i); + + if (nd->IsBridge ()) + { + Ptr bnd = nd->GetObject (); + NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); + + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) + { + if (bnd->GetBridgePort (j) == nd) + { + return true; + } + } + } + } return false; } diff -r 972310213d07 -r 206f627bd5af src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Wed Nov 19 18:44:20 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Wed Nov 19 21:21:14 2008 -0800 @@ -29,6 +29,7 @@ #include "ns3/node.h" #include "ns3/channel.h" #include "ns3/ipv4-address.h" +#include "ns3/net-device-container.h" #include "ns3/global-route-manager.h" namespace ns3 { @@ -642,6 +643,11 @@ private: bool FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const; Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal) const; bool AnotherRouterOnLink (Ptr nd) const; + void ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + void ProcessPointToPointLink (Ptr ndLocal, GlobalRoutingLSA *pLSA); + void BuildNetworkLSAs (NetDeviceContainer c); + bool IsNetDeviceBridged (Ptr nd) const; + typedef std::list ListOfLSAs_t; ListOfLSAs_t m_LSAs; changeset: 3875:49b432aefbd0 user: Craig Dowell date: Wed Nov 19 22:16:43 2008 -0800 summary: deal with bridged stub/transit networks on routers diff -r 206f627bd5af -r 49b432aefbd0 src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Wed Nov 19 21:21:14 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Wed Nov 19 22:16:43 2008 -0800 @@ -614,8 +614,23 @@ GlobalRouter::ProcessBroadcastLink (Ptr< { NS_LOG_FUNCTION (nd << pLSA << &c); + if (nd->IsBridge ()) + { + ProcessBridgedBroadcastLink (nd, pLSA, c); + } + else + { + ProcessSingleBroadcastLink (nd, pLSA, c); + } +} + + void +GlobalRouter::ProcessSingleBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c) +{ + NS_LOG_FUNCTION (nd << pLSA << &c); + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; - NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBroadcastLink(): Can't alloc link record"); + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record"); // // We have some preliminaries to do to get enough information to proceed. @@ -628,10 +643,10 @@ GlobalRouter::ProcessBroadcastLink (Ptr< uint32_t ifIndexLocal; bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal); - NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBroadcastLink(): No interface index associated with device"); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device"); Ptr ipv4Local = node->GetObject (); - NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBroadcastLink (): GetObject for interface failed"); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for interface failed"); Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); @@ -684,6 +699,147 @@ GlobalRouter::ProcessBroadcastLink (Ptr< // case. // Ipv4Address desigRtr = FindDesignatedRouterForLink (nd); + if (desigRtr == addrLocal) + { + c.Add (nd); + NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router"); + } + plr->SetLinkId (desigRtr); + + // + // OSPF says that the Link Data is this router's own IP address. + // + plr->SetLinkData (addrLocal); + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord (plr); + plr = 0; + } +} + + void +GlobalRouter::ProcessBridgedBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c) +{ + NS_LOG_FUNCTION (nd << pLSA << &c); + + NS_ASSERT_MSG (nd->IsBridge (), "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device"); + + Ptr bnd = nd->GetObject (); + NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); + + // + // We need to handle a bridge on the router. This means that we have been + // given a net device that is a BridgeNetDevice. It has an associated Ipv4 + // interface index and address. Some number of other net devices live "under" + // the bridge device as so-called bridge ports. In a nutshell, what we have + // to do is to repeat what is done for a single broadcast link on all of + // those net devices living under the bridge (trolls?) + // + bool areTransitNetwork = false; + Ipv4Address desigRtr ("255.255.255.255"); + + for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i) + { + Ptr ndTemp = bnd->GetBridgePort (i); + GlobalRoutingLSA *pLsaTest = new GlobalRoutingLSA; + NetDeviceContainer cTest; + ProcessSingleBroadcastLink (ndTemp, pLsaTest, cTest); + + // + // The GlobalRoutingLSA pLsaTest will now have a link record attached to + // it indicating what was found. If another router is found on any one + // of the bridged networks, we need to treat the whole bridge as a transit + // network. + // + // If the link type is a transit network, then we have got to do some work + // to figure out what to do about the other routers on the bridge. + // + if (pLsaTest->GetLinkRecord (0)->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork) + { + areTransitNetwork = true; + + // + // If we're going to be a transit network, then we have got to elect + // a designated router for the whole bridge. This means finding the + // router with the lowest IP address on the whole bridge. We ask + // for the lowest address on each segment and pick the lowest of them + // all. + // + Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp); + if (desigRtrTemp < desigRtr) + { + desigRtr = desigRtrTemp; + } + } + } + + // + // That's all the information we need to put it all together, just like we did + // in the case of a single broadcast link. + // + + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord; + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record"); + + // + // We have some preliminaries to do to get enough information to proceed. + // This information we need comes from the internet stack, so notice that + // there is an implied assumption that global routing is only going to + // work with devices attached to the internet stack (have an ipv4 interface + // associated to them. + // + Ptr node = nd->GetNode (); + + uint32_t ifIndexLocal; + bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal); + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device"); + + Ptr ipv4Local = node->GetObject (); + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for interface failed"); + + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal); + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal); + NS_LOG_LOGIC ("Working with local address " << addrLocal); + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal); + + if (areTransitNetwork == false) + { + // + // This is a net device connected to a bridge of stub networks + // + NS_LOG_LOGIC("**** Router-LSA Stub Network"); + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); + + // + // According to OSPF, the Link ID is the IP network number of + // the attached network. + // + plr->SetLinkId (addrLocal.CombineMask(maskLocal)); + + // + // and the Link Data is the network mask; converted to Ipv4Address + // + Ipv4Address maskLocalAddr; + maskLocalAddr.Set(maskLocal.Get ()); + plr->SetLinkData (maskLocalAddr); + plr->SetMetric (metricLocal); + pLSA->AddLinkRecord(plr); + plr = 0; + } + else + { + // + // We have multiple routers on a bridged broadcast interface, so this is + // a transit network. + // + NS_LOG_LOGIC ("**** Router-LSA Transit Network"); + plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); + + // + // By definition, the router with the lowest IP address is the + // designated router for the network. OSPF says that the Link ID + // gets the IP interface address of the designated router in this + // case. + // if (desigRtr == addrLocal) { c.Add (nd); diff -r 206f627bd5af -r 49b432aefbd0 src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Wed Nov 19 21:21:14 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Wed Nov 19 22:16:43 2008 -0800 @@ -644,6 +644,9 @@ private: Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal) const; bool AnotherRouterOnLink (Ptr nd) const; void ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + void ProcessSingleBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + void ProcessBridgedBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); + void ProcessPointToPointLink (Ptr ndLocal, GlobalRoutingLSA *pLSA); void BuildNetworkLSAs (NetDeviceContainer c); bool IsNetDeviceBridged (Ptr nd) const; changeset: 3876:476c3bed16c0 user: Craig Dowell date: Wed Nov 19 23:38:01 2008 -0800 summary: teach global routing about bridges diff -r 49b432aefbd0 -r 476c3bed16c0 src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Wed Nov 19 22:16:43 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Wed Nov 19 23:38:01 2008 -0800 @@ -547,7 +547,8 @@ GlobalRouter::DiscoverLSAs (void) // // Check to see if the net device we just got has a corresponding IP - // interface (could be a pure L2 NetDevice). + // interface (could be a pure L2 NetDevice) -- for example a net device + // associated with a bridge. // bool isIp = false; for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i ) @@ -659,7 +660,7 @@ GlobalRouter::ProcessSingleBroadcastLink // this is a stub network. If we find another router, then what we have here // is a transit network. // - if (AnotherRouterOnLink (nd) == false) + if (AnotherRouterOnLink (nd, true) == false) { // // This is a net device connected to a stub network @@ -740,20 +741,13 @@ GlobalRouter::ProcessBridgedBroadcastLin for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i) { Ptr ndTemp = bnd->GetBridgePort (i); - GlobalRoutingLSA *pLsaTest = new GlobalRoutingLSA; - NetDeviceContainer cTest; - ProcessSingleBroadcastLink (ndTemp, pLsaTest, cTest); // - // The GlobalRoutingLSA pLsaTest will now have a link record attached to - // it indicating what was found. If another router is found on any one - // of the bridged networks, we need to treat the whole bridge as a transit - // network. + // We have to decide if we are a transit network. This is characterized + // by the presence of another router on the network segment. If we find + // another router on any of our bridged links, we are a transit network. // - // If the link type is a transit network, then we have got to do some work - // to figure out what to do about the other routers on the bridge. - // - if (pLsaTest->GetLinkRecord (0)->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork) + if (AnotherRouterOnLink (ndTemp, true)) { areTransitNetwork = true; @@ -1112,36 +1106,83 @@ GlobalRouter::FindDesignatedRouterForLin // // Given a node and an attached net device, take a look off in the channel to // which the net device is attached and look for a node on the other side -// that has a GlobalRouter interface aggregated. +// that has a GlobalRouter interface aggregated. Life gets more complicated +// when there is a bridged net device on the other side. // bool -GlobalRouter::AnotherRouterOnLink (Ptr nd) const +GlobalRouter::AnotherRouterOnLink (Ptr nd, bool allowRecursion) const { - NS_LOG_FUNCTION_NOARGS (); + NS_LOG_FUNCTION (nd << allowRecursion); Ptr ch = nd->GetChannel(); uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); + // + // Look through all of the devices on the channel to which the net device + // in questin is attached. + // for (uint32_t i = 0; i < nDevices; i++) { - Ptr ndTemp = ch->GetDevice (i); - NS_ASSERT (ndTemp); + NS_LOG_LOGIC ("**** Examine device " << i << "on node " << nd->GetNode ()->GetId ()); - if (ndTemp == nd) + Ptr ndOther = ch->GetDevice (i); + NS_ASSERT (ndOther); + + // + // Ignore the net device itself. + // + if (ndOther == nd) { + NS_LOG_LOGIC ("**** Self"); continue; } - Ptr nodeTemp = ndTemp->GetNode (); + // + // For all other net devices, we need to check and see if a router + // is present. If the net device on the other side is a bridged + // device, we need to consider all of the other devices on the + // bridge. + // + Ptr bnd = NetDeviceIsBridged (ndOther); + if (bnd) + { + NS_LOG_LOGIC ("**** Device is bridged"); + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) + { + NS_LOG_LOGIC ("**** Examining bridge port " << j); + Ptr ndBridged = bnd->GetBridgePort (j); + if (ndBridged == ndOther) + { + NS_LOG_LOGIC ("**** Self"); + continue; + } + if (allowRecursion) + { + NS_LOG_LOGIC ("**** Recursing"); + if (AnotherRouterOnLink (ndBridged, false)) + { + NS_LOG_LOGIC ("**** Return true"); + return true; + } + } + } + NS_LOG_LOGIC ("**** Return false"); + return false; + } + + NS_LOG_LOGIC ("**** Device is not bridged"); + Ptr nodeTemp = ndOther->GetNode (); NS_ASSERT (nodeTemp); Ptr rtr = nodeTemp->GetObject (); if (rtr) { + NS_LOG_LOGIC ("**** Return true"); return true; } } + NS_LOG_LOGIC ("**** Return false"); return false; } @@ -1253,9 +1294,11 @@ GlobalRouter::FindIfIndexForDevice (Ptr< // // Decide whether or not a given net device is being bridged by a BridgeNetDevice. // - bool -GlobalRouter::IsNetDeviceBridged (Ptr nd) const + Ptr +GlobalRouter::NetDeviceIsBridged (Ptr nd) const { + NS_LOG_FUNCTION (nd); + Ptr node = nd->GetNode (); uint32_t nDevices = node->GetNDevices(); @@ -1267,23 +1310,28 @@ GlobalRouter::IsNetDeviceBridged (Ptr nd = node->GetDevice(i); + Ptr ndTest = node->GetDevice(i); + NS_LOG_LOGIC ("**** Examine device " << i << " " << ndTest); - if (nd->IsBridge ()) + if (ndTest->IsBridge ()) { - Ptr bnd = nd->GetObject (); + NS_LOG_LOGIC ("**** device " << i << " is a bridge net device"); + Ptr bnd = ndTest->GetObject (); NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) { + NS_LOG_LOGIC ("**** Examine bridge port " << j << " " << bnd->GetBridgePort (j)); if (bnd->GetBridgePort (j) == nd) { - return true; + NS_LOG_LOGIC ("**** Net device " << nd << " is bridged by " << bnd); + return bnd; } } } } - return false; + NS_LOG_LOGIC ("**** Net device " << nd << " is not bridged"); + return 0; } } // namespace ns3 diff -r 49b432aefbd0 -r 476c3bed16c0 src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Wed Nov 19 22:16:43 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Wed Nov 19 23:38:01 2008 -0800 @@ -30,6 +30,7 @@ #include "ns3/channel.h" #include "ns3/ipv4-address.h" #include "ns3/net-device-container.h" +#include "ns3/bridge-net-device.h" #include "ns3/global-route-manager.h" namespace ns3 { @@ -642,14 +643,14 @@ private: Ptr GetAdjacent(Ptr nd, Ptr ch) const; bool FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const; Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal) const; - bool AnotherRouterOnLink (Ptr nd) const; + bool AnotherRouterOnLink (Ptr nd, bool allowRecursion) const; void ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); void ProcessSingleBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); void ProcessBridgedBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); void ProcessPointToPointLink (Ptr ndLocal, GlobalRoutingLSA *pLSA); void BuildNetworkLSAs (NetDeviceContainer c); - bool IsNetDeviceBridged (Ptr nd) const; + Ptr NetDeviceIsBridged (Ptr nd) const; typedef std::list ListOfLSAs_t; changeset: 3877:eef10dbce686 user: Craig Dowell date: Thu Nov 20 16:48:21 2008 -0800 summary: fix bug 114 and bug 66 diff -r 476c3bed16c0 -r eef10dbce686 examples/csma-bridge-one-hop.cc --- a/examples/csma-bridge-one-hop.cc Wed Nov 19 23:38:01 2008 -0800 +++ b/examples/csma-bridge-one-hop.cc Thu Nov 20 16:48:21 2008 -0800 @@ -41,19 +41,19 @@ // Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes // with three net devices: // -// n0 n1 -// | | -// ----------- -// | bridge1 | <- n5 +// n0 n1 (n0 = 10.1.1.2) +// | | (n1 = 10.1.1.3) Note odd addressing +// ----------- (n2 = 10.1.1.1) +// | bridge1 | <- n5 // ----------- // | // router <- n2 // | // ----------- // | bridge2 | <- n6 -// ----------- -// | | -// n3 n4 +// ----------- (n2 = 10.1.2.1) +// | | (n3 = 10.1.2.2) +// n3 n4 (n4 = 10.1.2.3) // // So, this example shows two broadcast domains, each interconnected by a bridge // with a router node (n2) interconnecting the layer-2 broadcast domains @@ -61,7 +61,7 @@ // It is meant to mirror somewhat the csma-bridge example but adds another // bridged link separated by a router. // -// - CBR/UDP flows from n0 to n1 and from n3 to n0 +// - CBR/UDP flows from n0 (10.1.1.2) to n1 (10.1.1.3) and from n3 (10.1.2.2) to n0 (10.1.1.3) // - DropTail queues // - Global static routing // - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr" @@ -201,7 +201,9 @@ main (int argc, char *argv[]) // Create an optional packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); - sink.Install (n1); + ApplicationContainer sink1 = sink.Install (n1); + sink1.Start (Seconds (1.0)); + sink1.Stop (Seconds (10.0)); // // Create a similar flow from n3 to n0, starting at time 1.1 seconds @@ -209,11 +211,12 @@ main (int argc, char *argv[]) onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); ApplicationContainer app2 = onoff.Install (n3); - - sink.Install (n0); - app2.Start (Seconds (1.1)); app2.Stop (Seconds (10.0)); + + ApplicationContainer sink2 = sink.Install (n0); + sink2.Start (Seconds (1.1)); + sink2.Stop (Seconds (10.0)); // // Configure tracing of all enqueue, dequeue, and NetDevice receive events. diff -r 476c3bed16c0 -r eef10dbce686 src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Wed Nov 19 23:38:01 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Thu Nov 20 16:48:21 2008 -0800 @@ -383,9 +383,25 @@ GlobalRoutingLSA::SetStatus (GlobalRouti void GlobalRoutingLSA::Print (std::ostream &os) const { - os << "m_lsType = " << m_lsType << std::endl << - "m_linkStateId = " << m_linkStateId << std::endl << - "m_advertisingRtr = " << m_advertisingRtr << std::endl; + os << std::endl; + os << "========== Global Routing LSA ==========" << std::endl; + os << "m_lsType = " << m_lsType; + if (m_lsType == GlobalRoutingLSA::RouterLSA) + { + os << " (GlobalRoutingLSA::RouterLSA)"; + } + else if (m_lsType == GlobalRoutingLSA::NetworkLSA) + { + os << " (GlobalRoutingLSA::NetworkLSA)"; + } + else + { + os << "(Unknown LSType)"; + } + os << std::endl; + + os << "m_linkStateId = " << m_linkStateId << " (Router ID)" << std::endl; + os << "m_advertisingRtr = " << m_advertisingRtr << " (Router ID)" << std::endl; if (m_lsType == GlobalRoutingLSA::RouterLSA) { @@ -394,30 +410,49 @@ GlobalRoutingLSA::Print (std::ostream &o i++) { GlobalRoutingLinkRecord *p = *i; - os << "----------" << std::endl; - os << "m_linkId = " << p->GetLinkId () << std::endl; - os << "m_linkData = " << p->GetLinkData () << std::endl; - os << "m_metric = " << p->GetMetric () << std::endl; + + os << "---------- RouterLSA Link Record ----------" << std::endl; + os << "m_linkType = " << p->m_linkType; + if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork) + { + os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl; + os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl; + os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl; + os << "m_metric = " << p->m_metric << std::endl; + } + else if (p->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork) + { + os << "(GlobalRoutingLinkRecord::StubNetwork)" << std::endl; + os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl; + os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl; + os << "m_metric = " << p->m_metric << std::endl; + } + else + { + os << "(Unknown LinkType)" << std::endl; + os << "m_linkId = " << p->m_linkId << std::endl; + os << "m_linkData = " << p->m_linkData << std::endl; + os << "m_metric = " << p->m_metric << std::endl; + } + os << "---------- End RouterLSA Link Record ----------" << std::endl; } } else if (m_lsType == GlobalRoutingLSA::NetworkLSA) { - os << "----------" << std::endl; - os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask - << std::endl; - for ( ListOfAttachedRouters_t::const_iterator i = - m_attachedRouters.begin (); - i != m_attachedRouters.end (); - i++) + os << "---------- NetworkLSA Link Record ----------" << std::endl; + os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl; + for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); i != m_attachedRouters.end (); i++) { Ipv4Address p = *i; os << "attachedRouter = " << p << std::endl; } + os << "---------- End NetworkLSA Link Record ----------" << std::endl; } else { NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType); } + os << "========== End Global Routing LSA ==========" << std::endl; } std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa) @@ -699,7 +734,7 @@ GlobalRouter::ProcessSingleBroadcastLink // gets the IP interface address of the designated router in this // case. // - Ipv4Address desigRtr = FindDesignatedRouterForLink (nd); + Ipv4Address desigRtr = FindDesignatedRouterForLink (nd, true); if (desigRtr == addrLocal) { c.Add (nd); @@ -758,7 +793,7 @@ GlobalRouter::ProcessBridgedBroadcastLin // for the lowest address on each segment and pick the lowest of them // all. // - Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp); + Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp, true); if (desigRtrTemp < desigRtr) { desigRtr = desigRtrTemp; @@ -1041,66 +1076,114 @@ GlobalRouter::BuildNetworkLSAs (NetDevic // connecting to the channel becomes the designated router for the link. // Ipv4Address -GlobalRouter::FindDesignatedRouterForLink (Ptr ndLocal) const +GlobalRouter::FindDesignatedRouterForLink (Ptr ndLocal, bool allowRecursion) const { - NS_LOG_FUNCTION_NOARGS (); + NS_LOG_FUNCTION (ndLocal << allowRecursion); Ptr ch = ndLocal->GetChannel(); uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); - Ipv4Address addr ("255.255.255.255"); + NS_LOG_LOGIC ("**** Looking for designated router off of net device " << ndLocal << " on node " << + ndLocal->GetNode ()->GetId ()); + Ipv4Address desigRtr ("255.255.255.255"); + + // + // Look through all of the devices on the channel to which the net device + // in question is attached. + // for (uint32_t i = 0; i < nDevices; i++) { - Ptr currentNd = ch->GetDevice (i); - NS_ASSERT (currentNd); + Ptr ndOther = ch->GetDevice (i); + NS_ASSERT (ndOther); - Ptr currentNode = currentNd->GetNode (); - NS_ASSERT (currentNode); - // - // We require a designated router to have a GlobalRouter interface and - // an internet stack that includes the Ipv4 interface. - // - Ptr rtr = currentNode->GetObject (); - Ptr ipv4 = currentNode->GetObject (); - if (rtr == 0 || ipv4 == 0 ) - { - continue; - } + Ptr nodeOther = ndOther->GetNode (); + + NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << nodeOther->GetId ()); // - // This node could be a designated router, so we can check and see if - // it has a lower IP address than the one we have. In order to have - // an IP address, it needs to have an interface index. If it doesen't - // have an interface index directly, it's probably part of a bridge - // net device XXX which is not yet handled. + // For all other net devices, we need to check and see if a router + // is present. If the net device on the other side is a bridged + // device, we need to consider all of the other devices on the + // bridge as well (all of the bridge ports. // - uint32_t currentIfIndex; - bool rc = FindIfIndexForDevice(currentNode, currentNd, currentIfIndex); - if (rc == false) + NS_LOG_LOGIC ("**** checking to see if the device is bridged"); + Ptr bnd = NetDeviceIsBridged (ndOther); + if (bnd) { - continue; + NS_LOG_LOGIC ("**** Device is bridged by BridgeNetDevice " << bnd); + + // + // It is possible that the bridge net device is sitting under a + // router, so we have to check for the presence of that router + // before we run off and follow all the links + // + // We require a designated router to have a GlobalRouter interface and + // an internet stack that includes the Ipv4 interface. If it doesn't + // it can't play router. + // + NS_LOG_LOGIC ("**** Checking for router on bridge net device " << bnd); + Ptr rtr = nodeOther->GetObject (); + Ptr ipv4 = nodeOther->GetObject (); + if (rtr && ipv4) + { + uint32_t ifIndexOther; + if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther)) + { + NS_LOG_LOGIC ("**** Found router on bridge net device " << bnd); + Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther); + desigRtr = addrOther < desigRtr ? addrOther : desigRtr; + NS_LOG_LOGIC ("**** designated router now " << desigRtr); + } + } + + NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd); + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) + { + Ptr ndBridged = bnd->GetBridgePort (j); + NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged); + if (ndBridged == ndOther) + { + NS_LOG_LOGIC ("**** That bridge port is me, don't walk backward"); + continue; + } + + if (allowRecursion) + { + NS_LOG_LOGIC ("**** Recursively looking for routers down bridge port " << ndBridged); + Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false); + desigRtr = addrOther < desigRtr ? addrOther : desigRtr; + NS_LOG_LOGIC ("**** designated router now " << desigRtr); + } + } } + else + { + NS_LOG_LOGIC ("**** This device is not bridged"); + Ptr nodeOther = ndOther->GetNode (); + NS_ASSERT (nodeOther); - // - // Okay, get the IP address corresponding to the interface we're - // examining and if it's the lowest so far, remember it. - // - Ipv4Address currentAddr = ipv4->GetAddress(currentIfIndex); - - if (currentAddr < addr) - { - addr = currentAddr; + // + // We require a designated router to have a GlobalRouter interface and + // an internet stack that includes the Ipv4 interface. If it doesn't + // + Ptr rtr = nodeOther->GetObject (); + Ptr ipv4 = nodeOther->GetObject (); + if (rtr && ipv4) + { + uint32_t ifIndexOther; + if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther)) + { + NS_LOG_LOGIC ("**** Found router on net device " << ndOther); + Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther); + desigRtr = addrOther < desigRtr ? addrOther : desigRtr; + NS_LOG_LOGIC ("**** designated router now " << desigRtr); + } + } } } - - // - // Return the lowest IP address found, which will become the designated router - // for the link. - // - NS_ASSERT_MSG (addr.IsBroadcast() == false, "GlobalRouter::FindDesignatedRouterForLink(): Bogus address"); - return addr; + return desigRtr; } // @@ -1118,23 +1201,25 @@ GlobalRouter::AnotherRouterOnLink (PtrGetNDevices(); NS_ASSERT (nDevices); + NS_LOG_LOGIC ("**** Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ()); + // // Look through all of the devices on the channel to which the net device - // in questin is attached. + // in question is attached. // for (uint32_t i = 0; i < nDevices; i++) { - NS_LOG_LOGIC ("**** Examine device " << i << "on node " << nd->GetNode ()->GetId ()); - Ptr ndOther = ch->GetDevice (i); NS_ASSERT (ndOther); + + NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ()); // // Ignore the net device itself. // if (ndOther == nd) { - NS_LOG_LOGIC ("**** Self"); + NS_LOG_LOGIC ("**** Myself, skip"); continue; } @@ -1144,45 +1229,52 @@ GlobalRouter::AnotherRouterOnLink (Ptr bnd = NetDeviceIsBridged (ndOther); if (bnd) { - NS_LOG_LOGIC ("**** Device is bridged"); + NS_LOG_LOGIC ("**** Device is bridged by net device " << bnd); + NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd); for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) { - NS_LOG_LOGIC ("**** Examining bridge port " << j); Ptr ndBridged = bnd->GetBridgePort (j); + NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged); if (ndBridged == ndOther) { - NS_LOG_LOGIC ("**** Self"); + NS_LOG_LOGIC ("**** That bridge port is me, skip"); continue; } + if (allowRecursion) { - NS_LOG_LOGIC ("**** Recursing"); + NS_LOG_LOGIC ("**** Recursively looking for routers on bridge port " << ndBridged); if (AnotherRouterOnLink (ndBridged, false)) { - NS_LOG_LOGIC ("**** Return true"); + NS_LOG_LOGIC ("**** Found routers on bridge port, return true"); return true; } } } - NS_LOG_LOGIC ("**** Return false"); + NS_LOG_LOGIC ("**** No routers on bridged net device, return false"); return false; } - NS_LOG_LOGIC ("**** Device is not bridged"); + NS_LOG_LOGIC ("**** This device is not bridged"); Ptr nodeTemp = ndOther->GetNode (); NS_ASSERT (nodeTemp); Ptr rtr = nodeTemp->GetObject (); if (rtr) { - NS_LOG_LOGIC ("**** Return true"); + NS_LOG_LOGIC ("**** Found GlobalRouter interface, return true"); return true; } + else + { + NS_LOG_LOGIC ("**** No GlobalRouter interface on device, continue search"); + } } - NS_LOG_LOGIC ("**** Return false"); + NS_LOG_LOGIC ("**** No routers found, return false"); return false; } diff -r 476c3bed16c0 -r eef10dbce686 src/routing/global-routing/global-router-interface.h --- a/src/routing/global-routing/global-router-interface.h Wed Nov 19 23:38:01 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.h Thu Nov 20 16:48:21 2008 -0800 @@ -35,6 +35,8 @@ namespace ns3 { +class GlobalRouter; + /** * @brief A single link record for a link state advertisement. * @@ -45,6 +47,7 @@ class GlobalRoutingLinkRecord class GlobalRoutingLinkRecord { public: + friend class GlobalRoutingLSA; /** * @enum LinkType * @brief Enumeration of the possible types of Global Routing Link Records. @@ -642,7 +645,7 @@ private: Ptr GetAdjacent(Ptr nd, Ptr ch) const; bool FindIfIndexForDevice(Ptr node, Ptr nd, uint32_t &index) const; - Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal) const; + Ipv4Address FindDesignatedRouterForLink (Ptr ndLocal, bool allowRecursion) const; bool AnotherRouterOnLink (Ptr nd, bool allowRecursion) const; void ProcessBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); void ProcessSingleBroadcastLink (Ptr nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c); changeset: 3886:e2ada9e99280 parent: 3877:eef10dbce686 parent: 3885:5091e3a14b26 user: Craig Dowell date: Thu Nov 20 19:44:19 2008 -0800 summary: branch merge diff -r eef10dbce686 -r e2ada9e99280 bindings/python/wscript --- a/bindings/python/wscript Thu Nov 20 16:48:21 2008 -0800 +++ b/bindings/python/wscript Thu Nov 20 19:44:19 2008 -0800 @@ -16,14 +16,23 @@ LOCAL_PYBINDGEN_PATH = os.path.join(os.g LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen") #PYBINDGEN_BRANCH = 'lp:pybindgen' PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen' -if os.environ.get('PYTHONPATH', ''): - os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH + os.pathsep + os.environ.get('PYTHONPATH') -else: - os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH ## https://launchpad.net/pybindgen/ REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605) REQUIRED_PYGCCXML_VERSION = (0, 9, 5) + + +def add_to_python_path(path): + if os.environ.get('PYTHONPATH', ''): + os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH') + else: + os.environ['PYTHONPATH'] = path + +def set_pybindgen_pythonpath(env): + if env['WITH_PYBINDGEN']: + add_to_python_path(env['WITH_PYBINDGEN']) + else: + add_to_python_path(LOCAL_PYBINDGEN_PATH) def set_options(opt): @@ -41,6 +50,10 @@ def set_options(opt): "instead of using the system installed version."), action="store_true", default=False, dest='pybindgen_checkout') + opt.add_option('--with-pybindgen', + help=('Path to an existing pybindgen source tree to use.'), + default=None, + dest='with_pybindgen', type="string") def fetch_pybindgen(conf): """ @@ -127,14 +140,22 @@ def configure(conf): conf.env.append_value('CXXFLAGS_PYEXT','-fno-strict-aliasing') ## Check for pybindgen + + no_net = False + if Params.g_options.with_pybindgen: + conf.env['WITH_PYBINDGEN'] = os.path.abspath(Params.g_options.with_pybindgen) + no_net = True + if Params.g_options.pybindgen_checkout: fetch_pybindgen(conf) + + set_pybindgen_pythonpath(conf.env) try: conf.check_python_module('pybindgen') except Configure.ConfigurationError: warning("pybindgen missing") - if not fetch_pybindgen(conf): + if no_net or not fetch_pybindgen(conf): conf.report_optional_feature("python", "Python Bindings", False, "PyBindGen missing and could not be retrieved") return @@ -152,7 +173,7 @@ def configure(conf): warning("pybindgen (found %s) is too old (need %s)" % (pybindgen_version_str, '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION]))) - if not fetch_pybindgen(conf): + if no_net or not fetch_pybindgen(conf): conf.report_optional_feature("python", "Python Bindings", False, "PyBindGen too old and newer version could not be retrieved") return @@ -390,6 +411,8 @@ def build(bld): env = bld.env_of_name('default') curdir = bld.m_curdirnode.abspath() + + set_pybindgen_pythonpath(env) #Object.register('all-ns3-headers', AllNs3Headers) Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE') diff -r eef10dbce686 -r e2ada9e99280 regression.py --- a/regression.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression.py Thu Nov 20 19:44:19 2008 -0800 @@ -42,17 +42,16 @@ def dev_null(): ### Regression testing class Regression(object): - def __init__(self, testdir): + def __init__(self, testdir, reference_traces): self.testdir = testdir + self.reference_traces = reference_traces self.env = Params.g_build.env_of_name('default') - def run_test(self, verbose, generate, refDirName, testName, arguments=[], pyscript=None, refTestName=None): + def run_test(self, verbose, generate, testName, arguments=[], pyscript=None, refTestName=None): """ @param verbose: enable verbose execution @param generate: generate new traces instead of comparing with the reference - - @param refDirName: name of the base directory containing reference traces @param testName: name of the test @@ -70,11 +69,11 @@ class Regression(object): raise TypeError if refTestName is None: - refTestDirName = os.path.join(refDirName, (testName + ".ref")) + refTestDirName = os.path.join(self.reference_traces, (testName + ".ref")) else: - refTestDirName = os.path.join(refDirName, refTestName) + refTestDirName = os.path.join(self.reference_traces, refTestName) - if not os.path.exists(refDirName): + if not os.path.exists(self.reference_traces): print"No reference trace repository" return 1 @@ -90,7 +89,7 @@ class Regression(object): tmpl = tmpl + " " + arg wutils.run_program(testName, tmpl) else: - argv = [self.env['PYTHON'], os.path.join('..', '..', '..', *os.path.split(pyscript))] + arguments + argv = [self.env['PYTHON'], os.path.join(Params.g_cwd_launch, *os.path.split(pyscript))] + arguments before = os.getcwd() os.chdir(refTestDirName) try: @@ -170,16 +169,27 @@ def _find_tests(testdir): tests.sort() return tests -def run_regression(): - """Execute regression tests.""" +def run_regression(reference_traces): + """Execute regression tests. Called with cwd set to the 'regression' subdir of ns-3. + + @param reference_traces: reference traces directory, or None for default. + + """ testdir = "tests" if not os.path.exists(testdir): print "Tests directory does not exist" sys.exit(3) + + dir_name = (wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX) + if reference_traces is None: + reference_traces = dir_name + no_net = False + else: + no_net = True sys.path.append(testdir) - sys.modules['tracediff'] = Regression(testdir) + sys.modules['tracediff'] = Regression(testdir, reference_traces) if Params.g_options.regression_tests: tests = Params.g_options.regression_tests.split(',') @@ -187,36 +197,36 @@ def run_regression(): tests = _find_tests(testdir) print "========== Running Regression Tests ==========" - dir_name = wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX env = Params.g_build.env_of_name('default') - if env['MERCURIAL']: - print "Synchronizing reference traces using Mercurial." - if not os.path.exists(dir_name): - print "Cloning " + REGRESSION_TRACES_REPO + dir_name + " from repo." - argv = ["hg", "clone", REGRESSION_TRACES_REPO + dir_name, dir_name] - rv = subprocess.Popen(argv).wait() + if not no_net: + if env['MERCURIAL']: + print "Synchronizing reference traces using Mercurial." + if not os.path.exists(reference_traces): + print "Cloning " + REGRESSION_TRACES_REPO + dir_name + " from repo." + argv = ["hg", "clone", REGRESSION_TRACES_REPO + dir_name, reference_traces] + rv = subprocess.Popen(argv).wait() + else: + _dir = os.getcwd() + os.chdir(reference_traces) + try: + print "Pulling " + REGRESSION_TRACES_REPO + dir_name + " from repo." + result = subprocess.Popen(["hg", "-q", "pull", REGRESSION_TRACES_REPO + dir_name]).wait() + if not result: + result = subprocess.Popen(["hg", "-q", "update"]).wait() + finally: + os.chdir("..") + if result: + Params.fatal("Synchronizing reference traces using Mercurial failed.") else: - _dir = os.getcwd() - os.chdir(dir_name) - try: - print "Pulling " + REGRESSION_TRACES_REPO + dir_name + " from repo." - result = subprocess.Popen(["hg", "-q", "pull", REGRESSION_TRACES_REPO + dir_name]).wait() - if not result: - result = subprocess.Popen(["hg", "-q", "update"]).wait() - finally: - os.chdir("..") - if result: - Params.fatal("Synchronizing reference traces using Mercurial failed.") - else: - if not os.path.exists(dir_name): - traceball = dir_name + wutils.TRACEBALL_SUFFIX - print "Retrieving " + traceball + " from web." - urllib.urlretrieve(REGRESSION_TRACES_URL + traceball, traceball) - os.system("tar -xjf %s -C .." % (traceball)) - print "Done." + if not os.path.exists(reference_traces): + traceball = dir_name + wutils.TRACEBALL_SUFFIX + print "Retrieving " + traceball + " from web." + urllib.urlretrieve(REGRESSION_TRACES_URL + traceball, traceball) + os.system("tar -xjf %s -C .." % (traceball)) + print "Done." - if not os.path.exists(dir_name): - print "Reference traces directory (%s) does not exist" % dir_name + if not os.path.exists(reference_traces): + print "Reference traces directory (%s) does not exist" % reference_traces return 3 bad = [] @@ -254,9 +264,7 @@ def _run_regression_test(test): else: os.mkdir("traces") - dir_name = wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX - mod = __import__(test, globals(), locals(), []) return mod.run(verbose=(Params.g_options.verbose > 0), - generate=Params.g_options.regression_generate, - refDirName=dir_name) + generate=Params.g_options.regression_generate) + diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-bridge.py --- a/regression/tests/test-csma-bridge.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-bridge.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,10 +6,10 @@ import sys import sys import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" if tracediff.env['ENABLE_PYTHON_BINDINGS']: - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "csma-bridge", pyscript=os.path.join('examples', 'csma-bridge.py')) else: print >> sys.stderr, "Skipping csma-bridge: Python bindings not available." diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-broadcast.py --- a/regression/tests/test-csma-broadcast.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-broadcast.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-broadcast") + return tracediff.run_test(verbose, generate, "csma-broadcast") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-multicast.py --- a/regression/tests/test-csma-multicast.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-multicast.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-multicast") + return tracediff.run_test(verbose, generate, "csma-multicast") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-one-subnet.py --- a/regression/tests/test-csma-one-subnet.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-one-subnet.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-one-subnet") + return tracediff.run_test(verbose, generate, "csma-one-subnet") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-packet-socket.py --- a/regression/tests/test-csma-packet-socket.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-packet-socket.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,8 +6,8 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "csma-packet-socket") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-ping.py --- a/regression/tests/test-csma-ping.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-ping.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-ping") + return tracediff.run_test(verbose, generate, "csma-ping") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-raw-ip-socket.py --- a/regression/tests/test-csma-raw-ip-socket.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-raw-ip-socket.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-raw-ip-socket") + return tracediff.run_test(verbose, generate, "csma-raw-ip-socket") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-csma-star.py --- a/regression/tests/test-csma-star.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-csma-star.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "csma-star") + return tracediff.run_test(verbose, generate, "csma-star") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-realtime-udp-echo.py --- a/regression/tests/test-realtime-udp-echo.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-realtime-udp-echo.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "realtime-udp-echo") + return tracediff.run_test(verbose, generate, "realtime-udp-echo") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-simple-error-model.py --- a/regression/tests/test-simple-error-model.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-simple-error-model.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,8 +6,8 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "simple-error-model") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-simple-global-routing.py --- a/regression/tests/test-simple-global-routing.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-simple-global-routing.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,8 +6,8 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "simple-global-routing") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-simple-point-to-point-olsr.py --- a/regression/tests/test-simple-point-to-point-olsr.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-simple-point-to-point-olsr.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,8 +6,8 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "simple-point-to-point-olsr") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-tcp-large-transfer.py --- a/regression/tests/test-tcp-large-transfer.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-tcp-large-transfer.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,8 +6,8 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, "tcp-large-transfer") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-tcp-nsc-lfn.py --- a/regression/tests/test-tcp-nsc-lfn.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-tcp-nsc-lfn.py Thu Nov 20 19:44:19 2008 -0800 @@ -9,7 +9,7 @@ import platform import platform -def run(verbose, generate, refDirName): +def run(verbose, generate): """Run a Network Simulation Cradle test involving two TCP streams.""" if not tracediff.env['ENABLE_NSC']: @@ -29,5 +29,5 @@ def run(verbose, generate, refDirName): # string might not be the best idea? raise "Unknown architecture, not 64 or 32 bit?" - return tracediff.run_test(verbose, generate, refDirName, + return tracediff.run_test(verbose, generate, testName, arguments=arguments, refTestName=traceDirName) diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-udp-echo.py --- a/regression/tests/test-udp-echo.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-udp-echo.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" #print tracediff.env - return tracediff.run_test(verbose, generate, refDirName, "udp-echo") + return tracediff.run_test(verbose, generate, "udp-echo") diff -r eef10dbce686 -r e2ada9e99280 regression/tests/test-wifi-wired-bridging.py --- a/regression/tests/test-wifi-wired-bridging.py Thu Nov 20 16:48:21 2008 -0800 +++ b/regression/tests/test-wifi-wired-bridging.py Thu Nov 20 19:44:19 2008 -0800 @@ -6,7 +6,7 @@ import shutil import shutil import tracediff -def run(verbose, generate, refDirName): +def run(verbose, generate): """Execute a test.""" - return tracediff.run_test(verbose, generate, refDirName, "wifi-wired-bridging", ["--SendIp=0"]) + return tracediff.run_test(verbose, generate, "wifi-wired-bridging", ["--SendIp=0"]) diff -r eef10dbce686 -r e2ada9e99280 src/core/object.cc --- a/src/core/object.cc Thu Nov 20 16:48:21 2008 -0800 +++ b/src/core/object.cc Thu Nov 20 19:44:19 2008 -0800 @@ -111,10 +111,11 @@ Object::DoGetObject (TypeId tid) const { NS_ASSERT (CheckLoose ()); const Object *currentObject = this; + TypeId objectTid = Object::GetTypeId (); do { NS_ASSERT (currentObject != 0); TypeId cur = currentObject->GetInstanceTypeId (); - while (cur != tid && cur != Object::GetTypeId ()) + while (cur != tid && cur != objectTid) { cur = cur.GetParent (); } diff -r eef10dbce686 -r e2ada9e99280 src/core/type-id.cc --- a/src/core/type-id.cc Thu Nov 20 16:48:21 2008 -0800 +++ b/src/core/type-id.cc Thu Nov 20 19:44:19 2008 -0800 @@ -365,10 +365,6 @@ namespace ns3 { * The TypeId class *********************************************************************/ -TypeId::TypeId () - : m_tid (0) -{} - TypeId::TypeId (const char *name) { uint16_t uid = Singleton::Get ()->AllocateUid (name); @@ -379,8 +375,6 @@ TypeId::TypeId (const char *name) TypeId::TypeId (uint16_t tid) : m_tid (tid) -{} -TypeId::~TypeId () {} TypeId TypeId::LookupByName (std::string name) @@ -692,16 +686,6 @@ std::istream & operator >> (std::istream ATTRIBUTE_HELPER_CPP (TypeId); -bool operator == (TypeId a, TypeId b) -{ - return a.m_tid == b.m_tid; -} - -bool operator != (TypeId a, TypeId b) -{ - return a.m_tid != b.m_tid; -} - bool operator < (TypeId a, TypeId b) { return a.m_tid < b.m_tid; diff -r eef10dbce686 -r e2ada9e99280 src/core/type-id.h --- a/src/core/type-id.h Thu Nov 20 16:48:21 2008 -0800 +++ b/src/core/type-id.h Thu Nov 20 19:44:19 2008 -0800 @@ -351,8 +351,10 @@ public: void SetUid (uint16_t tid); // construct an invalid TypeId. - TypeId (); - ~TypeId (); + inline TypeId (); + inline TypeId (const TypeId &o); + inline TypeId &operator = (const TypeId &o); + inline ~TypeId (); private: friend class AttributeList; @@ -377,8 +379,8 @@ private: std::ostream & operator << (std::ostream &os, TypeId tid); std::istream & operator >> (std::istream &is, TypeId &tid); -bool operator == (TypeId a, TypeId b); -bool operator != (TypeId a, TypeId b); +inline bool operator == (TypeId a, TypeId b); +inline bool operator != (TypeId a, TypeId b); bool operator < (TypeId a, TypeId b); /** @@ -392,6 +394,28 @@ ATTRIBUTE_HELPER_HEADER (TypeId); } // namespace ns3 namespace ns3 { + +TypeId::TypeId () + : m_tid (0) {} +TypeId::TypeId (const TypeId &o) + : m_tid (o.m_tid) {} +TypeId &TypeId::operator = (const TypeId &o) +{ + m_tid = o.m_tid; + return *this; +} +TypeId::~TypeId () +{} +inline bool operator == (TypeId a, TypeId b) +{ + return a.m_tid == b.m_tid; +} + +inline bool operator != (TypeId a, TypeId b) +{ + return a.m_tid != b.m_tid; +} + /************************************************************************* * The TypeId implementation which depends on templates diff -r eef10dbce686 -r e2ada9e99280 src/internet-stack/ipv4-l3-protocol.cc --- a/src/internet-stack/ipv4-l3-protocol.cc Thu Nov 20 16:48:21 2008 -0800 +++ b/src/internet-stack/ipv4-l3-protocol.cc Thu Nov 20 19:44:19 2008 -0800 @@ -669,8 +669,15 @@ Ipv4L3Protocol::Send (Ptr packet else { NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ()); - m_txTrace (packetCopy, ifaceIndex); - outInterface->Send (packetCopy, destination); + if (outInterface->IsUp ()) + { + m_txTrace (packetCopy, ifaceIndex); + outInterface->Send (packetCopy, destination); + } + else + { + m_dropTrace (packetCopy); + } } } } @@ -732,13 +739,31 @@ Ipv4L3Protocol::SendRealOut (bool found, m_txTrace (packet, route.GetInterface ()); if (route.IsGateway ()) { - NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ()); - outInterface->Send (packet, route.GetGateway ()); + if (outInterface->IsUp ()) + { + NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ()); + m_txTrace (packet, route.GetInterface ()); + outInterface->Send (packet, route.GetGateway ()); + } + else + { + NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route.GetGateway ()); + m_dropTrace (packet); + } } else { - NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ()); - outInterface->Send (packet, ipHeader.GetDestination ()); + if (outInterface->IsUp ()) + { + NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ()); + m_txTrace (packet, route.GetInterface ()); + outInterface->Send (packet, ipHeader.GetDestination ()); + } + else + { + NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route.GetGateway ()); + m_dropTrace (packet); + } } } } diff -r eef10dbce686 -r e2ada9e99280 src/internet-stack/wscript --- a/src/internet-stack/wscript Thu Nov 20 16:48:21 2008 -0800 +++ b/src/internet-stack/wscript Thu Nov 20 19:44:19 2008 -0800 @@ -7,7 +7,7 @@ import urllib # Mercurial repository of the network simulation cradle NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc" NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc" -NSC_RELEASE_NAME = "nsc-0.4.0" +NSC_RELEASE_NAME = "nsc-0.5.0" # directory that contains network simulation cradle source # note, this path is relative to the project root diff -r eef10dbce686 -r e2ada9e99280 wscript --- a/wscript Thu Nov 20 16:48:21 2008 -0800 +++ b/wscript Thu Nov 20 19:44:19 2008 -0800 @@ -143,6 +143,10 @@ def set_options(opt): help=('Use sudo to setup suid bits on ns3 executables.'), dest='enable_sudo', action='store_true', default=False) + opt.add_option('--with-regression-traces', + help=('Path to the regression reference traces directory'), + default=None, + dest='regression_traces', type="string") # options provided in a script in a subdirectory named "src" opt.sub_options('src') @@ -192,6 +196,11 @@ def configure(conf): variant_name = debug_level variant_env['INCLUDEDIR'] = os.path.join(variant_env['PREFIX'], 'include') + + if Params.g_options.regression_traces is not None: + variant_env['REGRESSION_TRACES'] = os.path.join("..", Params.g_options.regression_traces) + else: + variant_env['REGRESSION_TRACES'] = None if Params.g_options.enable_gcov: variant_name += '-gcov' @@ -463,10 +472,14 @@ def shutdown(): if Params.g_options.regression or Params.g_options.regression_generate: if not env['DIFF']: Params.fatal("Cannot run regression tests: the 'diff' program is not installed.") + _dir = os.getcwd() os.chdir("regression") + regression_traces = env['REGRESSION_TRACES'] + if not regression_traces: + regression_traces = None try: - regression.run_regression() + regression.run_regression(regression_traces) finally: os.chdir(_dir) changeset: 3887:6a47ccdf2c5d tag: tip user: Craig Dowell date: Thu Nov 20 20:50:17 2008 -0800 summary: remove some hey-look-here debugging flags diff -r e2ada9e99280 -r 6a47ccdf2c5d src/routing/global-routing/global-router-interface.cc --- a/src/routing/global-routing/global-router-interface.cc Thu Nov 20 19:44:19 2008 -0800 +++ b/src/routing/global-routing/global-router-interface.cc Thu Nov 20 20:50:17 2008 -0800 @@ -597,7 +597,7 @@ GlobalRouter::DiscoverLSAs (void) if (!isIp) { - NS_LOG_LOGIC ("**** Net device " << ndLocal << "has no IP interface, skipping"); + NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface, skipping"); continue; } @@ -612,12 +612,12 @@ GlobalRouter::DiscoverLSAs (void) // if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () ) { - NS_LOG_LOGIC ("**** Broadcast link"); + NS_LOG_LOGIC ("Broadcast link"); ProcessBroadcastLink (ndLocal, pLSA, c); } else if (ndLocal->IsPointToPoint () ) { - NS_LOG_LOGIC ("**** Point=to-point link"); + NS_LOG_LOGIC ("Point=to-point link"); ProcessPointToPointLink (ndLocal, pLSA); } else @@ -700,7 +700,7 @@ GlobalRouter::ProcessSingleBroadcastLink // // This is a net device connected to a stub network // - NS_LOG_LOGIC("**** Router-LSA Stub Network"); + NS_LOG_LOGIC("Router-LSA Stub Network"); plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); // @@ -725,7 +725,7 @@ GlobalRouter::ProcessSingleBroadcastLink // We have multiple routers on a broadcast interface, so this is // a transit network. // - NS_LOG_LOGIC ("**** Router-LSA Transit Network"); + NS_LOG_LOGIC ("Router-LSA Transit Network"); plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); // @@ -835,7 +835,7 @@ GlobalRouter::ProcessBridgedBroadcastLin // // This is a net device connected to a bridge of stub networks // - NS_LOG_LOGIC("**** Router-LSA Stub Network"); + NS_LOG_LOGIC("Router-LSA Stub Network"); plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork); // @@ -860,7 +860,7 @@ GlobalRouter::ProcessBridgedBroadcastLin // We have multiple routers on a bridged broadcast interface, so this is // a transit network. // - NS_LOG_LOGIC ("**** Router-LSA Transit Network"); + NS_LOG_LOGIC ("Router-LSA Transit Network"); plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork); // @@ -1084,7 +1084,7 @@ GlobalRouter::FindDesignatedRouterForLin uint32_t nDevices = ch->GetNDevices(); NS_ASSERT (nDevices); - NS_LOG_LOGIC ("**** Looking for designated router off of net device " << ndLocal << " on node " << + NS_LOG_LOGIC ("Looking for designated router off of net device " << ndLocal << " on node " << ndLocal->GetNode ()->GetId ()); Ipv4Address desigRtr ("255.255.255.255"); @@ -1100,7 +1100,7 @@ GlobalRouter::FindDesignatedRouterForLin Ptr nodeOther = ndOther->GetNode (); - NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << nodeOther->GetId ()); + NS_LOG_LOGIC ("Examine channel device " << i << " on node " << nodeOther->GetId ()); // // For all other net devices, we need to check and see if a router @@ -1108,11 +1108,11 @@ GlobalRouter::FindDesignatedRouterForLin // device, we need to consider all of the other devices on the // bridge as well (all of the bridge ports. // - NS_LOG_LOGIC ("**** checking to see if the device is bridged"); + NS_LOG_LOGIC ("checking to see if the device is bridged"); Ptr bnd = NetDeviceIsBridged (ndOther); if (bnd) { - NS_LOG_LOGIC ("**** Device is bridged by BridgeNetDevice " << bnd); + NS_LOG_LOGIC ("Device is bridged by BridgeNetDevice " << bnd); // // It is possible that the bridge net device is sitting under a @@ -1123,7 +1123,7 @@ GlobalRouter::FindDesignatedRouterForLin // an internet stack that includes the Ipv4 interface. If it doesn't // it can't play router. // - NS_LOG_LOGIC ("**** Checking for router on bridge net device " << bnd); + NS_LOG_LOGIC ("Checking for router on bridge net device " << bnd); Ptr rtr = nodeOther->GetObject (); Ptr ipv4 = nodeOther->GetObject (); if (rtr && ipv4) @@ -1131,36 +1131,36 @@ GlobalRouter::FindDesignatedRouterForLin uint32_t ifIndexOther; if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther)) { - NS_LOG_LOGIC ("**** Found router on bridge net device " << bnd); + NS_LOG_LOGIC ("Found router on bridge net device " << bnd); Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther); desigRtr = addrOther < desigRtr ? addrOther : desigRtr; - NS_LOG_LOGIC ("**** designated router now " << desigRtr); + NS_LOG_LOGIC ("designated router now " << desigRtr); } } - NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd); + NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd); for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) { Ptr ndBridged = bnd->GetBridgePort (j); - NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged); + NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged); if (ndBridged == ndOther) { - NS_LOG_LOGIC ("**** That bridge port is me, don't walk backward"); + NS_LOG_LOGIC ("That bridge port is me, don't walk backward"); continue; } if (allowRecursion) { - NS_LOG_LOGIC ("**** Recursively looking for routers down bridge port " << ndBridged); + NS_LOG_LOGIC ("Recursively looking for routers down bridge port " << ndBridged); Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false); desigRtr = addrOther < desigRtr ? addrOther : desigRtr; - NS_LOG_LOGIC ("**** designated router now " << desigRtr); + NS_LOG_LOGIC ("designated router now " << desigRtr); } } } else { - NS_LOG_LOGIC ("**** This device is not bridged"); + NS_LOG_LOGIC ("This device is not bridged"); Ptr nodeOther = ndOther->GetNode (); NS_ASSERT (nodeOther); @@ -1175,10 +1175,10 @@ GlobalRouter::FindDesignatedRouterForLin uint32_t ifIndexOther; if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther)) { - NS_LOG_LOGIC ("**** Found router on net device " << ndOther); + NS_LOG_LOGIC ("Found router on net device " << ndOther); Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther); desigRtr = addrOther < desigRtr ? addrOther : desigRtr; - NS_LOG_LOGIC ("**** designated router now " << desigRtr); + NS_LOG_LOGIC ("designated router now " << desigRtr); } } } @@ -1201,7 +1201,7 @@ GlobalRouter::AnotherRouterOnLink (PtrGetNDevices(); NS_ASSERT (nDevices); - NS_LOG_LOGIC ("**** Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ()); + NS_LOG_LOGIC ("Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ()); // // Look through all of the devices on the channel to which the net device @@ -1212,14 +1212,14 @@ GlobalRouter::AnotherRouterOnLink (Ptr ndOther = ch->GetDevice (i); NS_ASSERT (ndOther); - NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ()); + NS_LOG_LOGIC ("Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ()); // // Ignore the net device itself. // if (ndOther == nd) { - NS_LOG_LOGIC ("**** Myself, skip"); + NS_LOG_LOGIC ("Myself, skip"); continue; } @@ -1229,52 +1229,52 @@ GlobalRouter::AnotherRouterOnLink (Ptr bnd = NetDeviceIsBridged (ndOther); if (bnd) { - NS_LOG_LOGIC ("**** Device is bridged by net device " << bnd); - NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd); + NS_LOG_LOGIC ("Device is bridged by net device " << bnd); + NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd); for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) { Ptr ndBridged = bnd->GetBridgePort (j); - NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged); + NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged); if (ndBridged == ndOther) { - NS_LOG_LOGIC ("**** That bridge port is me, skip"); + NS_LOG_LOGIC ("That bridge port is me, skip"); continue; } if (allowRecursion) { - NS_LOG_LOGIC ("**** Recursively looking for routers on bridge port " << ndBridged); + NS_LOG_LOGIC ("Recursively looking for routers on bridge port " << ndBridged); if (AnotherRouterOnLink (ndBridged, false)) { - NS_LOG_LOGIC ("**** Found routers on bridge port, return true"); + NS_LOG_LOGIC ("Found routers on bridge port, return true"); return true; } } } - NS_LOG_LOGIC ("**** No routers on bridged net device, return false"); + NS_LOG_LOGIC ("No routers on bridged net device, return false"); return false; } - NS_LOG_LOGIC ("**** This device is not bridged"); + NS_LOG_LOGIC ("This device is not bridged"); Ptr nodeTemp = ndOther->GetNode (); NS_ASSERT (nodeTemp); Ptr rtr = nodeTemp->GetObject (); if (rtr) { - NS_LOG_LOGIC ("**** Found GlobalRouter interface, return true"); + NS_LOG_LOGIC ("Found GlobalRouter interface, return true"); return true; } else { - NS_LOG_LOGIC ("**** No GlobalRouter interface on device, continue search"); + NS_LOG_LOGIC ("No GlobalRouter interface on device, continue search"); } } - NS_LOG_LOGIC ("**** No routers found, return false"); + NS_LOG_LOGIC ("No routers found, return false"); return false; } @@ -1365,7 +1365,7 @@ GlobalRouter::FindIfIndexForDevice (Ptr< Ptr ipv4 = node->GetObject (); if (ipv4 == 0) { - NS_LOG_LOGIC ("**** No Ipv4 interface on node " << node->GetId ()); + NS_LOG_LOGIC ("No Ipv4 interface on node " << node->GetId ()); return false; } @@ -1373,13 +1373,13 @@ GlobalRouter::FindIfIndexForDevice (Ptr< { if (ipv4->GetNetDevice(i) == nd) { - NS_LOG_LOGIC ("**** Device " << nd << " has associated ipv4 index " << i); + NS_LOG_LOGIC ("Device " << nd << " has associated ipv4 index " << i); index = i; return true; } } - NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index"); + NS_LOG_LOGIC ("Device " << nd << " has no associated ipv4 index"); return false; } @@ -1403,26 +1403,26 @@ GlobalRouter::NetDeviceIsBridged (Ptr ndTest = node->GetDevice(i); - NS_LOG_LOGIC ("**** Examine device " << i << " " << ndTest); + NS_LOG_LOGIC ("Examine device " << i << " " << ndTest); if (ndTest->IsBridge ()) { - NS_LOG_LOGIC ("**** device " << i << " is a bridge net device"); + NS_LOG_LOGIC ("device " << i << " is a bridge net device"); Ptr bnd = ndTest->GetObject (); NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for failed"); for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j) { - NS_LOG_LOGIC ("**** Examine bridge port " << j << " " << bnd->GetBridgePort (j)); + NS_LOG_LOGIC ("Examine bridge port " << j << " " << bnd->GetBridgePort (j)); if (bnd->GetBridgePort (j) == nd) { - NS_LOG_LOGIC ("**** Net device " << nd << " is bridged by " << bnd); + NS_LOG_LOGIC ("Net device " << nd << " is bridged by " << bnd); return bnd; } } } } - NS_LOG_LOGIC ("**** Net device " << nd << " is not bridged"); + NS_LOG_LOGIC ("Net device " << nd << " is not bridged"); return 0; }