A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv4-static-routing.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 Georgia Tech Research Corporation
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: George F. Riley<riley@ece.gatech.edu>
19  * Gustavo Carneiro <gjc@inescporto.pt>
20  */
21 
22 #ifndef IPV4_STATIC_ROUTING_H
23 #define IPV4_STATIC_ROUTING_H
24 
25 #include <list>
26 #include <utility>
27 #include <stdint.h>
28 #include "ns3/ipv4-address.h"
29 #include "ns3/ipv4-header.h"
30 #include "ns3/socket.h"
31 #include "ns3/ptr.h"
32 #include "ns3/ipv4.h"
33 #include "ns3/ipv4-routing-protocol.h"
34 
35 namespace ns3 {
36 
37 class Packet;
38 class NetDevice;
39 class Ipv4Interface;
40 class Ipv4Address;
41 class Ipv4Header;
42 class Ipv4RoutingTableEntry;
43 class Ipv4MulticastRoutingTableEntry;
44 class Node;
45 
70 {
71 public:
72  static TypeId GetTypeId (void);
73 
75  virtual ~Ipv4StaticRouting ();
76 
77  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
78 
79  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
82 
83  virtual void NotifyInterfaceUp (uint32_t interface);
84  virtual void NotifyInterfaceDown (uint32_t interface);
85  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
86  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
87  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
88  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
89 
102  void AddNetworkRouteTo (Ipv4Address network,
103  Ipv4Mask networkMask,
104  Ipv4Address nextHop,
105  uint32_t interface,
106  uint32_t metric = 0);
107 
119  void AddNetworkRouteTo (Ipv4Address network,
120  Ipv4Mask networkMask,
121  uint32_t interface,
122  uint32_t metric = 0);
123 
135  void AddHostRouteTo (Ipv4Address dest,
136  Ipv4Address nextHop,
137  uint32_t interface,
138  uint32_t metric = 0);
149  void AddHostRouteTo (Ipv4Address dest,
150  uint32_t interface,
151  uint32_t metric = 0);
171  void SetDefaultRoute (Ipv4Address nextHop,
172  uint32_t interface,
173  uint32_t metric = 0);
174 
181  uint32_t GetNRoutes (void) const;
182 
193 
207  Ipv4RoutingTableEntry GetRoute (uint32_t i) const;
208 
216  uint32_t GetMetric (uint32_t index) const;
217 
230  void RemoveRoute (uint32_t i);
231 
275  void AddMulticastRoute (Ipv4Address origin,
276  Ipv4Address group,
277  uint32_t inputInterface,
278  std::vector<uint32_t> outputInterfaces);
279 
304  void SetDefaultMulticastRoute (uint32_t outputInterface);
305 
312  uint32_t GetNMulticastRoutes (void) const;
313 
329 
355  bool RemoveMulticastRoute (Ipv4Address origin,
356  Ipv4Address group,
357  uint32_t inputInterface);
358 
372  void RemoveMulticastRoute (uint32_t index);
373 
374 protected:
375  virtual void DoDispose (void);
376 
377 private:
378  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> > NetworkRoutes;
379  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::const_iterator NetworkRoutesCI;
380  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::iterator NetworkRoutesI;
381 
382  typedef std::list<Ipv4MulticastRoutingTableEntry *> MulticastRoutes;
383  typedef std::list<Ipv4MulticastRoutingTableEntry *>::const_iterator MulticastRoutesCI;
384  typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
385 
386  Ptr<Ipv4Route> LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif = 0);
387  Ptr<Ipv4MulticastRoute> LookupStatic (Ipv4Address origin, Ipv4Address group,
388  uint32_t interface);
389 
390  Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest);
391 
392  NetworkRoutes m_networkRoutes;
393  MulticastRoutes m_multicastRoutes;
394 
395  Ptr<Ipv4> m_ipv4;
396 };
397 
398 } // Namespace ns3
399 
400 #endif /* IPV4_STATIC_ROUTING_H */
Callback template class.
Definition: callback.h:369
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
Ipv4RoutingTableEntry GetDefaultRoute(void)
Get the default route with lowest metric from the static routing table.
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a host route to the static routing table.
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual void NotifyInterfaceDown(uint32_t interface)
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
Static routing protocol for IP version 4 stacks.
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual void DoDispose(void)
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceUp(uint32_t interface)
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Abstract base class for IPv4 routing protocols.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
uint32_t GetNMulticastRoutes(void) const
Get the number of individual multicast routes that have been added to the routing table...
a unique identifier for an interface.
Definition: type-id.h:44
void SetDefaultMulticastRoute(uint32_t outputInterface)
Add a default multicast route to the static routing table.
void AddMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route to the static routing table.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.