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

(-)09ff9d07333e (+224 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
18
//
19
// Network topology
20
//
21
//  n0
22
//     \ 5 Mb/s, 2ms
23
//      \          1.5Mb/s, 10ms
24
//       n2 ------------------------n3
25
//      /                          /
26
//     / 5 Mb/s, 2ms              /
27
//   n1--------------------------
28
//          1.5 Mb/s, 100ms
29
//
30
// this is a modification of simple-global-routing to allow for
31
// a single hop but higher-cost path between n1 and n3
32
// 
33
// - Tracing of queues and packet receptions to file "simple-rerouting.tr"
34
35
#include <iostream>
36
#include <fstream>
37
#include <string>
38
#include <cassert>
39
40
#include "ns3/log.h"
41
42
#include "ns3/command-line.h"
43
#include "ns3/default-value.h"
44
#include "ns3/ptr.h"
45
#include "ns3/random-variable.h"
46
47
#include "ns3/simulator.h"
48
#include "ns3/nstime.h"
49
#include "ns3/data-rate.h"
50
51
#include "ns3/ascii-trace.h"
52
#include "ns3/pcap-trace.h"
53
#include "ns3/internet-node.h"
54
#include "ns3/point-to-point-channel.h"
55
#include "ns3/point-to-point-net-device.h"
56
#include "ns3/ipv4-address.h"
57
#include "ns3/ipv4.h"
58
#include "ns3/socket.h"
59
#include "ns3/inet-socket-address.h"
60
#include "ns3/ipv4-route.h"
61
#include "ns3/point-to-point-topology.h"
62
#include "ns3/onoff-application.h"
63
#include "ns3/packet-sink.h"
64
#include "ns3/global-route-manager.h"
65
66
using namespace ns3;
67
68
NS_LOG_COMPONENT_DEFINE ("SimpleAlternateRoutingExample");
69
70
int 
71
main (int argc, char *argv[])
72
{
73
  // Users may find it convenient to turn on explicit debugging
74
  // for selected modules; the below lines suggest how to do this
75
#if 0 
76
  LogComponentEnable("GlobalRouteManager", LOG_LOGIC);
77
  LogComponentEnable("GlobalRouter", LOG_LOGIC);
78
  LogComponentEnable("Object", LOG_LEVEL_ALL);
79
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
80
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
81
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
82
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
83
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
84
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
85
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
86
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
87
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
88
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
89
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
90
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
91
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
92
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
93
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
94
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
95
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
96
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
97
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
98
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
99
#endif
100
  // Set up some default values for the simulation.  Use the 
101
  // DefaultValue::Bind () technique to tell the system what subclass of 
102
  // Queue to use, and what the queue limit is
103
104
  // The below Bind command tells the queue factory which class to
105
  // instantiate, when the queue factory is invoked in the topology code
106
  DefaultValue::Bind ("Queue", "DropTailQueue");
107
108
  DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
109
  DefaultValue::Bind ("OnOffApplicationDataRate", "300b/s");
110
111
  // The below metric, if set to 3 or higher, will cause packets between
112
  // n1 and n3 to take the 2-hop route through n2
113
  // 
114
  // Additionally, we plumb this metric into the default value / command 
115
  // line argument system as well, for exemplary purposes.  This means 
116
  // that it can be resettable at the command-line to the program, 
117
  // rather than recompiling
118
  // e.g. waf --run "simple-alternate-routing --AlternateCost=5"
119
  uint16_t sampleMetric = 1;
120
  CommandLine::AddArgValue ("AlternateCost",
121
    "This metric is used in the example script between n3 and n1 ", 
122
    sampleMetric);
123
124
  // Allow the user to override any of the defaults and the above
125
  // DefaultValue::Bind ()s at run-time, via command-line arguments
126
  CommandLine::Parse (argc, argv);
127
128
  // Here, we will explicitly create four nodes.  In more sophisticated
129
  // topologies, we could configure a node factory.
130
  NS_LOG_INFO ("Create nodes.");
131
  Ptr<Node> n0 = Create<InternetNode> ();
132
  Ptr<Node> n1 = Create<InternetNode> (); 
133
  Ptr<Node> n2 = Create<InternetNode> (); 
134
  Ptr<Node> n3 = Create<InternetNode> ();
135
136
  // We create the channels first without any IP addressing information
137
  NS_LOG_INFO ("Create channels.");
138
  Ptr<PointToPointChannel> channel0 = 
139
    PointToPointTopology::AddPointToPointLink (
140
      n0, n2, DataRate (5000000), MilliSeconds (2));
141
142
  Ptr<PointToPointChannel> channel1 = 
143
    PointToPointTopology::AddPointToPointLink (
144
      n1, n2, DataRate (5000000), MilliSeconds (2));
145
  
146
  Ptr<PointToPointChannel> channel2 = 
147
    PointToPointTopology::AddPointToPointLink (
148
      n2, n3, DataRate (1500000), MilliSeconds (10));
149
  
150
  Ptr<PointToPointChannel> channel3 = 
151
    PointToPointTopology::AddPointToPointLink (
152
      n1, n3, DataRate (1500000), MilliSeconds (100));
153
  
154
  // Later, we add IP addresses.  The middle two octets correspond to 
155
 // the channel number.  
156
  NS_LOG_INFO ("Assign IP Addresses.");
157
  PointToPointTopology::AddIpv4Addresses (
158
      channel0, n0, Ipv4Address ("10.0.0.1"),
159
      n2, Ipv4Address ("10.0.0.2"));
160
  
161
  PointToPointTopology::AddIpv4Addresses (
162
      channel1, n1, Ipv4Address ("10.1.1.1"),
163
      n2, Ipv4Address ("10.1.1.2"));
164
  
165
  PointToPointTopology::AddIpv4Addresses (
166
      channel2, n2, Ipv4Address ("10.2.2.1"),
167
      n3, Ipv4Address ("10.2.2.2"));
168
169
  PointToPointTopology::AddIpv4Addresses (
170
      channel3, n1, Ipv4Address ("10.3.3.1"),
171
      n3, Ipv4Address ("10.3.3.2"));
172
173
  PointToPointTopology::SetIpv4Metric (
174
      channel3, n1, n3, sampleMetric);
175
176
  // Create router nodes, initialize routing database and set up the routing
177
  // tables in the nodes.
178
  GlobalRouteManager::PopulateRoutingTables ();
179
180
  // Create the OnOff application to send UDP datagrams 
181
  NS_LOG_INFO ("Create Application.");
182
  uint16_t port = 9;   // Discard port (RFC 863)
183
184
  // Create a flow from n3 to n1, starting at time 1.1 seconds
185
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
186
    n3, 
187
    InetSocketAddress ("10.1.1.1", port),
188
    "Udp",
189
    ConstantVariable (1), 
190
    ConstantVariable (0));
191
  // Start the application
192
  ooff->Start (Seconds (1.1));
193
  ooff->Stop (Seconds (10.0));
194
195
  // Create a packet sink to receive these packets
196
  Ptr<PacketSink> sink = Create<PacketSink> (
197
    n1, 
198
    InetSocketAddress (Ipv4Address::GetAny (), port), 
199
    "Udp");
200
  // Start the sink
201
  sink->Start (Seconds (1.1));
202
  sink->Stop (Seconds (10.0));
203
204
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
205
  // Trace output will be sent to the simple-alternate-routing.tr file
206
  NS_LOG_INFO ("Configure Tracing.");
207
  AsciiTrace asciitrace ("simple-alternate-routing.tr");
208
  asciitrace.TraceAllQueues ();
209
  asciitrace.TraceAllNetDeviceRx ();
210
211
  // Also configure some tcpdump traces; each interface will be traced
212
  // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId>
213
  // and can be read by the "tcpdump -r" command (use "-tt" option to
214
  // display timestamps correctly)
215
  PcapTrace pcaptrace ("simple-alternate-routing.pcap");
216
  pcaptrace.TraceAllIp ();
217
218
  NS_LOG_INFO ("Run Simulation.");
219
  Simulator::Run ();
220
  Simulator::Destroy ();
221
  NS_LOG_INFO ("Done.");
222
223
  return 0;
224
}
(-)a/examples/wscript (+4 lines)
 Lines 5-10   def build(bld): Link Here 
