A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-rreq-table.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30
31#ifndef DSR_RREQ_TABLE_H
32#define DSR_RREQ_TABLE_H
33
34#include "ns3/callback.h"
35#include "ns3/ipv4-address.h"
36#include "ns3/simulator.h"
37#include "ns3/timer.h"
38
39#include <list>
40#include <map>
41#include <vector>
42
43namespace ns3
44{
45namespace dsr
46{
47
48/**
49 * State of link
50 */
52{
53 PROBABLE = 0, //!< PROBABLE
54 QUESTIONABLE = 1, //!< QUESTIONABLE
55};
56
57/// BlackList description
59{
60 Ipv4Address m_neighborAddress; //!< IPv4 address of the black-listed neighbor
61 Time m_expireTime; //!< Expire time in the black list
62 LinkStates m_linkStates; //!< State of the link
63
64 /**
65 * Construct a BlackList with the given parameters
66 *
67 * \param ip IPv4 address of the neighbor
68 * \param t expire time for the black list entry
69 */
72 m_expireTime(t),
74 {
75 }
76};
77
78/**
79 * The route request table entries
80 */
82{
83 uint32_t m_reqNo; //!< Route request number
84 Time m_expire; //!< Expire time
85};
86
87/**
88 * The request entry for intermediate nodes to check if they have received this request or not
89 * This is used to control the duplication request from being processed
90 */
92{
93 public:
94 /**
95 * Construct a DsrReceivedRreqEntry with the given parameters
96 *
97 * \param d IPv4 address of the destination
98 * \param i identification
99 */
101 : m_destination(d),
103 {
104 }
105
106 /**
107 * \brief Compare send buffer entries (destination address and identification)
108 * \param o another DsrReceivedRreqEntry
109 * \return true if equal
110 */
111 bool operator==(const DsrReceivedRreqEntry& o) const
112 {
114 }
115
116 /**
117 * Return IPv4 address of the destination
118 *
119 * \return IPv4 address of the destination
120 */
122 {
123 return m_destination;
124 }
125
126 /**
127 * Set IPv4 address of the destination
128 *
129 * \param d IPv4 address of the destination
130 */
132 {
133 m_destination = d;
134 }
135
136 /**
137 * Return IPv4 address of the source
138 *
139 * \return IPv4 address of the source
140 */
142 {
143 return m_source;
144 }
145
146 /**
147 * Set IPv4 address of the source
148 *
149 * \param s IPv4 address of the source
150 */
152 {
153 m_source = s;
154 }
155
156 /**
157 * Return identification
158 *
159 * \return identification
160 */
161 uint16_t GetIdentification() const
162 {
163 return m_identification;
164 }
165
166 /**
167 * Set identification
168 *
169 * \param i identification
170 */
171 void SetIdentification(uint16_t i)
172 {
174 }
175
176 /**
177 * Set expire time for the RREQ entry.
178 * Note that the parameter is duration but
179 * the stored value is the absolute time.
180 *
181 * \param exp duration before expire
182 */
184 {
185 m_expire = exp + Simulator::Now();
186 }
187
188 /**
189 * Return the remaining time before the RREQ entry expires.
190 * Note that we return the remaining time but the stored
191 * value is the absolute time.
192 *
193 * \return the remaining time before the RREQ entry expires
194 */
196 {
197 return m_expire - Simulator::Now();
198 }
199
200 // \}
201 private:
202 Ipv4Address m_destination; //!< IPv4 address of the destination
203 Ipv4Address m_source; //!< IPv4 address of the source
204 uint16_t m_identification; //!< Route request identification
205 Time m_expire; //!< Route request expire time
206};
207
208/**
209 * \ingroup dsr
210 * \brief maintain list of DsrRreqTable entry
211 */
212class DsrRreqTable : public Object
213{
214 public:
215 /**
216 * \brief Get the type ID.
217 * \return the object TypeId
218 */
219 static TypeId GetTypeId();
220
221 DsrRreqTable();
222 ~DsrRreqTable() override;
223
224 /**
225 * Set the initial discovert hop limit
226 *
227 * \param hl the initial discovert hop limit
228 */
230 {
231 m_initHopLimit = hl;
232 }
233
234 /**
235 * Return the initial discovert hop limit
236 *
237 * \return the initial discovert hop limit
238 */
240 {
241 return m_initHopLimit;
242 }
243
244 /**
245 * Set the maximum number of request entries in
246 * the request table.
247 *
248 * \param rt the maximum number of request entries
249 */
251 {
253 }
254
255 /**
256 * Return the maximum number of request entries in
257 * the request table.
258 *
259 * \return the maximum number of request entries
260 */
262 {
263 return m_requestTableSize;
264 }
265
266 /**
267 * Set the maximum number of request source Ids in
268 * the request table
269 *
270 * \param id the maximum number of request source Ids
271 */
273 {
274 m_requestIdSize = id;
275 }
276
277 /**
278 * Return the maximum number of request source Ids in
279 * the request table
280 *
281 * \return the maximum number of request source Ids
282 */
284 {
285 return m_requestIdSize;
286 }
287
288 /**
289 * Set the maximum number of request Ids in
290 * the request table for a single destination.
291 *
292 * \param uid the maximum number of request Ids
293 */
295 {
296 m_maxRreqId = uid;
297 }
298
299 /**
300 * Return the maximum number of request Ids in
301 * the request table for a single destination.
302 *
303 * \return the maximum number of request Ids
304 */
306 {
307 return m_maxRreqId;
308 }
309
310 /// Remove the least used entry
311 void RemoveLeastExpire();
312 /// Find the entry in the route request queue to see if already exists
313 /// \param dst Destination IP
314 void FindAndUpdate(Ipv4Address dst);
315 /// Remove route request entry for dst
316 /// \param dst Destination IP
318 /// Get the request count number for one destination address
319 /// \param dst Destination IP
320 /// \return the route request counter
322
323 /**
324 * The following code generates new request id for each destination.
325 * Check for duplicate ids and save new entries if the id is not present in the table.
326 *
327 * \param dst IPv4 address of the destination
328 * \return id
329 */
331 /**
332 * Get the request id size
333 *
334 * \return the request id size
335 */
337
338 /**
339 * set the unidirectional entry as QUESTIONABLE state
340 */
341 void Invalidate();
342 /**
343 * \brief Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for
344 * blacklistTimeout period)
345 * \param neighbor neighbor address link to which assumed to be unidirectional
346 * \return true on success
347 */
349 /**
350 * \brief Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for
351 * blacklistTimeout period)
352 * \param neighbor neighbor address link to which assumed to be unidirectional
353 * \param blacklistTimeout time for which the neighboring node is put into the blacklist
354 * \return true on success
355 */
356 bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
357 /**
358 * Remove all expired black list entries
359 */
360 void PurgeNeighbor();
361
362 /**
363 * Find the source request entry in the route request queue, return false if not found
364 * \param src the source address we just received the source request
365 * \param dst the destination address the request is targeted at
366 * \param id the identification number for this request
367 * \return true if found, false otherwise
368 */
369 bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id);
370
371 private:
372 /// The max request period among requests
374 /// The original request period
376 /// The non-propagaton request timeout
378 /// The source route entry expire time
380 /// The initial hop limit
382 /// The request table size
384 /// The request source id size
386 /// The unique request id for any destination
388 /// The state of the unidirectional link
390 /// Map of entries
391 std::list<DsrReceivedRreqEntry> m_sourceRequests;
392 /// The id cache to ensure all the ids are unique, it is used when sending out route request
393 std::map<Ipv4Address, uint32_t> m_rreqIdCache;
394 /// The cache to save route request table entries indexed with destination address
395 std::map<Ipv4Address, RreqTableEntry> m_rreqDstMap;
396 /// The cache to ensure all the route request from unique source
397 std::map<Ipv4Address, std::list<DsrReceivedRreqEntry>> m_sourceRreqMap;
398
399 /// The Black list
400 std::vector<BlackList> m_blackList;
401
402 /// Check if the entry is expired or not
404 {
405 /**
406 * Check if the entry is expired
407 *
408 * \param b BlackList entry
409 * \return true if expired, false otherwise
410 */
411 bool operator()(const BlackList& b) const
412 {
413 return (b.m_expireTime < Simulator::Now());
414 }
415 };
416};
417} // namespace dsr
418} // namespace ns3
419
420#endif /* DSR_RREQ_TABLE_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
A base class which provides memory management and object aggregation.
Definition: object.h:89
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
The request entry for intermediate nodes to check if they have received this request or not This is u...
void SetExpireTime(Time exp)
Set expire time for the RREQ entry.
Ipv4Address GetDestination() const
Return IPv4 address of the destination.
void SetIdentification(uint16_t i)
Set identification.
Ipv4Address m_source
IPv4 address of the source.
void SetSource(Ipv4Address s)
Set IPv4 address of the source.
Time GetExpireTime() const
Return the remaining time before the RREQ entry expires.
void SetDestination(Ipv4Address d)
Set IPv4 address of the destination.
Time m_expire
Route request expire time.
DsrReceivedRreqEntry(Ipv4Address d=Ipv4Address(), uint16_t i=0)
Construct a DsrReceivedRreqEntry with the given parameters.
uint16_t m_identification
Route request identification.
bool operator==(const DsrReceivedRreqEntry &o) const
Compare send buffer entries (destination address and identification)
Ipv4Address GetSource() const
Return IPv4 address of the source.
Ipv4Address m_destination
IPv4 address of the destination.
uint16_t GetIdentification() const
Return identification.
maintain list of DsrRreqTable entry
Time NonpropRequestTimeout
The non-propagaton request timeout.
void FindAndUpdate(Ipv4Address dst)
Find the entry in the route request queue to see if already exists.
void RemoveLeastExpire()
Remove the least used entry.
std::map< Ipv4Address, std::list< DsrReceivedRreqEntry > > m_sourceRreqMap
The cache to ensure all the route request from unique source.
uint32_t CheckUniqueRreqId(Ipv4Address dst)
The following code generates new request id for each destination.
std::map< Ipv4Address, uint32_t > m_rreqIdCache
The id cache to ensure all the ids are unique, it is used when sending out route request.
void SetUniqueRreqIdSize(uint32_t uid)
Set the maximum number of request Ids in the request table for a single destination.
Time MaxRequestPeriod
The max request period among requests.
LinkStates m_linkStates
The state of the unidirectional link.
uint32_t m_initHopLimit
The initial hop limit.
void Invalidate()
set the unidirectional entry as QUESTIONABLE state
void SetInitHopLimit(uint32_t hl)
Set the initial discovert hop limit.
Time m_rreqEntryExpire
The source route entry expire time.
std::map< Ipv4Address, RreqTableEntry > m_rreqDstMap
The cache to save route request table entries indexed with destination address.
void RemoveRreqEntry(Ipv4Address dst)
Remove route request entry for dst.
uint32_t GetRreqIdSize() const
Return the maximum number of request source Ids in the request table.
std::vector< BlackList > m_blackList
The Black list.
uint32_t GetUniqueRreqIdSize() const
Return the maximum number of request Ids in the request table for a single destination.
uint32_t m_maxRreqId
The unique request id for any destination.
std::list< DsrReceivedRreqEntry > m_sourceRequests
Map of entries.
Time RequestPeriod
The original request period.
bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout)
Mark entry as unidirectional (e.g.
uint32_t m_requestTableSize
The request table size.
uint32_t GetRreqCnt(Ipv4Address dst)
Get the request count number for one destination address.
void SetRreqTableSize(uint32_t rt)
Set the maximum number of request entries in the request table.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetRreqTableSize() const
Return the maximum number of request entries in the request table.
uint32_t m_requestIdSize
The request source id size.
void PurgeNeighbor()
Remove all expired black list entries.
bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id)
Find the source request entry in the route request queue, return false if not found.
BlackList * FindUnidirectional(Ipv4Address neighbor)
Verify if entry is unidirectional or not(e.g.
uint32_t GetInitHopLimit() const
Return the initial discovert hop limit.
void SetRreqIdSize(uint32_t id)
Set the maximum number of request source Ids in the request table.
uint32_t GetRreqSize()
Get the request id size.
LinkStates
State of link.
@ PROBABLE
PROBABLE.
@ QUESTIONABLE
QUESTIONABLE.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
BlackList description.
Time m_expireTime
Expire time in the black list.
LinkStates m_linkStates
State of the link.
BlackList(Ipv4Address ip, Time t)
Construct a BlackList with the given parameters.
Ipv4Address m_neighborAddress
IPv4 address of the black-listed neighbor.
Check if the entry is expired or not.
bool operator()(const BlackList &b) const
Check if the entry is expired.
The route request table entries.
Time m_expire
Expire time.
uint32_t m_reqNo
Route request number.