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
51{
52 VALID = 0,
53 INVALID = 1,
55};
56
62{
63 public:
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
88 //\{
108 void DeleteAllPrecursors();
113 bool IsPrecursorListEmpty() const;
118 void GetPrecursors(std::vector<Ipv4Address>& prec) const;
119 //\}
120
125 void Invalidate(Time badLinkLifetime);
126
127 // Fields
133 {
134 return m_ipv4Route->GetDestination();
135 }
136
142 {
143 return m_ipv4Route;
144 }
145
151 {
152 m_ipv4Route = r;
153 }
154
160 {
161 m_ipv4Route->SetGateway(nextHop);
162 }
163
169 {
170 return m_ipv4Route->GetGateway();
171 }
172
178 {
179 m_ipv4Route->SetOutputDevice(dev);
180 }
181
187 {
188 return m_ipv4Route->GetOutputDevice();
189 }
190
196 {
197 return m_iface;
198 }
199
205 {
206 m_iface = iface;
207 }
208
213 void SetValidSeqNo(bool s)
214 {
215 m_validSeqNo = s;
216 }
217
222 bool GetValidSeqNo() const
223 {
224 return m_validSeqNo;
225 }
226
232 {
233 m_seqNo = sn;
234 }
235
241 {
242 return m_seqNo;
243 }
244
249 void SetHop(uint16_t hop)
250 {
251 m_hops = hop;
252 }
253
258 uint16_t GetHop() const
259 {
260 return m_hops;
261 }
262
268 {
269 m_lifeTime = lt + Simulator::Now();
270 }
271
277 {
278 return m_lifeTime - Simulator::Now();
279 }
280
286 {
287 m_flag = flag;
288 }
289
295 {
296 return m_flag;
297 }
298
303 void SetRreqCnt(uint8_t n)
304 {
305 m_reqCount = n;
306 }
307
312 uint8_t GetRreqCnt() const
313 {
314 return m_reqCount;
315 }
316
321 {
322 m_reqCount++;
323 }
324
329 void SetUnidirectional(bool u)
330 {
332 }
333
338 bool IsUnidirectional() const
339 {
340 return m_blackListState;
341 }
342
348 {
350 }
351
357 {
358 return m_blackListTimeout;
359 }
360
363
369 bool operator==(const Ipv4Address dst) const
370 {
371 return (m_ipv4Route->GetDestination() == dst);
372 }
373
379 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
380
381 private:
387 uint16_t m_hops;
406
408 std::vector<Ipv4Address> m_precursorList;
412 uint8_t m_reqCount;
417};
418
424{
425 public:
431
433 //\{
440 {
441 return m_badLinkLifetime;
442 }
443
450 {
452 }
453
454 //\}
466 bool DeleteRoute(Ipv4Address dst);
486 bool Update(RoutingTableEntry& rt);
493 bool SetEntryState(Ipv4Address dst, RouteFlags state);
501 std::map<Ipv4Address, uint32_t>& unreachable);
510 void InvalidateRoutesWithDst(const std::map<Ipv4Address, uint32_t>& unreachable);
516
518 void Clear()
519 {
520 m_ipv4AddressEntry.clear();
521 }
522
524 void Purge();
531 bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
537 void Print(Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
538
539 private:
541 std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
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:78
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
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:74
Routing table entry.
Definition: aodv-rtable.h:62
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:131
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:138
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:184
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:144
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:112
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:171
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:336
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:258
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:401
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:300
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:286
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
Definition: aodv-rtable.cc:491
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:237
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:320
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:377
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:355
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:474
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:272
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.