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
queue.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 University of Washington
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
19
#include "ns3/log.h"
20
#include "ns3/trace-source-accessor.h"
21
#include "
queue.h
"
22
23
NS_LOG_COMPONENT_DEFINE
(
"Queue"
);
24
25
namespace
ns3 {
26
27
NS_OBJECT_ENSURE_REGISTERED
(Queue);
28
29
TypeId
30
Queue::GetTypeId
(
void
)
31
{
32
static
TypeId
tid =
TypeId
(
"ns3::Queue"
)
33
.
SetParent
<
Object
> ()
34
.AddTraceSource (
"Enqueue"
,
"Enqueue a packet in the queue."
,
35
MakeTraceSourceAccessor
(&
Queue::m_traceEnqueue
))
36
.AddTraceSource (
"Dequeue"
,
"Dequeue a packet from the queue."
,
37
MakeTraceSourceAccessor
(&
Queue::m_traceDequeue
))
38
.AddTraceSource (
"Drop"
,
"Drop a packet stored in the queue."
,
39
MakeTraceSourceAccessor
(&
Queue::m_traceDrop
))
40
;
41
return
tid;
42
}
43
44
Queue::Queue
() :
45
m_nBytes (0),
46
m_nTotalReceivedBytes (0),
47
m_nPackets (0),
48
m_nTotalReceivedPackets (0),
49
m_nTotalDroppedBytes (0),
50
m_nTotalDroppedPackets (0)
51
{
52
NS_LOG_FUNCTION_NOARGS
();
53
}
54
55
Queue::~Queue
()
56
{
57
NS_LOG_FUNCTION_NOARGS
();
58
}
59
60
61
bool
62
Queue::Enqueue
(
Ptr<Packet>
p)
63
{
64
NS_LOG_FUNCTION
(
this
<< p);
65
66
//
67
// If DoEnqueue fails, Queue::Drop is called by the subclass
68
//
69
bool
retval =
DoEnqueue
(p);
70
if
(retval)
71
{
72
NS_LOG_LOGIC
(
"m_traceEnqueue (p)"
);
73
m_traceEnqueue
(p);
74
75
uint32_t size = p->
GetSize
();
76
m_nBytes
+= size;
77
m_nTotalReceivedBytes
+= size;
78
79
m_nPackets
++;
80
m_nTotalReceivedPackets
++;
81
}
82
return
retval;
83
}
84
85
Ptr<Packet>
86
Queue::Dequeue
(
void
)
87
{
88
NS_LOG_FUNCTION
(
this
);
89
90
Ptr<Packet>
packet =
DoDequeue
();
91
92
if
(packet != 0)
93
{
94
NS_ASSERT
(
m_nBytes
>= packet->
GetSize
());
95
NS_ASSERT
(
m_nPackets
> 0);
96
97
m_nBytes
-= packet->
GetSize
();
98
m_nPackets
--;
99
100
NS_LOG_LOGIC
(
"m_traceDequeue (packet)"
);
101
m_traceDequeue
(packet);
102
}
103
return
packet;
104
}
105
106
void
107
Queue::DequeueAll
(
void
)
108
{
109
NS_LOG_FUNCTION
(
this
);
110
while
(!
IsEmpty
())
111
{
112
Dequeue
();
113
}
114
}
115
116
Ptr<const Packet>
117
Queue::Peek
(
void
)
const
118
{
119
NS_LOG_FUNCTION
(
this
);
120
return
DoPeek
();
121
}
122
123
124
uint32_t
125
Queue::GetNPackets
(
void
)
const
126
{
127
NS_LOG_FUNCTION_NOARGS
();
128
NS_LOG_LOGIC
(
"returns "
<<
m_nPackets
);
129
return
m_nPackets
;
130
}
131
132
uint32_t
133
Queue::GetNBytes
(
void
)
const
134
{
135
NS_LOG_FUNCTION_NOARGS
();
136
NS_LOG_LOGIC
(
" returns "
<<
m_nBytes
);
137
return
m_nBytes
;
138
}
139
140
bool
141
Queue::IsEmpty
(
void
)
const
142
{
143
NS_LOG_FUNCTION_NOARGS
();
144
NS_LOG_LOGIC
(
"returns "
<< (
m_nPackets
== 0));
145
return
m_nPackets
== 0;
146
}
147
148
uint32_t
149
Queue::GetTotalReceivedBytes
(
void
)
const
150
{
151
NS_LOG_FUNCTION_NOARGS
();
152
NS_LOG_LOGIC
(
"returns "
<<
m_nTotalReceivedBytes
);
153
return
m_nTotalReceivedBytes
;
154
}
155
156
uint32_t
157
Queue::GetTotalReceivedPackets
(
void
)
const
158
{
159
NS_LOG_FUNCTION_NOARGS
();
160
NS_LOG_LOGIC
(
"returns "
<<
m_nTotalReceivedPackets
);
161
return
m_nTotalReceivedPackets
;
162
}
163
164
uint32_t
165
Queue:: GetTotalDroppedBytes
(
void
)
const
166
{
167
NS_LOG_FUNCTION_NOARGS
();
168
NS_LOG_LOGIC
(
"returns "
<<
m_nTotalDroppedBytes
);
169
return
m_nTotalDroppedBytes
;
170
}
171
172
uint32_t
173
Queue::GetTotalDroppedPackets
(
void
)
const
174
{
175
NS_LOG_FUNCTION_NOARGS
();
176
NS_LOG_LOGIC
(
"returns "
<<
m_nTotalDroppedPackets
);
177
return
m_nTotalDroppedPackets
;
178
}
179
180
void
181
Queue::ResetStatistics
(
void
)
182
{
183
NS_LOG_FUNCTION_NOARGS
();
184
m_nTotalReceivedBytes
= 0;
185
m_nTotalReceivedPackets
= 0;
186
m_nTotalDroppedBytes
= 0;
187
m_nTotalDroppedPackets
= 0;
188
}
189
190
void
191
Queue::Drop
(
Ptr<Packet>
p)
192
{
193
NS_LOG_FUNCTION
(
this
<< p);
194
195
m_nTotalDroppedPackets
++;
196
m_nTotalDroppedBytes
+= p->
GetSize
();
197
198
NS_LOG_LOGIC
(
"m_traceDrop (p)"
);
199
m_traceDrop
(p);
200
}
201
202
}
// namespace ns3
src
network
utils
queue.cc
Generated on Tue Oct 9 2012 16:45:44 for ns-3 by
1.8.1.2