Skip to contentSkip to conversation

support delivering packets in

PATCH Applied Yousuk Seung 4 participants 8 messages Aug 27, 2018 – Oct 3, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover support delivering packets in

This series adds support for the new "slot" netem parameter for slotting. Slotting is an approximation of shared media that gather up packets within a varying delay window before delivering them nearly at once.

Dave Taht (2):
tc: support conversions to or from 64 bit nanosecond-based time
q_netem: support delivering packets in delayed time slots

Yousuk Seung (1):
q_netem: slotting with non-uniform distribution

 include/utils.h     |  12 +++++
 lib/utils.c         | 104 +++++++++++++++++++++++++++++++++++++++
 man/man8/tc-netem.8 |  40 ++++++++++++++-
 tc/q_netem.c        | 115 +++++++++++++++++++++++++++++++++++++++++++-
 tc/tc_cbq.c         |   1 +
 tc/tc_core.c        |   1 +
 tc/tc_core.h        |   2 -
 tc/tc_estimator.c   |   1 +
 tc/tc_util.c        |  46 ------------------
 tc/tc_util.h        |   3 --
 10 files changed, 272 insertions(+), 53 deletions(-)
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
#1 lore raw

PATCH v2 1/3 tc: support conversions to or from 64 bit nanosecond-based time

From: Dave Taht <[email protected]>

Using a 32 bit field to represent time in nanoseconds results in a maximum value of about 4.3 seconds, which is well below many observed delays in WiFi and LTE, and barely in the ballpark for a trip past the Earth's moon, Luna.

Using 64 bit time fields in nanoseconds allows us to simulate network diameters of several hundred light-years. However, only conversions to and from ns, us, ms, and seconds are provided.

The iproute2 64 bit api uses signed values for time. Being able to represent positive or negative time allows us to calculate +/- deltas between, for example, the CLOCK_TAI and CLOCK_REALTIME clocks.

Time related utility functions in tc_util.c are moved to lib/utils.c.

---
 include/utils.h   |  12 ++++++
 lib/utils.c       | 104 ++++++++++++++++++++++++++++++++++++++++++++++
 tc/tc_cbq.c       |   1 +
 tc/tc_core.c      |   1 +
 tc/tc_core.h      |   2 -
 tc/tc_estimator.c |   1 +
 tc/tc_util.c      |  46 --------------------
 tc/tc_util.h      |   3 --
 8 files changed, 119 insertions(+), 51 deletions(-)
include/utils.h +12 -0
index 8cb4349e8a89..eba67b6ecf44 100644
@@ -46,6 +46,11 @@ void incomplete_command(void) __attribute__((noreturn));
 #define NEXT_ARG_FWD() do { argv++; argc--; } while(0)
 #define PREV_ARG() do { argv--; argc++; } while(0)
 
