A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tbf-queue-disc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Kungliga Tekniska Högskolan
3 * 2017 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 * TBF, The Token Bucket Filter Queueing discipline
19 *
20 * This implementation is based on linux kernel code by
21 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
22 * Dmitry Torokhov <dtor@mail.ru> - allow attaching inner qdiscs -
23 * original idea by Martin Devera
24 *
25 * Implemented in ns-3 by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
26 * Stefano Avallone <stavallo@unina.it>
27 */
28#ifndef TBF_QUEUE_DISC_H
29#define TBF_QUEUE_DISC_H
30
31#include "queue-disc.h"
32
33#include "ns3/boolean.h"
34#include "ns3/data-rate.h"
35#include "ns3/event-id.h"
36#include "ns3/nstime.h"
37#include "ns3/random-variable-stream.h"
38#include "ns3/trace-source-accessor.h"
39#include "ns3/traced-value.h"
40
41namespace ns3
42{
43
44/**
45 * \ingroup traffic-control
46 *
47 * \brief A TBF packet queue disc
48 */
49class TbfQueueDisc : public QueueDisc
50{
51 public:
52 /**
53 * \brief Get the type ID.
54 * \return the object TypeId
55 */
56 static TypeId GetTypeId();
57
58 /**
59 * \brief TbfQueueDisc Constructor
60 *
61 * Create a TBF queue disc
62 */
64
65 /**
66 * \brief Destructor
67 *
68 * Destructor
69 */
70 ~TbfQueueDisc() override;
71
72 /**
73 * \brief Set the size of the first bucket in bytes.
74 *
75 * \param burst The size of first bucket in bytes.
76 */
77 void SetBurst(uint32_t burst);
78
79 /**
80 * \brief Get the size of the first bucket in bytes.
81 *
82 * \returns The size of the first bucket in bytes.
83 */
84 uint32_t GetBurst() const;
85
86 /**
87 * \brief Set the size of the second bucket in bytes.
88 *
89 * \param mtu The size of second bucket in bytes.
90 */
91 void SetMtu(uint32_t mtu);
92
93 /**
94 * \brief Get the size of the second bucket in bytes.
95 *
96 * \returns The size of the second bucket in bytes.
97 */
98 uint32_t GetMtu() const;
99
100 /**
101 * \brief Set the rate of the tokens entering the first bucket.
102 *
103 * \param rate The rate of first bucket tokens.
104 */
105 void SetRate(DataRate rate);
106
107 /**
108 * \brief Get the rate of the tokens entering the first bucket.
109 *
110 * \returns The rate of first bucket tokens.
111 */
112 DataRate GetRate() const;
113
114 /**
115 * \brief Set the rate of the tokens entering the second bucket.
116 *
117 * \param peakRate The rate of second bucket tokens.
118 */
119 void SetPeakRate(DataRate peakRate);
120
121 /**
122 * \brief Get the rate of the tokens entering the second bucket.
123 *
124 * \returns The rate of second bucket tokens.
125 */
126 DataRate GetPeakRate() const;
127
128 /**
129 * \brief Get the current number of tokens inside the first bucket in bytes.
130 *
131 * \returns The number of first bucket tokens in bytes.
132 */
134
135 /**
136 * \brief Get the current number of tokens inside the second bucket in bytes.
137 *
138 * \returns The number of second bucket tokens in bytes.
139 */
141
142 protected:
143 /**
144 * \brief Dispose of the object
145 */
146 void DoDispose() override;
147
148 private:
149 bool DoEnqueue(Ptr<QueueDiscItem> item) override;
150 Ptr<QueueDiscItem> DoDequeue() override;
151 bool CheckConfig() override;
152 void InitializeParams() override;
153
154 /* parameters for the TBF Queue Disc */
155 uint32_t m_burst; //!< Size of first bucket in bytes
156 uint32_t m_mtu; //!< Size of second bucket in bytes
157 DataRate m_rate; //!< Rate at which tokens enter the first bucket
158 DataRate m_peakRate; //!< Rate at which tokens enter the second bucket
159
160 /* variables stored by TBF Queue Disc */
161 TracedValue<uint32_t> m_btokens; //!< Current number of tokens in first bucket
162 TracedValue<uint32_t> m_ptokens; //!< Current number of tokens in second bucket
163 Time m_timeCheckPoint; //!< Time check-point
164 EventId m_id; //!< EventId of the scheduled queue waking event when enough tokens are available
165};
166
167} // namespace ns3
168
169#endif /* TBF_QUEUE_DISC_H */
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:184
A TBF packet queue disc.
DataRate GetRate() const
Get the rate of the tokens entering the first bucket.
TbfQueueDisc()
TbfQueueDisc Constructor.
void SetBurst(uint32_t burst)
Set the size of the first bucket in bytes.
TracedValue< uint32_t > m_ptokens
Current number of tokens in second bucket.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
Time m_timeCheckPoint
Time check-point.
uint32_t m_mtu
Size of second bucket in bytes.
~TbfQueueDisc() override
Destructor.
void DoDispose() override
Dispose of the object.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
void SetPeakRate(DataRate peakRate)
Set the rate of the tokens entering the second bucket.
uint32_t m_burst
Size of first bucket in bytes.
DataRate m_rate
Rate at which tokens enter the first bucket.
EventId m_id
EventId of the scheduled queue waking event when enough tokens are available.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
DataRate GetPeakRate() const
Get the rate of the tokens entering the second bucket.
void SetRate(DataRate rate)
Set the rate of the tokens entering the first bucket.
void SetMtu(uint32_t mtu)
Set the size of the second bucket in bytes.
uint32_t GetBurst() const
Get the size of the first bucket in bytes.
uint32_t GetFirstBucketTokens() const
Get the current number of tokens inside the first bucket in bytes.
static TypeId GetTypeId()
Get the type ID.
bool CheckConfig() override
Check whether the current configuration is correct.
uint32_t GetSecondBucketTokens() const
Get the current number of tokens inside the second bucket in bytes.
uint32_t GetMtu() const
Get the size of the second bucket in bytes.
TracedValue< uint32_t > m_btokens
Current number of tokens in first bucket.
DataRate m_peakRate
Rate at which tokens enter the second bucket.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.