A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsdv-packet-queue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Hemanth Narra
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: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_PACKETQUEUE_H
32#define DSDV_PACKETQUEUE_H
33
34#include "ns3/ipv4-routing-protocol.h"
35#include "ns3/simulator.h"
36
37#include <vector>
38
39namespace ns3
40{
41namespace dsdv
42{
43/**
44 * \ingroup dsdv
45 * \brief DSDV Queue Entry
46 */
48{
49 public:
50 /// Unicast forward call back function typedef
52 /// Error callback function typedef
54
55 /**
56 * c-tor
57 *
58 * \param pa the packet to create the entry
59 * \param h the Ipv4Header
60 * \param ucb the UnicastForwardCallback function
61 * \param ecb the ErrorCallback function
62 */
64 const Ipv4Header& h = Ipv4Header(),
67 : m_packet(pa),
68 m_header(h),
69 m_ucb(ucb),
70 m_ecb(ecb),
72 {
73 }
74
75 /**
76 * Compare queue entries
77 * \param o QueueEntry to compare
78 * \return true if equal
79 */
80 bool operator==(const QueueEntry& o) const
81 {
82 return ((m_packet == o.m_packet) &&
84 (m_expire == o.m_expire));
85 }
86
87 // Fields
88 /**
89 * Get unicast forward callback function
90 * \returns the unicast forward callback
91 */
93 {
94 return m_ucb;
95 }
96
97 /**
98 * Set unicast forward callback function
99 * \param ucb the unicast forward callback
100 */
102 {
103 m_ucb = ucb;
104 }
105
106 /**
107 * Get error callback function
108 * \returns the error callback
109 */
111 {
112 return m_ecb;
113 }
114
115 /**
116 * Set error callback function
117 * \param ecb the error callback
118 */
120 {
121 m_ecb = ecb;
122 }
123
124 /**
125 * Get packet
126 * \returns the current packet
127 */
129 {
130 return m_packet;
131 }
132
133 /**
134 * Set packet
135 * \param p The current packet
136 */
138 {
139 m_packet = p;
140 }
141
142 /**
143 * Get IP header
144 * \returns the IPv4 header
145 */
147 {
148 return m_header;
149 }
150
151 /**
152 * Set IP header
153 * \param h The IPv4 header
154 */
156 {
157 m_header = h;
158 }
159
160 /**
161 * Set expire time
162 * \param exp
163 */
165 {
166 m_expire = exp + Simulator::Now();
167 }
168
169 /**
170 * Get expire time
171 * \returns the expire time
172 */
174 {
175 return m_expire - Simulator::Now();
176 }
177
178 private:
179 /// Data packet
181 /// IP header
183 /// Unicast forward callback
185 /// Error callback
187 /// Expire time for queue entry
189};
190
191/**
192 * \ingroup dsdv
193 * \brief DSDV Packet queue
194 *
195 * When a route is not available, the packets are queued. Every node can buffer up to 5 packets per
196 * destination. We have implemented a "drop front on full" queue where the first queued packet will
197 * be dropped to accommodate newer packets.
198 */
200{
201 public:
202 /// Default c-tor
204 {
205 }
206
207 /**
208 * Push entry in queue, if there is no entry with the same packet and destination address in
209 * queue.
210 * \param entry QueueEntry to compare
211 * \return true if successful
212 */
213 bool Enqueue(QueueEntry& entry);
214 /**
215 * Return first found (the earliest) entry for given destination
216 *
217 * \param dst the destination IP address
218 * \param entry the queue entry
219 * \returns true if successful
220 */
221 bool Dequeue(Ipv4Address dst, QueueEntry& entry);
222 /**
223 * Remove all packets with destination IP address dst
224 * \param dst the destination IP address
225 */
227 /**
228 * Finds whether a packet with destination dst exists in the queue
229 * \param dst the destination IP address
230 * \returns true if a packet found
231 */
232 bool Find(Ipv4Address dst);
233 /**
234 * Get count of packets with destination dst in the queue
235 * \param dst the destination IP address
236 * \returns the count
237 */
239 /**
240 * Get the number of entries
241 * \returns the number of entries
242 */
244
245 // Fields
246 /**
247 * Get maximum queue length
248 * \returns the maximum queue length
249 */
251 {
252 return m_maxLen;
253 }
254
255 /**
256 * Set maximum queue length
257 * \param len the maximum queue length
258 */
260 {
261 m_maxLen = len;
262 }
263
264 /**
265 * Get maximum packets per destination
266 * \returns the maximum packets per destination
267 */
269 {
270 return m_maxLenPerDst;
271 }
272
273 /**
274 * Set maximum packets per destination
275 * \param len The maximum packets per destination
276 */
278 {
279 m_maxLenPerDst = len;
280 }
281
282 /**
283 * Get queue timeout
284 * \returns the queue timeout
285 */
287 {
288 return m_queueTimeout;
289 }
290
291 /**
292 * Set queue timeout
293 * \param t The queue timeout
294 */
296 {
297 m_queueTimeout = t;
298 }
299
300 private:
301 std::vector<QueueEntry> m_queue; ///< the queue
302 /// Remove all expired entries
303 void Purge();
304 /**
305 * Notify that the packet is dropped from queue due to timeout
306 * \param en the queue entry
307 * \param reason the reason for the packet drop
308 */
309 void Drop(QueueEntry en, std::string reason);
310 /// The maximum number of packets that we allow a routing protocol to buffer.
312 /// The maximum number of packets that we allow per destination to buffer.
314 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
315 /// seconds.
317};
318} // namespace dsdv
319} // namespace ns3
320#endif /* DSDV_PACKETQUEUE_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Ipv4Address GetDestination() const
Definition: ipv4-header.cc:316
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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
DSDV Packet queue.
std::vector< QueueEntry > m_queue
the queue
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
uint32_t GetMaxPacketsPerDst() const
Get maximum packets per destination.
void SetQueueTimeout(Time t)
Set queue timeout.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
void SetMaxPacketsPerDst(uint32_t len)
Set maximum packets per destination.
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
uint32_t GetSize()
Get the number of entries.
void Drop(QueueEntry en, std::string reason)
Notify that the packet is dropped from queue due to timeout.
Time GetQueueTimeout() const
Get queue timeout.
uint32_t GetCountForPacketsWithDst(Ipv4Address dst)
Get count of packets with destination dst in the queue.
PacketQueue()
Default c-tor.
uint32_t m_maxLenPerDst
The maximum number of packets that we allow per destination to buffer.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void Purge()
Remove all expired entries.
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
DSDV Queue Entry.
Ptr< const Packet > GetPacket() const
Get packet.
void SetErrorCallback(ErrorCallback ecb)
Set error callback function.
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback function.
void SetExpireTime(Time exp)
Set expire time.
QueueEntry(Ptr< const Packet > pa=nullptr, const Ipv4Header &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback())
c-tor
Time GetExpireTime() const
Get expire time.
void SetPacket(Ptr< const Packet > p)
Set packet.
Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback
Unicast forward call back function typedef.
Ptr< const Packet > m_packet
Data packet.
UnicastForwardCallback m_ucb
Unicast forward callback.
ErrorCallback GetErrorCallback() const
Get error callback function.
bool operator==(const QueueEntry &o) const
Compare queue entries.
ErrorCallback m_ecb
Error callback.
Ipv4Header GetIpv4Header() const
Get IP header.
Ipv4Header m_header
IP header.
Time m_expire
Expire time for queue entry.
Ipv4RoutingProtocol::ErrorCallback ErrorCallback
Error callback function typedef.
void SetIpv4Header(Ipv4Header h)
Set IP header.
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback function.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.