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

(-)7e06b2dedca1 (+295 lines)
Added Link Here 
1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
2
//
3
// Copyright (c) 2008 University of Washington
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
19
#include "ns3/log.h"
20
#include "ns3/object.h"
21
#include "ipv4-global-routing.h"
22
#include "ns3/packet.h"
23
#include "ns3/node.h"
24
25
NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
26
27
namespace ns3 {
28
29
NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting);
30
31
TypeId 
32
Ipv4GlobalRouting::GetTypeId (void)
33
{ 
34
  static TypeId tid = TypeId ("ns3::Ipv4GlobalRouting")
35
    .SetParent<Object> ()
36
    ;
37
  return tid;
38
}
39
40
Ipv4GlobalRouting::Ipv4GlobalRouting () 
41
{
42
  NS_LOG_FUNCTION_NOARGS ();
43
}
44
45
void 
46
Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
47
                                   Ipv4Address nextHop, 
48
                                   uint32_t interface)
49
{
50
  Ptr<Node> n = this->GetObject<Node> ();
51
  NS_LOG_FUNCTION (n->GetId() << dest << nextHop << interface);
52
  Ipv4Route *route = new Ipv4Route ();
53
  *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface);
54
  m_hostRoutes.push_back (route);
55
}
56
57
void 
58
Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
59
                                   uint32_t interface)
60
{
61
  NS_LOG_FUNCTION (dest << interface);
62
  Ipv4Route *route = new Ipv4Route ();
63
  *route = Ipv4Route::CreateHostRouteTo (dest, interface);
64
  m_hostRoutes.push_back (route);
65
}
66
67
void 
68
Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
69
                                      Ipv4Mask networkMask, 
70
                                      Ipv4Address nextHop, 
71
                                      uint32_t interface)
72
{
73
  Ptr<Node> n = this->GetObject<Node> ();
74
  NS_LOG_FUNCTION (n->GetId () << network << networkMask << nextHop << interface);
75
  Ipv4Route *route = new Ipv4Route ();
76
  *route = Ipv4Route::CreateNetworkRouteTo (network,
77
                                            networkMask,
78
                                            nextHop,
79
                                            interface);
80
  m_networkRoutes.push_back (route);
81
}
82
83
void 
84
Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
85
                                      Ipv4Mask networkMask, 
86
                                      uint32_t interface)
87
{
88
  NS_LOG_FUNCTION (network << networkMask << interface);
89
  Ipv4Route *route = new Ipv4Route ();
90
  *route = Ipv4Route::CreateNetworkRouteTo (network,
91
                                            networkMask,
92
                                            interface);
93
  m_networkRoutes.push_back (route);
94
}
95
96
Ipv4Route *
97
Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
98
{
99
  NS_LOG_FUNCTION_NOARGS ();
100
  for (HostRoutesCI i = m_hostRoutes.begin (); 
101
       i != m_hostRoutes.end (); 
102
       i++) 
103
    {
104
      NS_ASSERT ((*i)->IsHost ());
105
      if ((*i)->GetDest ().IsEqual (dest)) 
106
        {
107
          NS_LOG_LOGIC ("Found global host route" << *i); 
108
          return (*i);
109
        }
110
    }
111
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
112
       j != m_networkRoutes.end (); 
113
       j++) 
114
    {
115
      NS_ASSERT ((*j)->IsNetwork ());
116
      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
117
      Ipv4Address entry = (*j)->GetDestNetwork ();
118
      if (mask.IsMatch (dest, entry)) 
119
        {
120
          NS_LOG_LOGIC ("Found global network route" << *j); 
121
          return (*j);
122
        }
123
    }
124
  return 0;
