View | Details | Raw Unified | Return to bug 114
Collapse All | Expand All

(-)0edba1e055aa (+209 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 */
16
17
// Network topology
18
//
19
//        n0     n1  
20
//        |      | 
21
//       -----------
22
//       | bridge1 |
23
//       -----------
24
//           |    
25
//           n2   
26
//           |
27
//       -----------
28
//       | bridge2 |
29
//       -----------
30
//        |      | 
31
//        n3     n4  
32
//
33
// This example shows two broadcast domains, each interconnected by a bridge
34
// with a router node (n2) interconnecting the layer-2 broadcast domains
35
// 
36
// It is meant to mirror somewhat the csma-bridge example but adds another
37
// bridged link separated by a router.
38
// 
39
// - CBR/UDP flows from n0 to n1 and from n3 to n0
40
// - DropTail queues 
41
// - Global static routing
42
// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
43
44
#include <iostream>
45
#include <fstream>
46
47
#include "ns3/simulator-module.h"
48
#include "ns3/node-module.h"
49
#include "ns3/core-module.h"
50
#include "ns3/helper-module.h"
51
#include "ns3/bridge-module.h"
52
#include "ns3/global-route-manager.h"
53
54
using namespace ns3;
55
56
NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample");
57
58
int 
59
main (int argc, char *argv[])
60
{
61
  //
62
  // Users may find it convenient to turn on explicit debugging
63
  // for selected modules; the below lines suggest how to do this
64
  //
65
#if 0 
66
  LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO);
67
#endif
68
69
  //
70
  // Make the random number generators generate reproducible results.
71
  //
72
  RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
73
74
  //
75
  // Allow the user to override any of the defaults and the above Bind() at
76
  // run-time, via command-line arguments
77
  //
78
  CommandLine cmd;
79
  cmd.Parse (argc, argv);
80
81
  //
82
  // Explicitly create the nodes required by the topology (shown above).
83
  //
84
  NS_LOG_INFO ("Create nodes.");
85
86
  Ptr<Node> n0 = CreateObject<Node> ();
87
  Ptr<Node> n1 = CreateObject<Node> ();
88
  Ptr<Node> n2 = CreateObject<Node> ();
89
  Ptr<Node> n3 = CreateObject<Node> ();
90
  Ptr<Node> n4 = CreateObject<Node> ();
91
92
  Ptr<Node> bridge1 = CreateObject<Node> ();
93
  Ptr<Node> bridge2 = CreateObject<Node> ();
94
95
  NS_LOG_INFO ("Build Topology");
96
  CsmaHelper csma;
97
  csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
98
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
99
100
  // Create the csma links, from each terminal to the bridge
101
  // This will create six network devices; we'll keep track separately
102
  // of the devices on and off the bridge respectively, for later configuration 
103
  NetDeviceContainer topLanDevices;
104
  NetDeviceContainer topBridgeDevices;
105
106
  // It is easier to iterate the nodes in C++ if we put them into a container
107
  NodeContainer topLan (n2, n0, n1);
108
109
  for (int i = 0; i < 3; i++)
110
    {
111
      NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
112
      topLanDevices.Add (link.Get (0));
113
      topBridgeDevices.Add (link.Get (1));
114
    }
115
116
  // Create the bridge netdevice, which will do the packet switching
117
  BridgeHelper bridge;
118
  bridge.Install (bridge1, topBridgeDevices);
119
120
  // Add internet stack to the topLan nodes
121
  InternetStackHelper internet;
122
  internet.Install (topLan);
123
124
  // Repeat for bottom bridged LAN
125
  NetDeviceContainer bottomLanDevices;
126
  NetDeviceContainer bottomBridgeDevices;
127
  NodeContainer bottomLan (n2, n3, n4);
128
  for (int i = 0; i < 3; i++)
129
    {
130
      NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2));
131
      bottomLanDevices.Add (link.Get (0));
132
      bottomBridgeDevices.Add (link.Get (1));
133
    }
134
  bridge.Install (bridge2, bottomBridgeDevices);
135
  internet.Install (NodeContainer (n3, n4));
136
137
138
  // We've got the "hardware" in place.  Now we need to add IP addresses.
139
  //
140
  NS_LOG_INFO ("Assign IP Addresses.");
141
  Ipv4AddressHelper ipv4;
142
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
143
  ipv4.Assign (topLanDevices);
144
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
145
  ipv4.Assign (bottomLanDevices);
146
147
  // Create router nodes, initialize routing database and set up the routing
148
  // tables in the nodes.
149
  GlobalRouteManager::PopulateRoutingTables ();
150
151
  //
152
  // Create an OnOff application to send UDP datagrams from node zero to node 1.
153
  //
154
  NS_LOG_INFO ("Create Applications.");
155
  uint16_t port = 9;   // Discard port (RFC 863)
156
157
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
158
                     Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port)));
159
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
160
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
161
162
  ApplicationContainer app = onoff.Install (n0);
163
  // Start the application
164
  app.Start (Seconds (1.0));
165
  app.Stop (Seconds (10.0));
166
167
  // Create an optional packet sink to receive these packets
168
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
169
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
170
  sink.Install (n1);
171
172
  // 
173
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
174
  //
175
  onoff.SetAttribute ("Remote", 
176
                      AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
177
  ApplicationContainer app2 = onoff.Install (n3);
178
179
  sink.Install (n0);
180
181
  app2.Start (Seconds (1.1));
182
  app2.Stop (Seconds (10.0));
183
184
  //
185
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
186
  // Trace output will be sent to the file "csma-bridge-one-hop.tr"
187
  //
188
  NS_LOG_INFO ("Configure Tracing.");
189
  std::ofstream ascii;
190
  ascii.open ("csma-bridge-one-hop.tr");
191
  CsmaHelper::EnableAsciiAll (ascii);
192
193
  //
194
  // Also configure some tcpdump traces; each interface will be traced.
195
  // The output files will be named:
196
  //     csma-bridge.pcap-<nodeId>-<interfaceId>
197
  // and can be read by the "tcpdump -r" command (use "-tt" option to
198
  // display timestamps correctly)
199
  //
200
  CsmaHelper::EnablePcapAll ("csma-bridge-one-hop");
201
202
  //
203
  // Now, do the actual simulation.
204
  //
205
  NS_LOG_INFO ("Run Simulation.");
206
  Simulator::Run ();
207
  Simulator::Destroy ();
208
  NS_LOG_INFO ("Done.");
209
}
(-)a/examples/wscript (+4 lines)
 Lines 27-32   def build(bld): Link Here 
27
    obj = bld.create_ns3_program('csma-bridge',
27
    obj = bld.create_ns3_program('csma-bridge',
28
                                 ['bridge', 'csma', 'internet-stack'])
28
                                 ['bridge', 'csma', 'internet-stack'])
29
    obj.source = 'csma-bridge.cc'
29
    obj.source = 'csma-bridge.cc'
30
31
    obj = bld.create_ns3_program('csma-bridge-one-hop',
32
                                 ['bridge', 'csma', 'internet-stack'])
33
    obj.source = 'csma-bridge-one-hop.cc'
30
34
31
    obj = bld.create_ns3_program('udp-echo',
35
    obj = bld.create_ns3_program('udp-echo',
32
                                 ['csma', 'internet-stack'])
36
                                 ['csma', 'internet-stack'])
(-)a/src/devices/bridge/bridge-net-device.cc (+6 lines)
 Lines 305-310   BridgeNetDevice::IsPointToPoint (void) c Link Here 
305
  return false;
305
  return false;
306
}
306
}
307
307
308
bool 
309
BridgeNetDevice::IsBridge (void) const
310
{
311
  return true;
312
}
313
308
314
309
bool 
315
bool 
310
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
316
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
(-)a/src/devices/bridge/bridge-net-device.h (+1 lines)
 Lines 98-103   public: Link Here 
98
  virtual bool IsMulticast (void) const;
98
  virtual bool IsMulticast (void) const;
99
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
99
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
100
  virtual bool IsPointToPoint (void) const;
100
  virtual bool IsPointToPoint (void) const;
101
  virtual bool IsBridge (void) const;
101
  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
102
  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
102
  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
103
  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
103
  virtual Ptr<Node> GetNode (void) const;
104
  virtual Ptr<Node> GetNode (void) const;
(-)a/src/devices/csma/csma-net-device.cc (+7 lines)
 Lines 837-842   CsmaNetDevice::IsPointToPoint (void) con Link Here 
837
  return false;
837
  return false;
838
}
838
}
839
839
840
  bool 
841
CsmaNetDevice::IsBridge (void) const
842
{
843
  NS_LOG_FUNCTION_NOARGS ();
844
  return false;
845
}
846
840
  bool
847
  bool
