A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsdv-routing-protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Hemanth Narra, Yufei Cheng
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Hemanth Narra <hemanth@ittc.ku.com>
7 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
8 *
9 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
10 * ResiliNets Research Group https://resilinets.org/
11 * Information and Telecommunication Technology Center (ITTC)
12 * and Department of Electrical Engineering and Computer Science
13 * The University of Kansas Lawrence, KS USA.
14 *
15 * Work supported in part by NSF FIND (Future Internet Design) Program
16 * under grant CNS-0626918 (Postmodern Internet Architecture),
17 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
18 * US Department of Defense (DoD), and ITTC at The University of Kansas.
19 */
20
21#ifndef DSDV_ROUTING_PROTOCOL_H
22#define DSDV_ROUTING_PROTOCOL_H
23
24#include "dsdv-packet-queue.h"
25#include "dsdv-packet.h"
26#include "dsdv-rtable.h"
27
28#include "ns3/ipv4-interface.h"
29#include "ns3/ipv4-l3-protocol.h"
30#include "ns3/ipv4-routing-protocol.h"
31#include "ns3/node.h"
32#include "ns3/output-stream-wrapper.h"
33#include "ns3/random-variable-stream.h"
34
35namespace ns3
36{
37namespace dsdv
38{
39
40/**
41 * \ingroup dsdv
42 * \brief DSDV routing protocol.
43 */
45{
46 public:
47 /**
48 * \brief Get the type ID.
49 * \return the object TypeId
50 */
51 static TypeId GetTypeId();
52 static const uint32_t DSDV_PORT;
53
54 /// c-tor
56
57 ~RoutingProtocol() override;
58 void DoDispose() override;
59
60 // From Ipv4RoutingProtocol
62 const Ipv4Header& header,
64 Socket::SocketErrno& sockerr) override;
65 /**
66 * Route input packet
67 * \param p The packet
68 * \param header The IPv4 header
69 * \param idev The device
70 * \param ucb The unicast forward callback
71 * \param mcb The multicast forward callback
72 * \param lcb The local deliver callback
73 * \param ecb The error callback
74 * \returns true if successful
75 */
77 const Ipv4Header& header,
79 const UnicastForwardCallback& ucb,
80 const MulticastForwardCallback& mcb,
81 const LocalDeliverCallback& lcb,
82 const ErrorCallback& ecb) override;
84 Time::Unit unit = Time::S) const 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;
90
91 // Methods to handle protocol parameters
92 /**
93 * Set enable buffer flag
94 * \param f The enable buffer flag
95 */
96 void SetEnableBufferFlag(bool f);
97 /**
98 * Get enable buffer flag
99 * \returns the enable buffer flag
100 */
101 bool GetEnableBufferFlag() const;
102 /**
103 * Set weighted settling time (WST) flag
104 * \param f the weighted settling time (WST) flag
105 */
106 void SetWSTFlag(bool f);
107 /**
108 * Get weighted settling time (WST) flag
109 * \returns the weighted settling time (WST) flag
110 */
111 bool GetWSTFlag() const;
112 /**
113 * Set enable route aggregation (RA) flag
114 * \param f the enable route aggregation (RA) flag
115 */
116 void SetEnableRAFlag(bool f);
117 /**
118 * Get enable route aggregation (RA) flag
119 * \returns the enable route aggregation (RA) flag
120 */
121 bool GetEnableRAFlag() const;
122
123 /**
124 * Assign a fixed random variable stream number to the random variables
125 * used by this model. Return the number of streams (possibly zero) that
126 * have been assigned.
127 *
128 * \param stream first stream index to use
129 * \return the number of stream indices assigned by this model
130 */
131 int64_t AssignStreams(int64_t stream);
132
133 private:
134 // Protocol parameters.
135 /// Holdtimes is the multiplicative factor of PeriodicUpdateInterval for which the node waits
136 /// since the last update before flushing a route from the routing table. If
137 /// PeriodicUpdateInterval is 8s and Holdtimes is 3, the node waits for 24s since the last
138 /// update to flush this route from its routing table.
140 /// PeriodicUpdateInterval specifies the periodic time interval between which the a node
141 /// broadcasts its entire routing table.
143 /// SettlingTime specifies the time for which a node waits before propagating an update.
144 /// It waits for this time interval in hope of receiving an update with a better metric.
146 /// Nodes IP address
148 /// IP protocol
150 /// Raw socket per each IP interface, map socket -> iface address (IP + mask)
152 /// Loopback device used to defer route requests until a route is found
154 /// Main Routing table for the node
156 /// Advertised Routing table for the node
158 /// The maximum number of packets that we allow a routing protocol to buffer.
160 /// The maximum number of packets that we allow per destination to buffer.
162 /// The maximum period of time that a routing protocol is allowed to buffer a packet for.
164 /// A "drop front on full" queue used by the routing layer to buffer packets to which it does
165 /// not have a route.
167 /// Flag that is used to enable or disable buffering
169 /// Flag that is used to enable or disable Weighted Settling Time
171 /// This is the weighted factor to determine the weighted settling time
173 /// This is a flag to enable route aggregation. Route aggregation will aggregate all routes for
174 /// 'RouteAggregationTime' from the time an update is received by a node and sends them as a
175 /// single update .
177 /// Parameter that holds the route aggregation time interval
179 /// Unicast callback for own packets
181 /// Error callback for own packets
183
184 private:
185 /// Start protocol operation
186 void Start();
187 /**
188 * Queue packet until we find a route
189 * \param p the packet to route
190 * \param header the Ipv4Header
191 * \param ucb the UnicastForwardCallback function
192 * \param ecb the ErrorCallback function
193 */
195 const Ipv4Header& header,
197 ErrorCallback ecb);
198 /// Look for any queued packets to send them out
200 /**
201 * Send packet from queue
202 * \param dst - destination address to which we are sending the packet to
203 * \param route - route identified for this packet
204 */
206 /**
207 * Find socket with local interface address iface
208 * \param iface the interface
209 * \returns the socket
210 */
212
213 // Receive dsdv control packets
214 /**
215 * Receive and process dsdv control packet
216 * \param socket the socket for receiving dsdv control packets
217 */
218 void RecvDsdv(Ptr<Socket> socket);
219 /**
220 * Send a packet
221 * \param route the route
222 * \param packet the packet
223 * \param header the IPv4 header
224 */
225 void Send(Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header& header);
226
227 /**
228 * Create loopback route for given header
229 *
230 * \param header the IP header
231 * \param oif the device
232 * \returns the route
233 */
234 Ptr<Ipv4Route> LoopbackRoute(const Ipv4Header& header, Ptr<NetDevice> oif) const;
235 /**
236 * Get settlingTime for a destination
237 * \param dst - destination address
238 * \return settlingTime for the destination if found
239 */
241 /// Sends trigger update from a node
242 void SendTriggeredUpdate();
243 /// Broadcasts the entire routing table for every PeriodicUpdateInterval
244 void SendPeriodicUpdate();
245 /// Merge periodic updates
247 /**
248 * Notify that packet is dropped for some reason
249 * \param packet the dropped packet
250 * \param header the IPv4 header
251 * \param err the error number
252 */
253 void Drop(Ptr<const Packet> packet, const Ipv4Header& header, Socket::SocketErrno err);
254 /// Timer to trigger periodic updates from a node
256 /// Timer used by the trigger updates in case of Weighted Settling Time is used
258
259 /// Provides uniform random variables.
261};
262
263} // namespace dsdv
264} // namespace ns3
265
266#endif /* DSDV_ROUTING_PROTOCOL_H */
Ipv4 addresses are stored in host order in this class.
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.
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
@ S
second
Definition nstime.h:105
A simple virtual Timer class.
Definition timer.h:67
a unique identifier for an interface.
Definition type-id.h:48
void SetIpv4(Ptr< Ipv4 > ipv4) override
Timer m_triggeredExpireTimer
Timer used by the trigger updates in case of Weighted Settling Time is used.
void Send(Ptr< Ipv4Route > route, Ptr< const Packet > packet, const Ipv4Header &header)
Send a packet.
bool GetWSTFlag() const
Get weighted settling time (WST) flag.
static const uint32_t DSDV_PORT
UDP Port for DSDV control traffic.
Time m_periodicUpdateInterval
PeriodicUpdateInterval specifies the periodic time interval between which the a node broadcasts its e...
void Start()
Start protocol operation.
bool EnableBuffering
Flag that is used to enable or disable buffering.
uint32_t m_maxQueuedPacketsPerDst
The maximum number of packets that we allow per destination to buffer.
void SetEnableRAFlag(bool f)
Set enable route aggregation (RA) flag.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Provides uniform random variables.
UnicastForwardCallback m_scb
Unicast callback for own packets.
void NotifyInterfaceUp(uint32_t interface) override
void SendPeriodicUpdate()
Broadcasts the entire routing table for every PeriodicUpdateInterval.
void DoDispose() override
Destructor implementation.
PacketQueue m_queue
A "drop front on full" queue used by the routing layer to buffer packets to which it does not have a ...
void SetEnableBufferFlag(bool f)
Set enable buffer flag.
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 input packet.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void Drop(Ptr< const Packet > packet, const Ipv4Header &header, Socket::SocketErrno err)
Notify that packet is dropped for some reason.
void DeferredRouteOutput(Ptr< const Packet > p, const Ipv4Header &header, UnicastForwardCallback ucb, ErrorCallback ecb)
Queue packet until we find a route.
Ptr< NetDevice > m_lo
Loopback device used to defer route requests until a route is found.
bool GetEnableBufferFlag() const
Get enable buffer flag.
void SetWSTFlag(bool f)
Set weighted settling time (WST) flag.
Time GetSettlingTime(Ipv4Address dst)
Get settlingTime for a destination.
Timer m_periodicUpdateTimer
Timer to trigger periodic updates from a node.
Time m_routeAggregationTime
Parameter that holds the route aggregation time interval.
bool EnableRouteAggregation
This is a flag to enable route aggregation.
void SendPacketFromQueue(Ipv4Address dst, Ptr< Ipv4Route > route)
Send packet from queue.
Ptr< Ipv4 > m_ipv4
IP protocol.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
ErrorCallback m_ecb
Error callback for own packets.
Time m_maxQueueTime
The maximum period of time that a routing protocol is allowed to buffer a packet for.
std::map< Ptr< Socket >, Ipv4InterfaceAddress > m_socketAddresses
Raw socket per each IP interface, map socket -> iface address (IP + mask)
Ptr< Ipv4Route > LoopbackRoute(const Ipv4Header &header, Ptr< NetDevice > oif) const
Create loopback route for given header.
void NotifyInterfaceDown(uint32_t interface) override
static TypeId GetTypeId()
Get the type ID.
bool GetEnableRAFlag() const
Get enable route aggregation (RA) flag.
bool EnableWST
Flag that is used to enable or disable Weighted Settling Time.
Time m_settlingTime
SettlingTime specifies the time for which a node waits before propagating an update.
Ptr< Socket > FindSocketWithInterfaceAddress(Ipv4InterfaceAddress iface) const
Find socket with local interface address iface.
RoutingTable m_routingTable
Main Routing table for the node.
uint32_t Holdtimes
Holdtimes is the multiplicative factor of PeriodicUpdateInterval for which the node waits since the l...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void RecvDsdv(Ptr< Socket > socket)
Receive and process dsdv control packet.
void LookForQueuedPackets()
Look for any queued packets to send them out.
void SendTriggeredUpdate()
Sends trigger update from a node.
RoutingTable m_advRoutingTable
Advertised Routing table for the node.
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.
uint32_t m_maxQueueLen
The maximum number of packets that we allow a routing protocol to buffer.
Ipv4Address m_mainAddress
Nodes IP address.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
void MergeTriggerPeriodicUpdates()
Merge periodic updates.
double m_weightedFactor
This is the weighted factor to determine the weighted settling time.
The Routing table used by DSDV protocol.
Every class exported by the ns3 library is enclosed in the ns3 namespace.