A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-errorbuff.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_ERRORBUFF_H
21#define DSR_ERRORBUFF_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 Error Buffer Entry
35 */
37{
38 public:
39 /**
40 * Create an DsrErrorBuffEntry 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
46 * @param exp expiration time
47 * @param p protocol number
48 */
53 Time exp = Simulator::Now(),
54 uint8_t p = 0)
55 : m_packet(pa),
56 m_dst(d),
57 m_source(s),
58 m_nextHop(n),
59 m_expire(exp + Simulator::Now()),
60 m_protocol(p)
61 {
62 }
63
64 /**
65 * Compare send buffer entries
66 * @param o another DsrErrorBuffEntry
67 * @return true if equal
68 */
69 bool operator==(const DsrErrorBuffEntry& o) const
70 {
71 return ((m_packet == o.m_packet) && (m_source == o.m_source) &&
72 (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
73 }
74
75 // Fields
76 /**
77 * Get packet from entry
78 * @returns the packet
79 */
81 {
82 return m_packet;
83 }
84
85 /**
86 * Set packet for entry
87 * @param p the packet
88 */
90 {
91 m_packet = p;
92 }
93
94 /**
95 * Get destination address
96 * @returns the destination IPv4 address
97 */
99 {
100 return m_dst;
101 }
102
103 /**
104 * Set destination address
105 * @param d the destination IPv4 address
106 */
108 {
109 m_dst = d;
110 }
111
112 /**
113 * Get source address
114 * @returns the source IPv4 address
115 */
117 {
118 return m_source;
119 }
120
121 /**
122 * Set source address
123 * @param s the source IPv4 address
124 */
126 {
127 m_source = s;
128 }
129
130 /**
131 * Get next hop
132 * @returns the next hop address
133 */
135 {
136 return m_nextHop;
137 }
138
139 /**
140 * Set next hop
141 * @param n the next hop IPv4 address
142 */
144 {
145 m_nextHop = n;
146 }
147
148 /**
149 * Set expire time
150 * @param exp the expire time
151 */
153 {
154 m_expire = exp + Simulator::Now();
155 }
156
157 /**
158 * Get expire time
159 * @returns the expire time
160 */
162 {
163 return m_expire - Simulator::Now();
164 }
165
166 /**
167 * Set protocol number
168 * @param p the protocol number
169 */
170 void SetProtocol(uint8_t p)
171 {
172 m_protocol = p;
173 }
174
175 /**
176 * Get protocol number
177 * @returns the protocol number
178 */
179 uint8_t GetProtocol() const
180 {
181 return m_protocol;
182 }
183
184 private:
185 /// Data packet
187 /// Destination address
188 Ipv4Address m_dst; ///< destination address
189 /// Source address
190 Ipv4Address m_source; ///< source address
191 /// Nexthop address
192 Ipv4Address m_nextHop; ///< next hop
193 /// Expire time for queue entry
194 Time m_expire; ///< expiration time
195 /// The protocol number
196 uint8_t m_protocol;
197};
198
199/**
200 * @ingroup dsr
201 * @brief DSR error buffer
202 */
203/************************************************************************************************************************/
205{
206 public:
207 /**
208 * Default constructor
209 */
211 {
212 }
213
214 /**
215 * Push entry in queue, if there is no entry with the same packet and destination address in
216 * queue.
217 *
218 * @param entry error buffer entry
219 * @return true if entry added
220 */
221 bool Enqueue(DsrErrorBuffEntry& entry);
222 /**
223 * Return first found (the earliest) entry for given destination
224 * @param [in] dst The destination to look for
225 * @param [out] entry The entry
226 * @return true if an entry is found
227 */
228 bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry& entry);
229 /**
230 * Remove all packets with the error link
231 * @param source The source
232 * @param nextHop The next hop
233 */
234 void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop);
235 /**
236 * Finds whether a packet with destination dst exists in the queue
237 * @param dst The destination
238 * @return true if a packet is found.
239 */
240 bool Find(Ipv4Address dst);
241 /**
242 * Returns the number of entries in the queue.
243 * @return the number of entries in the queue.
244 */
246
247 // Fields
248 /**
249 * Get maximum queue length
250 * @returns the maximum queue length
251 */
253 {
254 return m_maxLen;
255 }
256
257 /**
258 * Set maximum queue length
259 * @param len the maximum queue length
260 */
262 {
263 m_maxLen = len;
264 }
265
266 /**
267 * Get error buffer timeout
268 * @returns the error buffer timeout
269 */
271 {
273 }
274
275 /**
276 * Set error buffer timeout
277 * @param t the error buffer timeout
278 */
280 {
282 }
283
284 /**
285 * Get error buffer entry
286 * @returns the DSR error buffer
287 */
288 std::vector<DsrErrorBuffEntry>& GetBuffer()
289 {
290 return m_errorBuffer;
291 }
292
293 private:
294 /// The send buffer to cache unsent packet
295 std::vector<DsrErrorBuffEntry> m_errorBuffer;
296 /// Remove all expired entries
297 void Purge();
298 /**
299 * Notify that packet is dropped from queue by timeout
300 * @param en Error Buffer Entry
301 * @param reason Drop reason.
302 */
303 ///
304 void Drop(DsrErrorBuffEntry en, std::string reason);
305 /**
306 * Notify that packet is dropped from queue by link error
307 * @param en Error Buffer Entry
308 * @param reason Drop reason.
309 */
310 void DropLink(DsrErrorBuffEntry en, std::string reason);
311 /// The maximum number of packets that we allow a routing protocol to buffer.
313 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
314 /// seconds.
316};
317
318/*******************************************************************************************************************************/
319} // namespace dsr
320} // namespace ns3
321
322#endif /* DSR_ERRORBUFF_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 Error Buffer Entry.
DsrErrorBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Ipv4Address s=Ipv4Address(), Ipv4Address n=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Create an DsrErrorBuffEntry with the given parameters.
Ptr< const Packet > GetPacket() const
Get packet from entry.
void SetDestination(Ipv4Address d)
Set destination address.
Ipv4Address m_nextHop
Nexthop address.
void SetNextHop(Ipv4Address n)
Set next hop.
Ptr< const Packet > m_packet
Data packet.
void SetSource(Ipv4Address s)
Set source address.
void SetProtocol(uint8_t p)
Set protocol number.
void SetExpireTime(Time exp)
Set expire time.
Ipv4Address m_source
Source address.
Ipv4Address m_dst
Destination address.
Ipv4Address GetNextHop() const
Get next hop.
Ipv4Address GetSource() const
Get source address.
Time GetExpireTime() const
Get expire time.
void SetPacket(Ptr< const Packet > p)
Set packet for entry.
uint8_t m_protocol
The protocol number.
Time m_expire
Expire time for queue entry.
Ipv4Address GetDestination() const
Get destination address.
uint8_t GetProtocol() const
Get protocol number.
bool operator==(const DsrErrorBuffEntry &o) const
Compare send buffer entries.
Time m_errorBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
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.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
std::vector< DsrErrorBuffEntry > & GetBuffer()
Get error buffer entry.
Time GetErrorBufferTimeout() const
Get error buffer timeout.
bool Enqueue(DsrErrorBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void DropLink(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by link error.
bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry &entry)
Return first found (the earliest) entry for given destination.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
DsrErrorBuffer()
Default constructor.
void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop)
Remove all packets with the error link.
void SetErrorBufferTimeout(Time t)
Set error buffer timeout.
uint32_t GetSize()
Returns the number of entries in the queue.
std::vector< DsrErrorBuffEntry > m_errorBuffer
The send buffer to cache unsent packet.
void Drop(DsrErrorBuffEntry en, std::string reason)
Notify that packet is dropped from queue by 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.