View | Details | Raw Unified | Return to bug 2924
Collapse All | Expand All

(-)a/src/traffic-control/doc/queue-discs.rst (-1 / +11 lines)
 Lines 93-102   queue disc. A subclass is required to implement the following methods: Link Here 
93
93
94
* ``bool DoEnqueue (Ptr<QueueDiscItem> item)``:  Enqueue a packet
94
* ``bool DoEnqueue (Ptr<QueueDiscItem> item)``:  Enqueue a packet
95
* ``Ptr<QueueDiscItem> DoDequeue (void)``:  Dequeue a packet
95
* ``Ptr<QueueDiscItem> DoDequeue (void)``:  Dequeue a packet
96
* ``Ptr<const QueueDiscItem> DoPeek (void) const``: Peek a packet
97
* ``bool CheckConfig (void) const``: Check if the configuration is correct
96
* ``bool CheckConfig (void) const``: Check if the configuration is correct
98
* ``void InitializeParams (void)``: Initialize queue disc parameters
97
* ``void InitializeParams (void)``: Initialize queue disc parameters
99
98
99
and may override the default implementation of the following method:
100
101
* ``Ptr<const QueueDiscItem> DoPeek (void) const``: Peek the next packet to extract
102
103
The default implementation of the ``DoPeek`` method is based on the qdisc_peek_dequeued
104
function of the Linux kernel, which dequeues a packet and retains it in the
105
queue disc as a requeued packet. This approach is recommended
106
especially for queue discs for which it is not obvious what is the next
107
packet that will be dequeued (e.g., queue discs having multiple internal
108
queues or child queue discs or queue discs that drop packets after dequeue).
109
100
The C++ base class QueueDisc implements:
110
The C++ base class QueueDisc implements:
101
111
102
* methods to add/get a single queue, class or filter and methods to get the number \
112
* methods to add/get a single queue, class or filter and methods to get the number \
(-)a/src/traffic-control/model/codel-queue-disc.cc (-19 lines)
 Lines 362-386   CoDelQueueDisc::GetDropNext (void) Link Here 
362
  return m_dropNext;
362
  return m_dropNext;
