A Discrete-Event Network Simulator
API
ipv4-global-routing.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2008 University of Washington
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 //
18 
19 #ifndef IPV4_GLOBAL_ROUTING_H
20 #define IPV4_GLOBAL_ROUTING_H
21 
22 #include "ns3/ipv4-address.h"
23 #include "ns3/ipv4-header.h"
24 #include "ns3/ipv4-routing-protocol.h"
25 #include "ns3/ipv4.h"
26 #include "ns3/ptr.h"
27 #include "ns3/random-variable-stream.h"
28 
29 #include <list>
30 #include <stdint.h>
31 
32 namespace ns3
33 {
34 
35 class Packet;
36 class NetDevice;
37 class Ipv4Interface;
38 class Ipv4Address;
39 class Ipv4Header;
40 class Ipv4RoutingTableEntry;
41 class Ipv4MulticastRoutingTableEntry;
42 class Node;
43 
72 {
73  public:
78  static TypeId GetTypeId();
88  ~Ipv4GlobalRouting() override;
89 
90  // These methods inherited from base class
92  const Ipv4Header& header,
93  Ptr<NetDevice> oif,
94  Socket::SocketErrno& sockerr) override;
95 
97  const Ipv4Header& header,
102  ErrorCallback ecb) override;
103  void NotifyInterfaceUp(uint32_t interface) override;
104  void NotifyInterfaceDown(uint32_t interface) override;
105  void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
106  void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
107  void SetIpv4(Ptr<Ipv4> ipv4) override;
109  Time::Unit unit = Time::S) const override;
110 
121  void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface);
131  void AddHostRouteTo(Ipv4Address dest, uint32_t interface);
132 
144  void AddNetworkRouteTo(Ipv4Address network,
145  Ipv4Mask networkMask,
146  Ipv4Address nextHop,
147  uint32_t interface);
148 
159  void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, uint32_t interface);
160 
170  void AddASExternalRouteTo(Ipv4Address network,
171  Ipv4Mask networkMask,
172  Ipv4Address nextHop,
173  uint32_t interface);
174 
182  uint32_t GetNRoutes() const;
183 
204  Ipv4RoutingTableEntry* GetRoute(uint32_t i) const;
205 
222  void RemoveRoute(uint32_t i);
223 
232  int64_t AssignStreams(int64_t stream);
233 
234  protected:
235  void DoDispose() override;
236 
237  private:
246 
248  typedef std::list<Ipv4RoutingTableEntry*> HostRoutes;
250  typedef std::list<Ipv4RoutingTableEntry*>::const_iterator HostRoutesCI;
252  typedef std::list<Ipv4RoutingTableEntry*>::iterator HostRoutesI;
253 
255  typedef std::list<Ipv4RoutingTableEntry*> NetworkRoutes;
257  typedef std::list<Ipv4RoutingTableEntry*>::const_iterator NetworkRoutesCI;
259  typedef std::list<Ipv4RoutingTableEntry*>::iterator NetworkRoutesI;
260 
262  typedef std::list<Ipv4RoutingTableEntry*> ASExternalRoutes;
264  typedef std::list<Ipv4RoutingTableEntry*>::const_iterator ASExternalRoutesCI;
266  typedef std::list<Ipv4RoutingTableEntry*>::iterator ASExternalRoutesI;
267 
275 
279 
281 };
282 
283 } // Namespace ns3
284 
285 #endif /* IPV4_GLOBAL_ROUTING_H */
Callback template class.
Definition: callback.h:443
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Global routing protocol for IPv4 stacks.
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface)
Add a host route to the global routing table.
std::list< Ipv4RoutingTableEntry * >::iterator HostRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to hosts)
void AddASExternalRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add an external route to the global routing table.
Ipv4RoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
Destructor implementation.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< UniformRandomVariable > m_rand
A uniform random number generator for randomly routing packets among ECMP.
void RemoveRoute(uint32_t i)
Remove a route from the global unicast routing table.
void NotifyInterfaceDown(uint32_t interface) override
std::list< Ipv4RoutingTableEntry * > HostRoutes
container of Ipv4RoutingTableEntry (routes to hosts)
void NotifyInterfaceUp(uint32_t interface) override
void SetIpv4(Ptr< Ipv4 > ipv4) override
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
std::list< Ipv4RoutingTableEntry * > ASExternalRoutes
container of Ipv4RoutingTableEntry (routes to external AS)
uint32_t GetNRoutes() const
Get the number of individual unicast routes that have been added to the routing table.
std::list< Ipv4RoutingTableEntry * >::iterator ASExternalRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to external AS)
Ipv4GlobalRouting()
Construct an empty Ipv4GlobalRouting routing protocol,.
std::list< Ipv4RoutingTableEntry * >::const_iterator NetworkRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to networks)
Ptr< Ipv4 > m_ipv4
associated IPv4 instance
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 AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Add a network route to the global routing table.
std::list< Ipv4RoutingTableEntry * >::const_iterator HostRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to hosts)
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
std::list< Ipv4RoutingTableEntry * > NetworkRoutes
container of Ipv4RoutingTableEntry (routes to networks)
std::list< Ipv4RoutingTableEntry * >::iterator NetworkRoutesI
iterator of container of Ipv4RoutingTableEntry (routes to networks)
ASExternalRoutes m_ASexternalRoutes
External routes imported.
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)
HostRoutes m_hostRoutes
Routes to hosts.
bool m_respondToInterfaceEvents
Set to true if this interface should respond to interface events by globallly recomputing routes.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
bool m_randomEcmpRouting
Set to true if packets are randomly routed among ECMP; set to false for using only one route consiste...
NetworkRoutes m_networkRoutes
Routes to networks.
std::list< Ipv4RoutingTableEntry * >::const_iterator ASExternalRoutesCI
const iterator of container of Ipv4RoutingTableEntry (routes to external AS)
Ptr< Ipv4Route > LookupGlobal(Ipv4Address dest, Ptr< NetDevice > oif=nullptr)
Lookup in the forwarding table for destination.
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
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
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.