1.1 --- a/src/internet-stack/ipv4-static-routing-impl.h Tue Jun 30 23:58:56 2009 -0700
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,373 +0,0 @@
1.4 -// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
1.5 -//
1.6 -// Copyright (c) 2006 Georgia Tech Research Corporation
1.7 -//
1.8 -// This program is free software; you can redistribute it and/or modify
1.9 -// it under the terms of the GNU General Public License version 2 as
1.10 -// published by the Free Software Foundation;
1.11 -//
1.12 -// This program is distributed in the hope that it will be useful,
1.13 -// but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 -// GNU General Public License for more details.
1.16 -//
1.17 -// You should have received a copy of the GNU General Public License
1.18 -// along with this program; if not, write to the Free Software
1.19 -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 -//
1.21 -// Author: George F. Riley<riley@ece.gatech.edu>
1.22 -// Gustavo Carneiro <gjc@inescporto.pt>
1.23 -//
1.24 -
1.25 -#ifndef IPV4_STATIC_ROUTING_IMPL_H
1.26 -#define IPV4_STATIC_ROUTING_IMPL_H
1.27 -
1.28 -#include <list>
1.29 -#include <stdint.h>
1.30 -#include "ns3/ipv4-address.h"
1.31 -#include "ns3/ipv4-header.h"
1.32 -#include "ns3/socket.h"
1.33 -#include "ns3/ptr.h"
1.34 -#include "ns3/ipv4.h"
1.35 -#include "ns3/ipv4-static-routing.h"
1.36 -
1.37 -namespace ns3 {
1.38 -
1.39 -class Packet;
1.40 -class NetDevice;
1.41 -class Ipv4Interface;
1.42 -class Ipv4Address;
1.43 -class Ipv4Header;
1.44 -class Ipv4RoutingTableEntry;
1.45 -class Ipv4MulticastRoutingTableEntry;
1.46 -class Node;
1.47 -
1.48 -class Ipv4StaticRoutingImpl : public Ipv4StaticRouting
1.49 -{
1.50 -public:
1.51 - static TypeId GetTypeId (void);
1.52 -
1.53 - Ipv4StaticRoutingImpl ();
1.54 - virtual ~Ipv4StaticRoutingImpl ();
1.55 -
1.56 - virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
1.57 -
1.58 - virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
1.59 - UnicastForwardCallback ucb, MulticastForwardCallback mcb,
1.60 - LocalDeliverCallback lcb, ErrorCallback ecb);
1.61 -
1.62 - virtual void NotifyInterfaceUp (uint32_t interface);
1.63 - virtual void NotifyInterfaceDown (uint32_t interface);
1.64 - virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
1.65 - virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
1.66 - virtual void SetIpv4 (Ptr<Ipv4> ipv4);
1.67 -
1.68 -
1.69 -/**
1.70 - * \brief Add a host route to the static routing table.
1.71 - *
1.72 - * \param dest The Ipv4Address destination for this route.
1.73 - * \param nextHop The Ipv4Address of the next hop in the route.
1.74 - * \param interface The network interface index used to send packets to the
1.75 - * destination.
1.76 - *
1.77 - * \see Ipv4Address
1.78 - */
1.79 - void AddHostRouteTo (Ipv4Address dest,
1.80 - Ipv4Address nextHop,
1.81 - uint32_t interface);
1.82 -/**
1.83 - * \brief Add a host route to the static routing table.
1.84 - *
1.85 - * \param dest The Ipv4Address destination for this route.
1.86 - * \param interface The network interface index used to send packets to the
1.87 - * destination.
1.88 - *
1.89 - * \see Ipv4Address
1.90 - */
1.91 - void AddHostRouteTo (Ipv4Address dest,
1.92 - uint32_t interface);
1.93 -
1.94 -/**
1.95 - * \brief Add a network route to the static routing table.
1.96 - *
1.97 - * \param network The Ipv4Address network for this route.
1.98 - * \param networkMask The Ipv4Mask to extract the network.
1.99 - * \param nextHop The next hop in the route to the destination network.
1.100 - * \param interface The network interface index used to send packets to the
1.101 - * destination.
1.102 - *
1.103 - * \see Ipv4Address
1.104 - */
1.105 - void AddNetworkRouteTo (Ipv4Address network,
1.106 - Ipv4Mask networkMask,
1.107 - Ipv4Address nextHop,
1.108 - uint32_t interface);
1.109 -
1.110 -/**
1.111 - * \brief Add a network route to the static routing table.
1.112 - *
1.113 - * \param network The Ipv4Address network for this route.
1.114 - * \param networkMask The Ipv4Mask to extract the network.
1.115 - * \param interface The network interface index used to send packets to the
1.116 - * destination.
1.117 - *
1.118 - * \see Ipv4Address
1.119 - */
1.120 - void AddNetworkRouteTo (Ipv4Address network,
1.121 - Ipv4Mask networkMask,
1.122 - uint32_t interface);
1.123 -
1.124 -/**
1.125 - * \brief Add a default route to the static routing table.
1.126 - *
1.127 - * This method tells the routing system what to do in the case where a specific
1.128 - * route to a destination is not found. The system forwards packets to the
1.129 - * specified node in the hope that it knows better how to route the packet.
1.130 - *
1.131 - * If the default route is set, it is returned as the selected route from
1.132 - * LookupStatic irrespective of destination address if no specific route is
1.133 - * found.
1.134 - *
1.135 - * \param nextHop The Ipv4Address to send packets to in the hope that they
1.136 - * will be forwarded correctly.
1.137 - * \param interface The network interface index used to send packets.
1.138 - *
1.139 - * \see Ipv4Address
1.140 - * \see Ipv4StaticRouting::Lookup
1.141 - */
1.142 - void SetDefaultRoute (Ipv4Address nextHop,
1.143 - uint32_t interface);
1.144 -
1.145 -/**
1.146 - * \brief Get the number of individual unicast routes that have been added
1.147 - * to the routing table.
1.148 - *
1.149 - * \warning The default route counts as one of the routes.
1.150 - */
1.151 - uint32_t GetNRoutes (void);
1.152 -
1.153 -/**
1.154 - * \brief Get the default route from the static routing table.
1.155 - *
1.156 - * \return If the default route is set, a pointer to that Ipv4RoutingTableEntry is
1.157 - * returned, otherwise a zero pointer is returned.
1.158 - *
1.159 - * \see Ipv4RoutingTableEntry
1.160 - */
1.161 - Ipv4RoutingTableEntry GetDefaultRoute (void);
1.162 -
1.163 -/**
1.164 - * \brief Get a route from the static unicast routing table.
1.165 - *
1.166 - * Externally, the unicast static routing table appears simply as a table with
1.167 - * n entries. The one sublety of note is that if a default route has been set
1.168 - * it will appear as the zeroth entry in the table. This means that if you
1.169 - * add only a default route, the table will have one entry that can be accessed
1.170 - * either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
1.171 - *
1.172 - * Similarly, if the default route has been set, calling RemoveRoute (0) will
1.173 - * remove the default route.
1.174 - *
1.175 - * \param i The index (into the routing table) of the route to retrieve. If
1.176 - * the default route has been set, it will occupy index zero.
1.177 - * \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
1.178 - * a zero pointer is returned.
1.179 - *
1.180 - * \see Ipv4RoutingTableEntry
1.181 - * \see Ipv4StaticRouting::RemoveRoute
1.182 - */
1.183 - Ipv4RoutingTableEntry GetRoute (uint32_t i);
1.184 -
1.185 -/**
1.186 - * \brief Remove a route from the static unicast routing table.
1.187 - *
1.188 - * Externally, the unicast static routing table appears simply as a table with
1.189 - * n entries. The one sublety of note is that if a default route has been set
1.190 - * it will appear as the zeroth entry in the table. This means that if the
1.191 - * default route has been set, calling RemoveRoute (0) will remove the
1.192 - * default route.
1.193 - *
1.194 - * \param i The index (into the routing table) of the route to remove. If
1.195 - * the default route has been set, it will occupy index zero.
1.196 - *
1.197 - * \see Ipv4RoutingTableEntry
1.198 - * \see Ipv4StaticRouting::GetRoute
1.199 - * \see Ipv4StaticRouting::AddRoute
1.200 - */
1.201 - void RemoveRoute (uint32_t i);
1.202 -
1.203 -/**
1.204 - * \brief Add a multicast route to the static routing table.
1.205 - *
1.206 - * A multicast route must specify an origin IP address, a multicast group and
1.207 - * an input network interface index as conditions and provide a vector of
1.208 - * output network interface indices over which packets matching the conditions
1.209 - * are sent.
1.210 - *
1.211 - * Typically there are two main types of multicast routes: routes of the
1.212 - * first kind are used during forwarding. All of the conditions must be
1.213 - * exlicitly provided. The second kind of routes are used to get packets off
1.214 - * of a local node. The difference is in the input interface. Routes for
1.215 - * forwarding will always have an explicit input interface specified. Routes
1.216 - * off of a node will always set the input interface to a wildcard specified
1.217 - * by the index Ipv4RoutingProtocol::INTERFACE_ANY.
1.218 - *
1.219 - * For routes off of a local node wildcards may be used in the origin and
1.220 - * multicast group addresses. The wildcard used for Ipv4Adresses is that
1.221 - * address returned by Ipv4Address::GetAny () -- typically "0.0.0.0". Usage
1.222 - * of a wildcard allows one to specify default behavior to varying degrees.
1.223 - *
1.224 - * For example, making the origin address a wildcard, but leaving the
1.225 - * multicast group specific allows one (in the case of a node with multiple
1.226 - * interfaces) to create different routes using different output interfaces
1.227 - * for each multicast group.
1.228 - *
1.229 - * If the origin and multicast addresses are made wildcards, you have created
1.230 - * essentially a default multicast address that can forward to multiple
1.231 - * interfaces. Compare this to the actual default multicast address that is
1.232 - * limited to specifying a single output interface for compatibility with
1.233 - * existing functionality in other systems.
1.234 - *
1.235 - * \param origin The Ipv4Address of the origin of packets for this route. May
1.236 - * be Ipv4Address:GetAny for open groups.
1.237 - * \param group The Ipv4Address of the multicast group or this route.
1.238 - * \param inputInterface The input network interface index over which to
1.239 - * expect packets destined for this route. May be
1.240 - * Ipv4RoutingProtocol::INTERFACE_ANY for packets of local origin.
1.241 - * \param outputInterfaces A vector of network interface indices used to specify
1.242 - * how to send packets to the destination(s).
1.243 - *
1.244 - * \see Ipv4Address
1.245 - */
1.246 - void AddMulticastRoute (Ipv4Address origin,
1.247 - Ipv4Address group,
1.248 - uint32_t inputInterface,
1.249 - std::vector<uint32_t> outputInterfaces);
1.250 -
1.251 -/**
1.252 - * \brief Add a default multicast route to the static routing table.
1.253 - *
1.254 - * This is the multicast equivalent of the unicast version SetDefaultRoute.
1.255 - * We tell the routing system what to do in the case where a specific route
1.256 - * to a destination multicast group is not found. The system forwards
1.257 - * packets out the specified interface in the hope that "something out there"
1.258 - * knows better how to route the packet. This method is only used in
1.259 - * initially sending packets off of a host. The default multicast route is
1.260 - * not consulted during forwarding -- exact routes must be specified using
1.261 - * AddMulticastRoute for that case.
1.262 - *
1.263 - * Since we're basically sending packets to some entity we think may know
1.264 - * better what to do, we don't pay attention to "subtleties" like origin
1.265 - * address, nor do we worry about forwarding out multiple interfaces. If the
1.266 - * default multicast route is set, it is returned as the selected route from
1.267 - * LookupStatic irrespective of origin or multicast group if another specific
1.268 - * route is not found.
1.269 - *
1.270 - * \param outputInterface The network interface index used to specify where
1.271 - * to send packets in the case of unknown routes.
1.272 - *
1.273 - * \see Ipv4Address
1.274 - */
1.275 - void SetDefaultMulticastRoute (uint32_t outputInterface);
1.276 -
1.277 -/**
1.278 - * \brief Get the number of individual multicast routes that have been added
1.279 - * to the routing table.
1.280 - *
1.281 - * \warning The default multicast route counts as one of the routes.
1.282 - */
1.283 - uint32_t GetNMulticastRoutes (void) const;
1.284 -
1.285 -/**
1.286 - * \brief Get a route from the static multicast routing table.
1.287 - *
1.288 - * Externally, the multicast static routing table appears simply as a table
1.289 - * with n entries.
1.290 - *
1.291 - * \param i The index (into the routing table) of the multicast route to
1.292 - * retrieve.
1.293 - * \return If route \e i is set, a pointer to that Ipv4MulticastRoutingTableEntry is
1.294 - * returned, otherwise a zero pointer is returned.
1.295 - *
1.296 - * \see Ipv4MulticastRoutingTableEntry
1.297 - * \see Ipv4StaticRouting::RemoveRoute
1.298 - */
1.299 - Ipv4MulticastRoutingTableEntry GetMulticastRoute (uint32_t i) const;
1.300 -
1.301 -/**
1.302 - * \brief Remove a route from the static multicast routing table.
1.303 - *
1.304 - * Externally, the multicast static routing table appears simply as a table
1.305 - * with n entries.
1.306 - * This method causes the multicast routing table to be searched for the first
1.307 - * route that matches the parameters and removes it.
1.308 - *
1.309 - * Wildcards may be provided to this function, but the wildcards are used to
1.310 - * exacly match wildcards in the routes (see AddMulticastRoute). That is,
1.311 - * calling RemoveMulticastRoute with the origin set to "0.0.0.0" will not
1.312 - * remove routes with any address in the origin, but will only remove routes
1.313 - * with "0.0.0.0" set as the the origin.
1.314 - *
1.315 - * \param origin The IP address specified as the origin of packets for the
1.316 - * route.
1.317 - * \param group The IP address specified as the multicast group addres of
1.318 - * the route.
1.319 - * \param inputInterface The network interface index specified as the expected
1.320 - * input interface for the route.
1.321 - * \returns true if a route was found and removed, false otherwise.
1.322 - *
1.323 - * \see Ipv4MulticastRoutingTableEntry
1.324 - * \see Ipv4StaticRouting::AddMulticastRoute
1.325 - */
1.326 - bool RemoveMulticastRoute (Ipv4Address origin,
1.327 - Ipv4Address group,
1.328 - uint32_t inputInterface);
1.329 -
1.330 -/**
1.331 - * \brief Remove a route from the static multicast routing table.
1.332 - *
1.333 - * Externally, the multicast static routing table appears simply as a table
1.334 - * with n entries.
1.335 - *
1.336 - * \param index The index (into the multicast routing table) of the route to
1.337 - * remove.
1.338 - *
1.339 - * \see Ipv4RoutingTableEntry
1.340 - * \see Ipv4StaticRouting::GetRoute
1.341 - * \see Ipv4StaticRouting::AddRoute
1.342 - */
1.343 - void RemoveMulticastRoute (uint32_t index);
1.344 -
1.345 -protected:
1.346 - virtual void DoDispose (void);
1.347 -
1.348 -private:
1.349 - typedef std::list<Ipv4RoutingTableEntry *> HostRoutes;
1.350 - typedef std::list<Ipv4RoutingTableEntry *>::const_iterator HostRoutesCI;
1.351 - typedef std::list<Ipv4RoutingTableEntry *>::iterator HostRoutesI;
1.352 - typedef std::list<Ipv4RoutingTableEntry *> NetworkRoutes;
1.353 - typedef std::list<Ipv4RoutingTableEntry *>::const_iterator NetworkRoutesCI;
1.354 - typedef std::list<Ipv4RoutingTableEntry *>::iterator NetworkRoutesI;
1.355 -
1.356 - typedef std::list<Ipv4MulticastRoutingTableEntry *> MulticastRoutes;
1.357 - typedef std::list<Ipv4MulticastRoutingTableEntry *>::const_iterator MulticastRoutesCI;
1.358 - typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
1.359 -
1.360 - Ptr<Ipv4Route> LookupStatic (Ipv4Address dest);
1.361 - Ptr<Ipv4MulticastRoute> LookupStatic (Ipv4Address origin, Ipv4Address group,
1.362 - uint32_t interface);
1.363 -
1.364 - Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest);
1.365 -
1.366 - HostRoutes m_hostRoutes;
1.367 - NetworkRoutes m_networkRoutes;
1.368 - Ipv4RoutingTableEntry *m_defaultRoute;
1.369 - MulticastRoutes m_multicastRoutes;
1.370 -
1.371 - Ptr<Ipv4> m_ipv4;
1.372 -};
1.373 -
1.374 -} // Namespace ns3
1.375 -
1.376 -#endif /* IPV4_STATIC_ROUTING_IMPL_H */