A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-rtable.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
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 * Based on
18 * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
19 * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
20 *
21 * AODV-UU implementation by Erik Nordström of Uppsala University
22 * https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
23 *
24 * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
25 * Pavel Boyko <boyko@iitp.ru>
26 */
27#ifndef AODV_RTABLE_H
28#define AODV_RTABLE_H
29
30#include "ns3/ipv4-route.h"
31#include "ns3/ipv4.h"
32#include "ns3/net-device.h"
33#include "ns3/output-stream-wrapper.h"
34#include "ns3/timer.h"
35
36#include <cassert>
37#include <map>
38#include <stdint.h>
39#include <sys/types.h>
40
41namespace ns3
42{
43namespace aodv
44{
45
46/**
47 * \ingroup aodv
48 * \brief Route record states
49 */
51{
52 VALID = 0, //!< VALID
53 INVALID = 1, //!< INVALID
54 IN_SEARCH = 2, //!< IN_SEARCH
55};
56
57/**
58 * \ingroup aodv
59 * \brief Routing table entry
60 */
62{
63 public:
64 /**
65 * constructor
66 *
67 * \param dev the device
68 * \param dst the destination IP address
69 * \param vSeqNo verify sequence number flag
70 * \param seqNo the sequence number
71 * \param iface the interface
72 * \param hops the number of hops
73 * \param nextHop the IP address of the next hop
74 * \param lifetime the lifetime of the entry
75 */
78 bool vSeqNo = false,
79 uint32_t seqNo = 0,
81 uint16_t hops = 0,
82 Ipv4Address nextHop = Ipv4Address(),
83 Time lifetime = Simulator::Now());
84
86
87 ///\name Precursors management
88 //\{
89 /**
90 * Insert precursor in precursor list if it doesn't yet exist in the list
91 * \param id precursor address
92 * \return true on success
93 */
95 /**
96 * Lookup precursor by address
97 * \param id precursor address
98 * \return true on success
99 */
101 /**
102 * \brief Delete precursor
103 * \param id precursor address
104 * \return true on success
105 */
107 /// Delete all precursors
108 void DeleteAllPrecursors();
109 /**
110 * Check that precursor list is empty
111 * \return true if precursor list is empty
112 */
113 bool IsPrecursorListEmpty() const;
114 /**
115 * Inserts precursors in output parameter prec if they do not yet exist in vector
116 * \param prec vector of precursor addresses
117 */
118 void GetPrecursors(std::vector<Ipv4Address>& prec) const;
119 //\}
120
121 /**
122 * Mark entry as "down" (i.e. disable it)
123 * \param badLinkLifetime duration to keep entry marked as invalid
124 */
125 void Invalidate(Time badLinkLifetime);
126
127 // Fields
128 /**
129 * Get destination address function
130 * \returns the IPv4 destination address
131 */
133 {
134 return m_ipv4Route->GetDestination();
135 }
136
137 /**
138 * Get route function
139 * \returns The IPv4 route
140 */
142 {
143 return m_ipv4Route;
144 }
145
146 /**
147 * Set route function
148 * \param r the IPv4 route
149 */
151 {
152 m_ipv4Route = r;
153 }
154
155 /**
156 * Set next hop address
157 * \param nextHop the next hop IPv4 address
158 */
160 {
161 m_ipv4Route->SetGateway(nextHop);
162 }
163
164 /**
165 * Get next hop address
166 * \returns the next hop address
167 */
169 {
170 return m_ipv4Route->GetGateway();
171 }
172
173 /**
174 * Set output device
175 * \param dev The output device
176 */
178 {
179 m_ipv4Route->SetOutputDevice(dev);
180 }
181
182 /**
183 * Get output device
184 * \returns the output device
185 */
187 {
188 return m_ipv4Route->GetOutputDevice();
189 }
190
191 /**
192 * Get the Ipv4InterfaceAddress
193 * \returns the Ipv4InterfaceAddress
194 */
196 {
197 return m_iface;
198 }
199
200 /**
201 * Set the Ipv4InterfaceAddress
202 * \param iface The Ipv4InterfaceAddress
203 */
205 {
206 m_iface = iface;
207 }
208
209 /**
210 * Set the valid sequence number
211 * \param s the sequence number
212 */
213 void SetValidSeqNo(bool s)
214 {
215 m_validSeqNo = s;
216 }
217
218 /**
219 * Get the valid sequence number
220 * \returns the valid sequence number
221 */
222 bool GetValidSeqNo() const
223 {
224 return m_validSeqNo;
225 }
226
227 /**
228 * Set the sequence number
229 * \param sn the sequence number
230 */
232 {
233 m_seqNo = sn;
234 }
235
236 /**
237 * Get the sequence number
238 * \returns the sequence number
239 */
241 {
242 return m_seqNo;
243 }
244
245 /**
246 * Set the number of hops
247 * \param hop the number of hops
248 */
249 void SetHop(uint16_t hop)
250 {
251 m_hops = hop;
252 }
253
254 /**
255 * Get the number of hops
256 * \returns the number of hops
257 */
258 uint16_t GetHop() const
259 {
260 return m_hops;
261 }
262
263 /**
264 * Set the lifetime
265 * \param lt The lifetime
266 */
268 {
269 m_lifeTime = lt + Simulator::Now();
270 }
271
272 /**
273 * Get the lifetime
274 * \returns the lifetime
275 */
277 {
278 return m_lifeTime - Simulator::Now();
279 }
280
281 /**
282 * Set the route flags
283 * \param flag the route flags
284 */
286 {
287 m_flag = flag;
288 }
289
290 /**
291 * Get the route flags
292 * \returns the route flags
293 */
295 {
296 return m_flag;
297 }
298
299 /**
300 * Set the RREQ count
301 * \param n the RREQ count
302 */
303 void SetRreqCnt(uint8_t n)
304 {
305 m_reqCount = n;
306 }
307
308 /**
309 * Get the RREQ count
310 * \returns the RREQ count
311 */
312 uint8_t GetRreqCnt() const
313 {
314 return m_reqCount;
315 }
316
317 /**
318 * Increment the RREQ count
319 */
321 {
322 m_reqCount++;
323 }
324
325 /**
326 * Set the unidirectional flag
327 * \param u the uni directional flag
328 */
329 void SetUnidirectional(bool u)
330 {
332 }
333
334 /**
335 * Get the unidirectional flag
336 * \returns the unidirectional flag
337 */
338 bool IsUnidirectional() const
339 {
340 return m_blackListState;
341 }
342
343 /**
344 * Set the blacklist timeout
345 * \param t the blacklist timeout value
346 */
348 {
350 }
351
352 /**
353 * Get the blacklist timeout value
354 * \returns the blacklist timeout value
355 */
357 {
358 return m_blackListTimeout;
359 }
360
361 /// RREP_ACK timer
363
364 /**
365 * \brief Compare destination address
366 * \param dst IP address to compare
367 * \return true if equal
368 */
369 bool operator==(const Ipv4Address dst) const
370 {
371 return (m_ipv4Route->GetDestination() == dst);
372 }
373
374 /**
375 * Print packet to trace file
376 * \param stream The output stream
377 * \param unit The time unit to use (default Time::S)
378 */
379 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
380
381 private:
382 /// Valid Destination Sequence Number flag
384 /// Destination Sequence Number, if m_validSeqNo = true
386 /// Hop Count (number of hops needed to reach destination)
387 uint16_t m_hops;
388 /**
389 * \brief Expiration or deletion time of the route
390 * Lifetime field in the routing table plays dual role:
391 * for an active route it is the expiration time, and for an invalid route
392 * it is the deletion time.
393 */
395 /** Ip route, include
396 * - destination address
397 * - source address
398 * - next hop address (gateway)
399 * - output device
400 */
402 /// Output interface address
404 /// Routing flags: valid, invalid or in search
406
407 /// List of precursors
408 std::vector<Ipv4Address> m_precursorList;
409 /// When I can send another request
411 /// Number of route requests
412 uint8_t m_reqCount;
413 /// Indicate if this entry is in "blacklist"
415 /// Time for which the node is put into the blacklist
417};
418
419/**
420 * \ingroup aodv
421 * \brief The Routing table used by AODV protocol
422 */
424{
425 public:
426 /**
427 * constructor
428 * \param t the routing table entry lifetime
429 */
431
432 ///\name Handle lifetime of invalid route
433 //\{
434 /**
435 * Get the lifetime of a bad link
436 *
437 * \return the lifetime of a bad link
438 */
440 {
441 return m_badLinkLifetime;
442 }
443
444 /**
445 * Set the lifetime of a bad link
446 *
447 * \param t the lifetime of a bad link
448 */
450 {
452 }
453
454 //\}
455 /**
456 * Add routing table entry if it doesn't yet exist in routing table
457 * \param r routing table entry
458 * \return true in success
459 */
461 /**
462 * Delete routing table entry with destination address dst, if it exists.
463 * \param dst destination address
464 * \return true on success
465 */
466 bool DeleteRoute(Ipv4Address dst);
467 /**
468 * Lookup routing table entry with destination address dst
469 * \param dst destination address
470 * \param rt entry with destination address dst, if exists
471 * \return true on success
472 */
474 /**
475 * Lookup route in VALID state
476 * \param dst destination address
477 * \param rt entry with destination address dst, if exists
478 * \return true on success
479 */
481 /**
482 * Update routing table
483 * \param rt entry with destination address dst, if exists
484 * \return true on success
485 */
486 bool Update(RoutingTableEntry& rt);
487 /**
488 * Set routing table entry flags
489 * \param dst destination address
490 * \param state the routing flags
491 * \return true on success
492 */
493 bool SetEntryState(Ipv4Address dst, RouteFlags state);
494 /**
495 * Lookup routing entries with next hop Address dst and not empty list of precursors.
496 *
497 * \param nextHop the next hop IP address
498 * \param unreachable
499 */
501 std::map<Ipv4Address, uint32_t>& unreachable);
502 /**
503 * Update routing entries with this destination as follows:
504 * 1. The destination sequence number of this routing entry, if it
505 * exists and is valid, is incremented.
506 * 2. The entry is invalidated by marking the route entry as invalid
507 * 3. The Lifetime field is updated to current time plus DELETE_PERIOD.
508 * \param unreachable routes to invalidate
509 */
510 void InvalidateRoutesWithDst(const std::map<Ipv4Address, uint32_t>& unreachable);
511 /**
512 * Delete all route from interface with address iface
513 * \param iface the interface IP address
514 */
516
517 /// Delete all entries from routing table
518 void Clear()
519 {
520 m_ipv4AddressEntry.clear();
521 }
522
523 /// Delete all outdated entries and invalidate valid entry if Lifetime is expired
524 void Purge();
525 /** Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for blacklistTimeout
526 * period)
527 * \param neighbor neighbor address link to which assumed to be unidirectional
528 * \param blacklistTimeout time for which the neighboring node is put into the blacklist
529 * \return true on success
530 */
531 bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
532 /**
533 * Print routing table
534 * \param stream the output stream
535 * \param unit The time unit to use (default Time::S)
536 */
537 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
538
539 private:
540 /// The routing table
541 std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
542 /// Deletion time for invalid routes
544 /**
545 * const version of Purge, for use by Print() method
546 * \param table the routing table entry to purge
547 */
548 void Purge(std::map<Ipv4Address, RoutingTableEntry>& table) const;
549};
550
551} // namespace aodv
552} // namespace ns3
553
554#endif /* AODV_RTABLE_H */
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
A simple virtual Timer class.
Definition: timer.h:78
Routing table entry.
Definition: aodv-rtable.h:62
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:128
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:362
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodv-rtable.h:249
void SetRoute(Ptr< Ipv4Route > r)
Set route function.
Definition: aodv-rtable.h:150
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:403
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:408
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Definition: aodv-rtable.cc:135
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:79
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:414
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:383
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodv-rtable.h:186
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodv-rtable.h:312
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:195
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodv-rtable.h:159
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodv-rtable.h:267
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print packet to trace file.
Definition: aodv-rtable.cc:180
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodv-rtable.h:338
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in output parameter prec if they do not yet exist in vector.
Definition: aodv-rtable.cc:141
RouteFlags GetFlag() const
Get the route flags.
Definition: aodv-rtable.h:294
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodv-rtable.h:168
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodv-rtable.h:347
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:387
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: aodv-rtable.h:401
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodv-rtable.h:320
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:110
void SetSeqNo(uint32_t sn)
Set the sequence number.
Definition: aodv-rtable.h:231
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:204
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodv-rtable.h:303
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
Definition: aodv-rtable.cc:167
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:94
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodv-rtable.h:177
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodv-rtable.h:132
~RoutingTableEntry()
Definition: aodv-rtable.cc:74
bool operator==(const Ipv4Address dst) const
Compare destination address.
Definition: aodv-rtable.h:369
uint16_t GetHop() const
Get the number of hops.
Definition: aodv-rtable.h:258
void SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodv-rtable.h:213
Time m_routeRequestTimeout
When I can send another request.
Definition: aodv-rtable.h:410
uint32_t GetSeqNo() const
Get the sequence number.
Definition: aodv-rtable.h:240
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:385
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role: for an ...
Definition: aodv-rtable.h:394
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodv-rtable.h:329
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:416
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:405
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodv-rtable.h:222
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodv-rtable.h:285
uint8_t m_reqCount
Number of route requests.
Definition: aodv-rtable.h:412
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-rtable.h:276
Ptr< Ipv4Route > GetRoute() const
Get route function.
Definition: aodv-rtable.h:141
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodv-rtable.h:356
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:424
void GetListOfDestinationWithNextHop(Ipv4Address nextHop, std::map< Ipv4Address, uint32_t > &unreachable)
Lookup routing entries with next hop Address dst and not empty list of precursors.
Definition: aodv-rtable.cc:330
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:254
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:388
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:295
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:543
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:282
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
Definition: aodv-rtable.cc:477
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:233
void SetBadLinkLifetime(Time t)
Set the lifetime of a bad link.
Definition: aodv-rtable.h:449
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:314
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:365
Time GetBadLinkLifetime() const
Get the lifetime of a bad link.
Definition: aodv-rtable.h:439
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:518
void InvalidateRoutesWithDst(const std::map< Ipv4Address, uint32_t > &unreachable)
Update routing entries with this destination as follows:
Definition: aodv-rtable.cc:347
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
The routing table.
Definition: aodv-rtable.h:541
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:460
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:268
RouteFlags
Route record states.
Definition: aodv-rtable.h:51
@ INVALID
INVALID.
Definition: aodv-rtable.h:53
@ IN_SEARCH
IN_SEARCH.
Definition: aodv-rtable.h:54
@ VALID
VALID.
Definition: aodv-rtable.h:52
Every class exported by the ns3 library is enclosed in the ns3 namespace.