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