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