A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-rsendbuff.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_SENDBUFF_H
32#define DSR_SENDBUFF_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 Send Buffer Entry
46 */
48{
49 public:
50 /**
51 * Construct DsrSendBuffEntry with the given parameters.
52 *
53 * \param pa packet
54 * \param d destination address
55 * \param exp expiration time
56 * \param p protocol number
57 */
60 Time exp = Simulator::Now(),
61 uint8_t p = 0)
62 : m_packet(pa),
63 m_dst(d),
64 m_expire(exp + Simulator::Now()),
65 m_protocol(p)
66 {
67 }
68
69 /**
70 * Compare send buffer entries
71 * \param o another DsrSendBuffEntry
72 * \return true if equal
73 */
74 bool operator==(const DsrSendBuffEntry& o) const
75 {
76 return ((m_packet == o.m_packet) && (m_dst == o.m_dst) && (m_expire == o.m_expire));
77 }
78
79 // Fields
80 /**
81 * Get pointer to entry's packet
82 * \returns the current packet
83 */
85 {
86 return m_packet;
87 }
88
89 /**
90 * Set pointer to entry's packet
91 * \param p the current packet
92 */
94 {
95 m_packet = p;
96 }
97
98 /**
99 * Get destination address of entry
100 * \returns the destination IPv4 address
101 */
103 {
104 return m_dst;
105 }
106
107 /**
108 * Set destination address of entry
109 * \param d the destination IP address
110 */
112 {
113 m_dst = d;
114 }
115
116 /**
117 * Set expire time for entry
118 * \param exp the expire time
119 */
121 {
122 m_expire = exp + Simulator::Now();
123 }
124
125 /**
126 * Get expire time for entry
127 * \returns the expire time
128 */
130 {
131 return m_expire - Simulator::Now();
132 }
133
134 /**
135 * Set protocol value
136 * \param p the protocol
137 */
138 void SetProtocol(uint8_t p)
139 {
140 m_protocol = p;
141 }
142
143 /**
144 * Get protocol value
145 * \returns the protocol
146 */
147 uint8_t GetProtocol() const
148 {
149 return m_protocol;
150 }
151
152 private:
153 /// Data packet
155 /// Destination address
157 /// Expire time for queue entry
159 /// The protocol number
160 uint8_t m_protocol;
161};
162
163/**
164 * \ingroup dsr
165 * \brief DSR send buffer
166 */
167/************************************************************************************************************************/
169{
170 public:
171 /**
172 * Default constructor
173 */
175 {
176 }
177
178 /**
179 * Push entry in queue, if there is no entry with
180 * the same packet and destination address in queue.
181 *
182 * \param entry DsrSendBuffEntry to put in the queue
183 * \return true if successfully enqueued,
184 * false otherwise
185 */
186 bool Enqueue(DsrSendBuffEntry& entry);
187 /**
188 * Return first found (the earliest) entry for
189 * the given destination.
190 *
191 * \param dst IPv4 address of the destination
192 * \param entry pointer to entry to return
193 * \return true if successfully dequeued,
194 * false otherwise
195 */
196 bool Dequeue(Ipv4Address dst, DsrSendBuffEntry& entry);
197 /**
198 * Remove all packets with destination IP address dst
199 *
200 * \param dst IPv4 address of the destination
201 */
203 /**
204 * Check if a packet with destination dst exists in the queue
205 *
206 * \param dst IPv4 address of the destination
207 * \return true if found, false otherwise
208 */
209 bool Find(Ipv4Address dst);
210 /**
211 * Number of entries
212 *
213 * \return the number of entries in the queue
214 */
216
217 /**
218 * Return the maximum queue length
219 *
220 * \return the maximum queue length
221 */
223 {
224 return m_maxLen;
225 }
226
227 /**
228 * Set the maximum queue length
229 *
230 * \param len the maximum queue length
231 */
233 {
234 m_maxLen = len;
235 }
236
237 /**
238 * Return the entry lifetime in the queue
239 *
240 * \return the entry lifetime in the queue
241 */
243 {
244 return m_sendBufferTimeout;
245 }
246
247 /**
248 * Set the entry lifetime in the queue
249 *
250 * \param t the entry lifetime in the queue
251 */
253 {
255 }
256
257 // \}
258
259 /**
260 * Return a pointer to the internal queue
261 *
262 * \return a pointer to the internal queue
263 */
264 std::vector<DsrSendBuffEntry>& GetBuffer()
265 {
266 return m_sendBuffer;
267 }
268
269 private:
270 std::vector<DsrSendBuffEntry> m_sendBuffer; ///< The send buffer to cache unsent packet
271 void Purge(); ///< Remove all expired entries
272
273 /// Notify that packet is dropped from queue by timeout
274 /// \param en BuffEntry Buffer entry
275 /// \param reason Drop reason
276 void Drop(DsrSendBuffEntry en, std::string reason);
277
279 m_maxLen; ///< The maximum number of packets that we allow a routing protocol to buffer.
280 Time m_sendBufferTimeout; ///< The maximum period of time that a routing protocol is allowed to
281 ///< buffer a packet for, seconds.
282};
283
284/*******************************************************************************************************************************/
285} // namespace dsr
286} // namespace ns3
287
288#endif /* DSR_SENDBUFF_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 Send Buffer Entry.
Definition: dsr-rsendbuff.h:48
Ipv4Address m_dst
Destination address.
Ptr< const Packet > m_packet
Data packet.
DsrSendBuffEntry(Ptr< const Packet > pa=nullptr, Ipv4Address d=Ipv4Address(), Time exp=Simulator::Now(), uint8_t p=0)
Construct DsrSendBuffEntry with the given parameters.
Definition: dsr-rsendbuff.h:58
uint8_t m_protocol
The protocol number.
void SetDestination(Ipv4Address d)
Set destination address of entry.
void SetPacket(Ptr< const Packet > p)
Set pointer to entry's packet.
Definition: dsr-rsendbuff.h:93
Time GetExpireTime() const
Get expire time for entry.
void SetProtocol(uint8_t p)
Set protocol value.
Ipv4Address GetDestination() const
Get destination address of entry.
Time m_expire
Expire time for queue entry.
uint8_t GetProtocol() const
Get protocol value.
void SetExpireTime(Time exp)
Set expire time for entry.
Ptr< const Packet > GetPacket() const
Get pointer to entry's packet.
Definition: dsr-rsendbuff.h:84
bool operator==(const DsrSendBuffEntry &o) const
Compare send buffer entries.
Definition: dsr-rsendbuff.h:74
DSR send buffer.
void SetMaxQueueLen(uint32_t len)
Set the maximum queue length.
Time GetSendBufferTimeout() const
Return the entry lifetime in the queue.
uint32_t GetSize()
Number of entries.
bool Dequeue(Ipv4Address dst, DsrSendBuffEntry &entry)
Return first found (the earliest) entry for the given destination.
uint32_t GetMaxQueueLen() const
Return the maximum queue length.
void SetSendBufferTimeout(Time t)
Set the entry lifetime in the queue.
void Purge()
Remove all expired entries.
Time m_sendBufferTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
std::vector< DsrSendBuffEntry > m_sendBuffer
The send buffer to cache unsent packet.
std::vector< DsrSendBuffEntry > & GetBuffer()
Return a pointer to the internal queue.
bool Enqueue(DsrSendBuffEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
bool Find(Ipv4Address dst)
Check if a packet with destination dst exists in the queue.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void Drop(DsrSendBuffEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
DsrSendBuffer()
Default constructor.
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.