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