netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 0/3] netem iproute2 userspace parts
@ 2011-12-20 21:28 Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 1/3] utils: add s32 parser Hagen Paul Pfeifer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2011-12-20 21:28 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer

Hello Stephen,

the follow serie provides support for netem rate extension. The s32 parser was
already discussed. I extend the man page to describe the extension.

Hagen

Hagen Paul Pfeifer (3):
  utils: add s32 parser
  tc: netem rate shaping and cell extension
  netem: extend man page for rate extension

 include/linux/pkt_sched.h |    8 +++++
 include/utils.h           |    1 +
 lib/utils.c               |   19 +++++++++++++
 man/man8/tc-netem.8       |   66 +++++++++++++++++++++++++++++++++++---------
 tc/q_netem.c              |   53 +++++++++++++++++++++++++++++++++++-
 5 files changed, 132 insertions(+), 15 deletions(-)

-- 
1.7.7.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2 1/3] utils: add s32 parser
  2011-12-20 21:28 [PATCH iproute2 0/3] netem iproute2 userspace parts Hagen Paul Pfeifer
@ 2011-12-20 21:28 ` Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 2/3] tc: netem rate shaping and cell extension Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 3/3] netem: extend man page for rate extension Hagen Paul Pfeifer
  2 siblings, 0 replies; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2011-12-20 21:28 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 include/utils.h |    1 +
 lib/utils.c     |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/include/utils.h b/include/utils.h
index 47f8e07..496db68 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -85,6 +85,7 @@ extern int get_time_rtt(unsigned *val, const char *arg, int *raw);
 #define get_short get_s16
 extern int get_u64(__u64 *val, const char *arg, int base);
 extern int get_u32(__u32 *val, const char *arg, int base);
+extern int get_s32(__s32 *val, const char *arg, int base);
 extern int get_u16(__u16 *val, const char *arg, int base);
 extern int get_s16(__s16 *val, const char *arg, int base);
 extern int get_u8(__u8 *val, const char *arg, int base);
diff --git a/lib/utils.c b/lib/utils.c
index efaf377..d80f79b 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -25,6 +25,7 @@
 #include <linux/pkt_sched.h>
 #include <time.h>
 #include <sys/time.h>
+#include <errno.h>
 
 
 #include "utils.h"
@@ -198,6 +199,24 @@ int get_u8(__u8 *val, const char *arg, int base)
 	return 0;
 }
 
+int get_s32(__s32 *val, const char *arg, int base)
+{
+	long res;
+	char *ptr;
+
+	errno = 0;
+
+	if (!arg || !*arg)
+		return -1;
+	res = strtol(arg, &ptr, base);
+	if (ptr == arg || *ptr ||
+	    ((res ==  LONG_MIN || res == LONG_MAX) && errno == ERANGE) ||
+	    res > INT32_MAX || res < INT32_MIN)
+		return -1;
+	*val = res;
+	return 0;
+}
+
 int get_s16(__s16 *val, const char *arg, int base)
 {
 	long res;
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2 2/3] tc: netem rate shaping and cell extension
  2011-12-20 21:28 [PATCH iproute2 0/3] netem iproute2 userspace parts Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 1/3] utils: add s32 parser Hagen Paul Pfeifer
@ 2011-12-20 21:28 ` Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 3/3] netem: extend man page for rate extension Hagen Paul Pfeifer
  2 siblings, 0 replies; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2011-12-20 21:28 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer

This patch add rate shaping as well as cell support. The link-rate can be
specified via rate options. Three optional arguments control the cell
knobs: packet-overhead, cell-size, cell-overhead. To ratelimit eth0 root
queue to 5kbit/s, with a 20 byte packet overhead, 100 byte cell size and
a 5 byte per cell overhead:

	tc qdisc add dev eth0 root netem rate 5kbit 20 100 5

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 include/linux/pkt_sched.h |    8 ++++++
 tc/q_netem.c              |   53 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
index c533670..eaf4e9e 100644
--- a/include/linux/pkt_sched.h
+++ b/include/linux/pkt_sched.h
@@ -465,6 +465,7 @@ enum {
 	TCA_NETEM_REORDER,
 	TCA_NETEM_CORRUPT,
 	TCA_NETEM_LOSS,
+	TCA_NETEM_RATE,
 	__TCA_NETEM_MAX,
 };
 
@@ -495,6 +496,13 @@ struct tc_netem_corrupt {
 	__u32	correlation;
 };
 
