LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2016 NITK Surathkal | 3 * Copyright (c) 2016 NITK Surathkal |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 TypeId PieQueueDisc::GetTypeId (void) | 44 TypeId PieQueueDisc::GetTypeId (void) |
45 { | 45 { |
46 static TypeId tid = TypeId ("ns3::PieQueueDisc") | 46 static TypeId tid = TypeId ("ns3::PieQueueDisc") |
47 .SetParent<QueueDisc> () | 47 .SetParent<QueueDisc> () |
48 .SetGroupName ("TrafficControl") | 48 .SetGroupName ("TrafficControl") |
49 .AddConstructor<PieQueueDisc> () | 49 .AddConstructor<PieQueueDisc> () |
50 .AddAttribute ("Mode", | 50 .AddAttribute ("Mode", |
51 "Determines unit for QueueLimit", | 51 "Determines unit for QueueLimit", |
52 EnumValue (QUEUE_DISC_MODE_PACKETS), | 52 EnumValue (QUEUE_DISC_MODE_PACKETS), |
53 MakeEnumAccessor (&PieQueueDisc::SetMode), | 53 MakeEnumAccessor (&PieQueueDisc::SetMode, |
| 54 &PieQueueDisc::GetMode), |
54 MakeEnumChecker (QUEUE_DISC_MODE_BYTES, "QUEUE_DISC_MODE_BYTE
S", | 55 MakeEnumChecker (QUEUE_DISC_MODE_BYTES, "QUEUE_DISC_MODE_BYTE
S", |
55 QUEUE_DISC_MODE_PACKETS, "QUEUE_DISC_MODE_PA
CKETS")) | 56 QUEUE_DISC_MODE_PACKETS, "QUEUE_DISC_MODE_PA
CKETS"), |
| 57 TypeId::DEPRECATED, |
| 58 "Use the MaxSize attribute instead") |
56 .AddAttribute ("MeanPktSize", | 59 .AddAttribute ("MeanPktSize", |
57 "Average of packet size", | 60 "Average of packet size", |
58 UintegerValue (1000), | 61 UintegerValue (1000), |
59 MakeUintegerAccessor (&PieQueueDisc::m_meanPktSize), | 62 MakeUintegerAccessor (&PieQueueDisc::m_meanPktSize), |
60 MakeUintegerChecker<uint32_t> ()) | 63 MakeUintegerChecker<uint32_t> ()) |
61 .AddAttribute ("A", | 64 .AddAttribute ("A", |
62 "Value of alpha", | 65 "Value of alpha", |
63 DoubleValue (0.125), | 66 DoubleValue (0.125), |
64 MakeDoubleAccessor (&PieQueueDisc::m_a), | 67 MakeDoubleAccessor (&PieQueueDisc::m_a), |
65 MakeDoubleChecker<double> ()) | 68 MakeDoubleChecker<double> ()) |
66 .AddAttribute ("B", | 69 .AddAttribute ("B", |
67 "Value of beta", | 70 "Value of beta", |
68 DoubleValue (1.25), | 71 DoubleValue (1.25), |
69 MakeDoubleAccessor (&PieQueueDisc::m_b), | 72 MakeDoubleAccessor (&PieQueueDisc::m_b), |
70 MakeDoubleChecker<double> ()) | 73 MakeDoubleChecker<double> ()) |
71 .AddAttribute ("Tupdate", | 74 .AddAttribute ("Tupdate", |
72 "Time period to calculate drop probability", | 75 "Time period to calculate drop probability", |
73 TimeValue (Seconds (0.03)), | 76 TimeValue (Seconds (0.03)), |
74 MakeTimeAccessor (&PieQueueDisc::m_tUpdate), | 77 MakeTimeAccessor (&PieQueueDisc::m_tUpdate), |
75 MakeTimeChecker ()) | 78 MakeTimeChecker ()) |
76 .AddAttribute ("Supdate", | 79 .AddAttribute ("Supdate", |
77 "Start time of the update timer", | 80 "Start time of the update timer", |
78 TimeValue (Seconds (0)), | 81 TimeValue (Seconds (0)), |
79 MakeTimeAccessor (&PieQueueDisc::m_sUpdate), | 82 MakeTimeAccessor (&PieQueueDisc::m_sUpdate), |
80 MakeTimeChecker ()) | 83 MakeTimeChecker ()) |
81 .AddAttribute ("QueueLimit", | 84 .AddAttribute ("QueueLimit", |
82 "Queue limit in bytes/packets", | 85 "Queue limit in bytes/packets", |
83 UintegerValue (25), | 86 UintegerValue (25), |
84 MakeUintegerAccessor (&PieQueueDisc::SetQueueLimit), | 87 MakeUintegerAccessor (&PieQueueDisc::SetQueueLimit), |
85 MakeUintegerChecker<uint32_t> ()) | 88 MakeUintegerChecker<uint32_t> (), |
| 89 TypeId::DEPRECATED, |
| 90 "Use the MaxSize attribute instead") |
| 91 .AddAttribute ("MaxSize", |
| 92 "The maximum number of packets accepted by this queue disc", |
| 93 QueueSizeValue (QueueSize ("0p")), |
| 94 MakeQueueSizeAccessor (&QueueDisc::SetMaxSize, |
| 95 &QueueDisc::GetMaxSize), |
| 96 MakeQueueSizeChecker ()) |
86 .AddAttribute ("DequeueThreshold", | 97 .AddAttribute ("DequeueThreshold", |
87 "Minimum queue size in bytes before dequeue rate is measured"
, | 98 "Minimum queue size in bytes before dequeue rate is measured"
, |
88 UintegerValue (10000), | 99 UintegerValue (10000), |
89 MakeUintegerAccessor (&PieQueueDisc::m_dqThreshold), | 100 MakeUintegerAccessor (&PieQueueDisc::m_dqThreshold), |
90 MakeUintegerChecker<uint32_t> ()) | 101 MakeUintegerChecker<uint32_t> ()) |
91 .AddAttribute ("QueueDelayReference", | 102 .AddAttribute ("QueueDelayReference", |
92 "Desired queue delay", | 103 "Desired queue delay", |
93 TimeValue (Seconds (0.02)), | 104 TimeValue (Seconds (0.02)), |
94 MakeTimeAccessor (&PieQueueDisc::m_qDelayRef), | 105 MakeTimeAccessor (&PieQueueDisc::m_qDelayRef), |
95 MakeTimeChecker ()) | 106 MakeTimeChecker ()) |
96 .AddAttribute ("MaxBurstAllowance", | 107 .AddAttribute ("MaxBurstAllowance", |
97 "Current max burst allowance in seconds before random drop", | 108 "Current max burst allowance in seconds before random drop", |
98 TimeValue (Seconds (0.1)), | 109 TimeValue (Seconds (0.1)), |
99 MakeTimeAccessor (&PieQueueDisc::m_maxBurst), | 110 MakeTimeAccessor (&PieQueueDisc::m_maxBurst), |
100 MakeTimeChecker ()) | 111 MakeTimeChecker ()) |
101 ; | 112 ; |
102 | 113 |
103 return tid; | 114 return tid; |
104 } | 115 } |
105 | 116 |
106 PieQueueDisc::PieQueueDisc () | 117 PieQueueDisc::PieQueueDisc () |
107 : QueueDisc () | 118 : QueueDisc (QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE) |
108 { | 119 { |
109 NS_LOG_FUNCTION (this); | 120 NS_LOG_FUNCTION (this); |
110 m_uv = CreateObject<UniformRandomVariable> (); | 121 m_uv = CreateObject<UniformRandomVariable> (); |
111 m_rtrsEvent = Simulator::Schedule (m_sUpdate, &PieQueueDisc::CalculateP, this)
; | 122 m_rtrsEvent = Simulator::Schedule (m_sUpdate, &PieQueueDisc::CalculateP, this)
; |
112 } | 123 } |
113 | 124 |
114 PieQueueDisc::~PieQueueDisc () | 125 PieQueueDisc::~PieQueueDisc () |
115 { | 126 { |
116 NS_LOG_FUNCTION (this); | 127 NS_LOG_FUNCTION (this); |
117 } | 128 } |
118 | 129 |
119 void | 130 void |
120 PieQueueDisc::DoDispose (void) | 131 PieQueueDisc::DoDispose (void) |
121 { | 132 { |
122 NS_LOG_FUNCTION (this); | 133 NS_LOG_FUNCTION (this); |
123 m_uv = 0; | 134 m_uv = 0; |
124 Simulator::Remove (m_rtrsEvent); | 135 Simulator::Remove (m_rtrsEvent); |
125 QueueDisc::DoDispose (); | 136 QueueDisc::DoDispose (); |
126 } | 137 } |
127 | 138 |
128 void | 139 void |
129 PieQueueDisc::SetMode (QueueDiscMode mode) | 140 PieQueueDisc::SetMode (QueueDiscMode mode) |
130 { | 141 { |
131 NS_LOG_FUNCTION (this << mode); | 142 NS_LOG_FUNCTION (this << mode); |
132 m_mode = mode; | 143 |
| 144 if (mode == QUEUE_DISC_MODE_BYTES) |
| 145 { |
| 146 SetMaxSize (QueueSize (QueueSizeUnit::BYTES, GetMaxSize ().GetValue ())); |
| 147 } |
| 148 else if (mode == QUEUE_DISC_MODE_PACKETS) |
| 149 { |
| 150 SetMaxSize (QueueSize (QueueSizeUnit::PACKETS, GetMaxSize ().GetValue ()))
; |
| 151 } |
| 152 else |
| 153 { |
| 154 NS_ABORT_MSG ("Unknown queue size unit"); |
| 155 } |
133 } | 156 } |
134 | 157 |
135 PieQueueDisc::QueueDiscMode | 158 PieQueueDisc::QueueDiscMode |
136 PieQueueDisc::GetMode (void) | 159 PieQueueDisc::GetMode (void) const |
137 { | 160 { |
138 NS_LOG_FUNCTION (this); | 161 NS_LOG_FUNCTION (this); |
139 return m_mode; | 162 return (GetMaxSize ().GetUnit () == QueueSizeUnit::PACKETS ? QUEUE_DISC_MODE_P
ACKETS : QUEUE_DISC_MODE_BYTES); |
140 } | 163 } |
141 | 164 |
142 void | 165 void |
143 PieQueueDisc::SetQueueLimit (uint32_t lim) | 166 PieQueueDisc::SetQueueLimit (uint32_t lim) |
144 { | 167 { |
145 NS_LOG_FUNCTION (this << lim); | 168 NS_LOG_FUNCTION (this << lim); |
146 m_queueLimit = lim; | 169 SetMaxSize (QueueSize (GetMaxSize ().GetUnit (), lim)); |
147 } | 170 } |
148 | 171 |
149 uint32_t | 172 uint32_t |
150 PieQueueDisc::GetQueueSize (void) | 173 PieQueueDisc::GetQueueSize (void) |
151 { | 174 { |
152 NS_LOG_FUNCTION (this); | 175 NS_LOG_FUNCTION (this); |
153 if (GetMode () == QUEUE_DISC_MODE_BYTES) | 176 if (GetMode () == QUEUE_DISC_MODE_BYTES) |
154 { | 177 { |
155 return GetInternalQueue (0)->GetNBytes (); | 178 return GetInternalQueue (0)->GetNBytes (); |
156 } | 179 } |
(...skipping 20 matching lines...) Expand all Loading... |
177 NS_LOG_FUNCTION (this << stream); | 200 NS_LOG_FUNCTION (this << stream); |
178 m_uv->SetStream (stream); | 201 m_uv->SetStream (stream); |
179 return 1; | 202 return 1; |
180 } | 203 } |
181 | 204 |
182 bool | 205 bool |
183 PieQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) | 206 PieQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) |
184 { | 207 { |
185 NS_LOG_FUNCTION (this << item); | 208 NS_LOG_FUNCTION (this << item); |
186 | 209 |
187 uint32_t nQueued = GetQueueSize (); | 210 QueueSize nQueued = GetCurrentSize (); |
188 | 211 |
189 if ((GetMode () == QUEUE_DISC_MODE_PACKETS && nQueued >= m_queueLimit) | 212 if (nQueued + item > GetMaxSize ()) |
190 || (GetMode () == QUEUE_DISC_MODE_BYTES && nQueued + item->GetSize () > m_
queueLimit)) | |
191 { | 213 { |
192 // Drops due to queue limit: reactive | 214 // Drops due to queue limit: reactive |
193 DropBeforeEnqueue (item, FORCED_DROP); | 215 DropBeforeEnqueue (item, FORCED_DROP); |
194 return false; | 216 return false; |
195 } | 217 } |
196 else if (DropEarly (item, nQueued)) | 218 else if (DropEarly (item, nQueued.GetValue ())) |
197 { | 219 { |
198 // Early probability drop: proactive | 220 // Early probability drop: proactive |
199 DropBeforeEnqueue (item, UNFORCED_DROP); | 221 DropBeforeEnqueue (item, UNFORCED_DROP); |
200 return false; | 222 return false; |
201 } | 223 } |
202 | 224 |
203 // No drop | 225 // No drop |
204 bool retval = GetInternalQueue (0)->Enqueue (item); | 226 bool retval = GetInternalQueue (0)->Enqueue (item); |
205 | 227 |
206 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the | 228 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 m_dqCount = 0; | 467 m_dqCount = 0; |
446 m_inMeasurement = false; | 468 m_inMeasurement = false; |
447 } | 469 } |
448 } | 470 } |
449 } | 471 } |
450 | 472 |
451 return item; | 473 return item; |
452 } | 474 } |
453 | 475 |
454 Ptr<const QueueDiscItem> | 476 Ptr<const QueueDiscItem> |
455 PieQueueDisc::DoPeek () const | 477 PieQueueDisc::DoPeek () |
456 { | 478 { |
457 NS_LOG_FUNCTION (this); | 479 NS_LOG_FUNCTION (this); |
458 if (GetInternalQueue (0)->IsEmpty ()) | 480 |
| 481 Ptr<const QueueDiscItem> item = PeekDequeued (); |
| 482 |
| 483 if (!item) |
459 { | 484 { |
460 NS_LOG_LOGIC ("Queue empty"); | 485 NS_LOG_LOGIC ("Queue empty"); |
461 return 0; | 486 return 0; |
462 } | 487 } |
463 | 488 |
464 Ptr<const QueueDiscItem> item = GetInternalQueue (0)->Peek (); | |
465 | |
466 NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ()); | 489 NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ()); |
467 NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ()); | 490 NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ()); |
468 | 491 |
469 return item; | 492 return item; |
470 } | 493 } |
471 | 494 |
472 bool | 495 bool |
473 PieQueueDisc::CheckConfig (void) | 496 PieQueueDisc::CheckConfig (void) |
474 { | 497 { |
475 NS_LOG_FUNCTION (this); | 498 NS_LOG_FUNCTION (this); |
476 if (GetNQueueDiscClasses () > 0) | 499 if (GetNQueueDiscClasses () > 0) |
477 { | 500 { |
478 NS_LOG_ERROR ("PieQueueDisc cannot have classes"); | 501 NS_LOG_ERROR ("PieQueueDisc cannot have classes"); |
479 return false; | 502 return false; |
480 } | 503 } |
481 | 504 |
482 if (GetNPacketFilters () > 0) | 505 if (GetNPacketFilters () > 0) |
483 { | 506 { |
484 NS_LOG_ERROR ("PieQueueDisc cannot have packet filters"); | 507 NS_LOG_ERROR ("PieQueueDisc cannot have packet filters"); |
485 return false; | 508 return false; |
486 } | 509 } |
487 | 510 |
488 if (GetNInternalQueues () == 0) | 511 if (GetNInternalQueues () == 0) |
489 { | 512 { |
490 // create a DropTail queue | 513 // add a DropTail queue |
491 Ptr<InternalQueue> queue = CreateObjectWithAttributes<DropTailQueue<QueueD
iscItem> > ("Mode", EnumValue (m_mode)); | 514 AddInternalQueue (CreateObjectWithAttributes<DropTailQueue<QueueDiscItem>
> |
492 if (m_mode == QUEUE_DISC_MODE_PACKETS) | 515 ("MaxSize", QueueSizeValue (GetMaxSize ()))); |
493 { | |
494 queue->SetMaxPackets (m_queueLimit); | |
495 } | |
496 else | |
497 { | |
498 queue->SetMaxBytes (m_queueLimit); | |
499 } | |
500 AddInternalQueue (queue); | |
501 } | 516 } |
502 | 517 |
503 if (GetNInternalQueues () != 1) | 518 if (GetNInternalQueues () != 1) |
504 { | 519 { |
505 NS_LOG_ERROR ("PieQueueDisc needs 1 internal queue"); | 520 NS_LOG_ERROR ("PieQueueDisc needs 1 internal queue"); |
506 return false; | 521 return false; |
507 } | 522 } |
508 | 523 |
509 if ((GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_PACKETS && m_mo
de == QUEUE_DISC_MODE_BYTES) || | |
510 (GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_BYTES && m_mode
== QUEUE_DISC_MODE_PACKETS)) | |
511 { | |
512 NS_LOG_ERROR ("The mode of the provided queue does not match the mode set
on the PieQueueDisc"); | |
513 return false; | |
514 } | |
515 | |
516 if ((m_mode == QUEUE_DISC_MODE_PACKETS && GetInternalQueue (0)->GetMaxPackets
() != m_queueLimit) | |
517 || (m_mode == QUEUE_DISC_MODE_BYTES && GetInternalQueue (0)->GetMaxBytes
() != m_queueLimit)) | |
518 { | |
519 NS_LOG_ERROR ("The size of the internal queue differs from the queue disc
limit"); | |
520 return false; | |
521 } | |
522 | |
523 return true; | 524 return true; |
524 } | 525 } |
525 | 526 |
526 } //namespace ns3 | 527 } //namespace ns3 |
LEFT | RIGHT |