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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Authors: Priya S Tavarmani <priyast663@gmail.com> | 18 * Authors: Viyom Mittal <viyommittal@gmail.com> |
19 * Viyom Mittal <viyommittal@gmail.com> | |
20 * Mohit P. Tahiliani <tahiliani@nitk.edu.in> | 19 * Mohit P. Tahiliani <tahiliani@nitk.edu.in> |
21 */ | 20 */ |
22 | 21 |
23 /* | 22 /* |
24 * PORT NOTE: This code was ported from ns-2.36rc1 (queue/pi.cc). | 23 * PORT NOTE: This code was ported from ns-2.36rc1 (queue/pi.cc). |
25 * Most of the comments are also ported from the same. | 24 * Most of the comments are also ported from the same. |
26 */ | 25 */ |
27 | 26 |
28 #include "ns3/log.h" | 27 #include "ns3/log.h" |
29 #include "ns3/enum.h" | 28 #include "ns3/enum.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 .AddAttribute ("W", | 75 .AddAttribute ("W", |
77 "Sampling frequency", | 76 "Sampling frequency", |
78 DoubleValue (170), | 77 DoubleValue (170), |
79 MakeDoubleAccessor (&PiQueueDisc::m_w), | 78 MakeDoubleAccessor (&PiQueueDisc::m_w), |
80 MakeDoubleChecker<double> ()) | 79 MakeDoubleChecker<double> ()) |
81 .AddAttribute ("QueueLimit", | 80 .AddAttribute ("QueueLimit", |
82 "Queue limit in bytes/packets", | 81 "Queue limit in bytes/packets", |
83 DoubleValue (50), | 82 DoubleValue (50), |
84 MakeDoubleAccessor (&PiQueueDisc::SetQueueLimit), | 83 MakeDoubleAccessor (&PiQueueDisc::SetQueueLimit), |
85 MakeDoubleChecker<double> ()) | 84 MakeDoubleChecker<double> ()) |
| 85 .AddAttribute ("UseEcn", |
| 86 "True to use ECN (packets are marked instead of being dropped
)", |
| 87 BooleanValue (false), |
| 88 MakeBooleanAccessor (&PiQueueDisc::m_useEcn), |
| 89 MakeBooleanChecker ()) |
86 ; | 90 ; |
87 | 91 |
88 return tid; | 92 return tid; |
89 } | 93 } |
90 | 94 |
91 PiQueueDisc::PiQueueDisc () | 95 PiQueueDisc::PiQueueDisc () |
92 : QueueDisc () | 96 : QueueDisc () |
93 { | 97 { |
94 NS_LOG_FUNCTION (this); | 98 NS_LOG_FUNCTION (this); |
95 m_uv = CreateObject<UniformRandomVariable> (); | 99 m_uv = CreateObject<UniformRandomVariable> (); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 else if (GetMode () == QUEUE_DISC_MODE_PACKETS) | 146 else if (GetMode () == QUEUE_DISC_MODE_PACKETS) |
143 { | 147 { |
144 return GetInternalQueue (0)->GetNPackets (); | 148 return GetInternalQueue (0)->GetNPackets (); |
145 } | 149 } |
146 else | 150 else |
147 { | 151 { |
148 NS_ABORT_MSG ("Unknown PI mode."); | 152 NS_ABORT_MSG ("Unknown PI mode."); |
149 } | 153 } |
150 } | 154 } |
151 | 155 |
152 PiQueueDisc::Stats | |
153 PiQueueDisc::GetStats () | |
154 { | |
155 NS_LOG_FUNCTION (this); | |
156 return m_stats; | |
157 } | |
158 | |
159 int64_t | 156 int64_t |
160 PiQueueDisc::AssignStreams (int64_t stream) | 157 PiQueueDisc::AssignStreams (int64_t stream) |
161 { | 158 { |
162 NS_LOG_FUNCTION (this << stream); | 159 NS_LOG_FUNCTION (this << stream); |
163 m_uv->SetStream (stream); | 160 m_uv->SetStream (stream); |
164 return 1; | 161 return 1; |
165 } | 162 } |
166 | 163 |
167 bool | 164 bool |
168 PiQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) | 165 PiQueueDisc::DoEnqueue (Ptr<QueueDiscItem> item) |
169 { | 166 { |
170 NS_LOG_FUNCTION (this << item); | 167 NS_LOG_FUNCTION (this << item); |
171 | 168 |
172 uint32_t nQueued = GetQueueSize (); | 169 uint32_t nQueued = GetQueueSize (); |
173 | 170 |
174 if ((GetMode () == QUEUE_DISC_MODE_PACKETS && nQueued >= m_queueLimit) | 171 if ((GetMode () == QUEUE_DISC_MODE_PACKETS && nQueued >= m_queueLimit) |
175 || (GetMode () == QUEUE_DISC_MODE_BYTES && nQueued + item->GetSize () > m_
queueLimit)) | 172 || (GetMode () == QUEUE_DISC_MODE_BYTES && nQueued + item->GetSize () > m_
queueLimit)) |
176 { | 173 { |
177 // Drops due to queue limit: reactive | 174 // Drops due to queue limit: reactive |
178 Drop (item); | 175 DropBeforeEnqueue (item, FORCED_DROP); |
179 m_stats.forcedDrop++; | |
180 return false; | 176 return false; |
181 } | 177 } |
182 else if (DropEarly (item, nQueued)) | 178 else if (DropEarly (item, nQueued)) |
183 { | 179 { |
184 // Early probability drop: proactive | 180 if (!m_useEcn || !Mark (item, UNFORCED_MARK)) |
185 Drop (item); | 181 { |
186 m_stats.unforcedDrop++; | 182 // Early probability drop: proactive |
187 return false; | 183 DropBeforeEnqueue (item, UNFORCED_DROP); |
| 184 return false; |
| 185 } |
188 } | 186 } |
189 | 187 |
190 // No drop | 188 // No drop |
191 bool retval = GetInternalQueue (0)->Enqueue (item); | 189 bool retval = GetInternalQueue (0)->Enqueue (item); |
192 | 190 |
193 // If Queue::Enqueue fails, QueueDisc::Drop is called by the internal queue | 191 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the |
194 // because QueueDisc::AddInternalQueue sets the drop callback | 192 // internal queue because QueueDisc::AddInternalQueue sets the trace callback |
195 | 193 |
196 NS_LOG_LOGIC ("\t bytesInQueue " << GetInternalQueue (0)->GetNBytes ()); | 194 NS_LOG_LOGIC ("\t bytesInQueue " << GetInternalQueue (0)->GetNBytes ()); |
197 NS_LOG_LOGIC ("\t packetsInQueue " << GetInternalQueue (0)->GetNPackets ()); | 195 NS_LOG_LOGIC ("\t packetsInQueue " << GetInternalQueue (0)->GetNPackets ()); |
198 | 196 |
199 return retval; | 197 return retval; |
200 } | 198 } |
201 | 199 |
202 void | 200 void |
203 PiQueueDisc::InitializeParams (void) | 201 PiQueueDisc::InitializeParams (void) |
204 { | 202 { |
205 m_dropProb = 0; | 203 m_dropProb = 0; |
206 m_stats.forcedDrop = 0; | |
207 m_stats.unforcedDrop = 0; | |
208 m_qOld = 0; | 204 m_qOld = 0; |
209 } | 205 } |
210 | 206 |
211 bool PiQueueDisc::DropEarly (Ptr<QueueDiscItem> item, uint32_t qSize) | 207 bool PiQueueDisc::DropEarly (Ptr<QueueDiscItem> item, uint32_t qSize) |
212 { | 208 { |
213 NS_LOG_FUNCTION (this << item << qSize); | 209 NS_LOG_FUNCTION (this << item << qSize); |
214 | 210 |
215 double p = m_dropProb; | 211 double p = m_dropProb; |
216 bool earlyDrop = true; | 212 bool earlyDrop = true; |
217 | 213 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 return false; | 322 return false; |
327 } | 323 } |
328 | 324 |
329 if ((GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_PACKETS && m_mo
de == QUEUE_DISC_MODE_BYTES) | 325 if ((GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_PACKETS && m_mo
de == QUEUE_DISC_MODE_BYTES) |
330 || (GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_BYTES && m_m
ode == QUEUE_DISC_MODE_PACKETS)) | 326 || (GetInternalQueue (0)->GetMode () == QueueBase::QUEUE_MODE_BYTES && m_m
ode == QUEUE_DISC_MODE_PACKETS)) |
331 { | 327 { |
332 NS_LOG_ERROR ("The mode of the provided queue does not match the mode set
on the PiQueueDisc"); | 328 NS_LOG_ERROR ("The mode of the provided queue does not match the mode set
on the PiQueueDisc"); |
333 return false; | 329 return false; |
334 } | 330 } |
335 | 331 |
336 if ((m_mode == QUEUE_DISC_MODE_PACKETS && GetInternalQueue (0)->GetMaxPackets
() < m_queueLimit) | 332 if ((m_mode == QUEUE_DISC_MODE_PACKETS && GetInternalQueue (0)->GetMaxPackets
() != m_queueLimit) |
337 || (m_mode == QUEUE_DISC_MODE_BYTES && GetInternalQueue (0)->GetMaxBytes
() < m_queueLimit)) | 333 || (m_mode == QUEUE_DISC_MODE_BYTES && GetInternalQueue (0)->GetMaxBytes
() != m_queueLimit)) |
338 { | 334 { |
339 NS_LOG_ERROR ("The size of the internal queue is less than the queue disc
limit"); | 335 NS_LOG_ERROR ("The size of the internal queue differs from the queue disc
limit"); |
340 return false; | 336 return false; |
341 } | 337 } |
342 | 338 |
343 return true; | 339 return true; |
344 } | 340 } |
345 | 341 |
346 } //namespace ns3 | 342 } //namespace ns3 |
LEFT | RIGHT |