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-network-queue.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-network-queue.h
"
33
#include "ns3/test.h"
34
#include <map>
35
#include <algorithm>
36
#include <functional>
37
#include "ns3/log.h"
38
#include "ns3/ipv4-route.h"
39
#include "ns3/socket.h"
40
41
NS_LOG_COMPONENT_DEFINE
(
"DsrNetworkQueue"
);
42
43
namespace
ns3 {
44
namespace
dsr {
45
46
NS_OBJECT_ENSURE_REGISTERED
(DsrNetworkQueue)
47
;
48
49
TypeId
50
DsrNetworkQueue::GetTypeId
(
void
)
51
{
52
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrNetworkQueue"
)
53
.
SetParent
<
Object
> ()
54
.AddConstructor<DsrNetworkQueue> ()
55
;
56
return
tid;
57
}
58
59
DsrNetworkQueue::DsrNetworkQueue
(uint32_t maxLen,
Time
maxDelay)
60
: m_size (0),
61
m_maxSize (maxLen),
62
m_maxDelay (maxDelay)
63
{
64
NS_LOG_FUNCTION
(
this
);
65
}
66
67
DsrNetworkQueue::DsrNetworkQueue
() : m_size (0)
68
{
69
NS_LOG_FUNCTION
(
this
);
70
}
71
72
DsrNetworkQueue::~DsrNetworkQueue
()
73
{
74
NS_LOG_FUNCTION
(
this
);
75
Flush
();
76
}
77
78
void
79
DsrNetworkQueue::SetMaxNetworkSize
(uint32_t maxSize)
80
{
81
m_maxSize
= maxSize;
82
}
83
84
void
85
DsrNetworkQueue::SetMaxNetworkDelay
(
Time
delay)
86
{
87
m_maxDelay
= delay;
88
}
89
90
uint32_t
91
DsrNetworkQueue::GetMaxNetworkSize
(
void
)
const
92
{
93
return
m_maxSize
;
94
}
95
96
Time
97
DsrNetworkQueue::GetMaxNetworkDelay
(
void
)
const
98
{
99
return
m_maxDelay
;
100
}
101
102
bool
103
DsrNetworkQueue::Enqueue
(
DsrNetworkQueueEntry
& entry)
104
{
105
NS_LOG_FUNCTION
(
this
<<
m_size
<<
m_maxSize
);
106
if
(
m_size
>=
m_maxSize
)
107
{
108
return
false
;
109
}
110
Time
now =
Simulator::Now
();
111
entry.
SetInsertedTimeStamp
(now);
112
m_dsrNetworkQueue
.push_back (entry);
113
m_size
++;
114
NS_LOG_LOGIC
(
"The network queue size is "
<<
m_size
);
115
return
true
;
116
}
117
118
bool
119
DsrNetworkQueue::Dequeue
(
DsrNetworkQueueEntry
& entry)
120
{
121
NS_LOG_FUNCTION
(
this
);
122
Cleanup
();
123
std::vector<DsrNetworkQueueEntry>::iterator i =
m_dsrNetworkQueue
.begin ();
124
if
(i ==
m_dsrNetworkQueue
.end ())
125
{
126
// no elements in array
127
NS_LOG_LOGIC
(
"No queued packet in the network queue"
);
128
return
false
;
129
}
130
entry = *i;
131
m_dsrNetworkQueue
.erase (i);
132
m_size
--;
133
return
true
;
134
}
135
136
void
137
DsrNetworkQueue::Cleanup
(
void
)
138
{
139
NS_LOG_FUNCTION
(
this
);
140
if
(
m_dsrNetworkQueue
.empty ())
141
{
142
return
;
143
}
144
145
Time
now =
Simulator::Now
();
146
uint32_t n = 0;
147
for
(std::vector<DsrNetworkQueueEntry>::iterator i =
m_dsrNetworkQueue
.begin (); i !=
m_dsrNetworkQueue
.end (); )
148
{
149
if
(i->GetInsertedTimeStamp () +
m_maxDelay
> now)
150
{
151
i++;
152
}
153
else
154
{
155
NS_LOG_LOGIC
(
"Outdated packet"
);
156
i =
m_dsrNetworkQueue
.erase (i);
157
n++;
158
}
159
}
160
m_size
-= n;
161
}
162
163
uint32_t
164
DsrNetworkQueue::GetSize
()
165
{
166
NS_LOG_FUNCTION
(
this
);
167
return
m_size
;
168
}
169
170
void
171
DsrNetworkQueue::Flush
(
void
)
172
{
173
NS_LOG_FUNCTION
(
this
);
174
m_dsrNetworkQueue
.erase (
m_dsrNetworkQueue
.begin (),
m_dsrNetworkQueue
.end ());
175
m_size
= 0;
176
}
177
178
}
// namespace dsr
179
}
// namespace ns3
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::dsr::DsrNetworkQueue::GetSize
uint32_t GetSize()
Number of entries.
Definition:
dsr-network-queue.cc:164
dsr-network-queue.h
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::dsr::DsrNetworkQueue::Enqueue
bool Enqueue(DsrNetworkQueueEntry &entry)
Push entry in queue, if there is no entry with the same packet and destination address in queue...
Definition:
dsr-network-queue.cc:103
ns3::dsr::DsrNetworkQueue::m_maxSize
uint32_t m_maxSize
Maximum queue size.
Definition:
dsr-network-queue.h:219
ns3::dsr::DsrNetworkQueue::Dequeue
bool Dequeue(DsrNetworkQueueEntry &entry)
Return first found (the earliest) entry for given destination.
Definition:
dsr-network-queue.cc:119
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("DsrNetworkQueue")
ns3::dsr::DsrNetworkQueueEntry
DSR Network Queue Entry.
Definition:
dsr-network-queue.h:53
ns3::dsr::DsrNetworkQueue::GetMaxNetworkSize
uint32_t GetMaxNetworkSize(void) const
Return the maximum queue size.
Definition:
dsr-network-queue.cc:91
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:368
ns3::dsr::DsrNetworkQueue::SetMaxNetworkDelay
void SetMaxNetworkDelay(Time delay)
Set the maximum entry lifetime in the queue.
Definition:
dsr-network-queue.cc:85
ns3::dsr::DsrNetworkQueue::GetMaxNetworkDelay
Time GetMaxNetworkDelay(void) const
Return the maximum entry lifetime for this queue.
Definition:
dsr-network-queue.cc:97
ns3::Simulator::Now
static Time Now(void)
Return the "current simulation time".
Definition:
simulator.cc:180
ns3::dsr::DsrNetworkQueue::Cleanup
void Cleanup(void)
Clean the queue by removing entries that exceeded lifetime.
Definition:
dsr-network-queue.cc:137
ns3::dsr::DsrNetworkQueue::m_size
uint32_t m_size
Current queue size.
Definition:
dsr-network-queue.h:218
ns3::dsr::DsrNetworkQueue::DsrNetworkQueue
DsrNetworkQueue()
Definition:
dsr-network-queue.cc:67
ns3::dsr::DsrNetworkQueueEntry::SetInsertedTimeStamp
void SetInsertedTimeStamp(Time time)
Definition:
dsr-network-queue.h:123
ns3::dsr::DsrNetworkQueue::Flush
void Flush(void)
Clear the queue.
Definition:
dsr-network-queue.cc:171
ns3::dsr::DsrNetworkQueue::m_dsrNetworkQueue
std::vector< DsrNetworkQueueEntry > m_dsrNetworkQueue
Queue (vector) of entries.
Definition:
dsr-network-queue.h:217
ns3::dsr::DsrNetworkQueue::~DsrNetworkQueue
~DsrNetworkQueue()
Definition:
dsr-network-queue.cc:72
ns3::dsr::DsrNetworkQueue::m_maxDelay
Time m_maxDelay
Maximum entry lifetime.
Definition:
dsr-network-queue.h:220
ns3::dsr::DsrNetworkQueue::GetTypeId
static TypeId GetTypeId(void)
Definition:
dsr-network-queue.cc:50
ns3::dsr::DsrNetworkQueue::SetMaxNetworkSize
void SetMaxNetworkSize(uint32_t maxSize)
Set the maximum queue size.
Definition:
dsr-network-queue.cc:79
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
src
dsr
model
dsr-network-queue.cc
Generated on Sat Apr 19 2014 14:06:53 for ns-3 by
1.8.6