A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsr-rreq-table.h
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 
46 enum LinkStates
47 {
48  PROBABLE = 0, // !< PROBABLE
49  QUESTIONABLE = 1, // !< QUESTIONABLE
50 };
51 // / BlackList description
52 struct BlackList
53 {
54  Ipv4Address m_neighborAddress;
55  Time m_expireTime;
56  LinkStates m_linkStates;
57 
58  BlackList (Ipv4Address ip, Time t)
59  : m_neighborAddress (ip),
60  m_expireTime (t),
61  m_linkStates (PROBABLE)
62  {
63  }
64 };
69 {
70  uint32_t m_reqNo;
71  Time m_expire;
72 };
78 {
79 public:
80  // / c-tor
81  ReceivedRreqEntry (Ipv4Address d = Ipv4Address (), uint16_t i = 0)
82  : m_destination (d),
83  m_identification (i)
84  {
85  }
90  bool operator== (ReceivedRreqEntry const & o) const
91  {
92  return ((m_destination == o.m_destination) && (m_identification == o.m_identification)
93  );
94  }
95  // /\name Fields
96  // \{
97  Ipv4Address GetDestination () const
98  {
99  return m_destination;
100  }
101  void SetDestination (Ipv4Address d)
102  {
103  m_destination = d;
104  }
105  Ipv4Address GetSource () const
106  {
107  return m_source;
108  }
109  void SetSource (Ipv4Address s)
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  }
125  Time GetExpireTime () const
126  {
127  return m_expire - Simulator::Now ();
128  }
129  // \}
130 private:
131  Ipv4Address m_destination;
132  Ipv4Address m_source;
133  uint16_t m_identification;
134  Time m_expire;
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 
242  // / The max # of requests to retransmit
243  uint32_t MaxRequestRexmt;
244  // / The max request period among requests
245  Time MaxRequestPeriod;
246  // / The original request period
247  Time RequestPeriod;
248  // / The non-propagaton request timeout
249  Time NonpropRequestTimeout;
250  // / The source route entry expire time
251  Time m_rreqEntryExpire;
252  // / The initial hop limit
253  uint32_t m_initHopLimit;
254  // / The request table size
255  uint32_t m_requestTableSize;
256  // / The request source id size
257  uint32_t m_requestIdSize;
258  // / The unique request id for any destination
259  uint32_t m_maxRreqId;
260  // / The state of the unidirectional link
261  LinkStates m_linkStates;
262  // / Map of entries
263  std::list<ReceivedRreqEntry> m_sourceRequests;
264  // / The id cache to ensure all the ids are unique, it is used when sending out route request
265  std::map<Ipv4Address, uint32_t> m_rreqIdCache;
266  // / The cache to save route request table entries indexed with destination address
267  std::map<Ipv4Address, RreqTableEntry > m_rreqDstMap;
268  // / The cache to ensure all the route request from unique source
269  std::map<Ipv4Address, std::list<ReceivedRreqEntry> > m_sourceRreqMap;
270 
271  // / The Black list
272  std::vector<BlackList> m_blackList;
273  // / Check if the entry is expired or not
274  struct IsExpired
275  {
276  bool operator() (const struct BlackList & b) const
277  {
278  return (b.m_expireTime < Simulator::Now ());
279  }
280  };
281 };
282 } // namespace dsr
283 } // namespace ns3
284 
285 #endif /* DSR_RREQ_TABLE_H */
keep track of time unit.
Definition: nstime.h:149
static TypeId GetTypeId()
Get the type identificator.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for blacklistTimeout period) ...
virtual ~RreqTable()
Destructor.
bool operator==(ReceivedRreqEntry const &o) const
Compare send buffer entries.
maintain list of RreqTable entry
static Time Now(void)
Definition: simulator.cc:179
BlackList * FindUnidirectional(Ipv4Address neighbor)
Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for blacklistTimeout p...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id)
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44
RreqTable()
Constructor.
uint32_t CheckUniqueRreqId(Ipv4Address dst)