A Discrete-Event Network Simulator
API
aodv-rtable.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Based on
19  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21  *
22  * AODV-UU implementation by Erik Nordström of Uppsala University
23  * http://core.it.uu.se/core/index.php/AODV-UU
24  *
25  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26  * Pavel Boyko <boyko@iitp.ru>
27  */
28 #ifndef AODV_RTABLE_H
29 #define AODV_RTABLE_H
30 
31 #include <stdint.h>
32 #include <cassert>
33 #include <map>
34 #include <sys/types.h>
35 #include "ns3/ipv4.h"
36 #include "ns3/ipv4-route.h"
37 #include "ns3/timer.h"
38 #include "ns3/net-device.h"
39 #include "ns3/output-stream-wrapper.h"
40 
41 namespace ns3 {
42 namespace aodv {
43 
49 {
50  VALID = 0,
51  INVALID = 1,
52  IN_SEARCH = 2,
53 };
54 
60 {
61 public:
74  RoutingTableEntry (Ptr<NetDevice> dev = 0,Ipv4Address dst = Ipv4Address (), bool vSeqNo = false, uint32_t seqNo = 0,
75  Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), uint16_t hops = 0,
76  Ipv4Address nextHop = Ipv4Address (), Time lifetime = Simulator::Now ());
77 
79 
81  //\{
87  bool InsertPrecursor (Ipv4Address id);
93  bool LookupPrecursor (Ipv4Address id);
99  bool DeletePrecursor (Ipv4Address id);
101  void DeleteAllPrecursors ();
106  bool IsPrecursorListEmpty () const;
111  void GetPrecursors (std::vector<Ipv4Address> & prec) const;
112  //\}
113 
118  void Invalidate (Time badLinkLifetime);
119 
120  // Fields
126  {
127  return m_ipv4Route->GetDestination ();
128  }
134  {
135  return m_ipv4Route;
136  }
142  {
143  m_ipv4Route = r;
144  }
149  void SetNextHop (Ipv4Address nextHop)
150  {
151  m_ipv4Route->SetGateway (nextHop);
152  }
158  {
159  return m_ipv4Route->GetGateway ();
160  }
166  {
167  m_ipv4Route->SetOutputDevice (dev);
168  }
174  {
175  return m_ipv4Route->GetOutputDevice ();
176  }
182  {
183  return m_iface;
184  }
190  {
191  m_iface = iface;
192  }
197  void SetValidSeqNo (bool s)
198  {
199  m_validSeqNo = s;
200  }
205  bool GetValidSeqNo () const
206  {
207  return m_validSeqNo;
208  }
213  void SetSeqNo (uint32_t sn)
214  {
215  m_seqNo = sn;
216  }
221  uint32_t GetSeqNo () const
222  {
223  return m_seqNo;
224  }
229  void SetHop (uint16_t hop)
230  {
231  m_hops = hop;
232  }
237  uint16_t GetHop () const
238  {
239  return m_hops;
240  }
245  void SetLifeTime (Time lt)
246  {
247  m_lifeTime = lt + Simulator::Now ();
248  }
253  Time GetLifeTime () const
254  {
255  return m_lifeTime - Simulator::Now ();
256  }
261  void SetFlag (RouteFlags flag)
262  {
263  m_flag = flag;
264  }
270  {
271  return m_flag;
272  }
277  void SetRreqCnt (uint8_t n)
278  {
279  m_reqCount = n;
280  }
285  uint8_t GetRreqCnt () const
286  {
287  return m_reqCount;
288  }
293  {
294  m_reqCount++;
295  }
300  void SetUnidirectional (bool u)
301  {
302  m_blackListState = u;
303  }
308  bool IsUnidirectional () const
309  {
310  return m_blackListState;
311  }
317  {
318  m_blackListTimeout = t;
319  }
325  {
326  return m_blackListTimeout;
327  }
330 
336  bool operator== (Ipv4Address const dst) const
337  {
338  return (m_ipv4Route->GetDestination () == dst);
339  }
345  void Print (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
346 
347 private:
351  uint32_t m_seqNo;
353  uint16_t m_hops;
372 
374  std::vector<Ipv4Address> m_precursorList;
378  uint8_t m_reqCount;
383 };
384 
390 {
391 public:
396  RoutingTable (Time t);
398  //\{
405  {
406  return m_badLinkLifetime;
407  }
414  {
415  m_badLinkLifetime = t;
416  }
417  //\}
423  bool AddRoute (RoutingTableEntry & r);
429  bool DeleteRoute (Ipv4Address dst);
436  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
449  bool Update (RoutingTableEntry & rt);
456  bool SetEntryState (Ipv4Address dst, RouteFlags state);
463  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
472  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
479  void Clear ()
480  {
481  m_ipv4AddressEntry.clear ();
482  }
484  void Purge ();
490  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
496  void Print (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
497 
498 private:
500  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
507  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
508 };
509 
510 } // namespace aodv
511 } // namespace ns3
512 
513 #endif /* AODV_RTABLE_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
a class to store IPv4 address information on an interface
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ S
second
Definition: nstime.h:114
A simple virtual Timer class.
Definition: timer.h:74
Routing table entry.
Definition: aodv-rtable.h:60
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:121
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:329
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodv-rtable.h:229
void SetRoute(Ptr< Ipv4Route > r)
Set route function.
Definition: aodv-rtable.h:141
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:369
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:374
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodv-rtable.h:173
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Definition: aodv-rtable.cc:128
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:70
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:380
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:349
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodv-rtable.h:285
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:181
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodv-rtable.h:149
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodv-rtable.h:245
bool operator==(Ipv4Address const dst) const
Compare destination address.
Definition: aodv-rtable.h:336
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print packet to trace file.
Definition: aodv-rtable.cc:174
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodv-rtable.h:308
RoutingTableEntry(Ptr< NetDevice > dev=0, 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
Definition: aodv-rtable.cc:45
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:134
RouteFlags GetFlag() const
Get the route flags.
Definition: aodv-rtable.h:269
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodv-rtable.h:157
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodv-rtable.h:316
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:353
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: aodv-rtable.h:367
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodv-rtable.h:292
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:102
void SetSeqNo(uint32_t sn)
Set the sequence number.
Definition: aodv-rtable.h:213
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:189
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodv-rtable.h:277
Time m_routeRequestTimout
When I can send another request.
Definition: aodv-rtable.h:376
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
Definition: aodv-rtable.cc:161
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:85
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodv-rtable.h:165
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodv-rtable.h:125
~RoutingTableEntry()
Definition: aodv-rtable.cc:65
uint16_t GetHop() const
Get the number of hops.
Definition: aodv-rtable.h:237
void SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodv-rtable.h:197
Ptr< Ipv4Route > GetRoute() const
Get route function.
Definition: aodv-rtable.h:133
uint32_t GetSeqNo() const
Get the sequence number.
Definition: aodv-rtable.h:221
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:351
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:360
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodv-rtable.h:300
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:382
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:371
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodv-rtable.h:205
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodv-rtable.h:261
uint8_t m_reqCount
Number of route requests.
Definition: aodv-rtable.h:378
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-rtable.h:253
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodv-rtable.h:324
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:390
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:327
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destination as follows:
Definition: aodv-rtable.cc:344
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:249
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:290
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:502
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:276
void Print(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print routing table.
Definition: aodv-rtable.cc:480
RoutingTable(Time t)
constructor
Definition: aodv-rtable.cc:221
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:227
void SetBadLinkLifetime(Time t)
Set the lifetime of a bad link.
Definition: aodv-rtable.h:413
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:310
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:364
Time GetBadLinkLifetime() const
Get the lifetime of a bad link.
Definition: aodv-rtable.h:404
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:479
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
The routing table.
Definition: aodv-rtable.h:500
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:462
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:262
RouteFlags
Route record states.
Definition: aodv-rtable.h:49
@ INVALID
INVALID.
Definition: aodv-rtable.h:51
@ IN_SEARCH
IN_SEARCH.
Definition: aodv-rtable.h:52
@ VALID
VALID.
Definition: aodv-rtable.h:50
Every class exported by the ns3 library is enclosed in the ns3 namespace.