363
}
363
}
364
364
365
Ptr<const QueueDiscItem>
366
CoDelQueueDisc::DoPeek (void)
367
{
368
  NS_LOG_FUNCTION (this);
369
370
  Ptr<const QueueDiscItem> item = PeekDequeued ();
371
372
  if (!item)
373
    {
374
      NS_LOG_LOGIC ("Queue empty");
375
      return 0;
376
    }
377
378
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
379
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
380
381
  return item;
382
}
383
384
bool
365
bool
385
CoDelQueueDisc::CoDelTimeAfter (uint32_t a, uint32_t b)
366
CoDelQueueDisc::CoDelTimeAfter (uint32_t a, uint32_t b)
386
{
367
{
(-)a/src/traffic-control/model/codel-queue-disc.h (-1 lines)
 Lines 124-130   private: Link Here 
124
   */
124
   */
125
  virtual Ptr<QueueDiscItem> DoDequeue (void);
125
  virtual Ptr<QueueDiscItem> DoDequeue (void);
126
126
127
  virtual Ptr<const QueueDiscItem> DoPeek (void);
128
  virtual bool CheckConfig (void);
127
  virtual bool CheckConfig (void);
129
128
130
  /**
129
  /**
(-)a/src/traffic-control/model/fq-codel-queue-disc.cc (-8 lines)
 Lines 302-315   FqCoDelQueueDisc::DoDequeue (void) Link Here 
302
  return item;
302
  return item;
303
}
303
}
304
304
305
Ptr<const QueueDiscItem>
306
FqCoDelQueueDisc::DoPeek (void)
307
{
308
  NS_LOG_FUNCTION (this);
309
310
  return PeekDequeued ();
311
}
312
313
bool
305
bool
314
FqCoDelQueueDisc::CheckConfig (void)
306
FqCoDelQueueDisc::CheckConfig (void)
315
{
307
{
(-)a/src/traffic-control/model/fq-codel-queue-disc.h (-1 lines)
 Lines 133-139   public: Link Here 
133
private:
133
private:
134
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
134
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
135
  virtual Ptr<QueueDiscItem> DoDequeue (void);
135
  virtual Ptr<QueueDiscItem> DoDequeue (void);
136
  virtual Ptr<const QueueDiscItem> DoPeek (void);
137
  virtual bool CheckConfig (void);
136
  virtual bool CheckConfig (void);
138
  virtual void InitializeParams (void);
137
  virtual void InitializeParams (void);
139
138
(-)a/src/traffic-control/model/pie-queue-disc.cc (-19 lines)
 Lines 406-430   PieQueueDisc::DoDequeue () Link Here 
406
  return item;
406
  return item;
407
}
407
}
408
408
409
Ptr<const QueueDiscItem>
410
PieQueueDisc::DoPeek ()
411
{
412
  NS_LOG_FUNCTION (this);
413
414
  Ptr<const QueueDiscItem> item = PeekDequeued ();
415
416
  if (!item)
417
    {
418
      NS_LOG_LOGIC ("Queue empty");
419
      return 0;
420
    }
421
422
  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
423
  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
424
425
  return item;
426
}
427
428
bool
409
bool
429
PieQueueDisc::CheckConfig (void)
410
PieQueueDisc::CheckConfig (void)
430
{
411
{
(-)a/src/traffic-control/model/pie-queue-disc.h (-1 lines)
 Lines 107-113   protected: Link Here 
107
private:
107
private:
108
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
108
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
109
  virtual Ptr<QueueDiscItem> DoDequeue (void);
109
  virtual Ptr<QueueDiscItem> DoDequeue (void);
110
  virtual Ptr<const QueueDiscItem> DoPeek (void);
111
  virtual bool CheckConfig (void);
110
  virtual bool CheckConfig (void);
112
111
113
  /**
112
  /**
(-)a/src/traffic-control/model/queue-disc.cc (-21 / +14 lines)
 Lines 861-867   QueueDisc::Dequeue (void) Link Here 
861
{
861
{
862
  NS_LOG_FUNCTION (this);
862
  NS_LOG_FUNCTION (this);
863
863
864
  Ptr<QueueDiscItem> item = DoDequeue ();
864
  // The QueueDisc::DoPeek method dequeues a packet and keeps it as a requeued
865
  // packet. Thus, first check whether a peeked packet exists. Otherwise, call
866
  // the private DoDequeue method.
867
  Ptr<QueueDiscItem> item = m_requeued;
868
869
  if (item)
870
    {
871
      m_requeued = 0;
872
    }
873
  else
874
    {
875
      item = DoDequeue ();
876
    }
865
877
866
  NS_ASSERT (m_nPackets == m_stats.nTotalEnqueuedPackets - m_stats.nTotalDequeuedPackets);
878
  NS_ASSERT (m_nPackets == m_stats.nTotalEnqueuedPackets - m_stats.nTotalDequeuedPackets);
867
  NS_ASSERT (m_nBytes == m_stats.nTotalEnqueuedBytes - m_stats.nTotalDequeuedBytes);
879
  NS_ASSERT (m_nBytes == m_stats.nTotalEnqueuedBytes - m_stats.nTotalDequeuedBytes);
 Lines 877-883   QueueDisc::Peek (void) Link Here 
877
}
889
}
878
890
879
Ptr<const QueueDiscItem>
891
Ptr<const QueueDiscItem>
880
QueueDisc::PeekDequeued (void)
892
QueueDisc::DoPeek (void)
881
{
893
{
882
  NS_LOG_FUNCTION (this);
894
  NS_LOG_FUNCTION (this);
883
895
 Lines 888-912   QueueDisc::PeekDequeued (void) Link Here 
888
  return m_requeued;
900
  return m_requeued;
889
}
901
}
890
902
891
Ptr<QueueDiscItem>
892
QueueDisc::DequeuePeeked (void)
893
{
894
  NS_LOG_FUNCTION (this);
895
896
  Ptr<QueueDiscItem> item = m_requeued;
897
898
  if (item)
899
    {
900
      m_requeued = 0;
901
    }
902
  else
903
    {
904
      item = Dequeue ();
905
    }
906
907
  return item;
908
}
909
910
void
903
void
911
QueueDisc::Run (void)
904
QueueDisc::Run (void)
912
{
905
{
(-)a/src/traffic-control/model/queue-disc.h (-29 / +20 lines)
 Lines 371-379   public: Link Here 
371
  bool Enqueue (Ptr<QueueDiscItem> item);
371
  bool Enqueue (Ptr<QueueDiscItem> item);
372
372
373
  /**
373
  /**
374
   * Request the queue discipline to extract a packet. This function only updates
374
   * Extract from the queue disc the packet that has been dequeued by calling
375
   * the statistics and calls the (private) DoDequeue function, which must be
375
   * Peek, if any, or call the private DoDequeue method (which must be
376
   * implemented by derived classes.
376
   * implemented by derived classes) to dequeue a packet, otherwise.
377
   *
377
   * \return 0 if the operation was not successful; the item otherwise.
378
   * \return 0 if the operation was not successful; the item otherwise.
378
   */
379
   */
379
  Ptr<QueueDiscItem> Dequeue (void);
380
  Ptr<QueueDiscItem> Dequeue (void);
 Lines 381-399   public: Link Here 
381
  /**
382
  /**
382
   * Get a copy of the next packet the queue discipline will extract, without
383
   * Get a copy of the next packet the queue discipline will extract, without
383
   * actually extracting the packet. This function only calls the (private)
384
   * actually extracting the packet. This function only calls the (private)
384
   * DoPeek function, which must be implemented by derived classes.
385
   * DoPeek function.
385
   * \return 0 if the operation was not successful; the item otherwise.
386
   * \return 0 if the operation was not successful; the item otherwise.
386
   */
387
   */
387
  Ptr<const QueueDiscItem> Peek (void);
388
  Ptr<const QueueDiscItem> Peek (void);
388
389
389
  /**
390
   * Extract from the queue disc the packet that has been dequeued by calling
391
   * PeekDequeued.
392
   *
393
   * \return 0 if the operation was not successful; the item otherwise.
394
   */
395
  Ptr<QueueDiscItem> DequeuePeeked (void);
396
397
  /**
390
  /**
398
   * Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c)
391
   * Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c)
399
   * Dequeues multiple packets, until a quota is exceeded or sending a packet
392
   * Dequeues multiple packets, until a quota is exceeded or sending a packet
 Lines 543-563   protected: Link Here 
543
   */
536
   */
544
  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
537
  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
545
538
546
  /**
547
   * Dequeue a packet and retain it in the queue disc as a requeued packet.
548
   * The packet is not traced as requeued, nor is the total count of requeued
549
   * packets increased. The dequeued packet is not counted in the backlog of
550
   * the queue disc and is actually extracted from the queue disc by calling
551
   * DequeuePeeked. Queue discs can point their DoPeek method to this one. This
552
   * is recommended especially for queue discs for which it is not obvious what
553
   * is the next packet that will be dequeued (e.g., queue discs having multiple
554
   * internal queues or child queue discs or queue discs that drop packets
555
   * after dequeue).
556
   *
557
   * \return 0 if the operation was not successful; the item otherwise.
558
   */
559
  Ptr<const QueueDiscItem> PeekDequeued (void);
560
561
private:
539
private:
562
  /**
540
  /**
563
   * \brief Copy constructor
541
   * \brief Copy constructor
 Lines 590-599   private: Link Here 
590
  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
568
  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
591
569
592
  /**
570
  /**
593
   * This function returns a copy of the next packet the queue disc will extract.
571
   * \brief Return a copy of the next packet the queue disc will extract.
572
   *
573
   * The implementation of this method is based on the qdisc_peek_dequeued
574
   * function of the Linux kernel, which dequeues a packet and retains it in the
575
   * queue disc as a requeued packet. The packet is not traced as requeued, nor
576
   * is the total count of requeued packets increased. The dequeued packet is
577
   * not counted in the backlog of the queue disc and is actually extracted from
578
   * the queue disc by calling DequeuePeeked. This approach is recommended
579
   * especially for queue discs for which it is not obvious what is the next
580
   * packet that will be dequeued (e.g., queue discs having multiple internal
581
   * queues or child queue discs or queue discs that drop packets after dequeue).
582
   * Subclasses can however provide their own implementation of this method that
583
   * overrides the default one.
584
   *
594
   * \return 0 if the operation was not successful; the packet otherwise.
585
   * \return 0 if the operation was not successful; the packet otherwise.
595
   */
586
   */
596
  virtual Ptr<const QueueDiscItem> DoPeek (void) = 0;
587
  virtual Ptr<const QueueDiscItem> DoPeek (void);
597
588
598
  /**
589
  /**
599
   * Check whether the current configuration is correct. Default objects (such
590
   * Check whether the current configuration is correct. Default objects (such
(-)a/src/traffic-control/model/tbf-queue-disc.cc (-19 / +1 lines)
 Lines 193-216   TbfQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) Link Here 
193
  return retval;
193
  return retval;
194
}
194
}
195
195
196
Ptr<const QueueDiscItem>
197
TbfQueueDisc::DoPeek ()
198
{
199
  NS_LOG_FUNCTION (this);
200
201
  Ptr<const QueueDiscItem> item = PeekDequeued ();
202
203
  if (!item)
204
    {
205
      NS_LOG_LOGIC ("No packet returned");
206
      return 0;
207
    }
208
209
  NS_LOG_LOGIC ("Current queue size: " << GetNPackets () << " packets, " << GetNBytes () << " bytes");
210
211
  return item;
212
}
213
214
Ptr<QueueDiscItem>
196
Ptr<QueueDiscItem>
215
TbfQueueDisc::DoDequeue (void)
197
TbfQueueDisc::DoDequeue (void)
216
{
198
{
 Lines 254-260   TbfQueueDisc::DoDequeue (void) Link Here 
254
236
255
      if ((btoks|ptoks) >= 0) // else packet blocked
237
      if ((btoks|ptoks) >= 0) // else packet blocked
256
        {
238
        {
257
          Ptr<QueueDiscItem> item = GetQueueDiscClass (0)->GetQueueDisc ()->DequeuePeeked ();
239
          Ptr<QueueDiscItem> item = GetQueueDiscClass (0)->GetQueueDisc ()->Dequeue ();
258
          if (!item)
240
          if (!item)
259
            {
241
            {
260
              NS_LOG_DEBUG ("That's odd! Expecting the peeked packet, we got no packet.");
242
              NS_LOG_DEBUG ("That's odd! Expecting the peeked packet, we got no packet.");
(-)a/src/traffic-control/model/tbf-queue-disc.h (-1 lines)
 Lines 149-155   private: Link Here 
149
149
150
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
150
  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
151
  virtual Ptr<QueueDiscItem> DoDequeue (void);
151
  virtual Ptr<QueueDiscItem> DoDequeue (void);
152
  virtual Ptr<const QueueDiscItem> DoPeek (void);
153
  virtual bool CheckConfig (void);
152
  virtual bool CheckConfig (void);
154
  virtual void InitializeParams (void);
153
  virtual void InitializeParams (void);
155
154

Return to bug 2924