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