Commit 0dca51d3 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[PKT_SCHED] netem: allow random reordering (with fix)

Here is a fixed up version of the reorder feature of netem.
It is the same as the earlier patch plus with the bugfix from Julio merged in.
Has expected backwards compatibility behaviour.

Go ahead and merge this one, the TCP strangeness I was seeing was due
to the reordering bug, and previous version of TSO patch.
Signed-off-by: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0f9f32ac
...@@ -427,6 +427,7 @@ enum ...@@ -427,6 +427,7 @@ enum
TCA_NETEM_UNSPEC, TCA_NETEM_UNSPEC,
TCA_NETEM_CORR, TCA_NETEM_CORR,
TCA_NETEM_DELAY_DIST, TCA_NETEM_DELAY_DIST,
TCA_NETEM_REORDER,
__TCA_NETEM_MAX, __TCA_NETEM_MAX,
}; };
...@@ -437,7 +438,7 @@ struct tc_netem_qopt ...@@ -437,7 +438,7 @@ struct tc_netem_qopt
__u32 latency; /* added delay (us) */ __u32 latency; /* added delay (us) */
__u32 limit; /* fifo limit (packets) */ __u32 limit; /* fifo limit (packets) */
__u32 loss; /* random packet loss (0=none ~0=100%) */ __u32 loss; /* random packet loss (0=none ~0=100%) */
__u32 gap; /* re-ordering gap (0 for delay all) */ __u32 gap; /* re-ordering gap (0 for none) */
__u32 duplicate; /* random packet dup (0=none ~0=100%) */ __u32 duplicate; /* random packet dup (0=none ~0=100%) */
__u32 jitter; /* random jitter in latency (us) */ __u32 jitter; /* random jitter in latency (us) */
}; };
...@@ -449,6 +450,12 @@ struct tc_netem_corr ...@@ -449,6 +450,12 @@ struct tc_netem_corr
__u32 dup_corr; /* duplicate correlation */ __u32 dup_corr; /* duplicate correlation */
}; };
struct tc_netem_reorder
{
__u32 probability;
__u32 correlation;
};
#define NETEM_DIST_SCALE 8192 #define NETEM_DIST_SCALE 8192
#endif #endif
...@@ -62,11 +62,12 @@ struct netem_sched_data { ...@@ -62,11 +62,12 @@ struct netem_sched_data {
u32 gap; u32 gap;
u32 jitter; u32 jitter;
u32 duplicate; u32 duplicate;
u32 reorder;
struct crndstate { struct crndstate {
unsigned long last; unsigned long last;
unsigned long rho; unsigned long rho;
} delay_cor, loss_cor, dup_cor; } delay_cor, loss_cor, dup_cor, reorder_cor;
struct disttable { struct disttable {
u32 size; u32 size;
...@@ -180,23 +181,23 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch) ...@@ -180,23 +181,23 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
q->duplicate = dupsave; q->duplicate = dupsave;
} }
/* if (q->gap == 0 /* not doing reordering */
* Do re-ordering by putting one out of N packets at the front || q->counter < q->gap /* inside last reordering gap */
* of the queue. || q->reorder < get_crandom(&q->reorder_cor)) {
* gap == 0 is special case for no-reordering.
*/
if (q->gap == 0 || q->counter != q->gap) {
psched_time_t now; psched_time_t now;
PSCHED_GET_TIME(now); PSCHED_GET_TIME(now);
PSCHED_TADD2(now, PSCHED_TADD2(now, tabledist(q->latency, q->jitter,
tabledist(q->latency, q->jitter, &q->delay_cor, q->delay_dist), &q->delay_cor, q->delay_dist),
cb->time_to_send); cb->time_to_send);
++q->counter; ++q->counter;
ret = q->qdisc->enqueue(skb, q->qdisc); ret = q->qdisc->enqueue(skb, q->qdisc);
} else { } else {
q->counter = 0; /*
* Do re-ordering by putting one out of N packets at the front
* of the queue.
*/
PSCHED_GET_TIME(cb->time_to_send); PSCHED_GET_TIME(cb->time_to_send);
q->counter = 0;
ret = q->qdisc->ops->requeue(skb, q->qdisc); ret = q->qdisc->ops->requeue(skb, q->qdisc);
} }
...@@ -351,6 +352,19 @@ static int get_correlation(struct Qdisc *sch, const struct rtattr *attr) ...@@ -351,6 +352,19 @@ static int get_correlation(struct Qdisc *sch, const struct rtattr *attr)
return 0; return 0;
} }
static int get_reorder(struct Qdisc *sch, const struct rtattr *attr)
{
struct netem_sched_data *q = qdisc_priv(sch);
const struct tc_netem_reorder *r = RTA_DATA(attr);
if (RTA_PAYLOAD(attr) != sizeof(*r))
return -EINVAL;
q->reorder = r->probability;
init_crandom(&q->reorder_cor, r->correlation);
return 0;
}
static int netem_change(struct Qdisc *sch, struct rtattr *opt) static int netem_change(struct Qdisc *sch, struct rtattr *opt)
{ {
struct netem_sched_data *q = qdisc_priv(sch); struct netem_sched_data *q = qdisc_priv(sch);
...@@ -371,9 +385,15 @@ static int netem_change(struct Qdisc *sch, struct rtattr *opt) ...@@ -371,9 +385,15 @@ static int netem_change(struct Qdisc *sch, struct rtattr *opt)
q->jitter = qopt->jitter; q->jitter = qopt->jitter;
q->limit = qopt->limit; q->limit = qopt->limit;
q->gap = qopt->gap; q->gap = qopt->gap;
q->counter = 0;
q->loss = qopt->loss; q->loss = qopt->loss;
q->duplicate = qopt->duplicate; q->duplicate = qopt->duplicate;
/* for compatiablity with earlier versions.
* if gap is set, need to assume 100% probablity
*/
q->reorder = ~0;
/* Handle nested options after initial queue options. /* Handle nested options after initial queue options.
* Should have put all options in nested format but too late now. * Should have put all options in nested format but too late now.
*/ */
...@@ -395,6 +415,11 @@ static int netem_change(struct Qdisc *sch, struct rtattr *opt) ...@@ -395,6 +415,11 @@ static int netem_change(struct Qdisc *sch, struct rtattr *opt)
if (ret) if (ret)
return ret; return ret;
} }
if (tb[TCA_NETEM_REORDER-1]) {
ret = get_reorder(sch, tb[TCA_NETEM_REORDER-1]);
if (ret)
return ret;
}
} }
...@@ -412,7 +437,6 @@ static int netem_init(struct Qdisc *sch, struct rtattr *opt) ...@@ -412,7 +437,6 @@ static int netem_init(struct Qdisc *sch, struct rtattr *opt)
init_timer(&q->timer); init_timer(&q->timer);
q->timer.function = netem_watchdog; q->timer.function = netem_watchdog;
q->timer.data = (unsigned long) sch; q->timer.data = (unsigned long) sch;
q->counter = 0;
q->qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops); q->qdisc = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops);
if (!q->qdisc) { if (!q->qdisc) {
...@@ -444,6 +468,7 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -444,6 +468,7 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
struct rtattr *rta = (struct rtattr *) b; struct rtattr *rta = (struct rtattr *) b;
struct tc_netem_qopt qopt; struct tc_netem_qopt qopt;
struct tc_netem_corr cor; struct tc_netem_corr cor;
struct tc_netem_reorder reorder;
qopt.latency = q->latency; qopt.latency = q->latency;
qopt.jitter = q->jitter; qopt.jitter = q->jitter;
...@@ -457,6 +482,11 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -457,6 +482,11 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
cor.loss_corr = q->loss_cor.rho; cor.loss_corr = q->loss_cor.rho;
cor.dup_corr = q->dup_cor.rho; cor.dup_corr = q->dup_cor.rho;
RTA_PUT(skb, TCA_NETEM_CORR, sizeof(cor), &cor); RTA_PUT(skb, TCA_NETEM_CORR, sizeof(cor), &cor);
reorder.probability = q->reorder;
reorder.correlation = q->reorder_cor.rho;
RTA_PUT(skb, TCA_NETEM_REORDER, sizeof(reorder), &reorder);
rta->rta_len = skb->tail - b; rta->rta_len = skb->tail - b;
return skb->len; return skb->len;
......
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