125
}
126
127
uint32_t 
128
Ipv4GlobalRouting::GetNRoutes (void)
129
{
130
  NS_LOG_FUNCTION_NOARGS ();
131
  uint32_t n = 0;
132
  n += m_hostRoutes.size ();
133
  n += m_networkRoutes.size ();
134
  return n;
135
}
136
137
Ipv4Route *
138
Ipv4GlobalRouting::GetRoute (uint32_t index)
139
{
140
  NS_LOG_FUNCTION (index);
141
  if (index < m_hostRoutes.size ())
142
    {
143
      uint32_t tmp = 0;
144
      for (HostRoutesCI i = m_hostRoutes.begin (); 
145
           i != m_hostRoutes.end (); 
146
           i++) 
147
        {
148
          if (tmp  == index)
149
            {
150
              return *i;
151
            }
152
          tmp++;
153
        }
154
    }
155
  index -= m_hostRoutes.size ();
156
  uint32_t tmp = 0;
157
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
158
       j != m_networkRoutes.end (); 
159
       j++) 
160
    {
161
      if (tmp == index)
162
        {
163
          return *j;
164
        }
165
      tmp++;
166
    }
167
  NS_ASSERT (false);
168
  // quiet compiler.
169
  return 0;
170
}
171
void 
172
Ipv4GlobalRouting::RemoveRoute (uint32_t index)
173
{
174
  NS_LOG_FUNCTION (index);
175
  if (index < m_hostRoutes.size ())
176
    {
177
      uint32_t tmp = 0;
178
      for (HostRoutesI i = m_hostRoutes.begin (); 
179
           i != m_hostRoutes.end (); 
180
           i++) 
181
        {
182
          if (tmp  == index)
183
            {
184
              NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_hostRoutes.size());
185
              delete *i;
186
              m_hostRoutes.erase (i);
187
              NS_LOG_LOGIC ("Done removing host route " << index << "; host route remaining size = " << m_hostRoutes.size());
188
              return;
189
            }
190
          tmp++;
191
        }
192
    }
193
  index -= m_hostRoutes.size ();
194
  uint32_t tmp = 0;
195
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
196
       j != m_networkRoutes.end (); 
197
       j++) 
198
    {
199
      if (tmp == index)
200
        {
201
          NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_networkRoutes.size());
202
          delete *j;
203
          m_networkRoutes.erase (j);
204
          NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
205
          return;
206
        }
207
      tmp++;
208
    }
209
  NS_ASSERT (false);
210
}
211
212
bool
213
Ipv4GlobalRouting::RequestRoute (
214
  uint32_t ifIndex,
215
  Ipv4Header const &ipHeader,
216
  Ptr<Packet> packet,
217
  RouteReplyCallback routeReply)
218
{
219
  NS_LOG_FUNCTION (this << ifIndex << &ipHeader << packet << &routeReply);
220
221
  NS_LOG_LOGIC ("source = " << ipHeader.GetSource ());
222
223
  NS_LOG_LOGIC ("destination = " << ipHeader.GetDestination ());
224
225
  if (ipHeader.GetDestination ().IsMulticast ())
226
    {
227
      NS_LOG_LOGIC ("Multicast destination-- returning false");
228
      return false; // Let other routing protocols try to handle this
229
    }
230
231
// This is a unicast packet.  Check to see if we have a route for it.
232
//
233
  NS_LOG_LOGIC ("Unicast destination- looking up");
234
  Ipv4Route *route = LookupGlobal (ipHeader.GetDestination ());
235
  if (route != 0)
236
    {
237
      routeReply (true, *route, packet, ipHeader);
238
      return true;
239
    }
240
  else
241
    {
242
      return false; // Let other routing protocols try to handle this
243
                    // route request.
244
    }
245
}
246
247
bool
248
Ipv4GlobalRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex)
249
{
250
  NS_LOG_FUNCTION (this << destination << &ifIndex);
251
//
252
// First, see if this is a multicast packet we have a route for.  If we
253
// have a route, then send the packet down each of the specified interfaces.
254
//
255
  if (destination.IsMulticast ())
256
    {
257
      NS_LOG_LOGIC ("Multicast destination-- returning false");
258
      return false; // Let other routing protocols try to handle this
259
    }
260
//
261
// See if this is a unicast packet we have a route for.
262
//
263
  NS_LOG_LOGIC ("Unicast destination- looking up");
264
  Ipv4Route *route = LookupGlobal (destination);
265
  if (route)
266
    {
267
      ifIndex = route->GetInterface ();
268
      return true;
269
    }
270
  else
271
    {
272
      return false;
273
    }
274
}
275
276
void
277
Ipv4GlobalRouting::DoDispose (void)
278
{
279
  NS_LOG_FUNCTION_NOARGS ();
280
  for (HostRoutesI i = m_hostRoutes.begin (); 
281
       i != m_hostRoutes.end (); 
282
       i = m_hostRoutes.erase (i)) 
283
    {
284
      delete (*i);
285
    }
286
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
287
       j != m_networkRoutes.end (); 
288
       j = m_networkRoutes.erase (j)) 
289
    {
290
      delete (*j);
291
    }
292
  Ipv4RoutingProtocol::DoDispose ();
293
}
294
295
}//namespace ns3
(-)7e06b2dedca1 (+270 lines)
Added Link Here 
1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
2
//
3
// Copyright (c) 2008 University of Washington
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
//
19
20
#ifndef IPV4_GLOBAL_ROUTING_H
21
#define IPV4_GLOBAL_ROUTING_H
22
23
#include <list>
24
#include <stdint.h>
25
#include "ns3/ipv4-address.h"
26
#include "ns3/ipv4-header.h"
27
#include "ns3/ptr.h"
28
#include "ns3/ipv4.h"
29
30
namespace ns3 {
31
32
class Packet;
33
class NetDevice;
34
class Ipv4Interface;
35
class Ipv4Address;
36
class Ipv4Header;
37
class Ipv4Route;
38
class Node;
39
40
41
/**
42
 * @brief Global routing protocol for IP version 4 stacks.
43
 *
44
 * In ns-3 we have the concept of a pluggable routing protocol.  Routing
45
 * protocols are added to a list maintained by the Ipv4L3Protocol.  Every 
46
 * stack gets one routing protocol for free -- the Ipv4StaticRouting routing
47
 * protocol is added in the constructor of the Ipv4L3Protocol (this is the 
48
 * piece of code that implements the functionality of the IP layer).
49
 *
50
 * As an option to running a dynamic routing protocol, a GlobalRouteManager
51
 * object has been created to allow users to build routes for all participating
52
 * nodes.  One can think of this object as a "routing oracle"; it has
53
 * an omniscient view of the topology, and can construct shortest path
54
 * routes between all pairs of nodes.  These routes must be stored 
55
 * somewhere in the node, so therefore this class Ipv4GlobalRouting
56
 * is used as one of the pluggable routing protocols.  It is kept distinct
57
 * from Ipv4StaticRouting because these routes may be dynamically cleared
58
 * and rebuilt in the middle of the simulation, while manually entered
59
 * routes into the Ipv4StaticRouting may need to be kept distinct.
60
 *
61
 * This class deals with Ipv4 unicast routes only.
62
 *
63
 * @see Ipv4RoutingProtocol
64
 * @see GlobalRouteManager
65
 */
66
class Ipv4GlobalRouting : public Ipv4RoutingProtocol
67
{
68
public:
69
  static TypeId GetTypeId (void);
70
/**
71
 * @brief Construct an empty Ipv4GlobalRouting routing protocol,
72
 *
73
 * The Ipv4GlobalRouting class supports host and network unicast routes.
74
 * This method initializes the lists containing these routes to empty.
75
 *
76
 * @see Ipv4GlobalRouting
77
 */
78
  Ipv4GlobalRouting ();
79
80
/**
81
 * @brief Request that a check for a route bw performed and if a route is found
82
 * that the packet be sent on its way using the pre-packaged send callback.
83
 *
84
 * The source and destination IP addresses for the packet in question are found
85
 * in the provided Ipv4Header.  There are two major processing forks depending
86
 * on the type of destination address.  
87
 *
88
 * If the destination address is unicast then the routing table is consulted 
89
 * for a route to the destination and if it is found, the routeReply callback
90
 * is executed to send the packet (with the found route).
91
 * 
92
 * If the destination address is a multicast, then the method will return
93
 * false.
94
 *
95
 * @param ifIndex The network interface index over which the packed was 
96
 * received.  If the packet is from a local source, ifIndex will be set to
97
 * Ipv4RoutingProtocol::IF_INDEX_ANY.
98
 * @param ipHeader the Ipv4Header containing the source and destination IP
99
 * addresses for the packet.
100
 * @param packet The packet to be sent if a route is found.
101
 * @param routeReply A callback that packaged up the call to actually send the
102
 * packet.
103
 * @return Returns true if a route is found and the packet has been sent,
104
 * otherwise returns false indicating that the next routing protocol should
105
 * be consulted.  
106
 *
107
 * @see Ipv4GlobalRouting
108
 * @see Ipv4RoutingProtocol
109
 */
110
  virtual bool RequestRoute (uint32_t ifIndex,
111
                             Ipv4Header const &ipHeader,
112
                             Ptr<Packet> packet,
113
                             RouteReplyCallback routeReply);
114
115
/**
116
 * @brief Check to see if we can determine the interface index that will be
117
 * used if a packet is sent to this destination.
118
 *
119
 * This method addresses a problem in the IP stack where a destination address
120
 * must be present and checksummed into the IP header before the actual 
121
 * interface over which the packet is sent can be determined.  The answer is
122
 * to implement a known and intentional cross-layer violation.  This is the
123
 * endpoint of a call chain that started up quite high in the stack (sockets)
124
 * and has found its way down to the Ipv4L3Protocol which is consulting the
125
 * routing protocols for what they would do if presented with a packet of the
126
 * given destination.
127
 *
128
 * If there are multiple paths out of the node, the resolution is performed
129
 * by Ipv4L3Protocol::GetIfIndexforDestination which has access to more 
130
 * contextual information that is useful for making a determination.
131
 *
132
 * This method will return false on a multicast address.
133
 *
134
 * @param destination The Ipv4Address if the destination of a hypothetical 
135
 * packet.  This may be a multicast group address.
136
 * @param ifIndex A reference to the interface index over which a packet
137
 * sent to this destination would be sent.
138
 * @return Returns true if a route is found to the destination that involves
139
 * a single output interface index, otherwise returns false indicating that
140
 * the next routing protocol should be consulted.  
141
 *
142
 * @see Ipv4GlobalRouting
143
 * @see Ipv4RoutingProtocol
144
 * @see Ipv4L3Protocol
145
 */
146
  virtual bool RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex);
147
148
/**
149
 * @brief Add a host route to the global routing table.
150
 *
151
 * @param dest The Ipv4Address destination for this route.
152
 * @param nextHop The Ipv4Address of the next hop in the route.
153
 * @param interface The network interface index used to send packets to the
154
 * destination.
155
 *
156
 * @see Ipv4Address
157
 */
158
  void AddHostRouteTo (Ipv4Address dest, 
159
                       Ipv4Address nextHop, 
160
                       uint32_t interface);
161
/**
162
 * @brief Add a host route to the global routing table.
163
 *
164
 * @param dest The Ipv4Address destination for this route.
165
 * @param interface The network interface index used to send packets to the
166
 * destination.
167
 *
168
 * @see Ipv4Address
169
 */
170
  void AddHostRouteTo (Ipv4Address dest, 
171
                       uint32_t interface);
172
173
/**
174
 * @brief Add a network route to the global routing table.
175
 *
176
 * @param network The Ipv4Address network for this route.
177
 * @param networkMask The Ipv4Mask to extract the network.
178
 * @param nextHop The next hop in the route to the destination network.
179
 * @param interface The network interface index used to send packets to the
180
 * destination.
181
 *
182
 * @see Ipv4Address
183
 */
184
  void AddNetworkRouteTo (Ipv4Address network, 
185
                          Ipv4Mask networkMask, 
186
                          Ipv4Address nextHop, 
187
                          uint32_t interface);
188
189
/**
190
 * @brief Add a network route to the global routing table.
191
 *
192
 * @param network The Ipv4Address network for this route.
193
 * @param networkMask The Ipv4Mask to extract the network.
194
 * @param interface The network interface index used to send packets to the
195
 * destination.
196
 *
197
 * @see Ipv4Address
198
 */
199
  void AddNetworkRouteTo (Ipv4Address network, 
200
                          Ipv4Mask networkMask, 
201
                          uint32_t interface);
202
203
/**
204
 * @brief Get the number of individual unicast routes that have been added
205
 * to the routing table.
206
 *
207
 * @warning The default route counts as one of the routes.
208
 */
209
  uint32_t GetNRoutes (void);
210
211
/**
212
 * @brief Get a route from the global unicast routing table.
213
 *
214
 * Externally, the unicast global routing table appears simply as a table with
215
 * n entries.  The one sublety of note is that if a default route has been set
216
 * it will appear as the zeroth entry in the table.  This means that if you
217
 * add only a default route, the table will have one entry that can be accessed
218
 * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
219
 * 
220
 * Similarly, if the default route has been set, calling RemoveRoute (0) will
221
 * remove the default route.
222
 *
223
 * @param i The index (into the routing table) of the route to retrieve.  If
224
 * the default route has been set, it will occupy index zero.
225
 * @return If route is set, a pointer to that Ipv4Route is returned, otherwise
226
 * a zero pointer is returned.
227
 *
228
 * @see Ipv4Route
229
 * @see Ipv4GlobalRouting::RemoveRoute
230
 */
231
  Ipv4Route *GetRoute (uint32_t i);
232
233
/**
234
 * @brief Remove a route from the global unicast routing table.
235
 *
236
 * Externally, the unicast global routing table appears simply as a table with
237
 * n entries.  The one sublety of note is that if a default route has been set
238
 * it will appear as the zeroth entry in the table.  This means that if the
239
 * default route has been set, calling RemoveRoute (0) will remove the
240
 * default route.
241
 *
242
 * @param i The index (into the routing table) of the route to remove.  If
243
 * the default route has been set, it will occupy index zero.
244
 *
245
 * @see Ipv4Route
246
 * @see Ipv4GlobalRouting::GetRoute
247
 * @see Ipv4GlobalRouting::AddRoute
248
 */
249
  void RemoveRoute (uint32_t i);
250
251
protected:
252
  void DoDispose (void);
253
254
private:
255
  typedef std::list<Ipv4Route *> HostRoutes;
256
  typedef std::list<Ipv4Route *>::const_iterator HostRoutesCI;
257
  typedef std::list<Ipv4Route *>::iterator HostRoutesI;
258
  typedef std::list<Ipv4Route *> NetworkRoutes;
259
  typedef std::list<Ipv4Route *>::const_iterator NetworkRoutesCI;
260
  typedef std::list<Ipv4Route *>::iterator NetworkRoutesI;
261
262
  Ipv4Route *LookupGlobal (Ipv4Address dest);
263
264
  HostRoutes m_hostRoutes;
265
  NetworkRoutes m_networkRoutes;
266
};
267
268
} // Namespace ns3
269
270
#endif /* IPV4_GLOBAL_ROUTING_H */
(-)a/src/internet-stack/wscript (+2 lines)
 Lines 131-136   def build(bld): Link Here 
