public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events
@ 2023-08-22 14:04 francois.michel
  2023-08-22 14:04 ` [PATCH iproute2-next 1/2] " francois.michel
  2023-08-22 14:04 ` [PATCH iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel
  0 siblings, 2 replies; 5+ messages in thread
From: francois.michel @ 2023-08-22 14:04 UTC (permalink / raw)
  Cc: netdev, stephen, Francois Michel

From: François Michel <francois.michel@uclouvain.be>

Linux now features a seed parameter to guide and reproduce
the loss and corruption events. This patch integrates these
results in the tc CLI.

For instance, setting the seed 42424242 on the loopback
with a loss rate of 10% will systematically drop the 5th,
12th and 24th packet when sending 25 packets.

François Michel (2):
  tc: support the netem seed parameter for loss and corruption events
  man: tc-netem: add section for specifying the netem seed

 include/uapi/linux/pkt_sched.h |  1 +
 man/man8/tc-netem.8            | 11 ++++++++++-
 tc/q_netem.c                   | 26 ++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)


base-commit: ce67bbcccb237f837c0ec2b5d4c85a4fd11ef1b5
-- 
2.41.0


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

* [PATCH iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-22 14:04 [PATCH iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
@ 2023-08-22 14:04 ` francois.michel
  2023-08-22 15:43   ` Stephen Hemminger
  2023-08-22 14:04 ` [PATCH iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel
  1 sibling, 1 reply; 5+ messages in thread
From: francois.michel @ 2023-08-22 14:04 UTC (permalink / raw)
  Cc: netdev, stephen, Francois Michel

From: François Michel <francois.michel@uclouvain.be>

Signed-off-by: François Michel <francois.michel@uclouvain.be>
---
 include/uapi/linux/pkt_sched.h |  1 +
 tc/q_netem.c                   | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
index 00f6ff0a..3f85ae57 100644
--- a/include/uapi/linux/pkt_sched.h
+++ b/include/uapi/linux/pkt_sched.h
@@ -603,6 +603,7 @@ enum {
 	TCA_NETEM_JITTER64,
 	TCA_NETEM_SLOT,
 	TCA_NETEM_SLOT_DIST,
+	TCA_NETEM_PRNG_SEED,
 	__TCA_NETEM_MAX,
 };
 
diff --git a/tc/q_netem.c b/tc/q_netem.c
index 8ace2b61..6d48081a 100644
--- a/tc/q_netem.c
+++ b/tc/q_netem.c
@@ -31,6 +31,7 @@ static void explain(void)
 		"                 [ loss random PERCENT [CORRELATION]]\n"
 		"                 [ loss state P13 [P31 [P32 [P23 P14]]]\n"
 		"                 [ loss gemodel PERCENT [R [1-H [1-K]]]\n"
+		"                 [ seed SEED \n]"
 		"                 [ ecn ]\n"
 		"                 [ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]\n"
 		"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n"
@@ -208,6 +209,7 @@ static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
 	__u16 loss_type = NETEM_LOSS_UNSPEC;
 	int present[__TCA_NETEM_MAX] = {};
 	__u64 rate64 = 0;
+	__u64 seed = 0;
 
 	for ( ; argc > 0; --argc, ++argv) {
 		if (matches(*argv, "limit") == 0) {
@@ -363,6 +365,13 @@ random_loss_model:
 					*argv);
 				return -1;
 			}
+		} else if (matches(*argv, "seed") == 0) {
+			NEXT_ARG();
+			present[TCA_NETEM_PRNG_SEED] = 1;
+			if (get_u64(&seed, *argv, 10)) {
+				explain1("seed");
+				return -1;
+			}
 		} else if (matches(*argv, "ecn") == 0) {
 			present[TCA_NETEM_ECN] = 1;
 		} else if (matches(*argv, "reorder") == 0) {
@@ -627,6 +636,12 @@ random_loss_model:
 			return -1;
 	}
 
+	if (present[TCA_NETEM_PRNG_SEED] &&
+	    addattr_l(n, 1024, TCA_NETEM_PRNG_SEED, &seed,
+		      sizeof(seed)) < 0)
+		return -1;
+
+
 	if (dist_data) {
 		if (addattr_l(n, MAX_DIST * sizeof(dist_data[0]),
 			      TCA_NETEM_DELAY_DIST,
@@ -657,6 +672,8 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	struct tc_netem_qopt qopt;
 	const struct tc_netem_rate *rate = NULL;
 	const struct tc_netem_slot *slot = NULL;
+	bool seed_present = false;
+	__u64 seed = 0;
 	int len;
 	__u64 rate64 = 0;
 
@@ -722,6 +739,12 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				return -1;
 			slot = RTA_DATA(tb[TCA_NETEM_SLOT]);
 		}
+		if (tb[TCA_NETEM_PRNG_SEED]) {
+			if (RTA_PAYLOAD(tb[TCA_NETEM_PRNG_SEED]) < sizeof(seed))
+				return -1;
+			seed_present = true;
+			seed = rta_getattr_u64(tb[TCA_NETEM_PRNG_SEED]);
+		}
 	}
 
 	print_uint(PRINT_ANY, "limit", "limit %d", qopt.limit);
@@ -795,6 +818,9 @@ static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 		close_json_object();
 	}
 
+	if (seed_present)
+		print_u64(PRINT_ANY, "seed", " seed %llu", seed);
+
 	if (rate && rate->rate) {
 		open_json_object("rate");
 		rate64 = rate64 ? : rate->rate;
-- 
2.41.0


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

* [PATCH iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed
  2023-08-22 14:04 [PATCH iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
  2023-08-22 14:04 ` [PATCH iproute2-next 1/2] " francois.michel
@ 2023-08-22 14:04 ` francois.michel
  1 sibling, 0 replies; 5+ messages in thread
From: francois.michel @ 2023-08-22 14:04 UTC (permalink / raw)
  Cc: netdev, stephen, Francois Michel

From: François Michel <francois.michel@uclouvain.be>

Signed-off-by: François Michel <francois.michel@uclouvain.be>
---
 man/man8/tc-netem.8 | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/man/man8/tc-netem.8 b/man/man8/tc-netem.8
index bc7947da..a4cc0d61 100644
--- a/man/man8/tc-netem.8
+++ b/man/man8/tc-netem.8
@@ -9,7 +9,7 @@ netem \- Network Emulator
 
 .IR OPTIONS " := [ " LIMIT " ] [ " DELAY " ] [ " LOSS \
 " ] [ " CORRUPT " ] [ " DUPLICATION " ] [ " REORDERING " ] [ " RATE \
-" ] [ " SLOT " ]"
+" ] [ " SLOT " ] [ " SEED " ]"
 
 .IR LIMIT " := "
 .B limit
@@ -64,6 +64,10 @@ netem \- Network Emulator
 .BR bytes
 .IR BYTES " ]"
 
+.IR SEED " := "
+.B seed
+.I VALUE
+
 .SH DESCRIPTION
 The
 .B netem
@@ -240,6 +244,11 @@ 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.
 
+.TP
+.BI seed " VALUE"
+Specifies a seed to guide and reproduce the randomly generated
+loss or corruption events.
+
 .SH LIMITATIONS
 Netem is limited by the timer granularity in the kernel.
 Rate and delay maybe impacted by clock interrupts.
-- 
2.41.0


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

* Re: [PATCH iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-22 14:04 ` [PATCH iproute2-next 1/2] " francois.michel
@ 2023-08-22 15:43   ` Stephen Hemminger
  2023-08-23  9:58     ` François Michel
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2023-08-22 15:43 UTC (permalink / raw)
  To: francois.michel; +Cc: netdev

On Tue, 22 Aug 2023 16:04:02 +0200
francois.michel@uclouvain.be wrote:

> +	if (seed_present)
> +		print_u64(PRINT_ANY, "seed", " seed %llu", seed);
> +

Since seed is after slot in the manual, you might want to put
it after slot in the output.

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

* Re: [PATCH iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-22 15:43   ` Stephen Hemminger
@ 2023-08-23  9:58     ` François Michel
  0 siblings, 0 replies; 5+ messages in thread
From: François Michel @ 2023-08-23  9:58 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev



Le 22/08/23 à 17:43, Stephen Hemminger a écrit :
> On Tue, 22 Aug 2023 16:04:02 +0200
> francois.michel@uclouvain.be wrote:
> 
>> +	if (seed_present)
>> +		print_u64(PRINT_ANY, "seed", " seed %llu", seed);
>> +
> 
> Since seed is after slot in the manual, you might want to put
> it after slot in the output.

True, I updated the code and re-tested. I'll submit a v2 patch now.

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

end of thread, other threads:[~2023-08-23  9:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22 14:04 [PATCH iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
2023-08-22 14:04 ` [PATCH iproute2-next 1/2] " francois.michel
2023-08-22 15:43   ` Stephen Hemminger
2023-08-23  9:58     ` François Michel
2023-08-22 14:04 ` [PATCH iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox