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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#ifndef IPV4_LIST_ROUTING_H
8#define IPV4_LIST_ROUTING_H
9
11
12#include "ns3/nstime.h"
13#include "ns3/simulator.h"
14
15#include <list>
16
17namespace ns3
18{
19
20/**
21 * \ingroup ipv4Routing
22 *
23 * \brief IPv4 list routing.
24 *
25 * This class is a specialization of Ipv4RoutingProtocol that allows
26 * other instances of Ipv4RoutingProtocol to be inserted in a
27 * prioritized list. Routing protocols in the list are consulted one
28 * by one, from highest to lowest priority, until a routing protocol
29 * is found that will take the packet (this corresponds to a non-zero
30 * return value to RouteOutput, or a return value of true to RouteInput).
31 * The order by which routing protocols with the same priority value
32 * are consulted is undefined.
33 *
34 */
36{
37 public:
38 /**
39 * \brief Get the type ID of this class.
40 * \return type ID
41 */
42 static TypeId GetTypeId();
43
45 ~Ipv4ListRouting() override;
46
47 /**
48 * \brief Register a new routing protocol to be used in this IPv4 stack
49 *
50 * \param routingProtocol new routing protocol implementation object
51 * \param priority priority to give to this routing protocol.
52 * Values may range between -32768 and +32767.
53 */
54 virtual void AddRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol, int16_t priority);
55 /**
56 * \return number of routing protocols in the list
57 */
58 virtual uint32_t GetNRoutingProtocols() const;
59 /**
60 * Return pointer to routing protocol stored at index, with the
61 * first protocol (index 0) the highest priority, the next one (index 1)
62 * the second highest priority, and so on. The priority parameter is an
63 * output parameter and it returns the integer priority of the protocol.
64 *
65 * \return pointer to routing protocol indexed by
66 * \param index index of protocol to return
67 * \param priority output parameter, set to the priority of the protocol
68 being returned
69 */
70 virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol(uint32_t index, int16_t& priority) const;
71
72 // Below are from Ipv4RoutingProtocol
74 const Ipv4Header& header,
76 Socket::SocketErrno& sockerr) override;
77
79 const Ipv4Header& header,
81 const UnicastForwardCallback& ucb,
82 const MulticastForwardCallback& mcb,
83 const LocalDeliverCallback& lcb,
84 const ErrorCallback& ecb) override;
85 void NotifyInterfaceUp(uint32_t interface) override;
86 void NotifyInterfaceDown(uint32_t interface) override;
87 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
88 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
89 void SetIpv4(Ptr<Ipv4> ipv4) override;
91 Time::Unit unit = Time::S) const override;
92
93 protected:
94 void DoDispose() override;
95 void DoInitialize() override;
96
97 private:
98 /**
99 * \brief Container identifying an IPv4 Routing Protocol entry in the list.
100 */
101 typedef std::pair<int16_t, Ptr<Ipv4RoutingProtocol>> Ipv4RoutingProtocolEntry;
102 /**
103 * \brief Container of the IPv4 Routing Protocols.
104 */
105 typedef std::list<Ipv4RoutingProtocolEntry> Ipv4RoutingProtocolList;
106 Ipv4RoutingProtocolList m_routingProtocols; //!< List of routing protocols.
107
108 /**
109 * \brief Compare two routing protocols.
110 * \param a first object to compare
111 * \param b second object to compare
112 * \return true if they are the same, false otherwise
113 */
114 static bool Compare(const Ipv4RoutingProtocolEntry& a, const Ipv4RoutingProtocolEntry& b);
115 Ptr<Ipv4> m_ipv4; //!< Ipv4 this protocol is associated with.
116};
117
118} // namespace ns3
119
120#endif /* IPV4_LIST_ROUTING_H */
Packet header for IPv4.
Definition ipv4-header.h:23
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.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ S
second
Definition nstime.h:105
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.