131
        'ipv4-interface.cc',
131
        'ipv4-interface.cc',
132
        'ipv4-l3-protocol.cc',
132
        'ipv4-l3-protocol.cc',
133
        'ipv4-static-routing.cc',
133
        'ipv4-static-routing.cc',
134
        'ipv4-global-routing.cc',
134
        'ipv4-end-point.cc',
135
        'ipv4-end-point.cc',
135
        'udp-l4-protocol.cc',
136
        'udp-l4-protocol.cc',
136
        'tcp-l4-protocol.cc',
137
        'tcp-l4-protocol.cc',
 Lines 164-169   def build(bld): Link Here 
164
        'ipv4-interface.h',
165
        'ipv4-interface.h',
165
        'ipv4-l3-protocol.h',
166
        'ipv4-l3-protocol.h',
166
        'ipv4-static-routing.h',
167
        'ipv4-static-routing.h',
168
        'ipv4-global-routing.h',
167
        'icmpv4.h',
169
        'icmpv4.h',
168
        ]
170
        ]
169
171
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-4 / +56 lines)
 Lines 30-35    Link Here 
30
#include "ns3/log.h"
30
#include "ns3/log.h"
31
#include "ns3/node-list.h"
31
#include "ns3/node-list.h"
32
#include "ns3/ipv4.h"
32
#include "ns3/ipv4.h"
33
#include "ns3/ipv4-global-routing.h"
33
#include "global-router-interface.h"
34
#include "global-router-interface.h"
34
#include "global-route-manager-impl.h"
35
#include "global-route-manager-impl.h"
35
#include "candidate-queue.h"
36
#include "candidate-queue.h"
 Lines 349-354   GlobalRouteManagerImpl::DebugUseLsdb (Gl Link Here 
349
  m_lsdb = lsdb;
350
  m_lsdb = lsdb;
350
}
351
}
351
352
353
  void
