A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-passive-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_PASSIVEBUFF_H
21#define DSR_PASSIVEBUFF_H
22
23#include "ns3/ipv4-routing-protocol.h"
24#include "ns3/simulator.h"
25
26#include <vector>
27
28namespace ns3
29{
30namespace dsr
31{
32/**
33 * \ingroup dsr
34 * \brief DSR Passive Buffer Entry
35 */
37{
38 public:
39 /**
40 * Construct a DsrPassiveBuffEntry with the given parameters
41 *
42 * \param pa packet
43 * \param d IPv4 address of the destination
44 * \param s IPv4 address of the source
45 * \param n IPv4 address of the next hop node
46 * \param i ID
47 * \param f fragment offset
48 * \param seg number of segments left
49 * \param exp expiration time
50 * \param p protocol number
51 */
56 uint16_t i = 0,
57 uint16_t f = 0,
58 uint8_t seg = 0,
59 Time exp = Simulator::Now(),
60 uint8_t p = 0)
61 : m_packet(pa),
62 m_dst(d),
63 m_source(s),
64 m_nextHop(n),
67 m_segsLeft(seg),
68 m_expire(exp + Simulator::Now()),
69 m_protocol(p)
70 {
71 }
72
73 /**
74 * Compare send buffer entries
75 * \param o passive buffer entry to compare
76 * \return true if equal
77 */
78 bool operator==(const DsrPassiveBuffEntry& o) const
79 {
80 return ((m_packet == o.m_packet) && (m_source == o.m_source) &&
81 (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
82 }
83
84 // Fields
85 /**
86 * Get packet function
87 * \returns the current packet
88 */
90 {
91 return m_packet;
92 }
93
94 /**
95 * Set packet function
96 * \param p the current packet
97 */
99 {
100 m_packet = p;
101 }
102
103 /**
104 * Get destination address function
105 * \returns the destination IP address
106 */
108 {
109 return m_dst;
110 }
111
112 /**
113 * Set destination address function
114 * \param d the destination IP address
115 */
117 {
118 m_dst = d;
119 }
120
121 /**
122 * Get source address function
123 * \returns the source IP address
124 */
126 {
127 return m_source;
128 }
129
130 /**
131 * Set surce address function
132 * \param s the source IP address
133 */
135 {
136 m_source = s;
137 }
138
139 /**
140 * Get next hop address function
141 * \returns the next hop IP address
142 */
144 {
145 return m_nextHop;
146 }
147
148 /**
149 * Set next hop address function
150 * \param n the next hop address
151 */
153 {
154 m_nextHop = n;
155 }
156
157 /**
158 * Get identification function
159 * \returns the identification
160 */
161 uint16_t GetIdentification() const
162 {
163 return m_identification;
164 }
165
166 /**
167 * Set identification function
168 * \param i the identification
169 */
170 void SetIdentification(uint16_t i)
171 {
173 }
174
175 /**
176 * Get fragment offset function
177 * \returns the fragment offset
178 */
179 uint16_t GetFragmentOffset() const
180 {
181 return m_fragmentOffset;
182 }
183
184 /**
185 * Set fragment offset function
186 * \param f the fragment offset
187 */
188 void SetFragmentOffset(uint16_t f)
189 {
191 }
192
193 /**
194 * Get segments left function
195 * \returns the number of segments left
196 */
197 uint8_t GetSegsLeft() const
198 {
199 return m_segsLeft;
200 }
201
202 /**
203 * Set segments left
204 * \param seg the number of segments left
205 */
206 void SetSegsLeft(uint8_t seg)
207 {
208 m_segsLeft = seg;
209 }
210
211 /**
212 * Set expire time
213 * \param exp the expire time
214 */
216 {
217 m_expire = exp + Simulator::Now();
218 }
219
220 /**
221 * Get expire time
222 * \returns the expire time
223 */
225 {
226 return m_expire - Simulator::Now();
227 }
228
229 /**
230 * Set protocol function
231 * \param p the protocol
232 */
233 void SetProtocol(uint8_t p)
234 {
235 m_protocol = p;
236 }
237
238 /**
239 * Get protocol
240 * \returns the protocol number
241 */
242 uint8_t GetProtocol() const
243 {
244 return m_protocol;
245 }
246
247 private:
248 /// Data packet
250 /// Destination address
252 /// Source address
254 /// Nexthop address
256 /// Identification
258 /// Fragment offset
260 /// Segments left
261 uint8_t m_segsLeft;
262 /// Expire time for queue entry
264 /// The protocol number
265 uint8_t m_protocol;
266};
267
268/**
269 * \ingroup dsr
270 * \class DsrPassiveBuffer
271 * \brief DSR passive buffer
272 */
273/************************************************************************************************************************/
275{
276 public:
277 /**
278 * \brief Get the type ID.
279 * \return the object TypeId
280 */
281 static TypeId GetTypeId();
282
284 ~DsrPassiveBuffer() override;
285
286 /// Push entry in queue, if there is no entry with the same packet and destination address in
287 /// queue.
288 /// \param entry Buffer Entry
289 /// \return true on success adding the Entry.
290 bool Enqueue(DsrPassiveBuffEntry& entry);
291 /// Return first found (the earliest) entry for given destination
292 /// \param [in] dst Entry destination
293 /// \param [out] entry The Entry found (if any).
294 /// \return true on success
295 bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry& entry);
296 /// Finds whether a packet with destination dst exists in the queue
297 /// \param dst Destination.
298 /// \return true if there is a packet.
299 bool Find(Ipv4Address dst);
300 /// Check if all the entries in passive buffer entry is all equal or not
301 /// \note For real this function checks if at most one entry is equal. If it is,
302 /// that entry is removed. Further entries are NOT checked. This could be a bug.
303 /// \param entry The Entry to check
304 /// \return true if an Entry was found and removed.
305 bool AllEqual(DsrPassiveBuffEntry& entry);
306 /// Number of entries
307 /// \return The number of entries.
309
310 // Fields
311 /**
312 * Get maximum queue length
313 * \returns the maximum queue length
314 */
316 {
317 return m_maxLen;
318 }
319
320 /**
321 * Set maximum queue length
322 * \param len the maximum queue length
323 */
325 {
326 m_maxLen = len;
327 }
328
329 /**
330 * Get passive buffer timeout
331 * \returns the passive buffer timeout
332 */
334 {
336 }
337
338 /**
339 * Set passive buffer timeout
340 * \param t the passive buffer timeout
341 */
346
347 private:
348 /// The send buffer to cache unsent packet
349 std::vector<DsrPassiveBuffEntry> m_passiveBuffer;
350 /// Remove all expired entries
351 void Purge();
352 /// Notify that packet is dropped from queue by timeout
353 /// \param en BuffEntry Buffer entry
354 /// \param reason Drop reason
355 void Drop(DsrPassiveBuffEntry en, std::string reason);
356 /// Notify that packet is dropped from queue by timeout
357 /// \param en BuffEntry Buffer entry
358 /// \param reason Drop reason
359 void DropLink(DsrPassiveBuffEntry en, std::string reason);
360 /// The maximum number of packets that we allow a routing protocol to buffer.
362 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
363 /// seconds.
365
366 /// Check if the send buffer entry is the same or not
367 /// \param en The Entry to check
368 /// \param link The link to check
369 /// \return true if an Entry source and Next hop are equal to the Link parameters
370 static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector<Ipv4Address> link)
371 {
372 return ((en.GetSource() == link[0]) && (en.GetNextHop() == link[1]));
373 }
374};
375
376/*******************************************************************************************************************************/
377} // namespace dsr
378} // namespace ns3
379
380#endif /* DSR_PASSIVEBUFF_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
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
a unique identifier for an interface.
Definition type-id.h:48
DSR Passive Buffer Entry.
bool operator==(const DsrPassiveBuffEntry &o) const
Compare send buffer entries.
uint8_t m_protocol
The protocol number.
void SetExpireTime(Time exp)
Set expire time.
uint16_t m_fragmentOffset
Fragment offset.
Ipv4Address GetDestination() const
Get destination address function.
void SetIdentification(uint16_t i)
Set identification function.
void SetDestination(Ipv4Address d)
Set destination address function.
uint8_t m_segsLeft
Segments left.
uint8_t GetProtocol() const
Get protocol.
Ipv4Address m_dst
Destination address.
void SetNextHop(Ipv4Address n)
Set next hop address function.
Ptr< const Packet > GetPacket() const
Get packet function.
Ipv4Address GetNextHop() const
Get next hop address function.
void SetSegsLeft(uint8_t seg)
Set segments left.
uint16_t m_identification
Identification.
Ipv4Address GetSource() const
Get source address function.
void SetSource(Ipv4Address s)
Set surce address function.
Ipv4Address m_nextHop
Nexthop address.
Ptr< const Packet > m_packet
Data packet.
void SetProtocol(uint8_t p)
Set protocol function.
Time GetExpireTime() const
Get expire time.
DsrPassiveBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), uint16_t i=0, uint16_t f=0, uint8_t seg=0, Time exp=Simulator::Now(), uint8_t p=0)
Construct a DsrPassiveBuffEntry with the given parameters.
uint8_t GetSegsLeft() const
Get segments left function.
void SetPacket(Ptr< const Packet > p)
Set packet function.
uint16_t GetIdentification() const
Get identification function.
uint16_t GetFragmentOffset() const
Get fragment offset function.
Ipv4Address m_source
Source address.
Time m_expire
Expire time for queue entry.
void SetFragmentOffset(uint16_t f)
Set fragment offset function.
Time GetPassiveBufferTimeout() const
Get passive buffer timeout.
bool Enqueue(DsrPassiveBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void SetPassiveBufferTimeout(Time t)
Set passive buffer timeout.
uint32_t GetSize()
Number of entries.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Dequeue(Ipv4Address dst, DsrPassiveBuffEntry &entry)
Return first found (the earliest) entry for given destination.
void DropLink(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Time m_passiveBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void Purge()
Remove all expired entries.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
static bool LinkEqual(DsrPassiveBuffEntry en, const std::vector< Ipv4Address > link)
Check if the send buffer entry is the same or not.
std::vector< DsrPassiveBuffEntry > m_passiveBuffer
The send buffer to cache unsent packet.
void Drop(DsrPassiveBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
static TypeId GetTypeId()
Get the type ID.
bool AllEqual(DsrPassiveBuffEntry &entry)
Check if all the entries in passive buffer entry is all equal or not.
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.