5
    obj = bld.create_ns3_program('simple-global-routing',
5
    obj = bld.create_ns3_program('simple-global-routing',
6
        ['point-to-point', 'internet-node', 'global-routing'])
6
        ['point-to-point', 'internet-node', 'global-routing'])
7
    obj.source = 'simple-global-routing.cc'
7
    obj.source = 'simple-global-routing.cc'
8
9
    obj = bld.create_ns3_program('simple-alternate-routing',
10
        ['point-to-point', 'internet-node', 'global-routing'])
11
    obj.source = 'simple-alternate-routing.cc'
8
12
9
    obj = bld.create_ns3_program('simple-point-to-point',
13
    obj = bld.create_ns3_program('simple-point-to-point',
10
        ['point-to-point', 'internet-node'])
14
        ['point-to-point', 'internet-node'])
(-)a/src/devices/csma/csma-ipv4-topology.cc (-1 / +3 lines)
 Lines 96-102   CsmaIpv4Topology::AddIpv4Address( Link Here 
96
  Ptr<Node>             node,
96
  Ptr<Node>             node,
97
  uint32_t              netDeviceNumber,
97
  uint32_t              netDeviceNumber,
98
  const Ipv4Address     address,
98
  const Ipv4Address     address,
99
  const Ipv4Mask        mask)
