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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Hemanth Narra <hemanth@ittc.ku.com>
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 DSDV_PACKETQUEUE_H
21#define DSDV_PACKETQUEUE_H
22
23#include "ns3/ipv4-routing-protocol.h"
24#include "ns3/simulator.h"
25
26#include <vector>
27
28namespace ns3
29{
30namespace dsdv
31{
32/**
33 * @ingroup dsdv
34 * @brief DSDV Queue Entry
35 */
37{
38 public:
39 /// Unicast forward call back function typedef
41 /// Error callback function typedef
43
44 /**
45 * c-tor
46 *
47 * @param pa the packet to create the entry
48 * @param h the Ipv4Header
49 * @param ucb the UnicastForwardCallback function
50 * @param ecb the ErrorCallback function
51 */
53 const Ipv4Header& h = Ipv4Header(),
56 : m_packet(pa),
57 m_header(h),
58 m_ucb(ucb),
59 m_ecb(ecb),
60 m_expire()
61 {
62 }
63
64 /**
65 * Compare queue entries
66 * @param o QueueEntry to compare
67 * @return true if equal
68 */
69 bool operator==(const QueueEntry& o) const
70 {
71 return ((m_packet == o.m_packet) &&
73 (m_expire == o.m_expire));
74 }
75
76 // Fields
77 /**
78 * Get unicast forward callback function
79 * @returns the unicast forward callback
80 */
85
86 /**
87 * Set unicast forward callback function
88 * @param ucb the unicast forward callback
89 */
94
95 /**
96 * Get error callback function
97 * @returns the error callback
98 */
100 {
101 return m_ecb;
102 }
103
104 /**
105 * Set error callback function
106 * @param ecb the error callback
107 */
109 {
110 m_ecb = ecb;
111 }
112
113 /**
114 * Get packet
115 * @returns the current packet
116 */
118 {
119 return m_packet;
120 }
121
122 /**
123 * Set packet
124 * @param p The current packet
125 */
127 {
128 m_packet = p;
129 }
130
131 /**
132 * Get IP header
133 * @returns the IPv4 header
134 */
136 {
137 return m_header;
138 }
139
140 /**
141 * Set IP header
142 * @param h The IPv4 header
143 */
145 {
146 m_header = h;
147 }
148
149 /**
150 * Set expire time
151 * @param exp
152 */
154 {
155 m_expire = exp + Simulator::Now();
156 }
157
158 /**
159 * Get expire time
160 * @returns the expire time
161 */
163 {
164 return m_expire - Simulator::Now();
165 }
166
167 private:
168 /// Data packet
170 /// IP header
172 /// Unicast forward callback
174 /// Error callback
176 /// Expire time for queue entry
178};
179
180/**
181 * @ingroup dsdv
182 * @brief DSDV Packet queue
183 *
184 * When a route is not available, the packets are queued. Every node can buffer up to 5 packets per
185 * destination. We have implemented a "drop front on full" queue where the first queued packet will
186 * be dropped to accommodate newer packets.
187 */
189{
190 public:
191 /// Default c-tor
193 {
194 }
195
196 /**
197 * Push entry in queue, if there is no entry with the same packet and destination address in
198 * queue.
199 * @param entry QueueEntry to compare
200 * @return true if successful
201 */
202 bool Enqueue(QueueEntry& entry);
203 /**
204 * Return first found (the earliest) entry for given destination
205 *
206 * @param dst the destination IP address
207 * @param entry the queue entry
208 * @returns true if successful
209 */
210 bool Dequeue(Ipv4Address dst, QueueEntry& entry);
211 /**
212 * Remove all packets with destination IP address dst
213 * @param dst the destination IP address
214 */
216 /**
217 * Finds whether a packet with destination dst exists in the queue
218 * @param dst the destination IP address
219 * @returns true if a packet found
220 */
221 bool Find(Ipv4Address dst);
222 /**
223 * Get count of packets with destination dst in the queue
224 * @param dst the destination IP address
225 * @returns the count
226 */
228 /**
229 * Get the number of entries
230 * @returns the number of entries
231 */
233
234 // Fields
235 /**
236 * Get maximum queue length
237 * @returns the maximum queue length
238 */
240 {
241 return m_maxLen;
242 }
243
244 /**
245 * Set maximum queue length
246 * @param len the maximum queue length
247 */
249 {
250 m_maxLen = len;
251 }
252
253 /**
254 * Get maximum packets per destination
255 * @returns the maximum packets per destination
256 */
258 {
259 return m_maxLenPerDst;
260 }
261
262 /**
263 * Set maximum packets per destination
264 * @param len The maximum packets per destination
265 */
267 {
268 m_maxLenPerDst = len;
269 }
270
271 /**
272 * Get queue timeout
273 * @returns the queue timeout
274 */
276 {
277 return m_queueTimeout;
278 }
279
280 /**
281 * Set queue timeout
282 * @param t The queue timeout
283 */
285 {
286 m_queueTimeout = t;
287 }
288
289 private:
290 std::vector<QueueEntry> m_queue; ///< the queue
291 /// Remove all expired entries
292 void Purge();
293 /**
294 * Notify that the packet is dropped from queue due to timeout
295 * @param en the queue entry
296 * @param reason the reason for the packet drop
297 */
298 void Drop(QueueEntry en, std::string reason);
299 /// The maximum number of packets that we allow a routing protocol to buffer.
301 /// The maximum number of packets that we allow per destination to buffer.
303 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
304 /// seconds.
306};
307} // namespace dsdv
308} // namespace ns3
309#endif /* DSDV_PACKETQUEUE_H */
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
Ipv4Address GetDestination() const
Smart pointer class similar to boost::intrusive_ptr.
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
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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.