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