A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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
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"
41 namespace ns3 {
42 namespace aodv {
49 {
50  VALID = 0,
51  INVALID = 1,
52  IN_SEARCH = 2,
53 };
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 ());
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  //\}
103  void Invalidate (Time badLinkLifetime);
105  //\{
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  //\}
140  bool operator== (Ipv4Address const dst) const
141  {
142  return (m_ipv4Route->GetDestination () == dst);
143  }
144  void Print (Ptr<OutputStreamWrapper> stream) const;
146 private:
150  uint32_t m_seqNo;
152  uint16_t m_hops;
173  std::vector<Ipv4Address> m_precursorList;
177  uint8_t m_reqCount;
182 };
189 {
190 public:
192  RoutingTable (Time t);
194  //\{
197  //\}
203  bool AddRoute (RoutingTableEntry & r);
209  bool DeleteRoute (Ipv4Address dst);
216  bool LookupRoute (Ipv4Address dst, RoutingTableEntry & rt);
220  bool Update (RoutingTableEntry & rt);
222  bool SetEntryState (Ipv4Address dst, RouteFlags state);
224  void GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map<Ipv4Address, uint32_t> & unreachable);
232  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
236  void Clear () { m_ipv4AddressEntry.clear (); }
238  void Purge ();
244  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
246  void Print (Ptr<OutputStreamWrapper> stream) const;
248 private:
249  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
253  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
254 };
256 }
257 }
259 #endif /* AODV_RTABLE_H */
Time m_blackListTimeout
Time for which the node is put into the blacklist.
Definition: aodv-rtable.h:181
void InvalidateRoutesWithDst(std::map< Ipv4Address, uint32_t > const &unreachable)
Update routing entries with this destinations as follows:
Definition: aodv-rtable.cc:314
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
Definition: aodv-rtable.cc:420
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void SetOutputDevice(Ptr< NetDevice > dev)
RREP_ACK timer.
Definition: aodv-rtable.h:111
bool LookupRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup routing table entry with destination address dst.
Definition: aodv-rtable.cc:199
void Clear()
Delete all entries from routing table.
Definition: aodv-rtable.h:236
a simple Timer class
Definition: timer.h:45
Routing table entry.
Definition: aodv-rtable.h:59
bool Update(RoutingTableEntry &rt)
Update routing table.
Definition: aodv-rtable.cc:260
Timer m_ackTimer
RREP_ACK timer.
Definition: aodv-rtable.h:133
void IncrementRreqCnt()
RREP_ACK timer.
Definition: aodv-rtable.h:127
bool m_validSeqNo
Valid Destination Sequence Number flag.
Definition: aodv-rtable.h:148
Ptr< NetDevice > GetOutputDevice() const
RREP_ACK timer.
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:127
Definition: aodv-rtable.cc:60
void SetLifeTime(Time lt)
RREP_ACK timer.
Definition: aodv-rtable.h:121
void SetBalcklistTimeout(Time t)
RREP_ACK timer.
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:65
void Print(Ptr< OutputStreamWrapper > stream) const
Print routing table.
Definition: aodv-rtable.cc:438
Time GetLifeTime() const
RREP_ACK timer.
Definition: aodv-rtable.h:122
void SetRreqCnt(uint8_t n)
RREP_ACK timer.
Definition: aodv-rtable.h:125
bool IsPrecursorListEmpty() const
Check that precursor list empty.
Definition: aodv-rtable.cc:121
RouteFlags m_flag
Routing flags: valid, invalid or in search.
Definition: aodv-rtable.h:170
Time m_routeRequestTimout
When I can send another request.
Definition: aodv-rtable.h:175
void DeleteAllRoutesFromInterface(Ipv4InterfaceAddress iface)
Delete all route from interface with address iface.
Definition: aodv-rtable.cc:334
bool SetEntryState(Ipv4Address dst, RouteFlags state)
Set routing table entry flags.
Definition: aodv-rtable.cc:280
bool LookupPrecursor(Ipv4Address id)
Lookup precursor by address.
Definition: aodv-rtable.cc:78
Ipv4Address GetNextHop() const
RREP_ACK timer.
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:177
Ptr< SampleEmitter > s
Time m_badLinkLifetime
Deletion time for invalid routes.
Definition: aodv-rtable.h:251
bool DeletePrecursor(Ipv4Address id)
Delete precursor.
Definition: aodv-rtable.cc:95
void SetSeqNo(uint32_t sn)
RREP_ACK timer.
Definition: aodv-rtable.h:117
void SetValidSeqNo(bool s)
RREP_ACK timer.
Definition: aodv-rtable.h:115
Ptr< Ipv4Route > m_ipv4Route
Ip route, include.
Definition: aodv-rtable.h:166
Time GetBlacklistTimeout() const
RREP_ACK timer.
Definition: aodv-rtable.h:131
bool m_blackListState
Indicate if this entry is in "blacklist".
Definition: aodv-rtable.h:179
std::vector< Ipv4Address > m_precursorList
List of precursors.
Definition: aodv-rtable.h:173
Ipv4InterfaceAddress GetInterface() const
RREP_ACK timer.
Definition: aodv-rtable.h:113
Time GetBadLinkLifetime() const
Definition: aodv-rtable.h:195
void DeleteAllPrecursors()
Delete all precursors.
Definition: aodv-rtable.cc:114
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:297
void SetInterface(Ipv4InterfaceAddress iface)
RREP_ACK timer.
Definition: aodv-rtable.h:114
bool operator==(Ipv4Address const dst) const
Compare destination address.
Definition: aodv-rtable.h:140
void SetFlag(RouteFlags flag)
RREP_ACK timer.
Definition: aodv-rtable.h:123
void Invalidate(Time badLinkLifetime)
Mark entry as "down" (i.e. disable it)
Definition: aodv-rtable.cc:148
uint16_t GetHop() const
RREP_ACK timer.
Definition: aodv-rtable.h:120
void SetBadLinkLifetime(Time t)
Definition: aodv-rtable.h:196
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
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:188
Ipv4InterfaceAddress m_iface
Output interface address.
Definition: aodv-rtable.h:168
void SetUnidirectional(bool u)
RREP_ACK timer.
Definition: aodv-rtable.h:128
RoutingTable(Time t)
Definition: aodv-rtable.cc:193
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:159
Ipv4Address GetDestination(void) const
Definition: ipv4-route.cc:42
void SetHop(uint16_t hop)
RREP_ACK timer.
Definition: aodv-rtable.h:119
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
uint32_t GetSeqNo() const
RREP_ACK timer.
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:248
void SetRoute(Ptr< Ipv4Route > r)
RREP_ACK timer.
Definition: aodv-rtable.h:108
void SetNextHop(Ipv4Address nextHop)
RREP_ACK timer.
Definition: aodv-rtable.h:109
uint32_t m_seqNo
Destination Sequence Number, if m_validSeqNo = true.
Definition: aodv-rtable.h:150
uint16_t m_hops
Hop Count (number of hops needed to reach destination)
Definition: aodv-rtable.h:152
Ptr< Ipv4Route > GetRoute() const
RREP_ACK timer.
Definition: aodv-rtable.h:107
bool LookupValidRoute(Ipv4Address dst, RoutingTableEntry &rt)
Lookup route in VALID state.
Definition: aodv-rtable.cc:221
bool IsUnidirectional() const
RREP_ACK timer.
Definition: aodv-rtable.h:129
bool DeleteRoute(Ipv4Address dst)
Delete routing table entry with destination address dst, if it exists.
Definition: aodv-rtable.cc:234
void Purge()
Delete all outdated entries and invalidate valid entry if Lifetime is expired.
Definition: aodv-rtable.cc:354
std::map< Ipv4Address, RoutingTableEntry > m_ipv4AddressEntry
Definition: aodv-rtable.h:249
RouteFlags GetFlag() const
RREP_ACK timer.
Definition: aodv-rtable.h:124
Ipv4Address GetDestination() const
RREP_ACK timer.
Definition: aodv-rtable.h:106
uint8_t GetRreqCnt() const
RREP_ACK timer.
Definition: aodv-rtable.h:126
void Print(Ptr< OutputStreamWrapper > stream) const
Definition: aodv-rtable.cc:159
Route record states.
Definition: aodv-rtable.h:48
bool GetValidSeqNo() const
RREP_ACK timer.
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())
Definition: aodv-rtable.cc:46