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
dsdv-packet-queue.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Hemanth Narra
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
* Author: Hemanth Narra <hemanth@ittc.ku.com>
19
*
20
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22
* Information and Telecommunication Technology Center (ITTC)
23
* and Department of Electrical Engineering and Computer Science
24
* The University of Kansas Lawrence, KS USA.
25
*
26
* Work supported in part by NSF FIND (Future Internet Design) Program
27
* under grant CNS-0626918 (Postmodern Internet Architecture),
28
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
* US Department of Defense (DoD), and ITTC at The University of Kansas.
30
*/
31
#include "
dsdv-packet-queue.h
"
32
#include <algorithm>
33
#include <functional>
34
#include "ns3/ipv4-route.h"
35
#include "ns3/socket.h"
36
#include "ns3/log.h"
37
38
NS_LOG_COMPONENT_DEFINE
(
"DsdvPacketQueue"
);
39
40
namespace
ns3 {
41
namespace
dsdv {
42
uint32_t
43
PacketQueue::GetSize
()
44
{
45
Purge
();
46
return
m_queue
.size ();
47
}
48
49
bool
50
PacketQueue::Enqueue
(
QueueEntry
& entry)
51
{
52
NS_LOG_FUNCTION
(
"Enqueing packet destined for"
<< entry.
GetIpv4Header
().
GetDestination
());
53
Purge
();
54
uint32_t numPacketswithdst;
55
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
56
!=
m_queue
.end (); ++i)
57
{
58
if
((i->GetPacket ()->GetUid () == entry.
GetPacket
()->
GetUid
())
59
&& (i->GetIpv4Header ().GetDestination ()
60
== entry.
GetIpv4Header
().
GetDestination
()))
61
{
62
return
false
;
63
}
64
}
65
numPacketswithdst =
GetCountForPacketsWithDst
(entry.
GetIpv4Header
().
GetDestination
());
66
NS_LOG_DEBUG
(
"Number of packets with this destination: "
<< numPacketswithdst);
68
if
(numPacketswithdst >=
m_maxLenPerDst
||
m_queue
.size () >=
m_maxLen
)
69
{
70
NS_LOG_DEBUG
(
"Max packets reached for this destination. Not queuing any further packets"
);
71
return
false
;
72
}
73
else
74
{
75
// NS_LOG_DEBUG("Packet size while enqueing "<<entry.GetPacket()->GetSize());
76
entry.
SetExpireTime
(
m_queueTimeout
);
77
m_queue
.push_back (entry);
78
return
true
;
79
}
80
}
81
82
void
83
PacketQueue::DropPacketWithDst
(
Ipv4Address
dst)
84
{
85
NS_LOG_FUNCTION
(
"Dropping packet to "
<< dst);
86
Purge
();
87
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
88
!=
m_queue
.end (); ++i)
89
{
90
if
(
IsEqual
(*i, dst))
91
{
92
Drop
(*i,
"DropPacketWithDst "
);
93
}
94
}
95
m_queue
.erase (std::remove_if (
m_queue
.begin (),
m_queue
.end (),
96
std::bind2nd (std::ptr_fun (
PacketQueue::IsEqual
), dst)),
m_queue
.end ());
97
}
98
99
bool
100
PacketQueue::Dequeue
(
Ipv4Address
dst,
QueueEntry
& entry)
101
{
102
NS_LOG_FUNCTION
(
"Dequeueing packet destined for"
<< dst);
103
Purge
();
104
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i !=
m_queue
.end (); ++i)
105
{
106
if
(i->GetIpv4Header ().GetDestination () == dst)
107
{
108
entry = *i;
109
m_queue
.erase (i);
110
return
true
;
111
}
112
}
113
return
false
;
114
}
115
116
bool
117
PacketQueue::Find
(
Ipv4Address
dst)
118
{
119
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
120
!=
m_queue
.end (); ++i)
121
{
122
if
(i->GetIpv4Header ().GetDestination () == dst)
123
{
124
NS_LOG_DEBUG
(
"Find"
);
125
return
true
;
126
}
127
}
128
return
false
;
129
}
130
131
uint32_t
132
PacketQueue::GetCountForPacketsWithDst
(
Ipv4Address
dst)
133
{
134
uint32_t count = 0;
135
for
(std::vector<QueueEntry>::const_iterator i =
m_queue
.begin (); i
136
!=
m_queue
.end (); ++i)
137
{
138
if
(i->GetIpv4Header ().GetDestination () == dst)
139
{
140
count++;
141
}
142
}
143
return
count;
144
}
145
146
struct
IsExpired
147
{
148
bool
149
operator()
(
QueueEntry
const
& e)
const
150
{
151
// NS_LOG_DEBUG("Expire time for packet in req queue: "<<e.GetExpireTime ());
152
return
(e.
GetExpireTime
() <
Seconds
(0));
153
}
154
};
155
156
void
157
PacketQueue::Purge
()
158
{
159
// NS_LOG_DEBUG("Purging Queue");
160
IsExpired
pred;
161
for
(std::vector<QueueEntry>::iterator i =
m_queue
.begin (); i
162
!=
m_queue
.end (); ++i)
163
{
164
if
(pred (*i))
165
{
166
NS_LOG_DEBUG
(
"Dropping outdated Packets"
);
167
Drop
(*i,
"Drop outdated packet "
);
168
}
169
}
170
m_queue
.erase (std::remove_if (
m_queue
.begin (),
m_queue
.end (), pred),
171
m_queue
.end ());
172
}
173
174
void
175
PacketQueue::Drop
(
QueueEntry
en, std::string reason)
176
{
177
NS_LOG_LOGIC
(reason << en.
GetPacket
()->
GetUid
() <<
" "
<< en.
GetIpv4Header
().
GetDestination
());
178
// en.GetErrorCallback () (en.GetPacket (), en.GetIpv4Header (),
179
// Socket::ERROR_NOROUTETOHOST);
180
return
;
181
}
182
183
}
184
}
src
dsdv
model
dsdv-packet-queue.cc
Generated on Fri Dec 21 2012 19:00:34 for ns-3 by
1.8.1.2