A Discrete-Event Network Simulator
API
ipv4-static-routing.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Georgia Tech Research Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: George F. Riley<riley@ece.gatech.edu>
18  * Gustavo Carneiro <gjc@inescporto.pt>
19  */
20 
21 #ifndef IPV4_STATIC_ROUTING_H
22 #define IPV4_STATIC_ROUTING_H
23 
24 #include "ns3/ipv4-address.h"
25 #include "ns3/ipv4-header.h"
26 #include "ns3/ipv4-routing-protocol.h"
27 #include "ns3/ipv4.h"
28 #include "ns3/ptr.h"
29 #include "ns3/socket.h"
30 
31 #include <list>
32 #include <stdint.h>
33 #include <utility>
34 
35 namespace ns3
36 {
37 
38 class Packet;
39 class NetDevice;
40 class Ipv4Interface;
41 class Ipv4Address;
42 class Ipv4Header;
43 class Ipv4RoutingTableEntry;
44 class Ipv4MulticastRoutingTableEntry;
45 class Node;
46 
67 {
68  public:
73  static TypeId GetTypeId();
74 
76  ~Ipv4StaticRouting() override;
77 
79  const Ipv4Header& header,
80  Ptr<NetDevice> oif,
81  Socket::SocketErrno& sockerr) override;
82 
84  const Ipv4Header& header,
89  ErrorCallback ecb) override;
90 
91  void NotifyInterfaceUp(uint32_t interface) override;
92  void NotifyInterfaceDown(uint32_t interface) override;
93  void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
94  void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
95  void SetIpv4(Ptr<Ipv4> ipv4) override;
97  Time::Unit unit = Time::S) const override;
98 
111  void AddNetworkRouteTo(Ipv4Address network,
112  Ipv4Mask networkMask,
113  Ipv4Address nextHop,
114  uint32_t interface,
115  uint32_t metric = 0);
116 
128  void AddNetworkRouteTo(Ipv4Address network,
129  Ipv4Mask networkMask,
130  uint32_t interface,
131  uint32_t metric = 0);
132 
144  void AddHostRouteTo(Ipv4Address dest,
145  Ipv4Address nextHop,
146  uint32_t interface,
147  uint32_t metric = 0);
158  void AddHostRouteTo(Ipv4Address dest, uint32_t interface, uint32_t metric = 0);
178  void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric = 0);
179 
187  uint32_t GetNRoutes() const;
188 
199 
213  Ipv4RoutingTableEntry GetRoute(uint32_t i) const;
214 
223  uint32_t GetMetric(uint32_t index) const;
224 
237  void RemoveRoute(uint32_t i);
238 
263  void AddMulticastRoute(Ipv4Address origin,
264  Ipv4Address group,
265  uint32_t inputInterface,
266  std::vector<uint32_t> outputInterfaces);
267 
292  void SetDefaultMulticastRoute(uint32_t outputInterface);
293 
301  uint32_t GetNMulticastRoutes() const;
302 
318 
344  bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface);
345 
359  void RemoveMulticastRoute(uint32_t index);
360 
361  protected:
362  void DoDispose() override;
363 
364  private:
366  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>> NetworkRoutes;
367 
369  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>>::const_iterator NetworkRoutesCI;
370 
372  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>>::iterator NetworkRoutesI;
373 
375  typedef std::list<Ipv4MulticastRoutingTableEntry*> MulticastRoutes;
376 
378  typedef std::list<Ipv4MulticastRoutingTableEntry*>::const_iterator MulticastRoutesCI;
379 
381  typedef std::list<Ipv4MulticastRoutingTableEntry*>::iterator MulticastRoutesI;
382 
389  bool LookupRoute(const Ipv4RoutingTableEntry& route, uint32_t metric);
390 
398 
406  Ptr<Ipv4MulticastRoute> LookupStatic(Ipv4Address origin, Ipv4Address group, uint32_t interface);
407 
412 
417 
422 };
423 
424 } // Namespace ns3
425 
426 #endif /* IPV4_STATIC_ROUTING_H */
Callback template class.
Definition: callback.h:443
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Static routing protocol for IP version 4 stacks.
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb) override
Route an input packet (to be forwarded or locally delivered)
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
void SetIpv4(Ptr< Ipv4 > ipv4) override
void NotifyInterfaceUp(uint32_t interface) override
void DoDispose() override
Destructor implementation.
Ipv4RoutingTableEntry GetDefaultRoute()
Get the default route with lowest metric from the static routing table.
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
bool LookupRoute(const Ipv4RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
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.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
NetworkRoutes m_networkRoutes
the forwarding table for network.
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=nullptr)
Lookup in the forwarding table for destination.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
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.
uint32_t GetNMulticastRoutes() const
Get the number of individual multicast routes that have been added to the routing table.
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > > NetworkRoutes
Container for the network routes.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceDown(uint32_t interface) override
static TypeId GetTypeId()
The interface Id associated with this class.
std::list< Ipv4MulticastRoutingTableEntry * > MulticastRoutes
Container for the multicast routes.
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
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.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
uint32_t GetNRoutes() const
Get the number of individual unicast routes that have been added to the routing table.
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.