A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
network
utils
queue-size.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
//
3
// Copyright (c) 2018 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19
//
20
21
#ifndef QUEUE_SIZE_H
22
#define QUEUE_SIZE_H
23
24
#include <string>
25
#include <iostream>
26
#include "ns3/attribute.h"
27
#include "ns3/attribute-helper.h"
28
#include "ns3/abort.h"
29
30
namespace
ns3
{
31
42
enum
QueueSizeUnit
43
{
44
PACKETS
,
45
BYTES
,
46
};
47
94
class
QueueSize
95
{
96
public
:
97
QueueSize
();
105
QueueSize
(
QueueSizeUnit
unit, uint32_t value);
123
QueueSize
(std::string size);
124
130
bool
operator <
(
const
QueueSize
& rhs)
const
;
131
137
bool
operator <=
(
const
QueueSize
& rhs)
const
;
138
144
bool
operator >
(
const
QueueSize
& rhs)
const
;
145
151
bool
operator >=
(
const
QueueSize
& rhs)
const
;
152
158
bool
operator ==
(
const
QueueSize
& rhs)
const
;
159
165
bool
operator !=
(
const
QueueSize
& rhs)
const
;
166
171
QueueSizeUnit
GetUnit
()
const
;
172
177
uint32_t
GetValue
()
const
;
178
179
private
:
180
194
static
bool
DoParse
(
const
std::string s,
QueueSizeUnit
*unit, uint32_t *value);
195
196
// Uses DoParse
197
friend
std::istream &
operator >>
(std::istream &is,
QueueSize
&size);
198
199
QueueSizeUnit
m_unit
;
200
uint32_t
m_value
;
201
};
202
210
std::ostream &
operator <<
(std::ostream &os,
const
QueueSize
&size);
211
219
std::istream &
operator >>
(std::istream &is,
QueueSize
&size);
220
221
ATTRIBUTE_HELPER_HEADER
(
QueueSize
);
222
223
231
template
<
typename
Item>
232
QueueSize
operator+
(
const
QueueSize
& lhs,
const
Ptr<Item>
& rhs);
240
template
<
typename
Item>
241
QueueSize
operator+
(
const
Ptr<Item>
& lhs,
const
QueueSize
& rhs);
242
243
249
template
<
typename
Item>
250
QueueSize
operator+
(
const
QueueSize
& lhs,
const
Ptr<Item>
& rhs)
251
{
252
if
(lhs.
GetUnit
() ==
QueueSizeUnit::PACKETS
)
253
{
254
return
QueueSize
(lhs.
GetUnit
(), lhs.
GetValue
() + 1);
255
}
256
if
(lhs.
GetUnit
() ==
QueueSizeUnit::BYTES
)
257
{
258
return
QueueSize
(lhs.
GetUnit
(), lhs.
GetValue
() + rhs->GetSize ());
259
}
260
NS_FATAL_ERROR
(
"Unknown queue size mode"
);
261
}
262
263
template
<
typename
Item>
264
QueueSize
operator+
(
const
Ptr<Item>
& lhs,
const
QueueSize
& rhs)
265
{
266
if
(rhs.
GetUnit
() ==
QueueSizeUnit::PACKETS
)
267
{
268
return
QueueSize
(rhs.
GetUnit
(), rhs.
GetValue
() + 1);
269
}
270
if
(rhs.
GetUnit
() ==
QueueSizeUnit::BYTES
)
271
{
272
return
QueueSize
(rhs.
GetUnit
(), rhs.
GetValue
() + lhs->GetSize ());
273
}
274
NS_FATAL_ERROR
(
"Unknown queue size mode"
);
275
}
276
277
278
}
// namespace ns3
279
280
#endif
/* QUEUE_SIZE_H */
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition:
angles.cc:48
ns3::QueueSize::QueueSize
QueueSize()
Definition:
queue-size.cc:113
ns3::Ptr< Item >
ns3::QueueSize
Class for representing queue sizes.
Definition:
queue-size.h:94
ns3::operator+
int64x64_t operator+(const int64x64_t &lhs)
Unary plus operator.
Definition:
int64x64-128.h:410
ns3::QueueSize::m_value
uint32_t m_value
queue size [bytes or packets]
Definition:
queue-size.h:200
ns3::QueueSize::GetValue
uint32_t GetValue() const
Get the underlying value.
Definition:
queue-size.cc:175
ns3::QueueSizeUnit
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition:
queue-size.h:42
ns3::QueueSize::operator>>
friend std::istream & operator>>(std::istream &is, QueueSize &size)
Stream extraction operator.
Definition:
queue-size.cc:196
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:162
ns3::QueueSize::DoParse
static bool DoParse(const std::string s, QueueSizeUnit *unit, uint32_t *value)
Parse a string representing a QueueSize.
Definition:
queue-size.cc:33
ns3::PACKETS
Use number of packets for queue size.
Definition:
queue-size.h:44
ns3::QueueSize::operator<=
bool operator<=(const QueueSize &rhs) const
Definition:
queue-size.cc:134
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition:
angles.cc:42
ns3::QueueSize::m_unit
QueueSizeUnit m_unit
unit
Definition:
queue-size.h:199
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::QueueSize::operator==
bool operator==(const QueueSize &rhs) const
Definition:
queue-size.cc:155
ns3::QueueSize::GetUnit
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition:
queue-size.cc:169
ns3::QueueSize::operator>
bool operator>(const QueueSize &rhs) const
Definition:
queue-size.cc:141
ns3::QueueSize::operator!=
bool operator!=(const QueueSize &rhs) const
Definition:
queue-size.cc:162
ns3::QueueSize::operator<
bool operator<(const QueueSize &rhs) const
Definition:
queue-size.cc:127
ns3::QueueSize::operator>=
bool operator>=(const QueueSize &rhs) const
Definition:
queue-size.cc:148
ns3::BYTES
Use number of bytes for queue size.
Definition:
queue-size.h:45
ATTRIBUTE_HELPER_HEADER
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type.
Definition:
attribute-helper.h:384
Generated on Wed Nov 7 2018 10:02:08 for ns-3 by
1.8.14