A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-rqueue.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Based on
7 * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
8 * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
9 *
10 * AODV-UU implementation by Erik Nordström of Uppsala University
11 * https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
12 *
13 * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
14 * Pavel Boyko <boyko@iitp.ru>
15 */
16#include "aodv-rqueue.h"
17
18#include "ns3/ipv4-route.h"
19#include "ns3/log.h"
20#include "ns3/socket.h"
21
22#include <algorithm>
23#include <functional>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("AodvRequestQueue");
29
30namespace aodv
31{
34{
35 Purge();
36 return m_queue.size();
37}
38
39bool
41{
42 Purge();
43 for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
44 {
45 if ((i->GetPacket()->GetUid() == entry.GetPacket()->GetUid()) &&
46 (i->GetIpv4Header().GetDestination() == entry.GetIpv4Header().GetDestination()))
47 {
48 return false;
49 }
50 }
52 if (m_queue.size() == m_maxLen)
53 {
54 Drop(m_queue.front(), "Drop the most aged packet"); // Drop the most aged packet
55 m_queue.erase(m_queue.begin());
56 }
57 m_queue.push_back(entry);
58 return true;
59}
60
61void
63{
64 NS_LOG_FUNCTION(this << dst);
65 Purge();
66 for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
67 {
68 if (i->GetIpv4Header().GetDestination() == dst)
69 {
70 Drop(*i, "DropPacketWithDst ");
71 }
72 }
73 auto new_end = std::remove_if(m_queue.begin(), m_queue.end(), [&](const QueueEntry& en) {
74 return en.GetIpv4Header().GetDestination() == dst;
75 });
76 m_queue.erase(new_end, m_queue.end());
77}
78
79bool
81{
82 Purge();
83 for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
84 {
85 if (i->GetIpv4Header().GetDestination() == dst)
86 {
87 entry = *i;
88 m_queue.erase(i);
89 return true;
90 }
91 }
92 return false;
93}
94
95bool
97{
98 for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
99 {
100 if (i->GetIpv4Header().GetDestination() == dst)
101 {
102 return true;
103 }
104 }
105 return false;
106}
107
108/**
109 * @brief IsExpired structure
110 */
112{
113 /**
114 * Check if the entry is expired
115 *
116 * @param e QueueEntry entry
117 * @return true if expired, false otherwise
118 */
119 bool operator()(const QueueEntry& e) const
120 {
121 return (e.GetExpireTime().IsStrictlyNegative());
122 }
123};
124
125void
127{
128 IsExpired pred;
129 for (auto i = m_queue.begin(); i != m_queue.end(); ++i)
130 {
131 if (pred(*i))
132 {
133 Drop(*i, "Drop outdated packet ");
134 }
135 }
136 m_queue.erase(std::remove_if(m_queue.begin(), m_queue.end(), pred), m_queue.end());
137}
138
139void
140RequestQueue::Drop(QueueEntry en, std::string reason)
141{
142 NS_LOG_LOGIC(reason << en.GetPacket()->GetUid() << " " << en.GetIpv4Header().GetDestination());
144}
145
146} // namespace aodv
147} // namespace ns3
Ipv4 addresses are stored in host order in this class.
Ipv4Address GetDestination() const
uint64_t GetUid() const
Returns the packet's Uid.
Definition packet.cc:401
@ ERROR_NOROUTETOHOST
Definition socket.h:84
bool IsStrictlyNegative() const
Exactly equivalent to t < 0.
Definition nstime.h:331
AODV Queue Entry.
Definition aodv-rqueue.h:34
Time GetExpireTime() const
Get expire time.
ErrorCallback GetErrorCallback() const
Get error callback.
Definition aodv-rqueue.h:98
void SetExpireTime(Time exp)
Set expire time.
Ipv4Header GetIpv4Header() const
Get IPv4 header.
Ptr< const Packet > GetPacket() const
Get packet from entry.
bool Dequeue(Ipv4Address dst, QueueEntry &entry)
Return first found (the earliest) entry for given destination.
uint32_t m_maxLen
The maximum number of packets that we allow a routing protocol to buffer.
bool Find(Ipv4Address dst)
Finds whether a packet with destination dst exists in the queue.
void Purge()
Remove all expired entries.
std::vector< QueueEntry > m_queue
The queue.
Time m_queueTimeout
The maximum period of time that a routing protocol is allowed to buffer a packet for,...
void DropPacketWithDst(Ipv4Address dst)
Remove all packets with destination IP address dst.
bool Enqueue(QueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue.
void Drop(QueueEntry en, std::string reason)
Notify that packet is dropped from queue by timeout.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IsExpired structure.
bool operator()(const QueueEntry &e) const
Check if the entry is expired.