+#define TIME_UNITS_PER_SEC	1000000
+#define NSEC_PER_USEC 1000
+#define NSEC_PER_MSEC 1000000
+#define NSEC_PER_SEC 1000000000LL
+
 typedef struct
 {
 	__u16 flags;
@@ -310,4 +315,11 @@ size_t strlcat(char *dst, const char *src, size_t size);
 
 void drop_cap(void);
 
+int get_time(unsigned int *time, const char *str);
+int get_time64(__s64 *time, const char *str);
+void print_time(char *buf, int len, __u32 time);
+void print_time64(char *buf, int len, __s64 time);
+char *sprint_time(__u32 time, char *buf);
+char *sprint_time64(__s64 time, char *buf);
+
 #endif /* __UTILS_H__ */
lib/utils.c +104 -0

107 lines not on this page · raw message

tc/tc_cbq.c +1 -0
index 4cd584a91a26..c811456b1627 100644
@@ -20,6 +20,7 @@
 #include <arpa/inet.h>
 #include <string.h>
 
+#include "utils.h"
 #include "tc_core.h"
 #include "tc_cbq.h"
 
tc/tc_core.c +1 -0
index 1bde4d51e5dc..8eb11223eb9d 100644
@@ -21,6 +21,7 @@
 #include <arpa/inet.h>
 #include <string.h>
 
+#include "utils.h"
 #include "tc_core.h"
 #include <linux/atm.h>
 
tc/tc_core.h +0 -2
index 1dfa9a4f773b..bd4a99f0d8dd 100644
@@ -5,8 +5,6 @@
 #include <asm/types.h>
 #include <linux/pkt_sched.h>
 
-#define TIME_UNITS_PER_SEC	1000000
-
 enum link_layer {
 	LINKLAYER_UNSPEC,
 	LINKLAYER_ETHERNET,
tc/tc_estimator.c +1 -0
index e4edfc7e98d9..f494b7caa44e 100644
@@ -20,6 +20,7 @@
 #include <arpa/inet.h>
 #include <string.h>
 
+#include "utils.h"
 #include "tc_core.h"
 
 int tc_setup_estimator(unsigned int A, unsigned int time_const, struct tc_estimator *est)
tc/tc_util.c +0 -46

52 lines not on this page · raw message

tc/tc_util.h +0 -3
index 6632c4f9c528..76fd986d6e4c 100644
@@ -81,13 +81,11 @@ int get_rate64(__u64 *rate, const char *str);
 int get_percent_rate64(__u64 *rate, const char *str, const char *dev);
 int get_size(unsigned int *size, const char *str);
 int get_size_and_cell(unsigned int *size, int *cell_log, char *str);
-int get_time(unsigned int *time, const char *str);
 int get_linklayer(unsigned int *val, const char *arg);
 
 void print_rate(char *buf, int len, __u64 rate);
 void print_size(char *buf, int len, __u32 size);
 void print_qdisc_handle(char *buf, int len, __u32 h);
-void print_time(char *buf, int len, __u32 time);
 void print_linklayer(char *buf, int len, unsigned int linklayer);
 void print_devname(enum output_type type, int ifindex);
 
@@ -95,7 +93,6 @@ char *sprint_rate(__u64 rate, char *buf);
 char *sprint_size(__u32 size, char *buf);
 char *sprint_qdisc_handle(__u32 h, char *buf);
 char *sprint_tc_classid(__u32 h, char *buf);
-char *sprint_time(__u32 time, char *buf);
 char *sprint_ticks(__u32 ticks, char *buf);
 char *sprint_linklayer(unsigned int linklayer, char *buf);
 
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
#5 lore raw

PATCH v2 2/3 q_netem: support delivering packets in delayed time slots

In reply to Yousuk Seung

From: Dave Taht <[email protected]>

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
---
 man/man8/tc-netem.8 | 32 ++++++++++++++++++++++-
 tc/q_netem.c        | 64 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 94 insertions(+), 2 deletions(-)
man/man8/tc-netem.8 +31 -1
index f2cd86b6ed8a..8d485b026751 100644
@@ -8,7 +8,8 @@ NetEm \- Network Emulator
 .I OPTIONS
 
 .IR OPTIONS " := [ " LIMIT " ] [ " DELAY " ] [ " LOSS \
-" ] [ " CORRUPT " ] [ " DUPLICATION " ] [ " REORDERING " ][ " RATE " ]"
+" ] [ " CORRUPT " ] [ " DUPLICATION " ] [ " REORDERING " ] [ " RATE \
+" ] [ " SLOT " ]"
 
 .IR LIMIT " := "
 .B limit
@@ -51,6 +52,14 @@ NetEm \- Network Emulator
 .B rate
 .IR RATE " [ " PACKETOVERHEAD " [ " CELLSIZE " [ " CELLOVERHEAD " ]]]]"
 
+.IR SLOT " := "
+.BR slot
+.IR MIN_DELAY " [ " MAX_DELAY " ] ["
+.BR packets
+.IR PACKETS " ] [ "
+.BR bytes
+.IR BYTES " ]"
+
 
 .SH DESCRIPTION
 NetEm is an enhancement of the Linux traffic control facilities
@@ -162,6 +171,27 @@ granularity avoid a perfect shaping at a specific level. This will show up in
 an artificial packet compression (bursts). Another influence factor are network
 adapter buffers which can also add artificial delay.
 
+.SS slot
+defer delivering accumulated packets to within a slot, with each available slot
+configured with a minimum delay to acquire, and an optional maximum delay.  Slot
+delays can be specified in nanoseconds, microseconds, milliseconds or seconds
+(e.g. 800us). Values for the optional parameters
+.I BYTES
+will limit the number of bytes delivered per slot, and/or
+.I PACKETS
+will limit the number of packets delivered per slot.
+
+These slot options can provide a crude approximation of bursty MACs such as
+DOCSIS, WiFi, and LTE.
+
+Note that slotting is limited by several factors: the kernel clock granularity,
+as with a rate, and attempts to deliver many packets within a slot will be
+smeared by the timer resolution, and by the underlying native bandwidth also.
+
+It is possible to combine slotting with a rate, in which case complex behaviors
+where either the rate, or the slot limits on bytes or packets per slot, govern
+the actual delivered rate.
+
 .SH LIMITATIONS
 The main known limitation of Netem are related to timer granularity, since
 Linux is not a real-time operating system.
tc/q_netem.c +63 -1

106 lines not on this page · raw message

Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
#6 lore raw

PATCH v2 3/3 q_netem: slotting with non-uniform distribution

In reply to Yousuk Seung

Extend slotting with support for non-uniform distributions. This is similar to netem's non-uniform distribution delay feature.

Syntax:
slot distribution DISTRIBUTION DELAY JITTER [packets MAX_PACKETS] \
[bytes MAX_BYTES]

The syntax and use of the distribution table is the same as in the non-uniform distribution delay feature. A file DISTRIBUTION must be present in TC_LIB_DIR (e.g. /usr/lib/tc) containing numbers scaled by NETEM_DIST_SCALE. A random value x is selected from the table and it takes DELAY + ( x * JITTER ) as delay. Correlation between values is not supported.

Examples:
Normal distribution delay with mean = 800us and stdev = 100us.

Quoted 1 line

tc qdisc add dev eth0 root netem slot distribution normal \

    800us 100us

Optionally set the max slot size in bytes and/or packets.

Quoted 1 line

tc qdisc add dev eth0 root netem slot distribution normal \

    800us 100us bytes 64k packets 42
---
 man/man8/tc-netem.8 | 20 ++++++++----
 tc/q_netem.c        | 77 +++++++++++++++++++++++++++++++++++++--------
 2 files changed, 78 insertions(+), 19 deletions(-)
man/man8/tc-netem.8 +14 -6
index 8d485b026751..111109cf042f 100644
@@ -53,9 +53,13 @@ NetEm \- Network Emulator
 .IR RATE " [ " PACKETOVERHEAD " [ " CELLSIZE " [ " CELLOVERHEAD " ]]]]"
 
 .IR SLOT " := "
-.BR slot
-.IR MIN_DELAY " [ " MAX_DELAY " ] ["
-.BR packets
+.BR slot " { "
+.IR MIN_DELAY " [ " MAX_DELAY " ] |"
+.br
+.RB "               " distribution " { "uniform " | " normal " | " pareto " | " paretonormal " | "
+.IR FILE " } " DELAY " " JITTER " } "
+.br
+.RB "             [ " packets
 .IR PACKETS " ] [ "
 .BR bytes
 .IR BYTES " ]"
@@ -172,9 +176,13 @@ an artificial packet compression (bursts). Another influence factor are network
 adapter buffers which can also add artificial delay.
 
 .SS slot
-defer delivering accumulated packets to within a slot, with each available slot
-configured with a minimum delay to acquire, and an optional maximum delay.  Slot
-delays can be specified in nanoseconds, microseconds, milliseconds or seconds
+defer delivering accumulated packets to within a slot. Each available slot can be
+configured with a minimum delay to acquire, and an optional maximum delay.
+Alternatively it can be configured with the distribution similar to
+.BR distribution
+for
+.BR delay
+option. Slot delays can be specified in nanoseconds, microseconds, milliseconds or seconds
 (e.g. 800us). Values for the optional parameters
 .I BYTES
 will limit the number of bytes delivered per slot, and/or
tc/q_netem.c +64 -13

118 lines not on this page · raw message

Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
#2 lore raw

Re: [PATCH v2 iproute2-next 1/3] tc: support conversions to or from 64 bit nanosecond-based time

In reply to Yousuk Seung
Quoted 11 lines · On Sun, 26 Aug 2018 19:42:28 -0700 Yousuk Seung <[email protected]> wrote:
lib/utils.c +11 -0
+int get_time(unsigned int *time, const char *str)
+{
+	double t;
+	char *p;
+
+	t = strtod(str, &p);
+	if (p == str)
+		return -1;
+
+	if (*p) {
+		if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec") == 0 ||

lib/utils.c void drop_cap(void) · line 1657

Quoted 10 lines
lib/utils.c +10 -0
+		    strcasecmp(p, "secs") == 0)
+			t *= TIME_UNITS_PER_SEC;
+		else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec") == 0 ||
+			 strcasecmp(p, "msecs") == 0)
+			t *= TIME_UNITS_PER_SEC/1000;
+		else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec") == 0 ||
+			 strcasecmp(p, "usecs") == 0)
+			t *= TIME_UNITS_PER_SEC/1000000;
+		else
+			return -1;

Do we need to really support UPPER case.
Isn't existing matches semantics good enough?

#3 lore raw

Re: [PATCH v2 iproute2-next 1/3] tc: support conversions to or from 64 bit nanosecond-based time

Quoted 19 lines · Stephen Hemminger
Quoted 15 lines · On Sun, 26 Aug 2018 19:42:28 -0700 Yousuk Seung <[email protected]> wrote:
lib/utils.c +15 -0
+int get_time(unsigned int *time, const char *str)
+{
+     double t;
+     char *p;
+
+     t = strtod(str, &p);
+     if (p == str)
+             return -1;
+
+     if (*p) {
+             if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec") == 0 ||
+                 strcasecmp(p, "secs") == 0)
+                     t *= TIME_UNITS_PER_SEC;
+             else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec") == 0 ||
+                      strcasecmp(p, "msecs") == 0)
Quoted 8 lines

lib/utils.c void drop_cap(void) · line 1657

Quoted 6 lines
lib/utils.c +6 -0
+                     t *= TIME_UNITS_PER_SEC/1000;
+             else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec") == 0 ||
+                      strcasecmp(p, "usecs") == 0)
+                     t *= TIME_UNITS_PER_SEC/1000000;
+             else
+                     return -1;