99
  const Ipv4Mask        mask,
100
  uint16_t              metric)
100
{
101
{
101
  Ptr<NetDevice> nd = node->GetDevice(netDeviceNumber);
102
  Ptr<NetDevice> nd = node->GetDevice(netDeviceNumber);
102
103
 Lines 105-110   CsmaIpv4Topology::AddIpv4Address( Link Here 
105
106
106
  ipv4->SetAddress (ifIndex, address);
107
  ipv4->SetAddress (ifIndex, address);
107
  ipv4->SetNetworkMask (ifIndex, mask);
108
  ipv4->SetNetworkMask (ifIndex, mask);
109
  ipv4->SetMetric (ifIndex, metric);
108
  ipv4->SetUp (ifIndex);
110
  ipv4->SetUp (ifIndex);
109
  return ifIndex;
111
  return ifIndex;
110
}
112
}
(-)a/src/devices/csma/csma-ipv4-topology.h (-1 / +3 lines)
 Lines 103-108   public: Link Here 
103
   *        the address.
103
   *        the address.
104
   * \param address The Ipv4 Address for the interface.
104
   * \param address The Ipv4 Address for the interface.
105
   * \param network The network mask for the interface
105
   * \param network The network mask for the interface
106
   * \param metric (optional) metric (cost) to assign for routing calculations
106
   * 
107
   * 
107
   * Add an Ipv4Address to the Ipv4 interface associated with the
108
   * Add an Ipv4Address to the Ipv4 interface associated with the
108
   * ndNum CsmaIpv4NetDevices on the provided CsmaIpv4Channel
109
   * ndNum CsmaIpv4NetDevices on the provided CsmaIpv4Channel
 Lines 110-116   public: Link Here 
110
  static uint32_t AddIpv4Address(Ptr<Node> node,
111
  static uint32_t AddIpv4Address(Ptr<Node> node,
111
                                 uint32_t netDeviceNumber, 
112
                                 uint32_t netDeviceNumber, 
112
                                 const Ipv4Address address,
113
                                 const Ipv4Address address,
113
                                 const Ipv4Mask mask);
114
                                 const Ipv4Mask mask,
115
                                 uint16_t metric = 1);
114
116
115
  /**
117
  /**
116
   * \param nd1 Node
118
   * \param nd1 Node
(-)a/src/devices/point-to-point/point-to-point-topology.cc (+53 lines)
 Lines 104-109   PointToPointTopology::AddIpv4Addresses( Link Here 
104
}
104
}
105
105
106
void
106
void
107
PointToPointTopology::SetIpv4Metric(
108
  Ptr<const PointToPointChannel> chan,
109
  Ptr<Node> n1, Ptr<Node> n2, const uint16_t metric)
110
{
111
112
  // The PointToPoint channel is used to find the relevant NetDevices
113
  NS_ASSERT (chan->GetNDevices () == 2);
114
  Ptr<NetDevice> nd1 = chan->GetDevice (0);
115
  Ptr<NetDevice> nd2 = chan->GetDevice (1);
116
  // Make sure that nd1 belongs to n1 and nd2 to n2
117
  if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && 
118
       (nd2->GetNode ()->GetId () == n1->GetId () ) )
119
    {
120
      std::swap(nd1, nd2);
121
    }
122
  NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ());
123
  NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ());
124
  
125
  // The NetDevice ifIndex does not correspond to the
126
  // ifIndex used by Ipv4.  Therefore, we have to iterate
127
  // through the NetDevices until we find the Ipv4 ifIndex
128
  // that corresponds to NetDevice nd1
129
  // Get interface indexes for both nodes corresponding to the right channel
130
  uint32_t index = 0;
131
  bool found = false;
132
  Ptr<Ipv4> ip1 = n1->QueryInterface<Ipv4> (Ipv4::iid);
133
  for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++)
134
    {
135
      if (ip1 ->GetNetDevice (i) == nd1)
136
        {
137
          index = i;
138
          found = true;
139
        }
140
    }
141
  NS_ASSERT(found);
142
  ip1->SetMetric (index, metric);
143
144
  index = 0;
145
  found = false;
146
  Ptr<Ipv4> ip2 = n2->QueryInterface<Ipv4> (Ipv4::iid);
147
  for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++)
148
    {
149
      if (ip2 ->GetNetDevice (i) == nd2)
150
        {
151
          index = i;
152
          found = true;
153
        }
154
    }
155
  NS_ASSERT(found);
156
  ip2->SetMetric (index, metric);
157
}
158
159
void
107
PointToPointTopology::AddIpv4Routes (
160
PointToPointTopology::AddIpv4Routes (
108
  Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> chan)
161
  Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> chan)
109
{ 
162
{ 
(-)a/src/devices/point-to-point/point-to-point-topology.h (+14 lines)
 Lines 70-75   public: Link Here 
70
    Ptr<Node> n1, const Ipv4Address& addr1,
70
    Ptr<Node> n1, const Ipv4Address& addr1,
71
    Ptr<Node> n2, const Ipv4Address& addr2);
71
    Ptr<Node> n2, const Ipv4Address& addr2);
72
72
73
  /** 
74
   * \param chan PointToPointChannel to use
75
   * \param n1 Node
76
   * \param n2 Node
77
   * \param metric link metric to assign on Ipv4Link on chan between n1 and n2
78
   * 
79
   * Add a non-unit-cost link metric (bidirectionally) to the Ipv4 
80
   * interfaces associated with the two PointToPointNetDevices on the 
81
   * provided PointToPointChannel
82
   */
83
  static void SetIpv4Metric(
84
    Ptr<const PointToPointChannel> chan,
85
    Ptr<Node> n1, Ptr<Node> n2, const uint16_t metric);
86
73
  /**
87
  /**
74
   * \param channel PointToPointChannel to use
88
   * \param channel PointToPointChannel to use
75
   * \param n1 Node
89
   * \param n1 Node
(-)a/src/internet-node/ipv4-impl.cc (+12 lines)
 Lines 199-204   Ipv4Impl::GetAddress (uint32_t i) const Link Here 
199
Ipv4Impl::GetAddress (uint32_t i) const
199
Ipv4Impl::GetAddress (uint32_t i) const
200
{
200
{
201
  return m_ipv4->GetAddress (i);
201
  return m_ipv4->GetAddress (i);
202
}
203
204
void
205
Ipv4Impl::SetMetric (uint32_t i, uint16_t metric) 
206
{
207
  m_ipv4->SetMetric (i, metric);
208
}
209
210
uint16_t
211
Ipv4Impl::GetMetric (uint32_t i) const
212
{
213
  return m_ipv4->GetMetric (i);
202
}
214
}
203
215
204
bool
216
bool
(-)a/src/internet-node/ipv4-impl.h (+2 lines)
 Lines 88-93   public: Link Here 
88
  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
88
  virtual void SetNetworkMask (uint32_t i, Ipv4Mask mask);
89
  virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
89
  virtual Ipv4Mask GetNetworkMask (uint32_t t) const;
90
  virtual Ipv4Address GetAddress (uint32_t i) const;
90
  virtual Ipv4Address GetAddress (uint32_t i) const;
91
  virtual void SetMetric (uint32_t i, uint16_t metric);
92
  virtual uint16_t GetMetric (uint32_t i) const;
91
  virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const;
93
  virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const;
92
  virtual bool GetIfIndexForDestination (Ipv4Address dest, 
94
  virtual bool GetIfIndexForDestination (Ipv4Address dest, 
93
    uint32_t &ifIndex) const;
95
    uint32_t &ifIndex) const;
(-)a/src/internet-node/ipv4-interface.cc (-1 / +17 lines)
 Lines 37-43   namespace ns3 { Link Here 
37
   */
37
   */
38
Ipv4Interface::Ipv4Interface (Ptr<NetDevice> nd) 
38
Ipv4Interface::Ipv4Interface (Ptr<NetDevice> nd) 
39
  : m_netdevice (nd), 
39
  : m_netdevice (nd), 
40
    m_ifup(false)
40
    m_ifup(false),
41
    m_metric(1)
41
{
42
{
42
  NS_LOG_FUNCTION;
43
  NS_LOG_FUNCTION;
43
  NS_LOG_PARAM ("(" << &nd << ")");
44
  NS_LOG_PARAM ("(" << &nd << ")");
 Lines 94-99   Ipv4Interface::GetNetworkMask (void) con Link Here 
94
{
95
{
95
  NS_LOG_FUNCTION;
96
  NS_LOG_FUNCTION;
96
  return m_netmask;
97
  return m_netmask;
98
}
99
100
void
101
Ipv4Interface::SetMetric (uint16_t metric)
102
{
103
  NS_LOG_FUNCTION;
104
  NS_LOG_PARAM ("(" << metric << ")");
105
  m_metric = metric;
106
}
107
108
uint16_t
109
Ipv4Interface::GetMetric (void) const
110
{
111
  NS_LOG_FUNCTION;
112
  return m_metric;
97
}
113
}
98
114
99
Ipv4Address 
115
Ipv4Address 
(-)a/src/internet-node/ipv4-interface.h (+9 lines)
 Lines 97-102   public: Link Here 
97
   */
97
   */
98
  Ipv4Mask GetNetworkMask (void) const;
98
  Ipv4Mask GetNetworkMask (void) const;
99
  /**
99
  /**
100
   * \param configured routing metric (cost) of this interface
101
   */
102
  void SetMetric (uint16_t);
103
  /**
104
   * \returns configured routing metric (cost) of this interface
105
   */
106
  uint16_t GetMetric (void) const;
107
  /**
100
   * \returns the ipv4 address of this interface
108
   * \returns the ipv4 address of this interface
101
   */
109
   */
102
  Ipv4Address GetAddress (void) const;
110
  Ipv4Address GetAddress (void) const;
 Lines 147-152   private: Link Here 
147
  bool m_ifup;
155
  bool m_ifup;
148
  Ipv4Address m_address;
156
  Ipv4Address m_address;
149
  Ipv4Mask m_netmask;
157
  Ipv4Mask m_netmask;
158
  uint16_t m_metric;
150
};
159
};
151
160
152
}; // namespace ns3
161
}; // namespace ns3
(-)a/src/internet-node/ipv4-l3-protocol.cc (+18 lines)
 Lines 821-826   Ipv4L3Protocol::GetAddress (uint32_t i) Link Here 
