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:
50  UnicastForwardCallback ucb = UnicastForwardCallback (),
51  ErrorCallback ecb = ErrorCallback (), Time exp = Simulator::Now ()) :
52  m_packet (pa), m_header (h), m_ucb (ucb), m_ecb (ecb),
53  m_expire (exp + Simulator::Now ())
54  {}
55 
60  bool operator== (QueueEntry const & o) const
61  {
62  return ((m_packet == o.m_packet) && (m_header.GetDestination () == o.m_header.GetDestination ()) && (m_expire == o.m_expire));
63  }
64 
65  // Fields
66  UnicastForwardCallback GetUnicastForwardCallback () const { return m_ucb; }
67  void SetUnicastForwardCallback (UnicastForwardCallback ucb) { m_ucb = ucb; }
68  ErrorCallback GetErrorCallback () const { return m_ecb; }
69  void SetErrorCallback (ErrorCallback ecb) { m_ecb = ecb; }
70  Ptr<const Packet> GetPacket () const { return m_packet; }
72  Ipv4Header GetIpv4Header () const { return m_header; }
73  void SetIpv4Header (Ipv4Header h) { m_header = h; }
74  void SetExpireTime (Time exp) { m_expire = exp + Simulator::Now (); }
75  Time GetExpireTime () const { return m_expire - Simulator::Now (); }
76 
77 private:
78 
84  UnicastForwardCallback m_ucb;
86  ErrorCallback m_ecb;
89 };
97 {
98 public:
100  RequestQueue (uint32_t maxLen, Time routeToQueueTimeout) :
101  m_maxLen (maxLen), m_queueTimeout (routeToQueueTimeout)
102  {
103  }
105  bool Enqueue (QueueEntry & entry);
107  bool Dequeue (Ipv4Address dst, QueueEntry & entry);
109  void DropPacketWithDst (Ipv4Address dst);
111  bool Find (Ipv4Address dst);
113  uint32_t GetSize ();
114 
115  // Fields
116  uint32_t GetMaxQueueLen () const { return m_maxLen; }
117  void SetMaxQueueLen (uint32_t len) { m_maxLen = len; }
118  Time GetQueueTimeout () const { return m_queueTimeout; }
120 
121 private:
122 
123  std::vector<QueueEntry> m_queue;
125  void Purge ();
127  void Drop (QueueEntry en, std::string reason);
129  uint32_t m_maxLen;
132  static bool IsEqual (QueueEntry en, const Ipv4Address dst) { return (en.GetIpv4Header ().GetDestination () == dst); }
133 };
134 
135 
136 }
137 }
138 
139 #endif /* AODV_RQUEUE_H */
UnicastForwardCallback GetUnicastForwardCallback() const
Definition: aodv-rqueue.h:66
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:96
Ipv4Header GetIpv4Header() const
Definition: aodv-rqueue.h:72
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Definition: aodv-rqueue.cc:142
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
void SetMaxQueueLen(uint32_t len)
Definition: aodv-rqueue.h:117
void SetUnicastForwardCallback(UnicastForwardCallback ucb)
Definition: aodv-rqueue.h:67
QueueEntry(Ptr< const Packet > pa=0, Ipv4Header const &h=Ipv4Header(), UnicastForwardCallback ucb=UnicastForwardCallback(), ErrorCallback ecb=ErrorCallback(), Time exp=Simulator::Now())
c-tor
Definition: aodv-rqueue.h:49
UnicastForwardCallback m_ucb
Unicast forward callback.
Definition: aodv-rqueue.h:84
void SetExpireTime(Time exp)
Definition: aodv-rqueue.h:74
Ipv4RoutingProtocol::ErrorCallback ErrorCallback
Definition: aodv-rqueue.h:47
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:50
Packet header for IPv4.
Definition: ipv4-header.h:33
void SetErrorCallback(ErrorCallback ecb)
Definition: aodv-rqueue.h:69
Time GetQueueTimeout() const
Definition: aodv-rqueue.h:118
void SetIpv4Header(Ipv4Header h)
Definition: aodv-rqueue.h:73
bool operator==(QueueEntry const &o) const
Compare queue entries.
Definition: aodv-rqueue.h:60
Time m_expire
Expire time for queue entry.
Definition: aodv-rqueue.h:88
std::vector< QueueEntry > m_queue
Definition: aodv-rqueue.h:123
uint32_t GetMaxQueueLen() const
Definition: aodv-rqueue.h:116
Ptr< const Packet > GetPacket() const
Definition: aodv-rqueue.h:70
Ipv4RoutingProtocol::UnicastForwardCallback UnicastForwardCallback
Definition: aodv-rqueue.h:46
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition: aodv-rqueue.cc:72
Ptr< const Packet > m_packet
Data packet.
Definition: aodv-rqueue.h:80
AODV Queue Entry.
Definition: aodv-rqueue.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ErrorCallback GetErrorCallback() const
Definition: aodv-rqueue.h:68
uint32_t GetSize()
Number of entries.
Definition: aodv-rqueue.cc:43
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
Definition: aodv-rqueue.h:131
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
Time GetExpireTime() const
Definition: aodv-rqueue.h:75
ErrorCallback m_ecb
Error callback.
Definition: aodv-rqueue.h:86
Ipv4Header m_header
IP header.
Definition: aodv-rqueue.h:82
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
void SetQueueTimeout(Time t)
Definition: aodv-rqueue.h:119
void Purge()
Remove all expired entries.
Definition: aodv-rqueue.cc:126
static bool IsEqual(QueueEntry en, const Ipv4Address dst)
Definition: aodv-rqueue.h:132
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Definition: aodv-rqueue.h:129
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
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)
Default c-tor.
Definition: aodv-rqueue.h:100
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)
Definition: aodv-rqueue.h:71