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  {
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  }
344  void Print (Ptr<OutputStreamWrapper> stream) const;
345 
346 private:
350  uint32_t m_seqNo;
352  uint16_t m_hops;
371 
373  std::vector<Ipv4Address> m_precursorList;
377  uint8_t m_reqCount;
382 };
383 
389 {
390 public:
395  RoutingTable (Time t);
397  //\{
399  {
400  return m_badLinkLifetime;
401  }
403  {
404  m_badLinkLifetime = t;
405  }
406  //\}
412  bool AddRoute (RoutingTableEntry & r);
418  bool DeleteRoute (Ipv4Address dst);
425  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
438  bool Update (RoutingTableEntry & rt);
445  bool SetEntryState (Ipv4Address dst, RouteFlags state);
452  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
461  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
468  void Clear ()
469  {
470  m_ipv4AddressEntry.clear ();
471  }
473  void Purge ();
479  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
484  void Print (Ptr<OutputStreamWrapper> stream) const;
485 
486 private:
488  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
495  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
496 };
497 
498 } // namespace aodv
499 } // namespace ns3
500 
501 #endif /* AODV_RTABLE_H */
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:381
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destination as follows:
Definition: aodv-rtable.cc:331
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:449
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetOutputDevice(Ptr< NetDevice > dev)
Set output device.
Definition: aodv-rtable.h:165
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:214
Time GetBlacklistTimeout() const
Get the blacklist timeout value.
Definition: aodv-rtable.h:324
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:468
A simple Timer class.
Definition: timer.h:73
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: aodv-rtable.cc:467
bool IsUnidirectional() const
Get the unidirectional flag.
Definition: aodv-rtable.h:308
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:277
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:329
Ipv4Address GetDestination() const
Get destination address function.
Definition: aodv-rtable.h:125
void IncrementRreqCnt()
Increment the RREQ count.
Definition: aodv-rtable.h:292
Ipv4InterfaceAddress GetInterface() const
Get the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:181
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
bool IsPrecursorListEmpty() const
Check that precursor list is empty.
Definition: aodv-rtable.cc:128
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:348
~RoutingTableEntry()
Definition: aodv-rtable.cc:65
void SetLifeTime(Time lt)
Set the lifetime.
Definition: aodv-rtable.h:245
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
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
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn&#39;t yet exist in the list.
Definition: aodv-rtable.cc:70
void SetRreqCnt(uint8_t n)
Set the RREQ count.
Definition: aodv-rtable.h:277
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:370
Time m_routeRequestTimout
When I can send another request.
Definition: aodv-rtable.h:375
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:351
void Print(Ptr< OutputStreamWrapper > stream) const
Print packet to trace file.
Definition: aodv-rtable.cc:174
void SetBlacklistTimeout(Time t)
Set the blacklist timeout.
Definition: aodv-rtable.h:316
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:297
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:85
bool GetValidSeqNo() const
Get the valid sequence number.
Definition: aodv-rtable.h:205
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
uint8_t m_reqCount
Number of route requests.
Definition: aodv-rtable.h:377
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:490
Ipv4Address GetNextHop() const
Get next hop address.
Definition: aodv-rtable.h:157
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 SetValidSeqNo(bool s)
Set the valid sequence number.
Definition: aodv-rtable.h:197
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: aodv-rtable.h:366
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:379
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:373
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:121
bool operator==(Ipv4Address const dst) const
Compare destination address.
Definition: aodv-rtable.h:336
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:314
void SetInterface(Ipv4InterfaceAddress iface)
Set the Ipv4InterfaceAddress.
Definition: aodv-rtable.h:189
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetFlag(RouteFlags flag)
Set the route flags.
Definition: aodv-rtable.h:261
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e.
Definition: aodv-rtable.cc:161
void SetBadLinkLifetime(Time t)
Definition: aodv-rtable.h:402
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
Ptr< NetDevice > GetOutputDevice() const
Get output device.
Definition: aodv-rtable.h:173
uint8_t GetRreqCnt() const
Get the RREQ count.
Definition: aodv-rtable.h:285
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:388
Time GetBadLinkLifetime() const
Definition: aodv-rtable.h:398
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:368
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
void SetUnidirectional(bool u)
Set the unidirectional flag.
Definition: aodv-rtable.h:300
RoutingTable(Time t)
constructor
Definition: aodv-rtable.cc:208
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:359
void SetHop(uint16_t hop)
Set the number of hops.
Definition: aodv-rtable.h:229
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
a class to store IPv4 address information on an interface
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn&#39;t yet exist in routing table.
Definition: aodv-rtable.cc:263
void SetRoute(Ptr< Ipv4Route > r)
Set route function.
Definition: aodv-rtable.h:141
uint16_t GetHop() const
Get the number of hops.
Definition: aodv-rtable.h:237
void SetNextHop(Ipv4Address nextHop)
Set next hop address.
Definition: aodv-rtable.h:149
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:350
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:352
RouteFlags GetFlag() const
Get the route flags.
Definition: aodv-rtable.h:269
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-rtable.h:253
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:236
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:249
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:375
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
The routing table.
Definition: aodv-rtable.h:488
RouteFlags
Route record states.
Definition: aodv-rtable.h:48