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