A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
aodv-rqueue.cc
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
#include "
aodv-rqueue.h
"
29
#include <algorithm>
30
#include <functional>
31
#include "ns3/ipv4-route.h"
32
#include "ns3/socket.h"
33
#include "ns3/log.h"
34
35
namespace
ns3
{
36
37
NS_LOG_COMPONENT_DEFINE
(
"AodvRequestQueue"
);
38
39
namespace
aodv {
40
uint32_t
41
RequestQueue::GetSize
()
42
{
43
Purge
();
44
return
m_queue
.size ();
45
}
46
47
bool
48
RequestQueue::Enqueue
(
QueueEntry
& entry)
49
{
50
Purge
();
51
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
52
!=
m_queue
.end (); ++i)
53
{
54
if
((i->GetPacket ()->GetUid () == entry.
GetPacket
()->
GetUid
())
55
&& (i->GetIpv4Header ().GetDestination ()
56
== entry.
GetIpv4Header
().
GetDestination
()))
57
{
58
return
false
;
59
}
60
}
61
entry.
SetExpireTime
(
m_queueTimeout
);
62
if
(
m_queue
.size () ==
m_maxLen
)
63
{
64
Drop
(
m_queue
.front (),
"Drop the most aged packet"
);
// Drop the most aged packet
65
m_queue
.erase (
m_queue
.begin ());
66
}
67
m_queue
.push_back (entry);
68
return
true
;
69
}
70
71
void
72
RequestQueue::DropPacketWithDst
(
Ipv4Address
dst)
73
{
74
NS_LOG_FUNCTION
(
this
<< dst);
75
Purge
();
76
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
77
!=
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 (),
85
[&](
const
QueueEntry
& en) { return en.GetIpv4Header ().GetDestination () == dst; });
86
m_queue
.erase (new_end,
m_queue
.end ());
87
}
88
89
bool
90
RequestQueue::Dequeue
(
Ipv4Address
dst,
QueueEntry
& entry)
91
{
92
Purge
();
93
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i !=
m_queue
.end (); ++i)
94
{
95
if
(i->GetIpv4Header ().GetDestination () == dst)
96
{
97
entry = *i;
98
m_queue
.erase (i);
99
return
true
;
100
}
101
}
102
return
false
;
103
}
104
105
bool
106
RequestQueue::Find
(
Ipv4Address
dst)
107
{
108
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
109
!=
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
{
124
bool
131
operator()
(
QueueEntry
const
& e)
const
132
{
133
return
(e.
GetExpireTime
() <
Seconds
(0));
134
}
135
};
136
137
void
138
RequestQueue::Purge
()
139
{
140
IsExpired
pred;
141
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
142
!=
m_queue
.end (); ++i)
143
{
144
if
(pred (*i))
145
{
146
Drop
(*i,
"Drop outdated packet "
);
147
}
148
}
149
m_queue
.erase (std::remove_if (
m_queue
.begin (),
m_queue
.end (), pred),
150
m_queue
.end ());
151
}
152
153
void
154
RequestQueue::Drop
(
QueueEntry
en, std::string reason)
155
{
156
NS_LOG_LOGIC
(reason << en.
GetPacket
()->
GetUid
() <<
" "
<< en.
GetIpv4Header
().
GetDestination
());
157
en.
GetErrorCallback
() (en.
GetPacket
(), en.
GetIpv4Header
(),
158
Socket::ERROR_NOROUTETOHOST
);
159
return
;
160
}
161
162
}
// namespace aodv
163
}
// namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::aodv::QueueEntry::GetExpireTime
Time GetExpireTime() const
Get expire time.
Definition:
aodv-rqueue.h:157
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::aodv::RequestQueue::DropPacketWithDst
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
Definition:
aodv-rqueue.cc:72
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:41
ns3::aodv::RequestQueue::Dequeue
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition:
aodv-rqueue.cc:90
ns3::aodv::RequestQueue::m_maxLen
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
Definition:
aodv-rqueue.h:271
aodv-rqueue.h
ns3::aodv::RequestQueue::Find
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
Definition:
aodv-rqueue.cc:106
ns3::aodv::IsExpired
IsExpired structure.
Definition:
aodv-rqueue.cc:123
ns3::aodv::QueueEntry::SetExpireTime
void SetExpireTime(Time exp)
Set expire time.
Definition:
aodv-rqueue.h:149
ns3::aodv::RequestQueue::GetSize
uint32_t GetSize()
Definition:
aodv-rqueue.cc:41
ns3::aodv::RequestQueue::m_queue
std::vector< QueueEntry > m_queue
The queue.
Definition:
aodv-rqueue.h:261
ns3::aodv::QueueEntry::GetIpv4Header
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Definition:
aodv-rqueue.h:133
ns3::aodv::QueueEntry::GetPacket
Ptr< const Packet > GetPacket() const
Get packet from entry.
Definition:
aodv-rqueue.h:117
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition:
log.h:289
ns3::aodv::IsExpired::operator()
bool operator()(QueueEntry const &e) const
Check if the entry is expired.
Definition:
aodv-rqueue.cc:131
ns3::aodv::RequestQueue::Enqueue
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
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1289
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:244
ns3::aodv::QueueEntry::GetErrorCallback
ErrorCallback GetErrorCallback() const
Get error callback.
Definition:
aodv-rqueue.h:101
ns3::aodv::RequestQueue::Purge
void Purge()
Remove all expired entries.
Definition:
aodv-rqueue.cc:138
ns3::aodv::QueueEntry
AODV Queue Entry.
Definition:
aodv-rqueue.h:44
ns3::Ipv4Header::GetDestination
Ipv4Address GetDestination(void) const
Definition:
ipv4-header.cc:304
ns3::aodv::RequestQueue::m_queueTimeout
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
Definition:
aodv-rqueue.h:273
ns3::aodv::RequestQueue::Drop
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
Definition:
aodv-rqueue.cc:154
ns3::Socket::ERROR_NOROUTETOHOST
@ ERROR_NOROUTETOHOST
Definition:
socket.h:93
ns3::Packet::GetUid
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition:
packet.cc:390
src
aodv
model
aodv-rqueue.cc
Generated on Fri Oct 1 2021 17:02:54 for ns-3 by
1.8.20