A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
45 static const int CODEL_SHIFT = 10;
46 static const int DEFAULT_CODEL_LIMIT = 1000;
47 
48 #define REC_INV_SQRT_BITS (8 * sizeof(uint16_t))
49 #define REC_INV_SQRT_SHIFT (32 - REC_INV_SQRT_BITS)
50 
51 class TraceContainer;
52 
59 class CoDelQueue : public Queue
60 {
61 public:
62  static TypeId GetTypeId (void);
63 
69  CoDelQueue ();
70 
71  virtual ~CoDelQueue ();
72 
78  void SetMode (CoDelQueue::QueueMode mode);
79 
86 
92  uint32_t GetQueueSize (void);
93 
100  uint32_t GetDropOverLimit (void);
101 
107  uint32_t GetDropCount (void);
108 
114  Time GetTarget (void);
115 
121  Time GetInterval (void);
122 
128  uint32_t GetDropNext (void);
129 
130 private:
131  friend class::CoDelQueueNewtonStepTest; // Test code
132  friend class::CoDelQueueControlLawTest; // Test code
139  virtual bool DoEnqueue (Ptr<Packet> p);
140 
150  virtual Ptr<Packet> DoDequeue (void);
151 
152  virtual Ptr<const Packet> DoPeek (void) const;
153 
159  void NewtonStep (void);
160 
170  uint32_t ControlLaw (uint32_t t);
171 
180  bool OkToDrop (Ptr<Packet> p, uint32_t now);
181 
182  bool CoDelTimeAfter (uint32_t a, uint32_t b);
183  bool CoDelTimeAfterEq (uint32_t a, uint32_t b);
184  bool CoDelTimeBefore (uint32_t a, uint32_t b);
185  bool CoDelTimeBeforeEq (uint32_t a, uint32_t b);
186 
191  uint32_t Time2CoDel (Time t);
192 
193  std::queue<Ptr<Packet> > m_packets;
194  uint32_t m_maxPackets;
195  uint32_t m_maxBytes;
197  uint32_t m_minBytes;
202  TracedValue<uint32_t> m_lastCount; //<! Last number of packets dropped since entering drop state
204  uint16_t m_recInvSqrt;
205  uint32_t m_firstAboveTime;
207  uint32_t m_state1;
208  uint32_t m_state2;
209  uint32_t m_state3;
210  uint32_t m_states;
211  uint32_t m_dropOverLimit;
214 };
215 
216 } // namespace ns3
217 
218 #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:484
bool CoDelTimeAfter(uint32_t a, uint32_t b)
Definition: codel-queue.cc:533
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
bool CoDelTimeAfterEq(uint32_t a, uint32_t b)
Definition: codel-queue.cc:539
virtual bool DoEnqueue(Ptr< Packet > p)
Add a packet to the queue.
Definition: codel-queue.cc:249
uint32_t m_state1
Number of times packet sojourn goes above target for interval.
Definition: codel-queue.h:207
uint32_t m_minBytes
Minimum bytes in queue to allow a packet drop.
Definition: codel-queue.h:197
std::queue< Ptr< Packet > > m_packets
The packet queue.
Definition: codel-queue.h:193
TracedValue< uint32_t > m_dropNext
Time to drop next packet.
Definition: codel-queue.h:206
TracedValue< uint32_t > m_lastCount
Definition: codel-queue.h:202
TracedValue< bool > m_dropping
True if in dropping state.
Definition: codel-queue.h:203
uint32_t m_states
Total number of times we are in state 1, state 2, or state 3.
Definition: codel-queue.h:210
uint32_t GetDropCount(void)
Get the number of packets dropped according to CoDel algorithm.
Definition: codel-queue.cc:490
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:228
uint32_t m_state2
Number of times we perform next drop while in dropping state.
Definition: codel-queue.h:208
Abstract base class for packet Queues.
Definition: queue.h:45
uint16_t m_recInvSqrt
Reciprocal inverse square root.
Definition: codel-queue.h:204
Time m_interval
100 ms sliding minimum time window width
Definition: codel-queue.h:198
Time GetTarget(void)
Get the target queue delay.
Definition: codel-queue.cc:496
CoDelQueue::QueueMode GetMode(void)
Get the encapsulation mode of this device.
Definition: codel-queue.cc:242
bool OkToDrop(Ptr< Packet > p, uint32_t now)
Determine whether a packet is OK to be dropped.
Definition: codel-queue.cc:283
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
Definition: codel-queue.cc:466
TracedValue< uint32_t > m_dropCount
Number of dropped packets according CoDel algorithm.
Definition: codel-queue.h:201
A CoDel packet queue.
Definition: codel-queue.h:59
bool CoDelTimeBefore(uint32_t a, uint32_t b)
Definition: codel-queue.cc:545
uint32_t m_dropOverLimit
The number of packets dropped due to full queue.
Definition: codel-queue.h:211
uint32_t m_maxBytes
Max # of bytes accepted by the queue.
Definition: codel-queue.h:195
CoDelQueue()
CoDelQueue Constructor.
Definition: codel-queue.cc:187
uint32_t m_firstAboveTime
Time to declare sojourn time above target.
Definition: codel-queue.h:205
virtual ~CoDelQueue()
Definition: codel-queue.cc:209
Time m_target
5 ms target queue delay
Definition: codel-queue.h:199
uint32_t m_maxPackets
Max # of packets accepted by the queue.
Definition: codel-queue.h:194
bool CoDelTimeBeforeEq(uint32_t a, uint32_t b)
Definition: codel-queue.cc:551
uint32_t GetDropNext(void)
Get the time for next packet drop while in the dropping state.
Definition: codel-queue.cc:508
static const int CODEL_SHIFT
Definition: codel-queue.h:45
static TypeId GetTypeId(void)
Definition: codel-queue.cc:125
QueueMode m_mode
The operating mode (Bytes or packets)
Definition: codel-queue.h:212
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:126
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:215
void SetMode(CoDelQueue::QueueMode mode)
Set the operating mode of this device.
Definition: codel-queue.cc:235
uint32_t Time2CoDel(Time t)
returned unsigned 32-bit integer representation of the input Time object units are microseconds ...
Definition: codel-queue.cc:557
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
Definition: codel-queue.cc:514
Time GetInterval(void)
Get the interval.
Definition: codel-queue.cc:502
uint32_t m_state3
Number of times we enter drop state and drop the fist packet.
Definition: codel-queue.h:209
TracedValue< uint32_t > m_bytesInQueue
The total number of bytes in queue.
Definition: codel-queue.h:196
static const int DEFAULT_CODEL_LIMIT
Definition: codel-queue.h:46
TracedValue< uint32_t > m_count
Number of packets dropped since entering drop state.
Definition: codel-queue.h:200
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:325
a unique identifier for an interface.
Definition: type-id.h:49
TracedValue< Time > m_sojourn
Time in queue.
Definition: codel-queue.h:213