+struct tc_netem_rate {
+	__u32	rate;		 /* byte/s */
+	__s32	packet_overhead;
+	__u32	cell_size;
+	__s32	cell_overhead;
+};
+
 enum {
 	NETEM_LOSS_UNSPEC,
 	NETEM_LOSS_GI,		/* General Intuitive - 4 state model */
diff --git a/tc/q_netem.c b/tc/q_netem.c
index 6dc40bd..1fdfa44 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -34,7 +34,8 @@ static void explain(void)
 "                 [ drop PERCENT [CORRELATION]] \n" \
 "                 [ corrupt PERCENT [CORRELATION]] \n" \
 "                 [ duplicate PERCENT [CORRELATION]]\n" \
-"                 [ reorder PRECENT [CORRELATION] [ gap DISTANCE ]]\n");
+"                 [ reorder PRECENT [CORRELATION] [ gap DISTANCE ]]\n" \
+"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n");
 }
 
 static void explain1(const char *arg)
@@ -131,6 +132,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	struct tc_netem_corr cor;
 	struct tc_netem_reorder reorder;
 	struct tc_netem_corrupt corrupt;
+	struct tc_netem_rate rate;
 	__s16 *dist_data = NULL;
 	int present[__TCA_NETEM_MAX];
 
@@ -139,6 +141,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	memset(&cor, 0, sizeof(cor));
 	memset(&reorder, 0, sizeof(reorder));
 	memset(&corrupt, 0, sizeof(corrupt));
+	memset(&rate, 0, sizeof(rate));
 	memset(present, 0, sizeof(present));
 
 	while (argc > 0) {
@@ -244,6 +247,34 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 				free(dist_data);
 				return -1;
 			}
+		} else if (matches(*argv, "rate") == 0) {
+			++present[TCA_NETEM_RATE];
+			NEXT_ARG();
+			if (get_rate(&rate.rate, *argv)) {
+				explain1("rate");
+				return -1;
+			}
+			if (NEXT_IS_NUMBER()) {
+				NEXT_ARG();
+				if (get_s32(&rate.packet_overhead, *argv, 0)) {
+					explain1("rate");
+					return -1;
+				}
+			}
+			if (NEXT_IS_NUMBER()) {
+				NEXT_ARG();
+				if (get_u32(&rate.cell_size, *argv, 0)) {
+					explain1("rate");
+					return -1;
+				}
+			}
+			if (NEXT_IS_NUMBER()) {
+				NEXT_ARG();
+				if (get_s32(&rate.cell_overhead, *argv, 0)) {
+					explain1("rate");
+					return -1;
+				}
+			}
 		} else if (strcmp(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -290,6 +321,10 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	    addattr_l(n, 1024, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0)
 		return -1;
 
+	if (present[TCA_NETEM_RATE] &&
+	    addattr_l(n, 1024, TCA_NETEM_RATE, &rate, sizeof(rate)) < 0)
+		return -1;
+
 	if (dist_data) {
 		if (addattr_l(n, MAX_DIST * sizeof(dist_data[0]),
 			      TCA_NETEM_DELAY_DIST,
@@ -306,6 +341,7 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	const struct tc_netem_corr *cor = NULL;
 	const struct tc_netem_reorder *reorder = NULL;
 	const struct tc_netem_corrupt *corrupt = NULL;
+	const struct tc_netem_rate *rate = NULL;
 	struct tc_netem_qopt qopt;
 	int len = RTA_PAYLOAD(opt) - sizeof(qopt);
 	SPRINT_BUF(b1);
@@ -339,6 +375,11 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				return -1;
 			corrupt = RTA_DATA(tb[TCA_NETEM_CORRUPT]);
 		}
+		if (tb[TCA_NETEM_RATE]) {
+			if (RTA_PAYLOAD(tb[TCA_NETEM_RATE]) < sizeof(*rate))
+				return -1;
+			rate = RTA_DATA(tb[TCA_NETEM_RATE]);
+		}
 	}
 
 	fprintf(f, "limit %d", qopt.limit);
@@ -382,6 +423,16 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				sprint_percent(corrupt->correlation, b1));
 	}
 
+	if (rate && rate->rate) {
+		fprintf(f, " rate %s", sprint_rate(rate->rate, b1));
+		if (rate->packet_overhead)
+			fprintf(f, " packetoverhead %d", rate->packet_overhead);
+		if (rate->cell_size)
+			fprintf(f, " cellsize %u", rate->cell_size);
+		if (rate->cell_overhead)
+			fprintf(f, " celloverhead %d", rate->cell_overhead);
+	}
+
 	if (qopt.gap)
 		fprintf(f, " gap %lu", (unsigned long)qopt.gap);
 
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2 3/3] netem: extend man page for rate extension
  2011-12-20 21:28 [PATCH iproute2 0/3] netem iproute2 userspace parts Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 1/3] utils: add s32 parser Hagen Paul Pfeifer
  2011-12-20 21:28 ` [PATCH iproute2 2/3] tc: netem rate shaping and cell extension Hagen Paul Pfeifer
@ 2011-12-20 21:28 ` Hagen Paul Pfeifer
  2 siblings, 0 replies; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2011-12-20 21:28 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 man/man8/tc-netem.8 |   66 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/man/man8/tc-netem.8 b/man/man8/tc-netem.8