354
GlobalRouteManagerImpl::DeleteGlobalRoutes ()
355
{
356
  NS_LOG_FUNCTION_NOARGS ();
357
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
358
    {
359
      Ptr<Node> node = *i;
360
      Ptr<Ipv4GlobalRouting> gr = node->GetObject<Ipv4GlobalRouting> ();
361
      uint32_t j = 0;
362
      uint32_t nRoutes = gr->GetNRoutes ();
363
      NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ());
364
      // Each time we delete route 0, the route index shifts downward
365
      // We can delete all routes if we delete the route numbered 0
366
      // nRoutes times
367
      for (j = 0; j < nRoutes; j++)
368
        {
369
          NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ());
370
          gr->RemoveRoute (0);        
371
        }
372
      NS_LOG_LOGIC ("Deleted " << j << " global routes from node "<< node->GetId ());
373
    }
374
  if (m_lsdb)
375
    {
376
      NS_LOG_LOGIC ("Deleting LSDB, creating new one");
377
      delete m_lsdb;
378
      m_lsdb = new GlobalRouteManagerLSDB ();
379
    }
380
}
381
352
//
382
//
353
// In order to build the routing database, we need at least one of the nodes
383
// 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
384
// to participate as a router.  Eventually we expect to provide a mechanism
 Lines 363-373   GlobalRouteManagerImpl::SelectRouterNode Link Here 
