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:
63  RoutingTableEntry (Ptr<NetDevice> dev = 0,Ipv4Address dst = Ipv4Address (), bool vSeqNo = false, uint32_t m_seqNo = 0,
64  Ipv4InterfaceAddress iface = Ipv4InterfaceAddress (), uint16_t hops = 0,
65  Ipv4Address nextHop = Ipv4Address (), Time lifetime = Simulator::Now ());
66 
68 
70  //\{
76  bool InsertPrecursor (Ipv4Address id);
82  bool LookupPrecursor (Ipv4Address id);
88  bool DeletePrecursor (Ipv4Address id);
90  void DeleteAllPrecursors ();
95  bool IsPrecursorListEmpty () const;
99  void GetPrecursors (std::vector<Ipv4Address> & prec) const;
100  //\}
101 
103  void Invalidate (Time badLinkLifetime);
104 
105  // Fields
107  Ptr<Ipv4Route> GetRoute () const { return m_ipv4Route; }
109  void SetNextHop (Ipv4Address nextHop) { m_ipv4Route->SetGateway (nextHop); }
110  Ipv4Address GetNextHop () const { return m_ipv4Route->GetGateway (); }
114  void SetInterface (Ipv4InterfaceAddress iface) { m_iface = iface; }
115  void SetValidSeqNo (bool s) { m_validSeqNo = s; }
116  bool GetValidSeqNo () const { return m_validSeqNo; }
117  void SetSeqNo (uint32_t sn) { m_seqNo = sn; }
118  uint32_t GetSeqNo () const { return m_seqNo; }
119  void SetHop (uint16_t hop) { m_hops = hop; }
120  uint16_t GetHop () const { return m_hops; }
121  void SetLifeTime (Time lt) { m_lifeTime = lt + Simulator::Now (); }
122  Time GetLifeTime () const { return m_lifeTime - Simulator::Now (); }
123  void SetFlag (RouteFlags flag) { m_flag = flag; }
124  RouteFlags GetFlag () const { return m_flag; }
125  void SetRreqCnt (uint8_t n) { m_reqCount = n; }
126  uint8_t GetRreqCnt () const { return m_reqCount; }
128  void SetUnidirectional (bool u) { m_blackListState = u; }
129  bool IsUnidirectional () const { return m_blackListState; }
134 
139  bool operator== (Ipv4Address const dst) const
140  {
141  return (m_ipv4Route->GetDestination () == dst);
142  }
143  void Print (Ptr<OutputStreamWrapper> stream) const;
144 
145 private:
149  uint32_t m_seqNo;
151  uint16_t m_hops;
170 
172  std::vector<Ipv4Address> m_precursorList;
176  uint8_t m_reqCount;
181 };
182 
188 {
189 public:
191  RoutingTable (Time t);
193  //\{
196  //\}
202  bool AddRoute (RoutingTableEntry & r);
208  bool DeleteRoute (Ipv4Address dst);
215  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
219  bool Update (RoutingTableEntry & rt);
221  bool SetEntryState (Ipv4Address dst, RouteFlags state);
223  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
231  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
235  void Clear () { m_ipv4AddressEntry.clear (); }
237  void Purge ();
243  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
245  void Print (Ptr<OutputStreamWrapper> stream) const;
246 
247 private:
248  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
252  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
253 };
254 
255 }
256 }
257 
258 #endif /* AODV_RTABLE_H */
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:180
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destinations as follows:
Definition: aodv-rtable.cc:315
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:421
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetOutputDevice(Ptr< NetDevice > dev)
Definition: aodv-rtable.h:111
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:200
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:235
A simple Timer class.
Definition: timer.h:73
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:261
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:133
void IncrementRreqCnt()
Definition: aodv-rtable.h:127
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:147
Ptr< NetDevice > GetOutputDevice() const
Definition: aodv-rtable.h:112
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Inserts precursors in vector prec if they does not yet exist in vector.
Definition: aodv-rtable.cc:128
~RoutingTableEntry()
Definition: aodv-rtable.cc:61
void SetLifeTime(Time lt)
Definition: aodv-rtable.h:121
void SetBalcklistTimeout(Time t)
Definition: aodv-rtable.h:130
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
bool InsertPrecursor(Ipv4Address id)
Insert precursor in precursor list if it doesn't yet exist in the list.
Definition: aodv-rtable.cc:66
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: aodv-rtable.cc:439
Time GetLifeTime() const
Definition: aodv-rtable.h:122
void SetRreqCnt(uint8_t n)
Definition: aodv-rtable.h:125
bool IsPrecursorListEmpty() const
Check that precursor list empty.
Definition: aodv-rtable.cc:122
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:169
Time m_routeRequestTimout
When I can send another request.
Definition: aodv-rtable.h:174
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:335
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:281
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:79
Ipv4Address GetNextHop() const
Definition: aodv-rtable.h:110
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
uint8_t m_reqCount
Number of route requests.
Definition: aodv-rtable.h:176
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:250
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:96
void SetSeqNo(uint32_t sn)
Definition: aodv-rtable.h:117
void SetValidSeqNo(bool s)
Definition: aodv-rtable.h:115
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: aodv-rtable.h:165
Time GetBlacklistTimeout() const
Definition: aodv-rtable.h:131
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:178
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:172
Ipv4InterfaceAddress GetInterface() const
Definition: aodv-rtable.h:113
Time GetBadLinkLifetime() const
Definition: aodv-rtable.h:194
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:115
Ipv4Address GetGateway(void) const
Definition: ipv4-route.cc:70
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:298
void SetInterface(Ipv4InterfaceAddress iface)
Definition: aodv-rtable.h:114
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(Ipv4Address const dst) const
Compare destination address.
Definition: aodv-rtable.h:139
void SetFlag(RouteFlags flag)
Definition: aodv-rtable.h:123
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: aodv-rtable.cc:149
uint16_t GetHop() const
Definition: aodv-rtable.h:120
void SetBadLinkLifetime(Time t)
Definition: aodv-rtable.h:195
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
Definition: ipv4-route.cc:77
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:187
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:167
void SetUnidirectional(bool u)
Definition: aodv-rtable.h:128
RoutingTable(Time t)
c-tor
Definition: aodv-rtable.cc:194
Time m_lifeTime
Expiration or deletion time of the route Lifetime field in the routing table plays dual role – for a...
Definition: aodv-rtable.h:158
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
void SetHop(uint16_t hop)
Definition: aodv-rtable.h:119
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
uint32_t GetSeqNo() const
Definition: aodv-rtable.h:118
bool AddRoute(RoutingTableEntry &r)
Add routing table entry if it doesn't yet exist in routing table.
Definition: aodv-rtable.cc:249
void SetRoute(Ptr< Ipv4Route > r)
Definition: aodv-rtable.h:108
void SetNextHop(Ipv4Address nextHop)
Definition: aodv-rtable.h:109
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:149
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:151
Ptr< Ipv4Route > GetRoute() const
Definition: aodv-rtable.h:107
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:222
bool IsUnidirectional() const
Definition: aodv-rtable.h:129
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:235
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:355
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
Definition: aodv-rtable.h:248
RouteFlags GetFlag() const
Definition: aodv-rtable.h:124
Ipv4Address GetDestination() const
Definition: aodv-rtable.h:106
uint8_t GetRreqCnt() const
Definition: aodv-rtable.h:126
void Print(Ptr< OutputStreamWrapper > stream) const
Definition: aodv-rtable.cc:160
RouteFlags
Route record states.
Definition: aodv-rtable.h:48
bool GetValidSeqNo() const
Definition: aodv-rtable.h:116
RoutingTableEntry(Ptr< NetDevice > dev=0, Ipv4Address dst=Ipv4Address(), bool vSeqNo=false, uint32_t m_seqNo=0, Ipv4InterfaceAddress iface=Ipv4InterfaceAddress(), uint16_t hops=0, Ipv4Address nextHop=Ipv4Address(), Time lifetime=Simulator::Now())
c-to
Definition: aodv-rtable.cc:47