netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 4/4] meta: add tests for probability matching
Date: Thu,  3 Mar 2016 18:56:54 +0100	[thread overview]
Message-ID: <1457027814-14795-3-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1457027814-14795-1-git-send-email-fw@strlen.de>

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 tests/py/any/meta.t         | 16 ++++++++++++++++
 tests/py/any/meta.t.payload | 15 +++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/tests/py/any/meta.t b/tests/py/any/meta.t
index c10297a..4fa961f 100644
--- a/tests/py/any/meta.t
+++ b/tests/py/any/meta.t
@@ -197,3 +197,19 @@ meta cgroup {1048577-1048578};ok;cgroup { 1048577-1048578}
 meta iif . meta oif { lo . eth0 };ok
 meta iif . meta oif . meta mark { lo . eth0 . 0x0000000a };ok
 meta iif . meta oif vmap { lo . eth0 : drop };ok
+
+meta probability 0.0000001;ok
+meta probability 0.5;ok;meta probability 0.5000000
+meta probability 0.9999999;ok
+
+# outside of supported precision range
+meta probability 0.00000001;fail
+meta probability 0.99999999;fail
+
+# meta probability cannot be used with operators
+meta probability eq 0.5;fail
+
+# not 0.xxx format
+meta probability 1.5;fail
+meta probability foobar;fail
+meta probability 0;fail
diff --git a/tests/py/any/meta.t.payload b/tests/py/any/meta.t.payload
index 9f7a6d9..7c5eb72 100644
--- a/tests/py/any/meta.t.payload
+++ b/tests/py/any/meta.t.payload
@@ -754,3 +754,18 @@ ip test-ip4 output
   [ meta load oif => reg 9 ]
   [ lookup reg 1 set map%d dreg 0 ]
 
+# meta probability 0.0000001
+ip test-ip4 input
+  [ meta load prandom => reg 1 ]
+  [ cmp lte reg 1 0xad010000 ]
+
+# meta probability 0.5
+ip test-ip4 input
+  [ meta load prandom => reg 1 ]
+  [ cmp lte reg 1 0xffffff7f ]
+
+# meta probability 0.9999999
+ip test-ip4 input
+  [ meta load prandom => reg 1 ]
+  [ cmp lte reg 1 0x51feffff ]
+
-- 
2.4.10


      parent reply	other threads:[~2016-03-03 17:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03 17:56 [PATCH nft 1/3] expression: add helper to decide if operator needs to be shown Florian Westphal
2016-03-03 17:56 ` [PATCH nft 3/4] meta: add probability matching Florian Westphal
2016-03-03 19:36   ` Jan Engelhardt
2016-03-03 20:32     ` Florian Westphal
2016-03-03 20:45       ` Jan Engelhardt
2016-03-04 11:12         ` Florian Westphal
2016-03-04 12:34           ` Jan Engelhardt
2016-03-04 13:13             ` Florian Westphal
2016-03-03 17:56 ` Florian Westphal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457027814-14795-3-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).