Do we need to really support UPPER case.

But that's ALWAYS been the case in the 32 bit version of code above. Imagine how many former VMS and MVS hackers you'd upset if they had to turn caps-lock off!

Quoted 1 line

Isn't existing matches semantics good enough?

But that's the existing case for the 32 bit api, now replicated in the 64 bit api. ? I think the case-insensitive ship has sailed here. Can't break userspace.

Well.. adding UTF-8 would be cool. We could start using the actual greek symbols for delta (δ) and beta (β) in particular. It would replace a lot of typing, with a whole bunch more shift keys on a single letter, fit better into
80 column lines, and so on, and tc inputs and outputs are already pretty greek to many.

Applied
#7 lore raw
In reply to Yousuk Seung
Quoted 12 lines · Yousuk Seung

This series adds support for the new "slot" netem parameter for slotting. Slotting is an approximation of shared media that gather up packets within a varying delay window before delivering them nearly at once.

Dave Taht (2):
tc: support conversions to or from 64 bit nanosecond-based time
q_netem: support delivering packets in delayed time slots

Yousuk Seung (1):
q_netem: slotting with non-uniform distribution

Quoted 12 lines
 include/utils.h     |  12 +++++
 lib/utils.c         | 104 +++++++++++++++++++++++++++++++++++++++
 man/man8/tc-netem.8 |  40 ++++++++++++++-
 tc/q_netem.c        | 115 +++++++++++++++++++++++++++++++++++++++++++-
 tc/tc_cbq.c         |   1 +
 tc/tc_core.c        |   1 +
 tc/tc_core.h        |   2 -
 tc/tc_estimator.c   |   1 +
 tc/tc_util.c        |  46 ------------------
 tc/tc_util.h        |   3 --
 10 files changed, 272 insertions(+), 53 deletions(-)

