ns-3-simu-mod
changeset 4545:f6bc20790cb6
merge with HEAD
| author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|---|---|
| date | Fri Nov 28 08:56:47 2008 +0100 (3 years ago) |
| parents | 4ac29a986eef 016c554c4f6d |
| children | 75d47d7f4bc24ddcca845f07 |
| files |
line diff
1.1 --- a/CHANGES.html Fri Nov 28 08:55:24 2008 +0100
1.2 +++ b/CHANGES.html Fri Nov 28 08:56:47 2008 +0100
1.3 @@ -106,6 +106,14 @@
1.4 </li>
1.5 </ul>
1.6
1.7 +<li>17-11-2008; changeset
1.8 +<a href="http://code.nsnam.org/ns-3-dev/rev/756887a9bbea">756887a9bbea</a></li>
1.9 +<ul>
1.10 +<li>
1.11 +Global routing supports bridge devices.
1.12 +</li>
1.13 +</ul>
1.14 +
1.15 <hr>
1.16 <h1>changes from ns-3.1 to ns-3.2</h1>
1.17
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/csma-bridge-one-hop.cc Fri Nov 28 08:56:47 2008 +0100
2.3 @@ -0,0 +1,246 @@
2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2.5 +/*
2.6 + * This program is free software; you can redistribute it and/or modify
2.7 + * it under the terms of the GNU General Public License version 2 as
2.8 + * published by the Free Software Foundation;
2.9 + *
2.10 + * This program is distributed in the hope that it will be useful,
2.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.13 + * GNU General Public License for more details.
2.14 + *
2.15 + * You should have received a copy of the GNU General Public License
2.16 + * along with this program; if not, write to the Free Software
2.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.18 + */
2.19 +
2.20 +// Network topology
2.21 +//
2.22 +// bridge1 The node named bridge1 (node 5 in the nodelist)
2.23 +// ------------------ has three CMSA net devices that are bridged
2.24 +// CSMA CSMA CSMA together using a BridgeNetDevice.
2.25 +// | | |
2.26 +// | | | The bridge node talks over three CSMA channels
2.27 +// | | |
2.28 +// CSMA CSMA CSMA to three other CSMA net devices
2.29 +// ---- ---- ----
2.30 +// n0 n1 n2 Node two acts as a router and talks to another
2.31 +// ---- bridge that connects the remaining nodes.
2.32 +// CSMA
2.33 +// |
2.34 +// n3 n4 |
2.35 +// ---- ---- |
2.36 +// CSMA CSMA |
2.37 +// | | |
2.38 +// | | |
2.39 +// | | |
2.40 +// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist)
2.41 +// ------------------ has three CMSA net devices that are bridged
2.42 +// bridge2 together using a BridgeNetDevice.
2.43 +//
2.44 +// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes
2.45 +// with three net devices:
2.46 +//
2.47 +// n0 n1 (n0 = 10.1.1.2)
2.48 +// | | (n1 = 10.1.1.3) Note odd addressing
2.49 +// ----------- (n2 = 10.1.1.1)
2.50 +// | bridge1 | <- n5
2.51 +// -----------
2.52 +// |
2.53 +// router <- n2
2.54 +// |
2.55 +// -----------
2.56 +// | bridge2 | <- n6
2.57 +// ----------- (n2 = 10.1.2.1)
2.58 +// | | (n3 = 10.1.2.2)
2.59 +// n3 n4 (n4 = 10.1.2.3)
2.60 +//
2.61 +// So, this example shows two broadcast domains, each interconnected by a bridge
2.62 +// with a router node (n2) interconnecting the layer-2 broadcast domains
2.63 +//
2.64 +// It is meant to mirror somewhat the csma-bridge example but adds another
2.65 +// bridged link separated by a router.
2.66 +//
2.67 +// - 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)
2.68 +// - DropTail queues
2.69 +// - Global static routing
2.70 +// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
2.71 +
2.72 +#include <iostream>
2.73 +#include <fstream>
2.74 +
2.75 +#include "ns3/simulator-module.h"
2.76 +#include "ns3/node-module.h"
2.77 +#include "ns3/core-module.h"
2.78 +#include "ns3/helper-module.h"
2.79 +#include "ns3/bridge-module.h"
2.80 +#include "ns3/global-route-manager.h"
2.81 +
2.82 +using namespace ns3;
2.83 +
2.84 +NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample");
2.85 +
2.86 +int
2.87 +main (int argc, char *argv[])
2.88 +{
2.89 + //
2.90 + // Users may find it convenient to turn on explicit debugging
2.91 + // for selected modules; the below lines suggest how to do this
2.92 + //
2.93 +#if 0
2.94 + LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO);
2.95 +#endif
2.96 +
2.97 + //
2.98 + // Make the random number generators generate reproducible results.
2.99 + //
2.100 + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
2.101 +
2.102 + //
2.103 + // Allow the user to override any of the defaults and the above Bind() at
2.104 + // run-time, via command-line arguments
2.105 + //
2.106 + CommandLine cmd;
2.107 + cmd.Parse (argc, argv);
2.108 +
2.109 + //
2.110 + // Explicitly create the nodes required by the topology (shown above).
2.111 + //
2.112 + NS_LOG_INFO ("Create nodes.");
2.113 +
2.114 + Ptr<Node> n0 = CreateObject<Node> ();
2.115 + Ptr<Node> n1 = CreateObject<Node> ();
2.116 + Ptr<Node> n2 = CreateObject<Node> ();
2.117 + Ptr<Node> n3 = CreateObject<Node> ();
2.118 + Ptr<Node> n4 = CreateObject<Node> ();
2.119 +
2.120 + Ptr<Node> bridge1 = CreateObject<Node> ();
2.121 + Ptr<Node> bridge2 = CreateObject<Node> ();
2.122 +
2.123 + NS_LOG_INFO ("Build Topology");
2.124 + CsmaHelper csma;
2.125 + csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
2.126 + csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
2.127 +
2.128 + // Create the csma links, from each terminal to the bridge
2.129 + // This will create six network devices; we'll keep track separately
2.130 + // of the devices on and off the bridge respectively, for later configuration
2.131 + NetDeviceContainer topLanDevices;
2.132 + NetDeviceContainer topBridgeDevices;
2.133 +
2.134 + // It is easier to iterate the nodes in C++ if we put them into a container
2.135 + NodeContainer topLan (n2, n0, n1);
2.136 +
2.137 + for (int i = 0; i < 3; i++)
2.138 + {
2.139 + // install a csma channel between the ith toplan node and the bridge node
2.140 + NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
2.141 + topLanDevices.Add (link.Get (0));
2.142 + topBridgeDevices.Add (link.Get (1));
2.143 + }
2.144 +
2.145 + //
2.146 + // Now, Create the bridge netdevice, which will do the packet switching. The
2.147 + // bridge lives on the node bridge1 and bridges together the topBridgeDevices
2.148 + // which are the three CSMA net devices on the node in the diagram above.
2.149 + //
2.150 + BridgeHelper bridge;
2.151 + bridge.Install (bridge1, topBridgeDevices);
2.152 +
2.153 + // Add internet stack to the topLan nodes
2.154 + InternetStackHelper internet;
2.155 + internet.Install (topLan);
2.156 +
2.157 + // Repeat for bottom bridged LAN
2.158 + NetDeviceContainer bottomLanDevices;
2.159 + NetDeviceContainer bottomBridgeDevices;
2.160 + NodeContainer bottomLan (n2, n3, n4);
2.161 + for (int i = 0; i < 3; i++)
2.162 + {
2.163 + NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2));
2.164 + bottomLanDevices.Add (link.Get (0));
2.165 + bottomBridgeDevices.Add (link.Get (1));
2.166 + }
2.167 + bridge.Install (bridge2, bottomBridgeDevices);
2.168 +
2.169 + // Add internet stack to the bottomLan nodes
2.170 + internet.Install (NodeContainer (n3, n4));
2.171 +
2.172 + // We've got the "hardware" in place. Now we need to add IP addresses.
2.173 + NS_LOG_INFO ("Assign IP Addresses.");
2.174 + Ipv4AddressHelper ipv4;
2.175 + ipv4.SetBase ("10.1.1.0", "255.255.255.0");
2.176 + ipv4.Assign (topLanDevices);
2.177 + ipv4.SetBase ("10.1.2.0", "255.255.255.0");
2.178 + ipv4.Assign (bottomLanDevices);
2.179 +
2.180 + //
2.181 + // Create router nodes, initialize routing database and set up the routing
2.182 + // tables in the nodes. We excuse the bridge nodes from having to serve as
2.183 + // routers, since they don't even have internet stacks on them.
2.184 + //
2.185 + NodeContainer routerNodes (n0, n1, n2, n3, n4);
2.186 + GlobalRouteManager::PopulateRoutingTables (routerNodes);
2.187 +
2.188 + //
2.189 + // Create an OnOff application to send UDP datagrams from node zero to node 1.
2.190 + //
2.191 + NS_LOG_INFO ("Create Applications.");
2.192 + uint16_t port = 9; // Discard port (RFC 863)
2.193 +
2.194 + OnOffHelper onoff ("ns3::UdpSocketFactory",
2.195 + Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port)));
2.196 + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
2.197 + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
2.198 +
2.199 + ApplicationContainer app = onoff.Install (n0);
2.200 + // Start the application
2.201 + app.Start (Seconds (1.0));
2.202 + app.Stop (Seconds (10.0));
2.203 +
2.204 + // Create an optional packet sink to receive these packets
2.205 + PacketSinkHelper sink ("ns3::UdpSocketFactory",
2.206 + Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
2.207 + ApplicationContainer sink1 = sink.Install (n1);
2.208 + sink1.Start (Seconds (1.0));
2.209 + sink1.Stop (Seconds (10.0));
2.210 +
2.211 + //
2.212 + // Create a similar flow from n3 to n0, starting at time 1.1 seconds
2.213 + //
2.214 + onoff.SetAttribute ("Remote",
2.215 + AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
2.216 + ApplicationContainer app2 = onoff.Install (n3);
2.217 + app2.Start (Seconds (1.1));
2.218 + app2.Stop (Seconds (10.0));
2.219 +
2.220 + ApplicationContainer sink2 = sink.Install (n0);
2.221 + sink2.Start (Seconds (1.1));
2.222 + sink2.Stop (Seconds (10.0));
2.223 +
2.224 + //
2.225 + // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
2.226 + // Trace output will be sent to the file "csma-bridge-one-hop.tr"
2.227 + //
2.228 + NS_LOG_INFO ("Configure Tracing.");
2.229 + std::ofstream ascii;
2.230 + ascii.open ("csma-bridge-one-hop.tr");
2.231 + CsmaHelper::EnableAsciiAll (ascii);
2.232 +
2.233 + //
2.234 + // Also configure some tcpdump traces; each interface will be traced.
2.235 + // The output files will be named:
2.236 + // csma-bridge.pcap-<nodeId>-<interfaceId>
2.237 + // and can be read by the "tcpdump -r" command (use "-tt" option to
2.238 + // display timestamps correctly)
2.239 + //
2.240 + CsmaHelper::EnablePcapAll ("csma-bridge-one-hop");
2.241 +
2.242 + //
2.243 + // Now, do the actual simulation.
2.244 + //
2.245 + NS_LOG_INFO ("Run Simulation.");
2.246 + Simulator::Run ();
2.247 + Simulator::Destroy ();
2.248 + NS_LOG_INFO ("Done.");
2.249 +}
3.1 --- a/examples/wifi-wired-bridging.cc Fri Nov 28 08:55:24 2008 +0100
3.2 +++ b/examples/wifi-wired-bridging.cc Fri Nov 28 08:56:47 2008 +0100
3.3 @@ -1,4 +1,46 @@
3.4 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3.5 +/*
3.6 + * This program is free software; you can redistribute it and/or modify
3.7 + * it under the terms of the GNU General Public License version 2 as
3.8 + * published by the Free Software Foundation;
3.9 + *
3.10 + * This program is distributed in the hope that it will be useful,
3.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.13 + * GNU General Public License for more details.
3.14 + *
3.15 + * You should have received a copy of the GNU General Public License
3.16 + * along with this program; if not, write to the Free Software
3.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3.18 + */
3.19 +
3.20 +// Default network topology includes some number of AP nodes specified by
3.21 +// the variable nWifis (defaults to two). Off of each AP node, there are some
3.22 +// number of STA nodes specified by the variable nStas (defaults to two).
3.23 +// Each AP talks to its associated STA nodes. There are bridge net devices
3.24 +// on each AP node that bridge the whole thing into one network.
3.25 +//
3.26 +// +-----+ +-----+ +-----+ +-----+
3.27 +// | STA | | STA | | STA | | STA |
3.28 +// +-----+ +-----+ +-----+ +-----+
3.29 +// 192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6
3.30 +// -------- -------- -------- --------
3.31 +// WIFI STA WIFI STA WIFI STA WIFI STA
3.32 +// -------- -------- -------- --------
3.33 +// ((*)) ((*)) | ((*)) ((*))
3.34 +// |
3.35 +// ((*)) | ((*))
3.36 +// ------- -------
3.37 +// WIFI AP CSMA ========= CSMA WIFI AP
3.38 +// ------- ---- ---- -------
3.39 +// ############## ##############
3.40 +// BRIDGE BRIDGE
3.41 +// ############## ##############
3.42 +// 192.168.0.1 192.168.0.2
3.43 +// +---------+ +---------+
3.44 +// | AP Node | | AP Node |
3.45 +// +---------+ +---------+
3.46 +//
3.47
3.48 #include "ns3/core-module.h"
3.49 #include "ns3/simulator-module.h"
3.50 @@ -46,7 +88,6 @@
3.51 stack.Install (backboneNodes);
3.52
3.53 backboneDevices = csma.Install (backboneNodes);
3.54 - backboneInterfaces = ip.Assign (backboneDevices);
3.55
3.56 double wifiX = 0.0;
3.57 for (uint32_t i = 0; i < nWifis; ++i)
3.58 @@ -69,7 +110,6 @@
3.59 wifiPhy.SetChannel (wifiChannel.Create ());
3.60
3.61 sta.Create (nStas);
3.62 - ip.NewNetwork ();
3.63 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
3.64 "MinX", DoubleValue (wifiX),
3.65 "MinY", DoubleValue (0.0),
3.66 @@ -87,8 +127,12 @@
3.67 "BeaconGeneration", BooleanValue (true),
3.68 "BeaconInterval", TimeValue (Seconds (2.5)));
3.69 apDev = wifi.Install (wifiPhy, backboneNodes.Get (i));
3.70 - apInterface = ip.Assign (apDev);
3.71 - bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
3.72 +
3.73 + NetDeviceContainer bridgeDev;
3.74 + bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
3.75 +
3.76 + // assign AP IP address to bridge, not wifi
3.77 + apInterface = ip.Assign (bridgeDev);
3.78
3.79 // setup the STAs
3.80 stack.Install (sta);
4.1 --- a/examples/wscript Fri Nov 28 08:55:24 2008 +0100
4.2 +++ b/examples/wscript Fri Nov 28 08:56:47 2008 +0100
4.3 @@ -28,6 +28,10 @@
4.4 ['bridge', 'csma', 'internet-stack'])
4.5 obj.source = 'csma-bridge.cc'
4.6
4.7 + obj = bld.create_ns3_program('csma-bridge-one-hop',
4.8 + ['bridge', 'csma', 'internet-stack'])
4.9 + obj.source = 'csma-bridge-one-hop.cc'
4.10 +
4.11 obj = bld.create_ns3_program('udp-echo',
4.12 ['csma', 'internet-stack'])
4.13 obj.source = 'udp-echo.cc'
5.1 --- a/src/applications/v4ping/v4ping.cc Fri Nov 28 08:55:24 2008 +0100
5.2 +++ b/src/applications/v4ping/v4ping.cc Fri Nov 28 08:56:47 2008 +0100
5.3 @@ -149,6 +149,7 @@
5.4 V4Ping::StopApplication (void)
5.5 {
5.6 NS_LOG_FUNCTION (this);
5.7 + m_socket->Close ();
5.8 }
5.9
5.10
6.1 --- a/src/core/abort.h Fri Nov 28 08:55:24 2008 +0100
6.2 +++ b/src/core/abort.h Fri Nov 28 08:56:47 2008 +0100
6.3 @@ -21,6 +21,16 @@
6.4
6.5 #include "fatal-error.h"
6.6
6.7 +#define NS_ABORT_MSG(msg) \
6.8 + do { \
6.9 + std::cerr << "file=" << __FILE__ << \
6.10 + ", line=" << __LINE__ << ", abort, msg=\"" << \
6.11 + msg << "\"" << std::endl; \
6.12 + int *a = 0; \
6.13 + *a = 0; \
6.14 + } while (false)
6.15 +
6.16 +
6.17 #define NS_ABORT_IF(cond) \
6.18 do { \
6.19 if (cond) \
7.1 --- a/src/devices/bridge/bridge-net-device.cc Fri Nov 28 08:55:24 2008 +0100
7.2 +++ b/src/devices/bridge/bridge-net-device.cc Fri Nov 28 08:56:47 2008 +0100
7.3 @@ -57,6 +57,7 @@
7.4 m_ifIndex (0),
7.5 m_mtu (0xffff)
7.6 {
7.7 + NS_LOG_FUNCTION_NOARGS ();
7.8 m_channel = CreateObject<BridgeChannel> ();
7.9 }
7.10
7.11 @@ -100,6 +101,7 @@
7.12 BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
7.13 uint16_t protocol, Mac48Address src, Mac48Address dst)
7.14 {
7.15 + NS_LOG_FUNCTION_NOARGS ();
7.16 NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
7.17 << ", packet=" << packet << ", protocol="<<protocol
7.18 << ", src=" << src << ", dst=" << dst << ")");
7.19 @@ -133,6 +135,7 @@
7.20 BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
7.21 uint16_t protocol, Mac48Address src, Mac48Address dst)
7.22 {
7.23 + NS_LOG_FUNCTION_NOARGS ();
7.24 NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
7.25 << ", packet=" << packet << ", protocol="<<protocol
7.26 << ", src=" << src << ", dst=" << dst << ")");
7.27 @@ -154,6 +157,7 @@
7.28
7.29 void BridgeNetDevice::Learn (Mac48Address source, Ptr<NetDevice> port)
7.30 {
7.31 + NS_LOG_FUNCTION_NOARGS ();
7.32 if (m_enableLearning)
7.33 {
7.34 LearnedState &state = m_learnState[source];
7.35 @@ -164,6 +168,7 @@
7.36
7.37 Ptr<NetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
7.38 {
7.39 + NS_LOG_FUNCTION_NOARGS ();
7.40 if (m_enableLearning)
7.41 {
7.42 Time now = Simulator::Now ();
7.43 @@ -185,9 +190,25 @@
7.44 return NULL;
7.45 }
7.46
7.47 +uint32_t
7.48 +BridgeNetDevice::GetNBridgePorts (void) const
7.49 +{
7.50 + NS_LOG_FUNCTION_NOARGS ();
7.51 + return m_ports.size ();
7.52 +}
7.53 +
7.54 +
7.55 +Ptr<NetDevice>
7.56 +BridgeNetDevice::GetBridgePort (uint32_t n) const
7.57 +{
7.58 + NS_LOG_FUNCTION_NOARGS ();
7.59 + return m_ports[n];
7.60 +}
7.61 +
7.62 void
7.63 BridgeNetDevice::AddBridgePort (Ptr<NetDevice> bridgePort)
7.64 {
7.65 + NS_LOG_FUNCTION_NOARGS ();
7.66 NS_ASSERT (bridgePort != this);
7.67 if (!Mac48Address::IsMatchingType (bridgePort->GetAddress ()))
7.68 {
7.69 @@ -212,42 +233,49 @@
7.70 void
7.71 BridgeNetDevice::SetName(const std::string name)
7.72 {
7.73 + NS_LOG_FUNCTION_NOARGS ();
7.74 m_name = name;
7.75 }
7.76
7.77 std::string
7.78 BridgeNetDevice::GetName(void) const
7.79 {
7.80 + NS_LOG_FUNCTION_NOARGS ();
7.81 return m_name;
7.82 }
7.83
7.84 void
7.85 BridgeNetDevice::SetIfIndex(const uint32_t index)
7.86 {
7.87 + NS_LOG_FUNCTION_NOARGS ();
7.88 m_ifIndex = index;
7.89 }
7.90
7.91 uint32_t
7.92 BridgeNetDevice::GetIfIndex(void) const
7.93 {
7.94 + NS_LOG_FUNCTION_NOARGS ();
7.95 return m_ifIndex;
7.96 }
7.97
7.98 Ptr<Channel>
7.99 BridgeNetDevice::GetChannel (void) const
7.100 {
7.101 + NS_LOG_FUNCTION_NOARGS ();
7.102 return m_channel;
7.103 }
7.104
7.105 Address
7.106 BridgeNetDevice::GetAddress (void) const
7.107 {
7.108 + NS_LOG_FUNCTION_NOARGS ();
7.109 return m_address;
7.110 }
7.111
7.112 bool
7.113 BridgeNetDevice::SetMtu (const uint16_t mtu)
7.114 {
7.115 + NS_LOG_FUNCTION_NOARGS ();
7.116 m_mtu = mtu;
7.117 return true;
7.118 }
7.119 @@ -255,6 +283,7 @@
7.120 uint16_t
7.121 BridgeNetDevice::GetMtu (void) const
7.122 {
7.123 + NS_LOG_FUNCTION_NOARGS ();
7.124 return m_mtu;
7.125 }
7.126
7.127 @@ -262,6 +291,7 @@
7.128 bool
7.129 BridgeNetDevice::IsLinkUp (void) const
7.130 {
7.131 + NS_LOG_FUNCTION_NOARGS ();
7.132 return true;
7.133 }
7.134
7.135 @@ -274,6 +304,7 @@
7.136 bool
7.137 BridgeNetDevice::IsBroadcast (void) const
7.138 {
7.139 + NS_LOG_FUNCTION_NOARGS ();
7.140 return true;
7.141 }
7.142
7.143 @@ -281,12 +312,14 @@
7.144 Address
7.145 BridgeNetDevice::GetBroadcast (void) const
7.146 {
7.147 + NS_LOG_FUNCTION_NOARGS ();
7.148 return Mac48Address ("ff:ff:ff:ff:ff:ff");
7.149 }
7.150
7.151 bool
7.152 BridgeNetDevice::IsMulticast (void) const
7.153 {
7.154 + NS_LOG_FUNCTION_NOARGS ();
7.155 return true;
7.156 }
7.157
7.158 @@ -302,13 +335,22 @@
7.159 bool
7.160 BridgeNetDevice::IsPointToPoint (void) const
7.161 {
7.162 + NS_LOG_FUNCTION_NOARGS ();
7.163 return false;
7.164 }
7.165
7.166 +bool
7.167 +BridgeNetDevice::IsBridge (void) const
7.168 +{
7.169 + NS_LOG_FUNCTION_NOARGS ();
7.170 + return true;
7.171 +}
7.172 +
7.173
7.174 bool
7.175 BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
7.176 {
7.177 + NS_LOG_FUNCTION_NOARGS ();
7.178 for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
7.179 iter != m_ports.end (); iter++)
7.180 {
7.181 @@ -322,6 +364,7 @@
7.182 bool
7.183 BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
7.184 {
7.185 + NS_LOG_FUNCTION_NOARGS ();
7.186 for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
7.187 iter != m_ports.end (); iter++)
7.188 {
7.189 @@ -336,6 +379,7 @@
7.190 Ptr<Node>
7.191 BridgeNetDevice::GetNode (void) const
7.192 {
7.193 + NS_LOG_FUNCTION_NOARGS ();
7.194 return m_node;
7.195 }
7.196
7.197 @@ -343,6 +387,7 @@
7.198 void
7.199 BridgeNetDevice::SetNode (Ptr<Node> node)
7.200 {
7.201 + NS_LOG_FUNCTION_NOARGS ();
7.202 m_node = node;
7.203 }
7.204
7.205 @@ -350,6 +395,7 @@
7.206 bool
7.207 BridgeNetDevice::NeedsArp (void) const
7.208 {
7.209 + NS_LOG_FUNCTION_NOARGS ();
7.210 return true;
7.211 }
7.212
7.213 @@ -357,25 +403,28 @@
7.214 void
7.215 BridgeNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
7.216 {
7.217 + NS_LOG_FUNCTION_NOARGS ();
7.218 m_rxCallback = cb;
7.219 }
7.220
7.221 void
7.222 BridgeNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
7.223 {
7.224 + NS_LOG_FUNCTION_NOARGS ();
7.225 m_promiscRxCallback = cb;
7.226 }
7.227
7.228 bool
7.229 BridgeNetDevice::SupportsSendFrom () const
7.230 {
7.231 + NS_LOG_FUNCTION_NOARGS ();
7.232 return true;
7.233 }
7.234
7.235 -
7.236 void
7.237 BridgeNetDevice::DoDispose (void)
7.238 {
7.239 + NS_LOG_FUNCTION_NOARGS ();
7.240 m_node = 0;
7.241 NetDevice::DoDispose ();
7.242 }
8.1 --- a/src/devices/bridge/bridge-net-device.h Fri Nov 28 08:55:24 2008 +0100
8.2 +++ b/src/devices/bridge/bridge-net-device.h Fri Nov 28 08:56:47 2008 +0100
8.3 @@ -82,6 +82,10 @@
8.4 */
8.5 void AddBridgePort (Ptr<NetDevice> bridgePort);
8.6
8.7 + uint32_t GetNBridgePorts (void) const;
8.8 +
8.9 + Ptr<NetDevice> GetBridgePort (uint32_t n) const;
8.10 +
8.11 // inherited from NetDevice base class.
8.12 virtual void SetName(const std::string name);
8.13 virtual std::string GetName(void) const;
8.14 @@ -98,6 +102,7 @@
8.15 virtual bool IsMulticast (void) const;
8.16 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
8.17 virtual bool IsPointToPoint (void) const;
8.18 + virtual bool IsBridge (void) const;
8.19 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
8.20 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
8.21 virtual Ptr<Node> GetNode (void) const;
9.1 --- a/src/devices/csma/csma-net-device.cc Fri Nov 28 08:55:24 2008 +0100
9.2 +++ b/src/devices/csma/csma-net-device.cc Fri Nov 28 08:56:47 2008 +0100
9.3 @@ -837,6 +837,13 @@
9.4 return false;
9.5 }
9.6
9.7 + bool
9.8 +CsmaNetDevice::IsBridge (void) const
9.9 +{
9.10 + NS_LOG_FUNCTION_NOARGS ();
9.11 + return false;
9.12 +}
9.13 +
9.14 bool
9.15 CsmaNetDevice::Send (Ptr<Packet> packet,const Address& dest, uint16_t protocolNumber)
9.16 {
10.1 --- a/src/devices/csma/csma-net-device.h Fri Nov 28 08:55:24 2008 +0100
10.2 +++ b/src/devices/csma/csma-net-device.h Fri Nov 28 08:56:47 2008 +0100
10.3 @@ -351,6 +351,12 @@
10.4 virtual bool IsPointToPoint (void) const;
10.5
10.6 /**
10.7 + * Is this a bridge?
10.8 + * \returns false.
10.9 + */
10.10 + virtual bool IsBridge (void) const;
10.11 +
10.12 + /**
10.13 * Start sending a packet down the channel.
10.14 */
10.15 virtual bool Send (Ptr<Packet> packet, const Address& dest,
11.1 --- a/src/devices/emu/emu-net-device.cc Fri Nov 28 08:55:24 2008 +0100
11.2 +++ b/src/devices/emu/emu-net-device.cc Fri Nov 28 08:56:47 2008 +0100
11.3 @@ -882,6 +882,12 @@
11.4 return false;
11.5 }
11.6
11.7 +bool
11.8 +EmuNetDevice::IsBridge (void) const
11.9 +{
11.10 + return false;
11.11 +}
11.12 +
11.13 void
11.14 EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
11.15 {
12.1 --- a/src/devices/emu/emu-net-device.h Fri Nov 28 08:55:24 2008 +0100
12.2 +++ b/src/devices/emu/emu-net-device.h Fri Nov 28 08:56:47 2008 +0100
12.3 @@ -165,6 +165,12 @@
12.4 */
12.5 virtual bool IsPointToPoint (void) const;
12.6
12.7 + /**
12.8 + * Is this a bridge?
12.9 + * \returns false.
12.10 + */
12.11 + virtual bool IsBridge (void) const;
12.12 +
12.13 virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
12.14
12.15 virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
13.1 --- a/src/devices/point-to-point/point-to-point-net-device.cc Fri Nov 28 08:55:24 2008 +0100
13.2 +++ b/src/devices/point-to-point/point-to-point-net-device.cc Fri Nov 28 08:56:47 2008 +0100
13.3 @@ -392,6 +392,12 @@
13.4 }
13.5
13.6 bool
13.7 +PointToPointNetDevice::IsBridge (void) const
13.8 +{
13.9 + return false;
13.10 +}
13.11 +
13.12 + bool
13.13 PointToPointNetDevice::Send(
13.14 Ptr<Packet> packet,
13.15 const Address &dest,
14.1 --- a/src/devices/point-to-point/point-to-point-net-device.h Fri Nov 28 08:55:24 2008 +0100
14.2 +++ b/src/devices/point-to-point/point-to-point-net-device.h Fri Nov 28 08:56:47 2008 +0100
14.3 @@ -252,6 +252,7 @@
14.4 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
14.5
14.6 virtual bool IsPointToPoint (void) const;
14.7 + virtual bool IsBridge (void) const;
14.8
14.9 virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
14.10 virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
15.1 --- a/src/devices/wifi/wifi-net-device.cc Fri Nov 28 08:55:24 2008 +0100
15.2 +++ b/src/devices/wifi/wifi-net-device.cc Fri Nov 28 08:56:47 2008 +0100
15.3 @@ -238,6 +238,11 @@
15.4 return false;
15.5 }
15.6 bool
15.7 +WifiNetDevice::IsBridge (void) const
15.8 +{
15.9 + return false;
15.10 +}
15.11 +bool
15.12 WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
15.13 {
15.14 NS_ASSERT (Mac48Address::IsMatchingType (dest));
16.1 --- a/src/devices/wifi/wifi-net-device.h Fri Nov 28 08:55:24 2008 +0100
16.2 +++ b/src/devices/wifi/wifi-net-device.h Fri Nov 28 08:56:47 2008 +0100
16.3 @@ -90,6 +90,7 @@
16.4 virtual bool IsMulticast (void) const;
16.5 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
16.6 virtual bool IsPointToPoint (void) const;
16.7 + virtual bool IsBridge (void) const;
16.8 virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
16.9 virtual Ptr<Node> GetNode (void) const;
16.10 virtual void SetNode (Ptr<Node> node);
17.1 --- a/src/helper/bridge-helper.cc Fri Nov 28 08:55:24 2008 +0100
17.2 +++ b/src/helper/bridge-helper.cc Fri Nov 28 08:56:47 2008 +0100
17.3 @@ -1,24 +1,49 @@
17.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
17.5 +/*
17.6 + * Copyright (c)
17.7 + *
17.8 + * This program is free software; you can redistribute it and/or modify
17.9 + * it under the terms of the GNU General Public License version 2 as
17.10 + * published by the Free Software Foundation;
17.11 + *
17.12 + * This program is distributed in the hope that it will be useful,
17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.15 + * GNU General Public License for more details.
17.16 + *
17.17 + * You should have received a copy of the GNU General Public License
17.18 + * along with this program; if not, write to the Free Software
17.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17.20 + */
17.21 +
17.22 #include "bridge-helper.h"
17.23 -
17.24 +#include "ns3/log.h"
17.25 #include "ns3/bridge-net-device.h"
17.26 #include "ns3/node.h"
17.27
17.28 +NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
17.29 +
17.30 namespace ns3 {
17.31
17.32 BridgeHelper::BridgeHelper ()
17.33 {
17.34 + NS_LOG_FUNCTION_NOARGS ();
17.35 m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
17.36 }
17.37
17.38 void
17.39 BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
17.40 {
17.41 + NS_LOG_FUNCTION_NOARGS ();
17.42 m_deviceFactory.Set (n1, v1);
17.43 }
17.44
17.45 NetDeviceContainer
17.46 BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
17.47 {
17.48 + NS_LOG_FUNCTION_NOARGS ();
17.49 + NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
17.50 +
17.51 NetDeviceContainer devs;
17.52 Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
17.53 devs.Add (dev);
17.54 @@ -26,6 +51,7 @@
17.55
17.56 for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
17.57 {
17.58 + NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
17.59 dev->AddBridgePort (*i);
17.60 }
17.61 return devs;
18.1 --- a/src/helper/node-container.cc Fri Nov 28 08:55:24 2008 +0100
18.2 +++ b/src/helper/node-container.cc Fri Nov 28 08:56:47 2008 +0100
18.3 @@ -50,6 +50,17 @@
18.4 Add (d);
18.5 }
18.6
18.7 +NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
18.8 + const NodeContainer &c, const NodeContainer &d,
18.9 + const NodeContainer &e)
18.10 +{
18.11 + Add (a);
18.12 + Add (b);
18.13 + Add (c);
18.14 + Add (d);
18.15 + Add (e);
18.16 +}
18.17 +
18.18 NodeContainer::Iterator
18.19 NodeContainer::Begin (void) const
18.20 {
19.1 --- a/src/helper/node-container.h Fri Nov 28 08:55:24 2008 +0100
19.2 +++ b/src/helper/node-container.h Fri Nov 28 08:56:47 2008 +0100
19.3 @@ -64,6 +64,8 @@
19.4
19.5 NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c);
19.6 NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d);
19.7 + NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d,
19.8 + const NodeContainer &e);
19.9
19.10 /**
19.11 * \returns an iterator to the start of the vector of node pointers.
20.1 --- a/src/node/net-device.h Fri Nov 28 08:55:24 2008 +0100
20.2 +++ b/src/node/net-device.h Fri Nov 28 08:56:47 2008 +0100
20.3 @@ -184,6 +184,15 @@
20.4 virtual Address GetMulticast (Ipv6Address addr) const = 0;
20.5
20.6 /**
20.7 + * \brief Return true if the net device is acting as a bridge.
20.8 + *
20.9 + * \return value of m_isBridge flag
20.10 + */
20.11 + virtual bool IsBridge (void) const = 0;
20.12 +
20.13 + /**
20.14 + * \brief Return true if the net device is on a point-to-point link.
20.15 + *
20.16 * \return value of m_isPointToPoint flag
20.17 */
20.18 virtual bool IsPointToPoint (void) const = 0;
21.1 --- a/src/node/simple-net-device.cc Fri Nov 28 08:55:24 2008 +0100
21.2 +++ b/src/node/simple-net-device.cc Fri Nov 28 08:56:47 2008 +0100
21.3 @@ -163,6 +163,13 @@
21.4 {
21.5 return false;
21.6 }
21.7 +
21.8 +bool
21.9 +SimpleNetDevice::IsBridge (void) const
21.10 +{
21.11 + return false;
21.12 +}
21.13 +
21.14 bool
21.15 SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
21.16 {
22.1 --- a/src/node/simple-net-device.h Fri Nov 28 08:55:24 2008 +0100
22.2 +++ b/src/node/simple-net-device.h Fri Nov 28 08:56:47 2008 +0100
22.3 @@ -61,6 +61,7 @@
22.4 virtual bool IsMulticast (void) const;
22.5 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
22.6 virtual bool IsPointToPoint (void) const;
22.7 + virtual bool IsBridge (void) const;
22.8 virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
22.9 virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
22.10 virtual Ptr<Node> GetNode (void) const;
23.1 --- a/src/routing/global-routing/global-route-manager-impl.cc Fri Nov 28 08:55:24 2008 +0100
23.2 +++ b/src/routing/global-routing/global-route-manager-impl.cc Fri Nov 28 08:56:47 2008 +0100
23.3 @@ -97,7 +97,7 @@
23.4 void
23.5 SPFVertex::SetVertexType (SPFVertex::VertexType type)
23.6 {
23.7 - NS_LOG_FUNCTION_NOARGS ();
23.8 + NS_LOG_FUNCTION (type);
23.9 m_vertexType = type;
23.10 }
23.11
23.12 @@ -111,7 +111,7 @@
23.13 void
23.14 SPFVertex::SetVertexId (Ipv4Address id)
23.15 {
23.16 - NS_LOG_FUNCTION_NOARGS ();
23.17 + NS_LOG_FUNCTION (id);
23.18 m_vertexId = id;
23.19 }
23.20
23.21 @@ -125,7 +125,7 @@
23.22 void
23.23 SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
23.24 {
23.25 - NS_LOG_FUNCTION_NOARGS ();
23.26 + NS_LOG_FUNCTION (lsa);
23.27 m_lsa = lsa;
23.28 }
23.29
23.30 @@ -139,7 +139,7 @@
23.31 void
23.32 SPFVertex::SetDistanceFromRoot (uint32_t distance)
23.33 {
23.34 - NS_LOG_FUNCTION_NOARGS ();
23.35 + NS_LOG_FUNCTION (distance);
23.36 m_distanceFromRoot = distance;
23.37 }
23.38
23.39 @@ -153,7 +153,7 @@
23.40 void
23.41 SPFVertex::SetOutgoingTypeId (uint32_t id)
23.42 {
23.43 - NS_LOG_FUNCTION_NOARGS ();
23.44 + NS_LOG_FUNCTION (id);
23.45 m_rootOif = id;
23.46 }
23.47
23.48 @@ -167,7 +167,7 @@
23.49 void
23.50 SPFVertex::SetNextHop (Ipv4Address nextHop)
23.51 {
23.52 - NS_LOG_FUNCTION_NOARGS ();
23.53 + NS_LOG_FUNCTION (nextHop);
23.54 m_nextHop = nextHop;
23.55 }
23.56
23.57 @@ -181,7 +181,7 @@
23.58 void
23.59 SPFVertex::SetParent (SPFVertex* parent)
23.60 {
23.61 - NS_LOG_FUNCTION_NOARGS ();
23.62 + NS_LOG_FUNCTION (parent);
23.63 m_parent = parent;
23.64 }
23.65
23.66 @@ -202,7 +202,7 @@
23.67 SPFVertex*
23.68 SPFVertex::GetChild (uint32_t n) const
23.69 {
23.70 - NS_LOG_FUNCTION_NOARGS ();
23.71 + NS_LOG_FUNCTION (n);
23.72 uint32_t j = 0;
23.73
23.74 for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
23.75 @@ -214,14 +214,14 @@
23.76 return *i;
23.77 }
23.78 }
23.79 - NS_ASSERT_MSG(false, "Index <n> out of range.");
23.80 + NS_ASSERT_MSG (false, "Index <n> out of range.");
23.81 return 0;
23.82 }
23.83
23.84 uint32_t
23.85 SPFVertex::AddChild (SPFVertex* child)
23.86 {
23.87 - NS_LOG_FUNCTION_NOARGS ();
23.88 + NS_LOG_FUNCTION (child);
23.89 m_children.push_back (child);
23.90 return m_children.size ();
23.91 }
23.92 @@ -268,14 +268,14 @@
23.93 void
23.94 GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
23.95 {
23.96 - NS_LOG_FUNCTION_NOARGS ();
23.97 + NS_LOG_FUNCTION (addr << lsa);
23.98 m_database.insert (LSDBPair_t (addr, lsa));
23.99 }
23.100
23.101 GlobalRoutingLSA*
23.102 GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
23.103 {
23.104 - NS_LOG_FUNCTION_NOARGS ();
23.105 + NS_LOG_FUNCTION (addr);
23.106 //
23.107 // Look up an LSA by its address.
23.108 //
23.109 @@ -293,7 +293,7 @@
23.110 GlobalRoutingLSA*
23.111 GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
23.112 {
23.113 - NS_LOG_FUNCTION_NOARGS ();
23.114 + NS_LOG_FUNCTION (addr);
23.115 //
23.116 // Look up an LSA by its address.
23.117 //
23.118 @@ -341,7 +341,7 @@
23.119 void
23.120 GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
23.121 {
23.122 - NS_LOG_FUNCTION_NOARGS ();
23.123 + NS_LOG_FUNCTION (lsdb);
23.124 if (m_lsdb)
23.125 {
23.126 delete m_lsdb;
23.127 @@ -351,8 +351,7 @@
23.128
23.129 //
23.130 // In order to build the routing database, we need at least one of the nodes
23.131 -// to participate as a router. Eventually we expect to provide a mechanism
23.132 -// for selecting a subset of the nodes to participate; for now, we just make
23.133 +// to participate as a router. This is a convenience function that makes
23.134 // all nodes routers. We do this by walking the list of nodes in the system
23.135 // and aggregating a Global Router Interface to each of the nodes.
23.136 //
23.137 @@ -371,6 +370,21 @@
23.138 }
23.139 }
23.140
23.141 + void
23.142 +GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c)
23.143 +{
23.144 + NS_LOG_FUNCTION (&c);
23.145 + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
23.146 + {
23.147 + Ptr<Node> node = *i;
23.148 + NS_LOG_LOGIC ("Adding GlobalRouter interface to node " <<
23.149 + node->GetId ());
23.150 +
23.151 + Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
23.152 + node->AggregateObject (globalRouter);
23.153 + }
23.154 +}
23.155 +
23.156 //
23.157 // In order to build the routing database, we need to walk the list of nodes
23.158 // in the system and look for those that support the GlobalRouter interface.
23.159 @@ -385,14 +399,14 @@
23.160 {
23.161 NS_LOG_FUNCTION_NOARGS ();
23.162 //
23.163 -// Walk the list of nodes looking for the GlobalRouter Interface.
23.164 +// Walk the list of nodes looking for the GlobalRouter Interface. Nodes with
23.165 +// global router interfaces are, not too surprisingly, our routers.
23.166 //
23.167 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
23.168 {
23.169 Ptr<Node> node = *i;
23.170
23.171 - Ptr<GlobalRouter> rtr =
23.172 - node->GetObject<GlobalRouter> ();
23.173 + Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
23.174 //
23.175 // Ignore nodes that aren't participating in routing.
23.176 //
23.177 @@ -504,7 +518,7 @@
23.178 void
23.179 GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
23.180 {
23.181 - NS_LOG_FUNCTION_NOARGS ();
23.182 + NS_LOG_FUNCTION (v << &candidate);
23.183
23.184 SPFVertex* w = 0;
23.185 GlobalRoutingLSA* w_lsa = 0;
23.186 @@ -706,13 +720,13 @@
23.187 GlobalRoutingLinkRecord* l,
23.188 uint32_t distance)
23.189 {
23.190 - NS_LOG_FUNCTION_NOARGS ();
23.191 + NS_LOG_FUNCTION (v << w << l << distance);
23.192 //
23.193 // If w is a NetworkVertex, l should be null
23.194 /*
23.195 if (w->GetVertexType () == SPFVertex::VertexNetwork && l)
23.196 {
23.197 - NS_ASSERT_MSG(0, "Error: SPFNexthopCalculation parameter problem");
23.198 + NS_ASSERT_MSG (0, "Error: SPFNexthopCalculation parameter problem");
23.199 }
23.200 */
23.201
23.202 @@ -764,7 +778,7 @@
23.203 // return the link record describing the link from <w> to <v>. Think of it as
23.204 // SPFGetLink.
23.205 //
23.206 - NS_ASSERT(l);
23.207 + NS_ASSERT (l);
23.208 GlobalRoutingLinkRecord *linkRemote = 0;
23.209 linkRemote = SPFGetNextLink (w, v, linkRemote);
23.210 //
23.211 @@ -778,7 +792,7 @@
23.212 // from the root node to the host represented by vertex <w>, you have to send
23.213 // the packet to the next hop address specified in w->m_nextHop.
23.214 //
23.215 - w->SetNextHop(linkRemote->GetLinkData ());
23.216 + w->SetNextHop (linkRemote->GetLinkData ());
23.217 //
23.218 // Now find the outgoing interface corresponding to the point to point link
23.219 // from the perspective of <v> -- remember that <l> is the link "from"
23.220 @@ -832,7 +846,7 @@
23.221 * use can then be derived from the next hop IP address (or
23.222 * it can be inherited from the parent network).
23.223 */
23.224 - w->SetNextHop(linkRemote->GetLinkData ());
23.225 + w->SetNextHop (linkRemote->GetLinkData ());
23.226 w->SetOutgoingTypeId (v->GetOutgoingTypeId ());
23.227 NS_LOG_LOGIC ("Next hop from " <<
23.228 v->GetVertexId () << " to " << w->GetVertexId () <<
23.229 @@ -891,7 +905,7 @@
23.230 SPFVertex* w,
23.231 GlobalRoutingLinkRecord* prev_link)
23.232 {
23.233 - NS_LOG_FUNCTION_NOARGS ();
23.234 + NS_LOG_FUNCTION (v << w << prev_link);
23.235
23.236 bool skip = true;
23.237 bool found_prev_link = false;
23.238 @@ -966,7 +980,7 @@
23.239 void
23.240 GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
23.241 {
23.242 - NS_LOG_FUNCTION_NOARGS ();
23.243 + NS_LOG_FUNCTION (root);
23.244 SPFCalculate (root);
23.245 }
23.246
23.247 @@ -987,7 +1001,7 @@
23.248 // of the tree. Initially, this queue is empty.
23.249 //
23.250 CandidateQueue candidate;
23.251 - NS_ASSERT(candidate.Size () == 0);
23.252 + NS_ASSERT (candidate.Size () == 0);
23.253 //
23.254 // Initialize the shortest-path tree to only contain the router doing the
23.255 // calculation. Each router (and corresponding network) is a vertex in the
23.256 @@ -1094,7 +1108,7 @@
23.257 }
23.258 else
23.259 {
23.260 - NS_ASSERT_MSG(0, "illegal SPFVertex type");
23.261 + NS_ASSERT_MSG (0, "illegal SPFVertex type");
23.262 }
23.263 //
23.264 // RFC2328 16.1. (5).
23.265 @@ -1123,7 +1137,7 @@
23.266 uint32_t
23.267 GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask)
23.268 {
23.269 - NS_LOG_FUNCTION_NOARGS ();
23.270 + NS_LOG_FUNCTION (a << amask);
23.271 //
23.272 // We have an IP address <a> and a vertex ID of the root of the SPF tree.
23.273 // The question is what interface index does this address correspond to.
23.274 @@ -1199,7 +1213,7 @@
23.275 void
23.276 GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
23.277 {
23.278 - NS_LOG_FUNCTION_NOARGS ();
23.279 + NS_LOG_FUNCTION (v);
23.280
23.281 NS_ASSERT_MSG (m_spfroot,
23.282 "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
23.283 @@ -1316,7 +1330,7 @@
23.284 void
23.285 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
23.286 {
23.287 - NS_LOG_FUNCTION_NOARGS ();
23.288 + NS_LOG_FUNCTION (v);
23.289
23.290 NS_ASSERT_MSG (m_spfroot,
23.291 "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
23.292 @@ -1409,7 +1423,7 @@
23.293 void
23.294 GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
23.295 {
23.296 - NS_LOG_FUNCTION_NOARGS ();
23.297 + NS_LOG_FUNCTION (v);
23.298 v->GetParent ()->AddChild (v);
23.299 }
23.300
24.1 --- a/src/routing/global-routing/global-route-manager-impl.h Fri Nov 28 08:55:24 2008 +0100
24.2 +++ b/src/routing/global-routing/global-route-manager-impl.h Fri Nov 28 08:56:47 2008 +0100
24.3 @@ -29,6 +29,7 @@
24.4 #include "ns3/object.h"
24.5 #include "ns3/ptr.h"
24.6 #include "ns3/ipv4-address.h"
24.7 +#include "ns3/node-container.h"
24.8 #include "global-router-interface.h"
24.9
24.10 namespace ns3 {
24.11 @@ -708,6 +709,14 @@
24.12 virtual void SelectRouterNodes ();
24.13
24.14 /**
24.15 + * @brief Select which nodes in the system are to be router nodes and
24.16 + * aggregate the appropriate interfaces onto those nodes.
24.17 + * @internal
24.18 + *
24.19 + */
24.20 + virtual void SelectRouterNodes (NodeContainer c);
24.21 +
24.22 +/**
24.23 * @brief Build the routing database by gathering Link State Advertisements
24.24 * from each node exporting a GlobalRouter interface.
24.25 * @internal
25.1 --- a/src/routing/global-routing/global-route-manager.cc Fri Nov 28 08:55:24 2008 +0100
25.2 +++ b/src/routing/global-routing/global-route-manager.cc Fri Nov 28 08:56:47 2008 +0100
25.3 @@ -21,6 +21,7 @@
25.4 #include "ns3/assert.h"
25.5 #include "ns3/log.h"
25.6 #include "ns3/simulation-singleton.h"
25.7 +#include "ns3/node-container.h"
25.8 #include "global-route-manager.h"
25.9 #include "global-route-manager-impl.h"
25.10
25.11 @@ -33,7 +34,7 @@
25.12 // ---------------------------------------------------------------------------
25.13
25.14 void
25.15 -GlobalRouteManager::PopulateRoutingTables ()
25.16 +GlobalRouteManager::PopulateRoutingTables (void)
25.17 {
25.18 SelectRouterNodes ();
25.19 BuildGlobalRoutingDatabase ();
25.20 @@ -41,28 +42,43 @@
25.21 }
25.22
25.23 void
25.24 -GlobalRouteManager::SelectRouterNodes ()
25.25 +GlobalRouteManager::PopulateRoutingTables (NodeContainer c)
25.26 +{
25.27 + SelectRouterNodes (c);
25.28 + BuildGlobalRoutingDatabase ();
25.29 + InitializeRoutes ();
25.30 +}
25.31 +
25.32 + void
25.33 +GlobalRouteManager::SelectRouterNodes (void)
25.34 {
25.35 SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
25.36 SelectRouterNodes ();
25.37 }
25.38
25.39 void
25.40 -GlobalRouteManager::BuildGlobalRoutingDatabase ()
25.41 +GlobalRouteManager::SelectRouterNodes (NodeContainer c)
25.42 +{
25.43 + SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
25.44 + SelectRouterNodes (c);
25.45 +}
25.46 +
25.47 + void
25.48 +GlobalRouteManager::BuildGlobalRoutingDatabase (void)
25.49 {
25.50 SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
25.51 BuildGlobalRoutingDatabase ();
25.52 }
25.53
25.54 void
25.55 -GlobalRouteManager::InitializeRoutes ()
25.56 +GlobalRouteManager::InitializeRoutes (void)
25.57 {
25.58 SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
25.59 InitializeRoutes ();
25.60 }
25.61
25.62 uint32_t
25.63 -GlobalRouteManager::AllocateRouterId ()
25.64 +GlobalRouteManager::AllocateRouterId (void)
25.65 {
25.66 static uint32_t routerId = 0;
25.67 return routerId++;
26.1 --- a/src/routing/global-routing/global-route-manager.h Fri Nov 28 08:55:24 2008 +0100
26.2 +++ b/src/routing/global-routing/global-route-manager.h Fri Nov 28 08:56:47 2008 +0100
26.3 @@ -22,6 +22,8 @@
26.4 #ifndef GLOBAL_ROUTE_MANAGER_H
26.5 #define GLOBAL_ROUTE_MANAGER_H
26.6
26.7 +#include "ns3/node-container.h"
26.8 +
26.9 namespace ns3 {
26.10
26.11 /**
26.12 @@ -40,7 +42,8 @@
26.13 public:
26.14 /**
26.15 * @brief Build a routing database and initialize the routing tables of
26.16 - * the nodes in the simulation.
26.17 + * the nodes in the simulation. Makes all nodes in the simulation into
26.18 + * routers.
26.19 *
26.20 * All this function does is call BuildGlobalRoutingDatabase () and
26.21 * InitializeRoutes ().
26.22 @@ -51,6 +54,19 @@
26.23 static void PopulateRoutingTables ();
26.24
26.25 /**
26.26 + * @brief Build a routing database and initialize the routing tables of
26.27 + * the nodes in the simulation. Makes the nodes in the provided container
26.28 + * into routers.
26.29 + *
26.30 + * All this function does is call BuildGlobalRoutingDatabase () and
26.31 + * InitializeRoutes ().
26.32 + *
26.33 + * @see BuildGlobalRoutingDatabase ();
26.34 + * @see InitializeRoutes ();
26.35 + */
26.36 + static void PopulateRoutingTables (NodeContainer c);
26.37 +
26.38 +/**
26.39 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
26.40 */
26.41 static uint32_t AllocateRouterId ();
26.42 @@ -65,6 +81,14 @@
26.43 static void SelectRouterNodes ();
26.44
26.45 /**
26.46 + * @brief Select which nodes in the system are to be router nodes and
26.47 + * aggregate the appropriate interfaces onto those nodes.
26.48 + * @internal
26.49 + *
26.50 + */
26.51 + static void SelectRouterNodes (NodeContainer c);
26.52 +
26.53 +/**
26.54 * @brief Build the routing database by gathering Link State Advertisements
26.55 * from each node exporting a GlobalRouter interface.
26.56 * @internal
27.1 --- a/src/routing/global-routing/global-router-interface.cc Fri Nov 28 08:55:24 2008 +0100
27.2 +++ b/src/routing/global-routing/global-router-interface.cc Fri Nov 28 08:56:47 2008 +0100
27.3 @@ -20,11 +20,15 @@
27.4
27.5 #include "ns3/log.h"
27.6 #include "ns3/assert.h"
27.7 +#include "ns3/abort.h"
27.8 #include "ns3/channel.h"
27.9 #include "ns3/net-device.h"
27.10 #include "ns3/node.h"
27.11 #include "ns3/ipv4.h"
27.12 +#include "ns3/bridge-net-device.h"
27.13 +#include "ns3/net-device-container.h"
27.14 #include "global-router-interface.h"
27.15 +#include <vector>
27.16
27.17 NS_LOG_COMPONENT_DEFINE ("GlobalRouter");
27.18
27.19 @@ -365,8 +369,7 @@
27.20 return *i;
27.21 }
27.22 }
27.23 - NS_ASSERT_MSG(false,
27.24 - "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
27.25 + NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
27.26 return Ipv4Address("0.0.0.0");
27.27 }
27.28
27.29 @@ -380,9 +383,25 @@
27.30 void
27.31 GlobalRoutingLSA::Print (std::ostream &os) const
27.32 {
27.33 - os << "m_lsType = " << m_lsType << std::endl <<
27.34 - "m_linkStateId = " << m_linkStateId << std::endl <<
27.35 - "m_advertisingRtr = " << m_advertisingRtr << std::endl;
27.36 + os << std::endl;
27.37 + os << "========== Global Routing LSA ==========" << std::endl;
27.38 + os << "m_lsType = " << m_lsType;
27.39 + if (m_lsType == GlobalRoutingLSA::RouterLSA)
27.40 + {
27.41 + os << " (GlobalRoutingLSA::RouterLSA)";
27.42 + }
27.43 + else if (m_lsType == GlobalRoutingLSA::NetworkLSA)
27.44 + {
27.45 + os << " (GlobalRoutingLSA::NetworkLSA)";
27.46 + }
27.47 + else
27.48 + {
27.49 + os << "(Unknown LSType)";
27.50 + }
27.51 + os << std::endl;
27.52 +
27.53 + os << "m_linkStateId = " << m_linkStateId << " (Router ID)" << std::endl;
27.54 + os << "m_advertisingRtr = " << m_advertisingRtr << " (Router ID)" << std::endl;
27.55
27.56 if (m_lsType == GlobalRoutingLSA::RouterLSA)
27.57 {
27.58 @@ -391,30 +410,49 @@
27.59 i++)
27.60 {
27.61 GlobalRoutingLinkRecord *p = *i;
27.62 - os << "----------" << std::endl;
27.63 - os << "m_linkId = " << p->GetLinkId () << std::endl;
27.64 - os << "m_linkData = " << p->GetLinkData () << std::endl;
27.65 - os << "m_metric = " << p->GetMetric () << std::endl;
27.66 +
27.67 + os << "---------- RouterLSA Link Record ----------" << std::endl;
27.68 + os << "m_linkType = " << p->m_linkType;
27.69 + if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork)
27.70 + {
27.71 + os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
27.72 + os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl;
27.73 + os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl;
27.74 + os << "m_metric = " << p->m_metric << std::endl;
27.75 + }
27.76 + else if (p->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
27.77 + {
27.78 + os << "(GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
27.79 + os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl;
27.80 + os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl;
27.81 + os << "m_metric = " << p->m_metric << std::endl;
27.82 + }
27.83 + else
27.84 + {
27.85 + os << "(Unknown LinkType)" << std::endl;
27.86 + os << "m_linkId = " << p->m_linkId << std::endl;
27.87 + os << "m_linkData = " << p->m_linkData << std::endl;
27.88 + os << "m_metric = " << p->m_metric << std::endl;
27.89 + }
27.90 + os << "---------- End RouterLSA Link Record ----------" << std::endl;
27.91 }
27.92 }
27.93 else if (m_lsType == GlobalRoutingLSA::NetworkLSA)
27.94 {
27.95 - os << "----------" << std::endl;
27.96 - os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask
27.97 - << std::endl;
27.98 - for ( ListOfAttachedRouters_t::const_iterator i =
27.99 - m_attachedRouters.begin ();
27.100 - i != m_attachedRouters.end ();
27.101 - i++)
27.102 + os << "---------- NetworkLSA Link Record ----------" << std::endl;
27.103 + os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl;
27.104 + for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); i != m_attachedRouters.end (); i++)
27.105 {
27.106 Ipv4Address p = *i;
27.107 os << "attachedRouter = " << p << std::endl;
27.108 }
27.109 + os << "---------- End NetworkLSA Link Record ----------" << std::endl;
27.110 }
27.111 else
27.112 {
27.113 NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
27.114 }
27.115 + os << "========== End Global Routing LSA ==========" << std::endl;
27.116 }
27.117
27.118 std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa)
27.119 @@ -487,53 +525,79 @@
27.120 }
27.121
27.122 //
27.123 -// Go out and discover any adjacent routers and build the Link State
27.124 -// Advertisements that reflect them and their associated networks.
27.125 +// DiscoverLSAs is called on all nodes in the system that have a GlobalRouter
27.126 +// interface aggregated. We need to go out and discover any adjacent routers
27.127 +// and build the Link State Advertisements that reflect them and their associated
27.128 +// networks.
27.129 //
27.130 uint32_t
27.131 GlobalRouter::DiscoverLSAs (void)
27.132 {
27.133 NS_LOG_FUNCTION_NOARGS ();
27.134 Ptr<Node> node = GetObject<Node> ();
27.135 - NS_LOG_LOGIC("For node " << node->GetId () );
27.136 - NS_ASSERT_MSG(node,
27.137 - "GlobalRouter::DiscoverLSAs (): <Node> interface not set");
27.138 + NS_ABORT_MSG_UNLESS (node, "GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
27.139 + NS_LOG_LOGIC ("For node " << node->GetId () );
27.140
27.141 ClearLSAs ();
27.142
27.143 -// While building the router-LSA, keep a list of those NetDevices for
27.144 -// which I am the designated router and need to later build a NetworkLSA
27.145 - std::list<Ptr<NetDevice> > listOfDRInterfaces;
27.146 + //
27.147 + // While building the Router-LSA, keep a list of those NetDevices for
27.148 + // which the current node is the designated router and we will later build
27.149 + // a NetworkLSA for.
27.150 + //
27.151 + NetDeviceContainer c;
27.152
27.153 -//
27.154 -// We're aggregated to a node. We need to ask the node for a pointer to its
27.155 -// Ipv4 interface. This is where the information regarding the attached
27.156 -// interfaces lives.
27.157 -//
27.158 + //
27.159 + // We're aggregated to a node. We need to ask the node for a pointer to its
27.160 + // Ipv4 interface. This is where the information regarding the attached
27.161 + // interfaces lives. If we're a router, we had better have an Ipv4 interface.
27.162 + //
27.163 Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
27.164 - NS_ASSERT_MSG(ipv4Local,
27.165 - "GlobalRouter::DiscoverLSAs (): QI for <Ipv4> interface failed");
27.166 -//
27.167 -// Each node originates a Router-LSA
27.168 -//
27.169 + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
27.170 +
27.171 + //
27.172 + // Every router node originates a Router-LSA
27.173 + //
27.174 GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
27.175 pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
27.176 pLSA->SetLinkStateId (m_routerId);
27.177 pLSA->SetAdvertisingRouter (m_routerId);
27.178 pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
27.179 -//
27.180 -// We need to ask the node for the number of net devices attached. This isn't
27.181 -// necessarily equal to the number of links to adjacent nodes (other routers)
27.182 -// as the number of devices may include those for stub networks (e.g.,
27.183 -// ethernets, etc.).
27.184 -//
27.185 +
27.186 + //
27.187 + // Ask the node for the number of net devices attached. This isn't necessarily
27.188 + // equal to the number of links to adjacent nodes (other routers) as the number
27.189 + // of devices may include those for stub networks (e.g., ethernets, etc.) and
27.190 + // bridge devices also take up an "extra" net device.
27.191 + //
27.192 uint32_t numDevices = node->GetNDevices();
27.193 - NS_LOG_LOGIC ("numDevices = " << numDevices);
27.194 +
27.195 + //
27.196 + // Iterate through the devices on the node and walk the channel to see what's
27.197 + // on the other side of the standalone devices..
27.198 + //
27.199 for (uint32_t i = 0; i < numDevices; ++i)
27.200 {
27.201 Ptr<NetDevice> ndLocal = node->GetDevice(i);
27.202
27.203 - // Check if it is an IP interface (could be a pure L2 NetDevice)
27.204 + //
27.205 + // There is an assumption that bridge ports must never have an IP address
27.206 + // associated with them. This turns out to be a very convenient place to
27.207 + // check and make sure that this is the case.
27.208 + //
27.209 + if (NetDeviceIsBridged (ndLocal))
27.210 + {
27.211 + uint32_t ifIndexBridge;
27.212 + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexBridge);
27.213 + NS_ABORT_MSG_IF (rc, "GlobalRouter::DiscoverLSAs(): Bridge ports must not have an IPv4 interface index");
27.214 + }
27.215 +
27.216 + //
27.217 + // Check to see if the net device we just got has a corresponding IP
27.218 + // interface (could be a pure L2 NetDevice) -- for example a net device
27.219 + // associated with a bridge. We are only going to involve devices with
27.220 + // IP addresses in routing.
27.221 + //
27.222 bool isIp = false;
27.223 for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
27.224 {
27.225 @@ -543,240 +607,723 @@
27.226 break;
27.227 }
27.228 }
27.229 +
27.230 if (!isIp)
27.231 {
27.232 + NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface, skipping");
27.233 continue;
27.234 }
27.235
27.236 + //
27.237 + // We have a net device that we need to check out. If it suports
27.238 + // broadcast and is not a point-point link, then it will be either a stub
27.239 + // network or a transit network depending on the number of routers on
27.240 + // the segment. We add the appropriate link record to the LSA.
27.241 + //
27.242 + // If the device is a point to point link, we treat it separately. In
27.243 + // that case, there always two link records added.
27.244 + //
27.245 if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
27.246 {
27.247 NS_LOG_LOGIC ("Broadcast link");
27.248 - GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
27.249 -//
27.250 -// We need to determine whether we are on a transit or stub network
27.251 -// If we find at least one more router on this channel, we are a transit
27.252 -//
27.253 -//
27.254 -// Now, we have to find the Ipv4 interface whose netdevice is the one we
27.255 -// just found. This is still the IP on the local side of the channel. There
27.256 -// is a function to do this used down in the guts of the stack, but it's not
27.257 -// exported so we had to whip up an equivalent.
27.258 -//
27.259 - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
27.260 - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.261 - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.262 - NS_LOG_LOGIC ("Working with local address " << addrLocal);
27.263 - uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
27.264 -//
27.265 -// Now, we're going to walk over to the remote net device on the other end of
27.266 -// the point-to-point channel we now know we have. This is where our adjacent
27.267 -// router (to use OSPF lingo) is running.
27.268 -//
27.269 - Ptr<Channel> ch = ndLocal->GetChannel();
27.270 - uint32_t nDevices = ch->GetNDevices();
27.271 - if (nDevices == 1)
27.272 - {
27.273 - // This is a stub broadcast interface
27.274 - NS_LOG_LOGIC("Router-LSA stub broadcast link");
27.275 - // XXX in future, need to consider if >1 includes other routers
27.276 - plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
27.277 - // Link ID is IP network number of attached network
27.278 - plr->SetLinkId (addrLocal.CombineMask(maskLocal));
27.279 - // Link Data is network mask; convert to Ipv4Address
27.280 - Ipv4Address maskLocalAddr;
27.281 - maskLocalAddr.Set(maskLocal.Get ());
27.282 - plr->SetLinkData (maskLocalAddr);
27.283 - plr->SetMetric (metricLocal);
27.284 - pLSA->AddLinkRecord(plr);
27.285 - plr = 0;
27.286 - continue;
27.287 - }
27.288 - else
27.289 - {
27.290 - NS_LOG_LOGIC ("Router-LSA Broadcast link");
27.291 - // multiple routers on a broadcast interface
27.292 - // lowest IP address is designated router
27.293 - plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
27.294 - // Link ID is IP interface address of designated router
27.295 - Ipv4Address desigRtr =
27.296 - FindDesignatedRouterForLink (node, ndLocal);
27.297 - if (desigRtr == addrLocal)
27.298 - {
27.299 - listOfDRInterfaces.push_back (ndLocal);
27.300 - NS_LOG_LOGIC (node->GetId () << " is a DR");
27.301 - }
27.302 - plr->SetLinkId (desigRtr);
27.303 - // Link Data is router's own IP address
27.304 - plr->SetLinkData (addrLocal);
27.305 - plr->SetMetric (metricLocal);
27.306 - pLSA->AddLinkRecord (plr);
27.307 - plr = 0;
27.308 - continue;
27.309 - }
27.310 + ProcessBroadcastLink (ndLocal, pLSA, c);
27.311 }
27.312 else if (ndLocal->IsPointToPoint () )
27.313 {
27.314 - NS_LOG_LOGIC ("Router-LSA Point-to-point device");
27.315 -//
27.316 -// Now, we have to find the Ipv4 interface whose netdevice is the one we
27.317 -// just found. This is still the IP on the local side of the channel. There
27.318 -// is a function to do this used down in the guts of the stack, but it's not
27.319 -// exported so we had to whip up an equivalent.
27.320 -//
27.321 - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
27.322 -//
27.323 -// Now that we have the Ipv4 interface index, we can get the address and mask
27.324 -// we need.
27.325 -//
27.326 - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.327 - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.328 - NS_LOG_LOGIC ("Working with local address " << addrLocal);
27.329 - uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
27.330 -//
27.331 -// Now, we're going to walk over to the remote net device on the other end of
27.332 -// the point-to-point channel we now know we have. This is where our adjacent
27.333 -// router (to use OSPF lingo) is running.
27.334 -//
27.335 - Ptr<Channel> ch = ndLocal->GetChannel();
27.336 - if (ch == NULL)
27.337 - {
27.338 - continue;
27.339 - }
27.340 - Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
27.341 -//
27.342 -// The adjacent net device is aggregated to a node. We need to ask that net
27.343 -// device for its node, then ask that node for its Ipv4 interface.
27.344 -//
27.345 - Ptr<Node> nodeRemote = ndRemote->GetNode();
27.346 - Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
27.347 - NS_ASSERT_MSG(ipv4Remote,
27.348 - "GlobalRouter::DiscoverLSAs (): QI for remote <Ipv4> failed");
27.349 -//
27.350 -// Per the OSPF spec, we're going to need the remote router ID, so we might as
27.351 -// well get it now.
27.352 -//
27.353 - Ptr<GlobalRouter> srRemote =
27.354 - nodeRemote->GetObject<GlobalRouter> ();
27.355 - NS_ASSERT_MSG(srRemote,
27.356 - "GlobalRouter::DiscoverLSAs():QI for remote <GlobalRouter> failed");
27.357 - Ipv4Address rtrIdRemote = srRemote->GetRouterId();
27.358 - NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
27.359 -//
27.360 -// Now, just like we did above, we need to get the IP interface index for the
27.361 -// net device on the other end of the point-to-point channel.
27.362 -//
27.363 - uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote);
27.364 -//
27.365 -// Now that we have the Ipv4 interface, we can get the (remote) address and
27.366 -// mask we need.
27.367 -//
27.368 - Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
27.369 - Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
27.370 - NS_LOG_LOGIC ("Working with remote address " << addrRemote);
27.371 -//
27.372 -// Now we can fill out the link records for this link. There are always two
27.373 -// link records; the first is a point-to-point record describing the link and
27.374 -// the second is a stub network record with the network number.
27.375 -//
27.376 - GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
27.377 - plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
27.378 - plr->SetLinkId (rtrIdRemote);
27.379 - plr->SetLinkData (addrLocal);
27.380 - plr->SetMetric (metricLocal);
27.381 - pLSA->AddLinkRecord (plr);
27.382 - plr = 0;
27.383 -
27.384 - plr = new GlobalRoutingLinkRecord;
27.385 - plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
27.386 - plr->SetLinkId (addrRemote);
27.387 - plr->SetLinkData (Ipv4Address(maskRemote.Get())); // Frown
27.388 - plr->SetMetric (metricLocal);
27.389 - pLSA->AddLinkRecord (plr);
27.390 - plr = 0;
27.391 + NS_LOG_LOGIC ("Point=to-point link");
27.392 + ProcessPointToPointLink (ndLocal, pLSA);
27.393 }
27.394 else
27.395 {
27.396 NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
27.397 }
27.398 + }
27.399
27.400 + NS_LOG_LOGIC ("========== LSA for node " << node->GetId () << " ==========");
27.401 + NS_LOG_LOGIC (*pLSA);
27.402 + m_LSAs.push_back (pLSA);
27.403 + pLSA = 0;
27.404 +
27.405 + //
27.406 + // Now, determine whether we need to build a NetworkLSA. This is the case if
27.407 + // we found at least one designated router.
27.408 + //
27.409 + uint32_t nDesignatedRouters = c.GetN ();
27.410 + if (nDesignatedRouters > 0)
27.411 + {
27.412 + NS_LOG_LOGIC ("Build Network LSAs");
27.413 + BuildNetworkLSAs (c);
27.414 }
27.415 -//
27.416 -// The LSA goes on a list of LSAs in case we want to begin exporting other
27.417 -// kinds of advertisements (than Router LSAs).
27.418 - m_LSAs.push_back (pLSA);
27.419 - NS_LOG_LOGIC (*pLSA);
27.420
27.421 -// Now, determine whether we need to build a NetworkLSA
27.422 - if (listOfDRInterfaces.size () > 0)
27.423 + return m_LSAs.size ();
27.424 +}
27.425 +
27.426 + void
27.427 +GlobalRouter::ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
27.428 +{
27.429 + NS_LOG_FUNCTION (nd << pLSA << &c);
27.430 +
27.431 + if (nd->IsBridge ())
27.432 {
27.433 - for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
27.434 - i != listOfDRInterfaces.end (); i++)
27.435 + ProcessBridgedBroadcastLink (nd, pLSA, c);
27.436 + }
27.437 + else
27.438 + {
27.439 + ProcessSingleBroadcastLink (nd, pLSA, c);
27.440 + }
27.441 +}
27.442 +
27.443 + void
27.444 +GlobalRouter::ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
27.445 +{
27.446 + NS_LOG_FUNCTION (nd << pLSA << &c);
27.447 +
27.448 + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
27.449 + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
27.450 +
27.451 + //
27.452 + // We have some preliminaries to do to get enough information to proceed.
27.453 + // This information we need comes from the internet stack, so notice that
27.454 + // there is an implied assumption that global routing is only going to
27.455 + // work with devices attached to the internet stack (have an ipv4 interface
27.456 + // associated to them.
27.457 + //
27.458 + Ptr<Node> node = nd->GetNode ();
27.459 +
27.460 + uint32_t ifIndexLocal;
27.461 + bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
27.462 + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
27.463 +
27.464 + Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
27.465 + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
27.466 +
27.467 + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.468 + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.469 + NS_LOG_LOGIC ("Working with local address " << addrLocal);
27.470 + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
27.471 +
27.472 + //
27.473 + // Check to see if the net device is connected to a channel/network that has
27.474 + // another router on it. If there is no other router on the link (but us) then
27.475 + // this is a stub network. If we find another router, then what we have here
27.476 + // is a transit network.
27.477 + //
27.478 + if (AnotherRouterOnLink (nd, true) == false)
27.479 + {
27.480 + //
27.481 + // This is a net device connected to a stub network
27.482 + //
27.483 + NS_LOG_LOGIC("Router-LSA Stub Network");
27.484 + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
27.485 +
27.486 + //
27.487 + // According to OSPF, the Link ID is the IP network number of
27.488 + // the attached network.
27.489 + //
27.490 + plr->SetLinkId (addrLocal.CombineMask(maskLocal));
27.491 +
27.492 + //
27.493 + // and the Link Data is the network mask; converted to Ipv4Address
27.494 + //
27.495 + Ipv4Address maskLocalAddr;
27.496 + maskLocalAddr.Set(maskLocal.Get ());
27.497 + plr->SetLinkData (maskLocalAddr);
27.498 + plr->SetMetric (metricLocal);
27.499 + pLSA->AddLinkRecord(plr);
27.500 + plr = 0;
27.501 + }
27.502 + else
27.503 + {
27.504 + //
27.505 + // We have multiple routers on a broadcast interface, so this is
27.506 + // a transit network.
27.507 + //
27.508 + NS_LOG_LOGIC ("Router-LSA Transit Network");
27.509 + plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
27.510 +
27.511 + //
27.512 + // By definition, the router with the lowest IP address is the
27.513 + // designated router for the network. OSPF says that the Link ID
27.514 + // gets the IP interface address of the designated router in this
27.515 + // case.
27.516 + //
27.517 + Ipv4Address desigRtr = FindDesignatedRouterForLink (nd, true);
27.518 +
27.519 + //
27.520 + // Let's double-check that any designated router we find out on our
27.521 + // network is really on our network.
27.522 + //
27.523 + if (desigRtr != "255.255.255.255")
27.524 {
27.525 -// Build one NetworkLSA for each interface that is a DR
27.526 - Ptr<NetDevice> ndLocal = *i;
27.527 - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
27.528 - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.529 - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.530 + Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
27.531 + Ipv4Address networkThere = desigRtr.CombineMask (maskLocal);
27.532 + NS_ABORT_MSG_UNLESS (networkHere == networkThere,
27.533 + "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
27.534 + }
27.535 + if (desigRtr == addrLocal)
27.536 + {
27.537 + c.Add (nd);
27.538 + NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
27.539 + }
27.540 + plr->SetLinkId (desigRtr);
27.541 +
27.542 + //
27.543 + // OSPF says that the Link Data is this router's own IP address.
27.544 + //
27.545 + plr->SetLinkData (addrLocal);
27.546 + plr->SetMetric (metricLocal);
27.547 + pLSA->AddLinkRecord (plr);
27.548 + plr = 0;
27.549 + }
27.550 +}
27.551
27.552 - GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
27.553 - pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA);
27.554 - pLSA->SetLinkStateId (addrLocal);
27.555 - pLSA->SetAdvertisingRouter (m_routerId);
27.556 - pLSA->SetNetworkLSANetworkMask (maskLocal);
27.557 - pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
27.558 -// Build list of AttachedRouters
27.559 - Ptr<Channel> ch = ndLocal->GetChannel();
27.560 - uint32_t nDevices = ch->GetNDevices();
27.561 - NS_ASSERT (nDevices);
27.562 - for (uint32_t i = 0; i < nDevices; i++)
27.563 + void
27.564 +GlobalRouter::ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
27.565 +{
27.566 + NS_LOG_FUNCTION (nd << pLSA << &c);
27.567 + NS_ASSERT_MSG (nd->IsBridge (), "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
27.568 +
27.569 +#if 0
27.570 + //
27.571 + // It is possible to admit the possibility that a bridge device on a node
27.572 + // can also participate in routing. This would surprise people who don't
27.573 + // come from Microsoft-land where they do use such a construct. Based on
27.574 + // the principle of least-surprise, we will leave the relatively simple
27.575 + // code in place to do this, but not enable it until someone really wants
27.576 + // the capability. Even then, we will not enable this code as a default
27.577 + // but rather something you will have to go and turn on.
27.578 + //
27.579 +
27.580 + Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
27.581 + NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
27.582 +
27.583 + //
27.584 + // We have some preliminaries to do to get enough information to proceed.
27.585 + // This information we need comes from the internet stack, so notice that
27.586 + // there is an implied assumption that global routing is only going to
27.587 + // work with devices attached to the internet stack (have an ipv4 interface
27.588 + // associated to them.
27.589 + //
27.590 + Ptr<Node> node = nd->GetNode ();
27.591 +
27.592 + uint32_t ifIndexLocal;
27.593 + bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
27.594 + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
27.595 +
27.596 + Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
27.597 + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
27.598 +
27.599 + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.600 + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.601 + NS_LOG_LOGIC ("Working with local address " << addrLocal);
27.602 + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
27.603 +
27.604 + //
27.605 + // We need to handle a bridge on the router. This means that we have been
27.606 + // given a net device that is a BridgeNetDevice. It has an associated Ipv4
27.607 + // interface index and address. Some number of other net devices live "under"
27.608 + // the bridge device as so-called bridge ports. In a nutshell, what we have
27.609 + // to do is to repeat what is done for a single broadcast link on all of
27.610 + // those net devices living under the bridge (trolls?)
27.611 + //
27.612 +
27.613 + bool areTransitNetwork = false;
27.614 + Ipv4Address desigRtr ("255.255.255.255");
27.615 +
27.616 + for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
27.617 + {
27.618 + Ptr<NetDevice> ndTemp = bnd->GetBridgePort (i);
27.619 +
27.620 + //
27.621 + // We have to decide if we are a transit network. This is characterized
27.622 + // by the presence of another router on the network segment. If we find
27.623 + // another router on any of our bridged links, we are a transit network.
27.624 + //
27.625 + if (AnotherRouterOnLink (ndTemp, true))
27.626 + {
27.627 + areTransitNetwork = true;
27.628 +
27.629 + //
27.630 + // If we're going to be a transit network, then we have got to elect
27.631 + // a designated router for the whole bridge. This means finding the
27.632 + // router with the lowest IP address on the whole bridge. We ask
27.633 + // for the lowest address on each segment and pick the lowest of them
27.634 + // all.
27.635 + //
27.636 + Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp, true);
27.637 +
27.638 + //
27.639 + // Let's double-check that any designated router we find out on our
27.640 + // network is really on our network.
27.641 + //
27.642 + if (desigRtrTemp != "255.255.255.255")
27.643 {
27.644 - Ptr<NetDevice> tempNd = ch->GetDevice (i);
27.645 - NS_ASSERT (tempNd);
27.646 - Ptr<Node> tempNode = tempNd->GetNode ();
27.647 - uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd);
27.648 + Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
27.649 + Ipv4Address networkThere = desigRtrTemp.CombineMask (maskLocal);
27.650 + NS_ABORT_MSG_UNLESS (networkHere == networkThere,
27.651 + "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
27.652 + }
27.653 + if (desigRtrTemp < desigRtr)
27.654 + {
27.655 + desigRtr = desigRtrTemp;
27.656 + }
27.657 + }
27.658 + }
27.659 + //
27.660 + // That's all the information we need to put it all together, just like we did
27.661 + // in the case of a single broadcast link.
27.662 + //
27.663 +
27.664 + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
27.665 + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
27.666 +
27.667 + if (areTransitNetwork == false)
27.668 + {
27.669 + //
27.670 + // This is a net device connected to a bridge of stub networks
27.671 + //
27.672 + NS_LOG_LOGIC("Router-LSA Stub Network");
27.673 + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
27.674 +
27.675 + //
27.676 + // According to OSPF, the Link ID is the IP network number of
27.677 + // the attached network.
27.678 + //
27.679 + plr->SetLinkId (addrLocal.CombineMask(maskLocal));
27.680 +
27.681 + //
27.682 + // and the Link Data is the network mask; converted to Ipv4Address
27.683 + //
27.684 + Ipv4Address maskLocalAddr;
27.685 + maskLocalAddr.Set(maskLocal.Get ());
27.686 + plr->SetLinkData (maskLocalAddr);
27.687 + plr->SetMetric (metricLocal);
27.688 + pLSA->AddLinkRecord(plr);
27.689 + plr = 0;
27.690 + }
27.691 + else
27.692 + {
27.693 + //
27.694 + // We have multiple routers on a bridged broadcast interface, so this is
27.695 + // a transit network.
27.696 + //
27.697 + NS_LOG_LOGIC ("Router-LSA Transit Network");
27.698 + plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
27.699 +
27.700 + //
27.701 + // By definition, the router with the lowest IP address is the
27.702 + // designated router for the network. OSPF says that the Link ID
27.703 + // gets the IP interface address of the designated router in this
27.704 + // case.
27.705 + //
27.706 + if (desigRtr == addrLocal)
27.707 + {
27.708 + c.Add (nd);
27.709 + NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
27.710 + }
27.711 + plr->SetLinkId (desigRtr);
27.712 +
27.713 + //
27.714 + // OSPF says that the Link Data is this router's own IP address.
27.715 + //
27.716 + plr->SetLinkData (addrLocal);
27.717 + plr->SetMetric (metricLocal);
27.718 + pLSA->AddLinkRecord (plr);
27.719 + plr = 0;
27.720 + }
27.721 +#endif
27.722 +}
27.723 +
27.724 + void
27.725 +GlobalRouter::ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA)
27.726 +{
27.727 + NS_LOG_FUNCTION (ndLocal << pLSA);
27.728 +
27.729 + //
27.730 + // We have some preliminaries to do to get enough information to proceed.
27.731 + // This information we need comes from the internet stack, so notice that
27.732 + // there is an implied assumption that global routing is only going to
27.733 + // work with devices attached to the internet stack (have an ipv4 interface
27.734 + // associated to them.
27.735 + //
27.736 + Ptr<Node> nodeLocal = ndLocal->GetNode ();
27.737 +
27.738 + uint32_t ifIndexLocal;
27.739 + bool rc = FindIfIndexForDevice(nodeLocal, ndLocal, ifIndexLocal);
27.740 + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
27.741 +
27.742 + Ptr<Ipv4> ipv4Local = nodeLocal->GetObject<Ipv4> ();
27.743 + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
27.744 +
27.745 + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.746 + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.747 + NS_LOG_LOGIC ("Working with local address " << addrLocal);
27.748 + uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
27.749 +
27.750 + //
27.751 + // Now, we're going to walk over to the remote net device on the other end of
27.752 + // the point-to-point channel we know we have. This is where our adjacent
27.753 + // router (to use OSPF lingo) is running.
27.754 + //
27.755 + Ptr<Channel> ch = ndLocal->GetChannel();
27.756 +
27.757 + //
27.758 + // Get the net device on the other side of the point-to-point channel.
27.759 + //
27.760 + Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
27.761 +
27.762 + //
27.763 + // The adjacent net device is aggregated to a node. We need to ask that net
27.764 + // device for its node, then ask that node for its Ipv4 interface. Note a
27.765 + // requirement that nodes on either side of a point-to-point link must have
27.766 + // internet stacks; and an assumption that point-to-point links are incompatible
27.767 + // with bridging.
27.768 + //
27.769 + Ptr<Node> nodeRemote = ndRemote->GetNode();
27.770 + Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
27.771 + NS_ABORT_MSG_UNLESS (ipv4Remote,
27.772 + "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
27.773 +
27.774 + //
27.775 + // Further note the requirement that nodes on either side of a point-to-point
27.776 + // link must participate in global routing and therefore have a GlobalRouter
27.777 + // interface aggregated.
27.778 + //
27.779 + Ptr<GlobalRouter> rtrRemote = nodeRemote->GetObject<GlobalRouter> ();
27.780 + NS_ABORT_MSG_UNLESS(rtrRemote,
27.781 + "GlobalRouter::ProcessPointToPointLinks(): GetObject for remote <GlobalRouter> failed");
27.782 +
27.783 + //
27.784 + // We're going to need the remote router ID, so we might as well get it now.
27.785 + //
27.786 + Ipv4Address rtrIdRemote = rtrRemote->GetRouterId();
27.787 + NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
27.788 +
27.789 + //
27.790 + // Now, just like we did above, we need to get the IP interface index for the
27.791 + // net device on the other end of the point-to-point channel.
27.792 + //
27.793 + uint32_t ifIndexRemote;
27.794 + rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
27.795 + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
27.796 +
27.797 + //
27.798 + // Now that we have the Ipv4 interface, we can get the (remote) address and
27.799 + // mask we need.
27.800 + //
27.801 + Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
27.802 + Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
27.803 + NS_LOG_LOGIC ("Working with remote address " << addrRemote);
27.804 +
27.805 + //
27.806 + // Now we can fill out the link records for this link. There are always two
27.807 + // link records; the first is a point-to-point record describing the link and
27.808 + // the second is a stub network record with the network number.
27.809 + //
27.810 + GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
27.811 + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
27.812 + plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
27.813 + plr->SetLinkId (rtrIdRemote);
27.814 + plr->SetLinkData (addrLocal);
27.815 + plr->SetMetric (metricLocal);
27.816 + pLSA->AddLinkRecord (plr);
27.817 + plr = 0;
27.818 +
27.819 + plr = new GlobalRoutingLinkRecord;
27.820 + NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
27.821 + plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
27.822 + plr->SetLinkId (addrRemote);
27.823 + plr->SetLinkData (Ipv4Address(maskRemote.Get())); // Frown
27.824 + plr->SetMetric (metricLocal);
27.825 + pLSA->AddLinkRecord (plr);
27.826 + plr = 0;
27.827 +}
27.828 +
27.829 + void
27.830 +GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c)
27.831 +{
27.832 + NS_LOG_FUNCTION (&c);
27.833 +
27.834 + uint32_t nDesignatedRouters = c.GetN ();
27.835 +
27.836 + for (uint32_t i = 0; i < nDesignatedRouters; ++i)
27.837 + {
27.838 + //
27.839 + // Build one NetworkLSA for each net device talking to a network that we are the
27.840 + // designated router for. These devices are in the provided container.
27.841 + //
27.842 + Ptr<NetDevice> ndLocal = c.Get (i);
27.843 + Ptr<Node> node = ndLocal->GetNode ();
27.844 +
27.845 + uint32_t ifIndexLocal;
27.846 + bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
27.847 + NS_ABORT_MSG_IF (rc == false, "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
27.848 +
27.849 + Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
27.850 + NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
27.851 +
27.852 + Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.853 + Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.854 +
27.855 + GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
27.856 + NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
27.857 +
27.858 + pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA);
27.859 + pLSA->SetLinkStateId (addrLocal);
27.860 + pLSA->SetAdvertisingRouter (m_routerId);
27.861 + pLSA->SetNetworkLSANetworkMask (maskLocal);
27.862 + pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
27.863 +
27.864 + //
27.865 + // Build a list of AttachedRouters by walking the devices in the channel
27.866 + // and, if we find a node with a GlobalRouter interface and an IPv4
27.867 + // interface associated with that device, we call it an attached router.
27.868 + //
27.869 + Ptr<Channel> ch = ndLocal->GetChannel();
27.870 + uint32_t nDevices = ch->GetNDevices();
27.871 + NS_ASSERT (nDevices);
27.872 +
27.873 + for (uint32_t i = 0; i < nDevices; i++)
27.874 + {
27.875 + Ptr<NetDevice> tempNd = ch->GetDevice (i);
27.876 + NS_ASSERT (tempNd);
27.877 + Ptr<Node> tempNode = tempNd->GetNode ();
27.878 +
27.879 + //
27.880 + // Does the node in question have a GlobalRouter interface? If not it can
27.881 + // hardly be considered an attached router.
27.882 + //
27.883 + Ptr<GlobalRouter> rtr = tempNode->GetObject<GlobalRouter> ();
27.884 + if (rtr == 0)
27.885 + {
27.886 + continue;
27.887 + }
27.888 +
27.889 + //
27.890 + // Does the attached node have an ipv4 interface for the device we're probing?
27.891 + // If not, it can't play router.
27.892 + //
27.893 + uint32_t tempIfIndex;
27.894 + if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
27.895 + {
27.896 Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
27.897 NS_ASSERT (tempIpv4);
27.898 Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
27.899 pLSA->AddAttachedRouter (tempAddr);
27.900 }
27.901 - m_LSAs.push_back (pLSA);
27.902 - NS_LOG_LOGIC (*pLSA);
27.903 }
27.904 + m_LSAs.push_back (pLSA);
27.905 + pLSA = 0;
27.906 }
27.907 -
27.908 - return m_LSAs.size ();
27.909 }
27.910
27.911 +//
27.912 +// Given a local net device, we need to walk the channel to which the net device is
27.913 +// attached and look for nodes with GlobalRouter interfaces on them (one of them
27.914 +// will be us). Of these, the router with the lowest IP address on the net device
27.915 +// connecting to the channel becomes the designated router for the link.
27.916 +//
27.917 Ipv4Address
27.918 -GlobalRouter::FindDesignatedRouterForLink (Ptr<Node> node,
27.919 - Ptr<NetDevice> ndLocal) const
27.920 +GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const
27.921 {
27.922 - uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
27.923 - Ptr<Ipv4> ipv4Local = GetObject<Ipv4> ();
27.924 - NS_ASSERT (ipv4Local);
27.925 - Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
27.926 - Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
27.927 + NS_LOG_FUNCTION (ndLocal << allowRecursion);
27.928
27.929 Ptr<Channel> ch = ndLocal->GetChannel();
27.930 uint32_t nDevices = ch->GetNDevices();
27.931 NS_ASSERT (nDevices);
27.932 - Ipv4Address lowest = addrLocal;
27.933 - // iterate all NetDevices and return the lowest numbered IP address
27.934 +
27.935 + NS_LOG_LOGIC ("Looking for designated router off of net device " << ndLocal << " on node " <<
27.936 + ndLocal->GetNode ()->GetId ());
27.937 +
27.938 + Ipv4Address desigRtr ("255.255.255.255");
27.939 +
27.940 + //
27.941 + // Look through all of the devices on the channel to which the net device
27.942 + // in question is attached.
27.943 + //
27.944 for (uint32_t i = 0; i < nDevices; i++)
27.945 {
27.946 - Ptr<NetDevice> tempNd = ch->GetDevice (i);
27.947 - NS_ASSERT (tempNd);
27.948 - Ptr<Node> tempNode = tempNd->GetNode ();
27.949 - uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd);
27.950 - Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
27.951 - NS_ASSERT (tempIpv4);
27.952 - Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
27.953 - if (tempAddr < addrLocal)
27.954 + Ptr<NetDevice> ndOther = ch->GetDevice (i);
27.955 + NS_ASSERT (ndOther);
27.956 +
27.957 + Ptr<Node> nodeOther = ndOther->GetNode ();
27.958 +
27.959 + NS_LOG_LOGIC ("Examine channel device " << i << " on node " << nodeOther->GetId ());
27.960 +
27.961 + //
27.962 + // For all other net devices, we need to check and see if a router
27.963 + // is present. If the net device on the other side is a bridged
27.964 + // device, we need to consider all of the other devices on the
27.965 + // bridge as well (all of the bridge ports.
27.966 + //
27.967 + NS_LOG_LOGIC ("checking to see if the device is bridged");
27.968 + Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
27.969 + if (bnd)
27.970 {
27.971 - addrLocal = tempAddr;
27.972 + NS_LOG_LOGIC ("Device is bridged by BridgeNetDevice " << bnd);
27.973 +
27.974 + //
27.975 + // It is possible that the bridge net device is sitting under a
27.976 + // router, so we have to check for the presence of that router
27.977 + // before we run off and follow all the links
27.978 + //
27.979 + // We require a designated router to have a GlobalRouter interface and
27.980 + // an internet stack that includes the Ipv4 interface. If it doesn't
27.981 + // it can't play router.
27.982 + //
27.983 + NS_LOG_LOGIC ("Checking for router on bridge net device " << bnd);
27.984 + Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
27.985 + Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
27.986 + if (rtr && ipv4)
27.987 + {
27.988 + uint32_t ifIndexOther;
27.989 + if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
27.990 + {
27.991 + NS_LOG_LOGIC ("Found router on bridge net device " << bnd);
27.992 + Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
27.993 + desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
27.994 + NS_LOG_LOGIC ("designated router now " << desigRtr);
27.995 + }
27.996 + }
27.997 +
27.998 + NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
27.999 + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
27.1000 + {
27.1001 + Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
27.1002 + NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
27.1003 + if (ndBridged == ndOther)
27.1004 + {
27.1005 + NS_LOG_LOGIC ("That bridge port is me, don't walk backward");
27.1006 + continue;
27.1007 + }
27.1008 +
27.1009 + if (allowRecursion)
27.1010 + {
27.1011 + NS_LOG_LOGIC ("Recursively looking for routers down bridge port " << ndBridged);
27.1012 + Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false);
27.1013 + desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
27.1014 + NS_LOG_LOGIC ("designated router now " << desigRtr);
27.1015 + }
27.1016 + }
27.1017 + }
27.1018 + else
27.1019 + {
27.1020 + NS_LOG_LOGIC ("This device is not bridged");
27.1021 + Ptr<Node> nodeOther = ndOther->GetNode ();
27.1022 + NS_ASSERT (nodeOther);
27.1023 +
27.1024 + //
27.1025 + // We require a designated router to have a GlobalRouter interface and
27.1026 + // an internet stack that includes the Ipv4 interface. If it doesn't
27.1027 + //
27.1028 + Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
27.1029 + Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
27.1030 + if (rtr && ipv4)
27.1031 + {
27.1032 + uint32_t ifIndexOther;
27.1033 + if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
27.1034 + {
27.1035 + NS_LOG_LOGIC ("Found router on net device " << ndOther);
27.1036 + Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
27.1037 + desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
27.1038 + NS_LOG_LOGIC ("designated router now " << desigRtr);
27.1039 + }
27.1040 + }
27.1041 }
27.1042 }
27.1043 - return addrLocal;
27.1044 + return desigRtr;
27.1045 +}
27.1046 +
27.1047 +//
27.1048 +// Given a node and an attached net device, take a look off in the channel to
27.1049 +// which the net device is attached and look for a node on the other side
27.1050 +// that has a GlobalRouter interface aggregated. Life gets more complicated
27.1051 +// when there is a bridged net device on the other side.
27.1052 +//
27.1053 + bool
27.1054 +GlobalRouter::AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const
27.1055 +{
27.1056 + NS_LOG_FUNCTION (nd << allowRecursion);
27.1057 +
27.1058 + Ptr<Channel> ch = nd->GetChannel();
27.1059 + uint32_t nDevices = ch->GetNDevices();
27.1060 + NS_ASSERT (nDevices);
27.1061 +
27.1062 + NS_LOG_LOGIC ("Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ());
27.1063 +
27.1064 + //
27.1065 + // Look through all of the devices on the channel to which the net device
27.1066 + // in question is attached.
27.1067 + //
27.1068 + for (uint32_t i = 0; i < nDevices; i++)
27.1069 + {
27.1070 + Ptr<NetDevice> ndOther = ch->GetDevice (i);
27.1071 + NS_ASSERT (ndOther);
27.1072 +
27.1073 + NS_LOG_LOGIC ("Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ());
27.1074 +
27.1075 + //
27.1076 + // Ignore the net device itself.
27.1077 + //
27.1078 + if (ndOther == nd)
27.1079 + {
27.1080 + NS_LOG_LOGIC ("Myself, skip");
27.1081 + continue;
27.1082 + }
27.1083 +
27.1084 + //
27.1085 + // For all other net devices, we need to check and see if a router
27.1086 + // is present. If the net device on the other side is a bridged
27.1087 + // device, we need to consider all of the other devices on the
27.1088 + // bridge.
27.1089 + //
27.1090 + NS_LOG_LOGIC ("checking to see if device is bridged");
27.1091 + Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
27.1092 + if (bnd)
27.1093 + {
27.1094 + NS_LOG_LOGIC ("Device is bridged by net device " << bnd);
27.1095 + NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
27.1096 + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
27.1097 + {
27.1098 + Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
27.1099 + NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
27.1100 + if (ndBridged == ndOther)
27.1101 + {
27.1102 + NS_LOG_LOGIC ("That bridge port is me, skip");
27.1103 + continue;
27.1104 + }
27.1105 +
27.1106 + if (allowRecursion)
27.1107 + {
27.1108 + NS_LOG_LOGIC ("Recursively looking for routers on bridge port " << ndBridged);
27.1109 + if (AnotherRouterOnLink (ndBridged, false))
27.1110 + {
27.1111 + NS_LOG_LOGIC ("Found routers on bridge port, return true");
27.1112 + return true;
27.1113 + }
27.1114 + }
27.1115 + }
27.1116 + NS_LOG_LOGIC ("No routers on bridged net device, return false");
27.1117 + return false;
27.1118 + }
27.1119 +
27.1120 + NS_LOG_LOGIC ("This device is not bridged");
27.1121 + Ptr<Node> nodeTemp = ndOther->GetNode ();
27.1122 + NS_ASSERT (nodeTemp);
27.1123 +
27.1124 + Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
27.1125 + if (rtr)
27.1126 + {
27.1127 + NS_LOG_LOGIC ("Found GlobalRouter interface, return true");
27.1128 + return true;
27.1129 + }
27.1130 + else
27.1131 + {
27.1132 + NS_LOG_LOGIC ("No GlobalRouter interface on device, continue search");
27.1133 + }
27.1134 + }
27.1135 + NS_LOG_LOGIC ("No routers found, return false");
27.1136 + return false;
27.1137 }
27.1138
27.1139 uint32_t
27.1140 @@ -820,11 +1367,10 @@
27.1141 // other end. This only makes sense with a point-to-point channel.
27.1142 //
27.1143 Ptr<NetDevice>
27.1144 -GlobalRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const
27.1145 +GlobalRouter::GetAdjacent (Ptr<NetDevice> nd, Ptr<Channel> ch) const
27.1146 {
27.1147 NS_LOG_FUNCTION_NOARGS ();
27.1148 - NS_ASSERT_MSG(ch->GetNDevices() == 2,
27.1149 - "GlobalRouter::GetAdjacent (): Channel with other than two devices");
27.1150 + NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices");
27.1151 //
27.1152 // This is a point to point channel with two endpoints. Get both of them.
27.1153 //
27.1154 @@ -852,24 +1398,79 @@
27.1155 }
27.1156
27.1157 //
27.1158 -// Given a node and a net device, find the IPV4 interface index that
27.1159 -// corresponds to that net device.
27.1160 +// Given a node and a net device, find an IPV4 interface index that corresponds
27.1161 +// to that net device. This function may fail for various reasons. If a node
27.1162 +// does not have an internet stack (for example if it is a bridge) we won't have
27.1163 +// an IPv4 at all. If the node does have a stack, but the net device in question
27.1164 +// is bridged, there will not be an interface associated directly with the device.
27.1165 //
27.1166 - uint32_t
27.1167 -GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const
27.1168 + bool
27.1169 +GlobalRouter::FindIfIndexForDevice (Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const
27.1170 {
27.1171 NS_LOG_FUNCTION_NOARGS ();
27.1172 + NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd );
27.1173 +
27.1174 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
27.1175 - NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed");
27.1176 + if (ipv4 == 0)
27.1177 + {
27.1178 + NS_LOG_LOGIC ("No Ipv4 interface on node " << node->GetId ());
27.1179 + return false;
27.1180 + }
27.1181 +
27.1182 for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
27.1183 {
27.1184 if (ipv4->GetNetDevice(i) == nd)
27.1185 {
27.1186 - return i;
27.1187 + NS_LOG_LOGIC ("Device " << nd << " has associated ipv4 index " << i);
27.1188 + index = i;
27.1189 + return true;
27.1190 }
27.1191 }
27.1192
27.1193 - NS_ASSERT_MSG(0, "Cannot find interface for device");
27.1194 + NS_LOG_LOGIC ("Device " << nd << " has no associated ipv4 index");
27.1195 + return false;
27.1196 +}
27.1197 +
27.1198 +//
27.1199 +// Decide whether or not a given net device is being bridged by a BridgeNetDevice.
27.1200 +//
27.1201 + Ptr<BridgeNetDevice>
27.1202 +GlobalRouter::NetDeviceIsBridged (Ptr<NetDevice> nd) const
27.1203 +{
27.1204 + NS_LOG_FUNCTION (nd);
27.1205 +
27.1206 + Ptr<Node> node = nd->GetNode ();
27.1207 + uint32_t nDevices = node->GetNDevices();
27.1208 +
27.1209 + //
27.1210 + // There is no bit on a net device that says it is being bridged, so we have
27.1211 + // to look for bridges on the node to which the device is attached. If we
27.1212 + // find a bridge, we need to look through its bridge ports (the devices it
27.1213 + // bridges) to see if we find the device in question.
27.1214 + //
27.1215 + for (uint32_t i = 0; i < nDevices; ++i)
27.1216 + {
27.1217 + Ptr<NetDevice> ndTest = node->GetDevice(i);
27.1218 + NS_LOG_LOGIC ("Examine device " << i << " " << ndTest);
27.1219 +
27.1220 + if (ndTest->IsBridge ())
27.1221 + {
27.1222 + NS_LOG_LOGIC ("device " << i << " is a bridge net device");
27.1223 + Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> ();
27.1224 + NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
27.1225 +
27.1226 + for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
27.1227 + {
27.1228 + NS_LOG_LOGIC ("Examine bridge port " << j << " " << bnd->GetBridgePort (j));
27.1229 + if (bnd->GetBridgePort (j) == nd)
27.1230 + {
27.1231 + NS_LOG_LOGIC ("Net device " << nd << " is bridged by " << bnd);
27.1232 + return bnd;
27.1233 + }
27.1234 + }
27.1235 + }
27.1236 + }
27.1237 + NS_LOG_LOGIC ("Net device " << nd << " is not bridged");
27.1238 return 0;
27.1239 }
27.1240
28.1 --- a/src/routing/global-routing/global-router-interface.h Fri Nov 28 08:55:24 2008 +0100
28.2 +++ b/src/routing/global-routing/global-router-interface.h Fri Nov 28 08:56:47 2008 +0100
28.3 @@ -29,10 +29,14 @@
28.4 #include "ns3/node.h"
28.5 #include "ns3/channel.h"
28.6 #include "ns3/ipv4-address.h"
28.7 +#include "ns3/net-device-container.h"
28.8 +#include "ns3/bridge-net-device.h"
28.9 #include "ns3/global-route-manager.h"
28.10
28.11 namespace ns3 {
28.12
28.13 +class GlobalRouter;
28.14 +
28.15 /**
28.16 * @brief A single link record for a link state advertisement.
28.17 *
28.18 @@ -43,6 +47,7 @@
28.19 class GlobalRoutingLinkRecord
28.20 {
28.21 public:
28.22 + friend class GlobalRoutingLSA;
28.23 /**
28.24 * @enum LinkType
28.25 * @brief Enumeration of the possible types of Global Routing Link Records.
28.26 @@ -639,9 +644,17 @@
28.27 void ClearLSAs (void);
28.28
28.29 Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
28.30 - uint32_t FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const;
28.31 - Ipv4Address FindDesignatedRouterForLink (Ptr<Node> node,
28.32 - Ptr<NetDevice> ndLocal) const;
28.33 + bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
28.34 + Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const;
28.35 + bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
28.36 + void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
28.37 + void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
28.38 + void ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
28.39 +
28.40 + void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
28.41 + void BuildNetworkLSAs (NetDeviceContainer c);
28.42 + Ptr<BridgeNetDevice> NetDeviceIsBridged (Ptr<NetDevice> nd) const;
28.43 +
28.44
28.45 typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
28.46 ListOfLSAs_t m_LSAs;
29.1 --- a/wscript Fri Nov 28 08:55:24 2008 +0100
29.2 +++ b/wscript Fri Nov 28 08:56:47 2008 +0100
29.3 @@ -447,16 +447,13 @@
29.4
29.5 if Params.g_options.run:
29.6 # Check that the requested program name is valid
29.7 - try:
29.8 - wutils.find_program(Params.g_options.run, env)
29.9 - except ValueError, ex:
29.10 - Params.fatal(str(ex))
29.11 -
29.12 + program_name, dummy_program_argv = wutils.get_run_program(Params.g_options.run, get_command_template())
29.13 +
29.14 # When --run'ing a program, tell WAF to only build that program,
29.15 # nothing more; this greatly speeds up compilation when all you
29.16 # want to do is run a test program.
29.17 if not Params.g_options.compile_targets:
29.18 - Params.g_options.compile_targets = Params.g_options.run
29.19 + Params.g_options.compile_targets = program_name
29.20
29.21
29.22
30.1 --- a/wutils.py Fri Nov 28 08:55:24 2008 +0100
30.2 +++ b/wutils.py Fri Nov 28 08:56:47 2008 +0100
30.3 @@ -94,13 +94,12 @@
30.4 Params.fatal("Command %s exited with code %i" % (argv, retval))
30.5 return retval
30.6
30.7 -def run_program(program_string, command_template=None):
30.8 +def get_run_program(program_string, command_template=None):
30.9 """
30.10 - if command_template is not None, then program_string == program
30.11 - name and argv is given by command_template with %s replaced by the
30.12 - full path to the program. Else, program_string is interpreted as
30.13 - a shell command with first name being the program name.
30.14 + Return the program name and argv of the process that would be executed by
30.15 + run_program(program_string, command_template).
30.16 """
30.17 + #print "get_run_program_argv(program_string=%r, command_template=%r)" % (program_string, command_template)
30.18 env = Params.g_build.env_of_name('default')
30.19
30.20 if command_template in (None, '%s'):
30.21 @@ -132,7 +131,16 @@
30.22 Params.fatal("%s does not appear to be a program" % (program_name,))
30.23
30.24 execvec = shlex.split(command_template % (program_node.abspath(env),))
30.25 + return program_name, execvec
30.26
30.27 +def run_program(program_string, command_template=None):
30.28 + """
30.29 + if command_template is not None, then program_string == program
30.30 + name and argv is given by command_template with %s replaced by the
30.31 + full path to the program. Else, program_string is interpreted as
30.32 + a shell command with first name being the program name.
30.33 + """
30.34 + dummy_program_name, execvec = get_run_program(program_string, command_template)
30.35 former_cwd = os.getcwd()
30.36 if (Params.g_options.cwd_launch):
30.37 os.chdir(Params.g_options.cwd_launch)
