move global routing code into global routing directory
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed Jun 10 08:36:51 2009 +0200 (8 months ago)
changeset 45427a1359808b0e
parent 4541 4d3213e6eecd
child 4543 49927f942aea
move global routing code into global routing directory
bindings/python/ns3_module_internet_stack.py
src/internet-stack/ipv4-global-routing.cc
src/internet-stack/ipv4-global-routing.h
src/internet-stack/wscript
src/routing/global-routing/global-route-manager-impl.cc
src/routing/global-routing/ipv4-global-routing.cc
src/routing/global-routing/ipv4-global-routing.h
src/routing/global-routing/wscript
     1.1 --- a/bindings/python/ns3_module_internet_stack.py	Tue Jun 09 06:47:18 2009 -0700
     1.2 +++ b/bindings/python/ns3_module_internet_stack.py	Wed Jun 10 08:36:51 2009 +0200
     1.3 @@ -25,8 +25,6 @@
     1.4      module.add_class('UdpHeader', parent=root_module['ns3::Header'])
     1.5      ## ipv4-static-routing-impl.h: ns3::Ipv4StaticRoutingImpl [class]
     1.6      module.add_class('Ipv4StaticRoutingImpl', parent=root_module['ns3::Ipv4StaticRouting'])
     1.7 -    ## ipv4-global-routing.h: ns3::Ipv4GlobalRouting [class]
     1.8 -    module.add_class('Ipv4GlobalRouting', parent=root_module['ns3::Ipv4RoutingProtocol'])
     1.9      ## ipv4-list-routing-impl.h: ns3::Ipv4ListRoutingImpl [class]
    1.10      module.add_class('Ipv4ListRoutingImpl', parent=root_module['ns3::Ipv4ListRouting'])
    1.11      
    1.12 @@ -88,7 +86,6 @@
    1.13      register_Ns3TcpHeader_methods(root_module, root_module['ns3::TcpHeader'])
    1.14      register_Ns3UdpHeader_methods(root_module, root_module['ns3::UdpHeader'])
    1.15      register_Ns3Ipv4StaticRoutingImpl_methods(root_module, root_module['ns3::Ipv4StaticRoutingImpl'])
    1.16 -    register_Ns3Ipv4GlobalRouting_methods(root_module, root_module['ns3::Ipv4GlobalRouting'])
    1.17      register_Ns3Ipv4ListRoutingImpl_methods(root_module, root_module['ns3::Ipv4ListRoutingImpl'])
    1.18      return
    1.19  
    1.20 @@ -636,70 +633,6 @@
    1.21                     visibility='protected', is_virtual=True)
    1.22      return
    1.23  
    1.24 -def register_Ns3Ipv4GlobalRouting_methods(root_module, cls):
    1.25 -    ## ipv4-global-routing.h: ns3::Ipv4GlobalRouting::Ipv4GlobalRouting(ns3::Ipv4GlobalRouting const & arg0) [copy constructor]
    1.26 -    cls.add_constructor([param('ns3::Ipv4GlobalRouting const &', 'arg0')])
    1.27 -    ## ipv4-global-routing.h: static ns3::TypeId ns3::Ipv4GlobalRouting::GetTypeId() [member function]
    1.28 -    cls.add_method('GetTypeId', 
    1.29 -                   'ns3::TypeId', 
    1.30 -                   [], 
    1.31 -                   is_static=True)
    1.32 -    ## ipv4-global-routing.h: ns3::Ipv4GlobalRouting::Ipv4GlobalRouting() [constructor]
    1.33 -    cls.add_constructor([])
    1.34 -    ## ipv4-global-routing.h: ns3::Ptr<ns3::Ipv4Route> ns3::Ipv4GlobalRouting::RouteOutput(ns3::Ipv4Header const & header, uint32_t oif, ns3::Socket::SocketErrno & sockerr) [member function]
    1.35 -    cls.add_method('RouteOutput', 
    1.36 -                   'ns3::Ptr< ns3::Ipv4Route >', 
    1.37 -                   [param('ns3::Ipv4Header const &', 'header'), param('uint32_t', 'oif'), param('ns3::Socket::SocketErrno &', 'sockerr')], 
    1.38 -                   is_virtual=True)
    1.39 -    ## ipv4-global-routing.h: bool ns3::Ipv4GlobalRouting::RouteInput(ns3::Ptr<ns3::Packet const> p, ns3::Ipv4Header const & header, ns3::Ptr<const ns3::NetDevice> idev, ns3::Callback<void,ns3::Ptr<ns3::Ipv4Route>,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> ucb, ns3::Callback<void,ns3::Ptr<ns3::Ipv4MulticastRoute>,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> mcb, ns3::Callback<void,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,unsigned int,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> lcb, ns3::Callback<void,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> ecb) [member function]
    1.40 -    cls.add_method('RouteInput', 
    1.41 -                   'bool', 
    1.42 -                   [param('ns3::Ptr< ns3::Packet const >', 'p'), param('ns3::Ipv4Header const &', 'header'), param('ns3::Ptr< ns3::NetDevice const >', 'idev'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ucb'), param('ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'mcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'lcb'), param('ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >', 'ecb')], 
    1.43 -                   is_virtual=True)
    1.44 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddHostRouteTo(ns3::Ipv4Address dest, ns3::Ipv4Address nextHop, uint32_t interface) [member function]
    1.45 -    cls.add_method('AddHostRouteTo', 
    1.46 -                   'void', 
    1.47 -                   [param('ns3::Ipv4Address', 'dest'), param('ns3::Ipv4Address', 'nextHop'), param('uint32_t', 'interface')])
    1.48 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddHostRouteTo(ns3::Ipv4Address dest, uint32_t interface) [member function]
    1.49 -    cls.add_method('AddHostRouteTo', 
    1.50 -                   'void', 
    1.51 -                   [param('ns3::Ipv4Address', 'dest'), param('uint32_t', 'interface')])
    1.52 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddNetworkRouteTo(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask, ns3::Ipv4Address nextHop, uint32_t interface) [member function]
    1.53 -    cls.add_method('AddNetworkRouteTo', 
    1.54 -                   'void', 
    1.55 -                   [param('ns3::Ipv4Address', 'network'), param('ns3::Ipv4Mask', 'networkMask'), param('ns3::Ipv4Address', 'nextHop'), param('uint32_t', 'interface')])
    1.56 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddNetworkRouteTo(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask, uint32_t interface) [member function]
    1.57 -    cls.add_method('AddNetworkRouteTo', 
    1.58 -                   'void', 
    1.59 -                   [param('ns3::Ipv4Address', 'network'), param('ns3::Ipv4Mask', 'networkMask'), param('uint32_t', 'interface')])
    1.60 -    ## ipv4-global-routing.h: uint32_t ns3::Ipv4GlobalRouting::GetNRoutes() [member function]
    1.61 -    cls.add_method('GetNRoutes', 
    1.62 -                   'uint32_t', 
    1.63 -                   [])
    1.64 -    ## ipv4-global-routing.h: ns3::Ipv4RoutingTableEntry * ns3::Ipv4GlobalRouting::GetRoute(uint32_t i) [member function]
    1.65 -    cls.add_method('GetRoute', 
    1.66 -                   'ns3::Ipv4RoutingTableEntry *', 
    1.67 -                   [param('uint32_t', 'i')])
    1.68 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::RemoveRoute(uint32_t i) [member function]
    1.69 -    cls.add_method('RemoveRoute', 
    1.70 -                   'void', 
    1.71 -                   [param('uint32_t', 'i')])
    1.72 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::SetNode(ns3::Ptr<ns3::Node> node) [member function]
    1.73 -    cls.add_method('SetNode', 
    1.74 -                   'void', 
    1.75 -                   [param('ns3::Ptr< ns3::Node >', 'node')])
    1.76 -    ## ipv4-global-routing.h: ns3::Ptr<ns3::Node> ns3::Ipv4GlobalRouting::GetNode() const [member function]
    1.77 -    cls.add_method('GetNode', 
    1.78 -                   'ns3::Ptr< ns3::Node >', 
    1.79 -                   [], 
    1.80 -                   is_const=True)
    1.81 -    ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::DoDispose() [member function]
    1.82 -    cls.add_method('DoDispose', 
    1.83 -                   'void', 
    1.84 -                   [], 
    1.85 -                   visibility='protected', is_virtual=True)
    1.86 -    return
    1.87 -
    1.88  def register_Ns3Ipv4ListRoutingImpl_methods(root_module, cls):
    1.89      ## ipv4-list-routing-impl.h: ns3::Ipv4ListRoutingImpl::Ipv4ListRoutingImpl(ns3::Ipv4ListRoutingImpl const & arg0) [copy constructor]
    1.90      cls.add_constructor([param('ns3::Ipv4ListRoutingImpl const &', 'arg0')])
     2.1 --- a/src/internet-stack/ipv4-global-routing.cc	Tue Jun 09 06:47:18 2009 -0700
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,338 +0,0 @@
     2.4 -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
     2.5 -//
     2.6 -// Copyright (c) 2008 University of Washington
     2.7 -//
     2.8 -// This program is free software; you can redistribute it and/or modify
     2.9 -// it under the terms of the GNU General Public License version 2 as
    2.10 -// published by the Free Software Foundation;
    2.11 -//
    2.12 -// This program is distributed in the hope that it will be useful,
    2.13 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 -// GNU General Public License for more details.
    2.16 -//
    2.17 -// You should have received a copy of the GNU General Public License
    2.18 -// along with this program; if not, write to the Free Software
    2.19 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 -//
    2.21 -
    2.22 -#include "ns3/log.h"
    2.23 -#include "ns3/object.h"
    2.24 -#include "ns3/packet.h"
    2.25 -#include "ns3/node.h"
    2.26 -#include "ns3/ipv4-route.h"
    2.27 -#include "ns3/ipv4-routing-table-entry.h"
    2.28 -#include "ipv4-global-routing.h"
    2.29 -
    2.30 -NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
    2.31 -
    2.32 -namespace ns3 {
    2.33 -
    2.34 -NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting);
    2.35 -
    2.36 -TypeId 
    2.37 -Ipv4GlobalRouting::GetTypeId (void)
    2.38 -{ 
    2.39 -  static TypeId tid = TypeId ("ns3::Ipv4GlobalRouting")
    2.40 -    .SetParent<Object> ()
    2.41 -    ;
    2.42 -  return tid;
    2.43 -}
    2.44 -
    2.45 -Ipv4GlobalRouting::Ipv4GlobalRouting () 
    2.46 -{
    2.47 -  NS_LOG_FUNCTION_NOARGS ();
    2.48 -}
    2.49 -
    2.50 -Ipv4GlobalRouting::~Ipv4GlobalRouting ()
    2.51 -{
    2.52 -  NS_LOG_FUNCTION_NOARGS ();
    2.53 -}
    2.54 -
    2.55 -void 
    2.56 -Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
    2.57 -                                   Ipv4Address nextHop, 
    2.58 -                                   uint32_t interface)
    2.59 -{
    2.60 -  NS_LOG_FUNCTION (dest << nextHop << interface);
    2.61 -  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    2.62 -  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, nextHop, interface);
    2.63 -  m_hostRoutes.push_back (route);
    2.64 -}
    2.65 -
    2.66 -void 
    2.67 -Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
    2.68 -                                   uint32_t interface)
    2.69 -{
    2.70 -  NS_LOG_FUNCTION (dest << interface);
    2.71 -  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    2.72 -  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, interface);
    2.73 -  m_hostRoutes.push_back (route);
    2.74 -}
    2.75 -
    2.76 -void 
    2.77 -Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
    2.78 -                                      Ipv4Mask networkMask, 
    2.79 -                                      Ipv4Address nextHop, 
    2.80 -                                      uint32_t interface)
    2.81 -{
    2.82 -  NS_LOG_FUNCTION (network << networkMask << nextHop << interface);
    2.83 -  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    2.84 -  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
    2.85 -                                            networkMask,
    2.86 -                                            nextHop,
    2.87 -                                            interface);
    2.88 -  m_networkRoutes.push_back (route);
    2.89 -}
    2.90 -
    2.91 -void 
    2.92 -Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
    2.93 -                                      Ipv4Mask networkMask, 
    2.94 -                                      uint32_t interface)
    2.95 -{
    2.96 -  NS_LOG_FUNCTION (network << networkMask << interface);
    2.97 -  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    2.98 -  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
    2.99 -                                            networkMask,
   2.100 -                                            interface);
   2.101 -  m_networkRoutes.push_back (route);
   2.102 -}
   2.103 -
   2.104 -Ptr<Ipv4Route>
   2.105 -Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
   2.106 -{
   2.107 -  NS_LOG_FUNCTION_NOARGS ();
   2.108 -  Ptr<Ipv4Route> rtentry = 0;
   2.109 -  bool found = false;
   2.110 -  Ipv4RoutingTableEntry* route = 0;
   2.111 -
   2.112 -  for (HostRoutesCI i = m_hostRoutes.begin (); 
   2.113 -       i != m_hostRoutes.end (); 
   2.114 -       i++) 
   2.115 -    {
   2.116 -      NS_ASSERT ((*i)->IsHost ());
   2.117 -      if ((*i)->GetDest ().IsEqual (dest)) 
   2.118 -        {
   2.119 -          NS_LOG_LOGIC ("Found global host route" << *i); 
   2.120 -          route = (*i);
   2.121 -          found = true; 
   2.122 -          break;
   2.123 -        }
   2.124 -    }
   2.125 -  if (found == false)
   2.126 -    {
   2.127 -      for (NetworkRoutesI j = m_networkRoutes.begin (); 
   2.128 -           j != m_networkRoutes.end (); 
   2.129 -           j++) 
   2.130 -        {
   2.131 -          NS_ASSERT ((*j)->IsNetwork ());
   2.132 -          Ipv4Mask mask = (*j)->GetDestNetworkMask ();
   2.133 -          Ipv4Address entry = (*j)->GetDestNetwork ();
   2.134 -          if (mask.IsMatch (dest, entry)) 
   2.135 -            {
   2.136 -              NS_LOG_LOGIC ("Found global network route" << *j); 
   2.137 -              route = (*j);
   2.138 -              found = true;
   2.139 -              break;
   2.140 -            }
   2.141 -        }
   2.142 -    }
   2.143 -  if (found == true)
   2.144 -    {
   2.145 -      Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
   2.146 -      rtentry = Create<Ipv4Route> ();
   2.147 -      rtentry->SetDestination (route->GetDest ());
   2.148 -      // XXX handle multi-address case
   2.149 -      rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ());
   2.150 -      rtentry->SetGateway (route->GetGateway ());
   2.151 -      uint32_t interfaceIdx = route->GetInterface ();
   2.152 -      rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx));
   2.153 -      return rtentry;
   2.154 -    }
   2.155 -  else 
   2.156 -    {
   2.157 -      return 0;
   2.158 -    }
   2.159 -}
   2.160 -
   2.161 -uint32_t 
   2.162 -Ipv4GlobalRouting::GetNRoutes (void)
   2.163 -{
   2.164 -  NS_LOG_FUNCTION_NOARGS ();
   2.165 -  uint32_t n = 0;
   2.166 -  n += m_hostRoutes.size ();
   2.167 -  n += m_networkRoutes.size ();
   2.168 -  return n;
   2.169 -}
   2.170 -
   2.171 -Ipv4RoutingTableEntry *
   2.172 -Ipv4GlobalRouting::GetRoute (uint32_t index)
   2.173 -{
   2.174 -  NS_LOG_FUNCTION (index);
   2.175 -  if (index < m_hostRoutes.size ())
   2.176 -    {
   2.177 -      uint32_t tmp = 0;
   2.178 -      for (HostRoutesCI i = m_hostRoutes.begin (); 
   2.179 -           i != m_hostRoutes.end (); 
   2.180 -           i++) 
   2.181 -        {
   2.182 -          if (tmp  == index)
   2.183 -            {
   2.184 -              return *i;
   2.185 -            }
   2.186 -          tmp++;
   2.187 -        }
   2.188 -    }
   2.189 -  index -= m_hostRoutes.size ();
   2.190 -  uint32_t tmp = 0;
   2.191 -  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   2.192 -       j != m_networkRoutes.end (); 
   2.193 -       j++) 
   2.194 -    {
   2.195 -      if (tmp == index)
   2.196 -        {
   2.197 -          return *j;
   2.198 -        }
   2.199 -      tmp++;
   2.200 -    }
   2.201 -  NS_ASSERT (false);
   2.202 -  // quiet compiler.
   2.203 -  return 0;
   2.204 -}
   2.205 -void 
   2.206 -Ipv4GlobalRouting::RemoveRoute (uint32_t index)
   2.207 -{
   2.208 -  NS_LOG_FUNCTION (index);
   2.209 -  if (index < m_hostRoutes.size ())
   2.210 -    {
   2.211 -      uint32_t tmp = 0;
   2.212 -      for (HostRoutesI i = m_hostRoutes.begin (); 
   2.213 -           i != m_hostRoutes.end (); 
   2.214 -           i++) 
   2.215 -        {
   2.216 -          if (tmp  == index)
   2.217 -            {
   2.218 -              NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_hostRoutes.size());
   2.219 -              delete *i;
   2.220 -              m_hostRoutes.erase (i);
   2.221 -              NS_LOG_LOGIC ("Done removing host route " << index << "; host route remaining size = " << m_hostRoutes.size());
   2.222 -              return;
   2.223 -            }
   2.224 -          tmp++;
   2.225 -        }
   2.226 -    }
   2.227 -  index -= m_hostRoutes.size ();
   2.228 -  uint32_t tmp = 0;
   2.229 -  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   2.230 -       j != m_networkRoutes.end (); 
   2.231 -       j++) 
   2.232 -    {
   2.233 -      if (tmp == index)
   2.234 -        {
   2.235 -          NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_networkRoutes.size());
   2.236 -          delete *j;
   2.237 -          m_networkRoutes.erase (j);
   2.238 -          NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
   2.239 -          return;
   2.240 -        }
   2.241 -      tmp++;
   2.242 -    }
   2.243 -  NS_ASSERT (false);
   2.244 -}
   2.245 -
   2.246 -void
   2.247 -Ipv4GlobalRouting::DoDispose (void)
   2.248 -{
   2.249 -  NS_LOG_FUNCTION_NOARGS ();
   2.250 -  for (HostRoutesI i = m_hostRoutes.begin (); 
   2.251 -       i != m_hostRoutes.end (); 
   2.252 -       i = m_hostRoutes.erase (i)) 
   2.253 -    {
   2.254 -      delete (*i);
   2.255 -    }
   2.256 -  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   2.257 -       j != m_networkRoutes.end (); 
   2.258 -       j = m_networkRoutes.erase (j)) 
   2.259 -    {
   2.260 -      delete (*j);
   2.261 -    }
   2.262 -  Ipv4RoutingProtocol::DoDispose ();
   2.263 -}
   2.264 -
   2.265 -Ptr<Ipv4Route>
   2.266 -Ipv4GlobalRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
   2.267 -{      
   2.268 -
   2.269 -//
   2.270 -// First, see if this is a multicast packet we have a route for.  If we
   2.271 -// have a route, then send the packet down each of the specified interfaces.
   2.272 -//
   2.273 -  if (header.GetDestination().IsMulticast ())
   2.274 -    {
   2.275 -      NS_LOG_LOGIC ("Multicast destination-- returning false");
   2.276 -      return 0; // Let other routing protocols try to handle this
   2.277 -    }
   2.278 -//
   2.279 -// See if this is a unicast packet we have a route for.
   2.280 -//
   2.281 -  NS_LOG_LOGIC ("Unicast destination- looking up");
   2.282 -  Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination());
   2.283 -  if (rtentry)
   2.284 -    {
   2.285 -      sockerr = Socket::ERROR_NOTERROR;
   2.286 -    }
   2.287 -  else
   2.288 -    {
   2.289 -      sockerr = Socket::ERROR_NOROUTETOHOST;
   2.290 -    }
   2.291 -  return rtentry;
   2.292 -}
   2.293 -
   2.294 -bool 
   2.295 -Ipv4GlobalRouting::RouteInput  (Ptr<const Packet> p, const Ipv4Header &ipHeader, Ptr<const NetDevice> idev,                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
   2.296 -                             LocalDeliverCallback lcb, ErrorCallback ecb) 
   2.297 -{ 
   2.298 -
   2.299 -  NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev);
   2.300 -
   2.301 -  if (ipHeader.GetDestination ().IsMulticast ())
   2.302 -    {
   2.303 -      NS_LOG_LOGIC ("Multicast destination-- returning false");
   2.304 -      return false; // Let other routing protocols try to handle this
   2.305 -    }
   2.306 -
   2.307 -// This is a unicast packet.  Check to see if we have a route for it.
   2.308 -//
   2.309 -  NS_LOG_LOGIC ("Unicast destination- looking up");
   2.310 -  Ptr<Ipv4Route> rtentry = LookupGlobal (ipHeader.GetDestination ());
   2.311 -  if (rtentry != 0)
   2.312 -    {
   2.313 -      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
   2.314 -      ucb (rtentry, p, ipHeader);
   2.315 -      return true;
   2.316 -    }
   2.317 -  else
   2.318 -    {
   2.319 -      NS_LOG_LOGIC ("Did not find unicast destination- returning false");
   2.320 -      return false; // Let other routing protocols try to handle this
   2.321 -                    // route request.
   2.322 -    }
   2.323 -}
   2.324 -
   2.325 -void
   2.326 -Ipv4GlobalRouting::SetNode (Ptr<Node> node)
   2.327 -{
   2.328 -  NS_LOG_FUNCTION_NOARGS ();
   2.329 -  m_node = node;
   2.330 -}
   2.331 -
   2.332 -Ptr<Node>
   2.333 -Ipv4GlobalRouting::GetNode (void) const
   2.334 -{
   2.335 -  NS_LOG_FUNCTION_NOARGS ();
   2.336 -  return m_node;
   2.337 -}
   2.338 -
   2.339 -
   2.340 -
   2.341 -}//namespace ns3
     3.1 --- a/src/internet-stack/ipv4-global-routing.h	Tue Jun 09 06:47:18 2009 -0700
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,216 +0,0 @@
     3.4 -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
     3.5 -//
     3.6 -// Copyright (c) 2008 University of Washington
     3.7 -//
     3.8 -// This program is free software; you can redistribute it and/or modify
     3.9 -// it under the terms of the GNU General Public License version 2 as
    3.10 -// published by the Free Software Foundation;
    3.11 -//
    3.12 -// This program is distributed in the hope that it will be useful,
    3.13 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 -// GNU General Public License for more details.
    3.16 -//
    3.17 -// You should have received a copy of the GNU General Public License
    3.18 -// along with this program; if not, write to the Free Software
    3.19 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.20 -//
    3.21 -//
    3.22 -
    3.23 -#ifndef IPV4_GLOBAL_ROUTING_H
    3.24 -#define IPV4_GLOBAL_ROUTING_H
    3.25 -
    3.26 -#include <list>
    3.27 -#include <stdint.h>
    3.28 -#include "ns3/ipv4-address.h"
    3.29 -#include "ns3/ipv4-header.h"
    3.30 -#include "ns3/ptr.h"
    3.31 -#include "ns3/ipv4.h"
    3.32 -#include "ns3/ipv4-routing-protocol.h"
    3.33 -
    3.34 -namespace ns3 {
    3.35 -
    3.36 -class Packet;
    3.37 -class NetDevice;
    3.38 -class Ipv4Interface;
    3.39 -class Ipv4Address;
    3.40 -class Ipv4Header;
    3.41 -class Ipv4RoutingTableEntry;
    3.42 -class Ipv4MulticastRoutingTableEntry;
    3.43 -class Node;
    3.44 -
    3.45 -
    3.46 -/**
    3.47 - * \brief Global routing protocol for IP version 4 stacks.
    3.48 - *
    3.49 - * In ns-3 we have the concept of a pluggable routing protocol.  Routing
    3.50 - * protocols are added to a list maintained by the Ipv4L3Protocol.  Every 
    3.51 - * stack gets one routing protocol for free -- the Ipv4StaticRouting routing
    3.52 - * protocol is added in the constructor of the Ipv4L3Protocol (this is the 
    3.53 - * piece of code that implements the functionality of the IP layer).
    3.54 - *
    3.55 - * As an option to running a dynamic routing protocol, a GlobalRouteManager
    3.56 - * object has been created to allow users to build routes for all participating
    3.57 - * nodes.  One can think of this object as a "routing oracle"; it has
    3.58 - * an omniscient view of the topology, and can construct shortest path
    3.59 - * routes between all pairs of nodes.  These routes must be stored 
    3.60 - * somewhere in the node, so therefore this class Ipv4GlobalRouting
    3.61 - * is used as one of the pluggable routing protocols.  It is kept distinct
    3.62 - * from Ipv4StaticRouting because these routes may be dynamically cleared
    3.63 - * and rebuilt in the middle of the simulation, while manually entered
    3.64 - * routes into the Ipv4StaticRouting may need to be kept distinct.
    3.65 - *
    3.66 - * This class deals with Ipv4 unicast routes only.
    3.67 - *
    3.68 - * \see Ipv4RoutingProtocol
    3.69 - * \see GlobalRouteManager
    3.70 - */
    3.71 -class Ipv4GlobalRouting : public Ipv4RoutingProtocol
    3.72 -{
    3.73 -public:
    3.74 -  static TypeId GetTypeId (void);
    3.75 -/**
    3.76 - * \brief Construct an empty Ipv4GlobalRouting routing protocol,
    3.77 - *
    3.78 - * The Ipv4GlobalRouting class supports host and network unicast routes.
    3.79 - * This method initializes the lists containing these routes to empty.
    3.80 - *
    3.81 - * \see Ipv4GlobalRouting
    3.82 - */
    3.83 -  Ipv4GlobalRouting ();
    3.84 -  virtual ~Ipv4GlobalRouting ();
    3.85 -
    3.86 -  virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
    3.87 -
    3.88 -  virtual bool RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
    3.89 -                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
    3.90 -                             LocalDeliverCallback lcb, ErrorCallback ecb);
    3.91 -
    3.92 -/**
    3.93 - * \brief Add a host route to the global routing table.
    3.94 - *
    3.95 - * \param dest The Ipv4Address destination for this route.
    3.96 - * \param nextHop The Ipv4Address of the next hop in the route.
    3.97 - * \param interface The network interface index used to send packets to the
    3.98 - * destination.
    3.99 - *
   3.100 - * \see Ipv4Address
   3.101 - */
   3.102 -  void AddHostRouteTo (Ipv4Address dest, 
   3.103 -                       Ipv4Address nextHop, 
   3.104 -                       uint32_t interface);
   3.105 -/**
   3.106 - * \brief Add a host route to the global routing table.
   3.107 - *
   3.108 - * \param dest The Ipv4Address destination for this route.
   3.109 - * \param interface The network interface index used to send packets to the
   3.110 - * destination.
   3.111 - *
   3.112 - * \see Ipv4Address
   3.113 - */
   3.114 -  void AddHostRouteTo (Ipv4Address dest, 
   3.115 -                       uint32_t interface);
   3.116 -
   3.117 -/**
   3.118 - * \brief Add a network route to the global routing table.
   3.119 - *
   3.120 - * \param network The Ipv4Address network for this route.
   3.121 - * \param networkMask The Ipv4Mask to extract the network.
   3.122 - * \param nextHop The next hop in the route to the destination network.
   3.123 - * \param interface The network interface index used to send packets to the
   3.124 - * destination.
   3.125 - *
   3.126 - * \see Ipv4Address
   3.127 - */
   3.128 -  void AddNetworkRouteTo (Ipv4Address network, 
   3.129 -                          Ipv4Mask networkMask, 
   3.130 -                          Ipv4Address nextHop, 
   3.131 -                          uint32_t interface);
   3.132 -
   3.133 -/**
   3.134 - * \brief Add a network route to the global routing table.
   3.135 - *
   3.136 - * \param network The Ipv4Address network for this route.
   3.137 - * \param networkMask The Ipv4Mask to extract the network.
   3.138 - * \param interface The network interface index used to send packets to the
   3.139 - * destination.
   3.140 - *
   3.141 - * \see Ipv4Address
   3.142 - */
   3.143 -  void AddNetworkRouteTo (Ipv4Address network, 
   3.144 -                          Ipv4Mask networkMask, 
   3.145 -                          uint32_t interface);
   3.146 -
   3.147 -/**
   3.148 - * \brief Get the number of individual unicast routes that have been added
   3.149 - * to the routing table.
   3.150 - *
   3.151 - * \warning The default route counts as one of the routes.
   3.152 - */
   3.153 -  uint32_t GetNRoutes (void);
   3.154 -
   3.155 -/**
   3.156 - * \brief Get a route from the global unicast routing table.
   3.157 - *
   3.158 - * Externally, the unicast global routing table appears simply as a table with
   3.159 - * n entries.  The one sublety of note is that if a default route has been set
   3.160 - * it will appear as the zeroth entry in the table.  This means that if you
   3.161 - * add only a default route, the table will have one entry that can be accessed
   3.162 - * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
   3.163 - * 
   3.164 - * Similarly, if the default route has been set, calling RemoveRoute (0) will
   3.165 - * remove the default route.
   3.166 - *
   3.167 - * \param i The index (into the routing table) of the route to retrieve.  If
   3.168 - * the default route has been set, it will occupy index zero.
   3.169 - * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
   3.170 - * a zero pointer is returned.
   3.171 - *
   3.172 - * \see Ipv4RoutingTableEntry
   3.173 - * \see Ipv4GlobalRouting::RemoveRoute
   3.174 - */
   3.175 -  Ipv4RoutingTableEntry *GetRoute (uint32_t i);
   3.176 -
   3.177 -/**
   3.178 - * \brief Remove a route from the global unicast routing table.
   3.179 - *
   3.180 - * Externally, the unicast global routing table appears simply as a table with
   3.181 - * n entries.  The one sublety of note is that if a default route has been set
   3.182 - * it will appear as the zeroth entry in the table.  This means that if the
   3.183 - * default route has been set, calling RemoveRoute (0) will remove the
   3.184 - * default route.
   3.185 - *
   3.186 - * \param i The index (into the routing table) of the route to remove.  If
   3.187 - * the default route has been set, it will occupy index zero.
   3.188 - *
   3.189 - * \see Ipv4RoutingTableEntry
   3.190 - * \see Ipv4GlobalRouting::GetRoute
   3.191 - * \see Ipv4GlobalRouting::AddRoute
   3.192 - */
   3.193 -  void RemoveRoute (uint32_t i);
   3.194 -
   3.195 -  void SetNode (Ptr<Node> node);
   3.196 -  Ptr<Node> GetNode (void) const;
   3.197 -
   3.198 -protected:
   3.199 -  void DoDispose (void);
   3.200 -
   3.201 -private:
   3.202 -  typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
   3.203 -  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
   3.204 -  typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
   3.205 -  typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
   3.206 -  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
   3.207 -  typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
   3.208 -
   3.209 -  Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
   3.210 -
   3.211 -  HostRoutes m_hostRoutes;
   3.212 -  NetworkRoutes m_networkRoutes;
   3.213 -
   3.214 -  Ptr<Node> m_node;
   3.215 -};
   3.216 -
   3.217 -} // Namespace ns3
   3.218 -
   3.219 -#endif /* IPV4_GLOBAL_ROUTING_H */
     4.1 --- a/src/internet-stack/wscript	Tue Jun 09 06:47:18 2009 -0700
     4.2 +++ b/src/internet-stack/wscript	Wed Jun 10 08:36:51 2009 +0200
     4.3 @@ -82,7 +82,6 @@
     4.4          'ipv4-l3-protocol.cc',
     4.5          'ipv4-static-routing-impl.cc',
     4.6          'ipv4-list-routing-impl.cc',
     4.7 -        'ipv4-global-routing.cc',
     4.8          'ipv4-end-point.cc',
     4.9          'udp-l4-protocol.cc',
    4.10          'tcp-l4-protocol.cc',
    4.11 @@ -110,7 +109,6 @@
    4.12          'udp-header.h',
    4.13          'tcp-header.h',
    4.14          'sequence-number.h',
    4.15 -        'ipv4-global-routing.h',
    4.16          'ipv4-list-routing-impl.h',
    4.17          'ipv4-static-routing-impl.h',
    4.18          'icmpv4.h',
     5.1 --- a/src/routing/global-routing/global-route-manager-impl.cc	Tue Jun 09 06:47:18 2009 -0700
     5.2 +++ b/src/routing/global-routing/global-route-manager-impl.cc	Wed Jun 10 08:36:51 2009 +0200
     5.3 @@ -30,12 +30,12 @@
     5.4  #include "ns3/log.h"
     5.5  #include "ns3/node-list.h"
     5.6  #include "ns3/ipv4.h"
     5.7 -#include "ns3/ipv4-global-routing.h"
     5.8  #include "ns3/ipv4-routing-protocol.h"
     5.9  #include "ns3/ipv4-list-routing.h"
    5.10  #include "global-router-interface.h"
    5.11  #include "global-route-manager-impl.h"
    5.12  #include "candidate-queue.h"
    5.13 +#include "ipv4-global-routing.h"
    5.14  
    5.15  NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");
    5.16  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/routing/global-routing/ipv4-global-routing.cc	Wed Jun 10 08:36:51 2009 +0200
     6.3 @@ -0,0 +1,338 @@
     6.4 +// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
     6.5 +//
     6.6 +// Copyright (c) 2008 University of Washington
     6.7 +//
     6.8 +// This program is free software; you can redistribute it and/or modify
     6.9 +// it under the terms of the GNU General Public License version 2 as
    6.10 +// published by the Free Software Foundation;
    6.11 +//
    6.12 +// This program is distributed in the hope that it will be useful,
    6.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 +// GNU General Public License for more details.
    6.16 +//
    6.17 +// You should have received a copy of the GNU General Public License
    6.18 +// along with this program; if not, write to the Free Software
    6.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.20 +//
    6.21 +
    6.22 +#include "ns3/log.h"
    6.23 +#include "ns3/object.h"
    6.24 +#include "ns3/packet.h"
    6.25 +#include "ns3/node.h"
    6.26 +#include "ns3/ipv4-route.h"
    6.27 +#include "ns3/ipv4-routing-table-entry.h"
    6.28 +#include "ipv4-global-routing.h"
    6.29 +
    6.30 +NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
    6.31 +
    6.32 +namespace ns3 {
    6.33 +
    6.34 +NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting);
    6.35 +
    6.36 +TypeId 
    6.37 +Ipv4GlobalRouting::GetTypeId (void)
    6.38 +{ 
    6.39 +  static TypeId tid = TypeId ("ns3::Ipv4GlobalRouting")
    6.40 +    .SetParent<Object> ()
    6.41 +    ;
    6.42 +  return tid;
    6.43 +}
    6.44 +
    6.45 +Ipv4GlobalRouting::Ipv4GlobalRouting () 
    6.46 +{
    6.47 +  NS_LOG_FUNCTION_NOARGS ();
    6.48 +}
    6.49 +
    6.50 +Ipv4GlobalRouting::~Ipv4GlobalRouting ()
    6.51 +{
    6.52 +  NS_LOG_FUNCTION_NOARGS ();
    6.53 +}
    6.54 +
    6.55 +void 
    6.56 +Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
    6.57 +                                   Ipv4Address nextHop, 
    6.58 +                                   uint32_t interface)
    6.59 +{
    6.60 +  NS_LOG_FUNCTION (dest << nextHop << interface);
    6.61 +  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    6.62 +  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, nextHop, interface);
    6.63 +  m_hostRoutes.push_back (route);
    6.64 +}
    6.65 +
    6.66 +void 
    6.67 +Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest, 
    6.68 +                                   uint32_t interface)
    6.69 +{
    6.70 +  NS_LOG_FUNCTION (dest << interface);
    6.71 +  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    6.72 +  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, interface);
    6.73 +  m_hostRoutes.push_back (route);
    6.74 +}
    6.75 +
    6.76 +void 
    6.77 +Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
    6.78 +                                      Ipv4Mask networkMask, 
    6.79 +                                      Ipv4Address nextHop, 
    6.80 +                                      uint32_t interface)
    6.81 +{
    6.82 +  NS_LOG_FUNCTION (network << networkMask << nextHop << interface);
    6.83 +  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    6.84 +  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
    6.85 +                                            networkMask,
    6.86 +                                            nextHop,
    6.87 +                                            interface);
    6.88 +  m_networkRoutes.push_back (route);
    6.89 +}
    6.90 +
    6.91 +void 
    6.92 +Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network, 
    6.93 +                                      Ipv4Mask networkMask, 
    6.94 +                                      uint32_t interface)
    6.95 +{
    6.96 +  NS_LOG_FUNCTION (network << networkMask << interface);
    6.97 +  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
    6.98 +  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
    6.99 +                                            networkMask,
   6.100 +                                            interface);
   6.101 +  m_networkRoutes.push_back (route);
   6.102 +}
   6.103 +
   6.104 +Ptr<Ipv4Route>
   6.105 +Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
   6.106 +{
   6.107 +  NS_LOG_FUNCTION_NOARGS ();
   6.108 +  Ptr<Ipv4Route> rtentry = 0;
   6.109 +  bool found = false;
   6.110 +  Ipv4RoutingTableEntry* route = 0;
   6.111 +
   6.112 +  for (HostRoutesCI i = m_hostRoutes.begin (); 
   6.113 +       i != m_hostRoutes.end (); 
   6.114 +       i++) 
   6.115 +    {
   6.116 +      NS_ASSERT ((*i)->IsHost ());
   6.117 +      if ((*i)->GetDest ().IsEqual (dest)) 
   6.118 +        {
   6.119 +          NS_LOG_LOGIC ("Found global host route" << *i); 
   6.120 +          route = (*i);
   6.121 +          found = true; 
   6.122 +          break;
   6.123 +        }
   6.124 +    }
   6.125 +  if (found == false)
   6.126 +    {
   6.127 +      for (NetworkRoutesI j = m_networkRoutes.begin (); 
   6.128 +           j != m_networkRoutes.end (); 
   6.129 +           j++) 
   6.130 +        {
   6.131 +          NS_ASSERT ((*j)->IsNetwork ());
   6.132 +          Ipv4Mask mask = (*j)->GetDestNetworkMask ();
   6.133 +          Ipv4Address entry = (*j)->GetDestNetwork ();
   6.134 +          if (mask.IsMatch (dest, entry)) 
   6.135 +            {
   6.136 +              NS_LOG_LOGIC ("Found global network route" << *j); 
   6.137 +              route = (*j);
   6.138 +              found = true;
   6.139 +              break;
   6.140 +            }
   6.141 +        }
   6.142 +    }
   6.143 +  if (found == true)
   6.144 +    {
   6.145 +      Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
   6.146 +      rtentry = Create<Ipv4Route> ();
   6.147 +      rtentry->SetDestination (route->GetDest ());
   6.148 +      // XXX handle multi-address case
   6.149 +      rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ());
   6.150 +      rtentry->SetGateway (route->GetGateway ());
   6.151 +      uint32_t interfaceIdx = route->GetInterface ();
   6.152 +      rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx));
   6.153 +      return rtentry;
   6.154 +    }
   6.155 +  else 
   6.156 +    {
   6.157 +      return 0;
   6.158 +    }
   6.159 +}
   6.160 +
   6.161 +uint32_t 
   6.162 +Ipv4GlobalRouting::GetNRoutes (void)
   6.163 +{
   6.164 +  NS_LOG_FUNCTION_NOARGS ();
   6.165 +  uint32_t n = 0;
   6.166 +  n += m_hostRoutes.size ();
   6.167 +  n += m_networkRoutes.size ();
   6.168 +  return n;
   6.169 +}
   6.170 +
   6.171 +Ipv4RoutingTableEntry *
   6.172 +Ipv4GlobalRouting::GetRoute (uint32_t index)
   6.173 +{
   6.174 +  NS_LOG_FUNCTION (index);
   6.175 +  if (index < m_hostRoutes.size ())
   6.176 +    {
   6.177 +      uint32_t tmp = 0;
   6.178 +      for (HostRoutesCI i = m_hostRoutes.begin (); 
   6.179 +           i != m_hostRoutes.end (); 
   6.180 +           i++) 
   6.181 +        {
   6.182 +          if (tmp  == index)
   6.183 +            {
   6.184 +              return *i;
   6.185 +            }
   6.186 +          tmp++;
   6.187 +        }
   6.188 +    }
   6.189 +  index -= m_hostRoutes.size ();
   6.190 +  uint32_t tmp = 0;
   6.191 +  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   6.192 +       j != m_networkRoutes.end (); 
   6.193 +       j++) 
   6.194 +    {
   6.195 +      if (tmp == index)
   6.196 +        {
   6.197 +          return *j;
   6.198 +        }
   6.199 +      tmp++;
   6.200 +    }
   6.201 +  NS_ASSERT (false);
   6.202 +  // quiet compiler.
   6.203 +  return 0;
   6.204 +}
   6.205 +void 
   6.206 +Ipv4GlobalRouting::RemoveRoute (uint32_t index)
   6.207 +{
   6.208 +  NS_LOG_FUNCTION (index);
   6.209 +  if (index < m_hostRoutes.size ())
   6.210 +    {
   6.211 +      uint32_t tmp = 0;
   6.212 +      for (HostRoutesI i = m_hostRoutes.begin (); 
   6.213 +           i != m_hostRoutes.end (); 
   6.214 +           i++) 
   6.215 +        {
   6.216 +          if (tmp  == index)
   6.217 +            {
   6.218 +              NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_hostRoutes.size());
   6.219 +              delete *i;
   6.220 +              m_hostRoutes.erase (i);
   6.221 +              NS_LOG_LOGIC ("Done removing host route " << index << "; host route remaining size = " << m_hostRoutes.size());
   6.222 +              return;
   6.223 +            }
   6.224 +          tmp++;
   6.225 +        }
   6.226 +    }
   6.227 +  index -= m_hostRoutes.size ();
   6.228 +  uint32_t tmp = 0;
   6.229 +  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   6.230 +       j != m_networkRoutes.end (); 
   6.231 +       j++) 
   6.232 +    {
   6.233 +      if (tmp == index)
   6.234 +        {
   6.235 +          NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_networkRoutes.size());
   6.236 +          delete *j;
   6.237 +          m_networkRoutes.erase (j);
   6.238 +          NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
   6.239 +          return;
   6.240 +        }
   6.241 +      tmp++;
   6.242 +    }
   6.243 +  NS_ASSERT (false);
   6.244 +}
   6.245 +
   6.246 +void
   6.247 +Ipv4GlobalRouting::DoDispose (void)
   6.248 +{
   6.249 +  NS_LOG_FUNCTION_NOARGS ();
   6.250 +  for (HostRoutesI i = m_hostRoutes.begin (); 
   6.251 +       i != m_hostRoutes.end (); 
   6.252 +       i = m_hostRoutes.erase (i)) 
   6.253 +    {
   6.254 +      delete (*i);
   6.255 +    }
   6.256 +  for (NetworkRoutesI j = m_networkRoutes.begin (); 
   6.257 +       j != m_networkRoutes.end (); 
   6.258 +       j = m_networkRoutes.erase (j)) 
   6.259 +    {
   6.260 +      delete (*j);
   6.261 +    }
   6.262 +  Ipv4RoutingProtocol::DoDispose ();
   6.263 +}
   6.264 +
   6.265 +Ptr<Ipv4Route>
   6.266 +Ipv4GlobalRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
   6.267 +{      
   6.268 +
   6.269 +//
   6.270 +// First, see if this is a multicast packet we have a route for.  If we
   6.271 +// have a route, then send the packet down each of the specified interfaces.
   6.272 +//
   6.273 +  if (header.GetDestination().IsMulticast ())
   6.274 +    {
   6.275 +      NS_LOG_LOGIC ("Multicast destination-- returning false");
   6.276 +      return 0; // Let other routing protocols try to handle this
   6.277 +    }
   6.278 +//
   6.279 +// See if this is a unicast packet we have a route for.
   6.280 +//
   6.281 +  NS_LOG_LOGIC ("Unicast destination- looking up");
   6.282 +  Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination());
   6.283 +  if (rtentry)
   6.284 +    {
   6.285 +      sockerr = Socket::ERROR_NOTERROR;
   6.286 +    }
   6.287 +  else
   6.288 +    {
   6.289 +      sockerr = Socket::ERROR_NOROUTETOHOST;
   6.290 +    }
   6.291 +  return rtentry;
   6.292 +}
   6.293 +
   6.294 +bool 
   6.295 +Ipv4GlobalRouting::RouteInput  (Ptr<const Packet> p, const Ipv4Header &ipHeader, Ptr<const NetDevice> idev,                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
   6.296 +                             LocalDeliverCallback lcb, ErrorCallback ecb) 
   6.297 +{ 
   6.298 +
   6.299 +  NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev);
   6.300 +
   6.301 +  if (ipHeader.GetDestination ().IsMulticast ())
   6.302 +    {
   6.303 +      NS_LOG_LOGIC ("Multicast destination-- returning false");
   6.304 +      return false; // Let other routing protocols try to handle this
   6.305 +    }
   6.306 +
   6.307 +// This is a unicast packet.  Check to see if we have a route for it.
   6.308 +//
   6.309 +  NS_LOG_LOGIC ("Unicast destination- looking up");
   6.310 +  Ptr<Ipv4Route> rtentry = LookupGlobal (ipHeader.GetDestination ());
   6.311 +  if (rtentry != 0)
   6.312 +    {
   6.313 +      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
   6.314 +      ucb (rtentry, p, ipHeader);
   6.315 +      return true;
   6.316 +    }
   6.317 +  else
   6.318 +    {
   6.319 +      NS_LOG_LOGIC ("Did not find unicast destination- returning false");
   6.320 +      return false; // Let other routing protocols try to handle this
   6.321 +                    // route request.
   6.322 +    }
   6.323 +}
   6.324 +
   6.325 +void
   6.326 +Ipv4GlobalRouting::SetNode (Ptr<Node> node)
   6.327 +{
   6.328 +  NS_LOG_FUNCTION_NOARGS ();
   6.329 +  m_node = node;
   6.330 +}
   6.331 +
   6.332 +Ptr<Node>
   6.333 +Ipv4GlobalRouting::GetNode (void) const
   6.334 +{
   6.335 +  NS_LOG_FUNCTION_NOARGS ();
   6.336 +  return m_node;
   6.337 +}
   6.338 +
   6.339 +
   6.340 +
   6.341 +}//namespace ns3
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/routing/global-routing/ipv4-global-routing.h	Wed Jun 10 08:36:51 2009 +0200
     7.3 @@ -0,0 +1,216 @@
     7.4 +// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
     7.5 +//
     7.6 +// Copyright (c) 2008 University of Washington
     7.7 +//
     7.8 +// This program is free software; you can redistribute it and/or modify
     7.9 +// it under the terms of the GNU General Public License version 2 as
    7.10 +// published by the Free Software Foundation;
    7.11 +//
    7.12 +// This program is distributed in the hope that it will be useful,
    7.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 +// GNU General Public License for more details.
    7.16 +//
    7.17 +// You should have received a copy of the GNU General Public License
    7.18 +// along with this program; if not, write to the Free Software
    7.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.20 +//
    7.21 +//
    7.22 +
    7.23 +#ifndef IPV4_GLOBAL_ROUTING_H
    7.24 +#define IPV4_GLOBAL_ROUTING_H
    7.25 +
    7.26 +#include <list>
    7.27 +#include <stdint.h>
    7.28 +#include "ns3/ipv4-address.h"
    7.29 +#include "ns3/ipv4-header.h"
    7.30 +#include "ns3/ptr.h"
    7.31 +#include "ns3/ipv4.h"
    7.32 +#include "ns3/ipv4-routing-protocol.h"
    7.33 +
    7.34 +namespace ns3 {
    7.35 +
    7.36 +class Packet;
    7.37 +class NetDevice;
    7.38 +class Ipv4Interface;
    7.39 +class Ipv4Address;
    7.40 +class Ipv4Header;
    7.41 +class Ipv4RoutingTableEntry;
    7.42 +class Ipv4MulticastRoutingTableEntry;
    7.43 +class Node;
    7.44 +
    7.45 +
    7.46 +/**
    7.47 + * \brief Global routing protocol for IP version 4 stacks.
    7.48 + *
    7.49 + * In ns-3 we have the concept of a pluggable routing protocol.  Routing
    7.50 + * protocols are added to a list maintained by the Ipv4L3Protocol.  Every 
    7.51 + * stack gets one routing protocol for free -- the Ipv4StaticRouting routing
    7.52 + * protocol is added in the constructor of the Ipv4L3Protocol (this is the 
    7.53 + * piece of code that implements the functionality of the IP layer).
    7.54 + *
    7.55 + * As an option to running a dynamic routing protocol, a GlobalRouteManager
    7.56 + * object has been created to allow users to build routes for all participating
    7.57 + * nodes.  One can think of this object as a "routing oracle"; it has
    7.58 + * an omniscient view of the topology, and can construct shortest path
    7.59 + * routes between all pairs of nodes.  These routes must be stored 
    7.60 + * somewhere in the node, so therefore this class Ipv4GlobalRouting
    7.61 + * is used as one of the pluggable routing protocols.  It is kept distinct
    7.62 + * from Ipv4StaticRouting because these routes may be dynamically cleared
    7.63 + * and rebuilt in the middle of the simulation, while manually entered
    7.64 + * routes into the Ipv4StaticRouting may need to be kept distinct.
    7.65 + *
    7.66 + * This class deals with Ipv4 unicast routes only.
    7.67 + *
    7.68 + * \see Ipv4RoutingProtocol
    7.69 + * \see GlobalRouteManager
    7.70 + */
    7.71 +class Ipv4GlobalRouting : public Ipv4RoutingProtocol
    7.72 +{
    7.73 +public:
    7.74 +  static TypeId GetTypeId (void);
    7.75 +/**
    7.76 + * \brief Construct an empty Ipv4GlobalRouting routing protocol,
    7.77 + *
    7.78 + * The Ipv4GlobalRouting class supports host and network unicast routes.
    7.79 + * This method initializes the lists containing these routes to empty.
    7.80 + *
    7.81 + * \see Ipv4GlobalRouting
    7.82 + */
    7.83 +  Ipv4GlobalRouting ();
    7.84 +  virtual ~Ipv4GlobalRouting ();
    7.85 +
    7.86 +  virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
    7.87 +
    7.88 +  virtual bool RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
    7.89 +                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
    7.90 +                             LocalDeliverCallback lcb, ErrorCallback ecb);
    7.91 +
    7.92 +/**
    7.93 + * \brief Add a host route to the global routing table.
    7.94 + *
    7.95 + * \param dest The Ipv4Address destination for this route.
    7.96 + * \param nextHop The Ipv4Address of the next hop in the route.
    7.97 + * \param interface The network interface index used to send packets to the
    7.98 + * destination.
    7.99 + *
   7.100 + * \see Ipv4Address
   7.101 + */
   7.102 +  void AddHostRouteTo (Ipv4Address dest, 
   7.103 +                       Ipv4Address nextHop, 
   7.104 +                       uint32_t interface);
   7.105 +/**
   7.106 + * \brief Add a host route to the global routing table.
   7.107 + *
   7.108 + * \param dest The Ipv4Address destination for this route.
   7.109 + * \param interface The network interface index used to send packets to the
   7.110 + * destination.
   7.111 + *
   7.112 + * \see Ipv4Address
   7.113 + */
   7.114 +  void AddHostRouteTo (Ipv4Address dest, 
   7.115 +                       uint32_t interface);
   7.116 +
   7.117 +/**
   7.118 + * \brief Add a network route to the global routing table.
   7.119 + *
   7.120 + * \param network The Ipv4Address network for this route.
   7.121 + * \param networkMask The Ipv4Mask to extract the network.
   7.122 + * \param nextHop The next hop in the route to the destination network.
   7.123 + * \param interface The network interface index used to send packets to the
   7.124 + * destination.
   7.125 + *
   7.126 + * \see Ipv4Address
   7.127 + */
   7.128 +  void AddNetworkRouteTo (Ipv4Address network, 
   7.129 +                          Ipv4Mask networkMask, 
   7.130 +                          Ipv4Address nextHop, 
   7.131 +                          uint32_t interface);
   7.132 +
   7.133 +/**
   7.134 + * \brief Add a network route to the global routing table.
   7.135 + *
   7.136 + * \param network The Ipv4Address network for this route.
   7.137 + * \param networkMask The Ipv4Mask to extract the network.
   7.138 + * \param interface The network interface index used to send packets to the
   7.139 + * destination.
   7.140 + *
   7.141 + * \see Ipv4Address
   7.142 + */
   7.143 +  void AddNetworkRouteTo (Ipv4Address network, 
   7.144 +                          Ipv4Mask networkMask, 
   7.145 +                          uint32_t interface);
   7.146 +
   7.147 +/**
   7.148 + * \brief Get the number of individual unicast routes that have been added
   7.149 + * to the routing table.
   7.150 + *
   7.151 + * \warning The default route counts as one of the routes.
   7.152 + */
   7.153 +  uint32_t GetNRoutes (void);
   7.154 +
   7.155 +/**
   7.156 + * \brief Get a route from the global unicast routing table.
   7.157 + *
   7.158 + * Externally, the unicast global routing table appears simply as a table with
   7.159 + * n entries.  The one sublety of note is that if a default route has been set
   7.160 + * it will appear as the zeroth entry in the table.  This means that if you
   7.161 + * add only a default route, the table will have one entry that can be accessed
   7.162 + * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
   7.163 + * 
   7.164 + * Similarly, if the default route has been set, calling RemoveRoute (0) will
   7.165 + * remove the default route.
   7.166 + *
   7.167 + * \param i The index (into the routing table) of the route to retrieve.  If
   7.168 + * the default route has been set, it will occupy index zero.
   7.169 + * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
   7.170 + * a zero pointer is returned.
   7.171 + *
   7.172 + * \see Ipv4RoutingTableEntry
   7.173 + * \see Ipv4GlobalRouting::RemoveRoute
   7.174 + */
   7.175 +  Ipv4RoutingTableEntry *GetRoute (uint32_t i);
   7.176 +
   7.177 +/**
   7.178 + * \brief Remove a route from the global unicast routing table.
   7.179 + *
   7.180 + * Externally, the unicast global routing table appears simply as a table with
   7.181 + * n entries.  The one sublety of note is that if a default route has been set
   7.182 + * it will appear as the zeroth entry in the table.  This means that if the
   7.183 + * default route has been set, calling RemoveRoute (0) will remove the
   7.184 + * default route.
   7.185 + *
   7.186 + * \param i The index (into the routing table) of the route to remove.  If
   7.187 + * the default route has been set, it will occupy index zero.
   7.188 + *
   7.189 + * \see Ipv4RoutingTableEntry
   7.190 + * \see Ipv4GlobalRouting::GetRoute
   7.191 + * \see Ipv4GlobalRouting::AddRoute
   7.192 + */
   7.193 +  void RemoveRoute (uint32_t i);
   7.194 +
   7.195 +  void SetNode (Ptr<Node> node);
   7.196 +  Ptr<Node> GetNode (void) const;
   7.197 +
   7.198 +protected:
   7.199 +  void DoDispose (void);
   7.200 +
   7.201 +private:
   7.202 +  typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
   7.203 +  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
   7.204 +  typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
   7.205 +  typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
   7.206 +  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
   7.207 +  typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
   7.208 +
   7.209 +  Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
   7.210 +
   7.211 +  HostRoutes m_hostRoutes;
   7.212 +  NetworkRoutes m_networkRoutes;
   7.213 +
   7.214 +  Ptr<Node> m_node;
   7.215 +};
   7.216 +
   7.217 +} // Namespace ns3
   7.218 +
   7.219 +#endif /* IPV4_GLOBAL_ROUTING_H */
     8.1 --- a/src/routing/global-routing/wscript	Tue Jun 09 06:47:18 2009 -0700
     8.2 +++ b/src/routing/global-routing/wscript	Wed Jun 10 08:36:51 2009 +0200
     8.3 @@ -7,6 +7,7 @@
     8.4          'global-route-manager.cc',
     8.5          'global-route-manager-impl.cc',
     8.6          'candidate-queue.cc',
     8.7 +        'ipv4-global-routing.cc',
     8.8          ]
     8.9      headers = bld.new_task_gen('ns3header')
    8.10      headers.module = 'global-routing'