363
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
393
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
364
    {
394
    {
365
      Ptr<Node> node = *i;
395
      Ptr<Node> node = *i;
366
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
396
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ());
367
        node->GetId ());
368
397
369
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
398
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
370
      node->AggregateObject (globalRouter);
399
      node->AggregateObject (globalRouter);
400
401
      NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
402
      Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
403
      // This is the object that will keep the global routes.  We insert it
404
      // at slightly higher priority than static routing (which is at zero).
405
      // This means that global routes (e.g. host routes) will be consulted
406
      // before static routes
407
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
408
      NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
409
        "GetObject for <Ipv4> interface failed");
410
      // XXX make the below  priority value an attribute
411
      ipv4->AddRoutingProtocol (globalRouting, 3);  
412
      // XXX here is another temporary hack until IP refactoring is done.
413
      // we will need a way to get a handle to this globalRouting, but
414
      // there is no public API in ns3::Ipv4 to get it.  Therefore, 
415
      // rather than create new temporary public API, we use aggregation
416
      node->AggregateObject (globalRouting);
371
    }
417
    }
372
}
418
}
373
419
 Lines 1275-1280   GlobalRouteManagerImpl::SPFIntraAddRoute Link Here 
1275
// the local side of the point-to-point links found on the node described by
1321
// the local side of the point-to-point links found on the node described by
1276
// the vertex <v>.
1322
// the vertex <v>.
1277
//
1323
//
1324
          NS_LOG_LOGIC (" Node " << node->GetId () <<
1325
             " found " << nLinkRecords << " link records in LSA " << lsa << "with LinkStateId "<< lsa->GetLinkStateId ());
