A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsdv-rtable.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Hemanth Narra
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Hemanth Narra <hemanth@ittc.ku.com>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 * Work supported in part by NSF FIND (Future Internet Design) Program
15 * under grant CNS-0626918 (Postmodern Internet Architecture),
16 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17 * US Department of Defense (DoD), and ITTC at The University of Kansas.
18 */
19
20#ifndef DSDV_RTABLE_H
21#define DSDV_RTABLE_H
22
23#include "ns3/ipv4-route.h"
24#include "ns3/ipv4.h"
25#include "ns3/net-device.h"
26#include "ns3/output-stream-wrapper.h"
27#include "ns3/timer.h"
28
29#include <cassert>
30#include <map>
31#include <sys/types.h>
32
33namespace ns3
34{
35namespace dsdv
36{
38{
39 VALID = 0, // !< VALID
40 INVALID = 1, // !< INVALID
41};
42
43/**
44 * \ingroup dsdv
45 * \brief Routing table entry
46 */
48{
49 public:
50 /**
51 * c-tor
52 *
53 * \param dev the net device
54 * \param dst the destination IP address
55 * \param seqNo the sequence number
56 * \param iface the interface
57 * \param hops the number of hops
58 * \param nextHop the IP address of the next hop
59 * \param lifetime the lifetime
60 * \param settlingTime the settling time
61 * \param changedEntries flag for changed entries
62 */
65 uint32_t seqNo = 0,
67 uint32_t hops = 0,
68 Ipv4Address nextHop = Ipv4Address(),
69 Time lifetime = Simulator::Now(),
70 Time settlingTime = Simulator::Now(),
71 bool changedEntries = false);
72
74
75 /**
76 * Get destination IP address
77 * \returns the destination IPv4 address
78 */
80 {
81 return m_ipv4Route->GetDestination();
82 }
83
84 /**
85 * Get route
86 * \returns the IPv4 route
87 */
89 {
90 return m_ipv4Route;
91 }
92
93 /**
94 * Set route
95 * \param route the IPv4 route
96 */
98 {
99 m_ipv4Route = route;
100 }
101
102 /**
103 * Set next hop
104 * \param nextHop the IPv4 address of the next hop
105 */
107 {
108 m_ipv4Route->SetGateway(nextHop);
109 }
110
111 /**
112 * Get next hop
113 * \returns the IPv4 address of the next hop
114 */
116 {
117 return m_ipv4Route->GetGateway();
118 }
119
120 /**
121 * Set output device
122 * \param device the output device
123 */
125 {
126 m_ipv4Route->SetOutputDevice(device);
127 }
128
129 /**
130 * Get output device
131 * \returns the output device
132 */
134 {
135 return m_ipv4Route->GetOutputDevice();
136 }
137
138 /**
139 * Get interface address
140 * \returns the IPv4 interface address
141 */
143 {
144 return m_iface;
145 }
146
147 /**
148 * Set interface address
149 * \param iface the IPv4 interface address
150 */
152 {
153 m_iface = iface;
154 }
155
156 /**
157 * Set sequence number
158 * \param sequenceNumber the sequence number
159 */
160 void SetSeqNo(uint32_t sequenceNumber)
161 {
162 m_seqNo = sequenceNumber;
163 }
164
165 /**
166 * Get sequence number
167 * \returns the sequence number
168 */
170 {
171 return m_seqNo;
172 }
173
174 /**
175 * Set hop
176 * \param hopCount the hop count
177 */
178 void SetHop(uint32_t hopCount)
179 {
180 m_hops = hopCount;
181 }
182
183 /**
184 * Get hop
185 * \returns the hop count
186 */
188 {
189 return m_hops;
190 }
191
192 /**
193 * Set lifetime
194 * \param lifeTime the lifetime value
195 */
196 void SetLifeTime(Time lifeTime)
197 {
198 m_lifeTime = lifeTime;
199 }
200
201 /**
202 * Get lifetime
203 * \returns the lifetime value
204 */
206 {
207 return (Simulator::Now() - m_lifeTime);
208 }
209
210 /**
211 * Set settling time
212 * \param settlingTime the settling time
213 */
214 void SetSettlingTime(Time settlingTime)
215 {
216 m_settlingTime = settlingTime;
217 }
218
219 /**
220 * Get settling time
221 * \returns the settling time
222 */
224 {
225 return m_settlingTime;
226 }
227
228 /**
229 * Set route flags
230 * \param flag the route flags
231 */
233 {
234 m_flag = flag;
235 }
236
237 /**
238 * Get route flags
239 * \returns the route flags
240 */
242 {
243 return m_flag;
244 }
245
246 /**
247 * Set entries changed indicator
248 * \param entriesChanged
249 */
250 void SetEntriesChanged(bool entriesChanged)
251 {
252 m_entriesChanged = entriesChanged;
253 }
254
255 /**
256 * Get entries changed
257 * \returns the entries changed flag
258 */
259 bool GetEntriesChanged() const
260 {
261 return m_entriesChanged;
262 }
263
264 /**
265 * \brief Compare destination address
266 * \param destination destination node IP address
267 * \return true if equal
268 */
269 bool operator==(const Ipv4Address destination) const
270 {
271 return (m_ipv4Route->GetDestination() == destination);
272 }
273
274 /**
275 * Print routing table entry
276 * \param stream the output stream
277 * \param unit the Time unit
278 */
279 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
280
281 private:
282 // Fields
283 /// Destination Sequence Number
285 /// Hop Count (number of hops needed to reach destination)
287 /**
288 * \brief Expiration or deletion time of the route
289 * Lifetime field in the routing table plays dual role --
290 * for an active route it is the expiration time, and for an invalid route
291 * it is the deletion time.
292 */
294 /** Ip route, include
295 * - destination address
296 * - source address
297 * - next hop address (gateway)
298 * - output device
299 */
301 /// Output interface address
303 /// Routing flags: valid, invalid or in search
305 /// Time for which the node retains an update with changed metric before broadcasting it.
306 /// A node does that in hope of receiving a better update.
308 /// Flag to show if any of the routing table entries were changed with the routing update.
310};
311
312/**
313 * \ingroup dsdv
314 * \brief The Routing table used by DSDV protocol
315 */
317{
318 public:
319 /// c-tor
320 RoutingTable();
321 /**
322 * Add routing table entry if it doesn't yet exist in routing table
323 * \param r routing table entry
324 * \return true in success
325 */
327 /**
328 * Delete routing table entry with destination address dst, if it exists.
329 * \param dst destination address
330 * \return true on success
331 */
332 bool DeleteRoute(Ipv4Address dst);
333 /**
334 * Lookup routing table entry with destination address dst
335 * \param dst destination address
336 * \param rt entry with destination address dst, if exists
337 * \return true on success
338 */
340 /**
341 * Lookup routing table entry with destination address dst
342 * \param id destination address
343 * \param rt entry with destination address dst, if exists
344 * \param forRouteInput for routing input
345 * \return true onns3 success
346 */
347 bool LookupRoute(Ipv4Address id, RoutingTableEntry& rt, bool forRouteInput);
348 /**
349 * Updating the routing Table with routing table entry rt
350 * \param rt routing table entry
351 * \return true on success
352 */
353 bool Update(RoutingTableEntry& rt);
354 /**
355 * Lookup list of addresses for which nxtHp is the next Hop address
356 * \param nxtHp nexthop's address for which we want the list of destinations
357 * \param dstList is the list that will hold all these destination addresses
358 */
360 std::map<Ipv4Address, RoutingTableEntry>& dstList);
361 /**
362 * Lookup list of all addresses in the routing table
363 * \param allRoutes is the list that will hold all these addresses present in the nodes routing
364 * table
365 */
366 void GetListOfAllRoutes(std::map<Ipv4Address, RoutingTableEntry>& allRoutes);
367 /**
368 * Delete all route from interface with address iface
369 * \param iface the interface
370 */
372
373 /// Delete all entries from routing table
374 void Clear()
375 {
376 m_ipv4AddressEntry.clear();
377 }
378
379 /**
380 * Delete all outdated entries if Lifetime is expired
381 * \param removedAddresses is the list of addresses to purge
382 */
383 void Purge(std::map<Ipv4Address, RoutingTableEntry>& removedAddresses);
384 /**
385 * Print routing table
386 * \param stream the output stream
387 * \param unit the Time unit
388 */
389 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
390 /**
391 * Provides the number of routes present in that nodes routing table.
392 * \returns the number of routes
393 */
395 /**
396 * Add an event for a destination address so that the update to for that destination is sent
397 * after the event is completed.
398 * \param address destination address for which this event is running.
399 * \param id unique eventid that was generated.
400 * \return true on success
401 */
402 bool AddIpv4Event(Ipv4Address address, EventId id);
403 /**
404 * Clear up the entry from the map after the event is completed
405 * \param address destination address for which this event is running.
406 * \return true on success
407 */
408 bool DeleteIpv4Event(Ipv4Address address);
409 /**
410 * Force delete an update waiting for settling time to complete as a better update to
411 * same destination was received.
412 * \param address destination address for which this event is running.
413 * \return true on success
414 */
415 bool AnyRunningEvent(Ipv4Address address);
416 /**
417 * Force delete an update waiting for settling time to complete as a better update to
418 * same destination was received.
419 * \param address destination address for which this event is running.
420 * \return true on finding out that an event is already running for that destination address.
421 */
422 bool ForceDeleteIpv4Event(Ipv4Address address);
423 /**
424 * Get the EventId associated with that address.
425 * \param address destination address for which this event is running.
426 * \return EventId on finding out an event is associated else return NULL.
427 */
429
430 /**
431 * Get hold down time (time until an invalid route may be deleted)
432 * \returns the hold down time
433 */
435 {
436 return m_holddownTime;
437 }
438
439 /**
440 * Set hold down time (time until an invalid route may be deleted)
441 * \param t the hold down time
442 */
444 {
445 m_holddownTime = t;
446 }
447
448 private:
449 // Fields
450 /// an entry in the routing table.
451 std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
452 /// an entry in the event table.
453 std::map<Ipv4Address, EventId> m_ipv4Events;
454 /// hold down time of an expired route
456};
457} // namespace dsdv
458} // namespace ns3
459#endif /* DSDV_RTABLE_H */
An identifier for simulation events.
Definition event-id.h:45
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
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
Routing table entry.
Definition dsdv-rtable.h:48
void SetHop(uint32_t hopCount)
Set hop.
uint32_t m_seqNo
Destination Sequence Number.
void SetLifeTime(Time lifeTime)
Set lifetime.
Ptr< NetDevice > GetOutputDevice() const
Get output device.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table entry.
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for an...
RouteFlags GetFlag() const
Get route flags.
bool GetEntriesChanged() const
Get entries changed.
void SetEntriesChanged(bool entriesChanged)
Set entries changed indicator.
Time GetSettlingTime() const
Get settling time.
Ipv4Address GetDestination() const
Get destination IP address.
Definition dsdv-rtable.h:79
void SetSettlingTime(Time settlingTime)
Set settling time.
Ptr< Ipv4Route > GetRoute() const
Get route.
Definition dsdv-rtable.h:88
RouteFlags m_flag
Routing flags: valid, invalid or in search.
void SetOutputDevice(Ptr< NetDevice > device)
Set output device.
bool m_entriesChanged
Flag to show if any of the routing table entries were changed with the routing update.
~RoutingTableEntry()
void SetNextHop(Ipv4Address nextHop)
Set next hop.
void SetRoute(Ptr< Ipv4Route > route)
Set route.
Definition dsdv-rtable.h:97
Ipv4InterfaceAddress m_iface
Output interface address.
RoutingTableEntry(Ptr< NetDevice > dev=nullptr, Ipv4Address dst=Ipv4Address(), uint32_t seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint32_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now(), Time settlingTime=Simulator::Now(), bool changedEntries=false)
c-tor
bool operator==(const Ipv4Address destination) const
Compare destination address.
Ipv4InterfaceAddress GetInterface() const
Get interface address.
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Time m_settlingTime
Time for which the node retains an update with changed metric before broadcasting it.
uint32_t GetSeqNo() const
Get sequence number.
Time GetLifeTime() const
Get lifetime.
void SetFlag(RouteFlags flag)
Set route flags.
uint32_t GetHop() const
Get hop.
uint32_t m_hops
Hop Count (number of hops needed to reach destination)
Ipv4Address GetNextHop() const
Get next hop.
void SetInterface(Ipv4InterfaceAddress iface)
Set interface address.
void SetSeqNo(uint32_t sequenceNumber)
Set sequence number.
The Routing table used by DSDV protocol.
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Time m_holddownTime
hold down time of an expired route
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
bool ForceDeleteIpv4Event(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
void Clear()
Delete all entries from routing table.
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
void Setholddowntime(Time t)
Set hold down time (time until an invalid route may be deleted)
bool DeleteIpv4Event(Ipv4Address address)
Clear up the entry from the map after the event is completed.
bool Update(RoutingTableEntry &rt)
Updating the routing Table with routing table entry rt.
Time Getholddowntime() const
Get hold down time (time until an invalid route may be deleted)
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
an entry in the routing table.
void GetListOfDestinationWithNextHop(Ipv4Address nxtHp, std::map< Ipv4Address, RoutingTableEntry > &dstList)
Lookup list of addresses for which nxtHp is the next Hop address.
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
EventId GetEventId(Ipv4Address address)
Get the EventId associated with that address.
bool AddIpv4Event(Ipv4Address address, EventId id)
Add an event for a destination address so that the update to for that destination is sent after the e...
uint32_t RoutingTableSize()
Provides the number of routes present in that nodes routing table.
std::map< Ipv4Address, EventId > m_ipv4Events
an entry in the event table.
bool AnyRunningEvent(Ipv4Address address)
Force delete an update waiting for settling time to complete as a better update to same destination w...
void Purge(std::map< Ipv4Address, RoutingTableEntry > &removedAddresses)
Delete all outdated entries if Lifetime is expired.
void GetListOfAllRoutes(std::map< Ipv4Address, RoutingTableEntry > &allRoutes)
Lookup list of all addresses in the routing table.
Every class exported by the ns3 library is enclosed in the ns3 namespace.