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 * This code was ported from NS-2.34, with licence: | 3 * This code was ported from NS-2.34, with licence: |
4 * | 4 * |
5 * Copyright (c) 1990-1997 Regents of the University of California. | 5 * Copyright (c) 1990-1997 Regents of the University of California. |
6 * All rights reserved. | 6 * All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 16 matching lines...) Expand all Loading... |
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 * SUCH DAMAGE. | 34 * SUCH DAMAGE. |
35 * | 35 * |
36 * | 36 * |
37 * This port: Copyright © 2011 Marcos Talau (talau@users.sourceforge.net) | 37 * This port: |
| 38 * |
| 39 * Copyright © 2011 Marcos Talau |
38 * | 40 * |
39 * This program is free software: you can redistribute it and/or modify | 41 * This program is free software: you can redistribute it and/or modify |
40 * it under the terms of the GNU General Public License as published by | 42 * it under the terms of the GNU General Public License as published by |
41 * the Free Software Foundation, either version 3 of the License, or | 43 * the Free Software Foundation, either version 3 of the License, or |
42 * (at your option) any later version. | 44 * (at your option) any later version. |
43 * | 45 * |
44 * This program is distributed in the hope that it will be useful, | 46 * This program is distributed in the hope that it will be useful, |
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 47 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
47 * GNU General Public License for more details. | 49 * GNU General Public License for more details. |
48 * | 50 * |
49 * You should have received a copy of the GNU General Public License | 51 * You should have received a copy of the GNU General Public License |
50 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 52 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
51 * | 53 * |
| 54 * Author: Marcos Talau (talau@users.sourceforge.net) |
| 55 * |
52 * Thanks to: Duy Nguyen<duy@soe.ucsc.edu> by RED efforts in NS3 | 56 * Thanks to: Duy Nguyen<duy@soe.ucsc.edu> by RED efforts in NS3 |
53 * | 57 * |
| 58 */ |
| 59 |
| 60 /* |
| 61 * PORT NOTE: Almost all comments also been ported from NS-2 |
54 */ | 62 */ |
55 | 63 |
56 #ifndef RED_QUEUE_H | 64 #ifndef RED_QUEUE_H |
57 #define RED_QUEUE_H | 65 #define RED_QUEUE_H |
58 | 66 |
59 #include <queue> | 67 #include <queue> |
60 #include "ns3/packet.h" | 68 #include "ns3/packet.h" |
61 #include "ns3/queue.h" | 69 #include "ns3/queue.h" |
62 #include "ns3/nstime.h" | 70 #include "ns3/nstime.h" |
63 #include "ns3/random-variable.h" | 71 #include "ns3/random-variable.h" |
64 #include "ns3/boolean.h" | 72 #include "ns3/boolean.h" |
65 #include "ns3/data-rate.h" | 73 #include "ns3/data-rate.h" |
66 #include "ns3/nstime.h" | 74 #include "ns3/nstime.h" |
67 | 75 |
68 namespace ns3 { | 76 namespace ns3 { |
69 | 77 |
70 class TraceContainer; | 78 class TraceContainer; |
71 | 79 |
72 /** | 80 /* |
73 * \ingroup queue | 81 * \ingroup queue |
74 * | 82 * |
75 * \brief A RED packet queue | 83 * \brief A RED packet queue |
76 */ | 84 */ |
77 class RedQueue : public Queue | 85 class RedQueue : public Queue |
78 { | 86 { |
79 public: | 87 public: |
80 static TypeId GetTypeId (void); | 88 static TypeId GetTypeId (void); |
81 /** | 89 /* |
82 * \brief RedQueue Constructor | 90 * \brief RedQueue Constructor |
83 * | 91 * |
84 * Create a RED queue | 92 * Create a RED queue |
85 */ | 93 */ |
86 RedQueue (); | 94 RedQueue (); |
87 | 95 |
88 virtual ~RedQueue (); | 96 virtual ~RedQueue (); |
89 | 97 |
90 typedef struct | 98 typedef struct |
91 { | 99 { |
92 uint32_t unforcedDrop; ///< Early probability drops | 100 // Early probability drops |
93 uint32_t forcedDrop; ///< Forced drops, qavg > max threshold | 101 uint32_t unforcedDrop; |
94 uint32_t pdrop; ///< Drops due to queue limits | 102 // Forced drops, qavg > max threshold |
| 103 uint32_t forcedDrop; |
| 104 // Drops due to queue limits |
| 105 uint32_t qLimDrop; |
95 } Stats; | 106 } Stats; |
96 | 107 |
97 // Drop types | 108 // Drop types |
98 enum | 109 enum |
99 { | 110 { |
100 DTYPE_NONE, /* ok, no drop */ | 111 DTYPE_NONE, // Ok, no drop |
101 DTYPE_FORCED, /* a "forced" drop */ | 112 DTYPE_FORCED, // A "forced" drop |
102 DTYPE_UNFORCED, /* an "unforced" (random) drop */ | 113 DTYPE_UNFORCED, // An "unforced" (random) drop |
103 }; | 114 }; |
104 | 115 |
105 /** | 116 /* |
106 * Enumeration of the modes supported in the class. | 117 * Enumeration of the modes supported in the class. |
107 * | 118 * |
108 */ | 119 */ |
109 enum Mode | 120 enum Mode |
110 { | 121 { |
111 ILLEGAL, /**< Mode not set */ | 122 ILLEGAL, // Mode not set |
112 PACKETS, /**< Use number of packets for maximum queue size */ | 123 PACKETS, // Use number of packets for maximum queue size |
113 BYTES, /**< Use number of bytes for maximum queue size */ | 124 BYTES, // Use number of bytes for maximum queue size |
114 }; | 125 }; |
115 | 126 |
116 /** | 127 /* |
117 * Set the operating mode of this device. | 128 * Set the operating mode of this device. |
118 * | 129 * |
119 * \param mode The operating mode of this device. | 130 * \param mode The operating mode of this device. |
120 */ | 131 */ |
121 void SetMode (RedQueue::Mode mode); | 132 void SetMode (RedQueue::Mode mode); |
122 | 133 |
123 /** | 134 /* |
124 * Get the encapsulation mode of this device. | 135 * Get the encapsulation mode of this device. |
125 * | 136 * |
126 * \returns The encapsulation mode of this device. | 137 * \returns The encapsulation mode of this device. |
127 */ | 138 */ |
128 RedQueue::Mode GetMode (void); | 139 RedQueue::Mode GetMode (void); |
129 | 140 |
130 /** | 141 /* |
131 * Get the current value of the queue in bytes or packets. | 142 * Get the current value of the queue in bytes or packets. |
132 * | 143 * |
133 * \returns The queue size in bytes or packets. | 144 * \returns The queue size in bytes or packets. |
134 */ | 145 */ |
135 uint32_t GetQueueSize (void); | 146 uint32_t GetQueueSize (void); |
136 | 147 |
137 /** | 148 /* |
138 * Set the limit of the queue. | 149 * Set the limit of the queue. |
139 * | 150 * |
140 * \param lim The limit in bytes or packets. | 151 * \param lim The limit in bytes or packets. |
141 */ | 152 */ |
142 void SetQueueLimit(uint32_t lim); | 153 void SetQueueLimit(uint32_t lim); |
143 | 154 |
144 /** | 155 /* |
145 * Set the thresh limits of RED. | 156 * Set the thresh limits of RED. |
146 * | 157 * |
147 * \param min Minimum thresh in bytes or packets. | 158 * \param min Minimum thresh in bytes or packets. |
148 * \param max Maximum thresh in bytes or packets. | 159 * \param max Maximum thresh in bytes or packets. |
149 */ | 160 */ |
150 void SetTh(double min, double max); | 161 void SetTh(double minTh, double maxTh); |
151 | 162 |
152 /** | 163 /* |
153 * Get the RED statistics after running. | 164 * Get the RED statistics after running. |
154 * | 165 * |
155 * \returns The drop statistics. | 166 * \returns The drop statistics. |
156 */ | 167 */ |
157 Stats GetStats(); | 168 Stats GetStats(); |
158 | 169 |
159 private: | 170 private: |
160 virtual bool DoEnqueue (Ptr<Packet> p); | 171 virtual bool DoEnqueue (Ptr<Packet> p); |
161 virtual Ptr<Packet> DoDequeue (void); | 172 virtual Ptr<Packet> DoDequeue (void); |
162 virtual Ptr<const Packet> DoPeek (void) const; | 173 virtual Ptr<const Packet> DoPeek (void) const; |
163 | 174 |
| 175 // ... |
164 void InitializeParams (void); | 176 void InitializeParams (void); |
| 177 // Compute the average queue size |
165 double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW); | 178 double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW); |
| 179 // Check if packet p needs to be dropped due to probability mark |
166 uint32_t DropEarly (Ptr<Packet> p, uint32_t qSize); | 180 uint32_t DropEarly (Ptr<Packet> p, uint32_t qSize); |
| 181 // Returns a probability using these function parameters for the DropEarly fun
tion |
167 double CalculatePNew (double qAvg, double maxTh, bool gentle, double vA, | 182 double CalculatePNew (double qAvg, double maxTh, bool gentle, double vA, |
168 double vB, double vC, double vD, double maxP); | 183 double vB, double vC, double vD, double maxP); |
| 184 // Returns a probability using these function parameters for the DropEarly fun
tion |
169 double ModifyP(double p, uint32_t count, uint32_t countBytes, | 185 double ModifyP(double p, uint32_t count, uint32_t countBytes, |
170 uint32_t meanPktSize, bool wait, uint32_t size); | 186 uint32_t meanPktSize, bool wait, uint32_t size); |
171 | 187 |
172 std::list<Ptr<Packet> > m_packets; | 188 std::list<Ptr<Packet> > m_packets; |
173 | 189 |
174 uint32_t m_bytesInQueue; | 190 uint32_t m_bytesInQueue; |
175 bool m_redParams; | 191 bool m_hasRedStarted; |
176 Stats m_stats; | 192 Stats m_stats; |
177 | 193 |
178 //** variables supplied by user | 194 // ** Variables supplied by user |
179 // bytes or packets? | 195 // Bytes or packets? |
180 Mode m_mode; | 196 Mode m_mode; |
181 /* avg pkt size */ | 197 // Avg pkt size |
182 uint32_t m_meanPktSize; | 198 uint32_t m_meanPktSize; |
183 /* avg pkt size used during idle times */ | 199 // Avg pkt size used during idle times |
184 uint32_t m_idlePktSize; | 200 uint32_t m_idlePktSize; |
185 /* true for waiting between dropped packets */ | 201 // True for waiting between dropped packets |
186 bool m_wait; | 202 bool m_isWait; |
187 /* true to increases dropping prob. slowly * | 203 // True to increases dropping prob. slowly when ave queue exceeds maxthresh |
188 * when ave queue exceeds maxthresh. */ | 204 bool m_isGentle; |
189 bool m_gentle; | 205 // Min avg length threshold (bytes) |
190 double m_minTh; ///> Min avg length threshold (bytes), should be >= 2*minTh | 206 double m_minTh; |
191 double m_maxTh; ///> Max avg length threshold (bytes), should be >= 2*minTh | 207 // Max avg length threshold (bytes), should be >= 2*minTh |
192 // queue limit in bytes / packets | 208 double m_maxTh; |
| 209 // Queue limit in bytes / packets |
193 uint32_t m_queueLimit; | 210 uint32_t m_queueLimit; |
194 /* queue weight given to cur q size sample */ | 211 // Queue weight given to cur q size sample |
195 double m_qW; | 212 double m_qW; |
196 // The max probability of dropping a packet | 213 // The max probability of dropping a packet |
197 double m_lInterm; | 214 double m_lInterm; |
198 // ns-1 compatibility | 215 // Ns-1 compatibility |
199 bool m_ns1Compat; | 216 bool m_isNs1Compat; |
200 // link bandwidth | 217 // Link bandwidth |
201 DataRate m_linkBandwidth; | 218 DataRate m_linkBandwidth; |
202 // link delay | 219 // Link delay |
203 Time m_linkDelay; | 220 Time m_linkDelay; |
204 | 221 |
205 //** variables maintained by RED | 222 // ** Variables maintained by RED |
206 /* prob. of packet drop before "count". */ | 223 // Prob. of packet drop before "count" |
207 double m_vProb1; | 224 double m_vProb1; |
208 double m_vA;» » /* v_prob = v_a * v_ave + v_b */ | 225 // v_prob = v_a * v_ave + v_b |
| 226 double m_vA; |
209 double m_vB; | 227 double m_vB; |
210 double m_vC;» » /* used for "gentle" mode */ | 228 // Used for "gentle" mode |
211 double m_vD;» » /* used for "gentle" mode */ | 229 double m_vC; |
212 // current max_p | 230 // Used for "gentle" mode |
| 231 double m_vD; |
| 232 // Current max_p |
213 double m_curMaxP; | 233 double m_curMaxP; |
214 /* prob. of packet drop */ | 234 // Prob. of packet drop |
215 double m_vProb; | 235 double m_vProb; |
216 /* # of bytes since last drop */ | 236 // # of bytes since last drop |
217 uint32_t m_countBytes; | 237 uint32_t m_countBytes; |
218 /* 0 when average queue first exceeds thresh */ | 238 // 0 when average queue first exceeds thresh |
219 uint32_t m_old; | 239 uint32_t m_old; |
220 uint32_t m_idle; // 0/1 idle status | 240 // 0/1 idle status |
221 /* packet time constant in packets/second */ | 241 uint32_t m_idle; |
| 242 // packet time constant in packets/second |
222 double m_ptc; | 243 double m_ptc; |
223 double m_qAvg; ///> average q length; is double.. | 244 // Average queue length |
224 uint32_t m_count; ///> number of packets since last random number generation | 245 double m_qAvg; |
225 /* 0 for default RED */ | 246 // number of packets since last random number generation |
226 /* 1 for not dropping/marking when the */ | 247 uint32_t m_count; |
227 /* instantaneous queue is much below the */ | 248 /* |
228 /* average */ | 249 * 0 for default RED |
| 250 * 1 experimental (see red-queue.cc) |
| 251 * 2 experimental (see red-queue.cc) |
| 252 * 3 use Idle packet size in the ptc |
| 253 */ |
229 uint32_t m_cautious; | 254 uint32_t m_cautious; |
230 double m_minPacketsTh; /* always maintained in packets */ | 255 // Start of current idle period |
231 double m_maxPacketsTh; /* always maintained in packets */ | 256 Time m_idleTime; |
232 Time m_idleTime; ///> start of current idle period | |
233 }; | 257 }; |
234 | 258 |
235 }; // namespace ns3 | 259 }; // namespace ns3 |
236 | 260 |
237 #endif /* RED_QUEUE_H */ | 261 #endif // RED_QUEUE_H |
LEFT | RIGHT |