1278
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1326
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1279
            {
1327
            {
1280
//
1328
//
 Lines 1303-1309   GlobalRouteManagerImpl::SPFIntraAddRoute Link Here 
1303
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1351
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
1304
// which the packets should be send for forwarding.
1352
// which the packets should be send for forwarding.
1305
//
1353
//
1306
              ipv4->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
1354
              Ptr<Ipv4GlobalRouting> gr = node->GetObject<Ipv4GlobalRouting> ();
1355
              NS_ASSERT (gr);
1356
              gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
1307
                v->GetOutgoingTypeId ());
1357
                v->GetOutgoingTypeId ());
1308
            }
1358
            }
1309
//
1359
//
 Lines 1385-1391   GlobalRouteManagerImpl::SPFIntraAddTrans Link Here 
1385
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
1435
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
1386
          Ipv4Address tempip = lsa->GetLinkStateId ();
1436
          Ipv4Address tempip = lsa->GetLinkStateId ();
1387
          tempip = tempip.CombineMask (tempmask);
1437
          tempip = tempip.CombineMask (tempmask);
1388
          ipv4->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
1438
          Ptr<Ipv4GlobalRouting> gr = node->GetObject<Ipv4GlobalRouting> ();
1439
          NS_ASSERT (gr);
1440
          gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
1389
            v->GetOutgoingTypeId ());
1441
            v->GetOutgoingTypeId ());