index c8ed292..ef2a63b 100644
--- a/man/man8/tc-netem.8
+++ b/man/man8/tc-netem.8
@@ -3,90 +3,96 @@
 NetEm \- Network Emulator
 .SH SYNOPSIS
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ limit
 packets
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ logging
 LEVEL ]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ delay
 TIME [ JITTER [CORRELATION]]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ distribution
 {uniform|normal|pareto|paretonormal} ]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ drop
 PERCENT [CORRELATION]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ loss
 PERCENT [CORRELATION]]
 .B ]
 
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ query ] [ loss_GI
 ploss [burst_length [density [pisol [good_burst_length]]]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ query ] [ loss_4state
 [p13 [p31 [p32 [p23 [p14]]]]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ loss_gilb_ell
 p [r [1-h [1-k]]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ loss_gilb_ell_4s
 p [r [1-h [1-k]]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem [ loss_pattern
 FILENAME [REPETITIONS]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ corrupt
 PERCENT [CORRELATION]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ duplicate
 PERCENT [CORRELATION]]
 .B ]
 
 .B tc qdisc ... dev
-dev
+DEVICE
 .B ] add netem  [ reorder
 PRECENT [CORRELATION] [ gap DISTANCE ]]
 .B ]
 
+.B tc qdisc ... dev
+DEVICE
+.B ] add netem  [ rate
+RATE [PACKETOVERHEAD [CELLSIZE [CELLOVERHEAD]]]]
+.B ]
+
 .SH DESCRIPTION
 NetEm is an enhancement of the Linux traffic control facilities
 that allow to add delay, packet loss, duplication and more other
@@ -240,6 +246,38 @@ other packets are delayed by 10 ms
 in this second example 25% of packets are sent immediately (with correlation of
 50%) while the other are delayed by 10 ms.
 
+
+.B rate
+RATE [PACKETOVERHEAD [CELLSIZE [CELLOVERHEAD]]]
+
+delay packets based on packet size and is a replacement for TBF. Rate can be
+specified in common units (e.g. 100kbit). Optional PACKETOVERHEAD (in bytes)
+specify an per packet overhead and can be negative. A positive value can be
+used to simulate additional link layer headers. A negative value can be used to
+artificial strip the Ethernet header (e.g. -14) and/or simulate a link layer
+header compression scheme. The third parameter - an unsigned value - specify
+the cellsize. Cellsize can be used to simulate link layer schemes. ATM for
+example has an payload cellsize of 48 bytes and 5 byte per cell header. If a
+packet is 50 byte then ATM must use two cells: 2 * 48 bytes payload including 2
+* 5 byte header, thus consume 106 byte on the wire.  The last optional value
+CELLOVERHEAD can be used to specify per cell overhead - for our ATM example 5.
+CELLOVERHEAD can be negative, but use negative values with caution.
+
+Note that rate throttling is limited by several factors: the kernel clock
+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.
+
+To delay all outgoing packets on devive eth0 with a rate of 5kbit, a per packet
+overhead of 20 byte, a cellsize of 100 byte and a per celloverhead of 5 byte:
+
+tc qdisc add dev eth0 root netem rate 5kbit 20 100 5
+
+And show:
+
+tc qdisc show dev eth0
+
+
 .SH LIMITATIONS
 The main known limitation of Netem are related to timer granularity, since
 Linux is not a real-time operating system; to the choice of Pseudo-Random
-- 
1.7.7.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-12-20 21:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-20 21:28 [PATCH iproute2 0/3] netem iproute2 userspace parts Hagen Paul Pfeifer
2011-12-20 21:28 ` [PATCH iproute2 1/3] utils: add s32 parser Hagen Paul Pfeifer
2011-12-20 21:28 ` [PATCH iproute2 2/3] tc: netem rate shaping and cell extension Hagen Paul Pfeifer
2011-12-20 21:28 ` [PATCH iproute2 3/3] netem: extend man page for rate extension Hagen Paul Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).