A Discrete-Event Network Simulator
API
red-queue-disc.cc
Go to the documentation of this file.
1 // /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright © 2011 Marcos Talau
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  * Author: Marcos Talau (talau@users.sourceforge.net)
19  *
20  * Thanks to: Duy Nguyen<duy@soe.ucsc.edu> by RED efforts in NS3
21  *
22  *
23  * This file incorporates work covered by the following copyright and
24  * permission notice:
25  *
26  * Copyright (c) 1990-1997 Regents of the University of California.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  * 1. Redistributions of source code must retain the above copyright
33  * notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  * notice, this list of conditions and the following disclaimer in the
36  * documentation and/or other materials provided with the distribution.
37  * 3. Neither the name of the University nor of the Laboratory may be used
38  * to endorse or promote products derived from this software without
39  * specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  */
53 
54 /*
55  * PORT NOTE: This code was ported from ns-2 (queue/red.cc). Almost all
56  * comments have also been ported from NS-2
57  */
58 
59 #include "ns3/log.h"
60 #include "ns3/enum.h"
61 #include "ns3/uinteger.h"
62 #include "ns3/double.h"
63 #include "ns3/simulator.h"
64 #include "ns3/abort.h"
65 #include "red-queue-disc.h"
66 #include "ns3/drop-tail-queue.h"
67 #include "ns3/net-device-queue-interface.h"
68 
69 namespace ns3 {
70 
71 NS_LOG_COMPONENT_DEFINE ("RedQueueDisc");
72 
73 NS_OBJECT_ENSURE_REGISTERED (RedQueueDisc);
74 
76 {
77  static TypeId tid = TypeId ("ns3::RedQueueDisc")
78  .SetParent<QueueDisc> ()
79  .SetGroupName("TrafficControl")
80  .AddConstructor<RedQueueDisc> ()
81  .AddAttribute ("Mode",
82  "Determines unit for QueueLimit",
86  MakeEnumChecker (QUEUE_DISC_MODE_BYTES, "QUEUE_DISC_MODE_BYTES",
87  QUEUE_DISC_MODE_PACKETS, "QUEUE_DISC_MODE_PACKETS"),
89  "Use the MaxSize attribute instead")
90  .AddAttribute ("MeanPktSize",
91  "Average of packet size",
92  UintegerValue (500),
94  MakeUintegerChecker<uint32_t> ())
95  .AddAttribute ("IdlePktSize",
96  "Average packet size used during idle times. Used when m_cautions = 3",
97  UintegerValue (0),
99  MakeUintegerChecker<uint32_t> ())
100  .AddAttribute ("Wait",
101  "True for waiting between dropped packets",
102  BooleanValue (true),
105  .AddAttribute ("Gentle",
106  "True to increases dropping probability slowly when average queue exceeds maxthresh",
107  BooleanValue (true),
110  .AddAttribute ("ARED",
111  "True to enable ARED",
112  BooleanValue (false),
115  .AddAttribute ("AdaptMaxP",
116  "True to adapt m_curMaxP",
117  BooleanValue (false),
120  .AddAttribute ("FengAdaptive",
121  "True to enable Feng's Adaptive RED",
122  BooleanValue (false),
125  .AddAttribute ("NLRED",
126  "True to enable Nonlinear RED",
127  BooleanValue (false),
130  .AddAttribute ("MinTh",
131  "Minimum average length threshold in packets/bytes",
132  DoubleValue (5),
134  MakeDoubleChecker<double> ())
135  .AddAttribute ("MaxTh",
136  "Maximum average length threshold in packets/bytes",
137  DoubleValue (15),
139  MakeDoubleChecker<double> ())
140  .AddAttribute ("QueueLimit",
141  "Queue limit in bytes/packets",
142  UintegerValue (25),
144  MakeUintegerChecker<uint32_t> (),
146  "Use the MaxSize attribute instead")
147  .AddAttribute ("MaxSize",
148  "The maximum number of packets accepted by this queue disc",
149  QueueSizeValue (QueueSize ("0p")),
153  .AddAttribute ("QW",
154  "Queue weight related to the exponential weighted moving average (EWMA)",
155  DoubleValue (0.002),
157  MakeDoubleChecker <double> ())
158  .AddAttribute ("LInterm",
159  "The maximum probability of dropping a packet",
160  DoubleValue (50),
162  MakeDoubleChecker <double> ())
163  .AddAttribute ("TargetDelay",
164  "Target average queuing delay in ARED",
165  TimeValue (Seconds (0.005)),
167  MakeTimeChecker ())
168  .AddAttribute ("Interval",
169  "Time interval to update m_curMaxP",
170  TimeValue (Seconds (0.5)),
172  MakeTimeChecker ())
173  .AddAttribute ("Top",
174  "Upper bound for m_curMaxP in ARED",
175  DoubleValue (0.5),
177  MakeDoubleChecker <double> (0, 1))
178  .AddAttribute ("Bottom",
179  "Lower bound for m_curMaxP in ARED",
180  DoubleValue (0.0),
182  MakeDoubleChecker <double> (0, 1))
183  .AddAttribute ("Alpha",
184  "Increment parameter for m_curMaxP in ARED",
185  DoubleValue (0.01),
187  MakeDoubleChecker <double> (0, 1))
188  .AddAttribute ("Beta",
189  "Decrement parameter for m_curMaxP in ARED",
190  DoubleValue (0.9),
192  MakeDoubleChecker <double> (0, 1))
193  .AddAttribute ("FengAlpha",
194  "Decrement parameter for m_curMaxP in Feng's Adaptive RED",
195  DoubleValue (3.0),
197  MakeDoubleChecker <double> ())
198  .AddAttribute ("FengBeta",
199  "Increment parameter for m_curMaxP in Feng's Adaptive RED",
200  DoubleValue (2.0),
202  MakeDoubleChecker <double> ())
203  .AddAttribute ("LastSet",
204  "Store the last time m_curMaxP was updated",
205  TimeValue (Seconds (0.0)),
207  MakeTimeChecker ())
208  .AddAttribute ("Rtt",
209  "Round Trip Time to be considered while automatically setting m_bottom",
210  TimeValue (Seconds (0.1)),
212  MakeTimeChecker ())
213  .AddAttribute ("Ns1Compat",
214  "NS-1 compatibility",
215  BooleanValue (false),
218  .AddAttribute ("LinkBandwidth",
219  "The RED link bandwidth",
220  DataRateValue (DataRate ("1.5Mbps")),
223  .AddAttribute ("LinkDelay",
224  "The RED link delay",
225  TimeValue (MilliSeconds (20)),
227  MakeTimeChecker ())
228  .AddAttribute ("UseEcn",
229  "True to use ECN (packets are marked instead of being dropped)",
230  BooleanValue (false),
233  .AddAttribute ("UseHardDrop",
234  "True to always drop packets above max threshold",
235  BooleanValue (true),
238  ;
239 
240  return tid;
241 }
242 
245 {
246  NS_LOG_FUNCTION (this);
247  m_uv = CreateObject<UniformRandomVariable> ();
248 }
249 
251 {
252  NS_LOG_FUNCTION (this);
253 }
254 
255 void
257 {
258  NS_LOG_FUNCTION (this);
259  m_uv = 0;
261 }
262 
263 void
265 {
266  NS_LOG_FUNCTION (this << mode);
267 
268  if (mode == QUEUE_DISC_MODE_BYTES)
269  {
271  }
272  else if (mode == QUEUE_DISC_MODE_PACKETS)
273  {
275  }
276  else
277  {
278  NS_ABORT_MSG ("Unknown queue size unit");
279  }
280 }
281 
284 {
285  NS_LOG_FUNCTION (this);
287 }
288 
289 void
291 {
292  NS_LOG_FUNCTION (this << alpha);
293  m_alpha = alpha;
294 
295  if (m_alpha > 0.01)
296  {
297  NS_LOG_WARN ("Alpha value is above the recommended bound!");
298  }
299 }
300 
301 double
303 {
304  NS_LOG_FUNCTION (this);
305  return m_alpha;
306 }
307 
308 void
310 {
311  NS_LOG_FUNCTION (this << beta);
312  m_beta = beta;
313 
314  if (m_beta < 0.83)
315  {
316  NS_LOG_WARN ("Beta value is below the recommended bound!");
317  }
318 }
319 
320 double
322 {
323  NS_LOG_FUNCTION (this);
324  return m_beta;
325 }
326 
327 void
329 {
330  NS_LOG_FUNCTION (this << a);
331  m_a = a;
332 
333  if (m_a != 3)
334  {
335  NS_LOG_WARN ("Alpha value does not follow the recommendations!");
336  }
337 }
338 
339 double
341 {
342  NS_LOG_FUNCTION (this);
343  return m_a;
344 }
345 
346 void
348 {
349  NS_LOG_FUNCTION (this << b);
350  m_b = b;
351 
352  if (m_b != 2)
353  {
354  NS_LOG_WARN ("Beta value does not follow the recommendations!");
355  }
356 }
357 
358 double
360 {
361  NS_LOG_FUNCTION (this);
362  return m_b;
363 }
364 
365 void
367 {
368  NS_LOG_FUNCTION (this << lim);
369  SetMaxSize (QueueSize (GetMaxSize ().GetUnit (), lim));
370 }
371 
372 void
373 RedQueueDisc::SetTh (double minTh, double maxTh)
374 {
375  NS_LOG_FUNCTION (this << minTh << maxTh);
376  NS_ASSERT (minTh <= maxTh);
377  m_minTh = minTh;
378  m_maxTh = maxTh;
379 }
380 
381 int64_t
383 {
384  NS_LOG_FUNCTION (this << stream);
385  m_uv->SetStream (stream);
386  return 1;
387 }
388 
389 bool
391 {
392  NS_LOG_FUNCTION (this << item);
393 
394  uint32_t nQueued = GetInternalQueue (0)->GetCurrentSize ().GetValue ();
395 
396  // simulate number of packets arrival during idle period
397  uint32_t m = 0;
398 
399  if (m_idle == 1)
400  {
401  NS_LOG_DEBUG ("RED Queue Disc is idle.");
402  Time now = Simulator::Now ();
403 
404  if (m_cautious == 3)
405  {
406  double ptc = m_ptc * m_meanPktSize / m_idlePktSize;
407  m = uint32_t (ptc * (now - m_idleTime).GetSeconds ());
408  }
409  else
410  {
411  m = uint32_t (m_ptc * (now - m_idleTime).GetSeconds ());
412  }
413 
414  m_idle = 0;
415  }
416 
417  m_qAvg = Estimator (nQueued, m + 1, m_qAvg, m_qW);
418 
419  NS_LOG_DEBUG ("\t bytesInQueue " << GetInternalQueue (0)->GetNBytes () << "\tQavg " << m_qAvg);
420  NS_LOG_DEBUG ("\t packetsInQueue " << GetInternalQueue (0)->GetNPackets () << "\tQavg " << m_qAvg);
421 
422  m_count++;
423  m_countBytes += item->GetSize ();
424 
425  uint32_t dropType = DTYPE_NONE;
426  if (m_qAvg >= m_minTh && nQueued > 1)
427  {
428  if ((!m_isGentle && m_qAvg >= m_maxTh) ||
429  (m_isGentle && m_qAvg >= 2 * m_maxTh))
430  {
431  NS_LOG_DEBUG ("adding DROP FORCED MARK");
432  dropType = DTYPE_FORCED;
433  }
434  else if (m_old == 0)
435  {
436  /*
437  * The average queue size has just crossed the
438  * threshold from below to above m_minTh, or
439  * from above m_minTh with an empty queue to
440  * above m_minTh with a nonempty queue.
441  */
442  m_count = 1;
443  m_countBytes = item->GetSize ();
444  m_old = 1;
445  }
446  else if (DropEarly (item, nQueued))
447  {
448  NS_LOG_LOGIC ("DropEarly returns 1");
449  dropType = DTYPE_UNFORCED;
450  }
451  }
452  else
453  {
454  // No packets are being dropped
455  m_vProb = 0.0;
456  m_old = 0;
457  }
458 
459  if (dropType == DTYPE_UNFORCED)
460  {
461  if (!m_useEcn || !Mark (item, UNFORCED_MARK))
462  {
463  NS_LOG_DEBUG ("\t Dropping due to Prob Mark " << m_qAvg);
465  return false;
466  }
467  NS_LOG_DEBUG ("\t Marking due to Prob Mark " << m_qAvg);
468  }
469  else if (dropType == DTYPE_FORCED)
470  {
471  if (m_useHardDrop || !m_useEcn || !Mark (item, FORCED_MARK))
472  {
473  NS_LOG_DEBUG ("\t Dropping due to Hard Mark " << m_qAvg);
475  if (m_isNs1Compat)
476  {
477  m_count = 0;
478  m_countBytes = 0;
479  }
480  return false;
481  }
482  NS_LOG_DEBUG ("\t Marking due to Hard Mark " << m_qAvg);
483  }
484 
485  bool retval = GetInternalQueue (0)->Enqueue (item);
486 
487  // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
488  // internal queue because QueueDisc::AddInternalQueue sets the trace callback
489 
490  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
491  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
492 
493  return retval;
494 }
495 
496 /*
497  * Note: if the link bandwidth changes in the course of the
498  * simulation, the bandwidth-dependent RED parameters do not change.
499  * This should be fixed, but it would require some extra parameters,
500  * and didn't seem worth the trouble...
501  */
502 void
504 {
505  NS_LOG_FUNCTION (this);
506  NS_LOG_INFO ("Initializing RED params.");
507 
508  m_cautious = 0;
510 
511  if (m_isARED)
512  {
513  // Set m_minTh, m_maxTh and m_qW to zero for automatic setting
514  m_minTh = 0;
515  m_maxTh = 0;
516  m_qW = 0;
517 
518  // Turn on m_isAdaptMaxP to adapt m_curMaxP
519  m_isAdaptMaxP = true;
520  }
521 
522  if (m_isFengAdaptive)
523  {
524  // Initialize m_fengStatus
526  }
527 
528  if (m_minTh == 0 && m_maxTh == 0)
529  {
530  m_minTh = 5.0;
531 
532  // set m_minTh to max(m_minTh, targetqueue/2.0) [Ref: http://www.icir.org/floyd/papers/adaptiveRed.pdf]
533  double targetqueue = m_targetDelay.GetSeconds() * m_ptc;
534 
535  if (m_minTh < targetqueue / 2.0 )
536  {
537  m_minTh = targetqueue / 2.0;
538  }
539  if (GetMode () == QUEUE_DISC_MODE_BYTES)
540  {
542  }
543 
544  // set m_maxTh to three times m_minTh [Ref: http://www.icir.org/floyd/papers/adaptiveRed.pdf]
545  m_maxTh = 3 * m_minTh;
546  }
547 
549 
550  m_qAvg = 0.0;
551  m_count = 0;
552  m_countBytes = 0;
553  m_old = 0;
554  m_idle = 1;
555 
556  double th_diff = (m_maxTh - m_minTh);
557  if (th_diff == 0)
558  {
559  th_diff = 1.0;
560  }
561  m_vA = 1.0 / th_diff;
562  m_curMaxP = 1.0 / m_lInterm;
563  m_vB = -m_minTh / th_diff;
564 
565  if (m_isGentle)
566  {
567  m_vC = (1.0 - m_curMaxP) / m_maxTh;
568  m_vD = 2.0 * m_curMaxP - 1.0;
569  }
570  m_idleTime = NanoSeconds (0);
571 
572 /*
573  * If m_qW=0, set it to a reasonable value of 1-exp(-1/C)
574  * This corresponds to choosing m_qW to be of that value for
575  * which the packet time constant -1/ln(1-m)qW) per default RTT
576  * of 100ms is an order of magnitude more than the link capacity, C.
577  *
578  * If m_qW=-1, then the queue weight is set to be a function of
579  * the bandwidth and the link propagation delay. In particular,
580  * the default RTT is assumed to be three times the link delay and
581  * transmission delay, if this gives a default RTT greater than 100 ms.
582  *
583  * If m_qW=-2, set it to a reasonable value of 1-exp(-10/C).
584  */
585  if (m_qW == 0.0)
586  {
587  m_qW = 1.0 - std::exp (-1.0 / m_ptc);
588  }
589  else if (m_qW == -1.0)
590  {
591  double rtt = 3.0 * (m_linkDelay.GetSeconds () + 1.0 / m_ptc);
592 
593  if (rtt < 0.1)
594  {
595  rtt = 0.1;
596  }
597  m_qW = 1.0 - std::exp (-1.0 / (10 * rtt * m_ptc));
598  }
599  else if (m_qW == -2.0)
600  {
601  m_qW = 1.0 - std::exp (-10.0 / m_ptc);
602  }
603 
604  if (m_bottom == 0)
605  {
606  m_bottom = 0.01;
607  // Set bottom to at most 1/W, where W is the delay-bandwidth
608  // product in packets for a connection.
609  // So W = m_linkBandwidth.GetBitRate () / (8.0 * m_meanPktSize * m_rtt.GetSeconds())
610  double bottom1 = (8.0 * m_meanPktSize * m_rtt.GetSeconds()) / m_linkBandwidth.GetBitRate();
611  if (bottom1 < m_bottom)
612  {
613  m_bottom = bottom1;
614  }
615  }
616 
617  NS_LOG_DEBUG ("\tm_delay " << m_linkDelay.GetSeconds () << "; m_isWait "
618  << m_isWait << "; m_qW " << m_qW << "; m_ptc " << m_ptc
619  << "; m_minTh " << m_minTh << "; m_maxTh " << m_maxTh
620  << "; m_isGentle " << m_isGentle << "; th_diff " << th_diff
621  << "; lInterm " << m_lInterm << "; va " << m_vA << "; cur_max_p "
622  << m_curMaxP << "; v_b " << m_vB << "; m_vC "
623  << m_vC << "; m_vD " << m_vD);
624 }
625 
626 // Updating m_curMaxP, following the pseudocode
627 // from: A Self-Configuring RED Gateway, INFOCOMM '99.
628 // They recommend m_a = 3, and m_b = 2.
629 void
631 {
632  NS_LOG_FUNCTION (this << newAve);
633 
634  if (m_minTh < newAve && newAve < m_maxTh)
635  {
637  }
638  else if (newAve < m_minTh && m_fengStatus != Below)
639  {
641  m_curMaxP = m_curMaxP / m_a;
642  }
643  else if (newAve > m_maxTh && m_fengStatus != Above)
644  {
646  m_curMaxP = m_curMaxP * m_b;
647  }
648 }
649 
650 // Update m_curMaxP to keep the average queue length within the target range.
651 void
653 {
654  NS_LOG_FUNCTION (this << newAve);
655 
656  Time now = Simulator::Now ();
657  double m_part = 0.4 * (m_maxTh - m_minTh);
658  // AIMD rule to keep target Q~1/2(m_minTh + m_maxTh)
659  if (newAve < m_minTh + m_part && m_curMaxP > m_bottom)
660  {
661  // we should increase the average queue size, so decrease m_curMaxP
663  m_lastSet = now;
664  }
665  else if (newAve > m_maxTh - m_part && m_top > m_curMaxP)
666  {
667  // we should decrease the average queue size, so increase m_curMaxP
668  double alpha = m_alpha;
669  if (alpha > 0.25 * m_curMaxP)
670  {
671  alpha = 0.25 * m_curMaxP;
672  }
673  m_curMaxP = m_curMaxP + alpha;
674  m_lastSet = now;
675  }
676 }
677 
678 // Compute the average queue size
679 double
680 RedQueueDisc::Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW)
681 {
682  NS_LOG_FUNCTION (this << nQueued << m << qAvg << qW);
683 
684  double newAve = qAvg * std::pow (1.0 - qW, m);
685  newAve += qW * nQueued;
686 
687  Time now = Simulator::Now ();
688  if (m_isAdaptMaxP && now > m_lastSet + m_interval)
689  {
690  UpdateMaxP (newAve);
691  }
692  else if (m_isFengAdaptive)
693  {
694  UpdateMaxPFeng (newAve); // Update m_curMaxP in MIMD fashion.
695  }
696 
697  return newAve;
698 }
699 
700 // Check if packet p needs to be dropped due to probability mark
701 uint32_t
703 {
704  NS_LOG_FUNCTION (this << item << qSize);
705 
706  double prob1 = CalculatePNew ();
707  m_vProb = ModifyP (prob1, item->GetSize ());
708 
709  // Drop probability is computed, pick random number and act
710  if (m_cautious == 1)
711  {
712  /*
713  * Don't drop/mark if the instantaneous queue is much below the average.
714  * For experimental purposes only.
715  * pkts: the number of packets arriving in 50 ms
716  */
717  double pkts = m_ptc * 0.05;
718  double fraction = std::pow ((1 - m_qW), pkts);
719 
720  if ((double) qSize < fraction * m_qAvg)
721  {
722  // Queue could have been empty for 0.05 seconds
723  return 0;
724  }
725  }
726 
727  double u = m_uv->GetValue ();
728 
729  if (m_cautious == 2)
730  {
731  /*
732  * Decrease the drop probability if the instantaneous
733  * queue is much below the average.
734  * For experimental purposes only.
735  * pkts: the number of packets arriving in 50 ms
736  */
737  double pkts = m_ptc * 0.05;
738  double fraction = std::pow ((1 - m_qW), pkts);
739  double ratio = qSize / (fraction * m_qAvg);
740 
741  if (ratio < 1.0)
742  {
743  u *= 1.0 / ratio;
744  }
745  }
746 
747  if (u <= m_vProb)
748  {
749  NS_LOG_LOGIC ("u <= m_vProb; u " << u << "; m_vProb " << m_vProb);
750 
751  // DROP or MARK
752  m_count = 0;
753  m_countBytes = 0;
755 
756  return 1; // drop
757  }
758 
759  return 0; // no drop/mark
760 }
761 
762 // Returns a probability using these function parameters for the DropEarly funtion
763 double
765 {
766  NS_LOG_FUNCTION (this);
767  double p;
768 
769  if (m_isGentle && m_qAvg >= m_maxTh)
770  {
771  // p ranges from m_curMaxP to 1 as the average queue
772  // size ranges from m_maxTh to twice m_maxTh
773  p = m_vC * m_qAvg + m_vD;
774  }
775  else if (!m_isGentle && m_qAvg >= m_maxTh)
776  {
777  /*
778  * OLD: p continues to range linearly above m_curMaxP as
779  * the average queue size ranges above m_maxTh.
780  * NEW: p is set to 1.0
781  */
782  p = 1.0;
783  }
784  else
785  {
786  /*
787  * p ranges from 0 to m_curMaxP as the average queue size ranges from
788  * m_minTh to m_maxTh
789  */
790  p = m_vA * m_qAvg + m_vB;
791 
792  if (m_isNonlinear)
793  {
794  p *= p * 1.5;
795  }
796 
797  p *= m_curMaxP;
798  }
799 
800  if (p > 1.0)
801  {
802  p = 1.0;
803  }
804 
805  return p;
806 }
807 
808 // Returns a probability using these function parameters for the DropEarly funtion
809 double
810 RedQueueDisc::ModifyP (double p, uint32_t size)
811 {
812  NS_LOG_FUNCTION (this << p << size);
813  double count1 = (double) m_count;
814 
815  if (GetMode () == QUEUE_DISC_MODE_BYTES)
816  {
817  count1 = (double) (m_countBytes / m_meanPktSize);
818  }
819 
820  if (m_isWait)
821  {
822  if (count1 * p < 1.0)
823  {
824  p = 0.0;
825  }
826  else if (count1 * p < 2.0)
827  {
828  p /= (2.0 - count1 * p);
829  }
830  else
831  {
832  p = 1.0;
833  }
834  }
835  else
836  {
837  if (count1 * p < 1.0)
838  {
839  p /= (1.0 - count1 * p);
840  }
841  else
842  {
843  p = 1.0;
844  }
845  }
846 
847  if ((GetMode () == QUEUE_DISC_MODE_BYTES) && (p < 1.0))
848  {
849  p = (p * size) / m_meanPktSize;
850  }
851 
852  if (p > 1.0)
853  {
854  p = 1.0;
855  }
856 
857  return p;
858 }
859 
862 {
863  NS_LOG_FUNCTION (this);
864 
865  if (GetInternalQueue (0)->IsEmpty ())
866  {
867  NS_LOG_LOGIC ("Queue empty");
868  m_idle = 1;
870 
871  return 0;
872  }
873  else
874  {
875  m_idle = 0;
876  Ptr<QueueDiscItem> item = GetInternalQueue (0)->Dequeue ();
877 
878  NS_LOG_LOGIC ("Popped " << item);
879 
880  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
881  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
882 
883  return item;
884  }
885 }
886 
889 {
890  NS_LOG_FUNCTION (this);
891  if (GetInternalQueue (0)->IsEmpty ())
892  {
893  NS_LOG_LOGIC ("Queue empty");
894  return 0;
895  }
896 
897  Ptr<const QueueDiscItem> item = GetInternalQueue (0)->Peek ();
898 
899  NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
900  NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
901 
902  return item;
903 }
904 
905 bool
907 {
908  NS_LOG_FUNCTION (this);
909  if (GetNQueueDiscClasses () > 0)
910  {
911  NS_LOG_ERROR ("RedQueueDisc cannot have classes");
912  return false;
913  }
914 
915  if (GetNPacketFilters () > 0)
916  {
917  NS_LOG_ERROR ("RedQueueDisc cannot have packet filters");
918  return false;
919  }
920 
921  if (GetNInternalQueues () == 0)
922  {
923  // add a DropTail queue
925  ("MaxSize", QueueSizeValue (GetMaxSize ())));
926  }
927 
928  if (GetNInternalQueues () != 1)
929  {
930  NS_LOG_ERROR ("RedQueueDisc needs 1 internal queue");
931  return false;
932  }
933 
935  {
936  NS_LOG_ERROR ("m_isAdaptMaxP and m_isFengAdaptive cannot be simultaneously true");
937  }
938 
939  return true;
940 }
941 
942 } // namespace ns3
void SetMode(QueueDiscMode mode)
Set the operating mode of this queue disc.
bool m_isGentle
True to increase dropping prob.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:652
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
double m_beta
Decrement parameter for m_curMaxP in ARED.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
uint32_t m_count
Number of packets since last random number generation.
Class for representing queue sizes.
Definition: queue-size.h:94
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
void DropBeforeEnqueue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped before enqueue...
Definition: queue-disc.cc:704
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool m_isARED
True to enable Adaptive RED.
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:447
double GetFengAdaptiveA(void)
Get the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
double m_qAvg
Average queue length.
bool Mark(Ptr< QueueDiscItem > item, const char *reason)
Marks the given packet and, if successful, updates the counters associated with the given reason...
Definition: queue-disc.cc:782
Time m_linkDelay
Link delay.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
void SetAredBeta(double beta)
Set the beta value to adapt m_curMaxP.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
uint32_t m_idle
0/1 idle status
FengStatus m_fengStatus
For use in Feng's Adaptive RED.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1015
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
void SetFengAdaptiveB(double b)
Set the beta value to adapt m_curMaxP in Feng's Adaptive RED.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
bool m_useHardDrop
True if packets are always dropped above max threshold.
double m_qW
Queue weight given to cur queue size sample.
static constexpr const char * FORCED_MARK
Forced marks, m_qAvg > m_maxTh.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:181
A RED packet queue disc.
double m_b
Increment parameter for m_curMaxP in Feng's Adaptive RED.
static constexpr const char * FORCED_DROP
Forced drops, m_qAvg > m_maxTh.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
double GetAredAlpha(void)
Get the alpha value to adapt m_curMaxP.
Time m_rtt
Rtt to be considered while automatically setting m_bottom in ARED.
static constexpr const char * UNFORCED_DROP
Early probability drops.
double m_alpha
Increment parameter for m_curMaxP in ARED.
Time m_lastSet
Last time m_curMaxP was updated.
bool m_isAdaptMaxP
True to adapt m_curMaxP.
Ptr< const AttributeChecker > MakeDataRateChecker(void)
Definition: data-rate.cc:30
Ptr< InternalQueue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:587
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
static TypeId GetTypeId(void)
Get the type ID.
Class for representing data rates.
Definition: data-rate.h:88
double m_curMaxP
Current max_p.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:594
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:567
Time m_idleTime
Start of current idle period.
Ptr< T > CreateObjectWithAttributes(std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
Allocate an Object on the heap and initialize with a set of attributes.
Hold variables of type enum.
Definition: enum.h:54
AttributeValue implementation for Time.
Definition: nstime.h:1069
double GetFengAdaptiveB(void)
Get the beta value to adapt m_curMaxP in Feng's Adaptive RED.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1031
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual void InitializeParams(void)
Initialize the queue parameters.
uint32_t m_cautious
0 for default RED 1 experimental (see red-queue-disc.cc) 2 experimental (see red-queue-disc.cc) 3 use Idle packet size in the ptc
Use number of packets for queue size.
Definition: queue-size.h:44
Ptr< UniformRandomVariable > m_uv
rng stream
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
double m_vB
-m_minTh / (m_maxTh - m_minTh)
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:381
bool m_isNonlinear
True to enable Nonlinear RED.
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:614
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: data-rate.h:242
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
double m_minTh
Minimum threshold for m_qAvg (bytes or packets)
virtual Ptr< const QueueDiscItem > DoPeek(void)
This function returns a copy of the next packet the queue disc will extract.
Use number of bytes for maximum queue disc size.
uint32_t m_idlePktSize
Avg pkt size used during idle times.
Introspection did not find any typical Config paths.
Ptr< const AttributeChecker > MakeQueueSizeChecker(void)
Definition: queue-size.cc:29
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_vA
1.0 / (m_maxTh - m_minTh)
uint32_t m_countBytes
Number of bytes since last drop.
QueueDiscMode
Enumeration of the modes supported in the class.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
double m_lInterm
The max probability of dropping a packet.
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
uint64_t GetBitRate() const
Get the underlying bitrate.
Definition: data-rate.cc:249
static constexpr const char * UNFORCED_MARK
Early probability marks.
uint32_t DropEarly(Ptr< QueueDiscItem > item, uint32_t qSize)
Check if a packet needs to be dropped due to probability mark.
RedQueueDisc()
RedQueueDisc Constructor.
double m_bottom
Lower bound for m_curMaxP in ARED.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1070
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
When m_qAvg > m_maxTh.
void UpdateMaxP(double newAve)
Update m_curMaxP.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:103
uint32_t m_old
0 when average queue first exceeds threshold
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
Used by queue discs with single internal queue.
Definition: queue-disc.h:105
void SetFengAdaptiveA(double a)
Set the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
An "unforced" (random) drop.
DataRate m_linkBandwidth
Link bandwidth.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
Time m_interval
Time interval to update m_curMaxP.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:482
bool m_isWait
True for waiting between dropped packets.
Time m_targetDelay
Target average queuing delay in ARED.
double GetAredBeta(void)
Get the beta value to adapt m_curMaxP.
double m_ptc
packet time constant in packets/second
virtual ~RedQueueDisc()
Destructor.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:253
double m_top
Upper bound for m_curMaxP in ARED.
QueueDiscMode GetMode(void) const
Get the operating mode of this queue disc.
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
uint32_t m_meanPktSize
Avg pkt size.
void UpdateMaxPFeng(double newAve)
Update m_curMaxP based on Feng's Adaptive RED.
bool m_isFengAdaptive
True to enable Feng's Adaptive RED.
double CalculatePNew(void)
Returns a probability using these function parameters for the DropEarly function. ...
void SetAredAlpha(double alpha)
Set the alpha value to adapt m_curMaxP.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
virtual void DoDispose(void)
Dispose of the object.
double ModifyP(double p, uint32_t size)
Returns a probability using these function parameters for the DropEarly function. ...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
Use number of bytes for queue size.
Definition: queue-size.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
double m_vProb
Prob.
Use number of packets for maximum queue disc size.
double m_maxTh
Maximum threshold for m_qAvg (bytes or packets), should be >= 2 * m_minTh.
When m_maxTh < m_qAvg < m_minTh.
When m_qAvg < m_minTh.
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:454
double m_a
Decrement parameter for m_curMaxP in Feng's Adaptive RED.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:440
bool m_isNs1Compat
Ns-1 compatibility.