1.1 --- a/bindings/python/ns3_module_internet_stack.py Thu Jun 11 16:02:10 2009 +0100
1.2 +++ b/bindings/python/ns3_module_internet_stack.py Thu Jun 11 16:02:58 2009 +0100
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/devices/bridge/bridge-channel.cc Thu Jun 11 16:02:10 2009 +0100
2.2 +++ b/src/devices/bridge/bridge-channel.cc Thu Jun 11 16:02:58 2009 +0100
2.3 @@ -29,7 +29,9 @@
2.4 BridgeChannel::GetTypeId (void)
2.5 {
2.6 static TypeId tid = TypeId ("ns3::BridgeChannel")
2.7 - .SetParent<Channel> ();
2.8 + .SetParent<Channel> ()
2.9 + .AddConstructor<BridgeChannel> ()
2.10 + ;
2.11 return tid;
2.12 }
2.13
3.1 --- a/src/devices/wifi/wifi-net-device.cc Thu Jun 11 16:02:10 2009 +0100
3.2 +++ b/src/devices/wifi/wifi-net-device.cc Thu Jun 11 16:02:58 2009 +0100
3.3 @@ -38,6 +38,7 @@
3.4 {
3.5 static TypeId tid = TypeId ("ns3::WifiNetDevice")
3.6 .SetParent<NetDevice> ()
3.7 + .AddConstructor<WifiNetDevice> ()
3.8 .AddAttribute ("Channel", "The channel attached to this device",
3.9 PointerValue (),
3.10 MakePointerAccessor (&WifiNetDevice::DoGetChannel),
4.1 --- a/src/helper/nqos-wifi-mac-helper.h Thu Jun 11 16:02:10 2009 +0100
4.2 +++ b/src/helper/nqos-wifi-mac-helper.h Thu Jun 11 16:02:58 2009 +0100
4.3 @@ -31,6 +31,7 @@
4.4 virtual ~NqosWifiMacHelper ();
4.5 /**
4.6 * Create a mac helper in a default working state.
4.7 + * i.e., this is an adhoc mac by default.
4.8 */
4.9 static NqosWifiMacHelper Default (void);
4.10 /**
5.1 --- a/src/internet-stack/ipv4-global-routing.cc Thu Jun 11 16:02:10 2009 +0100
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,338 +0,0 @@
5.4 -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
5.5 -//
5.6 -// Copyright (c) 2008 University of Washington
5.7 -//
5.8 -// This program is free software; you can redistribute it and/or modify
5.9 -// it under the terms of the GNU General Public License version 2 as
5.10 -// published by the Free Software Foundation;
5.11 -//
5.12 -// This program is distributed in the hope that it will be useful,
5.13 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 -// GNU General Public License for more details.
5.16 -//
5.17 -// You should have received a copy of the GNU General Public License
5.18 -// along with this program; if not, write to the Free Software
5.19 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5.20 -//
5.21 -
5.22 -#include "ns3/log.h"
5.23 -#include "ns3/object.h"
5.24 -#include "ns3/packet.h"
5.25 -#include "ns3/node.h"
5.26 -#include "ns3/ipv4-route.h"
5.27 -#include "ns3/ipv4-routing-table-entry.h"
5.28 -#include "ipv4-global-routing.h"
5.29 -
5.30 -NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
5.31 -
5.32 -namespace ns3 {
5.33 -
5.34 -NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting);
5.35 -
5.36 -TypeId
5.37 -Ipv4GlobalRouting::GetTypeId (void)
5.38 -{
5.39 - static TypeId tid = TypeId ("ns3::Ipv4GlobalRouting")
5.40 - .SetParent<Object> ()
5.41 - ;
5.42 - return tid;
5.43 -}
5.44 -
5.45 -Ipv4GlobalRouting::Ipv4GlobalRouting ()
5.46 -{
5.47 - NS_LOG_FUNCTION_NOARGS ();
5.48 -}
5.49 -
5.50 -Ipv4GlobalRouting::~Ipv4GlobalRouting ()
5.51 -{
5.52 - NS_LOG_FUNCTION_NOARGS ();
5.53 -}
5.54 -
5.55 -void
5.56 -Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest,
5.57 - Ipv4Address nextHop,
5.58 - uint32_t interface)
5.59 -{
5.60 - NS_LOG_FUNCTION (dest << nextHop << interface);
5.61 - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
5.62 - *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, nextHop, interface);
5.63 - m_hostRoutes.push_back (route);
5.64 -}
5.65 -
5.66 -void
5.67 -Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest,
5.68 - uint32_t interface)
5.69 -{
5.70 - NS_LOG_FUNCTION (dest << interface);
5.71 - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
5.72 - *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, interface);
5.73 - m_hostRoutes.push_back (route);
5.74 -}
5.75 -
5.76 -void
5.77 -Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network,
5.78 - Ipv4Mask networkMask,
5.79 - Ipv4Address nextHop,
5.80 - uint32_t interface)
5.81 -{
5.82 - NS_LOG_FUNCTION (network << networkMask << nextHop << interface);
5.83 - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
5.84 - *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
5.85 - networkMask,
5.86 - nextHop,
5.87 - interface);
5.88 - m_networkRoutes.push_back (route);
5.89 -}
5.90 -
5.91 -void
5.92 -Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network,
5.93 - Ipv4Mask networkMask,
5.94 - uint32_t interface)
5.95 -{
5.96 - NS_LOG_FUNCTION (network << networkMask << interface);
5.97 - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
5.98 - *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
5.99 - networkMask,
5.100 - interface);
5.101 - m_networkRoutes.push_back (route);
5.102 -}
5.103 -
5.104 -Ptr<Ipv4Route>
5.105 -Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
5.106 -{
5.107 - NS_LOG_FUNCTION_NOARGS ();
5.108 - Ptr<Ipv4Route> rtentry = 0;
5.109 - bool found = false;
5.110 - Ipv4RoutingTableEntry* route = 0;
5.111 -
5.112 - for (HostRoutesCI i = m_hostRoutes.begin ();
5.113 - i != m_hostRoutes.end ();
5.114 - i++)
5.115 - {
5.116 - NS_ASSERT ((*i)->IsHost ());
5.117 - if ((*i)->GetDest ().IsEqual (dest))
5.118 - {
5.119 - NS_LOG_LOGIC ("Found global host route" << *i);
5.120 - route = (*i);
5.121 - found = true;
5.122 - break;
5.123 - }
5.124 - }
5.125 - if (found == false)
5.126 - {
5.127 - for (NetworkRoutesI j = m_networkRoutes.begin ();
5.128 - j != m_networkRoutes.end ();
5.129 - j++)
5.130 - {
5.131 - NS_ASSERT ((*j)->IsNetwork ());
5.132 - Ipv4Mask mask = (*j)->GetDestNetworkMask ();
5.133 - Ipv4Address entry = (*j)->GetDestNetwork ();
5.134 - if (mask.IsMatch (dest, entry))
5.135 - {
5.136 - NS_LOG_LOGIC ("Found global network route" << *j);
5.137 - route = (*j);
5.138 - found = true;
5.139 - break;
5.140 - }
5.141 - }
5.142 - }
5.143 - if (found == true)
5.144 - {
5.145 - Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
5.146 - rtentry = Create<Ipv4Route> ();
5.147 - rtentry->SetDestination (route->GetDest ());
5.148 - // XXX handle multi-address case
5.149 - rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ());
5.150 - rtentry->SetGateway (route->GetGateway ());
5.151 - uint32_t interfaceIdx = route->GetInterface ();
5.152 - rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx));
5.153 - return rtentry;
5.154 - }
5.155 - else
5.156 - {
5.157 - return 0;
5.158 - }
5.159 -}
5.160 -
5.161 -uint32_t
5.162 -Ipv4GlobalRouting::GetNRoutes (void)
5.163 -{
5.164 - NS_LOG_FUNCTION_NOARGS ();
5.165 - uint32_t n = 0;
5.166 - n += m_hostRoutes.size ();
5.167 - n += m_networkRoutes.size ();
5.168 - return n;
5.169 -}
5.170 -
5.171 -Ipv4RoutingTableEntry *
5.172 -Ipv4GlobalRouting::GetRoute (uint32_t index)
5.173 -{
5.174 - NS_LOG_FUNCTION (index);
5.175 - if (index < m_hostRoutes.size ())
5.176 - {
5.177 - uint32_t tmp = 0;
5.178 - for (HostRoutesCI i = m_hostRoutes.begin ();
5.179 - i != m_hostRoutes.end ();
5.180 - i++)
5.181 - {
5.182 - if (tmp == index)
5.183 - {
5.184 - return *i;
5.185 - }
5.186 - tmp++;
5.187 - }
5.188 - }
5.189 - index -= m_hostRoutes.size ();
5.190 - uint32_t tmp = 0;
5.191 - for (NetworkRoutesI j = m_networkRoutes.begin ();
5.192 - j != m_networkRoutes.end ();
5.193 - j++)
5.194 - {
5.195 - if (tmp == index)
5.196 - {
5.197 - return *j;
5.198 - }
5.199 - tmp++;
5.200 - }
5.201 - NS_ASSERT (false);
5.202 - // quiet compiler.
5.203 - return 0;
5.204 -}
5.205 -void
5.206 -Ipv4GlobalRouting::RemoveRoute (uint32_t index)
5.207 -{
5.208 - NS_LOG_FUNCTION (index);
5.209 - if (index < m_hostRoutes.size ())
5.210 - {
5.211 - uint32_t tmp = 0;
5.212 - for (HostRoutesI i = m_hostRoutes.begin ();
5.213 - i != m_hostRoutes.end ();
5.214 - i++)
5.215 - {
5.216 - if (tmp == index)
5.217 - {
5.218 - NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_hostRoutes.size());
5.219 - delete *i;
5.220 - m_hostRoutes.erase (i);
5.221 - NS_LOG_LOGIC ("Done removing host route " << index << "; host route remaining size = " << m_hostRoutes.size());
5.222 - return;
5.223 - }
5.224 - tmp++;
5.225 - }
5.226 - }
5.227 - index -= m_hostRoutes.size ();
5.228 - uint32_t tmp = 0;
5.229 - for (NetworkRoutesI j = m_networkRoutes.begin ();
5.230 - j != m_networkRoutes.end ();
5.231 - j++)
5.232 - {
5.233 - if (tmp == index)
5.234 - {
5.235 - NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_networkRoutes.size());
5.236 - delete *j;
5.237 - m_networkRoutes.erase (j);
5.238 - NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
5.239 - return;
5.240 - }
5.241 - tmp++;
5.242 - }
5.243 - NS_ASSERT (false);
5.244 -}
5.245 -
5.246 -void
5.247 -Ipv4GlobalRouting::DoDispose (void)
5.248 -{
5.249 - NS_LOG_FUNCTION_NOARGS ();
5.250 - for (HostRoutesI i = m_hostRoutes.begin ();
5.251 - i != m_hostRoutes.end ();
5.252 - i = m_hostRoutes.erase (i))
5.253 - {
5.254 - delete (*i);
5.255 - }
5.256 - for (NetworkRoutesI j = m_networkRoutes.begin ();
5.257 - j != m_networkRoutes.end ();
5.258 - j = m_networkRoutes.erase (j))
5.259 - {
5.260 - delete (*j);
5.261 - }
5.262 - Ipv4RoutingProtocol::DoDispose ();
5.263 -}
5.264 -
5.265 -Ptr<Ipv4Route>
5.266 -Ipv4GlobalRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
5.267 -{
5.268 -
5.269 -//
5.270 -// First, see if this is a multicast packet we have a route for. If we
5.271 -// have a route, then send the packet down each of the specified interfaces.
5.272 -//
5.273 - if (header.GetDestination().IsMulticast ())
5.274 - {
5.275 - NS_LOG_LOGIC ("Multicast destination-- returning false");
5.276 - return 0; // Let other routing protocols try to handle this
5.277 - }
5.278 -//
5.279 -// See if this is a unicast packet we have a route for.
5.280 -//
5.281 - NS_LOG_LOGIC ("Unicast destination- looking up");
5.282 - Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination());
5.283 - if (rtentry)
5.284 - {
5.285 - sockerr = Socket::ERROR_NOTERROR;
5.286 - }
5.287 - else
5.288 - {
5.289 - sockerr = Socket::ERROR_NOROUTETOHOST;
5.290 - }
5.291 - return rtentry;
5.292 -}
5.293 -
5.294 -bool
5.295 -Ipv4GlobalRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &ipHeader, Ptr<const NetDevice> idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb,
5.296 - LocalDeliverCallback lcb, ErrorCallback ecb)
5.297 -{
5.298 -
5.299 - NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev);
5.300 -
5.301 - if (ipHeader.GetDestination ().IsMulticast ())
5.302 - {
5.303 - NS_LOG_LOGIC ("Multicast destination-- returning false");
5.304 - return false; // Let other routing protocols try to handle this
5.305 - }
5.306 -
5.307 -// This is a unicast packet. Check to see if we have a route for it.
5.308 -//
5.309 - NS_LOG_LOGIC ("Unicast destination- looking up");
5.310 - Ptr<Ipv4Route> rtentry = LookupGlobal (ipHeader.GetDestination ());
5.311 - if (rtentry != 0)
5.312 - {
5.313 - NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
5.314 - ucb (rtentry, p, ipHeader);
5.315 - return true;
5.316 - }
5.317 - else
5.318 - {
5.319 - NS_LOG_LOGIC ("Did not find unicast destination- returning false");
5.320 - return false; // Let other routing protocols try to handle this
5.321 - // route request.
5.322 - }
5.323 -}
5.324 -
5.325 -void
5.326 -Ipv4GlobalRouting::SetNode (Ptr<Node> node)
5.327 -{
5.328 - NS_LOG_FUNCTION_NOARGS ();
5.329 - m_node = node;
5.330 -}
5.331 -
5.332 -Ptr<Node>
5.333 -Ipv4GlobalRouting::GetNode (void) const
5.334 -{
5.335 - NS_LOG_FUNCTION_NOARGS ();
5.336 - return m_node;
5.337 -}
5.338 -
5.339 -
5.340 -
5.341 -}//namespace ns3
6.1 --- a/src/internet-stack/ipv4-global-routing.h Thu Jun 11 16:02:10 2009 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,216 +0,0 @@
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 -
6.23 -#ifndef IPV4_GLOBAL_ROUTING_H
6.24 -#define IPV4_GLOBAL_ROUTING_H
6.25 -
6.26 -#include <list>
6.27 -#include <stdint.h>
6.28 -#include "ns3/ipv4-address.h"
6.29 -#include "ns3/ipv4-header.h"
6.30 -#include "ns3/ptr.h"
6.31 -#include "ns3/ipv4.h"
6.32 -#include "ns3/ipv4-routing-protocol.h"
6.33 -
6.34 -namespace ns3 {
6.35 -
6.36 -class Packet;
6.37 -class NetDevice;
6.38 -class Ipv4Interface;
6.39 -class Ipv4Address;
6.40 -class Ipv4Header;
6.41 -class Ipv4RoutingTableEntry;
6.42 -class Ipv4MulticastRoutingTableEntry;
6.43 -class Node;
6.44 -
6.45 -
6.46 -/**
6.47 - * \brief Global routing protocol for IP version 4 stacks.
6.48 - *
6.49 - * In ns-3 we have the concept of a pluggable routing protocol. Routing
6.50 - * protocols are added to a list maintained by the Ipv4L3Protocol. Every
6.51 - * stack gets one routing protocol for free -- the Ipv4StaticRouting routing
6.52 - * protocol is added in the constructor of the Ipv4L3Protocol (this is the
6.53 - * piece of code that implements the functionality of the IP layer).
6.54 - *
6.55 - * As an option to running a dynamic routing protocol, a GlobalRouteManager
6.56 - * object has been created to allow users to build routes for all participating
6.57 - * nodes. One can think of this object as a "routing oracle"; it has
6.58 - * an omniscient view of the topology, and can construct shortest path
6.59 - * routes between all pairs of nodes. These routes must be stored
6.60 - * somewhere in the node, so therefore this class Ipv4GlobalRouting
6.61 - * is used as one of the pluggable routing protocols. It is kept distinct
6.62 - * from Ipv4StaticRouting because these routes may be dynamically cleared
6.63 - * and rebuilt in the middle of the simulation, while manually entered
6.64 - * routes into the Ipv4StaticRouting may need to be kept distinct.
6.65 - *
6.66 - * This class deals with Ipv4 unicast routes only.
6.67 - *
6.68 - * \see Ipv4RoutingProtocol
6.69 - * \see GlobalRouteManager
6.70 - */
6.71 -class Ipv4GlobalRouting : public Ipv4RoutingProtocol
6.72 -{
6.73 -public:
6.74 - static TypeId GetTypeId (void);
6.75 -/**
6.76 - * \brief Construct an empty Ipv4GlobalRouting routing protocol,
6.77 - *
6.78 - * The Ipv4GlobalRouting class supports host and network unicast routes.
6.79 - * This method initializes the lists containing these routes to empty.
6.80 - *
6.81 - * \see Ipv4GlobalRouting
6.82 - */
6.83 - Ipv4GlobalRouting ();
6.84 - virtual ~Ipv4GlobalRouting ();
6.85 -
6.86 - virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
6.87 -
6.88 - virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
6.89 - UnicastForwardCallback ucb, MulticastForwardCallback mcb,
6.90 - LocalDeliverCallback lcb, ErrorCallback ecb);
6.91 -
6.92 -/**
6.93 - * \brief Add a host route to the global routing table.
6.94 - *
6.95 - * \param dest The Ipv4Address destination for this route.
6.96 - * \param nextHop The Ipv4Address of the next hop in the route.
6.97 - * \param interface The network interface index used to send packets to the
6.98 - * destination.
6.99 - *
6.100 - * \see Ipv4Address
6.101 - */
6.102 - void AddHostRouteTo (Ipv4Address dest,
6.103 - Ipv4Address nextHop,
6.104 - uint32_t interface);
6.105 -/**
6.106 - * \brief Add a host route to the global routing table.
6.107 - *
6.108 - * \param dest The Ipv4Address destination for this route.
6.109 - * \param interface The network interface index used to send packets to the
6.110 - * destination.
6.111 - *
6.112 - * \see Ipv4Address
6.113 - */
6.114 - void AddHostRouteTo (Ipv4Address dest,
6.115 - uint32_t interface);
6.116 -
6.117 -/**
6.118 - * \brief Add a network route to the global routing table.
6.119 - *
6.120 - * \param network The Ipv4Address network for this route.
6.121 - * \param networkMask The Ipv4Mask to extract the network.
6.122 - * \param nextHop The next hop in the route to the destination network.
6.123 - * \param interface The network interface index used to send packets to the
6.124 - * destination.
6.125 - *
6.126 - * \see Ipv4Address
6.127 - */
6.128 - void AddNetworkRouteTo (Ipv4Address network,
6.129 - Ipv4Mask networkMask,
6.130 - Ipv4Address nextHop,
6.131 - uint32_t interface);
6.132 -
6.133 -/**
6.134 - * \brief Add a network route to the global routing table.
6.135 - *
6.136 - * \param network The Ipv4Address network for this route.
6.137 - * \param networkMask The Ipv4Mask to extract the network.
6.138 - * \param interface The network interface index used to send packets to the
6.139 - * destination.
6.140 - *
6.141 - * \see Ipv4Address
6.142 - */
6.143 - void AddNetworkRouteTo (Ipv4Address network,
6.144 - Ipv4Mask networkMask,
6.145 - uint32_t interface);
6.146 -
6.147 -/**
6.148 - * \brief Get the number of individual unicast routes that have been added
6.149 - * to the routing table.
6.150 - *
6.151 - * \warning The default route counts as one of the routes.
6.152 - */
6.153 - uint32_t GetNRoutes (void);
6.154 -
6.155 -/**
6.156 - * \brief Get a route from the global unicast routing table.
6.157 - *
6.158 - * Externally, the unicast global routing table appears simply as a table with
6.159 - * n entries. The one sublety of note is that if a default route has been set
6.160 - * it will appear as the zeroth entry in the table. This means that if you
6.161 - * add only a default route, the table will have one entry that can be accessed
6.162 - * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
6.163 - *
6.164 - * Similarly, if the default route has been set, calling RemoveRoute (0) will
6.165 - * remove the default route.
6.166 - *
6.167 - * \param i The index (into the routing table) of the route to retrieve. If
6.168 - * the default route has been set, it will occupy index zero.
6.169 - * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
6.170 - * a zero pointer is returned.
6.171 - *
6.172 - * \see Ipv4RoutingTableEntry
6.173 - * \see Ipv4GlobalRouting::RemoveRoute
6.174 - */
6.175 - Ipv4RoutingTableEntry *GetRoute (uint32_t i);
6.176 -
6.177 -/**
6.178 - * \brief Remove a route from the global unicast routing table.
6.179 - *
6.180 - * Externally, the unicast global routing table appears simply as a table with
6.181 - * n entries. The one sublety of note is that if a default route has been set
6.182 - * it will appear as the zeroth entry in the table. This means that if the
6.183 - * default route has been set, calling RemoveRoute (0) will remove the
6.184 - * default route.
6.185 - *
6.186 - * \param i The index (into the routing table) of the route to remove. If
6.187 - * the default route has been set, it will occupy index zero.
6.188 - *
6.189 - * \see Ipv4RoutingTableEntry
6.190 - * \see Ipv4GlobalRouting::GetRoute
6.191 - * \see Ipv4GlobalRouting::AddRoute
6.192 - */
6.193 - void RemoveRoute (uint32_t i);
6.194 -
6.195 - void SetNode (Ptr<Node> node);
6.196 - Ptr<Node> GetNode (void) const;
6.197 -
6.198 -protected:
6.199 - void DoDispose (void);
6.200 -
6.201 -private:
6.202 - typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
6.203 - typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
6.204 - typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
6.205 - typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
6.206 - typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
6.207 - typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
6.208 -
6.209 - Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
6.210 -
6.211 - HostRoutes m_hostRoutes;
6.212 - NetworkRoutes m_networkRoutes;
6.213 -
6.214 - Ptr<Node> m_node;
6.215 -};
6.216 -
6.217 -} // Namespace ns3
6.218 -
6.219 -#endif /* IPV4_GLOBAL_ROUTING_H */
7.1 --- a/src/internet-stack/ipv4-list-routing-impl.cc Thu Jun 11 16:02:10 2009 +0100
7.2 +++ b/src/internet-stack/ipv4-list-routing-impl.cc Thu Jun 11 16:02:58 2009 +0100
7.3 @@ -35,6 +35,7 @@
7.4 {
7.5 static TypeId tid = TypeId ("ns3::Ipv4ListRoutingImpl")
7.6 .SetParent<Ipv4ListRouting> ()
7.7 + .AddConstructor<Ipv4ListRoutingImpl> ()
7.8 ;
7.9 return tid;
7.10 }
8.1 --- a/src/internet-stack/ipv4-static-routing-impl.cc Thu Jun 11 16:02:10 2009 +0100
8.2 +++ b/src/internet-stack/ipv4-static-routing-impl.cc Thu Jun 11 16:02:58 2009 +0100
8.3 @@ -36,6 +36,7 @@
8.4 {
8.5 static TypeId tid = TypeId ("ns3::Ipv4StaticRoutingImpl")
8.6 .SetParent<Ipv4StaticRouting> ()
8.7 + .AddConstructor<Ipv4StaticRoutingImpl> ()
8.8 ;
8.9 return tid;
8.10 }
9.1 --- a/src/internet-stack/wscript Thu Jun 11 16:02:10 2009 +0100
9.2 +++ b/src/internet-stack/wscript Thu Jun 11 16:02:58 2009 +0100
9.3 @@ -82,7 +82,6 @@
9.4 'ipv4-l3-protocol.cc',
9.5 'ipv4-static-routing-impl.cc',
9.6 'ipv4-list-routing-impl.cc',
9.7 - 'ipv4-global-routing.cc',
9.8 'ipv4-end-point.cc',
9.9 'udp-l4-protocol.cc',
9.10 'tcp-l4-protocol.cc',
9.11 @@ -110,7 +109,6 @@
9.12 'udp-header.h',
9.13 'tcp-header.h',
9.14 'sequence-number.h',
9.15 - 'ipv4-global-routing.h',
9.16 'ipv4-list-routing-impl.h',
9.17 'ipv4-static-routing-impl.h',
9.18 'icmpv4.h',
10.1 --- a/src/routing/global-routing/global-route-manager-impl.cc Thu Jun 11 16:02:10 2009 +0100
10.2 +++ b/src/routing/global-routing/global-route-manager-impl.cc Thu Jun 11 16:02:58 2009 +0100
10.3 @@ -30,12 +30,12 @@
10.4 #include "ns3/log.h"
10.5 #include "ns3/node-list.h"
10.6 #include "ns3/ipv4.h"
10.7 -#include "ns3/ipv4-global-routing.h"
10.8 #include "ns3/ipv4-routing-protocol.h"
10.9 #include "ns3/ipv4-list-routing.h"
10.10 #include "global-router-interface.h"
10.11 #include "global-route-manager-impl.h"
10.12 #include "candidate-queue.h"
10.13 +#include "ipv4-global-routing.h"
10.14
10.15 NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");
10.16
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/routing/global-routing/ipv4-global-routing.cc Thu Jun 11 16:02:58 2009 +0100
11.3 @@ -0,0 +1,338 @@
11.4 +// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
11.5 +//
11.6 +// Copyright (c) 2008 University of Washington
11.7 +//
11.8 +// This program is free software; you can redistribute it and/or modify
11.9 +// it under the terms of the GNU General Public License version 2 as
11.10 +// published by the Free Software Foundation;
11.11 +//
11.12 +// This program is distributed in the hope that it will be useful,
11.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 +// GNU General Public License for more details.
11.16 +//
11.17 +// You should have received a copy of the GNU General Public License
11.18 +// along with this program; if not, write to the Free Software
11.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11.20 +//
11.21 +
11.22 +#include "ns3/log.h"
11.23 +#include "ns3/object.h"
11.24 +#include "ns3/packet.h"
11.25 +#include "ns3/node.h"
11.26 +#include "ns3/ipv4-route.h"
11.27 +#include "ns3/ipv4-routing-table-entry.h"
11.28 +#include "ipv4-global-routing.h"
11.29 +
11.30 +NS_LOG_COMPONENT_DEFINE ("Ipv4GlobalRouting");
11.31 +
11.32 +namespace ns3 {
11.33 +
11.34 +NS_OBJECT_ENSURE_REGISTERED (Ipv4GlobalRouting);
11.35 +
11.36 +TypeId
11.37 +Ipv4GlobalRouting::GetTypeId (void)
11.38 +{
11.39 + static TypeId tid = TypeId ("ns3::Ipv4GlobalRouting")
11.40 + .SetParent<Object> ()
11.41 + ;
11.42 + return tid;
11.43 +}
11.44 +
11.45 +Ipv4GlobalRouting::Ipv4GlobalRouting ()
11.46 +{
11.47 + NS_LOG_FUNCTION_NOARGS ();
11.48 +}
11.49 +
11.50 +Ipv4GlobalRouting::~Ipv4GlobalRouting ()
11.51 +{
11.52 + NS_LOG_FUNCTION_NOARGS ();
11.53 +}
11.54 +
11.55 +void
11.56 +Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest,
11.57 + Ipv4Address nextHop,
11.58 + uint32_t interface)
11.59 +{
11.60 + NS_LOG_FUNCTION (dest << nextHop << interface);
11.61 + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
11.62 + *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, nextHop, interface);
11.63 + m_hostRoutes.push_back (route);
11.64 +}
11.65 +
11.66 +void
11.67 +Ipv4GlobalRouting::AddHostRouteTo (Ipv4Address dest,
11.68 + uint32_t interface)
11.69 +{
11.70 + NS_LOG_FUNCTION (dest << interface);
11.71 + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
11.72 + *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, interface);
11.73 + m_hostRoutes.push_back (route);
11.74 +}
11.75 +
11.76 +void
11.77 +Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network,
11.78 + Ipv4Mask networkMask,
11.79 + Ipv4Address nextHop,
11.80 + uint32_t interface)
11.81 +{
11.82 + NS_LOG_FUNCTION (network << networkMask << nextHop << interface);
11.83 + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
11.84 + *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
11.85 + networkMask,
11.86 + nextHop,
11.87 + interface);
11.88 + m_networkRoutes.push_back (route);
11.89 +}
11.90 +
11.91 +void
11.92 +Ipv4GlobalRouting::AddNetworkRouteTo (Ipv4Address network,
11.93 + Ipv4Mask networkMask,
11.94 + uint32_t interface)
11.95 +{
11.96 + NS_LOG_FUNCTION (network << networkMask << interface);
11.97 + Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
11.98 + *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
11.99 + networkMask,
11.100 + interface);
11.101 + m_networkRoutes.push_back (route);
11.102 +}
11.103 +
11.104 +Ptr<Ipv4Route>
11.105 +Ipv4GlobalRouting::LookupGlobal (Ipv4Address dest)
11.106 +{
11.107 + NS_LOG_FUNCTION_NOARGS ();
11.108 + Ptr<Ipv4Route> rtentry = 0;
11.109 + bool found = false;
11.110 + Ipv4RoutingTableEntry* route = 0;
11.111 +
11.112 + for (HostRoutesCI i = m_hostRoutes.begin ();
11.113 + i != m_hostRoutes.end ();
11.114 + i++)
11.115 + {
11.116 + NS_ASSERT ((*i)->IsHost ());
11.117 + if ((*i)->GetDest ().IsEqual (dest))
11.118 + {
11.119 + NS_LOG_LOGIC ("Found global host route" << *i);
11.120 + route = (*i);
11.121 + found = true;
11.122 + break;
11.123 + }
11.124 + }
11.125 + if (found == false)
11.126 + {
11.127 + for (NetworkRoutesI j = m_networkRoutes.begin ();
11.128 + j != m_networkRoutes.end ();
11.129 + j++)
11.130 + {
11.131 + NS_ASSERT ((*j)->IsNetwork ());
11.132 + Ipv4Mask mask = (*j)->GetDestNetworkMask ();
11.133 + Ipv4Address entry = (*j)->GetDestNetwork ();
11.134 + if (mask.IsMatch (dest, entry))
11.135 + {
11.136 + NS_LOG_LOGIC ("Found global network route" << *j);
11.137 + route = (*j);
11.138 + found = true;
11.139 + break;
11.140 + }
11.141 + }
11.142 + }
11.143 + if (found == true)
11.144 + {
11.145 + Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
11.146 + rtentry = Create<Ipv4Route> ();
11.147 + rtentry->SetDestination (route->GetDest ());
11.148 + // XXX handle multi-address case
11.149 + rtentry->SetSource (ipv4->GetAddress (route->GetInterface(), 0).GetLocal ());
11.150 + rtentry->SetGateway (route->GetGateway ());
11.151 + uint32_t interfaceIdx = route->GetInterface ();
11.152 + rtentry->SetOutputDevice (ipv4->GetNetDevice (interfaceIdx));
11.153 + return rtentry;
11.154 + }
11.155 + else
11.156 + {
11.157 + return 0;
11.158 + }
11.159 +}
11.160 +
11.161 +uint32_t
11.162 +Ipv4GlobalRouting::GetNRoutes (void)
11.163 +{
11.164 + NS_LOG_FUNCTION_NOARGS ();
11.165 + uint32_t n = 0;
11.166 + n += m_hostRoutes.size ();
11.167 + n += m_networkRoutes.size ();
11.168 + return n;
11.169 +}
11.170 +
11.171 +Ipv4RoutingTableEntry *
11.172 +Ipv4GlobalRouting::GetRoute (uint32_t index)
11.173 +{
11.174 + NS_LOG_FUNCTION (index);
11.175 + if (index < m_hostRoutes.size ())
11.176 + {
11.177 + uint32_t tmp = 0;
11.178 + for (HostRoutesCI i = m_hostRoutes.begin ();
11.179 + i != m_hostRoutes.end ();
11.180 + i++)
11.181 + {
11.182 + if (tmp == index)
11.183 + {
11.184 + return *i;
11.185 + }
11.186 + tmp++;
11.187 + }
11.188 + }
11.189 + index -= m_hostRoutes.size ();
11.190 + uint32_t tmp = 0;
11.191 + for (NetworkRoutesI j = m_networkRoutes.begin ();
11.192 + j != m_networkRoutes.end ();
11.193 + j++)
11.194 + {
11.195 + if (tmp == index)
11.196 + {
11.197 + return *j;
11.198 + }
11.199 + tmp++;
11.200 + }
11.201 + NS_ASSERT (false);
11.202 + // quiet compiler.
11.203 + return 0;
11.204 +}
11.205 +void
11.206 +Ipv4GlobalRouting::RemoveRoute (uint32_t index)
11.207 +{
11.208 + NS_LOG_FUNCTION (index);
11.209 + if (index < m_hostRoutes.size ())
11.210 + {
11.211 + uint32_t tmp = 0;
11.212 + for (HostRoutesI i = m_hostRoutes.begin ();
11.213 + i != m_hostRoutes.end ();
11.214 + i++)
11.215 + {
11.216 + if (tmp == index)
11.217 + {
11.218 + NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_hostRoutes.size());
11.219 + delete *i;
11.220 + m_hostRoutes.erase (i);
11.221 + NS_LOG_LOGIC ("Done removing host route " << index << "; host route remaining size = " << m_hostRoutes.size());
11.222 + return;
11.223 + }
11.224 + tmp++;
11.225 + }
11.226 + }
11.227 + index -= m_hostRoutes.size ();
11.228 + uint32_t tmp = 0;
11.229 + for (NetworkRoutesI j = m_networkRoutes.begin ();
11.230 + j != m_networkRoutes.end ();
11.231 + j++)
11.232 + {
11.233 + if (tmp == index)
11.234 + {
11.235 + NS_LOG_LOGIC ("Removing route " << index << "; size = " << m_networkRoutes.size());
11.236 + delete *j;
11.237 + m_networkRoutes.erase (j);
11.238 + NS_LOG_LOGIC ("Done removing network route " << index << "; network route remaining size = " << m_networkRoutes.size());
11.239 + return;
11.240 + }
11.241 + tmp++;
11.242 + }
11.243 + NS_ASSERT (false);
11.244 +}
11.245 +
11.246 +void
11.247 +Ipv4GlobalRouting::DoDispose (void)
11.248 +{
11.249 + NS_LOG_FUNCTION_NOARGS ();
11.250 + for (HostRoutesI i = m_hostRoutes.begin ();
11.251 + i != m_hostRoutes.end ();
11.252 + i = m_hostRoutes.erase (i))
11.253 + {
11.254 + delete (*i);
11.255 + }
11.256 + for (NetworkRoutesI j = m_networkRoutes.begin ();
11.257 + j != m_networkRoutes.end ();
11.258 + j = m_networkRoutes.erase (j))
11.259 + {
11.260 + delete (*j);
11.261 + }
11.262 + Ipv4RoutingProtocol::DoDispose ();
11.263 +}
11.264 +
11.265 +Ptr<Ipv4Route>
11.266 +Ipv4GlobalRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
11.267 +{
11.268 +
11.269 +//
11.270 +// First, see if this is a multicast packet we have a route for. If we
11.271 +// have a route, then send the packet down each of the specified interfaces.
11.272 +//
11.273 + if (header.GetDestination().IsMulticast ())
11.274 + {
11.275 + NS_LOG_LOGIC ("Multicast destination-- returning false");
11.276 + return 0; // Let other routing protocols try to handle this
11.277 + }
11.278 +//
11.279 +// See if this is a unicast packet we have a route for.
11.280 +//
11.281 + NS_LOG_LOGIC ("Unicast destination- looking up");
11.282 + Ptr<Ipv4Route> rtentry = LookupGlobal (header.GetDestination());
11.283 + if (rtentry)
11.284 + {
11.285 + sockerr = Socket::ERROR_NOTERROR;
11.286 + }
11.287 + else
11.288 + {
11.289 + sockerr = Socket::ERROR_NOROUTETOHOST;
11.290 + }
11.291 + return rtentry;
11.292 +}
11.293 +
11.294 +bool
11.295 +Ipv4GlobalRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &ipHeader, Ptr<const NetDevice> idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb,
11.296 + LocalDeliverCallback lcb, ErrorCallback ecb)
11.297 +{
11.298 +
11.299 + NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev);
11.300 +
11.301 + if (ipHeader.GetDestination ().IsMulticast ())
11.302 + {
11.303 + NS_LOG_LOGIC ("Multicast destination-- returning false");
11.304 + return false; // Let other routing protocols try to handle this
11.305 + }
11.306 +
11.307 +// This is a unicast packet. Check to see if we have a route for it.
11.308 +//
11.309 + NS_LOG_LOGIC ("Unicast destination- looking up");
11.310 + Ptr<Ipv4Route> rtentry = LookupGlobal (ipHeader.GetDestination ());
11.311 + if (rtentry != 0)
11.312 + {
11.313 + NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
11.314 + ucb (rtentry, p, ipHeader);
11.315 + return true;
11.316 + }
11.317 + else
11.318 + {
11.319 + NS_LOG_LOGIC ("Did not find unicast destination- returning false");
11.320 + return false; // Let other routing protocols try to handle this
11.321 + // route request.
11.322 + }
11.323 +}
11.324 +
11.325 +void
11.326 +Ipv4GlobalRouting::SetNode (Ptr<Node> node)
11.327 +{
11.328 + NS_LOG_FUNCTION_NOARGS ();
11.329 + m_node = node;
11.330 +}
11.331 +
11.332 +Ptr<Node>
11.333 +Ipv4GlobalRouting::GetNode (void) const
11.334 +{
11.335 + NS_LOG_FUNCTION_NOARGS ();
11.336 + return m_node;
11.337 +}
11.338 +
11.339 +
11.340 +
11.341 +}//namespace ns3
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/src/routing/global-routing/ipv4-global-routing.h Thu Jun 11 16:02:58 2009 +0100
12.3 @@ -0,0 +1,216 @@
12.4 +// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
12.5 +//
12.6 +// Copyright (c) 2008 University of Washington
12.7 +//
12.8 +// This program is free software; you can redistribute it and/or modify
12.9 +// it under the terms of the GNU General Public License version 2 as
12.10 +// published by the Free Software Foundation;
12.11 +//
12.12 +// This program is distributed in the hope that it will be useful,
12.13 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
12.14 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12.15 +// GNU General Public License for more details.
12.16 +//
12.17 +// You should have received a copy of the GNU General Public License
12.18 +// along with this program; if not, write to the Free Software
12.19 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12.20 +//
12.21 +//
12.22 +
12.23 +#ifndef IPV4_GLOBAL_ROUTING_H
12.24 +#define IPV4_GLOBAL_ROUTING_H
12.25 +
12.26 +#include <list>
12.27 +#include <stdint.h>
12.28 +#include "ns3/ipv4-address.h"
12.29 +#include "ns3/ipv4-header.h"
12.30 +#include "ns3/ptr.h"
12.31 +#include "ns3/ipv4.h"
12.32 +#include "ns3/ipv4-routing-protocol.h"
12.33 +
12.34 +namespace ns3 {
12.35 +
12.36 +class Packet;
12.37 +class NetDevice;
12.38 +class Ipv4Interface;
12.39 +class Ipv4Address;
12.40 +class Ipv4Header;
12.41 +class Ipv4RoutingTableEntry;
12.42 +class Ipv4MulticastRoutingTableEntry;
12.43 +class Node;
12.44 +
12.45 +
12.46 +/**
12.47 + * \brief Global routing protocol for IP version 4 stacks.
12.48 + *
12.49 + * In ns-3 we have the concept of a pluggable routing protocol. Routing
12.50 + * protocols are added to a list maintained by the Ipv4L3Protocol. Every
12.51 + * stack gets one routing protocol for free -- the Ipv4StaticRouting routing
12.52 + * protocol is added in the constructor of the Ipv4L3Protocol (this is the
12.53 + * piece of code that implements the functionality of the IP layer).
12.54 + *
12.55 + * As an option to running a dynamic routing protocol, a GlobalRouteManager
12.56 + * object has been created to allow users to build routes for all participating
12.57 + * nodes. One can think of this object as a "routing oracle"; it has
12.58 + * an omniscient view of the topology, and can construct shortest path
12.59 + * routes between all pairs of nodes. These routes must be stored
12.60 + * somewhere in the node, so therefore this class Ipv4GlobalRouting
12.61 + * is used as one of the pluggable routing protocols. It is kept distinct
12.62 + * from Ipv4StaticRouting because these routes may be dynamically cleared
12.63 + * and rebuilt in the middle of the simulation, while manually entered
12.64 + * routes into the Ipv4StaticRouting may need to be kept distinct.
12.65 + *
12.66 + * This class deals with Ipv4 unicast routes only.
12.67 + *
12.68 + * \see Ipv4RoutingProtocol
12.69 + * \see GlobalRouteManager
12.70 + */
12.71 +class Ipv4GlobalRouting : public Ipv4RoutingProtocol
12.72 +{
12.73 +public:
12.74 + static TypeId GetTypeId (void);
12.75 +/**
12.76 + * \brief Construct an empty Ipv4GlobalRouting routing protocol,
12.77 + *
12.78 + * The Ipv4GlobalRouting class supports host and network unicast routes.
12.79 + * This method initializes the lists containing these routes to empty.
12.80 + *
12.81 + * \see Ipv4GlobalRouting
12.82 + */
12.83 + Ipv4GlobalRouting ();
12.84 + virtual ~Ipv4GlobalRouting ();
12.85 +
12.86 + virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
12.87 +
12.88 + virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
12.89 + UnicastForwardCallback ucb, MulticastForwardCallback mcb,
12.90 + LocalDeliverCallback lcb, ErrorCallback ecb);
12.91 +
12.92 +/**
12.93 + * \brief Add a host route to the global routing table.
12.94 + *
12.95 + * \param dest The Ipv4Address destination for this route.
12.96 + * \param nextHop The Ipv4Address of the next hop in the route.
12.97 + * \param interface The network interface index used to send packets to the
12.98 + * destination.
12.99 + *
12.100 + * \see Ipv4Address
12.101 + */
12.102 + void AddHostRouteTo (Ipv4Address dest,
12.103 + Ipv4Address nextHop,
12.104 + uint32_t interface);
12.105 +/**
12.106 + * \brief Add a host route to the global routing table.
12.107 + *
12.108 + * \param dest The Ipv4Address destination for this route.
12.109 + * \param interface The network interface index used to send packets to the
12.110 + * destination.
12.111 + *
12.112 + * \see Ipv4Address
12.113 + */
12.114 + void AddHostRouteTo (Ipv4Address dest,
12.115 + uint32_t interface);
12.116 +
12.117 +/**
12.118 + * \brief Add a network route to the global routing table.
12.119 + *
12.120 + * \param network The Ipv4Address network for this route.
12.121 + * \param networkMask The Ipv4Mask to extract the network.
12.122 + * \param nextHop The next hop in the route to the destination network.
12.123 + * \param interface The network interface index used to send packets to the
12.124 + * destination.
12.125 + *
12.126 + * \see Ipv4Address
12.127 + */
12.128 + void AddNetworkRouteTo (Ipv4Address network,
12.129 + Ipv4Mask networkMask,
12.130 + Ipv4Address nextHop,
12.131 + uint32_t interface);
12.132 +
12.133 +/**
12.134 + * \brief Add a network route to the global routing table.
12.135 + *
12.136 + * \param network The Ipv4Address network for this route.
12.137 + * \param networkMask The Ipv4Mask to extract the network.
12.138 + * \param interface The network interface index used to send packets to the
12.139 + * destination.
12.140 + *
12.141 + * \see Ipv4Address
12.142 + */
12.143 + void AddNetworkRouteTo (Ipv4Address network,
12.144 + Ipv4Mask networkMask,
12.145 + uint32_t interface);
12.146 +
12.147 +/**
12.148 + * \brief Get the number of individual unicast routes that have been added
12.149 + * to the routing table.
12.150 + *
12.151 + * \warning The default route counts as one of the routes.
12.152 + */
12.153 + uint32_t GetNRoutes (void);
12.154 +
12.155 +/**
12.156 + * \brief Get a route from the global unicast routing table.
12.157 + *
12.158 + * Externally, the unicast global routing table appears simply as a table with
12.159 + * n entries. The one sublety of note is that if a default route has been set
12.160 + * it will appear as the zeroth entry in the table. This means that if you
12.161 + * add only a default route, the table will have one entry that can be accessed
12.162 + * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
12.163 + *
12.164 + * Similarly, if the default route has been set, calling RemoveRoute (0) will
12.165 + * remove the default route.
12.166 + *
12.167 + * \param i The index (into the routing table) of the route to retrieve. If
12.168 + * the default route has been set, it will occupy index zero.
12.169 + * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
12.170 + * a zero pointer is returned.
12.171 + *
12.172 + * \see Ipv4RoutingTableEntry
12.173 + * \see Ipv4GlobalRouting::RemoveRoute
12.174 + */
12.175 + Ipv4RoutingTableEntry *GetRoute (uint32_t i);
12.176 +
12.177 +/**
12.178 + * \brief Remove a route from the global unicast routing table.
12.179 + *
12.180 + * Externally, the unicast global routing table appears simply as a table with
12.181 + * n entries. The one sublety of note is that if a default route has been set
12.182 + * it will appear as the zeroth entry in the table. This means that if the
12.183 + * default route has been set, calling RemoveRoute (0) will remove the
12.184 + * default route.
12.185 + *
12.186 + * \param i The index (into the routing table) of the route to remove. If
12.187 + * the default route has been set, it will occupy index zero.
12.188 + *
12.189 + * \see Ipv4RoutingTableEntry
12.190 + * \see Ipv4GlobalRouting::GetRoute
12.191 + * \see Ipv4GlobalRouting::AddRoute
12.192 + */
12.193 + void RemoveRoute (uint32_t i);
12.194 +
12.195 + void SetNode (Ptr<Node> node);
12.196 + Ptr<Node> GetNode (void) const;
12.197 +
12.198 +protected:
12.199 + void DoDispose (void);
12.200 +
12.201 +private:
12.202 + typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
12.203 + typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
12.204 + typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
12.205 + typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
12.206 + typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
12.207 + typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
12.208 +
12.209 + Ptr<Ipv4Route> LookupGlobal (Ipv4Address dest);
12.210 +
12.211 + HostRoutes m_hostRoutes;
12.212 + NetworkRoutes m_networkRoutes;
12.213 +
12.214 + Ptr<Node> m_node;
12.215 +};
12.216 +
12.217 +} // Namespace ns3
12.218 +
12.219 +#endif /* IPV4_GLOBAL_ROUTING_H */
13.1 --- a/src/routing/global-routing/wscript Thu Jun 11 16:02:10 2009 +0100
13.2 +++ b/src/routing/global-routing/wscript Thu Jun 11 16:02:58 2009 +0100
13.3 @@ -7,6 +7,7 @@
13.4 'global-route-manager.cc',
13.5 'global-route-manager-impl.cc',
13.6 'candidate-queue.cc',
13.7 + 'ipv4-global-routing.cc',
13.8 ]
13.9 headers = bld.new_task_gen('ns3header')
13.10 headers.module = 'global-routing'