A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
codel-queue-disc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Andrew McGregor
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 * Codel, the COntrolled DELay Queueing discipline
18 * Based on ns2 simulation code presented by Kathie Nichols
19 *
20 * This port based on linux kernel code by
21 * Authors:
22 * Dave Täht <d@taht.net>
23 * Eric Dumazet <edumazet@google.com>
24 *
25 * Ported to ns-3 by: Andrew McGregor <andrewmcgr@gmail.com>
26 */
27
28#ifndef CODEL_H
29#define CODEL_H
30
31#include "queue-disc.h"
32
33#include "ns3/nstime.h"
34#include "ns3/simulator.h"
35#include "ns3/string.h"
36#include "ns3/trace-source-accessor.h"
37#include "ns3/traced-value.h"
38
39class CoDelQueueDiscNewtonStepTest; // Forward declaration for unit test
40class CoDelQueueDiscControlLawTest; // Forward declaration for unit test
41
42namespace ns3
43{
44
45/**
46 * Number of bits discarded from the time representation.
47 * The time is assumed to be in nanoseconds.
48 */
49static const int CODEL_SHIFT = 10;
50
51#define DEFAULT_CODEL_LIMIT 1000
52#define REC_INV_SQRT_BITS (8 * sizeof(uint16_t))
53#define REC_INV_SQRT_SHIFT (32 - REC_INV_SQRT_BITS)
54
55class TraceContainer;
56
57/**
58 * \ingroup traffic-control
59 *
60 * \brief A CoDel packet queue disc
61 */
62
64{
65 public:
66 /**
67 * Get the type ID.
68 * \brief Get the type ID.
69 * \return the object TypeId
70 */
71 static TypeId GetTypeId();
72
73 /**
74 * \brief CoDelQueueDisc Constructor
75 *
76 * Creates a CoDel queue
77 */
79
80 ~CoDelQueueDisc() override;
81
82 /**
83 * \brief Get the target queue delay
84 *
85 * \returns The target queue delay
86 */
88
89 /**
90 * \brief Get the interval
91 *
92 * \returns The interval
93 */
95
96 /**
97 * \brief Get the time for next packet drop while in the dropping state
98 *
99 * \returns The time for next packet drop
100 */
102
103 // Reasons for dropping packets
104 static constexpr const char* TARGET_EXCEEDED_DROP =
105 "Target exceeded drop"; //!< Sojourn time above target
106 static constexpr const char* OVERLIMIT_DROP = "Overlimit drop"; //!< Overlimit dropped packet
107 // Reasons for marking packets
108 static constexpr const char* TARGET_EXCEEDED_MARK =
109 "Target exceeded mark"; //!< Sojourn time above target
110 static constexpr const char* CE_THRESHOLD_EXCEEDED_MARK =
111 "CE threshold exceeded mark"; //!< Sojourn time above CE threshold
112
113 private:
114 friend class ::CoDelQueueDiscNewtonStepTest; // Test code
115 friend class ::CoDelQueueDiscControlLawTest; // Test code
116 /**
117 * \brief Add a packet to the queue
118 *
119 * \param item The item to be added
120 * \returns True if the packet can be added, False if the packet is dropped due to full queue
121 */
122 bool DoEnqueue(Ptr<QueueDiscItem> item) override;
123
124 /**
125 * \brief Remove a packet from queue based on the current state
126 * If we are in dropping state, check if we could leave the dropping state
127 * or if we should perform next drop
128 * If we are not currently in dropping state, check if we need to enter the state
129 * and drop the first packet
130 *
131 * \returns The packet that is examined
132 */
133 Ptr<QueueDiscItem> DoDequeue() override;
134
135 bool CheckConfig() override;
136
137 /**
138 * \brief Calculate the reciprocal square root of m_count by using Newton's method
139 * http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots
140 * m_recInvSqrt (new) = (m_recInvSqrt (old) / 2) * (3 - m_count * m_recInvSqrt^2)
141 * \param recInvSqrt reciprocal value of sqrt (count)
142 * \param count count value
143 * \return The new recInvSqrt value
144 */
145 static uint16_t NewtonStep(uint16_t recInvSqrt, uint32_t count);
146
147 /**
148 * \brief Determine the time for next drop
149 * CoDel control law is t + m_interval/sqrt(m_count).
150 * Here, we use m_recInvSqrt calculated by Newton's method in NewtonStep() to avoid
151 * both sqrt() and divide operations
152 *
153 * \param t Current next drop time (in units of CoDel time)
154 * \param interval interval (in units of CoDel time)
155 * \param recInvSqrt reciprocal value of sqrt (count)
156 * \return The new next drop time (in units of CoDel time)
157 */
158 static uint32_t ControlLaw(uint32_t t, uint32_t interval, uint32_t recInvSqrt);
159
160 /**
161 * \brief Determine whether a packet is OK to be dropped. The packet
162 * may not be actually dropped (depending on the drop state)
163 *
164 * \param item The packet that is considered
165 * \param now The current time represented as 32-bit unsigned integer (us)
166 * \returns True if it is OK to drop the packet (sojourn time above target for at least
167 * interval)
168 */
169 bool OkToDrop(Ptr<QueueDiscItem> item, uint32_t now);
170
171 /**
172 * Check if CoDel time a is successive to b
173 * @param a left operand
174 * @param b right operand
175 * @return true if a is greater than b
176 */
178 /**
179 * Check if CoDel time a is successive or equal to b
180 * @param a left operand
181 * @param b right operand
182 * @return true if a is greater than or equal to b
183 */
185 /**
186 * Check if CoDel time a is preceding b
187 * @param a left operand
188 * @param b right operand
189 * @return true if a is less than to b
190 */
192 /**
193 * Check if CoDel time a is preceding or equal to b
194 * @param a left operand
195 * @param b right operand
196 * @return true if a is less than or equal to b
197 */
199
200 /**
201 * Return the unsigned 32-bit integer representation of the input Time
202 * object. Units are microseconds
203 * @param t the input Time Object
204 * @return the unsigned 32-bit integer representation
205 */
207
208 void InitializeParams() override;
209
210 bool m_useEcn; //!< True if ECN is used (packets are marked instead of being dropped)
211 bool m_useL4s; //!< True if L4S is used (ECT1 packets are marked at CE threshold)
212 uint32_t m_minBytes; //!< Minimum bytes in queue to allow a packet drop
213 Time m_interval; //!< 100 ms sliding minimum time window width
214 Time m_target; //!< 5 ms target queue delay
215 Time m_ceThreshold; //!< Threshold above which to CE mark
216 TracedValue<uint32_t> m_count; //!< Number of packets dropped since entering drop state
217 TracedValue<uint32_t> m_lastCount; //!< Last number of packets dropped since entering drop state
218 TracedValue<bool> m_dropping; //!< True if in dropping state
219 uint16_t m_recInvSqrt; //!< Reciprocal inverse square root
220 uint32_t m_firstAboveTime; //!< Time to declare sojourn time above target
221 TracedValue<uint32_t> m_dropNext; //!< Time to drop next packet
222};
223
224} // namespace ns3
225
226#endif /* CODEL_H */
Test 4: ControlLaw unit test - test against explicit port of Linux implementation.
Test 3: NewtonStep unit test - test against explicit port of Linux implementation.
A CoDel packet queue disc.
bool CheckConfig() override
Check whether the current configuration is correct.
uint32_t GetDropNext()
Get the time for next packet drop while in the dropping state.
static uint16_t NewtonStep(uint16_t recInvSqrt, uint32_t count)
Calculate the reciprocal square root of m_count by using Newton's method http://en....
static constexpr const char * OVERLIMIT_DROP
Overlimit dropped packet.
static uint32_t ControlLaw(uint32_t t, uint32_t interval, uint32_t recInvSqrt)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
static constexpr const char * TARGET_EXCEEDED_DROP
Sojourn time above target.
uint16_t m_recInvSqrt
Reciprocal inverse square root.
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Check if CoDel time a is preceding or equal to b.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
Time m_ceThreshold
Threshold above which to CE mark.
Time GetInterval()
Get the interval.
Ptr< QueueDiscItem > DoDequeue() override
Remove a packet from queue based on the current state If we are in dropping state,...
uint32_t m_minBytes
Minimum bytes in queue to allow a packet drop.
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Check if CoDel time a is successive or equal to b.
static constexpr const char * CE_THRESHOLD_EXCEEDED_MARK
Sojourn time above CE threshold.
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
bool m_useL4s
True if L4S is used (ECT1 packets are marked at CE threshold)
bool OkToDrop(Ptr< QueueDiscItem > item, uint32_t now)
Determine whether a packet is OK to be dropped.
TracedValue< uint32_t > m_lastCount
Last number of packets dropped since entering drop state.
Time m_target
5 ms target queue delay
uint32_t Time2CoDel(Time t)
Return the unsigned 32-bit integer representation of the input Time object.
CoDelQueueDisc()
CoDelQueueDisc Constructor.
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
Time GetTarget()
Get the target queue delay.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
TracedValue< bool > m_dropping
True if in dropping state.
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Check if CoDel time a is successive to b.
bool CoDelTimeBefore(uint32_t a, uint32_t b)
Check if CoDel time a is preceding b.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
Add a packet to the queue.
static constexpr const char * TARGET_EXCEEDED_MARK
Sojourn time above target.
Time m_interval
100 ms sliding minimum time window width
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
static TypeId GetTypeId()
Get the type ID.
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
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.
static const int CODEL_SHIFT
Number of bits discarded from the time representation.