821
  return interface->GetAddress ();
821
  return interface->GetAddress ();
822
}
822
}
823
823
824
void 
825
Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
826
{
827
  NS_LOG_FUNCTION;
828
  NS_LOG_PARAM ("(" << i << ", " << metric << ")");
829
  Ptr<Ipv4Interface> interface = GetInterface (i);
830
  interface->SetMetric (metric);
831
}
832
833
uint16_t
834
Ipv4L3Protocol::GetMetric (uint32_t i) const
835
{
836
  NS_LOG_FUNCTION;
837
  NS_LOG_PARAM ("(" << i << ")");
838
  Ptr<Ipv4Interface> interface = GetInterface (i);
839
  return interface->GetMetric ();
840
}
841
824
bool
842
bool
825
Ipv4L3Protocol::GetIfIndexForDestination (
843
Ipv4L3Protocol::GetIfIndexForDestination (
826
  Ipv4Address destination, uint32_t& ifIndex) const
844
  Ipv4Address destination, uint32_t& ifIndex) const
(-)a/src/internet-node/ipv4-l3-protocol.h (+2 lines)
 Lines 198-203   public: Link Here 
198
  void SetNetworkMask (uint32_t i, Ipv4Mask mask);
198
  void SetNetworkMask (uint32_t i, Ipv4Mask mask);
199
  Ipv4Mask GetNetworkMask (uint32_t t) const;
199
  Ipv4Mask GetNetworkMask (uint32_t t) const;
200
  Ipv4Address GetAddress (uint32_t i) const;
200
  Ipv4Address GetAddress (uint32_t i) const;
201
  void SetMetric (uint32_t i, uint16_t metric);
202
  uint16_t GetMetric (uint32_t i) const;
201
  bool GetIfIndexForDestination (Ipv4Address destination, 
203
  bool GetIfIndexForDestination (Ipv4Address destination, 
202
                                 uint32_t& ifIndex) const;
204
                                 uint32_t& ifIndex) const;
203
  uint16_t GetMtu (uint32_t i) const;
205
  uint16_t GetMtu (uint32_t i) const;
(-)a/src/node/ipv4.h (+14 lines)
 Lines 385-390   public: Link Here 
385
385
386
  /**
386
  /**
387
   * \param i index of ipv4 interface
387
   * \param i index of ipv4 interface
388
   * \param metric routing metric (cost) associated to the underlying 
389
   *          ipv4 interface
390
   */
391
  virtual void SetMetric (uint32_t i, uint16_t metric) = 0;
392
393
  /**
394
   * \param i index of ipv4 interface
395
   * \returns routing metric (cost) associated to the underlying 
396
   *          ipv4 interface
397
   */
