Commit 836af83b authored by Dave Taht's avatar Dave Taht Committed by David S. Miller

netem: support delivering packets in delayed time slots

Slotting is a crude approximation of the behaviors of shared media such
as cable, wifi, and LTE, which gather up a bunch of packets within a
varying delay window and deliver them, relative to that, nearly all at
once.

It works within the existing loss, duplication, jitter and delay
parameters of netem. Some amount of inherent latency must be specified,
regardless.

The new "slot" parameter specifies a minimum and maximum delay between
transmission attempts.

The "bytes" and "packets" parameters can be used to limit the amount of
information transferred per slot.

Examples of use:

tc qdisc add dev eth0 root netem delay 200us \
         slot 800us 10ms bytes 64k packets 42

A more correct example, using stacked netem instances and a packet limit
to emulate a tail drop wifi queue with slots and variable packet
delivery, with a 200Mbit isochronous underlying rate, and 20ms path
delay:

tc qdisc add dev eth0 root handle 1: netem delay 20ms rate 200mbit \
         limit 10000
tc qdisc add dev eth0 parent 1:1 handle 10:1 netem delay 200us \
         slot 800us 10ms bytes 64k packets 42 limit 512
Signed-off-by: default avatarDave Taht <dave.taht@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 99803171
...@@ -539,6 +539,7 @@ enum { ...@@ -539,6 +539,7 @@ enum {
TCA_NETEM_PAD, TCA_NETEM_PAD,
TCA_NETEM_LATENCY64, TCA_NETEM_LATENCY64,
TCA_NETEM_JITTER64, TCA_NETEM_JITTER64,
TCA_NETEM_SLOT,
__TCA_NETEM_MAX, __TCA_NETEM_MAX,
}; };
...@@ -576,6 +577,13 @@ struct tc_netem_rate { ...@@ -576,6 +577,13 @@ struct tc_netem_rate {
__s32 cell_overhead; __s32 cell_overhead;
}; };
struct tc_netem_slot {
__s64 min_delay; /* nsec */
__s64 max_delay;
__s32 max_packets;
__s32 max_bytes;
};
enum { enum {
NETEM_LOSS_UNSPEC, NETEM_LOSS_UNSPEC,
NETEM_LOSS_GI, /* General Intuitive - 4 state model */ NETEM_LOSS_GI, /* General Intuitive - 4 state model */
......
...@@ -135,6 +135,13 @@ struct netem_sched_data { ...@@ -135,6 +135,13 @@ struct netem_sched_data {
u32 a5; /* p23 used only in 4-states */ u32 a5; /* p23 used only in 4-states */
} clg; } clg;
struct tc_netem_slot slot_config;
struct slotstate {
u64 slot_next;
s32 packets_left;
s32 bytes_left;
} slot;
}; };
/* Time stamp put into socket buffer control block /* Time stamp put into socket buffer control block
...@@ -591,6 +598,20 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch, ...@@ -591,6 +598,20 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
return NET_XMIT_SUCCESS; return NET_XMIT_SUCCESS;
} }
/* Delay the next round with a new future slot with a
* correct number of bytes and packets.
*/
static void get_slot_next(struct netem_sched_data *q, u64 now)
{
q->slot.slot_next = now + q->slot_config.min_delay +
(prandom_u32() *
(q->slot_config.max_delay -
q->slot_config.min_delay) >> 32);
q->slot.packets_left = q->slot_config.max_packets;
q->slot.bytes_left = q->slot_config.max_bytes;
}
static struct sk_buff *netem_dequeue(struct Qdisc *sch) static struct sk_buff *netem_dequeue(struct Qdisc *sch)
{ {
struct netem_sched_data *q = qdisc_priv(sch); struct netem_sched_data *q = qdisc_priv(sch);
...@@ -608,14 +629,17 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch) ...@@ -608,14 +629,17 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
p = rb_first(&q->t_root); p = rb_first(&q->t_root);
if (p) { if (p) {
u64 time_to_send; u64 time_to_send;
u64 now = ktime_get_ns();
skb = rb_to_skb(p); skb = rb_to_skb(p);
/* if more time remaining? */ /* if more time remaining? */
time_to_send = netem_skb_cb(skb)->time_to_send; time_to_send = netem_skb_cb(skb)->time_to_send;
if (time_to_send <= ktime_get_ns()) { if (q->slot.slot_next && q->slot.slot_next < time_to_send)
rb_erase(p, &q->t_root); get_slot_next(q, now);
if (time_to_send <= now && q->slot.slot_next <= now) {
rb_erase(p, &q->t_root);
sch->q.qlen--; sch->q.qlen--;
qdisc_qstats_backlog_dec(sch, skb); qdisc_qstats_backlog_dec(sch, skb);
skb->next = NULL; skb->next = NULL;
...@@ -634,6 +658,14 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch) ...@@ -634,6 +658,14 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
skb->tstamp = 0; skb->tstamp = 0;
#endif #endif
if (q->slot.slot_next) {
q->slot.packets_left--;
q->slot.bytes_left -= qdisc_pkt_len(skb);
if (q->slot.packets_left <= 0 ||
q->slot.bytes_left <= 0)
get_slot_next(q, now);
}
if (q->qdisc) { if (q->qdisc) {
unsigned int pkt_len = qdisc_pkt_len(skb); unsigned int pkt_len = qdisc_pkt_len(skb);
struct sk_buff *to_free = NULL; struct sk_buff *to_free = NULL;
...@@ -657,7 +689,10 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch) ...@@ -657,7 +689,10 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
if (skb) if (skb)
goto deliver; goto deliver;
} }
qdisc_watchdog_schedule_ns(&q->watchdog, time_to_send);
qdisc_watchdog_schedule_ns(&q->watchdog,
max(time_to_send,
q->slot.slot_next));
} }
if (q->qdisc) { if (q->qdisc) {
...@@ -688,6 +723,7 @@ static void dist_free(struct disttable *d) ...@@ -688,6 +723,7 @@ static void dist_free(struct disttable *d)
* Distribution data is a variable size payload containing * Distribution data is a variable size payload containing
* signed 16 bit values. * signed 16 bit values.
*/ */
static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr) static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
{ {
struct netem_sched_data *q = qdisc_priv(sch); struct netem_sched_data *q = qdisc_priv(sch);
...@@ -718,6 +754,23 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr) ...@@ -718,6 +754,23 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
return 0; return 0;
} }
static void get_slot(struct netem_sched_data *q, const struct nlattr *attr)
{
const struct tc_netem_slot *c = nla_data(attr);
q->slot_config = *c;
if (q->slot_config.max_packets == 0)
q->slot_config.max_packets = INT_MAX;
if (q->slot_config.max_bytes == 0)
q->slot_config.max_bytes = INT_MAX;
q->slot.packets_left = q->slot_config.max_packets;
q->slot.bytes_left = q->slot_config.max_bytes;
if (q->slot_config.min_delay | q->slot_config.max_delay)
q->slot.slot_next = ktime_get_ns();
else
q->slot.slot_next = 0;
}
static void get_correlation(struct netem_sched_data *q, const struct nlattr *attr) static void get_correlation(struct netem_sched_data *q, const struct nlattr *attr)
{ {
const struct tc_netem_corr *c = nla_data(attr); const struct tc_netem_corr *c = nla_data(attr);
...@@ -821,6 +874,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = { ...@@ -821,6 +874,7 @@ static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
[TCA_NETEM_RATE64] = { .type = NLA_U64 }, [TCA_NETEM_RATE64] = { .type = NLA_U64 },
[TCA_NETEM_LATENCY64] = { .type = NLA_S64 }, [TCA_NETEM_LATENCY64] = { .type = NLA_S64 },
[TCA_NETEM_JITTER64] = { .type = NLA_S64 }, [TCA_NETEM_JITTER64] = { .type = NLA_S64 },
[TCA_NETEM_SLOT] = { .len = sizeof(struct tc_netem_slot) },
}; };
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
...@@ -927,6 +981,9 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt) ...@@ -927,6 +981,9 @@ static int netem_change(struct Qdisc *sch, struct nlattr *opt)
if (tb[TCA_NETEM_ECN]) if (tb[TCA_NETEM_ECN])
q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]); q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]);
if (tb[TCA_NETEM_SLOT])
get_slot(q, tb[TCA_NETEM_SLOT]);
return ret; return ret;
} }
...@@ -1016,6 +1073,7 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -1016,6 +1073,7 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
struct tc_netem_reorder reorder; struct tc_netem_reorder reorder;
struct tc_netem_corrupt corrupt; struct tc_netem_corrupt corrupt;
struct tc_netem_rate rate; struct tc_netem_rate rate;
struct tc_netem_slot slot;
qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency), qopt.latency = min_t(psched_tdiff_t, PSCHED_NS2TICKS(q->latency),
UINT_MAX); UINT_MAX);
...@@ -1070,6 +1128,16 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -1070,6 +1128,16 @@ static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
if (dump_loss_model(q, skb) != 0) if (dump_loss_model(q, skb) != 0)
goto nla_put_failure; goto nla_put_failure;
if (q->slot_config.min_delay | q->slot_config.max_delay) {
slot = q->slot_config;
if (slot.max_packets == INT_MAX)
slot.max_packets = 0;
if (slot.max_bytes == INT_MAX)
slot.max_bytes = 0;
if (nla_put(skb, TCA_NETEM_SLOT, sizeof(slot), &slot))
goto nla_put_failure;
}
return nla_nest_end(skb, nla); return nla_nest_end(skb, nla);
nla_put_failure: nla_put_failure:
......
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