A Discrete-Event Network Simulator
API
codel-queue.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Andrew McGregor
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  * Codel, the COntrolled DELay Queueing discipline
19  * Based on ns2 simulation code presented by Kathie Nichols
20  *
21  * This port based on linux kernel code by
22  * Authors: 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>
32 #include "ns3/packet.h"
33 #include "ns3/queue.h"
34 #include "ns3/nstime.h"
35 #include "ns3/simulator.h"
36 #include "ns3/string.h"
37 #include "ns3/traced-value.h"
38 #include "ns3/trace-source-accessor.h"
39 
40 class CoDelQueueNewtonStepTest; // Forward declaration for unit test
41 class CoDelQueueControlLawTest; // Forward declaration for unit test
42 
43 namespace ns3 {
44 
49 static 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 
55 class TraceContainer;
56 
63 class CoDelQueue : public Queue
64 {
65 public:
71  static TypeId GetTypeId (void);
72 
78  CoDelQueue ();
79 
80  virtual ~CoDelQueue ();
81 
87  void SetMode (CoDelQueue::QueueMode mode);
88 
95 
101  uint32_t GetQueueSize (void);
102 
109  uint32_t GetDropOverLimit (void);
110 
116  uint32_t GetDropCount (void);
117 
123  Time GetTarget (void);
124 
130  Time GetInterval (void);
131 
137  uint32_t GetDropNext (void);
138 
139 private:
140  friend class::CoDelQueueNewtonStepTest; // Test code
141  friend class::CoDelQueueControlLawTest; // Test code
148  virtual bool DoEnqueue (Ptr<Packet> p);
149 
159  virtual Ptr<Packet> DoDequeue (void);
160 
161  virtual Ptr<const Packet> DoPeek (void) const;
162 
168  void NewtonStep (void);
169 
179  uint32_t ControlLaw (uint32_t t);
180 
189  bool OkToDrop (Ptr<Packet> p, uint32_t now);
190 
197  bool CoDelTimeAfter (uint32_t a, uint32_t b);
204  bool CoDelTimeAfterEq (uint32_t a, uint32_t b);
211  bool CoDelTimeBefore (uint32_t a, uint32_t b);
218  bool CoDelTimeBeforeEq (uint32_t a, uint32_t b);
219 
224  uint32_t Time2CoDel (Time t);
225 
226  std::queue<Ptr<Packet> > m_packets;
227  uint32_t m_maxPackets;
228  uint32_t m_maxBytes;
230  uint32_t m_minBytes;
237  uint16_t m_recInvSqrt;
238  uint32_t m_firstAboveTime;
240  uint32_t m_state1;
241  uint32_t m_state2;
242  uint32_t m_state3;
243  uint32_t m_states;
244  uint32_t m_dropOverLimit;
247 };
248 
249 } // namespace ns3
250 
251 #endif /* CODEL_H */
uint32_t GetDropOverLimit(void)
Get the number of packets dropped when packets arrive at a full queue and cannot be enqueued...
Definition: codel-queue.cc:526
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Check if CoDel time a is successive to b.
Definition: codel-queue.cc:575
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Check if CoDel time a is successive or equal to b.
Definition: codel-queue.cc:581
virtual bool DoEnqueue(Ptr< Packet > p)
Add a packet to the queue.
Definition: codel-queue.cc:279
uint32_t m_state1
Number of times packet sojourn goes above target for interval.
Definition: codel-queue.h:240
uint32_t m_minBytes
Minimum bytes in queue to allow a packet drop.
Definition: codel-queue.h:230
std::queue< Ptr< Packet > > m_packets
The packet queue.
Definition: codel-queue.h:226
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
Definition: codel-queue.h:239
TracedValue< uint32_t > m_lastCount
Last number of packets dropped since entering drop state.
Definition: codel-queue.h:235
TracedValue< bool > m_dropping
True if in dropping state.
Definition: codel-queue.h:236
uint32_t m_states
Total number of times we are in state 1, state 2, or state 3.
Definition: codel-queue.h:243
uint32_t GetDropCount(void)
Get the number of packets dropped according to CoDel algorithm.
Definition: codel-queue.cc:532
uint32_t ControlLaw(uint32_t t)
Determine the time for next drop CoDel control law is t + m_interval/sqrt(m_count).
Definition: codel-queue.cc:258
uint32_t m_state2
Number of times we perform next drop while in dropping state.
Definition: codel-queue.h:241
Abstract base class for packet Queues.
Definition: queue.h:45
uint16_t m_recInvSqrt
Reciprocal inverse square root.
Definition: codel-queue.h:237
Time m_interval
100 ms sliding minimum time window width
Definition: codel-queue.h:231
Time GetTarget(void)
Get the target queue delay.
Definition: codel-queue.cc:538
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:126
CoDelQueue::QueueMode GetMode(void)
Get the encapsulation mode of this device.
Definition: codel-queue.cc:272
bool OkToDrop(Ptr< Packet > p, uint32_t now)
Determine whether a packet is OK to be dropped.
Definition: codel-queue.cc:313
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
Definition: codel-queue.cc:508
TracedValue< uint32_t > m_dropCount
Number of dropped packets according CoDel algorithm.
Definition: codel-queue.h:234
A CoDel packet queue.
Definition: codel-queue.h:63
bool CoDelTimeBefore(uint32_t a, uint32_t b)
Check if CoDel time a is preceding b.
Definition: codel-queue.cc:587
uint32_t m_dropOverLimit
The number of packets dropped due to full queue.
Definition: codel-queue.h:244
uint32_t m_maxBytes
Max # of bytes accepted by the queue.
Definition: codel-queue.h:228
CoDelQueue()
CoDelQueue Constructor.
Definition: codel-queue.cc:217
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
Definition: codel-queue.h:238
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~CoDelQueue()
Definition: codel-queue.cc:239
Time m_target
5 ms target queue delay
Definition: codel-queue.h:232
uint32_t m_maxPackets
Max # of packets accepted by the queue.
Definition: codel-queue.h:227
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Check if CoDel time a is preceding or equal to b.
Definition: codel-queue.cc:593
uint32_t GetDropNext(void)
Get the time for next packet drop while in the dropping state.
Definition: codel-queue.cc:550
static const int CODEL_SHIFT
Number of bits discarded from the time representation.
Definition: codel-queue.h:49
static TypeId GetTypeId(void)
Get the type ID.
Definition: codel-queue.cc:147
QueueMode m_mode
The operating mode (Bytes or packets)
Definition: codel-queue.h:245
void NewtonStep(void)
Calculate the reciprocal square root of m_count by using Newton's method http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots m_recInvSqrt (new) = (m_recInvSqrt (old) / 2) * (3 - m_count * m_recInvSqrt^2)
Definition: codel-queue.cc:245
void SetMode(CoDelQueue::QueueMode mode)
Set the operating mode of this device.
Definition: codel-queue.cc:265
uint32_t Time2CoDel(Time t)
returned unsigned 32-bit integer representation of the input Time object units are microseconds ...
Definition: codel-queue.cc:599
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
Definition: codel-queue.cc:556
Time GetInterval(void)
Get the interval.
Definition: codel-queue.cc:544
uint32_t m_state3
Number of times we enter drop state and drop the fist packet.
Definition: codel-queue.h:242
TracedValue< uint32_t > m_bytesInQueue
The total number of bytes in queue.
Definition: codel-queue.h:229
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
Definition: codel-queue.h:233
virtual Ptr< Packet > DoDequeue(void)
Remove a packet from queue based on the current state If we are in dropping state, check if we could leave the dropping state or if we should perform next drop If we are not currently in dropping state, check if we need to enter the state and drop the first packet.
Definition: codel-queue.cc:355
a unique identifier for an interface.
Definition: type-id.h:58
TracedValue< Time > m_sojourn
Time in queue.
Definition: codel-queue.h:246