netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events
@ 2023-08-23 10:01 francois.michel
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 1/2] " francois.michel
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: francois.michel @ 2023-08-23 10:01 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.

v1 -> v2: Address comments and output the seed value
*after* slot information in netem_print_opt().

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] 9+ messages in thread

* [PATCH v2 iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-23 10:01 [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
@ 2023-08-23 10:01 ` francois.michel
  2023-08-29 10:07   ` Petr Machata
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: francois.michel @ 2023-08-23 10:01 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..febddd49 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);
@@ -823,6 +846,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);
+
 	print_bool(PRINT_JSON, "ecn", NULL, ecn);
 	if (ecn)
 		print_bool(PRINT_FP, NULL, " ecn ", ecn);
-- 
2.41.0


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

* [PATCH v2 iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed
  2023-08-23 10:01 [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 1/2] " francois.michel
@ 2023-08-23 10:01 ` francois.michel
  2023-08-23 13:16 ` [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events Stephen Hemminger
  2023-08-29  3:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 9+ messages in thread
From: francois.michel @ 2023-08-23 10:01 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] 9+ messages in thread

* Re: [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-23 10:01 [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 1/2] " francois.michel
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel
@ 2023-08-23 13:16 ` Stephen Hemminger
  2023-08-29  3:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2023-08-23 13:16 UTC (permalink / raw)
  To: francois.michel; +Cc: netdev

On Wed, 23 Aug 2023 12:01:08 +0200
francois.michel@uclouvain.be wrote:

> 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.
> 
> v1 -> v2: Address comments and output the seed value
> *after* slot information in netem_print_opt().

Daid will pickup the pkt_sched.h changes as part of regular header update

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

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

* Re: [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-23 10:01 [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
                   ` (2 preceding siblings ...)
  2023-08-23 13:16 ` [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events Stephen Hemminger
@ 2023-08-29  3:00 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-29  3:00 UTC (permalink / raw)
  To: =?utf-8?q?Fran=C3=A7ois_Michel_=3Cfrancois=2Emichel=40uclouvain=2Ebe=3E?=
  Cc: netdev, stephen

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Wed, 23 Aug 2023 12:01:08 +0200 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [v2,iproute2-next,1/2] tc: support the netem seed parameter for loss and corruption events
    (no matching commit)
  - [v2,iproute2-next,2/2] man: tc-netem: add section for specifying the netem seed
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=fcff3a8fe980

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH v2 iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-23 10:01 ` [PATCH v2 iproute2-next 1/2] " francois.michel
@ 2023-08-29 10:07   ` Petr Machata
  2023-08-30 12:30     ` François Michel
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Machata @ 2023-08-29 10:07 UTC (permalink / raw)
  To: francois.michel; +Cc: netdev, stephen

Took me a while to fight my way through all the unreads to this, and
it's already merged, but...

francois.michel@uclouvain.be writes:

> diff --git a/tc/q_netem.c b/tc/q_netem.c
> index 8ace2b61..febddd49 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]"

The newline seems misplaced.

>  		"                 [ ecn ]\n"
>  		"                 [ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]\n"
>  		"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n"

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

* Re: [PATCH v2 iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-29 10:07   ` Petr Machata
@ 2023-08-30 12:30     ` François Michel
  2023-08-30 13:22       ` Petr Machata
  0 siblings, 1 reply; 9+ messages in thread
From: François Michel @ 2023-08-30 12:30 UTC (permalink / raw)
  To: Petr Machata; +Cc: netdev, stephen

Hi,

Le 29/08/23 à 12:07, Petr Machata a écrit :
> Took me a while to fight my way through all the unreads to this, and
> it's already merged, but...
> 
> francois.michel@uclouvain.be writes:
> 
>> diff --git a/tc/q_netem.c b/tc/q_netem.c
>> index 8ace2b61..febddd49 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]"
> 
> The newline seems misplaced.

Sorry for that, I don't know how I could have missed that.
Should I send a patch to fix this ?

François
> 
>>   		"                 [ ecn ]\n"
>>   		"                 [ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]\n"
>>   		"                 [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n"

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

* Re: [PATCH v2 iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-30 12:30     ` François Michel
@ 2023-08-30 13:22       ` Petr Machata
  2023-08-30 15:01         ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Petr Machata @ 2023-08-30 13:22 UTC (permalink / raw)
  To: François Michel; +Cc: Petr Machata, netdev, stephen


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

> Hi,
>
> Le 29/08/23 à 12:07, Petr Machata a écrit :
>> Took me a while to fight my way through all the unreads to this, and
>> it's already merged, but...
>> francois.michel@uclouvain.be writes:
>> 
>>> diff --git a/tc/q_netem.c b/tc/q_netem.c
>>> index 8ace2b61..febddd49 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]"
>> The newline seems misplaced.
>
> Sorry for that, I don't know how I could have missed that.
> Should I send a patch to fix this ?

That would be the way to get it fixed, yes.

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

* Re: [PATCH v2 iproute2-next 1/2] tc: support the netem seed parameter for loss and corruption events
  2023-08-30 13:22       ` Petr Machata
@ 2023-08-30 15:01         ` David Ahern
  0 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2023-08-30 15:01 UTC (permalink / raw)
  To: Petr Machata, François Michel; +Cc: netdev, stephen

On 8/30/23 7:22 AM, Petr Machata wrote:
> 
> François Michel <francois.michel@uclouvain.be> writes:
> 
>> Hi,
>>
>> Le 29/08/23 à 12:07, Petr Machata a écrit :
>>> Took me a while to fight my way through all the unreads to this, and
>>> it's already merged, but...
>>> francois.michel@uclouvain.be writes:
>>>
>>>> diff --git a/tc/q_netem.c b/tc/q_netem.c
>>>> index 8ace2b61..febddd49 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]"
>>> The newline seems misplaced.
>>
>> Sorry for that, I don't know how I could have missed that.
>> Should I send a patch to fix this ?
> 
> That would be the way to get it fixed, yes.
> 

yes, please send a patch. thanks catching it, Petr.

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

end of thread, other threads:[~2023-08-30 15:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23 10:01 [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events francois.michel
2023-08-23 10:01 ` [PATCH v2 iproute2-next 1/2] " francois.michel
2023-08-29 10:07   ` Petr Machata
2023-08-30 12:30     ` François Michel
2023-08-30 13:22       ` Petr Machata
2023-08-30 15:01         ` David Ahern
2023-08-23 10:01 ` [PATCH v2 iproute2-next 2/2] man: tc-netem: add section for specifying the netem seed francois.michel
2023-08-23 13:16 ` [PATCH v2 iproute2-next 0/2] tc: support the netem seed parameter for loss and corruption events Stephen Hemminger
2023-08-29  3:00 ` patchwork-bot+netdevbpf

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).