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 * 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_ERRORBUFF_H
32#define DSR_ERRORBUFF_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 Error Buffer Entry
46 */
48{
49 public:
50 /**
51 * Create an DsrErrorBuffEntry 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
57 * \param exp expiration time
58 * \param p protocol number
59 */
64 Time exp = Simulator::Now(),
65 uint8_t p = 0)
66 : m_packet(pa),
67 m_dst(d),
68 m_source(s),
69 m_nextHop(n),
70 m_expire(exp + Simulator::Now()),
71 m_protocol(p)
72 {
73 }
74
75 /**
76 * Compare send buffer entries
77 * \param o another DsrErrorBuffEntry
78 * \return true if equal
79 */
80 bool operator==(const DsrErrorBuffEntry& o) const
81 {
82 return ((m_packet == o.m_packet) && (m_source == o.m_source) &&
83 (m_nextHop == o.m_nextHop) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
84 }
85
86 // Fields
87 /**
88 * Get packet from entry
89 * \returns the packet
90 */
92 {
93 return m_packet;
94 }
95
96 /**
97 * Set packet for entry
98 * \param p the packet
99 */
101 {
102 m_packet = p;
103 }
104
105 /**
106 * Get destination address
107 * \returns the destination IPv4 address
108 */
110 {
111 return m_dst;
112 }
113
114 /**
115 * Set destination address
116 * \param d the destination IPv4 address
117 */
119 {
120 m_dst = d;
121 }
122
123 /**
124 * Get source address
125 * \returns the source IPv4 address
126 */
128 {
129 return m_source;
130 }
131
132 /**
133 * Set source address
134 * \param s the source IPv4 address
135 */
137 {
138 m_source = s;
139 }
140
141 /**
142 * Get next hop
143 * \returns the next hop address
144 */
146 {
147 return m_nextHop;
148 }
149
150 /**
151 * Set next hop
152 * \param n the next hop IPv4 address
153 */
155 {
156 m_nextHop = n;
157 }
158
159 /**
160 * Set expire time
161 * \param exp the expire time
162 */
164 {
165 m_expire = exp + Simulator::Now();
166 }
167
168 /**
169 * Get expire time
170 * \returns the expire time
171 */
173 {
174 return m_expire - Simulator::Now();
175 }
176
177 /**
178 * Set protocol number
179 * \param p the protocol number
180 */
181 void SetProtocol(uint8_t p)
182 {
183 m_protocol = p;
184 }
185
186 /**
187 * Get protocol number
188 * \returns the protocol number
189 */
190 uint8_t GetProtocol() const
191 {
192 return m_protocol;
193 }
194
195 private:
196 /// Data packet
198 /// Destination address
199 Ipv4Address m_dst; ///< destination address
200 /// Source address
201 Ipv4Address m_source; ///< source address
202 /// Nexthop address
203 Ipv4Address m_nextHop; ///< next hop
204 /// Expire time for queue entry
205 Time m_expire; ///< expiration time
206 /// The protocol number
207 uint8_t m_protocol;
208};
209
210/**
211 * \ingroup dsr
212 * \brief DSR error buffer
213 */
214/************************************************************************************************************************/
216{
217 public:
218 /**
219 * Default constructor
220 */
222 {
223 }
224
225 /**
226 * Push entry in queue, if there is no entry with the same packet and destination address in
227 * queue.
228 *
229 * \param entry error buffer entry
230 * \return true if entry added
231 */
232 bool Enqueue(DsrErrorBuffEntry& entry);
233 /**
234 * Return first found (the earliest) entry for given destination
235 * \param [in] dst The destination to look for
236 * \param [out] entry The entry
237 * \return true if an entry is found
238 */
239 bool Dequeue(Ipv4Address dst, DsrErrorBuffEntry& entry);
240 /**
241 * Remove all packets with the error link
242 * \param source The source
243 * \param nextHop The next hop
244 */
245 void DropPacketForErrLink(Ipv4Address source, Ipv4Address nextHop);
246 /**
247 * Finds whether a packet with destination dst exists in the queue
248 * \param dst The destination
249 * \return true if a packet is found.
250 */
251 bool Find(Ipv4Address dst);
252 /**
253 * Returns the number of entries in the queue.
254 * \return the number of entries in the queue.
255 */
257
258 // Fields
259 /**
260 * Get maximum queue length
261 * \returns the maximum queue length
262 */
264 {
265 return m_maxLen;
266 }
267
268 /**
269 * Set maximum queue length
270 * \param len the maximum queue length
271 */
273 {
274 m_maxLen = len;
275 }
276
277 /**
278 * Get error buffer timeout
279 * \returns the error buffer timeout
280 */
282 {
284 }
285
286 /**
287 * Set error buffer timeout
288 * \param t the error buffer timeout
289 */
291 {
293 }
294
295 /**
296 * Get error buffer entry
297 * \returns the DSR error buffer
298 */
299 std::vector<DsrErrorBuffEntry>& GetBuffer()
300 {
301 return m_errorBuffer;
302 }
303
304 private:
305 /// The send buffer to cache unsent packet
306 std::vector<DsrErrorBuffEntry> m_errorBuffer;
307 /// Remove all expired entries
308 void Purge();
309 /**
310 * Notify that packet is dropped from queue by timeout
311 * \param en Error Buffer Entry
312 * \param reason Drop reason.
313 */
314 ///
315 void Drop(DsrErrorBuffEntry en, std::string reason);
316 /**
317 * Notify that packet is dropped from queue by link error
318 * \param en Error Buffer Entry
319 * \param reason Drop reason.
320 */
321 void DropLink(DsrErrorBuffEntry en, std::string reason);
322 /// The maximum number of packets that we allow a routing protocol to buffer.
324 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
325 /// seconds.
327};
328
329/*******************************************************************************************************************************/
330} // namespace dsr
331} // namespace ns3
332
333#endif /* DSR_ERRORBUFF_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 Error Buffer Entry.
Definition: dsr-errorbuff.h:48
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.
Definition: dsr-errorbuff.h:60
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: dsr-errorbuff.h:91
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.
Definition: dsr-errorbuff.h:80
DSR error buffer.
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:305
Every class exported by the ns3 library is enclosed in the ns3 namespace.