841
CsmaNetDevice::Send (Ptr<Packet> packet,const Address& dest, uint16_t protocolNumber)
848
CsmaNetDevice::Send (Ptr<Packet> packet,const Address& dest, uint16_t protocolNumber)
842
{
849
{
(-)a/src/devices/csma/csma-net-device.h (+6 lines)
 Lines 351-356   public: Link Here 
351
  virtual bool IsPointToPoint (void) const;
351
  virtual bool IsPointToPoint (void) const;
352
352
353
  /**
353
  /**
354
   * Is this a bridge?
355
   * \returns false.
356
   */
357
  virtual bool IsBridge (void) const;
358
359
  /**
354
   * Start sending a packet down the channel.
360
   * Start sending a packet down the channel.
355
   */
361
   */
356
  virtual bool Send (Ptr<Packet> packet, const Address& dest, 
362
  virtual bool Send (Ptr<Packet> packet, const Address& dest, 
(-)a/src/devices/emu/emu-net-device.cc (+6 lines)
 Lines 882-887   EmuNetDevice::IsPointToPoint (void) cons Link Here 
882
  return false;
882
  return false;
883
}
883
}
884
884
885
bool 
886
EmuNetDevice::IsBridge (void) const
887
{
888
  return false;
889
}
890
885
void
891
void
886
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
892
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
887
{
893
{
(-)a/src/devices/emu/emu-net-device.h (+6 lines)
 Lines 164-169   public: Link Here 
164
   * \returns false.
164
   * \returns false.
165
   */
165
   */
166
  virtual bool IsPointToPoint (void) const;
166
  virtual bool IsPointToPoint (void) const;
167
168
  /**
169
   * Is this a bridge?
170
   * \returns false.
171
   */
172
  virtual bool IsBridge (void) const;
167
173
168
  virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
174
  virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
169
175
(-)a/src/devices/point-to-point/point-to-point-net-device.cc (+6 lines)
 Lines 392-397   PointToPointNetDevice::IsPointToPoint (v Link Here 
392
}
392
}
393
393
394
  bool 
394
  bool 
395
PointToPointNetDevice::IsBridge (void) const
396
{
397
  return false;
398
}
399
400
  bool 
395
PointToPointNetDevice::Send(
401
PointToPointNetDevice::Send(
396
  Ptr<Packet> packet, 
402
  Ptr<Packet> packet, 
397
  const Address &dest, 
403
  const Address &dest, 
(-)a/src/devices/point-to-point/point-to-point-net-device.h (+1 lines)
 Lines 252-257   public: Link Here 
252
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
252
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
253
253
254
  virtual bool IsPointToPoint (void) const;
254
  virtual bool IsPointToPoint (void) const;
255
  virtual bool IsBridge (void) const;
255
256
256
  virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
257
  virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
257
  virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
258
  virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
(-)a/src/devices/wifi/wifi-net-device.cc (+5 lines)
 Lines 267-272   WifiNetDevice::IsPointToPoint (void) con Link Here 
267
  return false;
267
  return false;
268
}
268
}
269
bool 
269
bool 
270
WifiNetDevice::IsBridge (void) const
271
{
272
  return false;
273
}
274
bool 
270
WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
275
WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
271
{
276
{
272
  NS_ASSERT (Mac48Address::IsMatchingType (dest));
277
  NS_ASSERT (Mac48Address::IsMatchingType (dest));
(-)a/src/devices/wifi/wifi-net-device.h (+1 lines)
 Lines 94-99   public: Link Here 
94
  virtual bool IsMulticast (void) const;
94
  virtual bool IsMulticast (void) const;
95
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
95
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
96
  virtual bool IsPointToPoint (void) const;
96
  virtual bool IsPointToPoint (void) const;
97
  virtual bool IsBridge (void) const;
97
  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
98
  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
98
  virtual Ptr<Node> GetNode (void) const;
99
  virtual Ptr<Node> GetNode (void) const;
99
  virtual void SetNode (Ptr<Node> node);
100
  virtual void SetNode (Ptr<Node> node);
(-)a/src/node/net-device.h (+9 lines)
 Lines 184-189   public: Link Here 
184
  virtual Address GetMulticast (Ipv6Address addr) const = 0;
184
  virtual Address GetMulticast (Ipv6Address addr) const = 0;
185
185
186
  /**
186
  /**
187
   * \brief Return true if the net device is acting as a bridge.
188
   *
189
   * \return value of m_isBridge flag
190
   */
191
  virtual bool IsBridge (void) const = 0;
192
193
  /**
194
   * \brief Return true if the net device is on a point-to-point link.
195
   *
187
   * \return value of m_isPointToPoint flag
196
   * \return value of m_isPointToPoint flag
188
   */
197
   */
189
  virtual bool IsPointToPoint (void) const = 0;
198
  virtual bool IsPointToPoint (void) const = 0;
(-)a/src/node/simple-net-device.cc (+7 lines)
 Lines 163-168   SimpleNetDevice::IsPointToPoint (void) c Link Here 
163
{
163
{
164
  return false;
164
  return false;
165
}
165
}
166
167
bool 
168
SimpleNetDevice::IsBridge (void) const
169
{
170
  return false;
171
}
172
166
bool 
173
bool 
167
SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
174
SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
168
{
175
{
(-)a/src/node/simple-net-device.h (+1 lines)
 Lines 61-66   public: Link Here 
61
  virtual bool IsMulticast (void) const;
61
  virtual bool IsMulticast (void) const;
62
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
62
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
63
  virtual bool IsPointToPoint (void) const;
63
  virtual bool IsPointToPoint (void) const;
64
  virtual bool IsBridge (void) const;
64
  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
65
  virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
65
  virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
66
  virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
66
  virtual Ptr<Node> GetNode (void) const;
67
  virtual Ptr<Node> GetNode (void) const;
(-)a/examples/csma-bridge-one-hop.cc (-8 / +41 lines)
 Lines 16-36    Link Here 
16
16
17
// Network topology
17
// Network topology
18
//
18
//
19
//         bridge1         The node named bridge1 (node 5 in the nodelist)
20
//   ------------------        has three CMSA net devices that are bridged
21
//   CSMA   CSMA   CSMA        together using a BridgeNetDevice.
22
//     |      |      |
23
//     |      |      |     The bridge node talks over three CSMA channels
24
//     |      |      |
25
//   CSMA   CSMA   CSMA    to three other CSMA net devices
26
//   ----   ----   ----    
27
//    n0     n1     n2     Node two acts as a router and talks to another
28
//                 ----        bridge that connects the remaining nodes.
29
//                 CSMA
30
//                   |
31
//    n3     n4      |
32
//   ----   ----     |
33
//   CSMA   CSMA     |
34
//     |      |      |
35
//     |      |      |
36
//     |      |      |
37
//   CSMA   CSMA   CSMA    The node named bridge2 (node 6 in the nodelist)
38
//   ------------------        has three CMSA net devices that are bridged
39
//        bridge2              together using a BridgeNetDevice.
40
//
41
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes 
42
// with three net devices:
43
//
19
//        n0     n1  
44
//        n0     n1  
20
//        |      | 
45
//        |      | 
21
//       -----------
46
//       -----------
22
//       | bridge1 |
47
//       | bridge1 | <- n5
23
//       -----------
48
//       -----------
24
//           |    
49
//           |    
25
//           n2   
50
//         router    <- n2
26
//           |
51
//           |
27
//       -----------
52
//       -----------
28
//       | bridge2 |
53
//       | bridge2 | <- n6
29
//       -----------
54
//       -----------
30
//        |      | 
55
//        |      | 
31
//        n3     n4  
56
//        n3     n4  
32
//
57
//
33
// This example shows two broadcast domains, each interconnected by a bridge
58
// So, this example shows two broadcast domains, each interconnected by a bridge
34
// with a router node (n2) interconnecting the layer-2 broadcast domains
59
// with a router node (n2) interconnecting the layer-2 broadcast domains
35
// 
60
// 
36
// It is meant to mirror somewhat the csma-bridge example but adds another
61
// It is meant to mirror somewhat the csma-bridge example but adds another
 Lines 108-119   main (int argc, char *argv[]) Link Here 
108
133
109
  for (int i = 0; i < 3; i++)
134
  for (int i = 0; i < 3; i++)
110
    {
135
    {
136
      // install a csma channel between the ith toplan node and the bridge node
111
      NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
137
      NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
112
      topLanDevices.Add (link.Get (0));
138
      topLanDevices.Add (link.Get (0));
113
      topBridgeDevices.Add (link.Get (1));
139
      topBridgeDevices.Add (link.Get (1));
114
    }
140
    }
115
141
116
  // Create the bridge netdevice, which will do the packet switching
142
  //
143
  // Now, Create the bridge netdevice, which will do the packet switching.  The
144
  // bridge lives on the node bridge1 and bridges together the topBridgeDevices
145
  // which are the three CSMA net devices on the node in the diagram above.
146
  //
117
  BridgeHelper bridge;
147
  BridgeHelper bridge;
118
  bridge.Install (bridge1, topBridgeDevices);
148
  bridge.Install (bridge1, topBridgeDevices);
119
149
 Lines 132-142   main (int argc, char *argv[]) Link Here 
132
      bottomBridgeDevices.Add (link.Get (1));
162
      bottomBridgeDevices.Add (link.Get (1));
133
    }
163
    }
134
  bridge.Install (bridge2, bottomBridgeDevices);
164
  bridge.Install (bridge2, bottomBridgeDevices);
165
166
  // Add internet stack to the bottomLan nodes
135
  internet.Install (NodeContainer (n3, n4));
167
  internet.Install (NodeContainer (n3, n4));
136
168
137
138
  // We've got the "hardware" in place.  Now we need to add IP addresses.
169
  // We've got the "hardware" in place.  Now we need to add IP addresses.
139
  //
140
  NS_LOG_INFO ("Assign IP Addresses.");
170
  NS_LOG_INFO ("Assign IP Addresses.");
141
  Ipv4AddressHelper ipv4;
171
  Ipv4AddressHelper ipv4;
142
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
172
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
 Lines 144-152   main (int argc, char *argv[]) Link Here 
144
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
174
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
145
  ipv4.Assign (bottomLanDevices);
175
  ipv4.Assign (bottomLanDevices);
146
176
177
  // 
147
  // Create router nodes, initialize routing database and set up the routing
178
  // Create router nodes, initialize routing database and set up the routing
148
  // tables in the nodes.
179
  // tables in the nodes.
149
  GlobalRouteManager::PopulateRoutingTables ();
180
  //
181
  NodeContainer routerNodes (n0, n1, n2, n3, n4);
182
  GlobalRouteManager::PopulateRoutingTables (routerNodes);
150
183
151
  //
184
  //
152
  // Create an OnOff application to send UDP datagrams from node zero to node 1.
185
  // Create an OnOff application to send UDP datagrams from node zero to node 1.
(-)a/src/core/abort.h (+10 lines)
 Lines 20-25    Link Here 
20
#define NS3_ABORT_H
20
#define NS3_ABORT_H
21
21
22
#include "fatal-error.h"
22
#include "fatal-error.h"
23
24
#define NS_ABORT_MSG(msg)                                       \
25
  do {								\
26
    std::cerr << "file=" << __FILE__ <<                         \
27
      ", line=" << __LINE__ << ", abort, msg=\"" <<             \
28
      msg << "\"" << std::endl;                                 \
29
    int *a = 0;                                                 \
30
    *a = 0;							\
31
  } while (false)
32
23
33
24
#define NS_ABORT_IF(cond)					\
34
#define NS_ABORT_IF(cond)					\
25
  do {								\
35
  do {								\
(-)a/src/devices/bridge/bridge-net-device.cc (-1 / +44 lines)
 Lines 57-62   BridgeNetDevice::BridgeNetDevice () Link Here 
57
    m_ifIndex (0),
57
    m_ifIndex (0),
58
    m_mtu (0xffff)
58
    m_mtu (0xffff)
59
{
59
{
60
  NS_LOG_FUNCTION_NOARGS ();
60
  m_channel = CreateObject<BridgeChannel> ();
61
  m_channel = CreateObject<BridgeChannel> ();
61
}
62
}
62
63
 Lines 100-105   BridgeNetDevice::ForwardUnicast (Ptr<Net Link Here 
100
BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
101
BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
101
                                 uint16_t protocol, Mac48Address src, Mac48Address dst)
102
                                 uint16_t protocol, Mac48Address src, Mac48Address dst)
102
{
103
{
104
  NS_LOG_FUNCTION_NOARGS ();
103
  NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
105
  NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
104
                << ", packet=" << packet << ", protocol="<<protocol
106
                << ", packet=" << packet << ", protocol="<<protocol
105
                << ", src=" << src << ", dst=" << dst << ")");
107
                << ", src=" << src << ", dst=" << dst << ")");
 Lines 133-138   BridgeNetDevice::ForwardBroadcast (Ptr<N Link Here 
133
BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
135
BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
134
                                        uint16_t protocol, Mac48Address src, Mac48Address dst)
136
                                        uint16_t protocol, Mac48Address src, Mac48Address dst)
135
{
137
{
138
  NS_LOG_FUNCTION_NOARGS ();
136
  NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
139
  NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
137
                << ", packet=" << packet << ", protocol="<<protocol
140
                << ", packet=" << packet << ", protocol="<<protocol
138
                << ", src=" << src << ", dst=" << dst << ")");
141
                << ", src=" << src << ", dst=" << dst << ")");
 Lines 154-159   BridgeNetDevice::ForwardBroadcast (Ptr<N Link Here 
154
157
155
void BridgeNetDevice::Learn (Mac48Address source, Ptr<NetDevice> port)
158
void BridgeNetDevice::Learn (Mac48Address source, Ptr<NetDevice> port)
156
{
159
{
160
  NS_LOG_FUNCTION_NOARGS ();
157
  if (m_enableLearning)
161
  if (m_enableLearning)
158
    {
162
    {
159
      LearnedState &state = m_learnState[source];
163
      LearnedState &state = m_learnState[source];
 Lines 164-169   void BridgeNetDevice::Learn (Mac48Addres Link Here 
164
168
165
Ptr<NetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
169
Ptr<NetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
166
{
170
{
171
  NS_LOG_FUNCTION_NOARGS ();
167
  if (m_enableLearning)
172
  if (m_enableLearning)
168
    {
173
    {
169
      Time now = Simulator::Now ();
174
      Time now = Simulator::Now ();
 Lines 185-193   Ptr<NetDevice> BridgeNetDevice::GetLearn Link Here 
185
  return NULL;
190
  return NULL;
186
}
191
}
187
192
193
uint32_t
194
BridgeNetDevice::GetNBridgePorts (void) const
195
{
196
  NS_LOG_FUNCTION_NOARGS ();
197
  return m_ports.size ();
198
}
199
200
201
Ptr<NetDevice>
202
BridgeNetDevice::GetBridgePort (uint32_t n) const
203
{
204
  NS_LOG_FUNCTION_NOARGS ();
205
  return m_ports[n];
206
}
207
188
void 
208
void 
189
BridgeNetDevice::AddBridgePort (Ptr<NetDevice> bridgePort)
209
BridgeNetDevice::AddBridgePort (Ptr<NetDevice> bridgePort)
190
{
210
{
211
  NS_LOG_FUNCTION_NOARGS ();
191
  NS_ASSERT (bridgePort != this);
212
  NS_ASSERT (bridgePort != this);
192
  if (!Mac48Address::IsMatchingType (bridgePort->GetAddress ()))
213
  if (!Mac48Address::IsMatchingType (bridgePort->GetAddress ()))
193
    {
214
    {
 Lines 212-253   void Link Here 
212
void 
233
void 
213
BridgeNetDevice::SetName(const std::string name)
234
BridgeNetDevice::SetName(const std::string name)
214
{
235
{
236
  NS_LOG_FUNCTION_NOARGS ();
215
  m_name = name;
237
  m_name = name;
216
}
238
}
217
239
218
std::string 
240
std::string 
219
BridgeNetDevice::GetName(void) const
241
BridgeNetDevice::GetName(void) const
220
{
242
{
243
  NS_LOG_FUNCTION_NOARGS ();
221
  return m_name;
244
  return m_name;
222
}
245
}
223
246
224
void 
247
void 
225
BridgeNetDevice::SetIfIndex(const uint32_t index)
248
BridgeNetDevice::SetIfIndex(const uint32_t index)
226
{
249
{
250
  NS_LOG_FUNCTION_NOARGS ();
227
  m_ifIndex = index;
251
  m_ifIndex = index;
228
}
252
}
229
253
230
uint32_t 
254
uint32_t 
231
BridgeNetDevice::GetIfIndex(void) const
255
BridgeNetDevice::GetIfIndex(void) const
232
{
256
{
257
  NS_LOG_FUNCTION_NOARGS ();
233
  return m_ifIndex;
258
  return m_ifIndex;
234
}
259
}
235
260
236
Ptr<Channel> 
261
Ptr<Channel> 
237
BridgeNetDevice::GetChannel (void) const
262
BridgeNetDevice::GetChannel (void) const
238
{
263
{
264
  NS_LOG_FUNCTION_NOARGS ();
239
  return m_channel;
265
  return m_channel;
240
}
266
}
241
267
242
Address 
268
Address 
243
BridgeNetDevice::GetAddress (void) const
269
BridgeNetDevice::GetAddress (void) const
244
{
270
{
271
  NS_LOG_FUNCTION_NOARGS ();
245
  return m_address;
272
  return m_address;
246
}
273
}
247
274
248
bool 
275
bool 
249
BridgeNetDevice::SetMtu (const uint16_t mtu)
276
BridgeNetDevice::SetMtu (const uint16_t mtu)
250
{
277
{
278
  NS_LOG_FUNCTION_NOARGS ();
251
  m_mtu = mtu;
279
  m_mtu = mtu;
252
  return true;
280
  return true;
253
}
281
}
 Lines 255-260   uint16_t Link Here 
255
uint16_t 
283
uint16_t 
256
BridgeNetDevice::GetMtu (void) const
284
BridgeNetDevice::GetMtu (void) const
257
{
285
{
286
  NS_LOG_FUNCTION_NOARGS ();
258
  return m_mtu;
287
  return m_mtu;
259
}
288
}
260
289
 Lines 262-267   bool Link Here 
262
bool 
291
bool 
263
BridgeNetDevice::IsLinkUp (void) const
292
BridgeNetDevice::IsLinkUp (void) const
264
{
293
{
294
  NS_LOG_FUNCTION_NOARGS ();
265
  return true;
295
  return true;
266
}
296
}
267
297
 Lines 274-279   bool Link Here 
274
bool 
304
bool 
275
BridgeNetDevice::IsBroadcast (void) const
305
BridgeNetDevice::IsBroadcast (void) const
276
{
306
{
307
  NS_LOG_FUNCTION_NOARGS ();
277
  return true;
308
  return true;
278
}
309
}
279
310
 Lines 281-292   Address Link Here 
281
Address
312
Address
282
BridgeNetDevice::GetBroadcast (void) const
313
BridgeNetDevice::GetBroadcast (void) const
283
{
314
{
315
  NS_LOG_FUNCTION_NOARGS ();
284
  return Mac48Address ("ff:ff:ff:ff:ff:ff");
316
  return Mac48Address ("ff:ff:ff:ff:ff:ff");
285
}
317
}
286
318
287
bool
319
bool
288
BridgeNetDevice::IsMulticast (void) const
320
BridgeNetDevice::IsMulticast (void) const
289
{
321
{
322
  NS_LOG_FUNCTION_NOARGS ();
290
  return true;
323
  return true;
291
}
324
}
292
325
 Lines 302-313   bool Link Here 
302
bool 
335
bool 
303
BridgeNetDevice::IsPointToPoint (void) const
336
BridgeNetDevice::IsPointToPoint (void) const
304
{
337
{
338
  NS_LOG_FUNCTION_NOARGS ();
305
  return false;
339
  return false;
306
}
340
}
307
341
308
bool 
342
bool 
309
BridgeNetDevice::IsBridge (void) const
343
BridgeNetDevice::IsBridge (void) const
310
{
344
{
345
  NS_LOG_FUNCTION_NOARGS ();
311
  return true;
346
  return true;
312
}
347
}
313
348
 Lines 315-320   bool Link Here 
315
bool 
350
bool 
316
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
351
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
317
{
352
{
353
  NS_LOG_FUNCTION_NOARGS ();
318
  for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
354
  for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
319
         iter != m_ports.end (); iter++)
355
         iter != m_ports.end (); iter++)
320
    {
356
    {
 Lines 328-333   bool Link Here 
328
bool 
364
bool 
329
BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
365
BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
330
{
366
{
367
  NS_LOG_FUNCTION_NOARGS ();
331
  for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
368
  for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
332
         iter != m_ports.end (); iter++)
369
         iter != m_ports.end (); iter++)
333
    {
370
    {
 Lines 342-347   Ptr<Node> Link Here 
342
Ptr<Node> 
379
Ptr<Node> 
343
BridgeNetDevice::GetNode (void) const
380
BridgeNetDevice::GetNode (void) const
344
{
381
{
382
  NS_LOG_FUNCTION_NOARGS ();
345
  return m_node;
383
  return m_node;
346
}
384
}
347
385
 Lines 349-354   void Link Here 
349
void 
387
void 
350
BridgeNetDevice::SetNode (Ptr<Node> node)
388
BridgeNetDevice::SetNode (Ptr<Node> node)
351
{
389
{
390
  NS_LOG_FUNCTION_NOARGS ();
352
  m_node = node;
391
  m_node = node;
353
}
392
}
354
393
 Lines 356-361   bool Link Here 
356
bool 
395
bool 
357
BridgeNetDevice::NeedsArp (void) const
396
BridgeNetDevice::NeedsArp (void) const
358
{
397
{
398
  NS_LOG_FUNCTION_NOARGS ();
359
  return true;
399
  return true;
360
}
400
}
361
401
 Lines 363-387   void Link Here 
363
void 
403
void 
364
BridgeNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
404
BridgeNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
365
{
405
{
406
  NS_LOG_FUNCTION_NOARGS ();
366
  m_rxCallback = cb;
407
  m_rxCallback = cb;
367
}
408
}
368
409
369
void 
410
void 
370
BridgeNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
411
BridgeNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
371
{
412
{
413
  NS_LOG_FUNCTION_NOARGS ();
372
  m_promiscRxCallback = cb;
414
  m_promiscRxCallback = cb;
373
}
415
}
374
416
375
bool
417
bool
376
BridgeNetDevice::SupportsSendFrom () const
418
BridgeNetDevice::SupportsSendFrom () const
377
{
419
{
420
  NS_LOG_FUNCTION_NOARGS ();
378
  return true;
421
  return true;
379
}
422
}
380
381
423
382
void
424
void
383
BridgeNetDevice::DoDispose (void)
425
BridgeNetDevice::DoDispose (void)
384
{
426
{
427
  NS_LOG_FUNCTION_NOARGS ();
385
  m_node = 0;
428
  m_node = 0;
386
  NetDevice::DoDispose ();
429
  NetDevice::DoDispose ();
387
}
430
}
(-)a/src/devices/bridge/bridge-net-device.h (+4 lines)
 Lines 82-87   public: Link Here 
82
   */
82
   */
83
  void AddBridgePort (Ptr<NetDevice> bridgePort);
83
  void AddBridgePort (Ptr<NetDevice> bridgePort);
84
84
85
  uint32_t GetNBridgePorts (void) const;
86
87
  Ptr<NetDevice> GetBridgePort (uint32_t n) const;
88
85
  // inherited from NetDevice base class.
89
  // inherited from NetDevice base class.
86
  virtual void SetName(const std::string name);
90
  virtual void SetName(const std::string name);
87
  virtual std::string GetName(void) const;
91
  virtual std::string GetName(void) const;
(-)a/src/helper/bridge-helper.cc (-1 / +27 lines)
 Lines 1-24    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c)
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
1
#include "bridge-helper.h"
19
#include "bridge-helper.h"
2
20
#include "ns3/log.h"
3
#include "ns3/bridge-net-device.h"
21
#include "ns3/bridge-net-device.h"
4
#include "ns3/node.h"
22
#include "ns3/node.h"
23
24
NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
5
25
6
namespace ns3 {
26
namespace ns3 {
7
27
8
BridgeHelper::BridgeHelper ()
28
BridgeHelper::BridgeHelper ()
9
{
29
{
30
  NS_LOG_FUNCTION_NOARGS ();
10
  m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
31
  m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
11
}
32
}
12
33
13
void 
34
void 
14
BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
35
BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
15
{
36
{
37
  NS_LOG_FUNCTION_NOARGS ();
16
  m_deviceFactory.Set (n1, v1);
38
  m_deviceFactory.Set (n1, v1);
17
}
39
}
18
40
19
NetDeviceContainer
41
NetDeviceContainer
20
BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
42
BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
21
{
43
{
44
  NS_LOG_FUNCTION_NOARGS ();
45
  NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
46
22
  NetDeviceContainer devs;
47
  NetDeviceContainer devs;
23
  Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
48
  Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
24
  devs.Add (dev);
49
  devs.Add (dev);
 Lines 26-31   BridgeHelper::Install (Ptr<Node> node, N Link Here 
26
51
27
  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
52
  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
28
    {
53
    {
54
      NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
29
      dev->AddBridgePort (*i);
55
      dev->AddBridgePort (*i);
30
    }
56
    }
31
  return devs;
57
  return devs;
(-)a/src/helper/node-container.cc (+11 lines)
 Lines 48-53   NodeContainer::NodeContainer (const Node Link Here 
48
  Add (b);
48
  Add (b);
49
  Add (c);
49
  Add (c);
50
  Add (d);
50
  Add (d);
51
}
52
53
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, 
54
                              const NodeContainer &c, const NodeContainer &d,
55
                              const NodeContainer &e)
56
{
57
  Add (a);
58
  Add (b);
59
  Add (c);
60
  Add (d);
61
  Add (e);
51
}
62
}
52
63
53
NodeContainer::Iterator 
64
NodeContainer::Iterator 
(-)a/src/helper/node-container.h (+2 lines)
 Lines 64-69   public: Link Here 
64
64
65
  NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c);
65
  NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c);
66
  NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d);
66
  NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d);
67
  NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d,
68
                 const NodeContainer &e);
67
69
68
  /**
70
  /**
69
   * \returns an iterator to the start of the vector of node pointers.
71
   * \returns an iterator to the start of the vector of node pointers.
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-2 / +16 lines)
 Lines 351-358   GlobalRouteManagerImpl::DebugUseLsdb (Gl Link Here 
351
351
352
//
352
//
353
// In order to build the routing database, we need at least one of the nodes
353
// In order to build the routing database, we need at least one of the nodes
354
// to participate as a router.  Eventually we expect to provide a mechanism
354
// to participate as a router.  This is a convenience function that makes
355
// for selecting a subset of the nodes to participate; for now, we just make
356
// all nodes routers.  We do this by walking the list of nodes in the system
355
// all nodes routers.  We do this by walking the list of nodes in the system
357
// and aggregating a Global Router Interface to each of the nodes.
356
// and aggregating a Global Router Interface to each of the nodes.
358
//
357
//
 Lines 361-366   GlobalRouteManagerImpl::SelectRouterNode Link Here 
361
{
360
{
362
  NS_LOG_FUNCTION_NOARGS ();
361
  NS_LOG_FUNCTION_NOARGS ();
363
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
362
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
363
    {
364
      Ptr<Node> node = *i;
365
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
366
        node->GetId ());
367
368
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
369
      node->AggregateObject (globalRouter);
370
    }
371
}
372
373
  void
374
GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) 
375
{
376
  NS_LOG_FUNCTION_NOARGS ();
377
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
364
    {
378
    {
365
      Ptr<Node> node = *i;
379
      Ptr<Node> node = *i;
366
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
380
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
(-)a/src/routing/global-routing/global-route-manager-impl.h (+9 lines)
 Lines 29-34    Link Here 
29
#include "ns3/object.h"
29
#include "ns3/object.h"
30
#include "ns3/ptr.h"
30
#include "ns3/ptr.h"
31
#include "ns3/ipv4-address.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/node-container.h"
32
#include "global-router-interface.h"
33
#include "global-router-interface.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
 Lines 708-713   public: Link Here 
708
  virtual void SelectRouterNodes ();
709
  virtual void SelectRouterNodes ();
709
710
710
/**
711
/**
712
 * @brief Select which nodes in the system are to be router nodes and 
713
 * aggregate the appropriate interfaces onto those nodes.
714
 * @internal
715
 *
716
 */
717
  virtual void SelectRouterNodes (NodeContainer c);
718
719
/**
711
 * @brief Build the routing database by gathering Link State Advertisements
720
 * @brief Build the routing database by gathering Link State Advertisements
712
 * from each node exporting a GlobalRouter interface.
721
 * from each node exporting a GlobalRouter interface.
713
 * @internal
722
 * @internal
(-)a/src/routing/global-routing/global-route-manager.cc (-5 / +21 lines)
 Lines 21-26    Link Here 
21
#include "ns3/assert.h"
21
#include "ns3/assert.h"
22
#include "ns3/log.h"
22
#include "ns3/log.h"
23
#include "ns3/simulation-singleton.h"
23
#include "ns3/simulation-singleton.h"
24
#include "ns3/node-container.h"
24
#include "global-route-manager.h"
25
#include "global-route-manager.h"
25
#include "global-route-manager-impl.h"
26
#include "global-route-manager-impl.h"
26
27
 Lines 33-39   namespace ns3 { Link Here 
33
// ---------------------------------------------------------------------------
34
// ---------------------------------------------------------------------------
34
35
35
  void
36
  void
36
GlobalRouteManager::PopulateRoutingTables () 
37
GlobalRouteManager::PopulateRoutingTables (void) 
37
{
38
{
38
  SelectRouterNodes ();
39
  SelectRouterNodes ();
39
  BuildGlobalRoutingDatabase ();
40
  BuildGlobalRoutingDatabase ();
 Lines 41-68   GlobalRouteManager::PopulateRoutingTable Link Here 
41
}
42
}
42
43
43
  void
44
  void
44
GlobalRouteManager::SelectRouterNodes () 
45
GlobalRouteManager::PopulateRoutingTables (NodeContainer c) 
46
{
47
  SelectRouterNodes (c);
48
  BuildGlobalRoutingDatabase ();
49
  InitializeRoutes ();
50
}
51
52
  void
53
GlobalRouteManager::SelectRouterNodes (void) 
45
{
54
{
46
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
55
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
47
    SelectRouterNodes ();
56
    SelectRouterNodes ();
48
}
57
}
49
58
50
  void
59
  void
51
GlobalRouteManager::BuildGlobalRoutingDatabase () 
60
GlobalRouteManager::SelectRouterNodes (NodeContainer c) 
61
{
62
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
63
    SelectRouterNodes (c);
64
}
65
66
  void
67
GlobalRouteManager::BuildGlobalRoutingDatabase (void) 
52
{
68
{
53
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
69
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
54
    BuildGlobalRoutingDatabase ();
70
    BuildGlobalRoutingDatabase ();
55
}
71
}
56
72
57
  void
73
  void
58
GlobalRouteManager::InitializeRoutes ()
74
GlobalRouteManager::InitializeRoutes (void)
59
{
75
{
60
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
76
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
61
    InitializeRoutes ();
77
    InitializeRoutes ();
62
}
78
}
63
79
64
  uint32_t
80
  uint32_t
65
GlobalRouteManager::AllocateRouterId ()
81
GlobalRouteManager::AllocateRouterId (void)
66
{
82
{
67
  static uint32_t routerId = 0;
83
  static uint32_t routerId = 0;
68
  return routerId++;
84
  return routerId++;
(-)a/src/routing/global-routing/global-route-manager.h (-1 / +25 lines)
 Lines 22-27    Link Here 
22
#ifndef GLOBAL_ROUTE_MANAGER_H
22
#ifndef GLOBAL_ROUTE_MANAGER_H
23
#define GLOBAL_ROUTE_MANAGER_H
23
#define GLOBAL_ROUTE_MANAGER_H
24
24
25
#include "ns3/node-container.h"
26
25
namespace ns3 {
27
namespace ns3 {
26
28
27
/**
29
/**
 Lines 40-46   public: Link Here 
40
public:
42
public:
41
/**
43
/**
42
 * @brief Build a routing database and initialize the routing tables of
44
 * @brief Build a routing database and initialize the routing tables of
43
 * the nodes in the simulation.
45
 * the nodes in the simulation.  Makes all nodes in the simulation into
46
 * routers.
44
 *
47
 *
45
 * All this function does is call  BuildGlobalRoutingDatabase () and
48
 * All this function does is call  BuildGlobalRoutingDatabase () and
46
 * InitializeRoutes ().
49
 * InitializeRoutes ().
 Lines 49-54   public: Link Here 
49
 * @see InitializeRoutes ();
52
 * @see InitializeRoutes ();
50
 */
53
 */
51
  static void PopulateRoutingTables ();
54
  static void PopulateRoutingTables ();
55
56
/**
57
 * @brief Build a routing database and initialize the routing tables of
58
 * the nodes in the simulation.  Makes the nodes in the provided container
59
 * into routers.
60
 *
61
 * All this function does is call  BuildGlobalRoutingDatabase () and
62
 * InitializeRoutes ().
63
 *
64
 * @see BuildGlobalRoutingDatabase ();
65
 * @see InitializeRoutes ();
66
 */
67
  static void PopulateRoutingTables (NodeContainer c);
52
68
53
/**
69
/**
54
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
70
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
 Lines 63-68   private: Link Here 
63
 *
79
 *
64
 */
80
 */
65
  static void SelectRouterNodes ();
81
  static void SelectRouterNodes ();
82
83
/**
84
 * @brief Select which nodes in the system are to be router nodes and 
85
 * aggregate the appropriate interfaces onto those nodes.
86
 * @internal
87
 *
88
 */
89
  static void SelectRouterNodes (NodeContainer c);
66
90
67
/**
91
/**
68
 * @brief Build the routing database by gathering Link State Advertisements
92
 * @brief Build the routing database by gathering Link State Advertisements
(-)a/src/routing/global-routing/global-router-interface.cc (-65 / +233 lines)
 Lines 20-30    Link Here 
20
20
21
#include "ns3/log.h"
21
#include "ns3/log.h"
22
#include "ns3/assert.h"
22
#include "ns3/assert.h"
23
#include "ns3/abort.h"
23
#include "ns3/channel.h"
24
#include "ns3/channel.h"
24
#include "ns3/net-device.h"
25
#include "ns3/net-device.h"
25
#include "ns3/node.h"
26
#include "ns3/node.h"
26
#include "ns3/ipv4.h"
27
#include "ns3/ipv4.h"
28
#include "ns3/bridge-net-device.h"
27
#include "global-router-interface.h"
29
#include "global-router-interface.h"
30
#include <vector>
28
31
29
NS_LOG_COMPONENT_DEFINE ("GlobalRouter");
32
NS_LOG_COMPONENT_DEFINE ("GlobalRouter");
30
33
 Lines 365-372   GlobalRoutingLSA::GetAttachedRouter (uin Link Here 
365
          return *i;
368
          return *i;
366
        }
369
        }
367
    }
370
    }
368
  NS_ASSERT_MSG(false, 
371
  NS_ASSERT_MSG(false, "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
369
    "GlobalRoutingLSA::GetAttachedRouter (): invalid index");
370
  return Ipv4Address("0.0.0.0");
372
  return Ipv4Address("0.0.0.0");
371
}
373
}
372
374
 Lines 495-539   GlobalRouter::DiscoverLSAs (void) Link Here 
495
{
497
{
496
  NS_LOG_FUNCTION_NOARGS ();
498
  NS_LOG_FUNCTION_NOARGS ();
497
  Ptr<Node> node = GetObject<Node> ();
499
  Ptr<Node> node = GetObject<Node> ();
498
  NS_LOG_LOGIC("For node " << node->GetId () );
500
  NS_ABORT_MSG_UNLESS (node, "GlobalRouter::DiscoverLSAs (): GetObject for <Node> interface failed");
499
  NS_ASSERT_MSG(node, 
501
  NS_LOG_LOGIC ("For node " << node->GetId () );
500
    "GlobalRouter::DiscoverLSAs (): <Node> interface not set");
501
502
502
  ClearLSAs ();
503
  ClearLSAs ();
503
504
//
504
// While building the router-LSA, keep a list of those NetDevices for
505
// While building the router-LSA, keep a list of those NetDevices for
505
// which I am the designated router and need to later build a NetworkLSA
506
// which I am the designated router and need to later build a NetworkLSA
507
//
506
  std::list<Ptr<NetDevice> > listOfDRInterfaces;
508
  std::list<Ptr<NetDevice> > listOfDRInterfaces;
507
509
508
//
510
//
509
// We're aggregated to a node.  We need to ask the node for a pointer to its
511
// We're aggregated to a node.  We need to ask the node for a pointer to its
510
// Ipv4 interface.  This is where the information regarding the attached 
512
// Ipv4 interface.  This is where the information regarding the attached 
511
// interfaces lives.
513
// interfaces lives.  If we're a router, we had better have an Ipv4 interface.
512
//
514
//
513
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
515
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
514
  NS_ASSERT_MSG(ipv4Local, 
516
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
515
    "GlobalRouter::DiscoverLSAs (): QI for <Ipv4> interface failed");
516
//
517
//
517
// Each node originates a Router-LSA
518
// Each node is a router and so originates a Router-LSA
518
//
519
//
519
  GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
520
  GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
520
  pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
521
  pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
521
  pLSA->SetLinkStateId (m_routerId);
522
  pLSA->SetLinkStateId (m_routerId);
522
  pLSA->SetAdvertisingRouter (m_routerId);
523
  pLSA->SetAdvertisingRouter (m_routerId);
523
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
524
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
525
524
//
526
//
525
// We need to ask the node for the number of net devices attached. This isn't
527
// Ask the node for the number of net devices attached. This isn't necessarily 
526
// necessarily equal to the number of links to adjacent nodes (other routers)
528
// equal to the number of links to adjacent nodes (other routers) as the number
527
// as the number of devices may include those for stub networks (e.g., 
529
// of devices may include those for stub networks (e.g., ethernets, etc.) and 
528
// ethernets, etc.).  
530
// bridge devices also take up an "extra" net device.
529
//
531
//
530
  uint32_t numDevices = node->GetNDevices();
532
  uint32_t numDevices = node->GetNDevices();
531
  NS_LOG_LOGIC ("numDevices = " << numDevices);
533
  NS_LOG_LOGIC ("numDevices = " << numDevices);
534
535
//
536
// There are two broad classes of devices:  bridges in combination with the
537
// devices they bridge and everything else.  We need to first discover all of
538
// the "everything else" class of devices.
539
//
540
// To do this, we wander through all of the devices on the node looking for
541
// bridge net devices.  We then add any net devices associated to a bridge
542
// to a list of bridged devices.  These devices will not be treated as stand-
543
// alone devices later.
544
//
545
  std::vector<Ptr<NetDevice> > bridgedDevices;
546
547
  NS_LOG_LOGIC ("*************************");
548
549
  NS_LOG_LOGIC ("numDevices = " << numDevices);
550
  for (uint32_t i = 0; i < numDevices; ++i)
551
    {
552
      Ptr<NetDevice> nd = node->GetDevice(i);
553
      if (nd->IsBridge ())
554
        {
555
          NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge");
556
          //
557
          // XXX There is only one kind of bridge device so far.  We agreed to
558
          // assume that it is Gustavo's learning bridge until there is a need
559
          // to deal with another.  At that time, we'll have to break out a
560
          // bridge interface.
561
          //
562
          Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
563
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
564
565
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
566
            {
567
              NS_LOG_LOGIC ("**** Net device " << bnd << "is a bridged device");
568
              bridgedDevices.push_back (bnd->GetBridgePort (j));
569
            }
570
        }
571
    }
572
573
  //
574
  // Iterate through the devices on the node and walk the channel to see what's
575
  // on the other side of the standalone devices..
576
  //
532
  for (uint32_t i = 0; i < numDevices; ++i)
577
  for (uint32_t i = 0; i < numDevices; ++i)
533
    {
578
    {
534
      Ptr<NetDevice> ndLocal = node->GetDevice(i);
579
      Ptr<NetDevice> ndLocal = node->GetDevice(i);
580
      //
581
      // If the device in question is on our list of bridged devices, then we
582
      // just ignore it.  It will be dealt with correctly when we probe the 
583
      // bridge device it belongs to.  It is the case that the bridge code
584
      // assumes that bridged devices must not have IP interfaces, and so it 
585
      // may actually sufficient to perform the test for IP interface below, 
586
      // but that struck me as too indirect a condition.
587
      //
588
      for (uint32_t j = 0; j < bridgedDevices.size (); ++j)
589
        {
590
          if (ndLocal == bridgedDevices[j])
591
            {
592
              NS_LOG_LOGIC ("**** Skipping Bridged Device");
535
593
536
      // Check if it is an IP interface (could be a pure L2 NetDevice)
594
              continue;
595
            }
596
        }
597
598
      //
599
      // Check to see if the net device we just got has a corresponding IP 
600
      // interface (could be a pure L2 NetDevice).  
601
      //
537
      bool isIp = false;
602
      bool isIp = false;
538
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
603
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
539
        {
604
        {
 Lines 543-568   GlobalRouter::DiscoverLSAs (void) Link Here 
543
              break;
608
              break;
544
            }
609
            }
545
        }
610
        }
611
546
      if (!isIp)
612
      if (!isIp)
547
        {
613
        {
614
          NS_LOG_LOGIC ("**** Net device " << ndLocal << "has no IP interface, skipping");
548
          continue;
615
          continue;
549
        }
616
        }
550
617
551
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
618
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
552
        {
619
        {
553
          NS_LOG_LOGIC ("Broadcast link");
620
          NS_LOG_LOGIC ("**** Broadcast link");
554
          GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
621
          GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
555
//
622
//
556
// We need to determine whether we are on a transit or stub network
623
// We need to determine whether we are on a transit or stub network
557
// If we find at least one more router on this channel, we are a transit
624
// If we find at least one more router on this channel, we are a transit
558
//
625
// network.  If we're the only router, we're on a stub.
559
//
626
//
560
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
627
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
561
// just found.  This is still the IP on the local side of the channel.  There 
628
// just found.  This is still the IP on the local side of the channel.
562
// is a function to do this used down in the guts of the stack, but it's not 
563
// exported so we had to whip up an equivalent.
564
//
629
//
565
          uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
630
          uint32_t ifIndexLocal;
631
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
632
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
633
566
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
634
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
567
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
635
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
568
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
636
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
 Lines 577-583   GlobalRouter::DiscoverLSAs (void) Link Here 
577
          if (nDevices == 1)
645
          if (nDevices == 1)
578
            {
646
            {
579
              // This is a stub broadcast interface
647
              // This is a stub broadcast interface
580
              NS_LOG_LOGIC("Router-LSA stub broadcast link");
648
              NS_LOG_LOGIC("**** Router-LSA stub broadcast link");
581
              // XXX in future, need to consider if >1 includes other routers
649
              // XXX in future, need to consider if >1 includes other routers
582
              plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
650
              plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
583
              // Link ID is IP network number of attached network
651
              // Link ID is IP network number of attached network
 Lines 593-599   GlobalRouter::DiscoverLSAs (void) Link Here 
593
            }
661
            }
594
          else
662
          else
595
            {
663
            {
596
              NS_LOG_LOGIC ("Router-LSA Broadcast link");
664
              NS_LOG_LOGIC ("**** Router-LSA Broadcast link");
597
              // multiple routers on a broadcast interface
665
              // multiple routers on a broadcast interface
598
              // lowest IP address is designated router
666
              // lowest IP address is designated router
599
              plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
667
              plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
 Lines 616-629   GlobalRouter::DiscoverLSAs (void) Link Here 
616
        }
684
        }
617
      else if (ndLocal->IsPointToPoint () )
685
      else if (ndLocal->IsPointToPoint () )
618
        {
686
        {
619
          NS_LOG_LOGIC ("Router-LSA Point-to-point device");
687
          NS_LOG_LOGIC ("**** Router-LSA Point-to-point device");
620
//
688
//
621
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
689
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
622
// just found.  This is still the IP on the local side of the channel.  There 
690
// just found.  This is still the IP on the local side of the channel.  There 
623
// is a function to do this used down in the guts of the stack, but it's not 
691
// is a function to do this used down in the guts of the stack, but it's not 
624
// exported so we had to whip up an equivalent.
692
// exported so we had to whip up an equivalent.
625
//
693
//
626
          uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
694
          uint32_t ifIndexLocal;
695
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
696
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
627
//
697
//
628
// Now that we have the Ipv4 interface index, we can get the address and mask
698
// Now that we have the Ipv4 interface index, we can get the address and mask
629
// we need.
699
// we need.
 Lines 642-671   GlobalRouter::DiscoverLSAs (void) Link Here 
642
            {
712
            {
643
              continue;
713
              continue;
644
            }
714
            }
715
//
716
// Get the net device on the other side of the point-to-point channel.
717
//
645
          Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
718
          Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
646
//
719
//
647
// The adjacent net device is aggregated to a node.  We need to ask that net 
720
// The adjacent net device is aggregated to a node.  We need to ask that net 
648
// device for its node, then ask that node for its Ipv4 interface.
721
// device for its node, then ask that node for its Ipv4 interface.  Note a
722
// requirement that nodes on either side of a point-to-point link must have 
723
// internet stacks.
649
//
724
//
650
          Ptr<Node> nodeRemote = ndRemote->GetNode();
725
          Ptr<Node> nodeRemote = ndRemote->GetNode();
651
          Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
726
          Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
652
          NS_ASSERT_MSG(ipv4Remote, 
727
          NS_ABORT_MSG_UNLESS (ipv4Remote, 
653
            "GlobalRouter::DiscoverLSAs (): QI for remote <Ipv4> failed");
728
            "GlobalRouter::DiscoverLSAs (): GetObject for remote <Ipv4> failed");
654
//
729
//
655
// Per the OSPF spec, we're going to need the remote router ID, so we might as
730
// Per the OSPF spec, we're going to need the remote router ID, so we might as
656
// well get it now.
731
// well get it now.
657
//
732
//
658
          Ptr<GlobalRouter> srRemote = 
733
// While we're at it, further note the requirement that nodes on either side of
659
            nodeRemote->GetObject<GlobalRouter> ();
734
// a point-to-point link must participateg in global routing and therefore have
660
          NS_ASSERT_MSG(srRemote, 
735
// a GlobalRouter interface aggregated.
661
            "GlobalRouter::DiscoverLSAs():QI for remote <GlobalRouter> failed");
736
//
737
          Ptr<GlobalRouter> srRemote = nodeRemote->GetObject<GlobalRouter> ();
738
          NS_ABORT_MSG_UNLESS(srRemote, 
739
            "GlobalRouter::DiscoverLSAs(): GetObject for remote <GlobalRouter> failed");
740
662
          Ipv4Address rtrIdRemote = srRemote->GetRouterId();
741
          Ipv4Address rtrIdRemote = srRemote->GetRouterId();
663
          NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
742
          NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
664
//
743
//
665
// Now, just like we did above, we need to get the IP interface index for the 
744
// Now, just like we did above, we need to get the IP interface index for the 
666
// net device on the other end of the point-to-point channel.
745
// net device on the other end of the point-to-point channel.  We have yet another
746
// assumption that point to point devices are incompatible with bridges and that
747
// the remote device must have an associated ip interface.
667
//
748
//
668
          uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote);
749
          uint32_t ifIndexRemote;
750
          rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
751
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with remote device");
669
//
752
//
670
// Now that we have the Ipv4 interface, we can get the (remote) address and
753
// Now that we have the Ipv4 interface, we can get the (remote) address and
671
// mask we need.
754
// mask we need.
 Lines 698-720   GlobalRouter::DiscoverLSAs (void) Link Here 
698
        {
781
        {
699
          NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
782
          NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
700
        }
783
        }
701
702
    }
784
    }
703
//
785
//
704
// The LSA goes on a list of LSAs in case we want to begin exporting other
786
// The LSA goes on a list of LSAs in case we want to begin exporting other
705
// kinds of advertisements (than Router LSAs).
787
// kinds of advertisements (than Router LSAs).
788
//
706
  m_LSAs.push_back (pLSA);
789
  m_LSAs.push_back (pLSA);
707
  NS_LOG_LOGIC (*pLSA);
790
  NS_LOG_LOGIC (*pLSA);
708
791
709
// Now, determine whether we need to build a NetworkLSA
792
// 
793
// Now, determine whether we need to build a NetworkLSA.  This is the case if
794
// we found at least one designated router.
795
//
710
  if (listOfDRInterfaces.size () > 0)
796
  if (listOfDRInterfaces.size () > 0)
711
    {
797
    {
712
      for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
798
      for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
713
        i != listOfDRInterfaces.end (); i++)
799
        i != listOfDRInterfaces.end (); i++)
714
        {
800
        {
801
//
715
// Build one NetworkLSA for each interface that is a DR
802
// Build one NetworkLSA for each interface that is a DR
803
//
716
          Ptr<NetDevice> ndLocal = *i;
804
          Ptr<NetDevice> ndLocal = *i;
717
          uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
805
806
          //
807
          // We are working with a list of net devices off of the local node
808
          // on which we found a designated router.  We assume there must be
809
          // an associated ipv4 interface index.
810
          //
811
812
          uint32_t ifIndexLocal;
813
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
814
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
815
718
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
816
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
719
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
817
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
720
818
 Lines 724-730   GlobalRouter::DiscoverLSAs (void) Link Here 
724
          pLSA->SetAdvertisingRouter (m_routerId);
822
          pLSA->SetAdvertisingRouter (m_routerId);
725
          pLSA->SetNetworkLSANetworkMask (maskLocal);
823
          pLSA->SetNetworkLSANetworkMask (maskLocal);
726
          pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
824
          pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
727
// Build list of AttachedRouters
825
//
826
// XXX Doesn't deal with bridging
827
//
828
// Build a list of AttachedRouters by walking the devices in the channel
829
// and, if we find an IPv4 interface associated with that device, we
830
// call it an attached router.  
831
//
728
          Ptr<Channel> ch = ndLocal->GetChannel();
832
          Ptr<Channel> ch = ndLocal->GetChannel();
729
          uint32_t nDevices = ch->GetNDevices();
833
          uint32_t nDevices = ch->GetNDevices();
730
          NS_ASSERT (nDevices);
834
          NS_ASSERT (nDevices);
 Lines 733-743   GlobalRouter::DiscoverLSAs (void) Link Here 
733
              Ptr<NetDevice> tempNd = ch->GetDevice (i);
837
              Ptr<NetDevice> tempNd = ch->GetDevice (i);
734
              NS_ASSERT (tempNd);
838
              NS_ASSERT (tempNd);
735
              Ptr<Node> tempNode = tempNd->GetNode ();
839
              Ptr<Node> tempNode = tempNd->GetNode ();
736
              uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd);
840
              uint32_t tempIfIndex;
737
              Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
841
              if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
738
              NS_ASSERT (tempIpv4);
842
                {
739
              Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
843
740
              pLSA->AddAttachedRouter (tempAddr);
844
                  Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
845
                  NS_ASSERT (tempIpv4);
846
                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
847
                  pLSA->AddAttachedRouter (tempAddr);
848
849
                }
741
            }
850
            }
742
          m_LSAs.push_back (pLSA);
851
          m_LSAs.push_back (pLSA);
743
          NS_LOG_LOGIC (*pLSA);
852
          NS_LOG_LOGIC (*pLSA);
 Lines 747-779   GlobalRouter::DiscoverLSAs (void) Link Here 
747
  return m_LSAs.size ();
856
  return m_LSAs.size ();
748
}
857
}
749
858
859
//
860
// Given a node and an attached net device, we need to walk the channel to which
861
// the net device is attached and look for the lowest IP address on all of the
862
// devices attached to that channel.  This process is complicated by the fact 
863
// there may be bridge devices associated with any of the net devices attached
864
// to the channel.
865
//
750
  Ipv4Address
866
  Ipv4Address
751
GlobalRouter::FindDesignatedRouterForLink (Ptr<Node> node, 
867
  GlobalRouter::FindDesignatedRouterForLink (Ptr<Node> node, Ptr<NetDevice> ndLocal) const
752
  Ptr<NetDevice> ndLocal) const
753
{
868
{
754
  uint32_t ifIndexLocal = FindIfIndexForDevice(node, ndLocal);
869
  NS_LOG_FUNCTION_NOARGS ();
870
  NS_LOG_LOGIC("**** For node " << node->GetId () << " for net device " << ndLocal );
871
872
  uint32_t ifIndexLocal;
873
  bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
874
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
875
755
  Ptr<Ipv4> ipv4Local = GetObject<Ipv4> ();
876
  Ptr<Ipv4> ipv4Local = GetObject<Ipv4> ();
756
  NS_ASSERT (ipv4Local);
877
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for <Ipv4> interface failed"
878
                       " on node " << node->GetId ());
879
757
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
880
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
758
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
881
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
759
882
760
  Ptr<Channel> ch = ndLocal->GetChannel();
883
  Ptr<Channel> ch = ndLocal->GetChannel();
761
  uint32_t nDevices = ch->GetNDevices();
884
  uint32_t nDevices = ch->GetNDevices();
762
  NS_ASSERT (nDevices);
885
  NS_ASSERT (nDevices);
886
887
  NS_LOG_LOGIC("**** channel " << ch << " has " << nDevices << " net devices");
888
889
  //
890
  // We now have the channel associated with the net device in question.  We
891
  // need to iterate over all of the net devices attached to that channel.
892
  //
893
763
  Ipv4Address lowest = addrLocal;
894
  Ipv4Address lowest = addrLocal;
764
  // iterate all NetDevices and return the lowest numbered IP address 
895
765
  for (uint32_t i = 0; i < nDevices; i++)
896
  for (uint32_t i = 0; i < nDevices; i++)
766
    {
897
    {
767
      Ptr<NetDevice> tempNd = ch->GetDevice (i);
898
      Ptr<NetDevice> ndTemp = ch->GetDevice (i);
768
      NS_ASSERT (tempNd);
899
      NS_ASSERT_MSG (ndTemp, "GlobalRouter::FindDesignatedRouterForLink(): Null device attached to channel");
769
      Ptr<Node> tempNode = tempNd->GetNode ();
900
770
      uint32_t tempIfIndex = FindIfIndexForDevice (tempNode, tempNd);
901
      if (ndTemp == ndLocal)
771
      Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
772
      NS_ASSERT (tempIpv4);
773
      Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
774
      if (tempAddr < addrLocal)
775
        {
902
        {
776
          addrLocal = tempAddr;
903
          continue;
904
        }
905
906
      Ptr<Node> nodeTemp = ndTemp->GetNode ();
907
908
      NS_LOG_LOGIC("**** channel connects to node " << nodeTemp->GetId () << " with net device " << ndTemp);
909
910
      //
911
      // XXX doesn't admit the possibility of a bridge
912
      //
913
      // If the remote device doesn't have an ipv4 interface index associated 
914
      // with it, it cannot be a designated router.
915
      //
916
      uint32_t ifIndexTemp;
917
      bool rc = FindIfIndexForDevice(nodeTemp, ndTemp, ifIndexTemp);
918
      if (rc == false)
919
        {
920
          continue;
921
        }
922
923
      Ptr<Ipv4> ipv4Temp = nodeTemp->GetObject<Ipv4> ();
924
      NS_ASSERT_MSG (ipv4Temp, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for <Ipv4> interface failed"
925
                     " on node " << node->GetId ());
926
927
      Ipv4Address addrTemp = ipv4Temp->GetAddress(ifIndexTemp);
928
929
      NS_LOG_LOGIC("**** net device " << ndTemp << " has Ipv4Address " << addrTemp);
930
      if (addrTemp < addrLocal)
931
        {
932
          addrLocal = addrTemp;
777
        }
933
        }
778
    }
934
    }
779
  return addrLocal;
935
  return addrLocal;
 Lines 852-876   GlobalRouter::GetAdjacent(Ptr<NetDevice> Link Here 
852
}
1008
}
853
1009
854
//
1010
//
855
// Given a node and a net device, find the IPV4 interface index that 
1011
// Given a node and a net device, find an IPV4 interface index that corresponds
856
// corresponds to that net device.
1012
// to that net device.  This function may fail for various reasons.  If a node
1013
// does not have an internet stack (for example if it is a bridge) we won't have
1014
// an IPv4 at all.  If the node does have a stack, but the net device in question
1015
// is bridged, there will not be an interface associated directly with the device.
857
//
1016
//
858
  uint32_t
1017
  bool
859
GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const
1018
GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const
860
{
1019
{
861
  NS_LOG_FUNCTION_NOARGS ();
1020
  NS_LOG_FUNCTION_NOARGS ();
1021
  NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd );
1022
862
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1023
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
863
  NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed");
1024
  if (ipv4 == 0)
1025
    {
1026
      NS_LOG_LOGIC ("**** No Ipv4 interface on node " << node->GetId ());
1027
      return false;
1028
    }
1029
864
  for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
1030
  for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
865
    {
1031
    {
866
      if (ipv4->GetNetDevice(i) == nd) 
1032
      if (ipv4->GetNetDevice(i) == nd) 
867
        {
1033
        {
868
          return i;
1034
          NS_LOG_LOGIC ("**** Device " << nd << " has associated ipv4 index " << i);
1035
          index = i;
1036
          return true;
869
        }
1037
        }
870
    }
1038
    }
871
1039
872
  NS_ASSERT_MSG(0, "Cannot find interface for device");
1040
          NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index");
873
  return 0;
1041
  return false;
874
}
1042
}
875
1043
876
} // namespace ns3
1044
} // namespace ns3
(-)a/src/routing/global-routing/global-router-interface.h (-1 / +1 lines)
 Lines 639-645   private: Link Here 
639
  void ClearLSAs (void);
639
  void ClearLSAs (void);
640
640
641
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
641
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
642
  uint32_t FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const;
642
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
643
  Ipv4Address FindDesignatedRouterForLink (Ptr<Node> node,   
643
  Ipv4Address FindDesignatedRouterForLink (Ptr<Node> node,   
644
    Ptr<NetDevice> ndLocal) const;
644
    Ptr<NetDevice> ndLocal) const;
645
645
(-)a/examples/csma-bridge-one-hop.cc (-1 / +2 lines)
 Lines 176-182   main (int argc, char *argv[]) Link Here 
176
176
177
  // 
177
  // 
178
  // Create router nodes, initialize routing database and set up the routing
178
  // Create router nodes, initialize routing database and set up the routing
179
  // tables in the nodes.
179
  // tables in the nodes.  We excuse the bridge nodes from having to serve as
180
  // routers, since they don't even have internet stacks on them.
180
  //
181
  //
181
  NodeContainer routerNodes (n0, n1, n2, n3, n4);
182
  NodeContainer routerNodes (n0, n1, n2, n3, n4);
182
  GlobalRouteManager::PopulateRoutingTables (routerNodes);
183
  GlobalRouteManager::PopulateRoutingTables (routerNodes);
(-)a/src/routing/global-routing/global-router-interface.cc (-87 / +137 lines)
 Lines 530-535   GlobalRouter::DiscoverLSAs (void) Link Here 
530
// bridge devices also take up an "extra" net device.
530
// bridge devices also take up an "extra" net device.
531
//
531
//
532
  uint32_t numDevices = node->GetNDevices();
532
  uint32_t numDevices = node->GetNDevices();
533
  NS_LOG_LOGIC ("*************************");
533
  NS_LOG_LOGIC ("numDevices = " << numDevices);
534
  NS_LOG_LOGIC ("numDevices = " << numDevices);
534
535
535
//
536
//
 Lines 538-555   GlobalRouter::DiscoverLSAs (void) Link Here 
538
// the "everything else" class of devices.
539
// the "everything else" class of devices.
539
//
540
//
540
// To do this, we wander through all of the devices on the node looking for
541
// To do this, we wander through all of the devices on the node looking for
541
// bridge net devices.  We then add any net devices associated to a bridge
542
// bridge net devices.  We then add any net devices associated with each bridge
542
// to a list of bridged devices.  These devices will not be treated as stand-
543
// to a list of bridged devices.  These devices will be treated as a special
543
// alone devices later.
544
// case later.
544
//
545
//
545
  std::vector<Ptr<NetDevice> > bridgedDevices;
546
  std::vector<Ptr<NetDevice> > bridgedDevices;
546
547
547
  NS_LOG_LOGIC ("*************************");
548
549
  NS_LOG_LOGIC ("numDevices = " << numDevices);
550
  for (uint32_t i = 0; i < numDevices; ++i)
548
  for (uint32_t i = 0; i < numDevices; ++i)
551
    {
549
    {
552
      Ptr<NetDevice> nd = node->GetDevice(i);
550
      Ptr<NetDevice> nd = node->GetDevice(i);
551
553
      if (nd->IsBridge ())
552
      if (nd->IsBridge ())
554
        {
553
        {
555
          NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge");
554
          NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge");
 Lines 597-603   GlobalRouter::DiscoverLSAs (void) Link Here 
597
596
598
      //
597
      //
599
      // Check to see if the net device we just got has a corresponding IP 
598
      // Check to see if the net device we just got has a corresponding IP 
600
      // interface (could be a pure L2 NetDevice).  
599
      // interface (could be a pure L2 NetDevice that is not a bridge).  
601
      //
600
      //
602
      bool isIp = false;
601
      bool isIp = false;
603
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
602
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
 Lines 615-620   GlobalRouter::DiscoverLSAs (void) Link Here 
615
          continue;
614
          continue;
616
        }
615
        }
617
616
617
//
618
// We have a net device that we need to check out.  If it suports broadcast and
619
// is not a point-point link, then it will be either a stub network or a transit
620
// network depending on the number of routers.
621
//
618
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
622
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
619
        {
623
        {
620
          NS_LOG_LOGIC ("**** Broadcast link");
624
          NS_LOG_LOGIC ("**** Broadcast link");
 Lines 636-656   GlobalRouter::DiscoverLSAs (void) Link Here 
636
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
640
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
637
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
641
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
638
//
642
//
639
// Now, we're going to walk over to the remote net device on the other end of 
643
// Check to see if the net device is connected to a channel/network that has
640
// the point-to-point channel we now know we have.  This is where our adjacent 
644
// another router on it.  If there is no other router on the link (but us) then
641
// router (to use OSPF lingo) is running.  
645
// this is a stub network.  If we find another router, then what we have here
646
// is a transit network.
642
//
647
//
643
          Ptr<Channel> ch = ndLocal->GetChannel();
648
          if (AnotherRouterOnLink (ndLocal) == false)
644
          uint32_t nDevices = ch->GetNDevices();
645
          if (nDevices == 1)
646
            {
649
            {
647
              // This is a stub broadcast interface
650
              //
648
              NS_LOG_LOGIC("**** Router-LSA stub broadcast link");
651
              // This is a net device connected to a stub network
649
              // XXX in future, need to consider if >1 includes other routers
652
              //
653
              NS_LOG_LOGIC("**** Router-LSA Stub Network");
650
              plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
654
              plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
651
              // Link ID is IP network number of attached network
655
              // 
656
              // According to OSPF, the Link ID is the IP network number of 
657
              // the attached network.
658
              //
652
              plr->SetLinkId (addrLocal.CombineMask(maskLocal));
659
              plr->SetLinkId (addrLocal.CombineMask(maskLocal));
653
              // Link Data is network mask; convert to Ipv4Address
660
              //
661
              // and the Link Data is the network mask; converted to Ipv4Address
662
              //
654
              Ipv4Address maskLocalAddr;
663
              Ipv4Address maskLocalAddr;
655
              maskLocalAddr.Set(maskLocal.Get ());
664
              maskLocalAddr.Set(maskLocal.Get ());
656
              plr->SetLinkData (maskLocalAddr);
665
              plr->SetLinkData (maskLocalAddr);
 Lines 661-680   GlobalRouter::DiscoverLSAs (void) Link Here 
661
            }
670
            }
662
          else
671
          else
663
            {
672
            {
664
              NS_LOG_LOGIC ("**** Router-LSA Broadcast link");
673
              //
665
              // multiple routers on a broadcast interface
674
              // We have multiple routers on a broadcast interface, so this is
666
              // lowest IP address is designated router
675
              // a transit network.
676
              //
677
              NS_LOG_LOGIC ("**** Router-LSA Transit Network");
667
              plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
678
              plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
668
              // Link ID is IP interface address of designated router
679
              // 
669
              Ipv4Address desigRtr = 
680
              // By definition, the router with the lowest IP address is the
670
                FindDesignatedRouterForLink (node, ndLocal);
681
              // designated router for the network.  OSPF says that the Link ID
682
              // gets the IP interface address of the designated router in this 
683
              // case.
684
              //
685
              Ipv4Address desigRtr = FindDesignatedRouterForLink (ndLocal);
671
              if (desigRtr == addrLocal) 
686
              if (desigRtr == addrLocal) 
672
                {
687
                {
673
                  listOfDRInterfaces.push_back (ndLocal);
688
                  listOfDRInterfaces.push_back (ndLocal);
674
                  NS_LOG_LOGIC (node->GetId () << " is a DR");
689
                  NS_LOG_LOGIC (node->GetId () << " is a DR");
675
                }
690
                }
676
              plr->SetLinkId (desigRtr);
691
              plr->SetLinkId (desigRtr);
677
              // Link Data is router's own IP address
692
              //
693
              // OSPF says that the Link Data is this router's own IP address.
694
              //
678
              plr->SetLinkData (addrLocal);
695
              plr->SetLinkData (addrLocal);
679
              plr->SetMetric (metricLocal);
696
              plr->SetMetric (metricLocal);
680
              pLSA->AddLinkRecord (plr);
697
              pLSA->AddLinkRecord (plr);
 Lines 787-792   GlobalRouter::DiscoverLSAs (void) Link Here 
787
// kinds of advertisements (than Router LSAs).
804
// kinds of advertisements (than Router LSAs).
788
//
805
//
789
  m_LSAs.push_back (pLSA);
806
  m_LSAs.push_back (pLSA);
807
  NS_LOG_LOGIC ("========== Link State Advertisement for node " << node->GetId () << " ==========");
790
  NS_LOG_LOGIC (*pLSA);
808
  NS_LOG_LOGIC (*pLSA);
791
809
792
// 
810
// 
 Lines 795-813   GlobalRouter::DiscoverLSAs (void) Link Here 
795
//
813
//
796
  if (listOfDRInterfaces.size () > 0)
814
  if (listOfDRInterfaces.size () > 0)
797
    {
815
    {
816
      NS_LOG_LOGIC ("Build Network LSA");
798
      for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
817
      for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
799
        i != listOfDRInterfaces.end (); i++)
818
        i != listOfDRInterfaces.end (); i++)
800
        {
819
        {
801
//
820
//
802
// Build one NetworkLSA for each interface that is a DR
821
// Build one NetworkLSA for each net device talking to a netwok that we are the 
822
// designated router for.
803
//
823
//
804
          Ptr<NetDevice> ndLocal = *i;
824
          Ptr<NetDevice> ndLocal = *i;
805
806
          //
807
          // We are working with a list of net devices off of the local node
808
          // on which we found a designated router.  We assume there must be
809
          // an associated ipv4 interface index.
810
          //
811
825
812
          uint32_t ifIndexLocal;
826
          uint32_t ifIndexLocal;
813
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
827
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
 Lines 823-833   GlobalRouter::DiscoverLSAs (void) Link Here 
823
          pLSA->SetNetworkLSANetworkMask (maskLocal);
837
          pLSA->SetNetworkLSANetworkMask (maskLocal);
824
          pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
838
          pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
825
//
839
//
826
// XXX Doesn't deal with bridging
827
//
828
// Build a list of AttachedRouters by walking the devices in the channel
840
// Build a list of AttachedRouters by walking the devices in the channel
829
// and, if we find an IPv4 interface associated with that device, we
841
// and, if we find a node with a GlobalRouter interface and an IPv4 
830
// call it an attached router.  
842
// interface associated with that device, we call it an attached router.  
831
//
843
//
832
          Ptr<Channel> ch = ndLocal->GetChannel();
844
          Ptr<Channel> ch = ndLocal->GetChannel();
833
          uint32_t nDevices = ch->GetNDevices();
845
          uint32_t nDevices = ch->GetNDevices();
 Lines 837-851   GlobalRouter::DiscoverLSAs (void) Link Here 
837
              Ptr<NetDevice> tempNd = ch->GetDevice (i);
849
              Ptr<NetDevice> tempNd = ch->GetDevice (i);
838
              NS_ASSERT (tempNd);
850
              NS_ASSERT (tempNd);
839
              Ptr<Node> tempNode = tempNd->GetNode ();
851
              Ptr<Node> tempNode = tempNd->GetNode ();
852
//
853
// Does the node in question have a GlobalRouter interface?  If not it can
854
// hardly be considered an attached router.
855
//
856
              Ptr<GlobalRouter> rtr = tempNode->GetObject<GlobalRouter> ();
857
              if (rtr == 0)
858
                { 
859
                  continue;
860
                }
861
862
//
863
// Does the attached node have an ipv4 interface for the device we're probing?
864
// If not, it can't play router.
865
//
840
              uint32_t tempIfIndex;
866
              uint32_t tempIfIndex;
841
              if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
867
              if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
842
                {
868
                {
843
844
                  Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
869
                  Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
845
                  NS_ASSERT (tempIpv4);
870
                  NS_ASSERT (tempIpv4);
846
                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
871
                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
847
                  pLSA->AddAttachedRouter (tempAddr);
872
                  pLSA->AddAttachedRouter (tempAddr);
848
849
                }
873
                }
850
            }
874
            }
851
          m_LSAs.push_back (pLSA);
875
          m_LSAs.push_back (pLSA);
 Lines 857-938   GlobalRouter::DiscoverLSAs (void) Link Here 
857
}
881
}
858
882
859
//
883
//
860
// Given a node and an attached net device, we need to walk the channel to which
884
// Given a local net device, we need to walk the channel to which the net device is
861
// the net device is attached and look for the lowest IP address on all of the
885
// attached and look for nodes with GlobalRouter interfaces on them (one of them 
862
// devices attached to that channel.  This process is complicated by the fact 
886
// will be us).  Of these, the router with the lowest IP address on the net device 
863
// there may be bridge devices associated with any of the net devices attached
887
// connecting to the channel becomes the designated router for the link.
864
// to the channel.
865
//
888
//
866
  Ipv4Address
889
  Ipv4Address
867
  GlobalRouter::FindDesignatedRouterForLink (Ptr<Node> node, Ptr<NetDevice> ndLocal) const
890
GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const
868
{
891
{
869
  NS_LOG_FUNCTION_NOARGS ();
892
  NS_LOG_FUNCTION_NOARGS ();
870
  NS_LOG_LOGIC("**** For node " << node->GetId () << " for net device " << ndLocal );
871
872
  uint32_t ifIndexLocal;
873
  bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
874
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
875
876
  Ptr<Ipv4> ipv4Local = GetObject<Ipv4> ();
877
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for <Ipv4> interface failed"
878
                       " on node " << node->GetId ());
879
880
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
881
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
882
893
883
  Ptr<Channel> ch = ndLocal->GetChannel();
894
  Ptr<Channel> ch = ndLocal->GetChannel();
884
  uint32_t nDevices = ch->GetNDevices();
895
  uint32_t nDevices = ch->GetNDevices();
885
  NS_ASSERT (nDevices);
896
  NS_ASSERT (nDevices);
886
897
887
  NS_LOG_LOGIC("**** channel " << ch << " has " << nDevices << " net devices");
898
  Ipv4Address addr ("255.255.255.255");
899
900
  for (uint32_t i = 0; i < nDevices; i++)
901
    {
902
      Ptr<NetDevice> currentNd = ch->GetDevice (i);
903
      NS_ASSERT (currentNd);
904
905
      Ptr<Node> currentNode = currentNd->GetNode ();
906
      NS_ASSERT (currentNode);
907
      //
908
      // We require a designated router to have a GlobalRouter interface and
909
      // an internet stack that includes the Ipv4 interface.
910
      //
911
      Ptr<GlobalRouter> rtr = currentNode->GetObject<GlobalRouter> ();
912
      Ptr<Ipv4> ipv4 = currentNode->GetObject<Ipv4> ();
913
      if (rtr == 0 || ipv4 == 0 )
914
        {
915
          continue;
916
        }
917
918
      //
919
      // This node could be a designated router, so we can check and see if
920
      // it has a lower IP address than the one we have.  In order to have
921
      // an IP address, it needs to have an interface index.  If it doesen't
922
      // have an interface index directly, it's probably part of a bridge
923
      // net device XXX which is not yet handled.
924
      //
925
      uint32_t currentIfIndex;
926
      bool rc = FindIfIndexForDevice(currentNode, currentNd, currentIfIndex);
927
      if (rc == false)
928
        {
929
          continue;
930
        }
931
932
      //
933
      // Okay, get the IP address corresponding to the interface we're 
934
      // examining and if it's the lowest so far, remember it.
935
      //
936
      Ipv4Address currentAddr = ipv4->GetAddress(currentIfIndex);
937
938
      if (currentAddr < addr)
939
        {
940
          addr = currentAddr;
941
        }
942
    }
888
943
889
  //
944
  //
890
  // We now have the channel associated with the net device in question.  We
945
  // Return the lowest IP address found, which will become the designated router
891
  // need to iterate over all of the net devices attached to that channel.
946
  // for the link.
892
  //
947
  //
948
  NS_ASSERT_MSG (addr.IsBroadcast() == false, "GlobalRouter::FindDesignatedRouterForLink(): Bogus address");
949
  return addr;
950
}
893
951
894
  Ipv4Address lowest = addrLocal;
952
//
953
// Given a node and an attached net device, take a look off in the channel to 
954
// which the net device is attached and look for a node on the other side
955
// that has a GlobalRouter interface aggregated.
956
//
957
  bool
958
GlobalRouter::AnotherRouterOnLink (Ptr<NetDevice> nd) const
959
{
960
  NS_LOG_FUNCTION_NOARGS ();
961
962
  Ptr<Channel> ch = nd->GetChannel();
963
  uint32_t nDevices = ch->GetNDevices();
964
  NS_ASSERT (nDevices);
895
965
896
  for (uint32_t i = 0; i < nDevices; i++)
966
  for (uint32_t i = 0; i < nDevices; i++)
897
    {
967
    {
898
      Ptr<NetDevice> ndTemp = ch->GetDevice (i);
968
      Ptr<NetDevice> ndTemp = ch->GetDevice (i);
899
      NS_ASSERT_MSG (ndTemp, "GlobalRouter::FindDesignatedRouterForLink(): Null device attached to channel");
969
      NS_ASSERT (ndTemp);
900
970
901
      if (ndTemp == ndLocal)
971
      if (ndTemp == nd)
902
        {
972
        {
903
          continue;
973
          continue;
904
        }
974
        }
905
975
906
      Ptr<Node> nodeTemp = ndTemp->GetNode ();
976
      Ptr<Node> nodeTemp = ndTemp->GetNode ();
977
      NS_ASSERT (nodeTemp);
907
978
908
      NS_LOG_LOGIC("**** channel connects to node " << nodeTemp->GetId () << " with net device " << ndTemp);
979
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
909
980
      if (rtr)
910
      //
911
      // XXX doesn't admit the possibility of a bridge
912
      //
913
      // If the remote device doesn't have an ipv4 interface index associated 
914
      // with it, it cannot be a designated router.
915
      //
916
      uint32_t ifIndexTemp;
917
      bool rc = FindIfIndexForDevice(nodeTemp, ndTemp, ifIndexTemp);
918
      if (rc == false)
919
        {
981
        {
920
          continue;
982
          return true;
921
        }
922
923
      Ptr<Ipv4> ipv4Temp = nodeTemp->GetObject<Ipv4> ();
924
      NS_ASSERT_MSG (ipv4Temp, "GlobalRouter::FindDesignatedRouterForLink(): GetObject for <Ipv4> interface failed"
925
                     " on node " << node->GetId ());
926
927
      Ipv4Address addrTemp = ipv4Temp->GetAddress(ifIndexTemp);
928
929
      NS_LOG_LOGIC("**** net device " << ndTemp << " has Ipv4Address " << addrTemp);
930
      if (addrTemp < addrLocal)
931
        {
932
          addrLocal = addrTemp;
933
        }
983
        }
934
    }
984
    }
935
  return addrLocal;
985
  return false;
936
}
986
}
937
987
938
  uint32_t 
988
  uint32_t 
(-)a/src/routing/global-routing/global-router-interface.h (-2 / +2 lines)
 Lines 640-647   private: Link Here 
640
640
641
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
641
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
642
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
642
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
643
  Ipv4Address FindDesignatedRouterForLink (Ptr<Node> node,   
643
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
644
    Ptr<NetDevice> ndLocal) const;
644
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
645
645
646
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
646
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
647
  ListOfLSAs_t m_LSAs;
647
  ListOfLSAs_t m_LSAs;
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-3 / +3 lines)
 Lines 399-412   GlobalRouteManagerImpl::BuildGlobalRouti Link Here 
399
{
399
{
400
  NS_LOG_FUNCTION_NOARGS ();
400
  NS_LOG_FUNCTION_NOARGS ();
401
//
401
//
402
// Walk the list of nodes looking for the GlobalRouter Interface.
402
// Walk the list of nodes looking for the GlobalRouter Interface.  Nodes with
403
// global router interfaces are, not too surprisingly, our routers.
403
//
404
//
404
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
405
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
405
    {
406
    {
406
      Ptr<Node> node = *i;
407
      Ptr<Node> node = *i;
407
408
408
      Ptr<GlobalRouter> rtr = 
409
      Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
409
        node->GetObject<GlobalRouter> ();
410
//      
410
//      
411
// Ignore nodes that aren't participating in routing.
411
// Ignore nodes that aren't participating in routing.
412
//
412
//
(-)a/src/routing/global-routing/global-router-interface.cc (-328 / +367 lines)
 Lines 26-31    Link Here 
26
#include "ns3/node.h"
26
#include "ns3/node.h"
27
#include "ns3/ipv4.h"
27
#include "ns3/ipv4.h"
28
#include "ns3/bridge-net-device.h"
28
#include "ns3/bridge-net-device.h"
29
#include "ns3/net-device-container.h"
29
#include "global-router-interface.h"
30
#include "global-router-interface.h"
30
#include <vector>
31
#include <vector>
31
32
 Lines 489-496   GlobalRouter::GetRouterId (void) const Link Here 
489
}
490
}
490
491
491
//
492
//
492
// Go out and discover any adjacent routers and build the Link State 
493
// DiscoverLSAs is called on all nodes in the system that have a GlobalRouter
493
// Advertisements that reflect them and their associated networks.
494
// interface aggregated.  We need to go out and discover any adjacent routers 
495
// and build the Link State Advertisements that reflect them and their associated
496
// networks.
494
// 
497
// 
495
  uint32_t 
498
  uint32_t 
496
GlobalRouter::DiscoverLSAs (void)
499
GlobalRouter::DiscoverLSAs (void)
 Lines 501-573   GlobalRouter::DiscoverLSAs (void) Link Here 
501
  NS_LOG_LOGIC ("For node " << node->GetId () );
504
  NS_LOG_LOGIC ("For node " << node->GetId () );
502
505
503
  ClearLSAs ();
506
  ClearLSAs ();
504
//
505
// While building the router-LSA, keep a list of those NetDevices for
506
// which I am the designated router and need to later build a NetworkLSA
507
//
508
  std::list<Ptr<NetDevice> > listOfDRInterfaces;
509
507
510
//
508
  //
511
// We're aggregated to a node.  We need to ask the node for a pointer to its
509
  // While building the Router-LSA, keep a list of those NetDevices for
512
// Ipv4 interface.  This is where the information regarding the attached 
510
  // which the current node is the designated router and we will later build 
513
// interfaces lives.  If we're a router, we had better have an Ipv4 interface.
511
  // a NetworkLSA for.
514
//
512
  //
513
  NetDeviceContainer c;
514
515
  //
516
  // We're aggregated to a node.  We need to ask the node for a pointer to its
517
  // Ipv4 interface.  This is where the information regarding the attached 
518
  // interfaces lives.  If we're a router, we had better have an Ipv4 interface.
519
  //
515
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
520
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
516
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
521
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::DiscoverLSAs (): GetObject for <Ipv4> interface failed");
517
//
522
518
// Each node is a router and so originates a Router-LSA
523
  //
519
//
524
  // Every router node originates a Router-LSA
525
  //
520
  GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
526
  GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
521
  pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
527
  pLSA->SetLSType (GlobalRoutingLSA::RouterLSA);
522
  pLSA->SetLinkStateId (m_routerId);
528
  pLSA->SetLinkStateId (m_routerId);
523
  pLSA->SetAdvertisingRouter (m_routerId);
529
  pLSA->SetAdvertisingRouter (m_routerId);
524
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
530
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
525
531
526
//
532
  //
527
// Ask the node for the number of net devices attached. This isn't necessarily 
533
  // Ask the node for the number of net devices attached. This isn't necessarily 
528
// equal to the number of links to adjacent nodes (other routers) as the number
534
  // equal to the number of links to adjacent nodes (other routers) as the number
529
// of devices may include those for stub networks (e.g., ethernets, etc.) and 
535
  // of devices may include those for stub networks (e.g., ethernets, etc.) and 
530
// bridge devices also take up an "extra" net device.
536
  // bridge devices also take up an "extra" net device.
531
//
537
  //
532
  uint32_t numDevices = node->GetNDevices();
538
  uint32_t numDevices = node->GetNDevices();
533
  NS_LOG_LOGIC ("*************************");
534
  NS_LOG_LOGIC ("numDevices = " << numDevices);
535
536
//
537
// There are two broad classes of devices:  bridges in combination with the
538
// devices they bridge and everything else.  We need to first discover all of
539
// the "everything else" class of devices.
540
//
541
// To do this, we wander through all of the devices on the node looking for
542
// bridge net devices.  We then add any net devices associated with each bridge
543
// to a list of bridged devices.  These devices will be treated as a special
544
// case later.
545
//
546
  std::vector<Ptr<NetDevice> > bridgedDevices;
547
548
  for (uint32_t i = 0; i < numDevices; ++i)
549
    {
550
      Ptr<NetDevice> nd = node->GetDevice(i);
551
552
      if (nd->IsBridge ())
553
        {
554
          NS_LOG_LOGIC ("**** Net device " << nd << "is a bridge");
555
          //
556
          // XXX There is only one kind of bridge device so far.  We agreed to
557
          // assume that it is Gustavo's learning bridge until there is a need
558
          // to deal with another.  At that time, we'll have to break out a
559
          // bridge interface.
560
          //
561
          Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
562
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
563
564
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
565
            {
566
              NS_LOG_LOGIC ("**** Net device " << bnd << "is a bridged device");
567
              bridgedDevices.push_back (bnd->GetBridgePort (j));
568
            }
569
        }
570
    }
571
539
572
  //
540
  //
573
  // Iterate through the devices on the node and walk the channel to see what's
541
  // Iterate through the devices on the node and walk the channel to see what's
 Lines 576-602   GlobalRouter::DiscoverLSAs (void) Link Here 
576
  for (uint32_t i = 0; i < numDevices; ++i)
544
  for (uint32_t i = 0; i < numDevices; ++i)
577
    {
545
    {
578
      Ptr<NetDevice> ndLocal = node->GetDevice(i);
546
      Ptr<NetDevice> ndLocal = node->GetDevice(i);
579
      //
580
      // If the device in question is on our list of bridged devices, then we
581
      // just ignore it.  It will be dealt with correctly when we probe the 
582
      // bridge device it belongs to.  It is the case that the bridge code
583
      // assumes that bridged devices must not have IP interfaces, and so it 
584
      // may actually sufficient to perform the test for IP interface below, 
585
      // but that struck me as too indirect a condition.
586
      //
587
      for (uint32_t j = 0; j < bridgedDevices.size (); ++j)
588
        {
589
          if (ndLocal == bridgedDevices[j])
590
            {
591
              NS_LOG_LOGIC ("**** Skipping Bridged Device");
592
593
              continue;
594
            }
595
        }
596
547
597
      //
548
      //
598
      // Check to see if the net device we just got has a corresponding IP 
549
      // Check to see if the net device we just got has a corresponding IP 
599
      // interface (could be a pure L2 NetDevice that is not a bridge).  
550
      // interface (could be a pure L2 NetDevice).
600
      //
551
      //
601
      bool isIp = false;
552
      bool isIp = false;
602
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
553
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
 Lines 614-883   GlobalRouter::DiscoverLSAs (void) Link Here 
614
          continue;
565
          continue;
615
        }
566
        }
616
567
617
//
568
      //
618
// We have a net device that we need to check out.  If it suports broadcast and
569
      // We have a net device that we need to check out.  If it suports 
619
// is not a point-point link, then it will be either a stub network or a transit
570
      // broadcast and is not a point-point link, then it will be either a stub 
620
// network depending on the number of routers.
571
      // network or a transit network depending on the number of routers on
621
//
572
      // the segment.  We add the appropriate link record to the LSA.
573
      //
574
      // If the device is a point to point link, we treat it separately.  In
575
      // that case, there always two link records added.
576
      //
622
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
577
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
623
        {
578
        {
624
          NS_LOG_LOGIC ("**** Broadcast link");
579
          NS_LOG_LOGIC ("**** Broadcast link");
625
          GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
580
          ProcessBroadcastLink (ndLocal, pLSA, c);
626
//
627
// We need to determine whether we are on a transit or stub network
628
// If we find at least one more router on this channel, we are a transit
629
// network.  If we're the only router, we're on a stub.
630
//
631
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
632
// just found.  This is still the IP on the local side of the channel.
633
//
634
          uint32_t ifIndexLocal;
635
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
636
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
637
638
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
639
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
640
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
641
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
642
//
643
// Check to see if the net device is connected to a channel/network that has
644
// another router on it.  If there is no other router on the link (but us) then
645
// this is a stub network.  If we find another router, then what we have here
646
// is a transit network.
647
//
648
          if (AnotherRouterOnLink (ndLocal) == false)
649
            {
650
              //
651
              // This is a net device connected to a stub network
652
              //
653
              NS_LOG_LOGIC("**** Router-LSA Stub Network");
654
              plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
655
              // 
656
              // According to OSPF, the Link ID is the IP network number of 
657
              // the attached network.
658
              //
659
              plr->SetLinkId (addrLocal.CombineMask(maskLocal));
660
              //
661
              // and the Link Data is the network mask; converted to Ipv4Address
662
              //
663
              Ipv4Address maskLocalAddr;
664
              maskLocalAddr.Set(maskLocal.Get ());
665
              plr->SetLinkData (maskLocalAddr);
666
              plr->SetMetric (metricLocal);
667
              pLSA->AddLinkRecord(plr);
668
              plr = 0;
669
              continue;
670
            }
671
          else
672
            {
673
              //
674
              // We have multiple routers on a broadcast interface, so this is
675
              // a transit network.
676
              //
677
              NS_LOG_LOGIC ("**** Router-LSA Transit Network");
678
              plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
679
              // 
680
              // By definition, the router with the lowest IP address is the
681
              // designated router for the network.  OSPF says that the Link ID
682
              // gets the IP interface address of the designated router in this 
683
              // case.
684
              //
685
              Ipv4Address desigRtr = FindDesignatedRouterForLink (ndLocal);
686
              if (desigRtr == addrLocal) 
687
                {
688
                  listOfDRInterfaces.push_back (ndLocal);
689
                  NS_LOG_LOGIC (node->GetId () << " is a DR");
690
                }
691
              plr->SetLinkId (desigRtr);
692
              //
693
              // OSPF says that the Link Data is this router's own IP address.
694
              //
695
              plr->SetLinkData (addrLocal);
696
              plr->SetMetric (metricLocal);
697
              pLSA->AddLinkRecord (plr);
698
              plr = 0;
699
              continue;
700
            }
701
        }
581
        }
702
      else if (ndLocal->IsPointToPoint () )
582
      else if (ndLocal->IsPointToPoint () )
703
        {
583
        {
704
          NS_LOG_LOGIC ("**** Router-LSA Point-to-point device");
584
          NS_LOG_LOGIC ("**** Point=to-point link");
705
//
585
          ProcessPointToPointLink (ndLocal, pLSA);
706
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
707
// just found.  This is still the IP on the local side of the channel.  There 
708
// is a function to do this used down in the guts of the stack, but it's not 
709
// exported so we had to whip up an equivalent.
710
//
711
          uint32_t ifIndexLocal;
712
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
713
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
714
//
715
// Now that we have the Ipv4 interface index, we can get the address and mask
716
// we need.
717
//
718
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
719
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
720
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
721
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
722
//
723
// Now, we're going to walk over to the remote net device on the other end of 
724
// the point-to-point channel we now know we have.  This is where our adjacent 
725
// router (to use OSPF lingo) is running.  
726
//
727
          Ptr<Channel> ch = ndLocal->GetChannel();
728
          if (ch == NULL)
729
            {
730
              continue;
731
            }
732
//
733
// Get the net device on the other side of the point-to-point channel.
734
//
735
          Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
736
//
737
// The adjacent net device is aggregated to a node.  We need to ask that net 
738
// device for its node, then ask that node for its Ipv4 interface.  Note a
739
// requirement that nodes on either side of a point-to-point link must have 
740
// internet stacks.
741
//
742
          Ptr<Node> nodeRemote = ndRemote->GetNode();
743
          Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
744
          NS_ABORT_MSG_UNLESS (ipv4Remote, 
745
            "GlobalRouter::DiscoverLSAs (): GetObject for remote <Ipv4> failed");
746
//
747
// Per the OSPF spec, we're going to need the remote router ID, so we might as
748
// well get it now.
749
//
750
// While we're at it, further note the requirement that nodes on either side of
751
// a point-to-point link must participateg in global routing and therefore have
752
// a GlobalRouter interface aggregated.
753
//
754
          Ptr<GlobalRouter> srRemote = nodeRemote->GetObject<GlobalRouter> ();
755
          NS_ABORT_MSG_UNLESS(srRemote, 
756
            "GlobalRouter::DiscoverLSAs(): GetObject for remote <GlobalRouter> failed");
757
758
          Ipv4Address rtrIdRemote = srRemote->GetRouterId();
759
          NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
760
//
761
// Now, just like we did above, we need to get the IP interface index for the 
762
// net device on the other end of the point-to-point channel.  We have yet another
763
// assumption that point to point devices are incompatible with bridges and that
764
// the remote device must have an associated ip interface.
765
//
766
          uint32_t ifIndexRemote;
767
          rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
768
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with remote device");
769
//
770
// Now that we have the Ipv4 interface, we can get the (remote) address and
771
// mask we need.
772
//
773
          Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
774
          Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
775
          NS_LOG_LOGIC ("Working with remote address " << addrRemote);
776
//
777
// Now we can fill out the link records for this link.  There are always two
778
// link records; the first is a point-to-point record describing the link and
779
// the second is a stub network record with the network number.
780
//
781
          GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
782
          plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
783
          plr->SetLinkId (rtrIdRemote);
784
          plr->SetLinkData (addrLocal);
785
          plr->SetMetric (metricLocal);
786
          pLSA->AddLinkRecord (plr);
787
          plr = 0;
788
789
          plr = new GlobalRoutingLinkRecord;
790
          plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
791
          plr->SetLinkId (addrRemote);
792
          plr->SetLinkData (Ipv4Address(maskRemote.Get()));  // Frown
793
          plr->SetMetric (metricLocal);
794
          pLSA->AddLinkRecord (plr);
795
          plr = 0;
796
        }
586
        }
797
      else
587
      else
798
        {
588
        {
799
          NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
589
          NS_ASSERT_MSG(0, "GlobalRouter::DiscoverLSAs (): unknown link type");
800
        }
590
        }
801
    }
591
    }
802
//
592
803
// The LSA goes on a list of LSAs in case we want to begin exporting other
593
  NS_LOG_LOGIC ("========== LSA for node " << node->GetId () << " ==========");
804
// kinds of advertisements (than Router LSAs).
594
  NS_LOG_LOGIC (*pLSA);
805
//
806
  m_LSAs.push_back (pLSA);
595
  m_LSAs.push_back (pLSA);
807
  NS_LOG_LOGIC ("========== Link State Advertisement for node " << node->GetId () << " ==========");
596
  pLSA = 0;
808
  NS_LOG_LOGIC (*pLSA);
809
597
810
// 
598
  // 
811
// Now, determine whether we need to build a NetworkLSA.  This is the case if
599
  // Now, determine whether we need to build a NetworkLSA.  This is the case if
812
// we found at least one designated router.
600
  // we found at least one designated router.
813
//
601
  //
814
  if (listOfDRInterfaces.size () > 0)
602
  uint32_t nDesignatedRouters = c.GetN ();
603
  if (nDesignatedRouters > 0)
815
    {
604
    {
816
      NS_LOG_LOGIC ("Build Network LSA");
605
      NS_LOG_LOGIC ("Build Network LSAs");
817
      for (std::list<Ptr<NetDevice> >::iterator i = listOfDRInterfaces.begin ();
606
      BuildNetworkLSAs (c);
818
        i != listOfDRInterfaces.end (); i++)
819
        {
820
//
821
// Build one NetworkLSA for each net device talking to a netwok that we are the 
822
// designated router for.
823
//
824
          Ptr<NetDevice> ndLocal = *i;
825
826
          uint32_t ifIndexLocal;
827
          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
828
          NS_ABORT_MSG_IF (rc == false, "GlobalRouter::DiscoverLSAs (): No interface index associated with device");
829
830
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
831
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
832
833
          GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
834
          pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA);
835
          pLSA->SetLinkStateId (addrLocal);
836
          pLSA->SetAdvertisingRouter (m_routerId);
837
          pLSA->SetNetworkLSANetworkMask (maskLocal);
838
          pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
839
//
840
// Build a list of AttachedRouters by walking the devices in the channel
841
// and, if we find a node with a GlobalRouter interface and an IPv4 
842
// interface associated with that device, we call it an attached router.  
843
//
844
          Ptr<Channel> ch = ndLocal->GetChannel();
845
          uint32_t nDevices = ch->GetNDevices();
846
          NS_ASSERT (nDevices);
847
          for (uint32_t i = 0; i < nDevices; i++)
848
            {
849
              Ptr<NetDevice> tempNd = ch->GetDevice (i);
850
              NS_ASSERT (tempNd);
851
              Ptr<Node> tempNode = tempNd->GetNode ();
852
//
853
// Does the node in question have a GlobalRouter interface?  If not it can
854
// hardly be considered an attached router.
855
//
856
              Ptr<GlobalRouter> rtr = tempNode->GetObject<GlobalRouter> ();
857
              if (rtr == 0)
858
                { 
859
                  continue;
860
                }
861
862
//
863
// Does the attached node have an ipv4 interface for the device we're probing?
864
// If not, it can't play router.
865
//
866
              uint32_t tempIfIndex;
867
              if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
868
                {
869
                  Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
870
                  NS_ASSERT (tempIpv4);
871
                  Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
872
                  pLSA->AddAttachedRouter (tempAddr);
873
                }
874
            }
875
          m_LSAs.push_back (pLSA);
876
          NS_LOG_LOGIC (*pLSA);
877
        }
878
    }
607
    }
879
608
880
  return m_LSAs.size ();
609
  return m_LSAs.size ();
610
}
611
612
  void
613
GlobalRouter::ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
614
{
615
  NS_LOG_FUNCTION (nd << pLSA << &c);
616
617
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
618
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBroadcastLink(): Can't alloc link record");
619
620
  //
621
  // We have some preliminaries to do to get enough information to proceed.
622
  // This information we need comes from the internet stack, so notice that
623
  // there is an implied assumption that global routing is only going to 
624
  // work with devices attached to the internet stack (have an ipv4 interface
625
  // associated to them.
626
  //
627
  Ptr<Node> node = nd->GetNode ();
628
629
  uint32_t ifIndexLocal;
630
  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
631
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBroadcastLink(): No interface index associated with device");
632
633
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
634
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBroadcastLink (): GetObject for <Ipv4> interface failed");
635
636
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
637
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
638
  NS_LOG_LOGIC ("Working with local address " << addrLocal);
639
  uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
640
641
  //
642
  // Check to see if the net device is connected to a channel/network that has
643
  // another router on it.  If there is no other router on the link (but us) then
644
  // this is a stub network.  If we find another router, then what we have here
645
  // is a transit network.
646
  //
647
  if (AnotherRouterOnLink (nd) == false)
648
    {
649
      //
650
      // This is a net device connected to a stub network
651
      //
652
      NS_LOG_LOGIC("**** Router-LSA Stub Network");
653
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
654
655
      // 
656
      // According to OSPF, the Link ID is the IP network number of 
657
      // the attached network.
658
      //
659
      plr->SetLinkId (addrLocal.CombineMask(maskLocal));
660
661
      //
662
      // and the Link Data is the network mask; converted to Ipv4Address
663
      //
664
      Ipv4Address maskLocalAddr;
665
      maskLocalAddr.Set(maskLocal.Get ());
666
      plr->SetLinkData (maskLocalAddr);
667
      plr->SetMetric (metricLocal);
668
      pLSA->AddLinkRecord(plr);
669
      plr = 0;
670
    }
671
  else
672
    {
673
      //
674
      // We have multiple routers on a broadcast interface, so this is
675
      // a transit network.
676
      //
677
      NS_LOG_LOGIC ("**** Router-LSA Transit Network");
678
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
679
680
      // 
681
      // By definition, the router with the lowest IP address is the
682
      // designated router for the network.  OSPF says that the Link ID
683
      // gets the IP interface address of the designated router in this 
684
      // case.
685
      //
686
      Ipv4Address desigRtr = FindDesignatedRouterForLink (nd);
687
      if (desigRtr == addrLocal) 
688
        {
689
          c.Add (nd);
690
          NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
691
        }
692
      plr->SetLinkId (desigRtr);
693
      
694
      //
695
      // OSPF says that the Link Data is this router's own IP address.
696
      //
697
      plr->SetLinkData (addrLocal);
698
      plr->SetMetric (metricLocal);
699
      pLSA->AddLinkRecord (plr);
700
      plr = 0;
701
    }
702
}
703
704
  void
705
GlobalRouter::ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA)
706
{
707
  NS_LOG_FUNCTION (ndLocal << pLSA);
708
709
  //
710
  // We have some preliminaries to do to get enough information to proceed.
711
  // This information we need comes from the internet stack, so notice that
712
  // there is an implied assumption that global routing is only going to 
713
  // work with devices attached to the internet stack (have an ipv4 interface
714
  // associated to them.
715
  //
716
  Ptr<Node> nodeLocal = ndLocal->GetNode ();
717
718
  uint32_t ifIndexLocal;
719
  bool rc = FindIfIndexForDevice(nodeLocal, ndLocal, ifIndexLocal);
720
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLink (): No interface index associated with device");
721
722
  Ptr<Ipv4> ipv4Local = nodeLocal->GetObject<Ipv4> ();
723
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
724
725
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
726
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
727
  NS_LOG_LOGIC ("Working with local address " << addrLocal);
728
  uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
729
730
  //
731
  // Now, we're going to walk over to the remote net device on the other end of 
732
  // the point-to-point channel we know we have.  This is where our adjacent 
733
  // router (to use OSPF lingo) is running.  
734
  //
735
  Ptr<Channel> ch = ndLocal->GetChannel();
736
737
  //
738
  // Get the net device on the other side of the point-to-point channel.
739
  //
740
  Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
741
742
  //
743
  // The adjacent net device is aggregated to a node.  We need to ask that net 
744
  // device for its node, then ask that node for its Ipv4 interface.  Note a
745
  // requirement that nodes on either side of a point-to-point link must have 
746
  // internet stacks; and an assumption that point-to-point links are incompatible 
747
  // with bridging.
748
  //
749
  Ptr<Node> nodeRemote = ndRemote->GetNode();
750
  Ptr<Ipv4> ipv4Remote = nodeRemote->GetObject<Ipv4> ();
751
  NS_ABORT_MSG_UNLESS (ipv4Remote, 
752
                       "GlobalRouter::ProcessPointToPointLink(): GetObject for remote <Ipv4> failed");
753
754
  //
755
  // Further note the requirement that nodes on either side of a point-to-point 
756
  // link must participate in global routing and therefore have a GlobalRouter
757
  // interface aggregated.
758
  //
759
  Ptr<GlobalRouter> rtrRemote = nodeRemote->GetObject<GlobalRouter> ();
760
  NS_ABORT_MSG_UNLESS(rtrRemote, 
761
                      "GlobalRouter::ProcessPointToPointLinks(): GetObject for remote <GlobalRouter> failed");
762
763
  //
764
  // We're going to need the remote router ID, so we might as well get it now.
765
  //
766
  Ipv4Address rtrIdRemote = rtrRemote->GetRouterId();
767
  NS_LOG_LOGIC ("Working with remote router " << rtrIdRemote);
768
769
  //
770
  // Now, just like we did above, we need to get the IP interface index for the 
771
  // net device on the other end of the point-to-point channel.
772
  //
773
  uint32_t ifIndexRemote;
774
  rc = FindIfIndexForDevice(nodeRemote, ndRemote, ifIndexRemote);
775
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessPointToPointLinks(): No interface index associated with remote device");
776
777
  //
778
  // Now that we have the Ipv4 interface, we can get the (remote) address and
779
  // mask we need.
780
  //
781
  Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
782
  Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
783
  NS_LOG_LOGIC ("Working with remote address " << addrRemote);
784
785
  //
786
  // Now we can fill out the link records for this link.  There are always two
787
  // link records; the first is a point-to-point record describing the link and
788
  // the second is a stub network record with the network number.
789
  //
790
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
791
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
792
  plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
793
  plr->SetLinkId (rtrIdRemote);
794
  plr->SetLinkData (addrLocal);
795
  plr->SetMetric (metricLocal);
796
  pLSA->AddLinkRecord (plr);
797
  plr = 0;
798
799
  plr = new GlobalRoutingLinkRecord;
800
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessPointToPointLink(): Can't alloc link record");
801
  plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
802
  plr->SetLinkId (addrRemote);
803
  plr->SetLinkData (Ipv4Address(maskRemote.Get()));  // Frown
804
  plr->SetMetric (metricLocal);
805
  pLSA->AddLinkRecord (plr);
806
  plr = 0;
807
}
808
809
  void
810
GlobalRouter::BuildNetworkLSAs (NetDeviceContainer c)
811
{
812
  NS_LOG_FUNCTION (&c);
813
814
  uint32_t nDesignatedRouters = c.GetN ();
815
      
816
  for (uint32_t i = 0; i < nDesignatedRouters; ++i)
817
    {
818
      //
819
      // Build one NetworkLSA for each net device talking to a network that we are the 
820
      // designated router for.  These devices are in the provided container.
821
      //
822
      Ptr<NetDevice> ndLocal = c.Get (i);
823
      Ptr<Node> node = ndLocal->GetNode ();
824
825
      uint32_t ifIndexLocal;
826
      bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexLocal);
827
      NS_ABORT_MSG_IF (rc == false, "GlobalRouter::BuildNetworkLSAs (): No interface index associated with device");
828
829
      Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
830
      NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessPointToPointLink (): GetObject for <Ipv4> interface failed");
831
832
      Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
833
      Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
834
835
      GlobalRoutingLSA *pLSA = new GlobalRoutingLSA;
836
      NS_ABORT_MSG_IF (pLSA == 0, "GlobalRouter::BuildNetworkLSAs(): Can't alloc link record");
837
838
      pLSA->SetLSType (GlobalRoutingLSA::NetworkLSA);
839
      pLSA->SetLinkStateId (addrLocal);
840
      pLSA->SetAdvertisingRouter (m_routerId);
841
      pLSA->SetNetworkLSANetworkMask (maskLocal);
842
      pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
843
844
      //
845
      // Build a list of AttachedRouters by walking the devices in the channel
846
      // and, if we find a node with a GlobalRouter interface and an IPv4 
847
      // interface associated with that device, we call it an attached router.  
848
      //
849
      Ptr<Channel> ch = ndLocal->GetChannel();
850
      uint32_t nDevices = ch->GetNDevices();
851
      NS_ASSERT (nDevices);
852
      
853
      for (uint32_t i = 0; i < nDevices; i++)
854
        {
855
          Ptr<NetDevice> tempNd = ch->GetDevice (i);
856
          NS_ASSERT (tempNd);
857
          Ptr<Node> tempNode = tempNd->GetNode ();
858
859
          //
860
          // Does the node in question have a GlobalRouter interface?  If not it can
861
          // hardly be considered an attached router.
862
          //
863
          Ptr<GlobalRouter> rtr = tempNode->GetObject<GlobalRouter> ();
864
          if (rtr == 0)
865
            { 
866
              continue;
867
            }
868
869
          //
870
          // Does the attached node have an ipv4 interface for the device we're probing?
871
          // If not, it can't play router.
872
          //
873
          uint32_t tempIfIndex;
874
          if (FindIfIndexForDevice (tempNode, tempNd, tempIfIndex))
875
            {
876
              Ptr<Ipv4> tempIpv4 = tempNode->GetObject<Ipv4> ();
877
              NS_ASSERT (tempIpv4);
878
              Ipv4Address tempAddr = tempIpv4->GetAddress(tempIfIndex);
879
              pLSA->AddAttachedRouter (tempAddr);
880
            }
881
        }
882
      m_LSAs.push_back (pLSA);
883
      pLSA = 0;
884
    }
881
}
885
}
882
886
883
//
887
//
 Lines 1026-1036   GlobalRouter::GetLSA (uint32_t n, Global Link Here 
1026
// other end.  This only makes sense with a point-to-point channel.
1030
// other end.  This only makes sense with a point-to-point channel.
1027
//
1031
//
1028
  Ptr<NetDevice>
1032
  Ptr<NetDevice>
1029
GlobalRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const
1033
GlobalRouter::GetAdjacent (Ptr<NetDevice> nd, Ptr<Channel> ch) const
1030
{
1034
{
1031
  NS_LOG_FUNCTION_NOARGS ();
1035
  NS_LOG_FUNCTION_NOARGS ();
1032
  NS_ASSERT_MSG(ch->GetNDevices() == 2, 
1036
  NS_ASSERT_MSG(ch->GetNDevices() == 2, "GlobalRouter::GetAdjacent (): Channel with other than two devices");
1033
    "GlobalRouter::GetAdjacent (): Channel with other than two devices");
1034
//
1037
//
1035
// This is a point to point channel with two endpoints.  Get both of them.
1038
// This is a point to point channel with two endpoints.  Get both of them.
1036
//
1039
//
 Lines 1065-1071   GlobalRouter::GetAdjacent(Ptr<NetDevice> Link Here 
1065
// is bridged, there will not be an interface associated directly with the device.
1068
// is bridged, there will not be an interface associated directly with the device.
1066
//
1069
//
1067
  bool
1070
  bool
1068
GlobalRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const
1071
GlobalRouter::FindIfIndexForDevice (Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const
1069
{
1072
{
1070
  NS_LOG_FUNCTION_NOARGS ();
1073
  NS_LOG_FUNCTION_NOARGS ();
1071
  NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd );
1074
  NS_LOG_LOGIC("For node " << node->GetId () << " for net device " << nd );
 Lines 1087-1093   GlobalRouter::FindIfIndexForDevice(Ptr<N Link Here 
1087
        }
1090
        }
1088
    }
1091
    }
1089
1092
1090
          NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index");
1093
  NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index");
1094
  return false;
1095
}
1096
1097
//
1098
// Decide whether or not a given net device is being bridged by a BridgeNetDevice.
1099
//
1100
  bool
1101
GlobalRouter::IsNetDeviceBridged (Ptr<NetDevice> nd) const
1102
{
1103
  Ptr<Node> node = nd->GetNode ();
1104
  uint32_t nDevices = node->GetNDevices();
1105
1106
  //
1107
  // There is no bit on a net device that says it is being bridged, so we have
1108
  // to look for bridges on the node to which the device is attached.  If we
1109
  // find a bridge, we need to look through its bridge ports (the devices it
1110
  // bridges) to see if we find the device in question.
1111
  //
1112
  for (uint32_t i = 0; i < nDevices; ++i)
1113
    {
1114
      Ptr<NetDevice> nd = node->GetDevice(i);
1115
1116
      if (nd->IsBridge ())
1117
        {
1118
          Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
1119
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1120
1121
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1122
            {
1123
              if (bnd->GetBridgePort (j) == nd)
1124
                {
1125
                  return true;
1126
                }
1127
            }
1128
        }
1129
    }
1091
  return false;
1130
  return false;
1092
}
1131
}
1093
1132
(-)a/src/routing/global-routing/global-router-interface.h (+6 lines)
 Lines 29-34    Link Here 
29
#include "ns3/node.h"
29
#include "ns3/node.h"
30
#include "ns3/channel.h"
30
#include "ns3/channel.h"
31
#include "ns3/ipv4-address.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/net-device-container.h"
32
#include "ns3/global-route-manager.h"
33
#include "ns3/global-route-manager.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
 Lines 642-647   private: Link Here 
642
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
643
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
643
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
644
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
644
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
645
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
646
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
647
  void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
648
  void BuildNetworkLSAs (NetDeviceContainer c);
649
  bool IsNetDeviceBridged (Ptr<NetDevice> nd) const;
650
645
651
646
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
652
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
647
  ListOfLSAs_t m_LSAs;
653
  ListOfLSAs_t m_LSAs;
(-)a/src/routing/global-routing/global-router-interface.cc (-3 / +159 lines)
 Lines 614-621   GlobalRouter::ProcessBroadcastLink (Ptr< Link Here 
614
{
614
{
615
  NS_LOG_FUNCTION (nd << pLSA << &c);
615
  NS_LOG_FUNCTION (nd << pLSA << &c);
616
616
617
  if (nd->IsBridge ())
618
    {
619
      ProcessBridgedBroadcastLink (nd, pLSA, c);
620
    }
621
  else
622
    {
623
      ProcessSingleBroadcastLink (nd, pLSA, c);
624
    }
625
}
626
627
  void
628
GlobalRouter::ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
629
{
630
  NS_LOG_FUNCTION (nd << pLSA << &c);
631
617
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
632
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
618
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBroadcastLink(): Can't alloc link record");
633
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessSingleBroadcastLink(): Can't alloc link record");
619
634
620
  //
635
  //
621
  // We have some preliminaries to do to get enough information to proceed.
636
  // We have some preliminaries to do to get enough information to proceed.
 Lines 628-637   GlobalRouter::ProcessBroadcastLink (Ptr< Link Here 
628
643
629
  uint32_t ifIndexLocal;
644
  uint32_t ifIndexLocal;
630
  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
645
  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
631
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBroadcastLink(): No interface index associated with device");
646
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessSingleBroadcastLink(): No interface index associated with device");
632
647
633
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
648
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
634
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBroadcastLink (): GetObject for <Ipv4> interface failed");
649
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessSingleBroadcastLink (): GetObject for <Ipv4> interface failed");
635
650
636
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
651
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
637
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
652
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
 Lines 684-689   GlobalRouter::ProcessBroadcastLink (Ptr< Link Here 
684
      // case.
699
      // case.
685
      //
700
      //
686
      Ipv4Address desigRtr = FindDesignatedRouterForLink (nd);
701
      Ipv4Address desigRtr = FindDesignatedRouterForLink (nd);
702
      if (desigRtr == addrLocal) 
703
        {
704
          c.Add (nd);
705
          NS_LOG_LOGIC ("Node " << node->GetId () << " elected a designated router");
706
        }
707
      plr->SetLinkId (desigRtr);
708
      
709
      //
710
      // OSPF says that the Link Data is this router's own IP address.
711
      //
712
      plr->SetLinkData (addrLocal);
713
      plr->SetMetric (metricLocal);
714
      pLSA->AddLinkRecord (plr);
715
      plr = 0;
716
    }
717
}
718
719
  void
720
GlobalRouter::ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
721
{
722
  NS_LOG_FUNCTION (nd << pLSA << &c);
723
724
  NS_ASSERT_MSG (nd->IsBridge (), "GlobalRouter::ProcessBridgedBroadcastLink(): Called with non-bridge net device");
725
726
  Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
727
  NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
728
729
  //
730
  // We need to handle a bridge on the router.  This means that we have been 
731
  // given a net device that is a BridgeNetDevice.  It has an associated Ipv4
732
  // interface index and address.  Some number of other net devices live "under"
733
  // the bridge device as so-called bridge ports.  In a nutshell, what we have
734
  // to do is to repeat what is done for a single broadcast link on all of 
735
  // those net devices living under the bridge (trolls?)
736
  //
737
  bool areTransitNetwork = false;
738
  Ipv4Address desigRtr ("255.255.255.255");
739
740
  for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
741
    {
742
      Ptr<NetDevice> ndTemp = bnd->GetBridgePort (i);
743
      GlobalRoutingLSA *pLsaTest = new GlobalRoutingLSA;
744
      NetDeviceContainer cTest;
745
      ProcessSingleBroadcastLink (ndTemp, pLsaTest, cTest);
746
747
      //
748
      // The GlobalRoutingLSA pLsaTest will now have a link record attached to
749
      // it indicating what was found.  If another router is found on any one
750
      // of the bridged networks, we need to treat the whole bridge as a transit 
751
      // network.
752
      //
753
      // If the link type is a transit network, then we have got to do some work
754
      // to figure out what to do about the other routers on the bridge.
755
      //
756
      if (pLsaTest->GetLinkRecord (0)->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
757
        {
758
          areTransitNetwork = true;
759
760
          //
761
          // If we're going to be a transit network, then we have got to elect
762
          // a designated router for the whole bridge.  This means finding the
763
          // router with the lowest IP address on the whole bridge.  We ask 
764
          // for the lowest address on each segment and pick the lowest of them
765
          // all.
766
          //
767
          Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp);
768
          if (desigRtrTemp < desigRtr)
769
            {
770
              desigRtr = desigRtrTemp;
771
            }
772
        }
773
    }
774
775
  //
776
  // That's all the information we need to put it all together, just like we did
777
  // in the case of a single broadcast link.
778
  //
779
780
  GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
781
  NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
782
783
  //
784
  // We have some preliminaries to do to get enough information to proceed.
785
  // This information we need comes from the internet stack, so notice that
786
  // there is an implied assumption that global routing is only going to 
787
  // work with devices attached to the internet stack (have an ipv4 interface
788
  // associated to them.
789
  //
790
  Ptr<Node> node = nd->GetNode ();
791
792
  uint32_t ifIndexLocal;
793
  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
794
  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
795
796
  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
797
  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
798
799
  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
800
  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
801
  NS_LOG_LOGIC ("Working with local address " << addrLocal);
802
  uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
803
804
  if (areTransitNetwork == false)
805
    {
806
      //
807
      // This is a net device connected to a bridge of stub networks
808
      //
809
      NS_LOG_LOGIC("**** Router-LSA Stub Network");
810
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
811
812
      // 
813
      // According to OSPF, the Link ID is the IP network number of 
814
      // the attached network.
815
      //
816
      plr->SetLinkId (addrLocal.CombineMask(maskLocal));
817
818
      //
819
      // and the Link Data is the network mask; converted to Ipv4Address
820
      //
821
      Ipv4Address maskLocalAddr;
822
      maskLocalAddr.Set(maskLocal.Get ());
823
      plr->SetLinkData (maskLocalAddr);
824
      plr->SetMetric (metricLocal);
825
      pLSA->AddLinkRecord(plr);
826
      plr = 0;
827
    }
828
  else
829
    {
830
      //
831
      // We have multiple routers on a bridged broadcast interface, so this is
832
      // a transit network.
833
      //
834
      NS_LOG_LOGIC ("**** Router-LSA Transit Network");
835
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
836
837
      // 
838
      // By definition, the router with the lowest IP address is the
839
      // designated router for the network.  OSPF says that the Link ID
840
      // gets the IP interface address of the designated router in this 
841
      // case.
842
      //
687
      if (desigRtr == addrLocal) 
843
      if (desigRtr == addrLocal) 
688
        {
844
        {
689
          c.Add (nd);
845
          c.Add (nd);
(-)a/src/routing/global-routing/global-router-interface.h (+3 lines)
 Lines 644-649   private: Link Here 
644
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
644
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
645
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
645
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
646
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
646
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
647
  void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
648
  void ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
649
647
  void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
650
  void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
648
  void BuildNetworkLSAs (NetDeviceContainer c);
651
  void BuildNetworkLSAs (NetDeviceContainer c);
649
  bool IsNetDeviceBridged (Ptr<NetDevice> nd) const;
652
  bool IsNetDeviceBridged (Ptr<NetDevice> nd) const;
(-)a/src/routing/global-routing/global-router-interface.cc (-27 / +75 lines)
 Lines 547-553   GlobalRouter::DiscoverLSAs (void) Link Here 
547
547
548
      //
548
      //
549
      // Check to see if the net device we just got has a corresponding IP 
549
      // Check to see if the net device we just got has a corresponding IP 
550
      // interface (could be a pure L2 NetDevice).
550
      // interface (could be a pure L2 NetDevice) -- for example a net device
551
      // associated with a bridge.
551
      //
552
      //
552
      bool isIp = false;
553
      bool isIp = false;
553
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
554
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
 Lines 659-665   GlobalRouter::ProcessSingleBroadcastLink Link Here 
659
  // this is a stub network.  If we find another router, then what we have here
660
  // this is a stub network.  If we find another router, then what we have here
660
  // is a transit network.
661
  // is a transit network.
661
  //
662
  //
662
  if (AnotherRouterOnLink (nd) == false)
663
  if (AnotherRouterOnLink (nd, true) == false)
663
    {
664
    {
664
      //
665
      //
665
      // This is a net device connected to a stub network
666
      // This is a net device connected to a stub network
 Lines 740-759   GlobalRouter::ProcessBridgedBroadcastLin Link Here 
740
  for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
741
  for (uint32_t i = 0; i < bnd->GetNBridgePorts (); ++i)
741
    {
742
    {
742
      Ptr<NetDevice> ndTemp = bnd->GetBridgePort (i);
743
      Ptr<NetDevice> ndTemp = bnd->GetBridgePort (i);
743
      GlobalRoutingLSA *pLsaTest = new GlobalRoutingLSA;
744
      NetDeviceContainer cTest;
745
      ProcessSingleBroadcastLink (ndTemp, pLsaTest, cTest);
746
744
747
      //
745
      //
748
      // The GlobalRoutingLSA pLsaTest will now have a link record attached to
746
      // We have to decide if we are a transit network.  This is characterized
749
      // it indicating what was found.  If another router is found on any one
747
      // by the presence of another router on the network segment.  If we find
750
      // of the bridged networks, we need to treat the whole bridge as a transit 
748
      // another router on any of our bridged links, we are a transit network.
751
      // network.
752
      //
749
      //
753
      // If the link type is a transit network, then we have got to do some work
750
      if (AnotherRouterOnLink (ndTemp, true))
754
      // to figure out what to do about the other routers on the bridge.
755
      //
756
      if (pLsaTest->GetLinkRecord (0)->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
757
        {
751
        {
758
          areTransitNetwork = true;
752
          areTransitNetwork = true;
759
753
 Lines 1112-1147   GlobalRouter::FindDesignatedRouterForLin Link Here 
1112
//
1106
//
1113
// Given a node and an attached net device, take a look off in the channel to 
1107
// Given a node and an attached net device, take a look off in the channel to 
1114
// which the net device is attached and look for a node on the other side
1108
// which the net device is attached and look for a node on the other side
1115
// that has a GlobalRouter interface aggregated.
1109
// that has a GlobalRouter interface aggregated.  Life gets more complicated
1110
// when there is a bridged net device on the other side.
1116
//
1111
//
1117
  bool
1112
  bool
1118
GlobalRouter::AnotherRouterOnLink (Ptr<NetDevice> nd) const
1113
GlobalRouter::AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const
1119
{
1114
{
1120
  NS_LOG_FUNCTION_NOARGS ();
1115
  NS_LOG_FUNCTION (nd << allowRecursion);
1121
1116
1122
  Ptr<Channel> ch = nd->GetChannel();
1117
  Ptr<Channel> ch = nd->GetChannel();
1123
  uint32_t nDevices = ch->GetNDevices();
1118
  uint32_t nDevices = ch->GetNDevices();
1124
  NS_ASSERT (nDevices);
1119
  NS_ASSERT (nDevices);
1125
1120
1121
  //
1122
  // Look through all of the devices on the channel to which the net device
1123
  // in questin is attached.
1124
  //
1126
  for (uint32_t i = 0; i < nDevices; i++)
1125
  for (uint32_t i = 0; i < nDevices; i++)
1127
    {
1126
    {
1128
      Ptr<NetDevice> ndTemp = ch->GetDevice (i);
1127
      NS_LOG_LOGIC ("**** Examine device " << i << "on node " << nd->GetNode ()->GetId ());
1129
      NS_ASSERT (ndTemp);
1130
1128
1131
      if (ndTemp == nd)
1129
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1130
      NS_ASSERT (ndOther);
1131
1132
      // 
1133
      // Ignore the net device itself.
1134
      //
1135
      if (ndOther == nd)
1132
        {
1136
        {
1137
          NS_LOG_LOGIC ("**** Self");
1133
          continue;
1138
          continue;
1134
        }
1139
        }
1135
1140
1136
      Ptr<Node> nodeTemp = ndTemp->GetNode ();
1141
      //
1142
      // For all other net devices, we need to check and see if a router
1143
      // is present.  If the net device on the other side is a bridged
1144
      // device, we need to consider all of the other devices on the 
1145
      // bridge.
1146
      //
1147
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1148
      if (bnd)
1149
        {
1150
          NS_LOG_LOGIC ("**** Device is bridged");
1151
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1152
            {
1153
              NS_LOG_LOGIC ("**** Examining bridge port " << j);
1154
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1155
              if (ndBridged == ndOther)
1156
                {
1157
                  NS_LOG_LOGIC ("**** Self");
1158
                  continue;
1159
                }
1160
              if (allowRecursion)
1161
                {
1162
                  NS_LOG_LOGIC ("**** Recursing");
1163
                  if (AnotherRouterOnLink (ndBridged, false))
1164
                    {
1165
                      NS_LOG_LOGIC ("**** Return true");
1166
                      return true;
1167
                    }
1168
                }
1169
            }
1170
          NS_LOG_LOGIC ("**** Return false");
1171
          return false;
1172
        }
1173
1174
      NS_LOG_LOGIC ("**** Device is not bridged");
1175
      Ptr<Node> nodeTemp = ndOther->GetNode ();
1137
      NS_ASSERT (nodeTemp);
1176
      NS_ASSERT (nodeTemp);
1138
1177
1139
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1178
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1140
      if (rtr)
1179
      if (rtr)
1141
        {
1180
        {
1181
          NS_LOG_LOGIC ("**** Return true");
1142
          return true;
1182
          return true;
1143
        }
1183
        }
1144
    }
1184
    }
1185
  NS_LOG_LOGIC ("**** Return false");
1145
  return false;
1186
  return false;
1146
}
1187
}
1147
1188
 Lines 1253-1261   GlobalRouter::FindIfIndexForDevice (Ptr< Link Here 
1253
//
1294
//
1254
// Decide whether or not a given net device is being bridged by a BridgeNetDevice.
1295
// Decide whether or not a given net device is being bridged by a BridgeNetDevice.
1255
//
1296
//
1256
  bool
1297
  Ptr<BridgeNetDevice>
1257
GlobalRouter::IsNetDeviceBridged (Ptr<NetDevice> nd) const
1298
GlobalRouter::NetDeviceIsBridged (Ptr<NetDevice> nd) const
1258
{
1299
{
1300
  NS_LOG_FUNCTION (nd);
1301
1259
  Ptr<Node> node = nd->GetNode ();
1302
  Ptr<Node> node = nd->GetNode ();
1260
  uint32_t nDevices = node->GetNDevices();
1303
  uint32_t nDevices = node->GetNDevices();
1261
1304
 Lines 1267-1289   GlobalRouter::IsNetDeviceBridged (Ptr<Ne Link Here 
1267
  //
1310
  //
1268
  for (uint32_t i = 0; i < nDevices; ++i)
1311
  for (uint32_t i = 0; i < nDevices; ++i)
1269
    {
1312
    {
1270
      Ptr<NetDevice> nd = node->GetDevice(i);
1313
      Ptr<NetDevice> ndTest = node->GetDevice(i);
1314
      NS_LOG_LOGIC ("**** Examine device " << i << " " << ndTest);
1271
1315
1272
      if (nd->IsBridge ())
1316
      if (ndTest->IsBridge ())
1273
        {
1317
        {
1274
          Ptr<BridgeNetDevice> bnd = nd->GetObject<BridgeNetDevice> ();
1318
          NS_LOG_LOGIC ("**** device " << i << " is a bridge net device");
1319
          Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> ();
1275
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1320
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1276
1321
1277
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1322
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1278
            {
1323
            {
1324
              NS_LOG_LOGIC ("**** Examine bridge port " << j << " " << bnd->GetBridgePort (j));
1279
              if (bnd->GetBridgePort (j) == nd)
1325
              if (bnd->GetBridgePort (j) == nd)
1280
                {
1326
                {
1281
                  return true;
1327
                  NS_LOG_LOGIC ("**** Net device " << nd << " is bridged by " << bnd);
1328
                  return bnd;
1282
                }
1329
                }
1283
            }
1330
            }
1284
        }
1331
        }
1285
    }
1332
    }
1286
  return false;
1333
  NS_LOG_LOGIC ("**** Net device " << nd << " is not bridged");
1334
  return 0;
1287
}
1335
}
1288
1336
1289
} // namespace ns3
1337
} // namespace ns3
(-)a/src/routing/global-routing/global-router-interface.h (-2 / +3 lines)
 Lines 30-35    Link Here 
30
#include "ns3/channel.h"
30
#include "ns3/channel.h"
31
#include "ns3/ipv4-address.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/net-device-container.h"
32
#include "ns3/net-device-container.h"
33
#include "ns3/bridge-net-device.h"
33
#include "ns3/global-route-manager.h"
34
#include "ns3/global-route-manager.h"
34
35
35
namespace ns3 {
36
namespace ns3 {
 Lines 642-655   private: Link Here 
642
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
643
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
643
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
644
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
644
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
645
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
645
  bool AnotherRouterOnLink (Ptr<NetDevice> nd) const;
646
  bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
646
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
647
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
647
  void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
648
  void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
648
  void ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
649
  void ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
649
650
650
  void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
651
  void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
651
  void BuildNetworkLSAs (NetDeviceContainer c);
652
  void BuildNetworkLSAs (NetDeviceContainer c);
652
  bool IsNetDeviceBridged (Ptr<NetDevice> nd) const;
653
  Ptr<BridgeNetDevice> NetDeviceIsBridged (Ptr<NetDevice> nd) const;
653
654
654
655
655
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
656
  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
(-)a/examples/csma-bridge-one-hop.cc (-12 / +15 lines)
 Lines 41-59    Link Here 
41
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes 
41
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes 
42
// with three net devices:
42
// with three net devices:
43
//
43
//
44
//        n0     n1  
44
//        n0     n1                (n0 = 10.1.1.2)
45
//        |      | 
45
//        |      |                 (n1 = 10.1.1.3)  Note odd addressing
46
//       -----------
46
//       -----------               (n2 = 10.1.1.1)
47
//       | bridge1 | <- n5
47
//       | bridge1 | <- n5  
48
//       -----------
48
//       -----------
49
//           |    
49
//           |    
50
//         router    <- n2
50
//         router    <- n2
51
//           |
51
//           |
52
//       -----------
52
//       -----------
53
//       | bridge2 | <- n6
53
//       | bridge2 | <- n6
54
//       -----------
54
//       -----------               (n2 = 10.1.2.1)
55
//        |      | 
55
//        |      |                 (n3 = 10.1.2.2)
56
//        n3     n4  
56
//        n3     n4                (n4 = 10.1.2.3)
57
//
57
//
58
// So, this example shows two broadcast domains, each interconnected by a bridge
58
// So, this example shows two broadcast domains, each interconnected by a bridge
59
// with a router node (n2) interconnecting the layer-2 broadcast domains
59
// with a router node (n2) interconnecting the layer-2 broadcast domains
 Lines 61-67    Link Here 
61
// It is meant to mirror somewhat the csma-bridge example but adds another
61
// It is meant to mirror somewhat the csma-bridge example but adds another
62
// bridged link separated by a router.
62
// bridged link separated by a router.
63
// 
63
// 
64
// - CBR/UDP flows from n0 to n1 and from n3 to n0
64
// - 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)
65
// - DropTail queues 
65
// - DropTail queues 
66
// - Global static routing
66
// - Global static routing
67
// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
67
// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
 Lines 201-207   main (int argc, char *argv[]) Link Here 
201
  // Create an optional packet sink to receive these packets
201
  // Create an optional packet sink to receive these packets
202
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
202
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
203
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
203
                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
204
  sink.Install (n1);
204
  ApplicationContainer sink1 = sink.Install (n1);
205
  sink1.Start (Seconds (1.0));
206
  sink1.Stop (Seconds (10.0));
205
207
206
  // 
208
  // 
207
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
209
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
 Lines 209-219   main (int argc, char *argv[]) Link Here 
209
  onoff.SetAttribute ("Remote", 
211
  onoff.SetAttribute ("Remote", 
210
                      AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
212
                      AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
211
  ApplicationContainer app2 = onoff.Install (n3);
213
  ApplicationContainer app2 = onoff.Install (n3);
212
213
  sink.Install (n0);
214
215
  app2.Start (Seconds (1.1));
214
  app2.Start (Seconds (1.1));
216
  app2.Stop (Seconds (10.0));
215
  app2.Stop (Seconds (10.0));
216
217
  ApplicationContainer sink2 = sink.Install (n0);
218
  sink2.Start (Seconds (1.1));
219
  sink2.Stop (Seconds (10.0));
217
220
218
  //
221
  //
219
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
222
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
(-)a/src/routing/global-routing/global-router-interface.cc (-71 / +163 lines)
 Lines 383-391   GlobalRoutingLSA::SetStatus (GlobalRouti Link Here 
383
  void 
383
  void 
384
GlobalRoutingLSA::Print (std::ostream &os) const
384
GlobalRoutingLSA::Print (std::ostream &os) const
385
{
385
{
386
  os << "m_lsType = " << m_lsType << std::endl <<
386
  os << std::endl;
387
        "m_linkStateId = " << m_linkStateId << std::endl <<
387
  os << "========== Global Routing LSA ==========" << std::endl;
388
        "m_advertisingRtr = " << m_advertisingRtr << std::endl;
388
  os << "m_lsType = " << m_lsType;
389
  if (m_lsType == GlobalRoutingLSA::RouterLSA) 
390
    {
391
      os << " (GlobalRoutingLSA::RouterLSA)";
392
    }
393
  else if (m_lsType == GlobalRoutingLSA::NetworkLSA) 
394
    {
395
      os << " (GlobalRoutingLSA::NetworkLSA)";
396
    }
397
  else
398
    {
399
      os << "(Unknown LSType)";
400
    }
401
  os << std::endl;
402
403
  os << "m_linkStateId = " << m_linkStateId << " (Router ID)" << std::endl;
404
  os << "m_advertisingRtr = " << m_advertisingRtr << " (Router ID)" << std::endl;
389
405
390
  if (m_lsType == GlobalRoutingLSA::RouterLSA) 
406
  if (m_lsType == GlobalRoutingLSA::RouterLSA) 
391
    {
407
    {
 Lines 394-423   GlobalRoutingLSA::Print (std::ostream &o Link Here 
394
            i++)
410
            i++)
395
        {
411
        {
396
          GlobalRoutingLinkRecord *p = *i;
412
          GlobalRoutingLinkRecord *p = *i;
397
          os << "----------" << std::endl;
413
398
          os << "m_linkId = " << p->GetLinkId () << std::endl;
414
          os << "---------- RouterLSA Link Record ----------" << std::endl;
399
          os << "m_linkData = " << p->GetLinkData () << std::endl;
415
          os << "m_linkType = " << p->m_linkType;
400
          os << "m_metric = " << p->GetMetric () << std::endl;
416
          if (p->m_linkType == GlobalRoutingLinkRecord::TransitNetwork)
417
            {
418
              os << " (GlobalRoutingLinkRecord::TransitNetwork)" << std::endl;
419
              os << "m_linkId = " << p->m_linkId << " (Designated router for network)" << std::endl;
420
              os << "m_linkData = " << p->m_linkData << " (This router's IP address)" << std::endl;
421
              os << "m_metric = " << p->m_metric << std::endl;
422
            }
423
          else if (p->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
424
            {
425
              os << "(GlobalRoutingLinkRecord::StubNetwork)" << std::endl;
426
              os << "m_linkId = " << p->m_linkId << " (Network number of attached network)" << std::endl;
427
              os << "m_linkData = " << p->m_linkData << " (Network mask of attached network)" << std::endl;
428
              os << "m_metric = " << p->m_metric << std::endl;
429
            }
430
          else
431
            {
432
              os << "(Unknown LinkType)" << std::endl;
433
              os << "m_linkId = " << p->m_linkId << std::endl;
434
              os << "m_linkData = " << p->m_linkData << std::endl;
435
              os << "m_metric = " << p->m_metric << std::endl;
436
            }
437
          os << "---------- End RouterLSA Link Record ----------" << std::endl;
401
        }
438
        }
402
    }
439
    }
403
  else if (m_lsType == GlobalRoutingLSA::NetworkLSA) 
440
  else if (m_lsType == GlobalRoutingLSA::NetworkLSA) 
404
    {
441
    {
405
      os << "----------" << std::endl;
442
      os << "---------- NetworkLSA Link Record ----------" << std::endl;
406
      os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask 
443
      os << "m_networkLSANetworkMask = " << m_networkLSANetworkMask << std::endl;
407
         << std::endl;
444
      for ( ListOfAttachedRouters_t::const_iterator i = m_attachedRouters.begin (); i != m_attachedRouters.end (); i++)
408
      for ( ListOfAttachedRouters_t::const_iterator i = 
409
            m_attachedRouters.begin ();
410
            i != m_attachedRouters.end (); 
411
            i++)
412
        {
445
        {
413
          Ipv4Address p = *i;
446
          Ipv4Address p = *i;
414
          os << "attachedRouter = " << p << std::endl;
447
          os << "attachedRouter = " << p << std::endl;
415
        }
448
        }
449
      os << "---------- End NetworkLSA Link Record ----------" << std::endl;
416
    }
450
    }
417
  else 
451
  else 
418
    {
452
    {
419
      NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
453
      NS_ASSERT_MSG(0, "Illegal LSA LSType: " << m_lsType);
420
    }
454
    }
455
  os << "========== End Global Routing LSA ==========" << std::endl;
421
}
456
}
422
457
423
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa)
458
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa)
 Lines 699-705   GlobalRouter::ProcessSingleBroadcastLink Link Here 
699
      // gets the IP interface address of the designated router in this 
734
      // gets the IP interface address of the designated router in this 
700
      // case.
735
      // case.
701
      //
736
      //
702
      Ipv4Address desigRtr = FindDesignatedRouterForLink (nd);
737
      Ipv4Address desigRtr = FindDesignatedRouterForLink (nd, true);
703
      if (desigRtr == addrLocal) 
738
      if (desigRtr == addrLocal) 
704
        {
739
        {
705
          c.Add (nd);
740
          c.Add (nd);
 Lines 758-764   GlobalRouter::ProcessBridgedBroadcastLin Link Here 
758
          // for the lowest address on each segment and pick the lowest of them
793
          // for the lowest address on each segment and pick the lowest of them
759
          // all.
794
          // all.
760
          //
795
          //
761
          Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp);
796
          Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp, true);
762
          if (desigRtrTemp < desigRtr)
797
          if (desigRtrTemp < desigRtr)
763
            {
798
            {
764
              desigRtr = desigRtrTemp;
799
              desigRtr = desigRtrTemp;
 Lines 1041-1106   GlobalRouter::BuildNetworkLSAs (NetDevic Link Here 
1041
// connecting to the channel becomes the designated router for the link.
1076
// connecting to the channel becomes the designated router for the link.
1042
//
1077
//
1043
  Ipv4Address
1078
  Ipv4Address
1044
GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const
1079
GlobalRouter::FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const
1045
{
1080
{
1046
  NS_LOG_FUNCTION_NOARGS ();
1081
  NS_LOG_FUNCTION (ndLocal << allowRecursion);
1047
1082
1048
  Ptr<Channel> ch = ndLocal->GetChannel();
1083
  Ptr<Channel> ch = ndLocal->GetChannel();
1049
  uint32_t nDevices = ch->GetNDevices();
1084
  uint32_t nDevices = ch->GetNDevices();
1050
  NS_ASSERT (nDevices);
1085
  NS_ASSERT (nDevices);
1051
1086
1052
  Ipv4Address addr ("255.255.255.255");
1087
  NS_LOG_LOGIC ("**** Looking for designated router off of net device " << ndLocal << " on node " << 
1088
                ndLocal->GetNode ()->GetId ());
1053
1089
1090
  Ipv4Address desigRtr ("255.255.255.255");
1091
1092
  //
1093
  // Look through all of the devices on the channel to which the net device
1094
  // in question is attached.
1095
  //
1054
  for (uint32_t i = 0; i < nDevices; i++)
1096
  for (uint32_t i = 0; i < nDevices; i++)
1055
    {
1097
    {
1056
      Ptr<NetDevice> currentNd = ch->GetDevice (i);
1098
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1057
      NS_ASSERT (currentNd);
1099
      NS_ASSERT (ndOther);
1058
1100
1059
      Ptr<Node> currentNode = currentNd->GetNode ();
1101
      Ptr<Node> nodeOther = ndOther->GetNode ();
1060
      NS_ASSERT (currentNode);
1102
1061
      //
1103
      NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << nodeOther->GetId ());
1062
      // We require a designated router to have a GlobalRouter interface and
1063
      // an internet stack that includes the Ipv4 interface.
1064
      //
1065
      Ptr<GlobalRouter> rtr = currentNode->GetObject<GlobalRouter> ();
1066
      Ptr<Ipv4> ipv4 = currentNode->GetObject<Ipv4> ();
1067
      if (rtr == 0 || ipv4 == 0 )
1068
        {
1069
          continue;
1070
        }
1071
1104
1072
      //
1105
      //
1073
      // This node could be a designated router, so we can check and see if
1106
      // For all other net devices, we need to check and see if a router
1074
      // it has a lower IP address than the one we have.  In order to have
1107
      // is present.  If the net device on the other side is a bridged
1075
      // an IP address, it needs to have an interface index.  If it doesen't
1108
      // device, we need to consider all of the other devices on the 
1076
      // have an interface index directly, it's probably part of a bridge
1109
      // bridge as well (all of the bridge ports.
1077
      // net device XXX which is not yet handled.
1078
      //
1110
      //
1079
      uint32_t currentIfIndex;
1111
      NS_LOG_LOGIC ("**** checking to see if the device is bridged");
1080
      bool rc = FindIfIndexForDevice(currentNode, currentNd, currentIfIndex);
1112
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1081
      if (rc == false)
1113
      if (bnd)
1082
        {
1114
        {
1083
          continue;
1115
          NS_LOG_LOGIC ("**** Device is bridged by BridgeNetDevice " << bnd);
1116
1117
          //
1118
          // It is possible that the bridge net device is sitting under a
1119
          // router, so we have to check for the presence of that router
1120
          // before we run off and follow all the links
1121
          //
1122
          // We require a designated router to have a GlobalRouter interface and
1123
          // an internet stack that includes the Ipv4 interface.  If it doesn't
1124
          // it can't play router.
1125
          //
1126
          NS_LOG_LOGIC ("**** Checking for router on bridge net device " << bnd);
1127
          Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
1128
          Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
1129
          if (rtr && ipv4)
1130
            {
1131
              uint32_t ifIndexOther;
1132
              if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
1133
                {
1134
                  NS_LOG_LOGIC ("**** Found router on bridge net device " << bnd);
1135
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1136
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1137
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1138
                }
1139
            }
1140
1141
          NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd);
1142
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1143
            {
1144
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1145
              NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged);
1146
              if (ndBridged == ndOther)
1147
                {
1148
                  NS_LOG_LOGIC ("**** That bridge port is me, don't walk backward");
1149
                  continue;
1150
                }
1151
1152
              if (allowRecursion)
1153
                {
1154
                  NS_LOG_LOGIC ("**** Recursively looking for routers down bridge port " << ndBridged);
1155
                  Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false);
1156
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1157
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1158
                }
1159
            }
1084
        }
1160
        }
1161
      else
1162
        {
1163
          NS_LOG_LOGIC ("**** This device is not bridged");
1164
          Ptr<Node> nodeOther = ndOther->GetNode ();
1165
          NS_ASSERT (nodeOther);
1085
1166
1086
      //
1167
          //
1087
      // Okay, get the IP address corresponding to the interface we're 
1168
          // We require a designated router to have a GlobalRouter interface and
1088
      // examining and if it's the lowest so far, remember it.
1169
          // an internet stack that includes the Ipv4 interface.  If it doesn't
1089
      //
1170
          //
1090
      Ipv4Address currentAddr = ipv4->GetAddress(currentIfIndex);
1171
          Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
1091
1172
          Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
1092
      if (currentAddr < addr)
1173
          if (rtr && ipv4)
1093
        {
1174
            {
1094
          addr = currentAddr;
1175
              uint32_t ifIndexOther;
1176
              if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
1177
                {
1178
                  NS_LOG_LOGIC ("**** Found router on net device " << ndOther);
1179
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1180
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1181
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1182
                }
1183
            }
1095
        }
1184
        }
1096
    }
1185
    }
1097
1186
  return desigRtr;
1098
  //
1099
  // Return the lowest IP address found, which will become the designated router
1100
  // for the link.
1101
  //
1102
  NS_ASSERT_MSG (addr.IsBroadcast() == false, "GlobalRouter::FindDesignatedRouterForLink(): Bogus address");
1103
  return addr;
1104
}
1187
}
1105
1188
1106
//
1189
//
 Lines 1118-1140   GlobalRouter::AnotherRouterOnLink (Ptr<N Link Here 
1118
  uint32_t nDevices = ch->GetNDevices();
1201
  uint32_t nDevices = ch->GetNDevices();
1119
  NS_ASSERT (nDevices);
1202
  NS_ASSERT (nDevices);
1120
1203
1204
  NS_LOG_LOGIC ("**** Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ());
1205
1121
  //
1206
  //
1122
  // Look through all of the devices on the channel to which the net device
1207
  // Look through all of the devices on the channel to which the net device
1123
  // in questin is attached.
1208
  // in question is attached.
1124
  //
1209
  //
1125
  for (uint32_t i = 0; i < nDevices; i++)
1210
  for (uint32_t i = 0; i < nDevices; i++)
1126
    {
1211
    {
1127
      NS_LOG_LOGIC ("**** Examine device " << i << "on node " << nd->GetNode ()->GetId ());
1128
1129
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1212
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1130
      NS_ASSERT (ndOther);
1213
      NS_ASSERT (ndOther);
1214
1215
      NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ());
1131
1216
1132
      // 
1217
      // 
1133
      // Ignore the net device itself.
1218
      // Ignore the net device itself.
1134
      //
1219
      //
1135
      if (ndOther == nd)
1220
      if (ndOther == nd)
1136
        {
1221
        {
1137
          NS_LOG_LOGIC ("**** Self");
1222
          NS_LOG_LOGIC ("**** Myself, skip");
1138
          continue;
1223
          continue;
1139
        }
1224
        }
1140
1225
 Lines 1144-1188   GlobalRouter::AnotherRouterOnLink (Ptr<N Link Here 
1144
      // device, we need to consider all of the other devices on the 
1229
      // device, we need to consider all of the other devices on the 
1145
      // bridge.
1230
      // bridge.
1146
      //
1231
      //
1232
      NS_LOG_LOGIC ("**** checking to see if device is bridged");
1147
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1233
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1148
      if (bnd)
1234
      if (bnd)
1149
        {
1235
        {
1150
          NS_LOG_LOGIC ("**** Device is bridged");
1236
          NS_LOG_LOGIC ("**** Device is bridged by net device " << bnd);
1237
          NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd);
1151
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1238
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1152
            {
1239
            {
1153
              NS_LOG_LOGIC ("**** Examining bridge port " << j);
1154
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1240
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1241
              NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged);
1155
              if (ndBridged == ndOther)
1242
              if (ndBridged == ndOther)
1156
                {
1243
                {
1157
                  NS_LOG_LOGIC ("**** Self");
1244
                  NS_LOG_LOGIC ("**** That bridge port is me, skip");
1158
                  continue;
1245
                  continue;
1159
                }
1246
                }
1247
1160
              if (allowRecursion)
1248
              if (allowRecursion)
1161
                {
1249
                {
1162
                  NS_LOG_LOGIC ("**** Recursing");
1250
                  NS_LOG_LOGIC ("**** Recursively looking for routers on bridge port " << ndBridged);
1163
                  if (AnotherRouterOnLink (ndBridged, false))
1251
                  if (AnotherRouterOnLink (ndBridged, false))
1164
                    {
1252
                    {
1165
                      NS_LOG_LOGIC ("**** Return true");
1253
                      NS_LOG_LOGIC ("**** Found routers on bridge port, return true");
1166
                      return true;
1254
                      return true;
1167
                    }
1255
                    }
1168
                }
1256
                }
1169
            }
1257
            }
1170
          NS_LOG_LOGIC ("**** Return false");
1258
          NS_LOG_LOGIC ("**** No routers on bridged net device, return false");
1171
          return false;
1259
          return false;
1172
        }
1260
        }
1173
1261
1174
      NS_LOG_LOGIC ("**** Device is not bridged");
1262
      NS_LOG_LOGIC ("**** This device is not bridged");
1175
      Ptr<Node> nodeTemp = ndOther->GetNode ();
1263
      Ptr<Node> nodeTemp = ndOther->GetNode ();
1176
      NS_ASSERT (nodeTemp);
1264
      NS_ASSERT (nodeTemp);
1177
1265
1178
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1266
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1179
      if (rtr)
1267
      if (rtr)
1180
        {
1268
        {
1181
          NS_LOG_LOGIC ("**** Return true");
1269
          NS_LOG_LOGIC ("**** Found GlobalRouter interface, return true");
1182
          return true;
1270
          return true;
1183
        }
1271
        }
1272
      else 
1273
        {
1274
          NS_LOG_LOGIC ("**** No GlobalRouter interface on device, continue search");
1275
        }
1184
    }
1276
    }
1185
  NS_LOG_LOGIC ("**** Return false");
1277
  NS_LOG_LOGIC ("**** No routers found, return false");
1186
  return false;
1278
  return false;
1187
}
1279
}
1188
1280
(-)a/src/routing/global-routing/global-router-interface.h (-1 / +4 lines)
 Lines 35-40    Link Here 
35
35
36
namespace ns3 {
36
namespace ns3 {
37
37
38
class GlobalRouter;
39
38
/**
40
/**
39
 * @brief A single link record for a link state advertisement.
41
 * @brief A single link record for a link state advertisement.
40
 *
42
 *
 Lines 45-50   class GlobalRoutingLinkRecord Link Here 
45
class GlobalRoutingLinkRecord
47
class GlobalRoutingLinkRecord
46
{
48
{
47
public:
49
public:
50
  friend class GlobalRoutingLSA;
48
/**
51
/**
49
 * @enum LinkType
52
 * @enum LinkType
50
 * @brief Enumeration of the possible types of Global Routing Link Records.
53
 * @brief Enumeration of the possible types of Global Routing Link Records.
 Lines 642-648   private: Link Here 
642
645
643
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
646
  Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
644
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
647
  bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
645
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal) const;
648
  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const;
646
  bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
649
  bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
647
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
650
  void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
648
  void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
651
  void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
(-)a/bindings/python/wscript (-6 / +29 lines)
 Lines 16-29   LOCAL_PYBINDGEN_PATH = os.path.join(os.g Link Here 
16
LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen")
16
LOCAL_PYBINDGEN_PATH = os.path.join(os.getcwd(), "bindings", "python", "pybindgen")
17
#PYBINDGEN_BRANCH = 'lp:pybindgen'
17
#PYBINDGEN_BRANCH = 'lp:pybindgen'
18
PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen'
18
PYBINDGEN_BRANCH = 'https://launchpad.net/pybindgen'
19
if os.environ.get('PYTHONPATH', ''):
20
    os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH + os.pathsep + os.environ.get('PYTHONPATH')
21
else:
22
    os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH
23
19
24
## https://launchpad.net/pybindgen/
20
## https://launchpad.net/pybindgen/
25
REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605)
21
REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605)
26
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
22
REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
23
24
25
def add_to_python_path(path):
26
    if os.environ.get('PYTHONPATH', ''):
27
        os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH')
28
    else:
29
        os.environ['PYTHONPATH'] = path
30
31
def set_pybindgen_pythonpath(env):
32
    if env['WITH_PYBINDGEN']:
33
        add_to_python_path(env['WITH_PYBINDGEN'])
34
    else:
35
        add_to_python_path(LOCAL_PYBINDGEN_PATH)
27
36
28
37
29
def set_options(opt):
38
def set_options(opt):
 Lines 41-46   def set_options(opt): Link Here 
41
                         "instead of using the system installed version."),
50
                         "instead of using the system installed version."),
42
                   action="store_true", default=False,
51
                   action="store_true", default=False,
43
                   dest='pybindgen_checkout')
52
                   dest='pybindgen_checkout')
53
    opt.add_option('--with-pybindgen',
54
                   help=('Path to an existing pybindgen source tree to use.'),
55
                   default=None,
56
                   dest='with_pybindgen', type="string")
44
57
45
def fetch_pybindgen(conf):
58
def fetch_pybindgen(conf):
46
    """
59
    """
 Lines 127-140   def configure(conf): Link Here 
127
        conf.env.append_value('CXXFLAGS_PYEXT','-fno-strict-aliasing')
140
        conf.env.append_value('CXXFLAGS_PYEXT','-fno-strict-aliasing')
128
141
129
    ## Check for pybindgen
142
    ## Check for pybindgen
143
144
    no_net = False
145
    if Params.g_options.with_pybindgen:
146
        conf.env['WITH_PYBINDGEN'] = os.path.abspath(Params.g_options.with_pybindgen)
147
        no_net = True
148
130
    if Params.g_options.pybindgen_checkout:
149
    if Params.g_options.pybindgen_checkout:
131
        fetch_pybindgen(conf)
150
        fetch_pybindgen(conf)
151
152
    set_pybindgen_pythonpath(conf.env)
132
153
133
    try:
154
    try:
134
        conf.check_python_module('pybindgen')
155
        conf.check_python_module('pybindgen')
135
    except Configure.ConfigurationError:
156
    except Configure.ConfigurationError:
136
        warning("pybindgen missing")
157
        warning("pybindgen missing")
137
        if not fetch_pybindgen(conf):
158
        if no_net or not fetch_pybindgen(conf):
138
            conf.report_optional_feature("python", "Python Bindings", False,
159
            conf.report_optional_feature("python", "Python Bindings", False,
139
                                         "PyBindGen missing and could not be retrieved")
160
                                         "PyBindGen missing and could not be retrieved")
140
            return
161
            return
 Lines 152-158   def configure(conf): Link Here 
152
            warning("pybindgen (found %s) is too old (need %s)" %
173
            warning("pybindgen (found %s) is too old (need %s)" %
153
                    (pybindgen_version_str,
174
                    (pybindgen_version_str,
154
                     '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])))
175
                     '.'.join([str(x) for x in REQUIRED_PYBINDGEN_VERSION])))
155
            if not fetch_pybindgen(conf):
176
            if no_net or not fetch_pybindgen(conf):
156
                conf.report_optional_feature("python", "Python Bindings", False,
177
                conf.report_optional_feature("python", "Python Bindings", False,
157
                                             "PyBindGen too old and newer version could not be retrieved")
178
                                             "PyBindGen too old and newer version could not be retrieved")
158
                return
179
                return
 Lines 390-395   def build(bld): Link Here 
390
411
391
    env = bld.env_of_name('default')
412
    env = bld.env_of_name('default')
392
    curdir = bld.m_curdirnode.abspath()
413
    curdir = bld.m_curdirnode.abspath()
414
415
    set_pybindgen_pythonpath(env)
393
416
394
    #Object.register('all-ns3-headers', AllNs3Headers)
417
    #Object.register('all-ns3-headers', AllNs3Headers)
395
    Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE')
418
    Action.Action('gen-ns3-metaheader', func=gen_ns3_metaheader, color='BLUE')
(-)a/regression.py (-42 / +50 lines)
 Lines 42-58   def dev_null(): Link Here 
42
42
43
### Regression testing
43
### Regression testing
44
class Regression(object):
44
class Regression(object):
45
    def __init__(self, testdir):
45
    def __init__(self, testdir, reference_traces):
46
        self.testdir = testdir
46
        self.testdir = testdir
47
        self.reference_traces = reference_traces
47
        self.env = Params.g_build.env_of_name('default')
48
        self.env = Params.g_build.env_of_name('default')
48
49
49
    def run_test(self, verbose, generate, refDirName, testName, arguments=[], pyscript=None, refTestName=None):
50
    def run_test(self, verbose, generate, testName, arguments=[], pyscript=None, refTestName=None):
50
        """
51
        """
51
        @param verbose: enable verbose execution
52
        @param verbose: enable verbose execution
52
53
53
        @param generate: generate new traces instead of comparing with the reference
54
        @param generate: generate new traces instead of comparing with the reference
54
55
        @param refDirName: name of the base directory containing reference traces
56
55
57
        @param testName: name of the test
56
        @param testName: name of the test
58
57
 Lines 70-80   class Regression(object): Link Here 
70
            raise TypeError
69
            raise TypeError
71
        
70
        
72
        if refTestName is None:
71
        if refTestName is None:
73
            refTestDirName = os.path.join(refDirName, (testName + ".ref"))
72
            refTestDirName = os.path.join(self.reference_traces, (testName + ".ref"))
74
        else:
73
        else:
75
            refTestDirName = os.path.join(refDirName, refTestName)
74
            refTestDirName = os.path.join(self.reference_traces, refTestName)
76
75
77
        if not os.path.exists(refDirName):
76
        if not os.path.exists(self.reference_traces):
78
            print"No reference trace repository"
77
            print"No reference trace repository"
79
            return 1
78
            return 1
80
79
 Lines 90-96   class Regression(object): Link Here 
90
                    tmpl = tmpl + " " + arg
89
                    tmpl = tmpl + " " + arg
91
                wutils.run_program(testName, tmpl)
90
                wutils.run_program(testName, tmpl)
92
            else:
91
            else:
93
                argv = [self.env['PYTHON'], os.path.join('..', '..', '..', *os.path.split(pyscript))] + arguments
92
                argv = [self.env['PYTHON'], os.path.join(Params.g_cwd_launch, *os.path.split(pyscript))] + arguments
94
                before = os.getcwd()
93
                before = os.getcwd()
95
                os.chdir(refTestDirName)
94
                os.chdir(refTestDirName)
96
                try:
95
                try:
 Lines 170-185   def _find_tests(testdir): Link Here 
170
    tests.sort()
169
    tests.sort()
171
    return tests
170
    return tests
172
171
173
def run_regression():
172
def run_regression(reference_traces):
174
    """Execute regression tests."""
173
    """Execute regression tests.  Called with cwd set to the 'regression' subdir of ns-3.
174
175
    @param reference_traces: reference traces directory, or None for default.
176
177
    """
175
178
176
    testdir = "tests"
179
    testdir = "tests"
177
    if not os.path.exists(testdir):
180
    if not os.path.exists(testdir):
178
        print "Tests directory does not exist"
181
        print "Tests directory does not exist"
179
        sys.exit(3)
182
        sys.exit(3)
183
184
    dir_name = (wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX)
185
    if reference_traces is None:
186
        reference_traces = dir_name
187
        no_net = False
188
    else:
189
        no_net = True
180
    
190
    
181
    sys.path.append(testdir)
191
    sys.path.append(testdir)
182
    sys.modules['tracediff'] = Regression(testdir)
192
    sys.modules['tracediff'] = Regression(testdir, reference_traces)
183
193
184
    if Params.g_options.regression_tests:
194
    if Params.g_options.regression_tests:
185
        tests = Params.g_options.regression_tests.split(',')
195
        tests = Params.g_options.regression_tests.split(',')
 Lines 187-222   def run_regression(): Link Here 
187
        tests = _find_tests(testdir)
197
        tests = _find_tests(testdir)
188
198
189
    print "========== Running Regression Tests =========="
199
    print "========== Running Regression Tests =========="
190
    dir_name = wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX
191
    env = Params.g_build.env_of_name('default')
200
    env = Params.g_build.env_of_name('default')
192
    if env['MERCURIAL']:
201
    if not no_net:
193
        print "Synchronizing reference traces using Mercurial."
202
        if env['MERCURIAL']:
194
        if not os.path.exists(dir_name):
203
            print "Synchronizing reference traces using Mercurial."
195
            print "Cloning " + REGRESSION_TRACES_REPO + dir_name + " from repo."
204
            if not os.path.exists(reference_traces):
196
            argv = ["hg", "clone", REGRESSION_TRACES_REPO + dir_name, dir_name]
205
                print "Cloning " + REGRESSION_TRACES_REPO + dir_name + " from repo."
197
            rv = subprocess.Popen(argv).wait()
206
                argv = ["hg", "clone", REGRESSION_TRACES_REPO + dir_name, reference_traces]
207
                rv = subprocess.Popen(argv).wait()
208
            else:
209
                _dir = os.getcwd()
210
                os.chdir(reference_traces)
211
                try:
212
                    print "Pulling " + REGRESSION_TRACES_REPO + dir_name + " from repo."
213
                    result = subprocess.Popen(["hg", "-q", "pull", REGRESSION_TRACES_REPO + dir_name]).wait()
214
                    if not result:
215
                        result = subprocess.Popen(["hg", "-q", "update"]).wait()
216
                finally:
217
                    os.chdir("..")
218
                if result:
219
                    Params.fatal("Synchronizing reference traces using Mercurial failed.")
198
        else:
220
        else:
199
            _dir = os.getcwd()
221
            if not os.path.exists(reference_traces):
200
            os.chdir(dir_name)
222
                traceball = dir_name + wutils.TRACEBALL_SUFFIX
201
            try:
223
                print "Retrieving " + traceball + " from web."
202
                print "Pulling " + REGRESSION_TRACES_REPO + dir_name + " from repo."
224
                urllib.urlretrieve(REGRESSION_TRACES_URL + traceball, traceball)
203
                result = subprocess.Popen(["hg", "-q", "pull", REGRESSION_TRACES_REPO + dir_name]).wait()
225
                os.system("tar -xjf %s -C .." % (traceball))
204
                if not result:
226
                print "Done."
205
                    result = subprocess.Popen(["hg", "-q", "update"]).wait()
206
            finally:
207
                os.chdir("..")
208
            if result:
209
                Params.fatal("Synchronizing reference traces using Mercurial failed.")
210
    else:
211
        if not os.path.exists(dir_name):
212
            traceball = dir_name + wutils.TRACEBALL_SUFFIX
213
            print "Retrieving " + traceball + " from web."
214
            urllib.urlretrieve(REGRESSION_TRACES_URL + traceball, traceball)
215
            os.system("tar -xjf %s -C .." % (traceball))
216
            print "Done."
217
227
218
    if not os.path.exists(dir_name):
228
    if not os.path.exists(reference_traces):
219
        print "Reference traces directory (%s) does not exist" % dir_name
229
        print "Reference traces directory (%s) does not exist" % reference_traces
220
        return 3
230
        return 3
221
    
231
    
222
    bad = []
232
    bad = []
 Lines 254-262   def _run_regression_test(test): Link Here 
254
    else:
264
    else:
255
        os.mkdir("traces")
265
        os.mkdir("traces")
256
    
266
    
257
    dir_name = wutils.APPNAME + '-' + wutils.VERSION + REGRESSION_SUFFIX
258
259
    mod = __import__(test, globals(), locals(), [])
267
    mod = __import__(test, globals(), locals(), [])
260
    return mod.run(verbose=(Params.g_options.verbose > 0),
268
    return mod.run(verbose=(Params.g_options.verbose > 0),
261
                   generate=Params.g_options.regression_generate,
269
                   generate=Params.g_options.regression_generate)
262
                   refDirName=dir_name)
270
(-)a/regression/tests/test-csma-bridge.py (-2 / +2 lines)
 Lines 6-15   import sys Link Here 
6
import sys
6
import sys
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
    if tracediff.env['ENABLE_PYTHON_BINDINGS']:
11
    if tracediff.env['ENABLE_PYTHON_BINDINGS']:
12
        return tracediff.run_test(verbose, generate, refDirName,
12
        return tracediff.run_test(verbose, generate,
13
                                  "csma-bridge", pyscript=os.path.join('examples', 'csma-bridge.py'))
13
                                  "csma-bridge", pyscript=os.path.join('examples', 'csma-bridge.py'))
14
    else:
14
    else:
15
        print >> sys.stderr, "Skipping csma-bridge: Python bindings not available."
15
        print >> sys.stderr, "Skipping csma-bridge: Python bindings not available."
(-)a/regression/tests/test-csma-broadcast.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-broadcast")
12
    return tracediff.run_test(verbose, generate, "csma-broadcast")
(-)a/regression/tests/test-csma-multicast.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-multicast")
12
    return tracediff.run_test(verbose, generate, "csma-multicast")
(-)a/regression/tests/test-csma-one-subnet.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-one-subnet")
12
    return tracediff.run_test(verbose, generate, "csma-one-subnet")
(-)a/regression/tests/test-csma-packet-socket.py (-2 / +2 lines)
 Lines 6-13   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName,
12
    return tracediff.run_test(verbose, generate,
13
        "csma-packet-socket")
13
        "csma-packet-socket")
(-)a/regression/tests/test-csma-ping.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-ping")
12
    return tracediff.run_test(verbose, generate, "csma-ping")
(-)a/regression/tests/test-csma-raw-ip-socket.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-raw-ip-socket")
12
    return tracediff.run_test(verbose, generate, "csma-raw-ip-socket")
(-)a/regression/tests/test-csma-star.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "csma-star")
12
    return tracediff.run_test(verbose, generate, "csma-star")
(-)a/regression/tests/test-realtime-udp-echo.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "realtime-udp-echo")
12
    return tracediff.run_test(verbose, generate, "realtime-udp-echo")
(-)a/regression/tests/test-simple-error-model.py (-2 / +2 lines)
 Lines 6-13   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName,
12
    return tracediff.run_test(verbose, generate,
13
        "simple-error-model")
13
        "simple-error-model")
(-)a/regression/tests/test-simple-global-routing.py (-2 / +2 lines)
 Lines 6-13   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName,
12
    return tracediff.run_test(verbose, generate,
13
        "simple-global-routing")
13
        "simple-global-routing")
(-)a/regression/tests/test-simple-point-to-point-olsr.py (-2 / +2 lines)
 Lines 6-13   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName,
12
    return tracediff.run_test(verbose, generate,
13
        "simple-point-to-point-olsr")
13
        "simple-point-to-point-olsr")
(-)a/regression/tests/test-tcp-large-transfer.py (-2 / +2 lines)
 Lines 6-13   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName,
12
    return tracediff.run_test(verbose, generate,
13
        "tcp-large-transfer")
13
        "tcp-large-transfer")
(-)a/regression/tests/test-tcp-nsc-lfn.py (-2 / +2 lines)
 Lines 9-15   import platform Link Here 
9
import platform
9
import platform
10
10
11
11
12
def run(verbose, generate, refDirName):
12
def run(verbose, generate):
13
    """Run a Network Simulation Cradle test involving two TCP streams."""
13
    """Run a Network Simulation Cradle test involving two TCP streams."""
14
14
15
    if not tracediff.env['ENABLE_NSC']:
15
    if not tracediff.env['ENABLE_NSC']:
 Lines 29-33   def run(verbose, generate, refDirName): Link Here 
29
        # string might not be the best idea?
29
        # string might not be the best idea?
30
        raise "Unknown architecture, not 64 or 32 bit?"
30
        raise "Unknown architecture, not 64 or 32 bit?"
31
31
32
    return tracediff.run_test(verbose, generate, refDirName,
32
    return tracediff.run_test(verbose, generate,
33
        testName, arguments=arguments, refTestName=traceDirName)
33
        testName, arguments=arguments, refTestName=traceDirName)
(-)a/regression/tests/test-udp-echo.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
    #print tracediff.env
11
    #print tracediff.env
12
    return tracediff.run_test(verbose, generate, refDirName, "udp-echo")
12
    return tracediff.run_test(verbose, generate, "udp-echo")
(-)a/regression/tests/test-wifi-wired-bridging.py (-2 / +2 lines)
 Lines 6-12   import shutil Link Here 
6
import shutil
6
import shutil
7
import tracediff
7
import tracediff
8
8
9
def run(verbose, generate, refDirName):
9
def run(verbose, generate):
10
    """Execute a test."""
10
    """Execute a test."""
11
11
12
    return tracediff.run_test(verbose, generate, refDirName, "wifi-wired-bridging", ["--SendIp=0"])
12
    return tracediff.run_test(verbose, generate, "wifi-wired-bridging", ["--SendIp=0"])
(-)a/src/core/object.cc (-1 / +2 lines)
 Lines 111-120   Object::DoGetObject (TypeId tid) const Link Here 
111
{
111
{
112
  NS_ASSERT (CheckLoose ());
112
  NS_ASSERT (CheckLoose ());
113
  const Object *currentObject = this;
113
  const Object *currentObject = this;
114
  TypeId objectTid = Object::GetTypeId ();
114
  do {
115
  do {
115
    NS_ASSERT (currentObject != 0);
116
    NS_ASSERT (currentObject != 0);
116
    TypeId cur = currentObject->GetInstanceTypeId ();
117
    TypeId cur = currentObject->GetInstanceTypeId ();
117
    while (cur != tid && cur != Object::GetTypeId ())
118
    while (cur != tid && cur != objectTid)
118
      {
119
      {
119
        cur = cur.GetParent ();
120
        cur = cur.GetParent ();
120
      }
121
      }
(-)a/src/core/type-id.cc (-16 lines)
 Lines 365-374   namespace ns3 { Link Here 
365
 *         The TypeId class
365
 *         The TypeId class
366
 *********************************************************************/
366
 *********************************************************************/
367
367
368
TypeId::TypeId ()
369
  : m_tid (0)
370
{}
371
372
TypeId::TypeId (const char *name)
368
TypeId::TypeId (const char *name)
373
{
369
{
374
  uint16_t uid = Singleton<IidManager>::Get ()->AllocateUid (name);
370
  uint16_t uid = Singleton<IidManager>::Get ()->AllocateUid (name);
 Lines 379-386   TypeId::TypeId (const char *name) Link Here 
379
375
380
TypeId::TypeId (uint16_t tid)
376
TypeId::TypeId (uint16_t tid)
381
  : m_tid (tid)
377
  : m_tid (tid)
382
{}
383
TypeId::~TypeId ()
384
{}
378
{}
385
TypeId 
379
TypeId 
386
TypeId::LookupByName (std::string name)
380
TypeId::LookupByName (std::string name)
 Lines 692-707   std::istream & operator >> (std::istream Link Here 
692
686
693
ATTRIBUTE_HELPER_CPP (TypeId);
687
ATTRIBUTE_HELPER_CPP (TypeId);
694
688
695
bool operator == (TypeId a, TypeId b)
696
{
697
  return a.m_tid == b.m_tid;
698
}
699
700
bool operator != (TypeId a, TypeId b)
701
{
702
  return a.m_tid != b.m_tid;
703
}
704
705
bool operator < (TypeId a, TypeId b)
689
bool operator < (TypeId a, TypeId b)
706
{
690
{
707
  return a.m_tid < b.m_tid;
691
  return a.m_tid < b.m_tid;
(-)a/src/core/type-id.h (-4 / +28 lines)
 Lines 351-358   public: Link Here 
351
  void SetUid (uint16_t tid);
351
  void SetUid (uint16_t tid);
352
352
353
  // construct an invalid TypeId.
353
  // construct an invalid TypeId.
354
  TypeId ();
354
  inline TypeId ();
355
  ~TypeId ();
355
  inline TypeId (const TypeId &o);
356
  inline TypeId &operator = (const TypeId &o);
357
  inline ~TypeId ();
356
358
357
private:
359
private:
358
  friend class AttributeList;
360
  friend class AttributeList;
 Lines 377-384   private: Link Here 
377
379
378
std::ostream & operator << (std::ostream &os, TypeId tid);
380
std::ostream & operator << (std::ostream &os, TypeId tid);
379
std::istream & operator >> (std::istream &is, TypeId &tid);
381
std::istream & operator >> (std::istream &is, TypeId &tid);
380
bool operator == (TypeId a, TypeId b);
382
inline bool operator == (TypeId a, TypeId b);
381
bool operator != (TypeId a, TypeId b);
383
inline bool operator != (TypeId a, TypeId b);
382
bool operator <  (TypeId a, TypeId b);
384
bool operator <  (TypeId a, TypeId b);
383
385
384
/**
386
/**
 Lines 392-397   ATTRIBUTE_HELPER_HEADER (TypeId); Link Here 
392
} // namespace ns3 
394
} // namespace ns3 
393
395
394
namespace ns3 {
396
namespace ns3 {
397
398
TypeId::TypeId ()
399
  : m_tid (0) {}
400
TypeId::TypeId (const TypeId &o)
401
  : m_tid (o.m_tid) {}
402
TypeId &TypeId::operator = (const TypeId &o)
403
{
404
  m_tid = o.m_tid;
405
  return *this;
406
}
407
TypeId::~TypeId ()
408
{}
409
inline bool operator == (TypeId a, TypeId b)
410
{
411
  return a.m_tid == b.m_tid;
412
}
413
414
inline bool operator != (TypeId a, TypeId b)
415
{
416
  return a.m_tid != b.m_tid;
417
}
418
395
419
396
/*************************************************************************
420
/*************************************************************************
397
 *   The TypeId implementation which depends on templates
421
 *   The TypeId implementation which depends on templates
(-)a/src/internet-stack/ipv4-l3-protocol.cc (-6 / +31 lines)
 Lines 669-676   Ipv4L3Protocol::Send (Ptr<Packet> packet Link Here 
669
          else
669
          else
670
            {
670
            {
671
              NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
671
              NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
672
              m_txTrace (packetCopy, ifaceIndex);
672
              if (outInterface->IsUp ())
673
              outInterface->Send (packetCopy, destination);
673
                {
674
                  m_txTrace (packetCopy, ifaceIndex);
675
                  outInterface->Send (packetCopy, destination);
676
                }
677
              else
678
                {
679
                  m_dropTrace (packetCopy);
680
                }
674
            }
681
            }
675
        }
682
        }
676
    }
683
    }
 Lines 732-744   Ipv4L3Protocol::SendRealOut (bool found, Link Here 
732
      m_txTrace (packet, route.GetInterface ());
739
      m_txTrace (packet, route.GetInterface ());
733
      if (route.IsGateway ()) 
740
      if (route.IsGateway ()) 
734
        {
741
        {
735
          NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
742
          if (outInterface->IsUp ())
736
          outInterface->Send (packet, route.GetGateway ());
743
            {
744
              NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
745
              m_txTrace (packet, route.GetInterface ());
746
              outInterface->Send (packet, route.GetGateway ());
747
            }
748
          else
749
            {
750
              NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route.GetGateway ());
751
              m_dropTrace (packet);
752
            }
737
        } 
753
        } 
738
      else 
754
      else 
739
        {
755
        {
740
          NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
756
          if (outInterface->IsUp ())
741
          outInterface->Send (packet, ipHeader.GetDestination ());
757
            {
758
              NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
759
              m_txTrace (packet, route.GetInterface ());
760
              outInterface->Send (packet, ipHeader.GetDestination ());
761
            }
762
          else
763
            {
764
              NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route.GetGateway ());
765
              m_dropTrace (packet);
766
            }
742
        }
767
        }
743
    }
768
    }
744
}
769
}
(-)a/src/internet-stack/wscript (-1 / +1 lines)
 Lines 7-13   import urllib Link Here 
7
# Mercurial repository of the network simulation cradle
7
# Mercurial repository of the network simulation cradle
8
NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc"
8
NSC_REPO = "https://secure.wand.net.nz/mercurial/nsc"
9
NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
9
NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
10
NSC_RELEASE_NAME = "nsc-0.4.0"
10
NSC_RELEASE_NAME = "nsc-0.5.0"
11
11
12
# directory that contains network simulation cradle source
12
# directory that contains network simulation cradle source
13
# note, this path is relative to the project root
13
# note, this path is relative to the project root
(-)a/wscript (-1 / +14 lines)
 Lines 143-148   def set_options(opt): Link Here 
143
                   help=('Use sudo to setup suid bits on ns3 executables.'),
143
                   help=('Use sudo to setup suid bits on ns3 executables.'),
144
                   dest='enable_sudo', action='store_true',
144
                   dest='enable_sudo', action='store_true',
145
                   default=False)
145
                   default=False)
146
    opt.add_option('--with-regression-traces',
147
                   help=('Path to the regression reference traces directory'),
148
                   default=None,
149
                   dest='regression_traces', type="string")
146
150
147
    # options provided in a script in a subdirectory named "src"
151
    # options provided in a script in a subdirectory named "src"
148
    opt.sub_options('src')
152
    opt.sub_options('src')
 Lines 192-197   def configure(conf): Link Here 
192
        variant_name = debug_level
196
        variant_name = debug_level
193
197
194
    variant_env['INCLUDEDIR'] = os.path.join(variant_env['PREFIX'], 'include')
198
    variant_env['INCLUDEDIR'] = os.path.join(variant_env['PREFIX'], 'include')
199
200
    if Params.g_options.regression_traces is not None:
201
        variant_env['REGRESSION_TRACES'] = os.path.join("..", Params.g_options.regression_traces)
202
    else:
203
        variant_env['REGRESSION_TRACES'] = None
195
204
196
    if Params.g_options.enable_gcov:
205
    if Params.g_options.enable_gcov:
197
        variant_name += '-gcov'
206
        variant_name += '-gcov'
 Lines 463-472   def shutdown(): Link Here 
463
    if Params.g_options.regression or Params.g_options.regression_generate:
472
    if Params.g_options.regression or Params.g_options.regression_generate:
464
        if not env['DIFF']:
473
        if not env['DIFF']:
465
            Params.fatal("Cannot run regression tests: the 'diff' program is not installed.")
474
            Params.fatal("Cannot run regression tests: the 'diff' program is not installed.")
475
466
        _dir = os.getcwd()
476
        _dir = os.getcwd()
467
        os.chdir("regression")
477
        os.chdir("regression")
478
        regression_traces = env['REGRESSION_TRACES']
479
        if not regression_traces:
480
            regression_traces = None
468
        try:
481
        try:
469
            regression.run_regression()
482
            regression.run_regression(regression_traces)
470
        finally:
483
        finally:
471
            os.chdir(_dir)
484
            os.chdir(_dir)
472
485
(-)a/src/routing/global-routing/global-router-interface.cc (-45 / +45 lines)
 Lines 597-603   GlobalRouter::DiscoverLSAs (void) Link Here 
597
597
598
      if (!isIp)
598
      if (!isIp)
599
        {
599
        {
600
          NS_LOG_LOGIC ("**** Net device " << ndLocal << "has no IP interface, skipping");
600
          NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface, skipping");
601
          continue;
601
          continue;
602
        }
602
        }
603
603
 Lines 612-623   GlobalRouter::DiscoverLSAs (void) Link Here 
612
      //
612
      //
613
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
613
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
614
        {
614
        {
615
          NS_LOG_LOGIC ("**** Broadcast link");
615
          NS_LOG_LOGIC ("Broadcast link");
616
          ProcessBroadcastLink (ndLocal, pLSA, c);
616
          ProcessBroadcastLink (ndLocal, pLSA, c);
617
        }
617
        }
618
      else if (ndLocal->IsPointToPoint () )
618
      else if (ndLocal->IsPointToPoint () )
619
        {
619
        {
620
          NS_LOG_LOGIC ("**** Point=to-point link");
620
          NS_LOG_LOGIC ("Point=to-point link");
621
          ProcessPointToPointLink (ndLocal, pLSA);
621
          ProcessPointToPointLink (ndLocal, pLSA);
622
        }
622
        }
623
      else
623
      else
 Lines 700-706   GlobalRouter::ProcessSingleBroadcastLink Link Here 
700
      //
700
      //
701
      // This is a net device connected to a stub network
701
      // This is a net device connected to a stub network
702
      //
702
      //
703
      NS_LOG_LOGIC("**** Router-LSA Stub Network");
703
      NS_LOG_LOGIC("Router-LSA Stub Network");
704
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
704
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
705
705
706
      // 
706
      // 
 Lines 725-731   GlobalRouter::ProcessSingleBroadcastLink Link Here 
725
      // We have multiple routers on a broadcast interface, so this is
725
      // We have multiple routers on a broadcast interface, so this is
726
      // a transit network.
726
      // a transit network.
727
      //
727
      //
728
      NS_LOG_LOGIC ("**** Router-LSA Transit Network");
728
      NS_LOG_LOGIC ("Router-LSA Transit Network");
729
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
729
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
730
730
731
      // 
731
      // 
 Lines 835-841   GlobalRouter::ProcessBridgedBroadcastLin Link Here 
835
      //
835
      //
836
      // This is a net device connected to a bridge of stub networks
836
      // This is a net device connected to a bridge of stub networks
837
      //
837
      //
838
      NS_LOG_LOGIC("**** Router-LSA Stub Network");
838
      NS_LOG_LOGIC("Router-LSA Stub Network");
839
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
839
      plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
840
840
841
      // 
841
      // 
 Lines 860-866   GlobalRouter::ProcessBridgedBroadcastLin Link Here 
860
      // We have multiple routers on a bridged broadcast interface, so this is
860
      // We have multiple routers on a bridged broadcast interface, so this is
861
      // a transit network.
861
      // a transit network.
862
      //
862
      //
863
      NS_LOG_LOGIC ("**** Router-LSA Transit Network");
863
      NS_LOG_LOGIC ("Router-LSA Transit Network");
864
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
864
      plr->SetLinkType (GlobalRoutingLinkRecord::TransitNetwork);
865
865
866
      // 
866
      // 
 Lines 1084-1090   GlobalRouter::FindDesignatedRouterForLin Link Here 
1084
  uint32_t nDevices = ch->GetNDevices();
1084
  uint32_t nDevices = ch->GetNDevices();
1085
  NS_ASSERT (nDevices);
1085
  NS_ASSERT (nDevices);
1086
1086
1087
  NS_LOG_LOGIC ("**** Looking for designated router off of net device " << ndLocal << " on node " << 
1087
  NS_LOG_LOGIC ("Looking for designated router off of net device " << ndLocal << " on node " << 
1088
                ndLocal->GetNode ()->GetId ());
1088
                ndLocal->GetNode ()->GetId ());
1089
1089
1090
  Ipv4Address desigRtr ("255.255.255.255");
1090
  Ipv4Address desigRtr ("255.255.255.255");
 Lines 1100-1106   GlobalRouter::FindDesignatedRouterForLin Link Here 
1100
1100
1101
      Ptr<Node> nodeOther = ndOther->GetNode ();
1101
      Ptr<Node> nodeOther = ndOther->GetNode ();
1102
1102
1103
      NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << nodeOther->GetId ());
1103
      NS_LOG_LOGIC ("Examine channel device " << i << " on node " << nodeOther->GetId ());
1104
1104
1105
      //
1105
      //
1106
      // For all other net devices, we need to check and see if a router
1106
      // For all other net devices, we need to check and see if a router
 Lines 1108-1118   GlobalRouter::FindDesignatedRouterForLin Link Here 
1108
      // device, we need to consider all of the other devices on the 
1108
      // device, we need to consider all of the other devices on the 
1109
      // bridge as well (all of the bridge ports.
1109
      // bridge as well (all of the bridge ports.
1110
      //
1110
      //
1111
      NS_LOG_LOGIC ("**** checking to see if the device is bridged");
1111
      NS_LOG_LOGIC ("checking to see if the device is bridged");
1112
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1112
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1113
      if (bnd)
1113
      if (bnd)
1114
        {
1114
        {
1115
          NS_LOG_LOGIC ("**** Device is bridged by BridgeNetDevice " << bnd);
1115
          NS_LOG_LOGIC ("Device is bridged by BridgeNetDevice " << bnd);
1116
1116
1117
          //
1117
          //
1118
          // It is possible that the bridge net device is sitting under a
1118
          // It is possible that the bridge net device is sitting under a
 Lines 1123-1129   GlobalRouter::FindDesignatedRouterForLin Link Here 
1123
          // an internet stack that includes the Ipv4 interface.  If it doesn't
1123
          // an internet stack that includes the Ipv4 interface.  If it doesn't
1124
          // it can't play router.
1124
          // it can't play router.
1125
          //
1125
          //
1126
          NS_LOG_LOGIC ("**** Checking for router on bridge net device " << bnd);
1126
          NS_LOG_LOGIC ("Checking for router on bridge net device " << bnd);
1127
          Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
1127
          Ptr<GlobalRouter> rtr = nodeOther->GetObject<GlobalRouter> ();
1128
          Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
1128
          Ptr<Ipv4> ipv4 = nodeOther->GetObject<Ipv4> ();
1129
          if (rtr && ipv4)
1129
          if (rtr && ipv4)
 Lines 1131-1166   GlobalRouter::FindDesignatedRouterForLin Link Here 
1131
              uint32_t ifIndexOther;
1131
              uint32_t ifIndexOther;
1132
              if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
1132
              if (FindIfIndexForDevice(nodeOther, bnd, ifIndexOther))
1133
                {
1133
                {
1134
                  NS_LOG_LOGIC ("**** Found router on bridge net device " << bnd);
1134
                  NS_LOG_LOGIC ("Found router on bridge net device " << bnd);
1135
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1135
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1136
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1136
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1137
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1137
                  NS_LOG_LOGIC ("designated router now " << desigRtr);
1138
                }
1138
                }
1139
            }
1139
            }
1140
1140
1141
          NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd);
1141
          NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
1142
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1142
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1143
            {
1143
            {
1144
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1144
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1145
              NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged);
1145
              NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
1146
              if (ndBridged == ndOther)
1146
              if (ndBridged == ndOther)
1147
                {
1147
                {
1148
                  NS_LOG_LOGIC ("**** That bridge port is me, don't walk backward");
1148
                  NS_LOG_LOGIC ("That bridge port is me, don't walk backward");
1149
                  continue;
1149
                  continue;
1150
                }
1150
                }
1151
1151
1152
              if (allowRecursion)
1152
              if (allowRecursion)
1153
                {
1153
                {
1154
                  NS_LOG_LOGIC ("**** Recursively looking for routers down bridge port " << ndBridged);
1154
                  NS_LOG_LOGIC ("Recursively looking for routers down bridge port " << ndBridged);
1155
                  Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false);
1155
                  Ipv4Address addrOther = FindDesignatedRouterForLink (ndBridged, false);
1156
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1156
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1157
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1157
                  NS_LOG_LOGIC ("designated router now " << desigRtr);
1158
                }
1158
                }
1159
            }
1159
            }
1160
        }
1160
        }
1161
      else
1161
      else
1162
        {
1162
        {
1163
          NS_LOG_LOGIC ("**** This device is not bridged");
1163
          NS_LOG_LOGIC ("This device is not bridged");
1164
          Ptr<Node> nodeOther = ndOther->GetNode ();
1164
          Ptr<Node> nodeOther = ndOther->GetNode ();
1165
          NS_ASSERT (nodeOther);
1165
          NS_ASSERT (nodeOther);
1166
1166
 Lines 1175-1184   GlobalRouter::FindDesignatedRouterForLin Link Here 
1175
              uint32_t ifIndexOther;
1175
              uint32_t ifIndexOther;
1176
              if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
1176
              if (FindIfIndexForDevice(nodeOther, ndOther, ifIndexOther))
1177
                {
1177
                {
1178
                  NS_LOG_LOGIC ("**** Found router on net device " << ndOther);
1178
                  NS_LOG_LOGIC ("Found router on net device " << ndOther);
1179
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1179
                  Ipv4Address addrOther = ipv4->GetAddress (ifIndexOther);
1180
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1180
                  desigRtr = addrOther < desigRtr ? addrOther : desigRtr;
1181
                  NS_LOG_LOGIC ("**** designated router now " << desigRtr);
1181
                  NS_LOG_LOGIC ("designated router now " << desigRtr);
1182
                }
1182
                }
1183
            }
1183
            }
1184
        }
1184
        }
 Lines 1201-1207   GlobalRouter::AnotherRouterOnLink (Ptr<N Link Here 
1201
  uint32_t nDevices = ch->GetNDevices();
1201
  uint32_t nDevices = ch->GetNDevices();
1202
  NS_ASSERT (nDevices);
1202
  NS_ASSERT (nDevices);
1203
1203
1204
  NS_LOG_LOGIC ("**** Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ());
1204
  NS_LOG_LOGIC ("Looking for routers off of net device " << nd << " on node " << nd->GetNode ()->GetId ());
1205
1205
1206
  //
1206
  //
1207
  // Look through all of the devices on the channel to which the net device
1207
  // Look through all of the devices on the channel to which the net device
 Lines 1212-1225   GlobalRouter::AnotherRouterOnLink (Ptr<N Link Here 
1212
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1212
      Ptr<NetDevice> ndOther = ch->GetDevice (i);
1213
      NS_ASSERT (ndOther);
1213
      NS_ASSERT (ndOther);
1214
1214
1215
      NS_LOG_LOGIC ("**** Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ());
1215
      NS_LOG_LOGIC ("Examine channel device " << i << " on node " << ndOther->GetNode ()->GetId ());
1216
1216
1217
      // 
1217
      // 
1218
      // Ignore the net device itself.
1218
      // Ignore the net device itself.
1219
      //
1219
      //
1220
      if (ndOther == nd)
1220
      if (ndOther == nd)
1221
        {
1221
        {
1222
          NS_LOG_LOGIC ("**** Myself, skip");
1222
          NS_LOG_LOGIC ("Myself, skip");
1223
          continue;
1223
          continue;
1224
        }
1224
        }
1225
1225
 Lines 1229-1280   GlobalRouter::AnotherRouterOnLink (Ptr<N Link Here 
1229
      // device, we need to consider all of the other devices on the 
1229
      // device, we need to consider all of the other devices on the 
1230
      // bridge.
1230
      // bridge.
1231
      //
1231
      //
1232
      NS_LOG_LOGIC ("**** checking to see if device is bridged");
1232
      NS_LOG_LOGIC ("checking to see if device is bridged");
1233
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1233
      Ptr<BridgeNetDevice> bnd = NetDeviceIsBridged (ndOther);
1234
      if (bnd)
1234
      if (bnd)
1235
        {
1235
        {
1236
          NS_LOG_LOGIC ("**** Device is bridged by net device " << bnd);
1236
          NS_LOG_LOGIC ("Device is bridged by net device " << bnd);
1237
          NS_LOG_LOGIC ("**** Looking through bridge ports of bridge net device " << bnd);
1237
          NS_LOG_LOGIC ("Looking through bridge ports of bridge net device " << bnd);
1238
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1238
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1239
            {
1239
            {
1240
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1240
              Ptr<NetDevice> ndBridged = bnd->GetBridgePort (j);
1241
              NS_LOG_LOGIC ("**** Examining bridge port " << j << " device " << ndBridged);
1241
              NS_LOG_LOGIC ("Examining bridge port " << j << " device " << ndBridged);
1242
              if (ndBridged == ndOther)
1242
              if (ndBridged == ndOther)
1243
                {
1243
                {
1244
                  NS_LOG_LOGIC ("**** That bridge port is me, skip");
1244
                  NS_LOG_LOGIC ("That bridge port is me, skip");
1245
                  continue;
1245
                  continue;
1246
                }
1246
                }
1247
1247
1248
              if (allowRecursion)
1248
              if (allowRecursion)
1249
                {
1249
                {
1250
                  NS_LOG_LOGIC ("**** Recursively looking for routers on bridge port " << ndBridged);
1250
                  NS_LOG_LOGIC ("Recursively looking for routers on bridge port " << ndBridged);
1251
                  if (AnotherRouterOnLink (ndBridged, false))
1251
                  if (AnotherRouterOnLink (ndBridged, false))
1252
                    {
1252
                    {
1253
                      NS_LOG_LOGIC ("**** Found routers on bridge port, return true");
1253
                      NS_LOG_LOGIC ("Found routers on bridge port, return true");
1254
                      return true;
1254
                      return true;
1255
                    }
1255
                    }
1256
                }
1256
                }
1257
            }
1257
            }
1258
          NS_LOG_LOGIC ("**** No routers on bridged net device, return false");
1258
          NS_LOG_LOGIC ("No routers on bridged net device, return false");
1259
          return false;
1259
          return false;
1260
        }
1260
        }
1261
1261
1262
      NS_LOG_LOGIC ("**** This device is not bridged");
1262
      NS_LOG_LOGIC ("This device is not bridged");
1263
      Ptr<Node> nodeTemp = ndOther->GetNode ();
1263
      Ptr<Node> nodeTemp = ndOther->GetNode ();
1264
      NS_ASSERT (nodeTemp);
1264
      NS_ASSERT (nodeTemp);
1265
1265
1266
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1266
      Ptr<GlobalRouter> rtr = nodeTemp->GetObject<GlobalRouter> ();
1267
      if (rtr)
1267
      if (rtr)
1268
        {
1268
        {
1269
          NS_LOG_LOGIC ("**** Found GlobalRouter interface, return true");
1269
          NS_LOG_LOGIC ("Found GlobalRouter interface, return true");
1270
          return true;
1270
          return true;
1271
        }
1271
        }
1272
      else 
1272
      else 
1273
        {
1273
        {
1274
          NS_LOG_LOGIC ("**** No GlobalRouter interface on device, continue search");
1274
          NS_LOG_LOGIC ("No GlobalRouter interface on device, continue search");
1275
        }
1275
        }
1276
    }
1276
    }
1277
  NS_LOG_LOGIC ("**** No routers found, return false");
1277
  NS_LOG_LOGIC ("No routers found, return false");
1278
  return false;
1278
  return false;
1279
}
1279
}
1280
1280
 Lines 1365-1371   GlobalRouter::FindIfIndexForDevice (Ptr< Link Here 
1365
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1365
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1366
  if (ipv4 == 0)
1366
  if (ipv4 == 0)
1367
    {
1367
    {
1368
      NS_LOG_LOGIC ("**** No Ipv4 interface on node " << node->GetId ());
1368
      NS_LOG_LOGIC ("No Ipv4 interface on node " << node->GetId ());
1369
      return false;
1369
      return false;
1370
    }
1370
    }
1371
1371
 Lines 1373-1385   GlobalRouter::FindIfIndexForDevice (Ptr< Link Here 
1373
    {
1373
    {
1374
      if (ipv4->GetNetDevice(i) == nd) 
1374
      if (ipv4->GetNetDevice(i) == nd) 
1375
        {
1375
        {
1376
          NS_LOG_LOGIC ("**** Device " << nd << " has associated ipv4 index " << i);
1376
          NS_LOG_LOGIC ("Device " << nd << " has associated ipv4 index " << i);
1377
          index = i;
1377
          index = i;
1378
          return true;
1378
          return true;
1379
        }
1379
        }
1380
    }
1380
    }
1381
1381
1382
  NS_LOG_LOGIC ("**** Device " << nd << " has no associated ipv4 index");
1382
  NS_LOG_LOGIC ("Device " << nd << " has no associated ipv4 index");
1383
  return false;
1383
  return false;
1384
}
1384
}
1385
1385
 Lines 1403-1428   GlobalRouter::NetDeviceIsBridged (Ptr<Ne Link Here 
1403
  for (uint32_t i = 0; i < nDevices; ++i)
1403
  for (uint32_t i = 0; i < nDevices; ++i)
1404
    {
1404
    {
1405
      Ptr<NetDevice> ndTest = node->GetDevice(i);
1405
      Ptr<NetDevice> ndTest = node->GetDevice(i);
1406
      NS_LOG_LOGIC ("**** Examine device " << i << " " << ndTest);
1406
      NS_LOG_LOGIC ("Examine device " << i << " " << ndTest);
1407
1407
1408
      if (ndTest->IsBridge ())
1408
      if (ndTest->IsBridge ())
1409
        {
1409
        {
1410
          NS_LOG_LOGIC ("**** device " << i << " is a bridge net device");
1410
          NS_LOG_LOGIC ("device " << i << " is a bridge net device");
1411
          Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> ();
1411
          Ptr<BridgeNetDevice> bnd = ndTest->GetObject<BridgeNetDevice> ();
1412
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1412
          NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
1413
1413
1414
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1414
          for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
1415
            {
1415
            {
1416
              NS_LOG_LOGIC ("**** Examine bridge port " << j << " " << bnd->GetBridgePort (j));
1416
              NS_LOG_LOGIC ("Examine bridge port " << j << " " << bnd->GetBridgePort (j));
1417
              if (bnd->GetBridgePort (j) == nd)
1417
              if (bnd->GetBridgePort (j) == nd)
1418
                {
1418
                {
1419
                  NS_LOG_LOGIC ("**** Net device " << nd << " is bridged by " << bnd);
1419
                  NS_LOG_LOGIC ("Net device " << nd << " is bridged by " << bnd);
1420
                  return bnd;
1420
                  return bnd;
1421
                }
1421
                }
1422
            }
1422
            }
1423
        }
1423
        }
1424
    }
1424
    }
1425
  NS_LOG_LOGIC ("**** Net device " << nd << " is not bridged");
1425
  NS_LOG_LOGIC ("Net device " << nd << " is not bridged");
1426
  return 0;
1426
  return 0;
1427
}
1427
}
1428
1428

Return to bug 114