applied to iproute2-next after fixing up a whitespace issue and 2 checkpatch errors in patch 2.

#4 lore raw

Re: [PATCH v2 iproute2-next 1/3] tc: support conversions to or from 64 bit nanosecond-based time

In reply to Dave Taht
Quoted 31 lines · Dave Taht
Quoted 19 lines · Stephen Hemminger
Quoted 15 lines · On Sun, 26 Aug 2018 19:42:28 -0700 Yousuk Seung <[email protected]> wrote:
lib/utils.c +15 -0
+int get_time(unsigned int *time, const char *str)
+{
+     double t;
+     char *p;
+
+     t = strtod(str, &p);
+     if (p == str)
+             return -1;
+
+     if (*p) {
+             if (strcasecmp(p, "s") == 0 || strcasecmp(p, "sec") == 0 ||
+                 strcasecmp(p, "secs") == 0)
+                     t *= TIME_UNITS_PER_SEC;
+             else if (strcasecmp(p, "ms") == 0 || strcasecmp(p, "msec") == 0 ||
+                      strcasecmp(p, "msecs") == 0)
Quoted 8 lines

lib/utils.c void drop_cap(void) · line 1657

Quoted 6 lines
lib/utils.c +6 -0
+                     t *= TIME_UNITS_PER_SEC/1000;
+             else if (strcasecmp(p, "us") == 0 || strcasecmp(p, "usec") == 0 ||
+                      strcasecmp(p, "usecs") == 0)
+                     t *= TIME_UNITS_PER_SEC/1000000;
+             else
+                     return -1;

Do we need to really support UPPER case.

Quoted 3 lines

But that's ALWAYS been the case in the 32 bit version of code above. Imagine how many former VMS and MVS hackers you'd upset if they had to turn caps-lock off!

I was trying to be funny, of course. If you want us to rework the patch to also downgrade to
being lowercase for both, ok... I'd rather like to finish getting this upstream, there's
a change to netem enabling nsec time long stuck behind it.

Quoted 19 lines
Quoted 2 lines

Isn't existing matches semantics good enough?

But that's the existing case for the 32 bit api, now replicated in the 64 bit api. ? I think the case-insensitive ship has sailed here. Can't break userspace.

Well.. adding UTF-8 would be cool. We could start using the actual greek symbols for delta (δ) and beta (β) in particular. It would replace a lot of typing, with a whole bunch more shift keys on a single letter, fit better into
80 column lines, and so on, and tc inputs and outputs are already pretty greek to many.
--

Dave Täht
CEO, TekLibre, LLC
http://www.teklibre.com
Tel: 1-669-226-2619

Signature · 4 lines
Dave Täht
CEO, TekLibre, LLC
http://www.teklibre.com
Tel: 1-669-226-2619