A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"AodvRequestQueue"
);
36
37
namespace
ns3
38
{
39
namespace
aodv
40
{
41
uint32_t
42
RequestQueue::GetSize
()
43
{
44
Purge
();
45
return
m_queue
.size ();
46
}
47
48
bool
49
RequestQueue::Enqueue
(
QueueEntry
& entry)
50
{
51
Purge
();
52
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
53
!=
m_queue
.end (); ++i)
54
{
55
if
((i->GetPacket ()->GetUid () == entry.
GetPacket
()->
GetUid
())
56
&& (i->GetIpv4Header ().GetDestination ()
57
== entry.
GetIpv4Header
().
GetDestination
()))
58
return
false
;
59
}
60
entry.
SetExpireTime
(
m_queueTimeout
);
61
if
(
m_queue
.size () ==
m_maxLen
)
62
{
63
Drop
(
m_queue
.front (),
"Drop the most aged packet"
);
// Drop the most aged packet
64
m_queue
.erase (
m_queue
.begin ());
65
}
66
m_queue
.push_back (entry);
67
return
true
;
68
}
69
70
void
71
RequestQueue::DropPacketWithDst
(
Ipv4Address
dst)
72
{
73
NS_LOG_FUNCTION
(
this
<< dst);
74
Purge
();
75
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
76
!=
m_queue
.end (); ++i)
77
{
78
if
(
IsEqual
(*i, dst))
79
{
80
Drop
(*i,
"DropPacketWithDst "
);
81
}
82
}
83
m_queue
.erase (std::remove_if (
m_queue
.begin (),
m_queue
.end (),
84
std::bind2nd (std::ptr_fun (
RequestQueue::IsEqual
), dst)),
m_queue
.end ());
85
}
86
87
bool
88
RequestQueue::Dequeue
(
Ipv4Address
dst,
QueueEntry
& entry)
89
{
90
Purge
();
91
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i !=
m_queue
.end (); ++i)
92
{
93
if
(i->GetIpv4Header ().GetDestination () == dst)
94
{
95
entry = *i;
96
m_queue
.erase (i);
97
return
true
;
98
}
99
}
100
return
false
;
101
}
102
103
bool
104
RequestQueue::Find
(
Ipv4Address
dst)
105
{
106
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
107
!=
m_queue
.end (); ++i)
108
{
109
if
(i->GetIpv4Header ().GetDestination () == dst)
110
return
true
;
111
}
112
return
false
;
113
}
114
115
struct
IsExpired
116
{
117
bool
118
operator()
(
QueueEntry
const
& e)
const
119
{
120
return
(e.
GetExpireTime
() <
Seconds
(0));
121
}
122
};
123
124
void
125
RequestQueue::Purge
()
126
{
127
IsExpired
pred;
128
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
129
!=
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),
137
m_queue
.end ());
138
}
139
140
void
141
RequestQueue::Drop
(
QueueEntry
en, std::string reason)
142
{
143
NS_LOG_LOGIC
(reason << en.
GetPacket
()->
GetUid
() <<
" "
<< en.
GetIpv4Header
().
GetDestination
());
144
en.
GetErrorCallback
() (en.
GetPacket
(), en.
GetIpv4Header
(),
145
Socket::ERROR_NOROUTETOHOST
);
146
return
;
147
}
148
149
}
150
}
src
aodv
model
aodv-rqueue.cc
Generated on Tue Nov 13 2012 10:32:08 for ns-3 by
1.8.1.2