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