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 
70 {
71 public:
76  static TypeId GetTypeId (void);
77 
79  virtual ~Ipv4StaticRouting ();
80 
81  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
82 
83  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
86 
87  virtual void NotifyInterfaceUp (uint32_t interface);
88  virtual void NotifyInterfaceDown (uint32_t interface);
89  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
90  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
91  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
92  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
93 
106  void AddNetworkRouteTo (Ipv4Address network,
107  Ipv4Mask networkMask,
108  Ipv4Address nextHop,
109  uint32_t interface,
110  uint32_t metric = 0);
111 
123  void AddNetworkRouteTo (Ipv4Address network,
124  Ipv4Mask networkMask,
125  uint32_t interface,
126  uint32_t metric = 0);
127 
139  void AddHostRouteTo (Ipv4Address dest,
140  Ipv4Address nextHop,
141  uint32_t interface,
142  uint32_t metric = 0);
153  void AddHostRouteTo (Ipv4Address dest,
154  uint32_t interface,
155  uint32_t metric = 0);
175  void SetDefaultRoute (Ipv4Address nextHop,
176  uint32_t interface,
177  uint32_t metric = 0);
178 
186  uint32_t GetNRoutes (void) const;
187 
198 
212  Ipv4RoutingTableEntry GetRoute (uint32_t i) const;
213 
221  uint32_t GetMetric (uint32_t index) const;
222 
235  void RemoveRoute (uint32_t i);
236 
280  void AddMulticastRoute (Ipv4Address origin,
282  uint32_t inputInterface,
283  std::vector<uint32_t> outputInterfaces);
284 
309  void SetDefaultMulticastRoute (uint32_t outputInterface);
310 
318  uint32_t GetNMulticastRoutes (void) const;
319 
335 
361  bool RemoveMulticastRoute (Ipv4Address origin,
362  Ipv4Address group,
363  uint32_t inputInterface);
364 
378  void RemoveMulticastRoute (uint32_t index);
379 
380 protected:
381  virtual void DoDispose (void);
382 
383 private:
385  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> > NetworkRoutes;
386 
388  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::const_iterator NetworkRoutesCI;
389 
391  typedef std::list<std::pair <Ipv4RoutingTableEntry *, uint32_t> >::iterator NetworkRoutesI;
392 
394  typedef std::list<Ipv4MulticastRoutingTableEntry *> MulticastRoutes;
395 
397  typedef std::list<Ipv4MulticastRoutingTableEntry *>::const_iterator MulticastRoutesCI;
398 
400  typedef std::list<Ipv4MulticastRoutingTableEntry *>::iterator MulticastRoutesI;
401 
409 
418  uint32_t interface);
419 
423  NetworkRoutes m_networkRoutes;
424 
428  MulticastRoutes m_multicastRoutes;
429 
434 };
435 
436 } // Namespace ns3
437 
438 #endif /* IPV4_STATIC_ROUTING_H */
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Callback template class.
Definition: callback.h:1164
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:234
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.
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:31
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.
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: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.