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 "ipv4-header.h"
25 #include "ipv4-routing-protocol.h"
26 #include "ipv4.h"
27 
28 #include "ns3/ipv4-address.h"
29 #include "ns3/ptr.h"
30 #include "ns3/socket.h"
31 
32 #include <list>
33 #include <stdint.h>
34 #include <utility>
35 
36 namespace ns3
37 {
38 
39 class Packet;
40 class NetDevice;
41 class Ipv4Interface;
42 class Ipv4Address;
43 class Ipv4Header;
44 class Ipv4RoutingTableEntry;
45 class Ipv4MulticastRoutingTableEntry;
46 class Node;
47 
68 {
69  public:
74  static TypeId GetTypeId();
75 
77  ~Ipv4StaticRouting() override;
78 
80  const Ipv4Header& header,
81  Ptr<NetDevice> oif,
82  Socket::SocketErrno& sockerr) override;
83 
85  const Ipv4Header& header,
87  const UnicastForwardCallback& ucb,
88  const MulticastForwardCallback& mcb,
89  const LocalDeliverCallback& lcb,
90  const ErrorCallback& ecb) override;
91 
92  void NotifyInterfaceUp(uint32_t interface) override;
93  void NotifyInterfaceDown(uint32_t interface) override;
94  void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
95  void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
96  void SetIpv4(Ptr<Ipv4> ipv4) override;
98  Time::Unit unit = Time::S) const override;
99 
112  void AddNetworkRouteTo(Ipv4Address network,
113  Ipv4Mask networkMask,
114  Ipv4Address nextHop,
115  uint32_t interface,
116  uint32_t metric = 0);
117 
129  void AddNetworkRouteTo(Ipv4Address network,
130  Ipv4Mask networkMask,
131  uint32_t interface,
132  uint32_t metric = 0);
133 
145  void AddHostRouteTo(Ipv4Address dest,
146  Ipv4Address nextHop,
147  uint32_t interface,
148  uint32_t metric = 0);
159  void AddHostRouteTo(Ipv4Address dest, uint32_t interface, uint32_t metric = 0);
179  void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric = 0);
180 
188  uint32_t GetNRoutes() const;
189 
200 
214  Ipv4RoutingTableEntry GetRoute(uint32_t i) const;
215 
224  uint32_t GetMetric(uint32_t index) const;
225 
238  void RemoveRoute(uint32_t i);
239 
264  void AddMulticastRoute(Ipv4Address origin,
265  Ipv4Address group,
266  uint32_t inputInterface,
267  std::vector<uint32_t> outputInterfaces);
268 
293  void SetDefaultMulticastRoute(uint32_t outputInterface);
294 
302  uint32_t GetNMulticastRoutes() const;
303 
319 
345  bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface);
346 
360  void RemoveMulticastRoute(uint32_t index);
361 
362  protected:
363  void DoDispose() override;
364 
365  private:
367  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>> NetworkRoutes;
368 
370  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>>::const_iterator NetworkRoutesCI;
371 
373  typedef std::list<std::pair<Ipv4RoutingTableEntry*, uint32_t>>::iterator NetworkRoutesI;
374 
376  typedef std::list<Ipv4MulticastRoutingTableEntry*> MulticastRoutes;
377 
379  typedef std::list<Ipv4MulticastRoutingTableEntry*>::const_iterator MulticastRoutesCI;
380 
382  typedef std::list<Ipv4MulticastRoutingTableEntry*>::iterator MulticastRoutesI;
383 
390  bool LookupRoute(const Ipv4RoutingTableEntry& route, uint32_t metric);
391 
399 
407  Ptr<Ipv4MulticastRoute> LookupStatic(Ipv4Address origin, Ipv4Address group, uint32_t interface);
408 
413 
418 
423 };
424 
425 } // Namespace ns3
426 
427 #endif /* IPV4_STATIC_ROUTING_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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:257
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.
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
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
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:77
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:59
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.