398
  virtual uint16_t GetMetric (uint32_t i) const = 0;
399
400
  /**
401
   * \param i index of ipv4 interface
388
   * \returns the address associated to the underlying ipv4 interface
402
   * \returns the address associated to the underlying ipv4 interface
389
   */
403
   */
390
  virtual Ipv4Address GetAddress (uint32_t i) const = 0;
404
  virtual Ipv4Address GetAddress (uint32_t i) const = 0;
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-6 / +12 lines)
 Lines 529-535   GlobalRouteManagerImpl::SPFNext (SPFVert Link Here 
529
// Get w_lsa:  In case of V is Router-LSA
529
// Get w_lsa:  In case of V is Router-LSA
530
      if (v->GetVertexType () == SPFVertex::VertexRouter) 
530
      if (v->GetVertexType () == SPFVertex::VertexRouter) 
531
        {
531
        {
532
          NS_LOG_LOGIC ("Examining " << v->GetVertexId () << "'s " <<
532
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
533
            v->GetVertexId () << "'s " <<
533
            v->GetLSA ()->GetNLinkRecords () << " link records");
534
            v->GetLSA ()->GetNLinkRecords () << " link records");
534
//
535
//
535
// (a) If this is a link to a stub network, examine the next link in V's LSA.
536
// (a) If this is a link to a stub network, examine the next link in V's LSA.
 Lines 637-643   GlobalRouteManagerImpl::SPFNext (SPFVert Link Here 
637
              candidate.Push (w);
638
              candidate.Push (w);
638
              NS_LOG_LOGIC ("Pushing " << 
639
              NS_LOG_LOGIC ("Pushing " << 
639
                w->GetVertexId () << ", parent vertexId: " << 
640
                w->GetVertexId () << ", parent vertexId: " << 
640
                v->GetVertexId ());
641
                v->GetVertexId () << ", distance: " <<
642
                w->GetDistanceFromRoot ());
641
            }
643
            }
642
        }
644
        }
643
      else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE)
645
      else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE)
 Lines 688-694   GlobalRouteManagerImpl::SPFNext (SPFVert Link Here 
688
}
690
}
689
691
690
//
692
//
691
// This method is derived from quagga ospf_next_hop_calculation() 16.1.1.  
693
// This method is derived from quagga ospf_nexthop_calculation() 16.1.1.  
692
//
694
//
693
// Calculate nexthop from root through V (parent) to vertex W (destination)
695
// Calculate nexthop from root through V (parent) to vertex W (destination)
694
// with given distance from root->W.
696
// with given distance from root->W.
 Lines 784-794   GlobalRouteManagerImpl::SPFNexthopCalcul Link Here 
784
//
786
//
785
          w->SetOutgoingInterfaceId (
787
          w->SetOutgoingInterfaceId (
786
            FindOutgoingInterfaceId (l->GetLinkData ()));
788
            FindOutgoingInterfaceId (l->GetLinkData ()));
787
789
          w->SetDistanceFromRoot (distance);
790
          w->SetParent (v);
788
          NS_LOG_LOGIC ("Next hop from " << 
791
          NS_LOG_LOGIC ("Next hop from " << 
789
            v->GetVertexId () << " to " << w->GetVertexId () << 
792
            v->GetVertexId () << " to " << w->GetVertexId () << 
790
            " goes through next hop " << w->GetNextHop () <<
793
            " goes through next hop " << w->GetNextHop () <<
791
            " via outgoing interface " << w->GetOutgoingInterfaceId ());
794
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
795
            " with distance " << distance);
792
        }  // end W is a router vertes
796
        }  // end W is a router vertes
793
      else 
797
      else 
794
        {
798
        {
 Lines 804-810   GlobalRouteManagerImpl::SPFNexthopCalcul Link Here 
804
          w->SetParent (v);
808
          w->SetParent (v);
805
          NS_LOG_LOGIC ("Next hop from " << 
809
          NS_LOG_LOGIC ("Next hop from " << 
806
            v->GetVertexId () << " to network " << w->GetVertexId () << 
810
            v->GetVertexId () << " to network " << w->GetVertexId () << 
807
            " via outgoing interface " << w->GetOutgoingInterfaceId ());
811
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
812
            " with distance " << distance);
808
          return 1;
813
          return 1;
809
        }
814
        }
810
    } // end v is the root
815
    } // end v is the root
 Lines 997-1002   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
997
  m_spfroot= v;
1002
  m_spfroot= v;