1390
          NS_LOG_LOGIC ("Node " << node->GetId () <<
1442
          NS_LOG_LOGIC ("Node " << node->GetId () <<
1391
            " add network route to " << tempip <<
1443
            " add network route to " << tempip <<
(-)a/src/routing/global-routing/global-route-manager-impl.h (+10 lines)
 Lines 699-704   public: Link Here 
699
public:
699
public:
700
  GlobalRouteManagerImpl ();
700
  GlobalRouteManagerImpl ();
701
  virtual ~GlobalRouteManagerImpl ();
701
  virtual ~GlobalRouteManagerImpl ();
702
/**
703
 * @brief Delete all static routes on all nodes that have a
704
 * GlobalRouterInterface
705
 *
706
 * TODO:  separate manually assigned static routes from static routes that
707
 * the global routing code injects, and only delete the latter
708
 * @internal
709
 *
710
 */
711
  virtual void DeleteGlobalRoutes ();
702
/**
712
/**
703
 * @brief Select which nodes in the system are to be router nodes and 
713
 * @brief Select which nodes in the system are to be router nodes and 
704
 * aggregate the appropriate interfaces onto those nodes.
714
 * aggregate the appropriate interfaces onto those nodes.
(-)a/src/routing/global-routing/global-route-manager.cc (+15 lines)
 Lines 41-46   GlobalRouteManager::PopulateRoutingTable Link Here 
41
}
41
}
42
42
43
  void
43
  void
44
GlobalRouteManager::RecomputeRoutingTables ()
45
{
46
  DeleteGlobalRoutes ();
47
  BuildGlobalRoutingDatabase ();
48
  InitializeRoutes ();
49
}
50
51
  void
52
GlobalRouteManager::DeleteGlobalRoutes ()
53
{
54
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
55
    DeleteGlobalRoutes ();
56
}
57
58
  void
44
GlobalRouteManager::SelectRouterNodes () 
59
GlobalRouteManager::SelectRouterNodes () 
45
{
60
{
46
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
61
  SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
(-)a/src/routing/global-routing/global-route-manager.h (-1 / +31 lines)
 Lines 42-54   public: Link Here 
42
 * @brief Build a routing database and initialize the routing tables of
42
 * @brief Build a routing database and initialize the routing tables of
43
 * the nodes in the simulation.
43
 * the nodes in the simulation.
44
 *
44
 *
45
 * All this function does is call  BuildGlobalRoutingDatabase () and
45
 * All this function does is call the three private functions
46
 * SelectRouterNodes (), BuildGlobalRoutingDatabase (), and
46
 * InitializeRoutes ().
47
 * InitializeRoutes ().
47
 *
48
 *
49
 * @see SelectRouterNodes ();
48
 * @see BuildGlobalRoutingDatabase ();
50
 * @see BuildGlobalRoutingDatabase ();
49
 * @see InitializeRoutes ();
51
 * @see InitializeRoutes ();
50
 */
52
 */
51
  static void PopulateRoutingTables ();
53
  static void PopulateRoutingTables ();
54
55
 /**
56
  *@brief Remove all routes that were previously installed in a prior call
57
 * to either PopulateRoutingTables() or RecomputeRoutingTables(), and 
58
 * add a new set of routes.  
59
 * 
60
 * This method does not change the set of nodes
61
 * over which GlobalRouting is being used, but it will dynamically update
62
 * its representation of the global topology before recomputing routes.
63
 * Users must first call PopulateRoutingTables() and then may subsequently
64
 * call RecomputeRoutingTables() at any later time in the simulation.
65
 *
66
 * @see DeleteGlobalRoutes ();
67
 * @see BuildGlobalRoutingDatabase ();
68
 * @see InitializeRoutes ();
69
 */
70
 static void RecomputeRoutingTables ();
52
71
53
/**
72
/**
54
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
73
 * @brief Allocate a 32-bit router ID from monotonically increasing counter.
 Lines 56-61   public: Link Here 
56
  static uint32_t AllocateRouterId ();
75
  static uint32_t AllocateRouterId ();
57
76
58
private:
77
private:
78
79
/**
80
 * @brief Delete all static routes on all nodes that have a 
81
 * GlobalRouterInterface
82
 *
83
 * TODO:  separate manually assigned static routes from static routes that
84
 * the global routing code injects, and only delete the latter
85
 * @internal
86
 */
87
  static void DeleteGlobalRoutes ();
88
59
/**
89
/**
60
 * @brief Select which nodes in the system are to be router nodes and 
90
 * @brief Select which nodes in the system are to be router nodes and 
61
 * aggregate the appropriate interfaces onto those nodes.
91
 * aggregate the appropriate interfaces onto those nodes.
(-)a/src/routing/global-routing/global-router-interface.cc (-7 / +13 lines)
 Lines 475-481   GlobalRouter::ClearLSAs () Link Here 
475
475
476
      *i = 0;
476
      *i = 0;
477
    }
477
    }
478
  NS_LOG_LOGIC ("Clear list");
478
  NS_LOG_LOGIC ("Clear list of LSAs");
479
  m_LSAs.clear();
479
  m_LSAs.clear();
480
}
480
}
481
481
 Lines 535-553   GlobalRouter::DiscoverLSAs (void) Link Here 
535
535
536
      // Check if it is an IP interface (could be a pure L2 NetDevice)
536
      // Check if it is an IP interface (could be a pure L2 NetDevice)
537
      bool isIp = false;
537
      bool isIp = false;
538
      for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
538
      for (uint32_t j = 0; j < ipv4Local->GetNInterfaces (); ++j )
539
        {
539
        {
540
          if (ipv4Local->GetNetDevice (i) == ndLocal) 
540
          if (ipv4Local->GetNetDevice (j) == ndLocal) 
541
            {
541
            {
542
              isIp = true;
542
              if (ipv4Local->IsUp (j))
543
              break;
543
                {
544
                  isIp = true;
545
                  break;
546
                }
544
            }
547
            }
545
        }
548
        }
546
      if (!isIp)
549
      if (!isIp)
547
        {
550
        {
548
          continue;
551
          continue;
549
        }
552
        }
550
551
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
553
      if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
552
        {
554
        {
553
          NS_LOG_LOGIC ("Broadcast link");
555
          NS_LOG_LOGIC ("Broadcast link");
 Lines 666-671   GlobalRouter::DiscoverLSAs (void) Link Here 
666
// net device on the other end of the point-to-point channel.
668
// net device on the other end of the point-to-point channel.
667
//
669
//
668
          uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote);
670
          uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote);
671
          if (!ipv4Remote->IsUp (ifIndexRemote))
672
            {
673
              continue;
674
            }
669
//
675
//
670
// Now that we have the Ipv4 interface, we can get the (remote) address and
676
// Now that we have the Ipv4 interface, we can get the (remote) address and
671
// mask we need.
677
// mask we need.

Return to bug 406