A Discrete-Event Network Simulator
API
aodv-rqueue.cc
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 #include "aodv-rqueue.h"
28 
29 #include "ns3/ipv4-route.h"
30 #include "ns3/log.h"
31 #include "ns3/socket.h"
32 
33 #include <algorithm>
34 #include <functional>
35 
36 namespace ns3
37 {
38 
39 NS_LOG_COMPONENT_DEFINE("AodvRequestQueue");
40 
41 namespace aodv
42 {
43 uint32_t
45 {
46  Purge();
47  return m_queue.size();
48 }
49 
50 bool
52 {
53  Purge();
54  for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
55  {
56  if ((i->GetPacket()->GetUid() == entry.GetPacket()->GetUid()) &&
57  (i->GetIpv4Header().GetDestination() == entry.GetIpv4Header().GetDestination()))
58  {
59  return false;
60  }
61  }
63  if (m_queue.size() == m_maxLen)
64  {
65  Drop(m_queue.front(), "Drop the most aged packet"); // Drop the most aged packet
66  m_queue.erase(m_queue.begin());
67  }
68  m_queue.push_back(entry);
69  return true;
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION(this << dst);
76  Purge();
77  for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
78  {
79  if (i->GetIpv4Header().GetDestination() == dst)
80  {
81  Drop(*i, "DropPacketWithDst ");
82  }
83  }
84  auto new_end = std::remove_if(m_queue.begin(), m_queue.end(), [&](const QueueEntry& en) {
85  return en.GetIpv4Header().GetDestination() == dst;
86  });
87  m_queue.erase(new_end, m_queue.end());
88 }
89 
90 bool
92 {
93  Purge();
94  for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
95  {
96  if (i->GetIpv4Header().GetDestination() == dst)
97  {
98  entry = *i;
99  m_queue.erase(i);
100  return true;
101  }
102  }
103  return false;
104 }
105 
106 bool
108 {
109  for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
110  {
111  if (i->GetIpv4Header().GetDestination() == dst)
112  {
113  return true;
114  }
115  }
116  return false;
117 }
118 
122 struct IsExpired
123 {
130  bool operator()(const QueueEntry& e) const
131  {
132  return (e.GetExpireTime() < Seconds(0));
133  }
134 };
135 
136 void
138 {
139  IsExpired pred;
140  for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
141  {
142  if (pred(*i))
143  {
144  Drop(*i, "Drop outdated packet ");
145  }
146  }
147  m_queue.erase(std::remove_if(m_queue.begin(), m_queue.end(), pred), m_queue.end());
148 }
149 
150 void
151 RequestQueue::Drop(QueueEntry en, std::string reason)
152 {
153  NS_LOG_LOGIC(reason << en.GetPacket()->GetUid() << " " << en.GetIpv4Header().GetDestination());
155 }
156 
157 } // namespace aodv
158 } // namespace ns3
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Ipv4Address GetDestination() const
Definition: ipv4-header.cc:316
uint64_t GetUid() const
Returns the packet's Uid.
Definition: packet.cc:412
@ ERROR_NOROUTETOHOST
Definition: socket.h:95
AODV Queue Entry.
Definition: aodv-rqueue.h:45
Time GetExpireTime() const
Get expire time.
Definition: aodv-rqueue.h:172
ErrorCallback GetErrorCallback() const
Get error callback.
Definition: aodv-rqueue.h:109
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
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
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition: aodv-rqueue.cc:107
void Purge()
Remove all expired entries.
Definition: aodv-rqueue.cc:137
std::vector< QueueEntry > m_queue
The queue.
Definition: aodv-rqueue.h:282
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
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Definition: aodv-rqueue.cc:151
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IsExpired structure.
Definition: aodv-rqueue.cc:123
bool operator()(const QueueEntry &e) const
Check if the entry is expired.
Definition: aodv-rqueue.cc:130