998
  v->SetDistanceFromRoot (0);
1003
  v->SetDistanceFromRoot (0);
999
  v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1004
  v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1005
  NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
1000
1006
1001
  for (;;)
1007
  for (;;)
1002
    {
1008
    {
(-)a/src/routing/global-routing/global-router-interface.cc (-7 / +11 lines)
 Lines 50-56   GlobalRoutingLinkRecord::GlobalRoutingLi Link Here 
50
  LinkType    linkType, 
50
  LinkType    linkType, 
51
  Ipv4Address linkId, 
51
  Ipv4Address linkId, 
52
  Ipv4Address linkData, 
52
  Ipv4Address linkData, 
53
  uint32_t    metric)
53
  uint16_t    metric)
54
:
54
:
55
  m_linkId (linkId),
55
  m_linkId (linkId),
56
  m_linkData (linkData),
56
  m_linkData (linkData),
 Lines 110-116   GlobalRoutingLinkRecord::SetLinkType ( Link Here 
110
  m_linkType = linkType;
110
  m_linkType = linkType;
111
}
111
}
112
112
113
  uint32_t
113
  uint16_t
114
GlobalRoutingLinkRecord::GetMetric (void) const
114
GlobalRoutingLinkRecord::GetMetric (void) const
115
{
115
{
116
  NS_LOG_FUNCTION;
116
  NS_LOG_FUNCTION;
 Lines 118-124   GlobalRoutingLinkRecord::GetMetric (void Link Here 
118
}
118
}
119
119
120
  void
120
  void
121
GlobalRoutingLinkRecord::SetMetric (uint32_t metric)
121
GlobalRoutingLinkRecord::SetMetric (uint16_t metric)
122
{
122
{
123
  NS_LOG_FUNCTION;
123
  NS_LOG_FUNCTION;
124
  m_metric = metric;
124
  m_metric = metric;
 Lines 202-207   GlobalRoutingLSA::CopyLinkRecords (const Link Here 
202
      pDst->SetLinkType (pSrc->GetLinkType ());
202
      pDst->SetLinkType (pSrc->GetLinkType ());
203
      pDst->SetLinkId (pSrc->GetLinkId ());
203
      pDst->SetLinkId (pSrc->GetLinkId ());
204
      pDst->SetLinkData (pSrc->GetLinkData ());
204
      pDst->SetLinkData (pSrc->GetLinkData ());
205
      pDst->SetMetric (pSrc->GetMetric ());
205
206
206
      m_linkRecords.push_back(pDst);
207
      m_linkRecords.push_back(pDst);
207
      pDst = 0;
208
      pDst = 0;
 Lines 397-402   GlobalRoutingLSA::Print (std::ostream &o Link Here 
397
          os << "----------" << std::endl;
398
          os << "----------" << std::endl;
398
          os << "m_linkId = " << p->GetLinkId () << std::endl;
399
          os << "m_linkId = " << p->GetLinkId () << std::endl;
399
          os << "m_linkData = " << p->GetLinkData () << std::endl;
400
          os << "m_linkData = " << p->GetLinkData () << std::endl;
401
          os << "m_metric = " << p->GetMetric () << std::endl;
400
        }
402
        }
401
    }
403
    }
402
  else if (m_lsType == GlobalRoutingLSA::NetworkLSA) 
404
  else if (m_lsType == GlobalRoutingLSA::NetworkLSA) 
 Lines 547-552   GlobalRouter::DiscoverLSAs (void) Link Here 
547
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
549
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
548
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
550
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
549
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
551
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
552
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
550
//
553
//
551
// Now, we're going to walk over to the remote net device on the other end of 
554
// Now, we're going to walk over to the remote net device on the other end of 
552
// the point-to-point channel we now know we have.  This is where our adjacent 
555
// the point-to-point channel we now know we have.  This is where our adjacent 
 Lines 566-573   GlobalRouter::DiscoverLSAs (void) Link Here 
566
              Ipv4Address maskLocalAddr;
569
              Ipv4Address maskLocalAddr;
567
              maskLocalAddr.Set(maskLocal.GetHostOrder ());
570
              maskLocalAddr.Set(maskLocal.GetHostOrder ());
568
              plr->SetLinkData (maskLocalAddr);
571
              plr->SetLinkData (maskLocalAddr);
569
              // Cost is interface's configured output cost (NOTYET)
572
              plr->SetMetric (metricLocal);
570
              plr->SetMetric (1);
571
              pLSA->AddLinkRecord(plr);
573
              pLSA->AddLinkRecord(plr);
572
              plr = 0;
574
              plr = 0;
573
              continue;
575
              continue;
 Lines 589-596   GlobalRouter::DiscoverLSAs (void) Link Here 
589
              plr->SetLinkId (desigRtr);
591
              plr->SetLinkId (desigRtr);
590
              // Link Data is router's own IP address
592
              // Link Data is router's own IP address
591
              plr->SetLinkData (addrLocal);
593
              plr->SetLinkData (addrLocal);
592
              // Cost is interface's configured output cost (NOTYET)
594
              plr->SetMetric (metricLocal);
593
              plr->SetMetric (1);
594
              pLSA->AddLinkRecord (plr);
595
              pLSA->AddLinkRecord (plr);
595
              plr = 0;
596
              plr = 0;
596
              continue;
597
              continue;
 Lines 613-618   GlobalRouter::DiscoverLSAs (void) Link Here 
613
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
614
          Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
614
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
615
          Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
615
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
616
          NS_LOG_LOGIC ("Working with local address " << addrLocal);
617
          uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
616
//
618
//
617
// Now, we're going to walk over to the remote net device on the other end of 
619
// Now, we're going to walk over to the remote net device on the other end of 
618
// the point-to-point channel we now know we have.  This is where our adjacent 
620
// the point-to-point channel we now know we have.  This is where our adjacent 
 Lines 659-664   GlobalRouter::DiscoverLSAs (void) Link Here 
659
          plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
661
          plr->SetLinkType (GlobalRoutingLinkRecord::PointToPoint);
660
          plr->SetLinkId (rtrIdRemote);
662
          plr->SetLinkId (rtrIdRemote);
661
          plr->SetLinkData (addrLocal);
663
          plr->SetLinkData (addrLocal);
664
          plr->SetMetric (metricLocal);
662
          pLSA->AddLinkRecord (plr);
665
          pLSA->AddLinkRecord (plr);
663
          plr = 0;
666
          plr = 0;
664
667
 Lines 666-671   GlobalRouter::DiscoverLSAs (void) Link Here 
666
          plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
669
          plr->SetLinkType (GlobalRoutingLinkRecord::StubNetwork);
667
          plr->SetLinkId (addrRemote);
670
          plr->SetLinkId (addrRemote);
668
          plr->SetLinkData (Ipv4Address(maskRemote.GetHostOrder()));  // Frown
671
          plr->SetLinkData (Ipv4Address(maskRemote.GetHostOrder()));  // Frown
672
          plr->SetMetric (metricLocal);
669
          pLSA->AddLinkRecord (plr);
673
          pLSA->AddLinkRecord (plr);
670
          plr = 0;
674
          plr = 0;
671
        }
