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
dsr-passive-buff.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Yufei Cheng
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: Yufei Cheng <yfcheng@ittc.ku.edu>
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
32
#include "
dsr-passive-buff.h
"
33
#include <algorithm>
34
#include <functional>
35
#include "ns3/ipv4-route.h"
36
#include "ns3/socket.h"
37
#include "ns3/log.h"
38
39
NS_LOG_COMPONENT_DEFINE
(
"PassiveBuffer"
);
40
41
namespace
ns3 {
42
namespace
dsr {
43
44
NS_OBJECT_ENSURE_REGISTERED
(PassiveBuffer);
45
46
TypeId
PassiveBuffer::GetTypeId
()
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::dsr::PassiveBuffer"
)
49
.
SetParent
<
Object
> ()
50
.AddConstructor<PassiveBuffer> ()
51
;
52
return
tid;
53
}
54
55
PassiveBuffer::PassiveBuffer
()
56
{
57
}
58
59
PassiveBuffer::~PassiveBuffer
()
60
{
61
}
62
63
uint32_t
64
PassiveBuffer::GetSize
()
65
{
66
Purge
();
67
return
m_passiveBuffer
.size ();
68
}
69
70
bool
71
PassiveBuffer::Enqueue
(
PassiveBuffEntry
& entry)
72
{
73
Purge
();
74
for
(std::vector<PassiveBuffEntry>::const_iterator i =
m_passiveBuffer
.begin (); i
75
!=
m_passiveBuffer
.end (); ++i)
76
{
77
// NS_LOG_INFO ("packet id " << i->GetPacket ()->GetUid () << " " << entry.GetPacket ()->GetUid () << " source " << i->GetSource () << " " << entry.GetSource ()
78
// << " dst " << i->GetDestination () << " " << entry.GetDestination () << " identification " << i->GetIdentification () << " "
79
// << entry.GetIdentification () << " fragment " << i->GetFragmentOffset () << " " << entry.GetFragmentOffset ()
80
// << " segLeft " << i->GetSegsLeft () << " " << entry.GetSegsLeft ());
81
82
if
((i->GetPacket ()->GetUid () == entry.
GetPacket
()->
GetUid
()) && (i->GetSource () == entry.
GetSource
()) && (i->GetNextHop () == entry.
GetNextHop
())
83
&& (i->GetDestination () == entry.
GetDestination
()) && (i->GetIdentification () == entry.
GetIdentification
()) && (i->GetFragmentOffset () == entry.
GetFragmentOffset
())
84
&& (i->GetSegsLeft () == entry.
GetSegsLeft
() + 1))
85
{
86
return
false
;
87
}
88
}
89
90
entry.
SetExpireTime
(
m_passiveBufferTimeout
);
// Initialize the send buffer timeout
91
/*
92
* Drop the most aged packet when buffer reaches to max
93
*/
94
if
(
m_passiveBuffer
.size () >=
m_maxLen
)
95
{
96
Drop
(
m_passiveBuffer
.front (),
"Drop the most aged packet"
);
// Drop the most aged packet
97
m_passiveBuffer
.erase (
m_passiveBuffer
.begin ());
98
}
99
// enqueue the entry
100
m_passiveBuffer
.push_back (entry);
101
return
true
;
102
}
103
104
bool
105
PassiveBuffer::AllEqual
(
PassiveBuffEntry
& entry)
106
{
107
for
(std::vector<PassiveBuffEntry>::iterator i =
m_passiveBuffer
.begin (); i
108
!=
m_passiveBuffer
.end (); ++i)
109
{
110
// NS_LOG_INFO ("packet id " << i->GetPacket ()->GetUid () << " " << entry.GetPacket ()->GetUid () << " source " << i->GetSource () << " " << entry.GetSource ()
111
// << " dst " << i->GetDestination () << " " << entry.GetDestination () << " identification " << i->GetIdentification () << " "
112
// << entry.GetIdentification () << " fragment " << i->GetFragmentOffset () << " " << entry.GetFragmentOffset ()
113
// << " segLeft " << (uint32_t) i->GetSegsLeft () << " " << (uint32_t) entry.GetSegsLeft ());
114
115
if
((i->GetPacket ()->GetUid () == entry.
GetPacket
()->
GetUid
()) && (i->GetSource () == entry.
GetSource
()) && (i->GetNextHop () == entry.
GetNextHop
())
116
&& (i->GetDestination () == entry.
GetDestination
()) && (i->GetIdentification () == entry.
GetIdentification
()) && (i->GetFragmentOffset () == entry.
GetFragmentOffset
())
117
&& (i->GetSegsLeft () == entry.
GetSegsLeft
() + 1))
118
{
119
m_passiveBuffer
.erase (i);
// Erase the same maintain buffer entry for the received packet
120
return
true
;
121
}
122
}
123
return
false
;
124
}
125
126
bool
127
PassiveBuffer::Dequeue
(
Ipv4Address
dst,
PassiveBuffEntry
& entry)
128
{
129
Purge
();
130
/*
131
* Dequeue the entry with destination address dst
132
*/
133
for
(std::vector<PassiveBuffEntry>::iterator i =
m_passiveBuffer
.begin (); i !=
m_passiveBuffer
.end (); ++i)
134
{
135
if
(i->GetDestination () == dst)
136
{
137
entry = *i;
138
m_passiveBuffer
.erase (i);
139
NS_LOG_DEBUG
(
"Packet size while dequeuing "
<< entry.
GetPacket
()->
GetSize
());
140
return
true
;
141
}
142
}
143
return
false
;
144
}
145
146
bool
147
PassiveBuffer::Find
(
Ipv4Address
dst)
148
{
149
/*
150
* Make sure if the send buffer contains entry with certain dst
151
*/
152
for
(std::vector<PassiveBuffEntry>::const_iterator i =
m_passiveBuffer
.begin (); i
153
!=
m_passiveBuffer
.end (); ++i)
154
{
155
if
(i->GetDestination () == dst)
156
{
157
NS_LOG_DEBUG
(
"Found the packet"
);
158
return
true
;
159
}
160
}
161
return
false
;
162
}
163
164
struct
IsExpired
165
{
166
bool
167
operator()
(
PassiveBuffEntry
const
& e)
const
168
{
169
// NS_LOG_DEBUG("Expire time for packet in req queue: "<<e.GetExpireTime ());
170
return
(e.
GetExpireTime
() <
Seconds
(0));
171
}
172
};
173
174
void
175
PassiveBuffer::Purge
()
176
{
177
/*
178
* Purge the buffer to eliminate expired entries
179
*/
180
NS_LOG_DEBUG
(
"The passive buffer size "
<<
m_passiveBuffer
.size ());
181
IsExpired
pred;
182
for
(std::vector<PassiveBuffEntry>::iterator i =
m_passiveBuffer
.begin (); i
183
!=
m_passiveBuffer
.end (); ++i)
184
{
185
if
(pred (*i))
186
{
187
NS_LOG_DEBUG
(
"Dropping Queue Packets"
);
188
Drop
(*i,
"Drop out-dated packet "
);
189
}
190
}
191
m_passiveBuffer
.erase (std::remove_if (
m_passiveBuffer
.begin (),
m_passiveBuffer
.end (), pred),
192
m_passiveBuffer
.end ());
193
}
194
195
void
196
PassiveBuffer::Drop
(
PassiveBuffEntry
en, std::string reason)
197
{
198
NS_LOG_LOGIC
(reason << en.
GetPacket
()->
GetUid
() <<
" "
<< en.
GetDestination
());
199
// en.GetErrorCallback () (en.GetPacket (), en.GetDestination (),
200
// Socket::ERROR_NOROUTETOHOST);
201
return
;
202
}
203
204
void
205
PassiveBuffer::DropLink
(
PassiveBuffEntry
en, std::string reason)
206
{
207
NS_LOG_LOGIC
(reason << en.
GetPacket
()->
GetUid
() <<
" "
<< en.
GetSource
() <<
" "
<< en.
GetNextHop
());
208
// en.GetErrorCallback () (en.GetPacket (), en.GetDestination (),
209
// Socket::ERROR_NOROUTETOHOST);
210
return
;
211
}
212
}
// namespace dsr
213
}
// namespace ns3
src
dsr
model
dsr-passive-buff.cc
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2