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