675
        }
(-)a/src/routing/global-routing/global-router-interface.h (-4 / +4 lines)
 Lines 82-88   public: Link Here 
82
    LinkType    linkType, 
82
    LinkType    linkType, 
83
    Ipv4Address linkId, 
83
    Ipv4Address linkId, 
84
    Ipv4Address linkData, 
84
    Ipv4Address linkData, 
85
    uint32_t    metric);
85
    uint16_t    metric);
86
86
87
/**
87
/**
88
 * @brief Destroy a Global Routing Link Record.
88
 * @brief Destroy a Global Routing Link Record.
 Lines 176-182   public: Link Here 
176
 *
176
 *
177
 * @returns The metric field of the Global Routing Link Record.
177
 * @returns The metric field of the Global Routing Link Record.
178
 */
178
 */
179
  uint32_t GetMetric(void) const;
179
  uint16_t GetMetric(void) const;
180
180
181
/**
181
/**
182
 * @brief Set the Metric Data field of the Global Routing Link Record.
182
 * @brief Set the Metric Data field of the Global Routing Link Record.
 Lines 189-195   public: Link Here 
189
 *
189
 *
190
 * @param metric The new metric for the current Global Routing Link Record.
190
 * @param metric The new metric for the current Global Routing Link Record.
191
 */
191
 */
192
  void SetMetric(uint32_t metric);
192
  void SetMetric(uint16_t metric);
193
193
194
private:
194
private:
195
/**
195
/**
 Lines 230-236   private: Link Here 
230
 * of two hops relate to the cost of sending a packet); rather you should
230
 * of two hops relate to the cost of sending a packet); rather you should
231
 * use something like delay.
231
 * use something like delay.
232
 */
232
 */
233
  uint32_t m_metric;  
233
  uint16_t m_metric;  
234
};
234
};
235
235
236
/**  
236
/**  

Return to bug 84