A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dsr-rreq-table.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Yufei Cheng
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  * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  * Work supported in part by NSF FIND (Future Internet Design) Program
27  * under grant CNS-0626918 (Postmodern Internet Architecture),
28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
30  */
31 
32 #ifndef DSR_RREQ_TABLE_H
33 #define DSR_RREQ_TABLE_H
34 
35 #include "ns3/simulator.h"
36 #include "ns3/timer.h"
37 #include "ns3/ipv4-address.h"
38 #include "ns3/callback.h"
39 #include <list>
40 #include <vector>
41 #include <map>
42 
43 namespace ns3 {
44 namespace dsr {
45 
47 {
48  PROBABLE = 0, // !< PROBABLE
49  QUESTIONABLE = 1, // !< QUESTIONABLE
50 };
51 // / BlackList description
52 struct BlackList
53 {
57 
59  : m_neighborAddress (ip),
60  m_expireTime (t),
62  {
63  }
64 };
69 {
70  uint32_t m_reqNo;
72 };
78 {
79 public:
80  // / c-tor
81  ReceivedRreqEntry (Ipv4Address d = Ipv4Address (), uint16_t i = 0)
82  : m_destination (d),
84  {
85  }
90  bool operator== (ReceivedRreqEntry const & o) const
91  {
93  );
94  }
95  // /\name Fields
96  // \{
98  {
99  return m_destination;
100  }
102  {
103  m_destination = d;
104  }
106  {
107  return m_source;
108  }
110  {
111  m_source = s;
112  }
113  uint16_t GetIdentification () const
114  {
115  return m_identification;
116  }
117  void SetIdentification (uint16_t i)
118  {
119  m_identification = i;
120  }
121  void SetExpireTime (Time exp)
122  {
123  m_expire = exp + Simulator::Now ();
124  }
126  {
127  return m_expire - Simulator::Now ();
128  }
129  // \}
130 private:
135 };
136 
141 class RreqTable : public Object
142 {
143 public:
144  // / c-tor
149  static TypeId GetTypeId ();
153  RreqTable ();
157  virtual ~RreqTable ();
158 
159  // /\name Fields
160  // \{
161  void SetInitHopLimit (uint32_t hl)
162  {
163  m_initHopLimit = hl;
164  }
165  uint32_t GetInitHopLimit () const
166  {
167  return m_initHopLimit;
168  }
169  void SetRreqTableSize (uint32_t rt)
170  {
171  m_requestTableSize = rt;
172  }
173  uint32_t GetRreqTableSize () const
174  {
175  return m_requestTableSize;
176  }
177  void SetRreqIdSize (uint32_t id)
178  {
179  m_requestIdSize = id;
180  }
181  uint32_t GetRreqIdSize () const
182  {
183  return m_requestIdSize;
184  }
185  void SetUniqueRreqIdSize (uint32_t uid)
186  {
187  m_maxRreqId = uid;
188  }
189  uint32_t GetUniqueRreqIdSize () const
190  {
191  return m_maxRreqId;
192  }
193 
194  // \}
195  // / Remove the least used entry
196  void RemoveLeastExpire (std::map<Ipv4Address, RreqTableEntry > & rreqDstMap);
197  // / Find the entry in the route request queue to see if already exists
198  void FindAndUpdate (Ipv4Address dst);
199  // / Remove route request entry for dst
200  void RemoveRreqEntry (Ipv4Address dst);
201  // / Get the request count number for one destination address
202  uint32_t GetRreqCnt (Ipv4Address dst);
203  //----------------------------------------------------------------------------------------------------------
207  // / Check for duplicate ids and save new entries if the id is not present in the table
208  uint32_t CheckUniqueRreqId (Ipv4Address dst);
209  // / Get the request id size
210  uint32_t GetRreqSize ();
211  // ---------------------------------------------------------------------------------------------------------
215  void Invalidate ();
228  bool MarkLinkAsUnidirectional (Ipv4Address neighbor, Time blacklistTimeout);
230  void PurgeNeighbor ();
231  // ----------------------------------------------------------------------------------------------------------
238  bool FindSourceEntry (Ipv4Address src, Ipv4Address dst, uint16_t id);
239 
240 private:
241  // / The max request period among requests
243  // / The original request period
245  // / The non-propagaton request timeout
247  // / The source route entry expire time
249  // / The initial hop limit
250  uint32_t m_initHopLimit;
251  // / The request table size
253  // / The request source id size
254  uint32_t m_requestIdSize;
255  // / The unique request id for any destination
256  uint32_t m_maxRreqId;
257  // / The state of the unidirectional link
259  // / Map of entries
260  std::list<ReceivedRreqEntry> m_sourceRequests;
261  // / The id cache to ensure all the ids are unique, it is used when sending out route request
262  std::map<Ipv4Address, uint32_t> m_rreqIdCache;
263  // / The cache to save route request table entries indexed with destination address
264  std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap;
265  // / The cache to ensure all the route request from unique source
266  std::map<Ipv4Address, std::list<ReceivedRreqEntry> > m_sourceRreqMap;
267 
268  // / The Black list
269  std::vector<BlackList> m_blackList;
270  // / Check if the entry is expired or not
271  struct IsExpired
272  {
273  bool operator() (const struct BlackList & b) const
274  {
275  return (b.m_expireTime < Simulator::Now ());
276  }
277  };
278 };
279 } // namespace dsr
280 } // namespace ns3
281 
282 #endif /* DSR_RREQ_TABLE_H */
std::list< ReceivedRreqEntry > m_sourceRequests
Ipv4Address m_neighborAddress
uint32_t m_reqNo
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t GetRreqCnt(Ipv4Address dst)
std::map< Ipv4Address, std::list< ReceivedRreqEntry > > m_sourceRreqMap
Time m_expire
std::map< Ipv4Address, RreqTableEntry > m_rreqDstMap
void SetRreqTableSize(uint32_t rt)
void SetIdentification(uint16_t i)
ReceivedRreqEntry(Ipv4Address d=Ipv4Address(), uint16_t i=0)
uint16_t m_identification
void SetRreqIdSize(uint32_t id)
void RemoveLeastExpire(std::map< Ipv4Address, RreqTableEntry > &rreqDstMap)
static TypeId GetTypeId()
Get the type identificator.
void FindAndUpdate(Ipv4Address dst)
Ipv4Address GetDestination() const
std::vector< BlackList > m_blackList
void SetDestination(Ipv4Address d)
uint32_t GetRreqTableSize() const
Ptr< SampleEmitter > s
Ipv4Address m_destination
uint32_t GetUniqueRreqIdSize() const
void SetUniqueRreqIdSize(uint32_t uid)
uint32_t GetInitHopLimit() const
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for blacklistTimeout period) ...
void SetSource(Ipv4Address s)
virtual ~RreqTable()
Destructor.
bool operator==(ReceivedRreqEntry const &o) const
Compare send buffer entries.
std::map< Ipv4Address, uint32_t > m_rreqIdCache
void SetInitHopLimit(uint32_t hl)
Ipv4Address m_source
uint32_t GetRreqIdSize() const
maintain list of RreqTable entry
void RemoveRreqEntry(Ipv4Address dst)
static Time Now(void)
Definition: simulator.cc:180
BlackList * FindUnidirectional(Ipv4Address neighbor)
Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for blacklistTimeout p...
uint16_t GetIdentification() const
bool operator()(const struct BlackList &b) const
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
BlackList(Ipv4Address ip, Time t)
bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id)
Time GetExpireTime() const
Time m_expire
LinkStates m_linkStates
a base class which provides memory management and object aggregation
Definition: object.h:63
void SetExpireTime(Time exp)
a unique identifier for an interface.
Definition: type-id.h:49
RreqTable()
Constructor.
uint32_t CheckUniqueRreqId(Ipv4Address dst)
Ipv4Address GetSource() const