Commit cb3ef7b0 authored by Harshit Mogalapalli's avatar Harshit Mogalapalli Committed by David S. Miller

net: sched: sch_netem: Refactor code in 4-state loss generator

Fixed comments to match description with variable names and
refactored code to match the convention as per [1].

To match the convention mapping is done as follows:
State 3 - LOST_IN_BURST_PERIOD
State 4 - LOST_IN_GAP_PERIOD

[1] S. Salsano, F. Ludovici, A. Ordine, "Definition of a general
and intuitive loss model for packet networks and its implementation
in the Netem module in the Linux kernel"

Fixes: a6e2fe17 ("sch_netem: replace magic numbers with enumerate")
Signed-off-by: default avatarHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Acked-by: default avatarStephen Hemminger <stephen@networkplumber.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e99fa423
...@@ -208,17 +208,17 @@ static bool loss_4state(struct netem_sched_data *q) ...@@ -208,17 +208,17 @@ static bool loss_4state(struct netem_sched_data *q)
* next state and if the next packet has to be transmitted or lost. * next state and if the next packet has to be transmitted or lost.
* The four states correspond to: * The four states correspond to:
* TX_IN_GAP_PERIOD => successfully transmitted packets within a gap period * TX_IN_GAP_PERIOD => successfully transmitted packets within a gap period
* LOST_IN_BURST_PERIOD => isolated losses within a gap period * LOST_IN_GAP_PERIOD => isolated losses within a gap period
* LOST_IN_GAP_PERIOD => lost packets within a burst period * LOST_IN_BURST_PERIOD => lost packets within a burst period
* TX_IN_GAP_PERIOD => successfully transmitted packets within a burst period * TX_IN_BURST_PERIOD => successfully transmitted packets within a burst period
*/ */
switch (clg->state) { switch (clg->state) {
case TX_IN_GAP_PERIOD: case TX_IN_GAP_PERIOD:
if (rnd < clg->a4) { if (rnd < clg->a4) {
clg->state = LOST_IN_BURST_PERIOD; clg->state = LOST_IN_GAP_PERIOD;
return true; return true;
} else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) { } else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) {
clg->state = LOST_IN_GAP_PERIOD; clg->state = LOST_IN_BURST_PERIOD;
return true; return true;
} else if (clg->a1 + clg->a4 < rnd) { } else if (clg->a1 + clg->a4 < rnd) {
clg->state = TX_IN_GAP_PERIOD; clg->state = TX_IN_GAP_PERIOD;
...@@ -227,24 +227,24 @@ static bool loss_4state(struct netem_sched_data *q) ...@@ -227,24 +227,24 @@ static bool loss_4state(struct netem_sched_data *q)
break; break;
case TX_IN_BURST_PERIOD: case TX_IN_BURST_PERIOD:
if (rnd < clg->a5) { if (rnd < clg->a5) {
clg->state = LOST_IN_GAP_PERIOD; clg->state = LOST_IN_BURST_PERIOD;
return true; return true;
} else { } else {
clg->state = TX_IN_BURST_PERIOD; clg->state = TX_IN_BURST_PERIOD;
} }
break; break;
case LOST_IN_GAP_PERIOD: case LOST_IN_BURST_PERIOD:
if (rnd < clg->a3) if (rnd < clg->a3)
clg->state = TX_IN_BURST_PERIOD; clg->state = TX_IN_BURST_PERIOD;
else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) {
clg->state = TX_IN_GAP_PERIOD; clg->state = TX_IN_GAP_PERIOD;
} else if (clg->a2 + clg->a3 < rnd) { } else if (clg->a2 + clg->a3 < rnd) {
clg->state = LOST_IN_GAP_PERIOD; clg->state = LOST_IN_BURST_PERIOD;
return true; return true;
} }
break; break;
case LOST_IN_BURST_PERIOD: case LOST_IN_GAP_PERIOD:
clg->state = TX_IN_GAP_PERIOD; clg->state = TX_IN_GAP_PERIOD;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment