A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-maintain-buff.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_MAINTAIN_BUFF_H
21#define DSR_MAINTAIN_BUFF_H
22
23#include "dsr-option-header.h"
24
25#include "ns3/ipv4-header.h"
26#include "ns3/ipv4-routing-protocol.h"
27#include "ns3/simulator.h"
28
29#include <vector>
30
31namespace ns3
32{
33namespace dsr
34{
35/**
36 * The maintenance buffer is responsible for maintaining packet next hop delivery
37 * The data packet is saved in maintenance buffer whenever the data packet is sent out of send
38 * buffer
39 */
40struct LinkKey
41{
42 Ipv4Address m_source; ///< source address
43 Ipv4Address m_destination; ///< destination address
44 Ipv4Address m_ourAdd; ///< local address
45 Ipv4Address m_nextHop; ///< next hop address
46
47 /**
48 * Compare maintain Buffer entries
49 * @param o object to compare
50 * @return true if equal
51 */
52 bool operator<(const LinkKey& o) const
53 {
54 if (m_source < o.m_source)
55 {
56 return true;
57 }
58 if (o.m_source < m_source)
59 {
60 return false;
61 }
63 {
64 return true;
65 }
67 {
68 return false;
69 }
70 if (m_ourAdd < o.m_ourAdd)
71 {
72 return true;
73 }
74 if (o.m_ourAdd < m_ourAdd)
75 {
76 return false;
77 }
78 if (m_nextHop < o.m_nextHop)
79 {
80 return true;
81 }
82 if (o.m_nextHop < m_nextHop)
83 {
84 return false;
85 }
86 return false;
87 }
88};
89
90/// NetworkKey structure
92{
93 uint16_t m_ackId; ///< acknowledge ID
94 Ipv4Address m_ourAdd; ///< local address
95 Ipv4Address m_nextHop; ///< next hop
96 Ipv4Address m_source; ///< source address
97 Ipv4Address m_destination; ///< destination address
98
99 /**
100 * Compare maintain Buffer entries
101 * @param o object to compare
102 * @return true if equal
103 */
104 bool operator<(const NetworkKey& o) const
105 {
106 if (m_ackId < o.m_ackId)
107 {
108 return true;
109 }
110 if (o.m_ackId < m_ackId)
111 {
112 return false;
113 }
114 if (m_source < o.m_source)
115 {
116 return true;
117 }
118 if (o.m_source < m_source)
119 {
120 return false;
121 }
123 {
124 return true;
125 }
127 {
128 return false;
129 }
130 if (m_ourAdd < o.m_ourAdd)
131 {
132 return true;
133 }
134 if (o.m_ourAdd < m_ourAdd)
135 {
136 return false;
137 }
138 if (m_nextHop < o.m_nextHop)
139 {
140 return true;
141 }
142 if (o.m_nextHop < m_nextHop)
143 {
144 return false;
145 }
146 return false;
147 }
148};
149
150/// PassiveKey structure
152{
153 uint16_t m_ackId; ///< acknowledge ID
154 Ipv4Address m_source; ///< source address
155 Ipv4Address m_destination; ///< destination address
156 uint8_t m_segsLeft; ///< segments left
157
158 /**
159 * Compare maintain Buffer entries
160 * @param o is the object to compare
161 * @return true if equal
162 */
163 bool operator<(const PassiveKey& o) const
164 {
165 if (m_ackId < o.m_ackId)
166 {
167 return true;
168 }
169 if (o.m_ackId < m_ackId)
170 {
171 return false;
172 }
173 if (m_source < o.m_source)
174 {
175 return true;
176 }
177 if (o.m_source < m_source)
178 {
179 return false;
180 }
182 {
183 return true;
184 }
186 {
187 return false;
188 }
189 if (m_segsLeft < o.m_segsLeft)
190 {
191 return true;
192 }
193 if (o.m_segsLeft < m_segsLeft)
194 {
195 return false;
196 }
197 return false;
198 }
199};
200
201/**
202 * @ingroup dsr
203 * @brief DSR Maintain Buffer Entry
204 */
206{
207 public:
208 /**
209 * Construct a DsrMaintainBuffEntry with the given parameters
210 *
211 * @param packet packet
212 * @param ourAddress our IPv4 address
213 * @param nextHop next hop IPv4 address
214 * @param src IPv4 address of the source
215 * @param dst IPv4 address of the destination
216 * @param ackId ACK ID
217 * @param segsLeft number of segments left
218 * @param expire expiration time
219 */
221 Ipv4Address ourAddress = Ipv4Address(),
222 Ipv4Address nextHop = Ipv4Address(),
223 Ipv4Address src = Ipv4Address(),
224 Ipv4Address dst = Ipv4Address(),
225 uint16_t ackId = 0,
226 uint8_t segsLeft = 0,
227 Time expire = Simulator::Now())
228 : m_packet(packet),
229 m_ourAdd(ourAddress),
230 m_nextHop(nextHop),
231 m_src(src),
232 m_dst(dst),
233 m_ackId(ackId),
234 m_segsLeft(segsLeft),
235 m_expire(expire + Simulator::Now())
236 {
237 }
238
239 // Fields
240 /**
241 * Get packet
242 * @returns the current packet
243 */
245 {
246 return m_packet;
247 }
248
249 /**
250 * Set packet
251 * @param p the current packet
252 */
254 {
255 m_packet = p;
256 }
257
258 /**
259 * Get local address of entry
260 * @returns the local IP address
261 */
263 {
264 return m_ourAdd;
265 }
266
267 /**
268 * Set local address of entry
269 * @param us the local IP address
270 */
272 {
273 m_ourAdd = us;
274 }
275
276 /**
277 * Get next hop of entry
278 * @returns the IP address for the next hop
279 */
281 {
282 return m_nextHop;
283 }
284
285 /**
286 * Set next hop of entry
287 * @param n the next hop IP address
288 */
290 {
291 m_nextHop = n;
292 }
293
294 /**
295 * Get destination address
296 * @returns the destination IP address
297 */
299 {
300 return m_dst;
301 }
302
303 /**
304 * Set destination address
305 * @param n the destination IP address
306 */
308 {
309 m_dst = n;
310 }
311
312 /**
313 * Get source address
314 * @returns the source IP address
315 */
317 {
318 return m_src;
319 }
320
321 /**
322 * Set source address
323 * @param s the source IP address
324 */
326 {
327 m_src = s;
328 }
329
330 /**
331 * Get acknowledge ID
332 * @returns the acknowledge ID
333 */
334 uint16_t GetAckId() const
335 {
336 return m_ackId;
337 }
338
339 /**
340 * Set acknowledge ID
341 * @param ackId the acknowledge ID
342 */
343 void SetAckId(uint16_t ackId)
344 {
345 m_ackId = ackId;
346 }
347
348 /**
349 * Get segments left
350 * @returns the number of segments left
351 */
352 uint8_t GetSegsLeft() const
353 {
354 return m_segsLeft;
355 }
356
357 /**
358 * Set segments left
359 * @param segs the number of segments left
360 */
361 void SetSegsLeft(uint8_t segs)
362 {
363 m_segsLeft = segs;
364 }
365
366 /**
367 * Set expiration time
368 * @param exp the expire time
369 */
371 {
372 m_expire = exp + Simulator::Now();
373 }
374
375 /**
376 * Get expiration time
377 * @returns the expiration time
378 */
380 {
381 return m_expire - Simulator::Now();
382 }
383
384 private:
385 /// Data packet
387 /// Our own ip address
389 /// Next hop Ip address
391 /// The source address
393 /// The destination address
395 /// The data ack id
396 uint16_t m_ackId;
397 /// The segments left field
398 uint8_t m_segsLeft;
399 /// Expire time for queue entry
401};
402
403/**
404 * @ingroup dsr
405 * @brief DSR maintain buffer
406 */
407/************************************************************************************************************************/
409{
410 public:
411 /**
412 * Default constructor
413 */
415 {
416 }
417
418 /// Push entry in queue, if there is no entry with the same packet and destination address in
419 /// queue.
420 /// @param entry Maintain Buffer Entry
421 /// @return true on success adding the Entry.
422 bool Enqueue(DsrMaintainBuffEntry& entry);
423 /// Return first found (the earliest) entry for given destination
424 /// @param [in] dst Entry destination
425 /// @param [out] entry The Entry found (if any).
426 /// @return true on success
427 bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry& entry);
428 /// Remove all packets with next hop IP address dst
429 /// @param nextHop Next hop in the route.
431 /// Finds whether a packet with next hop dst exists in the queue
432 /// @param nextHop Next hop in the route.
433 /// @return true if there is a packet directed to the next hop.
434 bool Find(Ipv4Address nextHop);
435 /// Number of entries
436 /// @return The number of entries.
438
439 // Fields
440 /**
441 * Get maximum queue length
442 * @returns the maximum queue length
443 */
445 {
446 return m_maxLen;
447 }
448
449 /**
450 * Set maximum queue length
451 * @param len the maximum queue length
452 */
454 {
455 m_maxLen = len;
456 }
457
458 /**
459 * Get maintain buffer timeout
460 * @returns the maintain buffer timeout
461 */
466
467 /**
468 * Set maintain buffer timeout
469 * @param t the maintain buffer timeout
470 */
475
476 /// Verify if all the elements in the maintenance buffer entry is the same
477 /// @note For real this function checks if at most one entry is equal. If it is,
478 /// that entry is removed. Further entries are NOT checked. This could be a bug.
479 /// @param entry The Entry to check
480 /// @return true if an Entry was found and removed.
481 bool AllEqual(DsrMaintainBuffEntry& entry);
482 /// Verify if the maintain buffer entry is the same in every field for link ack
483 /// @param entry The Entry to check
484 /// @return true if an Entry was found and removed.
485 bool LinkEqual(DsrMaintainBuffEntry& entry);
486 /// Verify if the maintain buffer entry is the same in every field for network ack
487 /// @param entry The Entry to check
488 /// @return true if an Entry was found and removed.
490 /// Verify if the maintain buffer entry is the same in every field for promiscuous ack
491 /// @param entry The Entry to check
492 /// @return true if an Entry was found and removed.
494
495 private:
496 /// The vector of maintain buffer entries
497 std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
498 /// The vector of network keys
499 std::vector<NetworkKey> m_allNetworkKey;
500 /// Remove all expired entries
501 void Purge();
502 /// The maximum number of packets that we allow a routing protocol to buffer.
504 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
505 /// seconds.
507};
508
509/*******************************************************************************************************************************/
510} // namespace dsr
511} // namespace ns3
512#endif /* DSR_MAINTAIN_BUFF_H */
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
Definition simulator.h:57
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
DSR Maintain Buffer Entry.
uint8_t GetSegsLeft() const
Get segments left.
void SetDst(Ipv4Address n)
Set destination address.
DsrMaintainBuffEntry(Ptr< const Packet > packet=nullptr, Ipv4Address ourAddress=Ipv4Address(), Ipv4Address nextHop=Ipv4Address(), Ipv4Address src=Ipv4Address(), Ipv4Address dst=Ipv4Address(), uint16_t ackId=0, uint8_t segsLeft=0, Time expire=Simulator::Now())
Construct a DsrMaintainBuffEntry with the given parameters.
void SetExpireTime(Time exp)
Set expiration time.
void SetNextHop(Ipv4Address n)
Set next hop of entry.
Ipv4Address m_nextHop
Next hop Ip address.
Ipv4Address GetSrc() const
Get source address.
void SetSegsLeft(uint8_t segs)
Set segments left.
void SetPacket(Ptr< const Packet > p)
Set packet.
uint8_t m_segsLeft
The segments left field.
Ptr< const Packet > GetPacket() const
Get packet.
Ipv4Address m_dst
The destination address.
Ptr< const Packet > m_packet
Data packet.
Ipv4Address m_ourAdd
Our own ip address.
void SetOurAdd(Ipv4Address us)
Set local address of entry.
void SetSrc(Ipv4Address s)
Set source address.
uint16_t m_ackId
The data ack id.
uint16_t GetAckId() const
Get acknowledge ID.
Ipv4Address GetOurAdd() const
Get local address of entry.
Time GetExpireTime() const
Get expiration time.
void SetAckId(uint16_t ackId)
Set acknowledge ID.
Time m_expire
Expire time for queue entry.
Ipv4Address GetNextHop() const
Get next hop of entry.
Ipv4Address m_src
The source address.
Ipv4Address GetDst() const
Get destination address.
bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry &entry)
Return first found (the earliest) entry for given destination.
Time m_maintainBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void DropPacketWithNextHop(Ipv4Address nextHop)
Remove all packets with next hop IP address dst.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool AllEqual(DsrMaintainBuffEntry &entry)
Verify if all the elements in the maintenance buffer entry is the same.
bool LinkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for link ack.
std::vector< NetworkKey > m_allNetworkKey
The vector of network keys.
bool Find(Ipv4Address nextHop)
Finds whether a packet with next hop dst exists in the queue.
void SetMaintainBufferTimeout(Time t)
Set maintain buffer timeout.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
uint32_t GetSize()
Number of entries.
bool PromiscEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for promiscuous ack.
DsrMaintainBuffer()
Default constructor.
bool NetworkEqual(DsrMaintainBuffEntry &entry)
Verify if the maintain buffer entry is the same in every field for network ack.
bool Enqueue(DsrMaintainBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
std::vector< DsrMaintainBuffEntry > m_maintainBuffer
The vector of maintain buffer entries.
Time GetMaintainBufferTimeout() const
Get maintain buffer timeout.
void Purge()
Remove all expired entries.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NetworkKey structure.
Ipv4Address m_ourAdd
local address
bool operator<(const NetworkKey &o) const
Compare maintain Buffer entries.
Ipv4Address m_destination
destination address
uint16_t m_ackId
acknowledge ID
Ipv4Address m_source
source address
Ipv4Address m_nextHop
next hop
PassiveKey structure.
Ipv4Address m_destination
destination address
Ipv4Address m_source
source address
bool operator<(const PassiveKey &o) const
Compare maintain Buffer entries.
uint8_t m_segsLeft
segments left
uint16_t m_ackId
acknowledge ID