A Discrete-Event Network Simulator
API
aodv-rqueue.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Based on
19  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21  *
22  * AODV-UU implementation by Erik Nordström of Uppsala University
23  * http://core.it.uu.se/core/index.php/AODV-UU
24  *
25  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26  * Pavel Boyko <boyko@iitp.ru>
27  */
28 #ifndef AODV_RQUEUE_H
29 #define AODV_RQUEUE_H
30 
31 #include <vector>
32 #include "ns3/ipv4-routing-protocol.h"
33 #include "ns3/simulator.h"
34 
35 
36 namespace ns3 {
37 namespace aodv {
38 
44 {
45 public:
62  : m_packet (pa),
63  m_header (h),
64  m_ucb (ucb),
65  m_ecb (ecb),
66  m_expire (exp + Simulator::Now ())
67  {
68  }
69 
75  bool operator== (QueueEntry const & o) const
76  {
77  return ((m_packet == o.m_packet) && (m_header.GetDestination () == o.m_header.GetDestination ()) && (m_expire == o.m_expire));
78  }
79 
80  // Fields
86  {
87  return m_ucb;
88  }
94  {
95  m_ucb = ucb;
96  }
102  {
103  return m_ecb;
104  }
110  {
111  m_ecb = ecb;
112  }
118  {
119  return m_packet;
120  }
126  {
127  m_packet = p;
128  }
134  {
135  return m_header;
136  }
142  {
143  m_header = h;
144  }
149  void SetExpireTime (Time exp)
150  {
151  m_expire = exp + Simulator::Now ();
152  }
158  {
159  return m_expire - Simulator::Now ();
160  }
161 
162 private:
173 };
181 {
182 public:
189  RequestQueue (uint32_t maxLen, Time routeToQueueTimeout)
190  : m_maxLen (maxLen),
191  m_queueTimeout (routeToQueueTimeout)
192  {
193  }
199  bool Enqueue (QueueEntry & entry);
207  bool Dequeue (Ipv4Address dst, QueueEntry & entry);
212  void DropPacketWithDst (Ipv4Address dst);
219  bool Find (Ipv4Address dst);
223  uint32_t GetSize ();
224 
225  // Fields
230  uint32_t GetMaxQueueLen () const
231  {
232  return m_maxLen;
233  }
238  void SetMaxQueueLen (uint32_t len)
239  {
240  m_maxLen = len;
241  }
247  {
248  return m_queueTimeout;
249  }
255  {
256  m_queueTimeout = t;
257  }
258 
259 private:
261  std::vector<QueueEntry> m_queue;
263  void Purge ();
269  void Drop (QueueEntry en, std::string reason);
271  uint32_t m_maxLen;
280  static bool IsEqual (QueueEntry en, const Ipv4Address dst)
281  {
282  return (en.GetIpv4Header ().GetDestination () == dst);
283  }
284 };
285 
286 
287 } // namespace aodv
288 } // namespace ns3
289 
290 #endif /* AODV_RQUEUE_H */
UnicastForwardCallback GetUnicastForwardCallback() const
Get unicast forward callback.
Definition: aodv-rqueue.h:85
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Control the scheduling of simulation events.
Definition: simulator.h:68
Callback template class.
Definition: callback.h:1176
AODV route request queue.
Definition: aodv-rqueue.h:180
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Definition: aodv-rqueue.cc:153
void SetMaxQueueLen(uint32_t len)
Set maximum queue length.
Definition: aodv-rqueue.h:238
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Set unicast forward callback.
Definition: aodv-rqueue.h:93
QueueEntry(Ptr< const Packet > pa=0, Ipv4Header const &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback(), Time exp=Simulator::Now())
constructor
Definition: aodv-rqueue.h:59
UnicastForwardCallback m_ucb
Unicast forward callback.
Definition: aodv-rqueue.h:168
void SetExpireTime(Time exp)
Set expire time.
Definition: aodv-rqueue.h:149
Ipv4RoutingProtocol::ErrorCallback ErrorCallback
IPv4 routing error callback typedef.
Definition: aodv-rqueue.h:49
Time GetExpireTime() const
Get expire time.
Definition: aodv-rqueue.h:157
Time GetQueueTimeout() const
Get queue timeout.
Definition: aodv-rqueue.h:246
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:48
Packet header for IPv4.
Definition: ipv4-header.h:33
void SetErrorCallback(ErrorCallback ecb)
Set error callback.
Definition: aodv-rqueue.h:109
void SetIpv4Header(Ipv4Header h)
Set IPv4 header.
Definition: aodv-rqueue.h:141
Time m_expire
Expire time for queue entry.
Definition: aodv-rqueue.h:172
std::vector< QueueEntry > m_queue
The queue.
Definition: aodv-rqueue.h:261
Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback
IPv4 routing unicast forward callback typedef.
Definition: aodv-rqueue.h:47
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition: aodv-rqueue.cc:72
bool operator==(QueueEntry const &o) const
Compare queue entries.
Definition: aodv-rqueue.h:75
Ptr< const Packet > m_packet
Data packet.
Definition: aodv-rqueue.h:164
AODV Queue Entry.
Definition: aodv-rqueue.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
Definition: aodv-rqueue.h:273
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
ErrorCallback m_ecb
Error callback.
Definition: aodv-rqueue.h:170
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
Ipv4Header m_header
IP header.
Definition: aodv-rqueue.h:166
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Definition: aodv-rqueue.h:133
void SetQueueTimeout(Time t)
Set queue timeout.
Definition: aodv-rqueue.h:254
void Purge()
Remove all expired entries.
Definition: aodv-rqueue.cc:137
static bool IsEqual(QueueEntry en, const Ipv4Address dst)
Determine if queue matches a destination address.
Definition: aodv-rqueue.h:280
ErrorCallback GetErrorCallback() const
Get error callback.
Definition: aodv-rqueue.h:101
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Definition: aodv-rqueue.h:271
uint32_t GetMaxQueueLen() const
Get maximum queue length.
Definition: aodv-rqueue.h:230
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:105
RequestQueue(uint32_t maxLen, Time routeToQueueTimeout)
constructor
Definition: aodv-rqueue.h:189
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition: aodv-rqueue.cc:89
void SetPacket(Ptr< const Packet > p)
Set packet in entry.
Definition: aodv-rqueue.h:125
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition: aodv-rqueue.h:117