A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-rqueue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Based on
7 * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
8 * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
9 *
10 * AODV-UU implementation by Erik Nordström of Uppsala University
11 * https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
12 *
13 * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
14 * Pavel Boyko <boyko@iitp.ru>
15 */
16#ifndef AODV_RQUEUE_H
17#define AODV_RQUEUE_H
18
19#include "ns3/ipv4-routing-protocol.h"
20#include "ns3/simulator.h"
21
22#include <vector>
23
24namespace ns3
25{
26namespace aodv
27{
28
29/**
30 * \ingroup aodv
31 * \brief AODV Queue Entry
32 */
34{
35 public:
36 /// IPv4 routing unicast forward callback typedef
38 /// IPv4 routing error callback typedef
40
41 /**
42 * constructor
43 *
44 * \param pa the packet to add to the queue
45 * \param h the Ipv4Header
46 * \param ucb the UnicastForwardCallback function
47 * \param ecb the ErrorCallback function
48 * \param exp the expiration time
49 */
51 const Ipv4Header& h = Ipv4Header(),
54 Time exp = Simulator::Now())
55 : m_packet(pa),
56 m_header(h),
57 m_ucb(ucb),
58 m_ecb(ecb),
59 m_expire(exp + Simulator::Now())
60 {
61 }
62
63 /**
64 * \brief Compare queue entries
65 * \param o QueueEntry to compare
66 * \return true if equal
67 */
68 bool operator==(const QueueEntry& o) const
69 {
70 return ((m_packet == o.m_packet) &&
72 (m_expire == o.m_expire));
73 }
74
75 // Fields
76 /**
77 * Get unicast forward callback
78 * \returns unicast callback
79 */
84
85 /**
86 * Set unicast forward callback
87 * \param ucb The unicast callback
88 */
93
94 /**
95 * Get error callback
96 * \returns the error callback
97 */
99 {
100 return m_ecb;
101 }
102
103 /**
104 * Set error callback
105 * \param ecb The error callback
106 */
108 {
109 m_ecb = ecb;
110 }
111
112 /**
113 * Get packet from entry
114 * \returns the packet
115 */
117 {
118 return m_packet;
119 }
120
121 /**
122 * Set packet in entry
123 * \param p The packet
124 */
126 {
127 m_packet = p;
128 }
129
130 /**
131 * Get IPv4 header
132 * \returns the IPv4 header
133 */
135 {
136 return m_header;
137 }
138
139 /**
140 * Set IPv4 header
141 * \param h the IPv4 header
142 */
144 {
145 m_header = h;
146 }
147
148 /**
149 * Set expire time
150 * \param exp The expiration time
151 */
153 {
154 m_expire = exp + Simulator::Now();
155 }
156
157 /**
158 * Get expire time
159 * \returns the expiration time
160 */
162 {
163 return m_expire - Simulator::Now();
164 }
165
166 private:
167 /// Data packet
169 /// IP header
171 /// Unicast forward callback
173 /// Error callback
175 /// Expire time for queue entry
177};
178
179/**
180 * \ingroup aodv
181 * \brief AODV route request queue
182 *
183 * Since AODV is an on demand routing we queue requests while looking for route.
184 */
186{
187 public:
188 /**
189 * constructor
190 *
191 * \param maxLen the maximum length
192 * \param routeToQueueTimeout the route to queue timeout
193 */
194 RequestQueue(uint32_t maxLen, Time routeToQueueTimeout)
195 : m_maxLen(maxLen),
196 m_queueTimeout(routeToQueueTimeout)
197 {
198 }
199
200 /**
201 * Push entry in queue, if there is no entry with the same packet and destination address in
202 * queue.
203 * \param entry the queue entry
204 * \returns true if the entry is queued
205 */
206 bool Enqueue(QueueEntry& entry);
207 /**
208 * Return first found (the earliest) entry for given destination
209 *
210 * \param dst the destination IP address
211 * \param entry the queue entry
212 * \returns true if the entry is dequeued
213 */
214 bool Dequeue(Ipv4Address dst, QueueEntry& entry);
215 /**
216 * Remove all packets with destination IP address dst
217 * \param dst the destination IP address
218 */
220 /**
221 * Finds whether a packet with destination dst exists in the queue
222 *
223 * \param dst the destination IP address
224 * \returns true if an entry with the IP address is found
225 */
226 bool Find(Ipv4Address dst);
227 /**
228 * \returns the number of entries
229 */
231
232 // Fields
233 /**
234 * Get maximum queue length
235 * \returns the maximum queue length
236 */
238 {
239 return m_maxLen;
240 }
241
242 /**
243 * Set maximum queue length
244 * \param len The maximum queue length
245 */
247 {
248 m_maxLen = len;
249 }
250
251 /**
252 * Get queue timeout
253 * \returns the queue timeout
254 */
256 {
257 return m_queueTimeout;
258 }
259
260 /**
261 * Set queue timeout
262 * \param t The queue timeout
263 */
265 {
266 m_queueTimeout = t;
267 }
268
269 private:
270 /// The queue
271 std::vector<QueueEntry> m_queue;
272 /// Remove all expired entries
273 void Purge();
274 /**
275 * Notify that packet is dropped from queue by timeout
276 * \param en the queue entry to drop
277 * \param reason the reason to drop the entry
278 */
279 void Drop(QueueEntry en, std::string reason);
280 /// The maximum number of packets that we allow a routing protocol to buffer.
282 /// The maximum period of time that a routing protocol is allowed to buffer a packet for,
283 /// seconds.
285};
286
287} // namespace aodv
288} // namespace ns3
289
290#endif /* AODV_RQUEUE_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.
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
AODV Queue Entry.
Definition aodv-rqueue.h:34
Time GetExpireTime() const
Get expire time.
Ipv4RoutingProtocol::ErrorCallback ErrorCallback
IPv4 routing error callback typedef.
Definition aodv-rqueue.h:39
Ipv4Header m_header
IP header.
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
Ptr< const Packet > m_packet
Data packet.
bool operator==(const QueueEntry &o) const
Compare queue entries.
Definition aodv-rqueue.h:68
UnicastForwardCallback m_ucb
Unicast forward callback.
ErrorCallback GetErrorCallback() const
Get error callback.
Definition aodv-rqueue.h:98
void SetPacket(Ptr< const Packet > p)
Set packet in entry.
ErrorCallback m_ecb
Error callback.
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition aodv-rqueue.h:89
void SetExpireTime(Time exp)
Set expire time.
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Ptr< const Packet > GetPacket() const
Get packet from entry.
Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback
IPv4 routing unicast forward callback typedef.
Definition aodv-rqueue.h:37
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition aodv-rqueue.h:80
QueueEntry(Ptr< const Packet > pa=nullptr, const Ipv4Header &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback(), Time exp=Simulator::Now())
constructor
Definition aodv-rqueue.h:50
Time m_expire
Expire time for queue entry.
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
AODV route request queue.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Time GetQueueTimeout() const
Get queue timeout.
void Purge()
Remove all expired entries.
std::vector< QueueEntry > m_queue
The queue.
void SetQueueTimeout(Time t)
Set queue timeout.
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
RequestQueue(uint32_t maxLen, Time routeToQueueTimeout)
constructor
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
uint32_t GetMaxQueueLen() const
Get maximum queue length.
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.