A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aodv-rtable.h
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  uint16_t channelNo = 1);
67 
69 
71  //\{
77  bool InsertPrecursor (Ipv4Address id);
83  bool LookupPrecursor (Ipv4Address id);
89  bool DeletePrecursor (Ipv4Address id);
91  void DeleteAllPrecursors ();
96  bool IsPrecursorListEmpty () const;
100  void GetPrecursors (std::vector<Ipv4Address> & prec) const;
101  //\}
102 
104  void Invalidate (Time badLinkLifetime);
106  //\{
107  Ipv4Address GetDestination () const { return m_ipv4Route->GetDestination (); }
108  Ptr<Ipv4Route> GetRoute () const { return m_ipv4Route; }
109  void SetRoute (Ptr<Ipv4Route> r) { m_ipv4Route = r; }
110  void SetNextHop (Ipv4Address nextHop) { m_ipv4Route->SetGateway (nextHop); }
111  Ipv4Address GetNextHop () const { return m_ipv4Route->GetGateway (); }
112  void SetOutputDevice (Ptr<NetDevice> dev) { m_ipv4Route->SetOutputDevice (dev); }
113  Ptr<NetDevice> GetOutputDevice () const { return m_ipv4Route->GetOutputDevice (); }
114  Ipv4InterfaceAddress GetInterface () const { return m_iface; }
115  void SetInterface (Ipv4InterfaceAddress iface) { m_iface = iface; }
116  void SetValidSeqNo (bool s) { m_validSeqNo = s; }
117  bool GetValidSeqNo () const { return m_validSeqNo; }
118  void SetSeqNo (uint32_t sn) { m_seqNo = sn; }
119  uint32_t GetSeqNo () const { return m_seqNo; }
120  void SetHop (uint16_t hop) { m_hops = hop; }
121  uint16_t GetHop () const { return m_hops; }
122  void SetChannel (uint16_t channel) { m_channel = channel; }
123  uint16_t GetChannel () const { return m_channel; }
124  void SetLifeTime (Time lt) { m_lifeTime = lt + Simulator::Now (); }
125  Time GetLifeTime () const { return m_lifeTime - Simulator::Now (); }
126  void SetFlag (RouteFlags flag) { m_flag = flag; }
127  RouteFlags GetFlag () const { return m_flag; }
128  void SetRreqCnt (uint8_t n) { m_reqCount = n; }
129  uint8_t GetRreqCnt () const { return m_reqCount; }
130  void IncrementRreqCnt () { m_reqCount++; }
131  void SetUnidirectional (bool u) { m_blackListState = u; }
132  bool IsUnidirectional () const { return m_blackListState; }
133  void SetBalcklistTimeout (Time t) { m_blackListTimeout = t; }
134  Time GetBlacklistTimeout () const { return m_blackListTimeout; }
137  //\}
138 
143  bool operator== (Ipv4Address const dst) const
144  {
145  return (m_ipv4Route->GetDestination () == dst);
146  }
147  void Print (Ptr<OutputStreamWrapper> stream) const;
148 
149 private:
153  uint32_t m_seqNo;
155  uint16_t m_hops;
174 
176  std::vector<Ipv4Address> m_precursorList;
180  uint8_t m_reqCount;
186  uint16_t m_channel;
187 };
188 
194 {
195 public:
197  RoutingTable (Time t);
199  //\{
200  Time GetBadLinkLifetime () const { return m_badLinkLifetime; }
201  void SetBadLinkLifetime (Time t) { m_badLinkLifetime = t; }
202  //\}
208  bool AddRoute (RoutingTableEntry & r);
214  bool DeleteRoute (Ipv4Address dst);
221  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
225  bool Update (RoutingTableEntry & rt);
227  bool SetEntryState (Ipv4Address dst, RouteFlags state);
229  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
237  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
241  void Clear () { m_ipv4AddressEntry.clear (); }
243  void Purge ();
249  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
251  void Print (Ptr<OutputStreamWrapper> stream) const;
252 
253 private:
254  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
258  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
259 };
260 
261 }
262 }
263 
264 #endif /* AODV_RTABLE_H */
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:184
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Definition: aodv-rtable.cc:316
keep track of time unit.
Definition: nstime.h:149
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Definition: aodv-rtable.cc:422
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Definition: aodv-rtable.cc:201
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:241
a simple Timer class
Definition: timer.h:45
uint16_t m_channel
Channel number for route's destination.
Definition: aodv-rtable.h:186
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:262
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:136
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:151
void GetPrecursors(std::vector< Ipv4Address > &prec) const
Definition: aodv-rtable.cc:129
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
bool InsertPrecursor(Ipv4Address id)
Definition: aodv-rtable.cc:67
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: aodv-rtable.cc:440
bool IsPrecursorListEmpty() const
Definition: aodv-rtable.cc:123
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:173
Time m_routeRequestTimout
When I can send another request.
Definition: aodv-rtable.h:178
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:336
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:282
bool LookupPrecursor(Ipv4Address id)
Definition: aodv-rtable.cc:80
void SetGateway(Ipv4Address gw)
Definition: ipv4-route.cc:63
uint8_t m_reqCount
Number of route requests.
Definition: aodv-rtable.h:180
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:256
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:97
Ptr< Ipv4Route > m_ipv4Route
Definition: aodv-rtable.h:169
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:182
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:176
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:116
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:299
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(), uint16_t channelNo=1)
c-to
Definition: aodv-rtable.cc:46
bool operator==(Ipv4Address const dst) const
Compare destination address.
Definition: aodv-rtable.h:143
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: aodv-rtable.cc:150
static Time Now(void)
Definition: simulator.cc:179
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Definition: ipv4-route.cc:77
The Routing table used by AODV protocol.
Definition: aodv-rtable.h:193
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:171
RoutingTable(Time t)
c-tor
Definition: aodv-rtable.cc:195
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:162
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
a class to store IPv4 address information on an interface
bool AddRoute(RoutingTableEntry &r)
Definition: aodv-rtable.cc:250
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:153
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:155
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:223
bool DeleteRoute(Ipv4Address dst)
Definition: aodv-rtable.cc:236
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:356
RouteFlags
Route record states.
Definition: aodv-rtable.h:48