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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
drop-tail-queue.cc
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/enum.h"
21
#include "ns3/uinteger.h"
22
#include "drop-tail-queue.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"DropTailQueue"
);
25
26
namespace
ns3 {
27
28
NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
29
30
TypeId DropTailQueue::GetTypeId (
void
)
31
{
32
static
TypeId tid = TypeId (
"ns3::DropTailQueue"
)
33
.SetParent<Queue> ()
34
.AddConstructor<DropTailQueue> ()
35
.AddAttribute (
"Mode"
,
36
"Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric."
,
37
EnumValue (
QUEUE_MODE_PACKETS
),
38
MakeEnumAccessor (&
DropTailQueue::SetMode
),
39
MakeEnumChecker (
QUEUE_MODE_BYTES
,
"QUEUE_MODE_BYTES"
,
40
QUEUE_MODE_PACKETS
,
"QUEUE_MODE_PACKETS"
))
41
.AddAttribute (
"MaxPackets"
,
42
"The maximum number of packets accepted by this DropTailQueue."
,
43
UintegerValue (100),
44
MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
45
MakeUintegerChecker<uint32_t> ())
46
.AddAttribute (
"MaxBytes"
,
47
"The maximum number of bytes accepted by this DropTailQueue."
,
48
UintegerValue (100 * 65535),
49
MakeUintegerAccessor (&DropTailQueue::m_maxBytes),
50
MakeUintegerChecker<uint32_t> ())
51
;
52
53
return
tid;
54
}
55
56
DropTailQueue::DropTailQueue
() :
57
Queue
(),
58
m_packets (),
59
m_bytesInQueue (0)
60
{
61
NS_LOG_FUNCTION
(
this
);
62
}
63
64
DropTailQueue::~DropTailQueue ()
65
{
66
NS_LOG_FUNCTION
(
this
);
67
}
68
69
void
70
DropTailQueue::SetMode
(
DropTailQueue::QueueMode
mode)
71
{
72
NS_LOG_FUNCTION
(
this
<< mode);
73
m_mode = mode;
74
}
75
76
DropTailQueue::QueueMode
77
DropTailQueue::GetMode
(
void
)
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_mode;
81
}
82
83
bool
84
DropTailQueue::DoEnqueue (
Ptr<Packet>
p)
85
{
86
NS_LOG_FUNCTION
(
this
<< p);
87
88
if
(m_mode ==
QUEUE_MODE_PACKETS
&& (m_packets.size () >= m_maxPackets))
89
{
90
NS_LOG_LOGIC
(
"Queue full (at max packets) -- droppping pkt"
);
91
Drop (p);
92
return
false
;
93
}
94
95
if
(m_mode ==
QUEUE_MODE_BYTES
&& (m_bytesInQueue + p->
GetSize
() >= m_maxBytes))
96
{
97
NS_LOG_LOGIC
(
"Queue full (packet would exceed max bytes) -- droppping pkt"
);
98
Drop (p);
99
return
false
;
100
}
101
102
m_bytesInQueue += p->
GetSize
();
103
m_packets.push (p);
104
105
NS_LOG_LOGIC
(
"Number packets "
<< m_packets.size ());
106
NS_LOG_LOGIC
(
"Number bytes "
<< m_bytesInQueue);
107
108
return
true
;
109
}
110
111
Ptr<Packet>
112
DropTailQueue::DoDequeue (
void
)
113
{
114
NS_LOG_FUNCTION
(
this
);
115
116
if
(m_packets.empty ())
117
{
118
NS_LOG_LOGIC
(
"Queue empty"
);
119
return
0;
120
}
121
122
Ptr<Packet> p = m_packets.front ();
123
m_packets.pop ();
124
m_bytesInQueue -= p->GetSize ();
125
126
NS_LOG_LOGIC
(
"Popped "
<< p);
127
128
NS_LOG_LOGIC
(
"Number packets "
<< m_packets.size ());
129
NS_LOG_LOGIC
(
"Number bytes "
<< m_bytesInQueue);
130
131
return
p;
132
}
133
134
Ptr<const Packet>
135
DropTailQueue::DoPeek (
void
)
const
136
{
137
NS_LOG_FUNCTION
(
this
);
138
139
if
(m_packets.empty ())
140
{
141
NS_LOG_LOGIC
(
"Queue empty"
);
142
return
0;
143
}
144
145
Ptr<Packet> p = m_packets.front ();
146
147
NS_LOG_LOGIC
(
"Number packets "
<< m_packets.size ());
148
NS_LOG_LOGIC
(
"Number bytes "
<< m_bytesInQueue);
149
150
return
p;
151
}
152
153
}
// namespace ns3
154
ns3::Ptr< Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::DropTailQueue::SetMode
void SetMode(DropTailQueue::QueueMode mode)
Definition:
drop-tail-queue.cc:70
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::Packet::GetSize
uint32_t GetSize(void) const
Definition:
packet.h:620
ns3::Queue
Abstract base class for packet Queues.
Definition:
queue.h:45
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:334
ns3::Queue::QUEUE_MODE_BYTES
Definition:
queue.h:125
ns3::Queue::QueueMode
QueueMode
Enumeration of the modes supported in the class.
Definition:
queue.h:122
ns3::Queue::QUEUE_MODE_PACKETS
Definition:
queue.h:124
ns3::DropTailQueue::DropTailQueue
DropTailQueue()
DropTailQueue Constructor.
Definition:
drop-tail-queue.cc:56
ns3::DropTailQueue::GetMode
DropTailQueue::QueueMode GetMode(void)
Definition:
drop-tail-queue.cc:77
src
network
utils
drop-tail-queue.cc
Generated on Sun Mar 16 2014 11:25:09 for ns-3 by
1.8.6