A Discrete-Event Network Simulator
API
ipv4-static-routing.h
Go to the documentation of this file.
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 
66 {
67 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, Time::Unit unit = Time::S) 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 
182  uint32_t GetNRoutes (void) const;
183 
194 
208  Ipv4RoutingTableEntry GetRoute (uint32_t i) const;
209 
217  uint32_t GetMetric (uint32_t index) const;
218 
231  void RemoveRoute (uint32_t i);
232 
276  void AddMulticastRoute (Ipv4Address origin,
278  uint32_t inputInterface,
279  std::vector<uint32_t> outputInterfaces);
280 
305  void SetDefaultMulticastRoute (uint32_t outputInterface);
306 
314  uint32_t GetNMulticastRoutes (void) const;
315 
331 
357  bool RemoveMulticastRoute (Ipv4Address origin,
358  Ipv4Address group,
359  uint32_t inputInterface);
360 
374  void RemoveMulticastRoute (uint32_t index);
375 
376 protected:
377  virtual void DoDispose (void);
378 
379 private:
381  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> > NetworkRoutes;
382 
384  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::const_iterator NetworkRoutesCI;
385 
387  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::iterator NetworkRoutesI;
388 
390  typedef std::list<Ipv4MulticastRoutingTableEntry *> MulticastRoutes;
391 
393  typedef std::list<Ipv4MulticastRoutingTableEntry *>::const_iterator MulticastRoutesCI;
394 
396  typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
397 
405 
414  uint32_t interface);
415 
419  NetworkRoutes m_networkRoutes;
420 
424  MulticastRoutes m_multicastRoutes;
425 
430 };
431 
432 } // Namespace ns3
433 
434 #endif /* IPV4_STATIC_ROUTING_H */
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:108
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Callback template class.
Definition: callback.h:1176
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
static TypeId GetTypeId(void)
The interface Id associated with this class.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
second
Definition: nstime.h:114
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a host route to the static routing table.
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=0)
Lookup in the forwarding table for destination.
Packet header for IPv4.
Definition: ipv4-header.h:33
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
virtual void NotifyInterfaceDown(uint32_t interface)
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
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)
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Static routing protocol for IP version 4 stacks.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
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:40
virtual void DoDispose(void)
Destructor implementation.
std::list< Ipv4MulticastRoutingTableEntry * > MulticastRoutes
Container for the multicast routes.
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceUp(uint32_t interface)
NetworkRoutes m_networkRoutes
the forwarding table for network.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > > NetworkRoutes
Container for the network routes.
Abstract base class for IPv4 routing protocols.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
tuple address
Definition: first.py:37
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:58
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.