diff options
author | Yang Yingliang <yangyingliang@huawei.com> | 2014-01-18 05:13:31 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-19 20:17:34 -0500 |
commit | a6e2fe17eba47681e82cdb9cfed5a67b57802a78 (patch) | |
tree | c70aefc7a1b0de525e21908c31ae6ec123091a5c /net/sched/sch_netem.c | |
parent | 6444f72b4b74f627c51891101e93ba2b94078b0a (diff) |
sch_netem: replace magic numbers with enumerate
Replace some magic numbers which describe states of 4-state model
loss generator with enumerate.
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/sch_netem.c')
-rw-r--r-- | net/sched/sch_netem.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 3019c10d6c56..a2bfc371b44a 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c | |||
@@ -110,6 +110,13 @@ struct netem_sched_data { | |||
110 | CLG_GILB_ELL, | 110 | CLG_GILB_ELL, |
111 | } loss_model; | 111 | } loss_model; |
112 | 112 | ||
113 | enum { | ||
114 | TX_IN_GAP_PERIOD = 1, | ||
115 | TX_IN_BURST_PERIOD, | ||
116 | LOST_IN_GAP_PERIOD, | ||
117 | LOST_IN_BURST_PERIOD, | ||
118 | } _4_state_model; | ||
119 | |||
113 | /* Correlated Loss Generation models */ | 120 | /* Correlated Loss Generation models */ |
114 | struct clgstate { | 121 | struct clgstate { |
115 | /* state of the Markov chain */ | 122 | /* state of the Markov chain */ |
@@ -205,43 +212,45 @@ static bool loss_4state(struct netem_sched_data *q) | |||
205 | * probabilities outgoing from the current state, then decides the | 212 | * probabilities outgoing from the current state, then decides the |
206 | * next state and if the next packet has to be transmitted or lost. | 213 | * next state and if the next packet has to be transmitted or lost. |
207 | * The four states correspond to: | 214 | * The four states correspond to: |
208 | * 1 => successfully transmitted packets within a gap period | 215 | * TX_IN_GAP_PERIOD => successfully transmitted packets within a gap period |
209 | * 4 => isolated losses within a gap period | 216 | * LOST_IN_BURST_PERIOD => isolated losses within a gap period |
210 | * 3 => lost packets within a burst period | 217 | * LOST_IN_GAP_PERIOD => lost packets within a burst period |
211 | * 2 => successfully transmitted packets within a burst period | 218 | * TX_IN_GAP_PERIOD => successfully transmitted packets within a burst period |
212 | */ | 219 | */ |
213 | switch (clg->state) { | 220 | switch (clg->state) { |
214 | case 1: | 221 | case TX_IN_GAP_PERIOD: |
215 | if (rnd < clg->a4) { | 222 | if (rnd < clg->a4) { |
216 | clg->state = 4; | 223 | clg->state = LOST_IN_BURST_PERIOD; |
217 | return true; | 224 | return true; |
218 | } else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) { | 225 | } else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) { |
219 | clg->state = 3; | 226 | clg->state = LOST_IN_GAP_PERIOD; |
220 | return true; | 227 | return true; |
221 | } else if (clg->a1 + clg->a4 < rnd) | 228 | } else if (clg->a1 + clg->a4 < rnd) { |
222 | clg->state = 1; | 229 | clg->state = TX_IN_GAP_PERIOD; |
230 | } | ||
223 | 231 | ||
224 | break; | 232 | break; |
225 | case 2: | 233 | case TX_IN_BURST_PERIOD: |
226 | if (rnd < clg->a5) { | 234 | if (rnd < clg->a5) { |
227 | clg->state = 3; | 235 | clg->state = LOST_IN_GAP_PERIOD; |
228 | return true; | 236 | return true; |
229 | } else | 237 | } else { |
230 | clg->state = 2; | 238 | clg->state = TX_IN_BURST_PERIOD; |
239 | } | ||
231 | 240 | ||
232 | break; | 241 | break; |
233 | case 3: | 242 | case LOST_IN_GAP_PERIOD: |
234 | if (rnd < clg->a3) | 243 | if (rnd < clg->a3) |
235 | clg->state = 2; | 244 | clg->state = TX_IN_BURST_PERIOD; |
236 | else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { | 245 | else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { |
237 | clg->state = 1; | 246 | clg->state = TX_IN_GAP_PERIOD; |
238 | } else if (clg->a2 + clg->a3 < rnd) { | 247 | } else if (clg->a2 + clg->a3 < rnd) { |
239 | clg->state = 3; | 248 | clg->state = LOST_IN_GAP_PERIOD; |
240 | return true; | 249 | return true; |
241 | } | 250 | } |
242 | break; | 251 | break; |
243 | case 4: | 252 | case LOST_IN_BURST_PERIOD: |
244 | clg->state = 1; | 253 | clg->state = TX_IN_GAP_PERIOD; |
245 | break; | 254 | break; |
246 | } | 255 | } |
247 | 256 | ||