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 * Modified by: Tommaso Pecorella <tommaso.pecorella@unifi.it>
8 * Lorenzo Bartolini <l.bartolini02@gmail.com>
9 *
10 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
11 * ResiliNets Research Group https://resilinets.org/
12 * Information and Telecommunication Technology Center (ITTC)
13 * and Department of Electrical Engineering and Computer Science
14 * The University of Kansas Lawrence, KS USA.
15 *
16 * Work supported in part by NSF FIND (Future Internet Design) Program
17 * under grant CNS-0626918 (Postmodern Internet Architecture),
18 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
19 * US Department of Defense (DoD), and ITTC at The University of Kansas.
20 */
21
22#ifndef DSR_MAINTAIN_BUFF_H
23#define DSR_MAINTAIN_BUFF_H
24
25#include "dsr-option-header.h"
26
27#include "ns3/ipv4-header.h"
28#include "ns3/ipv4-routing-protocol.h"
29#include "ns3/simulator.h"
30
31#include <vector>
32
33namespace ns3
34{
35namespace dsr
36{
37
39
40/**
41 * The maintenance buffer is responsible for maintaining packet next hop delivery
42 * The data packet is saved in maintenance buffer whenever the data packet is sent out of send
43 * buffer
44 */
45struct LinkKey
46{
47 Ipv4Address m_source; ///< source address
48 Ipv4Address m_destination; ///< destination address
49 Ipv4Address m_ourAdd; ///< local address
50 Ipv4Address m_nextHop; ///< next hop address
51
52 constexpr LinkKey() = default;
53
54 /**
55 * Constructor from a DsrMaintainBuffEntry.
56 * @param entry the DsrMaintainBuffEntry
57 */
58 LinkKey(const DsrMaintainBuffEntry& entry);
59
60 /**
61 * @brief Three-way comparison operator.
62 *
63 * @param other the other LinkKey to compare with
64 * @returns comparison result
65 */
66 constexpr std::strong_ordering operator<=>(const LinkKey& other) const = default;
67};
68
69/// NetworkKey structure
71{
72 uint16_t m_ackId; ///< acknowledge ID
73 Ipv4Address m_ourAdd; ///< local address
74 Ipv4Address m_nextHop; ///< next hop
75 Ipv4Address m_source; ///< source address
76 Ipv4Address m_destination; ///< destination address
77
78 constexpr NetworkKey() = default;
79
80 /**
81 * Constructor from a DsrMaintainBuffEntry.
82 * @param entry the DsrMaintainBuffEntry
83 */
84 NetworkKey(const DsrMaintainBuffEntry& entry);
85
86 /**
87 * @brief Three-way comparison operator.
88 *
89 * @param other the other NetworkKey to compare with
90 * @returns comparison result
91 */
92 constexpr std::strong_ordering operator<=>(const NetworkKey& other) const = default;
93};
94
95/// PassiveKey structure
97{
98 uint16_t m_ackId; ///< acknowledge ID
99 Ipv4Address m_source; ///< source address
100 Ipv4Address m_destination; ///< destination address
101 uint8_t m_segsLeft; ///< segments left
102
103 constexpr PassiveKey() = default;
104
105 /**
106 * Constructor from a DsrMaintainBuffEntry.
107 * @param entry the DsrMaintainBuffEntry
108 */
109 PassiveKey(const DsrMaintainBuffEntry& entry);
110
111 /**
112 * @brief Three-way comparison operator.
113 *
114 * @param other the other NetworkKey to compare with
115 * @returns comparison result
116 */
117 constexpr std::strong_ordering operator<=>(const PassiveKey& other) const = default;
118};
119
120/**
121 * @ingroup dsr
122 * @brief DSR Maintain Buffer Entry
123 */
125{
126 public:
127 /**
128 * Construct a DsrMaintainBuffEntry with the given parameters
129 *
130 * @param packet packet
131 * @param ourAddress our IPv4 address
132 * @param nextHop next hop IPv4 address
133 * @param src IPv4 address of the source
134 * @param dst IPv4 address of the destination
135 * @param ackId ACK ID
136 * @param segsLeft number of segments left
137 * @param expire expiration time
138 */
140 Ipv4Address ourAddress = Ipv4Address(),
141 Ipv4Address nextHop = Ipv4Address(),
142 Ipv4Address src = Ipv4Address(),
143 Ipv4Address dst = Ipv4Address(),
144 uint16_t ackId = 0,
145 uint8_t segsLeft = 0,
146 Time expire = Simulator::Now())
147 : m_packet(packet),
148 m_ourAdd(ourAddress),
149 m_nextHop(nextHop),
150 m_src(src),
151 m_dst(dst),
152 m_ackId(ackId),
153 m_segsLeft(segsLeft),
154 m_expire(expire + Simulator::Now())
155 {
156 }
157
158 // Fields
159 /**
160 * Get packet
161 * @returns the current packet
162 */
164 {
165 return m_packet;
166 }
167
168 /**
169 * Set packet
170 * @param p the current packet
171 */
173 {
174 m_packet = p;
175 }
176
177 /**
178 * Get local address of entry
179 * @returns the local IP address
180 */
182 {
183 return m_ourAdd;
184 }
185
186 /**
187 * Set local address of entry
188 * @param us the local IP address
189 */
191 {
192 m_ourAdd = us;
193 }
194
195 /**
196 * Get next hop of entry
197 * @returns the IP address for the next hop
198 */
200 {
201 return m_nextHop;
202 }
203
204 /**
205 * Set next hop of entry
206 * @param n the next hop IP address
207 */
209 {
210 m_nextHop = n;
211 }
212
213 /**
214 * Get destination address
215 * @returns the destination IP address
216 */
218 {
219 return m_dst;
220 }
221
222 /**
223 * Set destination address
224 * @param n the destination IP address
225 */
227 {
228 m_dst = n;
229 }
230
231 /**
232 * Get source address
233 * @returns the source IP address
234 */
236 {
237 return m_src;
238 }
239
240 /**
241 * Set source address
242 * @param s the source IP address
243 */
245 {
246 m_src = s;
247 }
248
249 /**
250 * Get acknowledge ID
251 * @returns the acknowledge ID
252 */
253 uint16_t GetAckId() const
254 {
255 return m_ackId;
256 }
257
258 /**
259 * Set acknowledge ID
260 * @param ackId the acknowledge ID
261 */
262 void SetAckId(uint16_t ackId)
263 {
264 m_ackId = ackId;
265 }
266
267 /**
268 * Get segments left
269 * @returns the number of segments left
270 */
271 uint8_t GetSegsLeft() const
272 {
273 return m_segsLeft;
274 }
275
276 /**
277 * Set segments left
278 * @param segs the number of segments left
279 */
280 void SetSegsLeft(uint8_t segs)
281 {
282 m_segsLeft = segs;
283 }
284
285 /**
286 * Set expiration time
287 * @param exp the expire time
288 */
290 {
291 m_expire = exp + Simulator::Now();
292 }
293
294 /**
295 * Get expiration time
296 * @returns the expiration time
297 */
299 {
300 return m_expire - Simulator::Now();
301 }
302
303 private:
304 /// Data packet
306 /// Our own ip address
308 /// Next hop Ip address
310 /// The source address
312 /// The destination address
314 /// The data ack id
315 uint16_t m_ackId;
316 /// The segments left field
317 uint8_t m_segsLeft;
318 /// Expire time for queue entry
320};
321
322/**
323 * @ingroup dsr
324 * @brief DSR maintain buffer
325 */
326/************************************************************************************************************************/
328{
329 public:
330 /**
331 * Default constructor
332 */
334 {
335 }
336
337 /// Push entry in queue, if there is no entry with the same packet and destination address in
338 /// queue.
339 /// @param entry Maintain Buffer Entry
340 /// @return true on success adding the Entry.
341 bool Enqueue(DsrMaintainBuffEntry& entry);
342 /// Return first found (the earliest) entry for given destination
343 /// @param [in] dst Entry destination
344 /// @param [out] entry The Entry found (if any).
345 /// @return true on success
346 bool Dequeue(Ipv4Address dst, DsrMaintainBuffEntry& entry);
347 /// Remove all packets with next hop IP address dst
348 /// @param nextHop Next hop in the route.
350 /// Finds whether a packet with next hop dst exists in the queue
351 /// @param nextHop Next hop in the route.
352 /// @return true if there is a packet directed to the next hop.
353 bool Find(Ipv4Address nextHop);
354 /// Number of entries
355 /// @return The number of entries.
357
358 // Fields
359 /**
360 * Get maximum queue length
361 * @returns the maximum queue length
362 */
364 {
365 return m_maxLen;
366 }
367
368 /**
369 * Set maximum queue length
370 * @param len the maximum queue length
371 */
373 {
374 m_maxLen = len;
375 }
376
377 /**
378 * Get maintain buffer timeout
379 * @returns the maintain buffer timeout
380 */
385
386 /**
387 * Set maintain buffer timeout
388 * @param t the maintain buffer timeout
389 */
394
395 /// Verify if all the elements in the maintenance buffer entry is the same
396 /// @note For real this function checks if at most one entry is equal. If it is,
397 /// that entry is removed. Further entries are NOT checked. This could be a bug.
398 /// @param entry The Entry to check
399 /// @return true if an Entry was found and removed.
400 bool AllEqual(DsrMaintainBuffEntry& entry);
401 /// Verify if the maintain buffer entry is the same in every field for link ack
402 /// @param entry The Entry to check
403 /// @return true if an Entry was found and removed.
404 bool LinkEqual(DsrMaintainBuffEntry& entry);
405 /// Verify if the maintain buffer entry is the same in every field for network ack
406 /// @param entry The Entry to check
407 /// @return true if an Entry was found and removed.
409 /// Verify if the maintain buffer entry is the same in every field for promiscuous ack
410 /// @param entry The Entry to check
411 /// @return true if an Entry was found and removed.
413
414 private:
415 /// The vector of maintain buffer entries
416 std::vector<DsrMaintainBuffEntry> m_maintainBuffer;
417 /// The vector of network keys
418 std::vector<NetworkKey> m_allNetworkKey;
419 /// Remove all expired entries
420 void Purge();
421 /// The maximum number of packets that we allow a routing protocol to buffer.
423 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
424 /// seconds.
426};
427
428/*******************************************************************************************************************************/
429} // namespace dsr
430} // namespace ns3
431#endif /* DSR_MAINTAIN_BUFF_H */
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Control the scheduling of simulation events.
Definition simulator.h:57
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
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:288
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4Address m_ourAdd
local address
constexpr NetworkKey()=default
constexpr std::strong_ordering operator<=>(const NetworkKey &other) const =default
Three-way comparison operator.
Ipv4Address m_destination
destination address
uint16_t m_ackId
acknowledge ID
Ipv4Address m_source
source address
Ipv4Address m_nextHop
next hop
Ipv4Address m_destination
destination address
Ipv4Address m_source
source address
constexpr PassiveKey()=default
constexpr std::strong_ordering operator<=>(const PassiveKey &other) const =default
Three-way comparison operator.
uint8_t m_segsLeft
segments left
uint16_t m_ackId
acknowledge ID