A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-routing-protocol.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#ifndef IPV4_ROUTING_PROTOCOL_H
7#define IPV4_ROUTING_PROTOCOL_H
8
9#include "ipv4-header.h"
11#include "ipv4.h"
12
13#include "ns3/callback.h"
14#include "ns3/nstime.h"
15#include "ns3/object.h"
16#include "ns3/output-stream-wrapper.h"
17#include "ns3/packet.h"
18#include "ns3/socket.h"
19
20namespace ns3
21{
22
23class Ipv4MulticastRoute;
24class Ipv4Route;
25class NetDevice;
26
27/**
28 * \ingroup internet
29 * \defgroup ipv4Routing IPv4 Routing Protocols.
30 *
31 * The classes in this group implement different routing protocols
32 * for IPv4. Other modules could implement further protocols
33 * (e.g., AODV, OLSR, etc.).
34 */
35
36/**
37 * \ingroup ipv4Routing
38 * \brief Abstract base class for IPv4 routing protocols.
39 *
40 * Defines two virtual functions for packet routing and forwarding. The first,
41 * RouteOutput(), is used for locally originated packets, and the second,
42 * RouteInput(), is used for forwarding and/or delivering received packets.
43 * Also defines the signatures of four callbacks used in RouteInput().
44 *
45 */
47{
48 public:
49 /**
50 * \brief Get the type ID.
51 * \return the object TypeId
52 */
53 static TypeId GetTypeId();
54
55 /// Callback for unicast packets to be forwarded
58
59 /// Callback for multicast packets to be forwarded
62
63 /// Callback for packets to be locally delivered
65
66 /// Callback for routing errors (e.g., no route found)
68
69 /**
70 * \brief Query routing cache for an existing route, for an outbound packet
71 *
72 * This lookup is used by transport protocols. It does not cause any
73 * packet to be forwarded, and is synchronous. Can be used for
74 * multicast or unicast. The Linux equivalent is ip_route_output()
75 *
76 * The header input parameter may have an uninitialized value
77 * for the source address, but the destination address should always be
78 * properly set by the caller.
79 *
80 * \param p packet to be routed. Note that this method may modify the packet.
81 * Callers may also pass in a null pointer.
82 * \param header input parameter (used to form key to search for the route)
83 * \param oif Output interface Netdevice. May be zero, or may be bound via
84 * socket options to a particular output interface.
85 * \param sockerr Output parameter; socket errno
86 *
87 * \returns a code that indicates what happened in the lookup
88 */
90 const Ipv4Header& header,
92 Socket::SocketErrno& sockerr) = 0;
93
94 /**
95 * \brief Route an input packet (to be forwarded or locally delivered)
96 *
97 * This lookup is used in the forwarding process. The packet is
98 * handed over to the Ipv4RoutingProtocol, and will get forwarded onward
99 * by one of the callbacks. The Linux equivalent is ip_route_input().
100 * There are four valid outcomes, and a matching callbacks to handle each.
101 *
102 * \param p received packet
103 * \param header input parameter used to form a search key for a route
104 * \param idev Pointer to ingress network device
105 * \param ucb Callback for the case in which the packet is to be forwarded
106 * as unicast
107 * \param mcb Callback for the case in which the packet is to be forwarded
108 * as multicast
109 * \param lcb Callback for the case in which the packet is to be locally
110 * delivered
111 * \param ecb Callback to call if there is an error in forwarding
112 * \returns true if the Ipv4RoutingProtocol takes responsibility for
113 * forwarding or delivering the packet, false otherwise
114 */
116 const Ipv4Header& header,
118 const UnicastForwardCallback& ucb,
119 const MulticastForwardCallback& mcb,
120 const LocalDeliverCallback& lcb,
121 const ErrorCallback& ecb) = 0;
122
123 /**
124 * \param interface the index of the interface we are being notified about
125 *
126 * Protocols are expected to implement this method to be notified of the state change of
127 * an interface in a node.
128 */
129 virtual void NotifyInterfaceUp(uint32_t interface) = 0;
130 /**
131 * \param interface the index of the interface we are being notified about
132 *
133 * Protocols are expected to implement this method to be notified of the state change of
134 * an interface in a node.
135 */
136 virtual void NotifyInterfaceDown(uint32_t interface) = 0;
137
138 /**
139 * \param interface the index of the interface we are being notified about
140 * \param address a new address being added to an interface
141 *
142 * Protocols are expected to implement this method to be notified whenever
143 * a new address is added to an interface. Typically used to add a 'network route' on an
144 * interface. Can be invoked on an up or down interface.
145 */
146 virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) = 0;
147
148 /**
149 * \param interface the index of the interface we are being notified about
150 * \param address a new address being added to an interface
151 *
152 * Protocols are expected to implement this method to be notified whenever
153 * a new address is removed from an interface. Typically used to remove the 'network route' of
154 * an interface. Can be invoked on an up or down interface.
155 */
156 virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) = 0;
157
158 /**
159 * \param ipv4 the ipv4 object this routing protocol is being associated with
160 *
161 * Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol
162 */
163 virtual void SetIpv4(Ptr<Ipv4> ipv4) = 0;
164
165 /**
166 * \brief Print the Routing Table entries
167 *
168 * \param stream The ostream the Routing table is printed to
169 * \param unit The time unit to be used in the report
170 */
172 Time::Unit unit = Time::S) const = 0;
173};
174
175} // namespace ns3
176
177#endif /* IPV4_ROUTING_PROTOCOL_H */
Callback template class.
Definition callback.h:422
Packet header for IPv4.
Definition ipv4-header.h:23
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual 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)=0
Route an input packet (to be forwarded or locally delivered)
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const Ipv4Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv4Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
Callback< void, Ptr< Ipv4Route >, Ptr< const Packet >, const Ipv4Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const =0
Print the Routing Table entries.
virtual void NotifyInterfaceDown(uint32_t interface)=0
Callback< void, Ptr< const Packet >, const Ipv4Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found)
virtual void NotifyInterfaceUp(uint32_t interface)=0
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)=0
Query routing cache for an existing route, for an outbound packet.
static TypeId GetTypeId()
Get the type ID.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual void SetIpv4(Ptr< Ipv4 > ipv4)=0
A base class which provides memory management and object aggregation.
Definition object.h:78
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.