A Discrete-Event Network Simulator
API
queue-size.h
Go to the documentation of this file.
1//
2// Copyright (c) 2018 Universita' degli Studi di Napoli Federico II
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 2 as
6// published by the Free Software Foundation;
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// Author: Stefano Avallone <stavallo@unina.it>
18//
19
20#ifndef QUEUE_SIZE_H
21#define QUEUE_SIZE_H
22
23#include "ns3/abort.h"
24#include "ns3/attribute-helper.h"
25#include "ns3/attribute.h"
26
27#include <iostream>
28#include <string>
29
30namespace ns3
31{
32
44{
47};
48
96{
97 public:
98 QueueSize();
124 QueueSize(std::string size);
125
131 bool operator<(const QueueSize& rhs) const;
132
138 bool operator<=(const QueueSize& rhs) const;
139
145 bool operator>(const QueueSize& rhs) const;
146
152 bool operator>=(const QueueSize& rhs) const;
153
159 bool operator==(const QueueSize& rhs) const;
160
166 bool operator!=(const QueueSize& rhs) const;
167
172 QueueSizeUnit GetUnit() const;
173
178 uint32_t GetValue() const;
179
180 private:
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
201};
202
210std::ostream& operator<<(std::ostream& os, const QueueSize& size);
211
219std::istream& operator>>(std::istream& is, QueueSize& size);
220
222
230template <typename Item>
231QueueSize operator+(const QueueSize& lhs, const Ptr<Item>& rhs);
239template <typename Item>
240QueueSize operator+(const Ptr<Item>& lhs, const QueueSize& rhs);
241
246template <typename Item>
248operator+(const QueueSize& lhs, const Ptr<Item>& rhs)
249{
250 if (lhs.GetUnit() == QueueSizeUnit::PACKETS)
251 {
252 return QueueSize(lhs.GetUnit(), lhs.GetValue() + 1);
253 }
254 if (lhs.GetUnit() == QueueSizeUnit::BYTES)
255 {
256 return QueueSize(lhs.GetUnit(), lhs.GetValue() + rhs->GetSize());
257 }
258 NS_FATAL_ERROR("Unknown queue size mode");
259}
260
261template <typename Item>
262QueueSize
263operator+(const Ptr<Item>& lhs, const QueueSize& rhs)
264{
265 if (rhs.GetUnit() == QueueSizeUnit::PACKETS)
266 {
267 return QueueSize(rhs.GetUnit(), rhs.GetValue() + 1);
268 }
269 if (rhs.GetUnit() == QueueSizeUnit::BYTES)
270 {
271 return QueueSize(rhs.GetUnit(), rhs.GetValue() + lhs->GetSize());
272 }
273 NS_FATAL_ERROR("Unknown queue size mode");
274}
275
276} // namespace ns3
277
278#endif /* QUEUE_SIZE_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Class for representing queue sizes.
Definition: queue-size.h:96
bool operator>(const QueueSize &rhs) const
Definition: queue-size.cc:144
friend std::istream & operator>>(std::istream &is, QueueSize &size)
Stream extraction operator.
Definition: queue-size.cc:206
bool operator<(const QueueSize &rhs) const
Definition: queue-size.cc:128
bool operator<=(const QueueSize &rhs) const
Definition: queue-size.cc:136
QueueSizeUnit GetUnit() const
Get the underlying unit.
Definition: queue-size.cc:176
bool operator!=(const QueueSize &rhs) const
Definition: queue-size.cc:168
uint32_t m_value
queue size [bytes or packets]
Definition: queue-size.h:200
bool operator>=(const QueueSize &rhs) const
Definition: queue-size.cc:152
bool operator==(const QueueSize &rhs) const
Definition: queue-size.cc:160
QueueSizeUnit m_unit
unit
Definition: queue-size.h:199
static bool DoParse(const std::string s, QueueSizeUnit *unit, uint32_t *value)
Parse a string representing a QueueSize.
Definition: queue-size.cc:33
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:183
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition: int64x64.h:88
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:44
@ BYTES
Use number of bytes for queue size.
Definition: queue-size.h:46
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ATTRIBUTE_HELPER_HEADER(ValueClassTest)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:129
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:153
value
Definition: second.py:41