A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
queue-size.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 Universita' degli Studi di Napoli Federico II
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Stefano Avallone <stavallo@unina.it>
7
*/
8
9
#include "
queue-size.h
"
10
11
#include "ns3/log.h"
12
13
namespace
ns3
14
{
15
16
NS_LOG_COMPONENT_DEFINE
(
"QueueSize"
);
17
18
ATTRIBUTE_HELPER_CPP
(
QueueSize
);
19
20
/* static */
21
bool
22
QueueSize::DoParse
(
const
std::string s,
QueueSizeUnit
* unit,
uint32_t
* value)
23
{
24
NS_LOG_FUNCTION
(s << unit << value);
25
std::string::size_type n = s.find_first_not_of(
"0123456789."
);
26
if
(n != std::string::npos)
27
{
// Found non-numeric
28
std::istringstream iss;
29
iss.str(s.substr(0, n));
30
double
r;
31
iss >> r;
32
std::string trailer = s.substr(n, std::string::npos);
33
if
(trailer ==
"B"
)
34
{
35
// bytes
36
*unit =
QueueSizeUnit::BYTES
;
37
*value =
static_cast<
uint32_t
>
(r);
38
}
39
else
if
(trailer ==
"kB"
|| trailer ==
"KB"
)
40
{
41
// kilobytes
42
*unit =
QueueSizeUnit::BYTES
;
43
*value =
static_cast<
uint32_t
>
(r * 1000);
44
}
45
else
if
(trailer ==
"KiB"
)
46
{
47
// kibibytes
48
*unit =
QueueSizeUnit::BYTES
;
49
*value =
static_cast<
uint32_t
>
(r * 1024);
50
}
51
else
if
(trailer ==
"MB"
)
52
{
53
// MegaBytes
54
*unit =
QueueSizeUnit::BYTES
;
55
*value =
static_cast<
uint32_t
>
(r * 1000000);
56
}
57
else
if
(trailer ==
"MiB"
)
58
{
59
// MebiBytes
60
*unit =
QueueSizeUnit::BYTES
;
61
*value =
static_cast<
uint32_t
>
(r * 1048576);
62
}
63
else
if
(trailer ==
"p"
)
64
{
65
// packets
66
*unit =
QueueSizeUnit::PACKETS
;
67
*value =
static_cast<
uint32_t
>
(r);
68
}
69
else
if
(trailer ==
"kp"
|| trailer ==
"Kp"
)
70
{
71
// kilopackets
72
*unit =
QueueSizeUnit::PACKETS
;
73
*value =
static_cast<
uint32_t
>
(r * 1000);
74
}
75
else
if
(trailer ==
"Kip"
)
76
{
77
// kibipackets
78
*unit =
QueueSizeUnit::PACKETS
;
79
*value =
static_cast<
uint32_t
>
(r * 1024);
80
}
81
else
if
(trailer ==
"Mp"
)
82
{
83
// MegaPackets
84
*unit =
QueueSizeUnit::PACKETS
;
85
*value =
static_cast<
uint32_t
>
(r * 1000000);
86
}
87
else
if
(trailer ==
"Mip"
)
88
{
89
// MebiPackets
90
*unit =
QueueSizeUnit::PACKETS
;
91
*value =
static_cast<
uint32_t
>
(r * 1048576);
92
}
93
else
94
{
95
return
false
;
// unsupported unit string
96
}
97
return
true
;
98
}
99
return
false
;
// a unit string is required
100
}
101
102
QueueSize::QueueSize
()
103
: m_unit(
QueueSizeUnit
::
PACKETS
),
104
m_value(0)
105
{
106
NS_LOG_FUNCTION
(
this
);
107
}
108
109
QueueSize::QueueSize
(
QueueSizeUnit
unit,
uint32_t
value)
110
: m_unit(unit),
111
m_value(value)
112
{
113
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint16_t
>
(unit) << value);
114
}
115
116
bool
117
QueueSize::operator<
(
const
QueueSize
& rhs)
const
118
{
119
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
120
121
return
m_value
< rhs.
m_value
;
122
}
123
124
bool
125
QueueSize::operator<=
(
const
QueueSize
& rhs)
const
126
{
127
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
128
129
return
m_value
<= rhs.
m_value
;
130
}
131
132
bool
133
QueueSize::operator>
(
const
QueueSize
& rhs)
const
134
{
135
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
136
137
return
m_value
> rhs.
m_value
;
138
}
139
140
bool
141
QueueSize::operator>=
(
const
QueueSize
& rhs)
const
142
{
143
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
144
145
return
m_value
>= rhs.
m_value
;
146
}
147
148
bool
149
QueueSize::operator==
(
const
QueueSize
& rhs)
const
150
{
151
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
152
153
return
m_value
== rhs.
m_value
;
154
}
155
156
bool
157
QueueSize::operator!=
(
const
QueueSize
& rhs)
const
158
{
159
NS_ABORT_MSG_IF
(
m_unit
!= rhs.
GetUnit
(),
"Cannot compare heterogeneous sizes"
);
160
161
return
m_value
!= rhs.
m_value
;
162
}
163
164
QueueSizeUnit
165
QueueSize::GetUnit
()
const
166
{
167
NS_LOG_FUNCTION
(
this
);
168
return
m_unit
;
169
}
170
171
uint32_t
172
QueueSize::GetValue
()
const
173
{
174
NS_LOG_FUNCTION
(
this
);
175
return
m_value
;
176
}
177
178
QueueSize::QueueSize
(std::string size)
179
{
180
NS_LOG_FUNCTION
(
this
<< size);
181
bool
ok =
DoParse
(size, &
m_unit
, &
m_value
);
182
NS_ABORT_MSG_IF
(!ok,
"Could not parse queue size: "
<< size);
183
}
184
185
/* For printing of queue size */
186
std::ostream&
187
operator<<
(std::ostream& os,
const
QueueSize
& size)
188
{
189
os << size.
GetValue
() << (size.
GetUnit
() ==
QueueSizeUnit::PACKETS
?
"p"
:
"B"
);
190
return
os;
191
}
192
193
/* Initialize a queue size from an input stream */
194
std::istream&
195
operator>>
(std::istream& is,
QueueSize
& size)
196
{
197
std::string value;
198
is >> value;
199
QueueSizeUnit
m;
200
uint32_t
l;
201
bool
ok =
QueueSize::DoParse
(value, &m, &l);
202
if
(!ok)
203
{
204
is.setstate(std::ios_base::failbit);
205
}
206
size =
QueueSize
(m, l);
207
return
is;
208
}
209
210
}
// namespace ns3
ns3::QueueSize
Class for representing queue sizes.
Definition
queue-size.h:85
ns3::QueueSize::operator>
bool operator>(const QueueSize &rhs) const
Definition
queue-size.cc:133
ns3::QueueSize::QueueSize
QueueSize()
Definition
queue-size.cc:102
ns3::QueueSize::operator<
bool operator<(const QueueSize &rhs) const
Definition
queue-size.cc:117
ns3::QueueSize::operator<=
bool operator<=(const QueueSize &rhs) const
Definition
queue-size.cc:125
ns3::QueueSize::GetUnit
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition
queue-size.cc:165
ns3::QueueSize::operator!=
bool operator!=(const QueueSize &rhs) const
Definition
queue-size.cc:157
ns3::QueueSize::m_value
uint32_t m_value
queue size [bytes or packets]
Definition
queue-size.h:189
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:149
ns3::QueueSize::m_unit
QueueSizeUnit m_unit
unit
Definition
queue-size.h:188
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:22
ns3::QueueSize::GetValue
uint32_t GetValue() const
Get the underlying value.
Definition
queue-size.cc:172
uint32_t
ATTRIBUTE_HELPER_CPP
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
Definition
attribute-helper.h:419
NS_ABORT_MSG_IF
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition
abort.h:97
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3::QueueSizeUnit
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition
queue-size.h:33
ns3::BYTES
@ BYTES
Use number of bytes for queue size.
Definition
queue-size.h:35
ns3::PACKETS
@ PACKETS
Use number of packets for queue size.
Definition
queue-size.h:34
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition
angles.cc:148
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition
angles.cc:172
queue-size.h
src
network
utils
queue-size.cc
Generated on Mon Dec 2 2024 18:20:47 for ns-3 by
1.11.0