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