A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-list-routing.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 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#ifndef IPV4_LIST_ROUTING_H
19#define IPV4_LIST_ROUTING_H
20
22
23#include "ns3/nstime.h"
24#include "ns3/simulator.h"
25
26#include <list>
27
28namespace ns3
29{
30
31/**
32 * \ingroup ipv4Routing
33 *
34 * \brief IPv4 list routing.
35 *
36 * This class is a specialization of Ipv4RoutingProtocol that allows
37 * other instances of Ipv4RoutingProtocol to be inserted in a
38 * prioritized list. Routing protocols in the list are consulted one
39 * by one, from highest to lowest priority, until a routing protocol
40 * is found that will take the packet (this corresponds to a non-zero
41 * return value to RouteOutput, or a return value of true to RouteInput).
42 * The order by which routing protocols with the same priority value
43 * are consulted is undefined.
44 *
45 */
47{
48 public:
49 /**
50 * \brief Get the type ID of this class.
51 * \return type ID
52 */
53 static TypeId GetTypeId();
54
56 ~Ipv4ListRouting() override;
57
58 /**
59 * \brief Register a new routing protocol to be used in this IPv4 stack
60 *
61 * \param routingProtocol new routing protocol implementation object
62 * \param priority priority to give to this routing protocol.
63 * Values may range between -32768 and +32767.
64 */
65 virtual void AddRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol, int16_t priority);
66 /**
67 * \return number of routing protocols in the list
68 */
69 virtual uint32_t GetNRoutingProtocols() const;
70 /**
71 * Return pointer to routing protocol stored at index, with the
72 * first protocol (index 0) the highest priority, the next one (index 1)
73 * the second highest priority, and so on. The priority parameter is an
74 * output parameter and it returns the integer priority of the protocol.
75 *
76 * \return pointer to routing protocol indexed by
77 * \param index index of protocol to return
78 * \param priority output parameter, set to the priority of the protocol
79 being returned
80 */
81 virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol(uint32_t index, int16_t& priority) const;
82
83 // Below are from Ipv4RoutingProtocol
85 const Ipv4Header& header,
87 Socket::SocketErrno& sockerr) override;
88
90 const Ipv4Header& header,
92 const UnicastForwardCallback& ucb,
93 const MulticastForwardCallback& mcb,
94 const LocalDeliverCallback& lcb,
95 const ErrorCallback& ecb) override;
96 void NotifyInterfaceUp(uint32_t interface) override;
97 void NotifyInterfaceDown(uint32_t interface) override;
98 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
99 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
100 void SetIpv4(Ptr<Ipv4> ipv4) override;
102 Time::Unit unit = Time::S) const override;
103
104 protected:
105 void DoDispose() override;
106 void DoInitialize() override;
107
108 private:
109 /**
110 * \brief Container identifying an IPv4 Routing Protocol entry in the list.
111 */
112 typedef std::pair<int16_t, Ptr<Ipv4RoutingProtocol>> Ipv4RoutingProtocolEntry;
113 /**
114 * \brief Container of the IPv4 Routing Protocols.
115 */
116 typedef std::list<Ipv4RoutingProtocolEntry> Ipv4RoutingProtocolList;
117 Ipv4RoutingProtocolList m_routingProtocols; //!< List of routing protocols.
118
119 /**
120 * \brief Compare two routing protocols.
121 * \param a first object to compare
122 * \param b second object to compare
123 * \return true if they are the same, false otherwise
124 */
125 static bool Compare(const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b);
126 Ptr<Ipv4> m_ipv4; //!< Ipv4 this protocol is associated with.
127};
128
129} // namespace ns3
130
131#endif /* IPV4_LIST_ROUTING_H */
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
IPv4 list routing.
std::pair< int16_t, Ptr< Ipv4RoutingProtocol > > Ipv4RoutingProtocolEntry
Container identifying an IPv4 Routing Protocol entry in the list.
static TypeId GetTypeId()
Get the type ID of this class.
void DoDispose() override
Destructor implementation.
Ipv4RoutingProtocolList m_routingProtocols
List of routing protocols.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
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 SetIpv4(Ptr< Ipv4 > ipv4) override
virtual uint32_t GetNRoutingProtocols() const
std::list< Ipv4RoutingProtocolEntry > Ipv4RoutingProtocolList
Container of the IPv4 Routing Protocols.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
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)
virtual void AddRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol, int16_t priority)
Register a new routing protocol to be used in this IPv4 stack.
Ptr< Ipv4 > m_ipv4
Ipv4 this protocol is associated with.
static bool Compare(const Ipv4RoutingProtocolEntry &a, const Ipv4RoutingProtocolEntry &b)
Compare two routing protocols.
void NotifyInterfaceDown(uint32_t interface) override
void DoInitialize() override
Initialize() implementation.
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(uint32_t index, int16_t &priority) const
Return pointer to routing protocol stored at index, with the first protocol (index 0) the highest pri...
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceUp(uint32_t interface) override
Abstract base class for IPv4 routing protocols.
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.