From nobody Sun Dec 17 21:55:51 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4StcGJ1sWvz54Kj1; Sun, 17 Dec 2023 21:55:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4StcGH6kgvz4dpc; Sun, 17 Dec 2023 21:55:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702850151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rL02p6lSHn2r4IdlMV0m15mjpJYFSGKrLYCPscc8jMM=; b=dHILmEoo491dXsHVv8NgGL23eWdYqN9c38Pj43LUS3KEuyX6e73Fj15tlZhIDOhfUxSjQ1 2NWDiavtIvs00R0LbZv3Mt4/T3z9scuTr+MaR5iUFasiysnPcsGPzpYkMsJzK2tUoD3YW4 eeb2Qxe2AWrFq7dhabjoNpzCRfYNAU/NAd95YFvwxJ/Wd1EoIyTTX2gAZThBi24ZuM6Go9 5GljHMSsur1r6Qz5HxdEkNxwdnusT6csueFXUYbrpTe0Bi++hzKQNQjrjqEdDLR6xNkSMs 4KgASEjXJXYhP0Q+jobaa3+MKkk6AZP0ywkr7757oiUQ79vVgTqTa3THhVEVmw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702850151; a=rsa-sha256; cv=none; b=P6oKM67mvHtXsj4nGtHwq0c7O6t6+c3NDwDIpDobYcP/iI+Y2/OLyZWf736fQRhKEIS3dm r1sjYCZrSZ9FKNlRV6y95k1Z2KoWh/Jkm3r17vhT4YWeU90mXlwd7DMn7uzRBtV4JnGUwB LsCuGpOP7u5Kd0+0FyYYOitbBnq9Gdvi7fbME7ersEDWT73vys2OC6DiejeMOEvzWFLHex r9lh+Z2DxGs5CG3pdd1tn2RUnOSf8V5UZHaAP/vWaSCMAsvWCvjvvFCwbuIzyd9h0WtIVr jqkmXXgWIYS5nTzSOh6FDr67Si+TcBies79iEP1/n+EcKT8D3LPByHf+78Scvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702850151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rL02p6lSHn2r4IdlMV0m15mjpJYFSGKrLYCPscc8jMM=; b=GijWanOoCYsmfwCjKKcFGRx6h9z4KBmqDFVVcRtZQIfbvZ3bRj0zUhrqaoT9revatcv2yP PmFO83dexQIFkHyn48HsddTPmMAI+t/3osCNZjeHKJAT14g6jTnVeLvvpNNlkbtqxvqwO6 adus48Z4C6cnSarhvaJqG9dr9GnNcSSdwqHka4bgrlg5R8FZJGCYKLRLgrqcjiQj27Udrf C9dmCZM7RmaUAzhC9J0tJjPmYSI3e+GXaz6IDNug5WRhs8a8DkjTqcCNDZbtDXgD4vif12 uB/Y/lp/zBiVT8ZxKCMOsK2HS05AWXSqWJEKmvGaMZVDMha9LbTUa1yB7oXkuw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4StcGH5pqSzv4W; Sun, 17 Dec 2023 21:55:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BHLtpRS044692; Sun, 17 Dec 2023 21:55:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BHLtpqR044689; Sun, 17 Dec 2023 21:55:51 GMT (envelope-from git) Date: Sun, 17 Dec 2023 21:55:51 GMT Message-Id: <202312172155.3BHLtpqR044689@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Richard Scheffenegger Subject: git: 31cf66d7554c - main - dummynet: add simple gilbert-elliott channel model List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rscheff X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 31cf66d7554c2fa6a5aea77f4cd54712e611cdd0 Auto-Submitted: auto-generated The branch main has been updated by rscheff: URL: https://cgit.FreeBSD.org/src/commit/?id=31cf66d7554c2fa6a5aea77f4cd54712e611cdd0 commit 31cf66d7554c2fa6a5aea77f4cd54712e611cdd0 Author: Richard Scheffenegger AuthorDate: 2023-12-17 12:19:52 +0000 Commit: Richard Scheffenegger CommitDate: 2023-12-17 12:20:45 +0000 dummynet: add simple gilbert-elliott channel model Have a simple Gilbert-Elliott channel model in dummynet to mimick correlated loss behavior of realistic environments. This allows simpler testing of burst-loss environments. Reviewed By: tuexen, kp, pauamma_gundo.com, #manpages Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D42980 --- sbin/ipfw/dummynet.c | 44 +++++++++++---- sbin/ipfw/ipfw.8 | 39 +++++++++++++- sys/netinet/ip_dummynet.h | 3 +- sys/netpfil/ipfw/ip_dn_glue.c | 51 ++++++++++-------- sys/netpfil/ipfw/ip_dn_io.c | 24 ++++++++- sys/netpfil/ipfw/ip_dn_private.h | 9 ++++ tests/sys/netpfil/common/dummynet.sh | 102 +++++++++++++++++++++++++++++++++++ 7 files changed, 235 insertions(+), 37 deletions(-) diff --git a/sbin/ipfw/dummynet.c b/sbin/ipfw/dummynet.c index 26d535428ec3..9663e983b31a 100644 --- a/sbin/ipfw/dummynet.c +++ b/sbin/ipfw/dummynet.c @@ -471,7 +471,7 @@ print_flowset_parms(struct dn_fs *fs, char *prefix) { int l; char qs[30]; - char plr[30]; + char plr[40]; char red[200]; /* Display RED parameters */ l = fs->qsize; @@ -482,9 +482,17 @@ print_flowset_parms(struct dn_fs *fs, char *prefix) sprintf(qs, "%d B", l); } else sprintf(qs, "%3d sl.", l); - if (fs->plr) - sprintf(plr, "plr %f", 1.0 * fs->plr / (double)(0x7fffffff)); - else + if (fs->plr[0] || fs->plr[1]) { + if (fs->plr[1] == 0) + sprintf(plr, "plr %f", + 1.0 * fs->plr[0] / (double)(0x7fffffff)); + else + sprintf(plr, "plr %f,%f,%f,%f", + 1.0 * fs->plr[0] / (double)(0x7fffffff), + 1.0 * fs->plr[1] / (double)(0x7fffffff), + 1.0 * fs->plr[2] / (double)(0x7fffffff), + 1.0 * fs->plr[3] / (double)(0x7fffffff)); + } else plr[0] = '\0'; if (fs->flags & DN_IS_RED) { /* RED parameters */ @@ -1408,13 +1416,27 @@ ipfw_config_pipe(int ac, char **av) case TOK_PLR: NEED(fs, "plr is only for pipes"); - NEED1("plr needs argument 0..1\n"); - d = strtod(av[0], NULL); - if (d > 1) - d = 1; - else if (d < 0) - d = 0; - fs->plr = (int)(d*0x7fffffff); + NEED1("plr needs one or four arguments 0..1\n"); + if ((end = strsep(&av[0], ","))) { + d = strtod(end, NULL); + d = (d < 0) ? 0 : (d <= 1) ? d : 1; + fs->plr[0] = (int)(d*0x7fffffff); + } + if ((end = strsep(&av[0], ","))) { + d = strtod(end, NULL); + d = (d < 0) ? 0 : (d <= 1) ? d : 1; + fs->plr[1] = (int)(d*0x7fffffff); + } + if ((end = strsep(&av[0], ","))) { + d = strtod(end, NULL); + d = (d < 0) ? 0 : (d <= 1) ? d : 1; + fs->plr[2] = (int)(d*0x7fffffff); + } + if ((end = strsep(&av[0], ","))) { + d = strtod(end, NULL); + d = (d < 0) ? 0 : (d <= 1) ? d : 1; + fs->plr[3] = (int)(d*0x7fffffff); + } ac--; av++; break; diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index e62b8d6efc95..715d8580f1ce 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -1,5 +1,5 @@ .\" -.Dd September 28, 2023 +.Dd December 17, 2023 .Dt IPFW 8 .Os .Sh NAME @@ -3039,12 +3039,47 @@ needed for some experimental setups where you want to simulate loss or congestion at a remote router. .Pp .It Cm plr Ar packet-loss-rate +.It Cm plr Ar K,p,H,r Packet loss rate. Argument .Ar packet-loss-rate is a floating-point number between 0 and 1, with 0 meaning no loss, 1 meaning 100% loss. -The loss rate is internally represented on 31 bits. +.Pp +When invoked with four arguments, the simple Gilbert-Elliott +channel model with two states (Good and Bad) is used. +.Bd -literal -offset indent + r + .----------------. + v | + .------------. .------------. + | G | | B | + | drop (K) | | drop (H) | + '------------' '------------' + | ^ + '----------------' + p + +.Ed +This has the associated probabilities +.Po Ar K +and +.Ar H Pc +for the loss probability. This is different from the literature, +where this model is described with probabilities of successful +transmission k and h. However, converting from literature is +easy: +.Pp +K = 1 - k ; H = 1 - h +.Pp +This is to retain consistency within the interface and allow the +quick re-use of loss probability when giving only a single argument. +In addition the state change probabilities +.Po Ar p +and +.Ar r Pc +are given. +All of the above probabilities are internally represented on 31 bits. .Pp .It Cm queue Brq Ar slots | size Ns Cm Kbytes Queue size, in diff --git a/sys/netinet/ip_dummynet.h b/sys/netinet/ip_dummynet.h index b36b93bbe96b..4e05dcca606f 100644 --- a/sys/netinet/ip_dummynet.h +++ b/sys/netinet/ip_dummynet.h @@ -145,7 +145,7 @@ struct dn_fs { uint32_t fs_nr; /* the flowset number */ uint32_t flags; /* userland flags */ int qsize; /* queue size in slots or bytes */ - int32_t plr; /* PLR, pkt loss rate (2^31-1 means 100%) */ + int32_t pl_state; /* packet loss state */ uint32_t buckets; /* buckets used for the queue hash table */ struct ipfw_flow_id flow_mask; @@ -168,6 +168,7 @@ struct dn_fs { int min_th ; /* minimum threshold for queue (scaled) */ int max_p ; /* maximum value for p_b (scaled) */ + int32_t plr[4]; /* PLR, pkt loss rate (2^31-1 means 100%) */ }; /* diff --git a/sys/netpfil/ipfw/ip_dn_glue.c b/sys/netpfil/ipfw/ip_dn_glue.c index 204b34091781..0412b730e4df 100644 --- a/sys/netpfil/ipfw/ip_dn_glue.c +++ b/sys/netpfil/ipfw/ip_dn_glue.c @@ -77,35 +77,35 @@ struct dn_heap7 { /* Common to 7.2 and 8 */ struct dn_flow_set { - SLIST_ENTRY(dn_flow_set) next; /* linked list in a hash slot */ + SLIST_ENTRY(dn_flow_set) next; /* linked list in a hash slot */ - u_short fs_nr ; /* flow_set number */ + u_short fs_nr ; /* flow_set number */ u_short flags_fs; #define DNOLD_HAVE_FLOW_MASK 0x0001 -#define DNOLD_IS_RED 0x0002 +#define DNOLD_IS_RED 0x0002 #define DNOLD_IS_GENTLE_RED 0x0004 -#define DNOLD_QSIZE_IS_BYTES 0x0008 /* queue size is measured in bytes */ -#define DNOLD_NOERROR 0x0010 /* do not report ENOBUFS on drops */ -#define DNOLD_HAS_PROFILE 0x0020 /* the pipe has a delay profile. */ -#define DNOLD_IS_PIPE 0x4000 -#define DNOLD_IS_QUEUE 0x8000 +#define DNOLD_QSIZE_IS_BYTES 0x0008 /* queue size is measured in bytes */ +#define DNOLD_NOERROR 0x0010 /* do not report ENOBUFS on drops */ +#define DNOLD_HAS_PROFILE 0x0020 /* the pipe has a delay profile. */ +#define DNOLD_IS_PIPE 0x4000 +#define DNOLD_IS_QUEUE 0x8000 - struct dn_pipe7 *pipe ; /* pointer to parent pipe */ - u_short parent_nr ; /* parent pipe#, 0 if local to a pipe */ + struct dn_pipe7 *pipe ; /* pointer to parent pipe */ + u_short parent_nr ; /* parent pipe#, 0 if local to a pipe */ - int weight ; /* WFQ queue weight */ - int qsize ; /* queue size in slots or bytes */ - int plr ; /* pkt loss rate (2^31-1 means 100%) */ + int weight ; /* WFQ queue weight */ + int qsize ; /* queue size in slots or bytes */ + int plr[4] ; /* pkt loss rate (2^31-1 means 100%) */ struct ipfw_flow_id flow_mask ; /* hash table of queues onto this flow_set */ - int rq_size ; /* number of slots */ - int rq_elements ; /* active elements */ - struct dn_flow_queue7 **rq; /* array of rq_size entries */ + int rq_size ; /* number of slots */ + int rq_elements ; /* active elements */ + struct dn_flow_queue7 **rq ; /* array of rq_size entries */ - u_int32_t last_expired ; /* do not expire too frequently */ - int backlogged ; /* #active queues for this flowset */ + u_int32_t last_expired ; /* do not expire too frequently */ + int backlogged ; /* #active queues for this flowset */ /* RED parameters */ #define SCALE_RED 16 @@ -420,7 +420,10 @@ dn_compat_config_queue(struct dn_fs *fs, void* v) fs->flow_mask = f->flow_mask; fs->buckets = f->rq_size; fs->qsize = f->qsize; - fs->plr = f->plr; + fs->plr[0] = f->plr[0]; + fs->plr[1] = f->plr[1]; + fs->plr[2] = f->plr[2]; + fs->plr[3] = f->plr[3]; fs->par[0] = f->weight; fs->flags = convertflags2new(f->flags_fs); if (fs->flags & DN_IS_GENTLE_RED || fs->flags & DN_IS_RED) { @@ -645,7 +648,10 @@ dn_c_copy_pipe(struct dn_schk *s, struct copy_args *a, int nq) fs->parent_nr = l->link_nr - DN_MAX_ID; fs->qsize = f->fs.qsize; - fs->plr = f->fs.plr; + fs->plr[0] = f->fs.plr[0]; + fs->plr[1] = f->fs.plr[1]; + fs->plr[2] = f->fs.plr[2]; + fs->plr[3] = f->fs.plr[3]; fs->w_q = f->fs.w_q; fs->max_th = f->max_th; fs->min_th = f->min_th; @@ -698,7 +704,10 @@ dn_c_copy_fs(struct dn_fsk *f, struct copy_args *a, int nq) fs->next.sle_next = (struct dn_flow_set *)DN_IS_QUEUE; fs->fs_nr = f->fs.fs_nr; fs->qsize = f->fs.qsize; - fs->plr = f->fs.plr; + fs->plr[0] = f->fs.plr[0]; + fs->plr[1] = f->fs.plr[1]; + fs->plr[2] = f->fs.plr[2]; + fs->plr[3] = f->fs.plr[3]; fs->w_q = f->fs.w_q; fs->max_th = f->max_th; fs->min_th = f->min_th; diff --git a/sys/netpfil/ipfw/ip_dn_io.c b/sys/netpfil/ipfw/ip_dn_io.c index 3e6bd0e229b5..03116cb0641c 100644 --- a/sys/netpfil/ipfw/ip_dn_io.c +++ b/sys/netpfil/ipfw/ip_dn_io.c @@ -497,8 +497,28 @@ dn_enqueue(struct dn_queue *q, struct mbuf* m, int drop) ni->tot_pkts++; if (drop) goto drop; - if (f->plr && random() < f->plr) - goto drop; + if (f->plr[0] || f->plr[1]) { + if (__predict_true(f->plr[1] == 0)) { + if (random() < f->plr[0]) + goto drop; + } else { + switch (f->pl_state) { + case PLR_STATE_B: + if (random() < f->plr[3]) + f->pl_state = PLR_STATE_G; + if (random() < f->plr[2]) + goto drop; + break; + case PLR_STATE_G: /* FALLTHROUGH */ + default: + if (random() < f->plr[1]) + f->pl_state = PLR_STATE_B; + if (random() < f->plr[0]) + goto drop; + break; + } + } + } if (m->m_pkthdr.rcvif != NULL) m_rcvif_serialize(m); #ifdef NEW_AQM diff --git a/sys/netpfil/ipfw/ip_dn_private.h b/sys/netpfil/ipfw/ip_dn_private.h index ea5b809d8d28..756a997b6ec3 100644 --- a/sys/netpfil/ipfw/ip_dn_private.h +++ b/sys/netpfil/ipfw/ip_dn_private.h @@ -392,6 +392,15 @@ enum { PROTO_IFB = 0x0c, /* layer2 + ifbridge */ }; +/* + * States for the Packet Loss Rate Gilbert-Elliott + * channel model + */ +enum { + PLR_STATE_G = 0, + PLR_STATE_B, +}; + //extern struct dn_parms V_dn_cfg; VNET_DECLARE(struct dn_parms, dn_cfg); #define V_dn_cfg VNET(dn_cfg) diff --git a/tests/sys/netpfil/common/dummynet.sh b/tests/sys/netpfil/common/dummynet.sh index 14d863d001c8..e5ffd3836dfc 100644 --- a/tests/sys/netpfil/common/dummynet.sh +++ b/tests/sys/netpfil/common/dummynet.sh @@ -517,6 +517,102 @@ nat_cleanup() firewall_cleanup $1 } +pls_basic_head() +{ + atf_set descr 'Basic dummynet packet loss rate test' + atf_set require.user root +} + +pls_basic_body() +{ + fw=$1 + firewall_init $fw + dummynet_init $fw + + epair=$(vnet_mkepair) + vnet_mkjail alcatraz ${epair}b + + ifconfig ${epair}a 192.0.2.1/24 up + jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up + + firewall_config alcatraz ${fw} \ + "ipfw" \ + "ipfw add 65432 ip from any to any" \ + "pf" \ + "pass on ${epair}b" + + # Sanity check + atf_check -s exit:0 -o match:'100 packets transmitted, 100 packets received' ping -i .1 -c 100 192.0.2.2 + + jexec alcatraz dnctl pipe 1 config plr 0.1 + + firewall_config alcatraz ${fw} \ + "ipfw" \ + "ipfw add 1000 pipe 1 ip from 192.0.2.1 to 192.0.2.2" \ + "pf" \ + "pass on ${epair}b dnpipe 1" + + # check if the expected number of pings + # are dropped (84 - 96 responses). + # repeat up to 6 times if the initial + # checks fail + atf_check -s exit:0 -o match:'100 packets transmitted, (8[4-9]|9[0-6]) packets received' -r 6:10 ping -i 0.010 -c 100 192.0.2.2 +} + +pls_basic_cleanup() +{ + firewall_cleanup $1 +} + +pls_gilbert_head() +{ + atf_set descr 'dummynet Gilbert-Elliott packet loss model test' + atf_set require.user root +} + +pls_gilbert_body() +{ + fw=$1 + firewall_init $fw + dummynet_init $fw + + epair=$(vnet_mkepair) + vnet_mkjail alcatraz ${epair}b + + ifconfig ${epair}a 192.0.2.1/24 up + jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up + + firewall_config alcatraz ${fw} \ + "ipfw" \ + "ipfw add 65432 ip from any to any" \ + "pf" \ + "pass on ${epair}b" + + # Sanity check + atf_check -s exit:0 -o match:'100 packets transmitted, 100 packets received' ping -i .1 -c 100 192.0.2.2 + + jexec alcatraz dnctl pipe 1 config plr 0.01,0.1,0.8,0.2 + + firewall_config alcatraz ${fw} \ + "ipfw" \ + "ipfw add 1000 pipe 1 ip from 192.0.2.1 to 192.0.2.2" \ + "pf" \ + "pass on ${epair}b dnpipe 1" + + # check if the expected number of pings + # are dropped (70 - 85 responses). + # repeat up to 6 times if the initial + # checks fail + atf_check -s exit:0 -o match:'100 packets transmitted, (7[0-9]|8[0-5]) packets received' -r 6:10 ping -i 0.010 -c 100 192.0.2.2 +} + +pls_gilbert_cleanup() +{ + firewall_cleanup $1 +} + + + setup_tests \ interface_removal \ ipfw \ @@ -539,4 +635,10 @@ setup_tests \ ipfw \ pf \ nat \ + pf \ + pls_basic \ + ipfw \ + pf \ + pls_gilbert \ + ipfw \ pf