A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cobalt-queue-disc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 NITK Surathkal
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 * Cobalt, the CoDel - BLUE - Alternate Queueing discipline
18 * Based on linux code.
19 *
20 * Ported to ns-3 by: Vignesh Kannan <vignesh2496@gmail.com>
21 * Harsh Lara <harshapplefan@gmail.com>
22 * Jendaipou Palmei <jendaipoupalmei@gmail.com>
23 * Shefali Gupta <shefaligups11@gmail.com>
24 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
25 *
26 */
27
28#ifndef COBALT_H
29#define COBALT_H
30
31#include "queue-disc.h"
32
33#include "ns3/boolean.h"
34#include "ns3/data-rate.h"
35#include "ns3/nstime.h"
36#include "ns3/random-variable-stream.h"
37#include "ns3/simulator.h"
38#include "ns3/string.h"
39#include "ns3/trace-source-accessor.h"
40#include "ns3/traced-value.h"
41
42namespace ns3
43{
44
45#define REC_INV_SQRT_CACHE (16)
46#define DEFAULT_COBALT_LIMIT 1000
47
48class TraceContainer;
49
50/**
51 * \ingroup traffic-control
52 *
53 * \brief Cobalt packet queue disc
54 *
55 * Cobalt uses CoDel and BLUE algorithms in parallel, in order
56 * to obtain the best features of each. CoDel is excellent on flows
57 * which respond to congestion signals in a TCP-like way. BLUE is far
58 * more effective on unresponsive flows.
59 */
61{
62 public:
63 /**
64 * \brief Get the type ID.
65 * \return the object TypeId
66 */
67 static TypeId GetTypeId();
68
69 /**
70 * \brief CobaltQueueDisc Constructor
71 *
72 * Create a Cobalt queue disc
73 */
75
76 /**
77 * \brief Destructor
78 *
79 * Destructor
80 */
81 ~CobaltQueueDisc() override;
82
83 /**
84 * \brief Get the target queue delay
85 *
86 * \returns The target queue delay
87 */
88 Time GetTarget() const;
89
90 /**
91 * \brief Get the interval
92 *
93 * \returns The interval
94 */
95 Time GetInterval() const;
96
97 /**
98 * \brief Get the time for next packet drop while in the dropping state
99 *
100 * \returns The time (in microseconds) for next packet drop
101 */
102 int64_t GetDropNext() const;
103
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 static constexpr const char* FORCED_MARK =
108 "forcedMark"; //!< forced marks by Codel on ECN-enabled
109 static constexpr const char* CE_THRESHOLD_EXCEEDED_MARK =
110 "CE threshold exceeded mark"; //!< Sojourn time above CE threshold
111
112 /**
113 * \brief Get the drop probability of Blue
114 *
115 * \returns The current value of Blue's drop probability
116 */
117 double GetPdrop() const;
118
119 /**
120 * Assign a fixed random variable stream number to the random variables
121 * used by this model. Return the number of streams (possibly zero) that
122 * have been assigned.
123 *
124 * \param stream first stream index to use
125 * \return the number of stream indices assigned by this model
126 */
127 int64_t AssignStreams(int64_t stream);
128
129 /**
130 * Return the unsigned 32-bit integer representation of the input Time
131 * object. Units are microseconds
132 * @param t the input Time Object
133 * @return the unsigned 32-bit integer representation
134 */
135 int64_t Time2CoDel(Time t) const;
136
137 protected:
138 /**
139 * \brief Dispose of the object
140 */
141 void DoDispose() override;
142
143 private:
144 bool DoEnqueue(Ptr<QueueDiscItem> item) override;
145 Ptr<QueueDiscItem> DoDequeue() override;
147 bool CheckConfig() override;
148
149 /**
150 * \brief Initialize the queue parameters.
151 */
152 void InitializeParams() override;
153
154 /**
155 * \brief Calculate the reciprocal square root of m_count by using Newton's method
156 * http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots
157 * m_recInvSqrt (new) = (m_recInvSqrt (old) / 2) * (3 - m_count * m_recInvSqrt^2)
158 */
159 void NewtonStep();
160
161 /**
162 * \brief Determine the time for next drop
163 * CoDel control law is t + m_interval/sqrt(m_count).
164 * Here, we use m_recInvSqrt calculated by Newton's method in NewtonStep() to avoid
165 * both sqrt() and divide operations
166 *
167 * \param t Current next drop time
168 * \returns The new next drop time:
169 */
170 int64_t ControlLaw(int64_t t);
171
172 /**
173 * \brief Updates the inverse square root
174 */
175 void InvSqrt();
176
177 /**
178 * There is a big difference in timing between the accurate values placed in
179 * the cache and the approximations given by a single Newton step for small
180 * count values, particularly when stepping from count 1 to 2 or vice versa.
181 * Above 16, a single Newton step gives sufficient accuracy in either
182 * direction, given the precision stored.
183 *
184 * The magnitude of the error when stepping up to count 2 is such as to give
185 * the value that *should* have been produced at count 4.
186 */
187 void CacheInit();
188
189 /**
190 * Check if CoDel time a is successive to b
191 * @param a left operand
192 * @param b right operand
193 * @return true if a is greater than b
194 */
195
196 bool CoDelTimeAfter(int64_t a, int64_t b);
197
198 /**
199 * Check if CoDel time a is successive or equal to b
200 * @param a left operand
201 * @param b right operand
202 * @return true if a is greater than or equal to b
203 */
204 bool CoDelTimeAfterEq(int64_t a, int64_t b);
205
206 /**
207 * Called when the queue becomes full to alter the drop probabilities of Blue
208 * \param now time in CoDel time units (microseconds)
209 */
210 void CobaltQueueFull(int64_t now);
211
212 /**
213 * Called when the queue becomes empty to alter the drop probabilities of Blue
214 * \param now time in CoDel time units (microseconds)
215 */
216 void CobaltQueueEmpty(int64_t now);
217
218 /**
219 * Called to decide whether the current packet should be dropped based on decisions taken by
220 * Blue and Codel working parallelly
221 *
222 * \return true if the packet should be dropped, false otherwise
223 * \param item current packet
224 * \param now time in CoDel time units (microseconds)
225 */
226 bool CobaltShouldDrop(Ptr<QueueDiscItem> item, int64_t now);
227
228 // Common to CoDel and Blue
229 // Maintained by Cobalt
230 Stats m_stats; //!< Cobalt statistics
231
232 // Codel parameters
233 // Maintained by Cobalt
234 TracedValue<uint32_t> m_count; //!< Number of packets dropped since entering drop state
235 TracedValue<int64_t> m_dropNext; //!< Time to drop next packet
236 TracedValue<bool> m_dropping; //!< True if in dropping state
237 uint32_t m_recInvSqrt; //!< Reciprocal inverse square root
239 0}; //!< Cache to maintain some initial values of InvSqrt
240
241 // Supplied by user
242 Time m_interval; //!< sliding minimum time window width
243 Time m_target; //!< target queue delay
244 bool m_useEcn; //!< True if ECN is used (packets are marked instead of being dropped)
245 Time m_ceThreshold; //!< Threshold above which to CE mark
246 bool m_useL4s; //!< True if L4S is used (ECT1 packets are marked at CE threshold)
247 Time m_blueThreshold; //!< Threshold to enable blue enhancement
248
249 // Blue parameters
250 // Maintained by Cobalt
252 uint32_t m_lastUpdateTimeBlue; //!< Blue's last update time for drop probability
253
254 // Supplied by user
255 double m_increment; //!< increment value for marking probability
256 double m_decrement; //!< decrement value for marking probability
257 double m_pDrop; //!< Drop Probability
258};
259
260} // namespace ns3
261
262#endif /* COBALT_H */
Cobalt packet queue disc.
Time m_ceThreshold
Threshold above which to CE mark.
uint32_t m_recInvSqrtCache[REC_INV_SQRT_CACHE]
Cache to maintain some initial values of InvSqrt.
Time m_target
target queue delay
static constexpr const char * CE_THRESHOLD_EXCEEDED_MARK
Sojourn time above CE threshold.
bool CheckConfig() override
Check whether the current configuration is correct.
void NewtonStep()
Calculate the reciprocal square root of m_count by using Newton's method http://en....
Time GetTarget() const
Get the target queue delay.
int64_t GetDropNext() const
Get the time for next packet drop while in the dropping state.
void InitializeParams() override
Initialize the queue parameters.
bool CoDelTimeAfterEq(int64_t a, int64_t b)
Check if CoDel time a is successive or equal to b.
void InvSqrt()
Updates the inverse square root.
double GetPdrop() const
Get the drop probability of Blue.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void DoDispose() override
Dispose of the object.
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
Stats m_stats
Cobalt statistics.
double m_increment
increment value for marking probability
void CobaltQueueFull(int64_t now)
Called when the queue becomes full to alter the drop probabilities of Blue.
Time m_interval
sliding minimum time window width
double m_decrement
decrement value for marking probability
bool CobaltShouldDrop(Ptr< QueueDiscItem > item, int64_t now)
Called to decide whether the current packet should be dropped based on decisions taken by Blue and Co...
static TypeId GetTypeId()
Get the type ID.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
void CacheInit()
There is a big difference in timing between the accurate values placed in the cache and the approxima...
~CobaltQueueDisc() override
Destructor.
static constexpr const char * TARGET_EXCEEDED_DROP
Sojourn time above target.
int64_t Time2CoDel(Time t) const
Return the unsigned 32-bit integer representation of the input Time object.
bool CoDelTimeAfter(int64_t a, int64_t b)
Check if CoDel time a is successive to b.
Time GetInterval() const
Get the interval.
double m_pDrop
Drop Probability.
CobaltQueueDisc()
CobaltQueueDisc Constructor.
int64_t ControlLaw(int64_t t)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
static constexpr const char * FORCED_MARK
forced marks by Codel on ECN-enabled
Time m_blueThreshold
Threshold to enable blue enhancement.
uint32_t m_recInvSqrt
Reciprocal inverse square root.
Ptr< UniformRandomVariable > m_uv
Rng stream.
uint32_t m_lastUpdateTimeBlue
Blue's last update time for drop probability.
static constexpr const char * OVERLIMIT_DROP
Overlimit dropped packet.
TracedValue< bool > m_dropping
True if in dropping state.
Ptr< const QueueDiscItem > DoPeek() override
Return a copy of the next packet the queue disc will extract.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
TracedValue< int64_t > m_dropNext
Time to drop next packet.
void CobaltQueueEmpty(int64_t now)
Called when the queue becomes empty to alter the drop probabilities of Blue.
bool m_useL4s
True if L4S is used (ECT1 packets are marked at CE threshold)
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
#define REC_INV_SQRT_CACHE
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:188