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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 * Work supported in part by NSF FIND (Future Internet Design) Program
15 * under grant CNS-0626918 (Postmodern Internet Architecture),
16 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17 * US Department of Defense (DoD), and ITTC at The University of Kansas.
18 */
19
20#ifndef DSR_RREQ_TABLE_H
21#define DSR_RREQ_TABLE_H
22
23#include "ns3/callback.h"
24#include "ns3/ipv4-address.h"
25#include "ns3/simulator.h"
26#include "ns3/timer.h"
27
28#include <list>
29#include <map>
30#include <vector>
31
32namespace ns3
33{
34namespace dsr
35{
36
37/**
38 * State of link
39 */
41{
42 PROBABLE = 0, //!< PROBABLE
43 QUESTIONABLE = 1, //!< QUESTIONABLE
44};
45
46/// BlackList description
48{
49 Ipv4Address m_neighborAddress; //!< IPv4 address of the black-listed neighbor
50 Time m_expireTime; //!< Expire time in the black list
51 LinkStates m_linkStates; //!< State of the link
52
53 /**
54 * Construct a BlackList with the given parameters
55 *
56 * @param ip IPv4 address of the neighbor
57 * @param t expire time for the black list entry
58 */
65};
66
67/**
68 * The route request table entries
69 */
71{
72 uint32_t m_reqNo; //!< Route request number
73 Time m_expire; //!< Expire time
74};
75
76/**
77 * The request entry for intermediate nodes to check if they have received this request or not
78 * This is used to control the duplication request from being processed
79 */
81{
82 public:
83 /**
84 * Construct a DsrReceivedRreqEntry with the given parameters
85 *
86 * @param d IPv4 address of the destination
87 * @param i identification
88 */
90 : m_destination(d),
92 {
93 }
94
95 /**
96 * @brief Compare send buffer entries (destination address and identification)
97 * @param o another DsrReceivedRreqEntry
98 * @return true if equal
99 */
100 bool operator==(const DsrReceivedRreqEntry& o) const
101 {
103 }
104
105 /**
106 * Return IPv4 address of the destination
107 *
108 * @return IPv4 address of the destination
109 */
111 {
112 return m_destination;
113 }
114
115 /**
116 * Set IPv4 address of the destination
117 *
118 * @param d IPv4 address of the destination
119 */
121 {
122 m_destination = d;
123 }
124
125 /**
126 * Return IPv4 address of the source
127 *
128 * @return IPv4 address of the source
129 */
131 {
132 return m_source;
133 }
134
135 /**
136 * Set IPv4 address of the source
137 *
138 * @param s IPv4 address of the source
139 */
141 {
142 m_source = s;
143 }
144
145 /**
146 * Return identification
147 *
148 * @return identification
149 */
150 uint16_t GetIdentification() const
151 {
152 return m_identification;
153 }
154
155 /**
156 * Set identification
157 *
158 * @param i identification
159 */
160 void SetIdentification(uint16_t i)
161 {
163 }
164
165 /**
166 * Set expire time for the RREQ entry.
167 * Note that the parameter is duration but
168 * the stored value is the absolute time.
169 *
170 * @param exp duration before expire
171 */
173 {
174 m_expire = exp + Simulator::Now();
175 }
176
177 /**
178 * Return the remaining time before the RREQ entry expires.
179 * Note that we return the remaining time but the stored
180 * value is the absolute time.
181 *
182 * @return the remaining time before the RREQ entry expires
183 */
185 {
186 return m_expire - Simulator::Now();
187 }
188
189 // \}
190 private:
191 Ipv4Address m_destination; //!< IPv4 address of the destination
192 Ipv4Address m_source; //!< IPv4 address of the source
193 uint16_t m_identification; //!< Route request identification
194 Time m_expire; //!< Route request expire time
195};
196
197/**
198 * @ingroup dsr
199 * @brief maintain list of DsrRreqTable entry
200 */
201class DsrRreqTable : public Object
202{
203 public:
204 /**
205 * @brief Get the type ID.
206 * @return the object TypeId
207 */
208 static TypeId GetTypeId();
209
210 DsrRreqTable();
211 ~DsrRreqTable() override;
212
213 /**
214 * Set the initial discovert hop limit
215 *
216 * @param hl the initial discovert hop limit
217 */
219 {
220 m_initHopLimit = hl;
221 }
222
223 /**
224 * Return the initial discovert hop limit
225 *
226 * @return the initial discovert hop limit
227 */
229 {
230 return m_initHopLimit;
231 }
232
233 /**
234 * Set the maximum number of request entries in
235 * the request table.
236 *
237 * @param rt the maximum number of request entries
238 */
240 {
242 }
243
244 /**
245 * Return the maximum number of request entries in
246 * the request table.
247 *
248 * @return the maximum number of request entries
249 */
251 {
252 return m_requestTableSize;
253 }
254
255 /**
256 * Set the maximum number of request source Ids in
257 * the request table
258 *
259 * @param id the maximum number of request source Ids
260 */
262 {
263 m_requestIdSize = id;
264 }
265
266 /**
267 * Return the maximum number of request source Ids in
268 * the request table
269 *
270 * @return the maximum number of request source Ids
271 */
273 {
274 return m_requestIdSize;
275 }
276
277 /**
278 * Set the maximum number of request Ids in
279 * the request table for a single destination.
280 *
281 * @param uid the maximum number of request Ids
282 */
284 {
285 m_maxRreqId = uid;
286 }
287
288 /**
289 * Return the maximum number of request Ids in
290 * the request table for a single destination.
291 *
292 * @return the maximum number of request Ids
293 */
295 {
296 return m_maxRreqId;
297 }
298
299 /// Remove the least used entry
300 void RemoveLeastExpire();
301 /// Find the entry in the route request queue to see if already exists
302 /// @param dst Destination IP
303 void FindAndUpdate(Ipv4Address dst);
304 /// Remove route request entry for dst
305 /// @param dst Destination IP
307 /// Get the request count number for one destination address
308 /// @param dst Destination IP
309 /// @return the route request counter
311
312 /**
313 * The following code generates new request id for each destination.
314 * Check for duplicate ids and save new entries if the id is not present in the table.
315 *
316 * @param dst IPv4 address of the destination
317 * @return id
318 */
320 /**
321 * Get the request id size
322 *
323 * @return the request id size
324 */
326
327 /**
328 * set the unidirectional entry as QUESTIONABLE state
329 */
330 void Invalidate();
331 /**
332 * @brief Verify if entry is unidirectional or not(e.g. add this neighbor to "blacklist" for
333 * blacklistTimeout period)
334 * @param neighbor neighbor address link to which assumed to be unidirectional
335 * @return true on success
336 */
338 /**
339 * @brief Mark entry as unidirectional (e.g. add this neighbor to "blacklist" for
340 * blacklistTimeout period)
341 * @param neighbor neighbor address link to which assumed to be unidirectional
342 * @param blacklistTimeout time for which the neighboring node is put into the blacklist
343 * @return true on success
344 */
345 bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
346 /**
347 * Remove all expired black list entries
348 */
349 void PurgeNeighbor();
350
351 /**
352 * Find the source request entry in the route request queue, return false if not found
353 * @param src the source address we just received the source request
354 * @param dst the destination address the request is targeted at
355 * @param id the identification number for this request
356 * @return true if found, false otherwise
357 */
358 bool FindSourceEntry(Ipv4Address src, Ipv4Address dst, uint16_t id);
359
360 private:
361 /// The max request period among requests
363 /// The original request period
365 /// The non-propagation request timeout
367 /// The source route entry expire time
369 /// The initial hop limit
371 /// The request table size
373 /// The request source id size
375 /// The unique request id for any destination
377 /// The state of the unidirectional link
379 /// Map of entries
380 std::list<DsrReceivedRreqEntry> m_sourceRequests;
381 /// The id cache to ensure all the ids are unique, it is used when sending out route request
382 std::map<Ipv4Address, uint32_t> m_rreqIdCache;
383 /// The cache to save route request table entries indexed with destination address
384 std::map<Ipv4Address, RreqTableEntry> m_rreqDstMap;
385 /// The cache to ensure all the route request from unique source
386 std::map<Ipv4Address, std::list<DsrReceivedRreqEntry>> m_sourceRreqMap;
387
388 /// The Black list
389 std::vector<BlackList> m_blackList;
390
391 /// Check if the entry is expired or not
393 {
394 /**
395 * Check if the entry is expired
396 *
397 * @param b BlackList entry
398 * @return true if expired, false otherwise
399 */
400 bool operator()(const BlackList& b) const
401 {
402 return (b.m_expireTime < Simulator::Now());
403 }
404 };
405};
406} // namespace dsr
407} // namespace ns3
408
409#endif /* DSR_RREQ_TABLE_H */
Ipv4 addresses are stored in host order in this class.
A base class which provides memory management and object aggregation.
Definition object.h:78
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
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-propagation 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.