netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jhs@mojatatu.com, xiyou.wangcong@gmail.com,
	jakub.kicinski@netronome.com, simon.horman@netronome.com,
	john.hurley@netronome.com, dsahern@gmail.com, mlxsw@mellanox.com,
	sridhar.samudrala@intel.com
Subject: [patch net-next v2 9/9] selftests: forwarding: add tests for TC chain templates
Date: Thu, 28 Jun 2018 15:09:07 +0200	[thread overview]
Message-ID: <20180628130907.951-10-jiri@resnulli.us> (raw)
In-Reply-To: <20180628130907.951-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

Add basic sanity tests for TC chain templates.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- adjust to the userspace cmdline changes
---
 tools/testing/selftests/net/forwarding/lib.sh      |   9 ++
 .../selftests/net/forwarding/tc_chaintemplates.sh  | 160 +++++++++++++++++++++
 2 files changed, 169 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/tc_chaintemplates.sh

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index df589ac1eac0..20be128709b1 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -39,6 +39,15 @@ check_tc_shblock_support()
 	fi
 }
 
+check_tc_chaintemplate_support()
+{
+	tc help 2>&1|grep chaintemplate &> /dev/null
+	if [[ $? -ne 0 ]]; then
+		echo "SKIP: iproute2 too old; tc is missing chain template support"
+		exit 1
+	fi
+}
+
 if [[ "$(id -u)" -ne 0 ]]; then
 	echo "SKIP: need root privileges"
 	exit 0
diff --git a/tools/testing/selftests/net/forwarding/tc_chaintemplates.sh b/tools/testing/selftests/net/forwarding/tc_chaintemplates.sh
new file mode 100755
index 000000000000..fb47ea1e30e0
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/tc_chaintemplates.sh
@@ -0,0 +1,160 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ALL_TESTS="template_create_destroy template_filter_fits \
+	   template_create_nonempty template_destroy_nonempty"
+NUM_NETIFS=2
+source tc_common.sh
+source lib.sh
+
+h1_create()
+{
+	simple_if_init $h1 192.0.2.1/24
+}
+
+h1_destroy()
+{
+	simple_if_fini $h1 192.0.2.1/24
+}
+
+h2_create()
+{
+	simple_if_init $h2 192.0.2.2/24
+	tc qdisc add dev $h2 clsact
+}
+
+h2_destroy()
+{
+	tc qdisc del dev $h2 clsact
+	simple_if_fini $h2 192.0.2.2/24
+}
+
+template_create_destroy()
+{
+	RET=0
+
+	tc chaintemplate add dev $h2 ingress protocol ip \
+		flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF
+	check_err $? "Failed to create template for default chain"
+
+	tc chaintemplate add dev $h2 ingress chain 1 protocol ip \
+		flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF
+	check_err $? "Failed to create template for chain 1"
+
+	tc chaintemplate del dev $h2 ingress
+	check_err $? "Failed to destroy template for default chain"
+
+	tc chaintemplate del dev $h2 ingress chain 1
+	check_err $? "Failed to destroy template for chain 1"
+
+	log_test "template create destroy"
+}
+
+template_filter_fits()
+{
+	RET=0
+
+	tc chaintemplate add dev $h2 ingress protocol ip \
+		flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
+	tc chaintemplate add dev $h2 ingress chain 1 protocol ip \
+		flower src_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
+
+	tc filter add dev $h2 ingress protocol ip pref 1 handle 1101 \
+		flower dst_mac $h2mac action drop
+	check_err $? "Failed to insert filter which fits template"
+
+	tc filter add dev $h2 ingress protocol ip pref 1 handle 1102 \
+		flower src_mac $h2mac action drop &> /dev/null
+	check_fail $? "Incorrectly succeded to insert filter which does not template"
+
+	tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
+		flower src_mac $h2mac action drop
+	check_err $? "Failed to insert filter which fits template"
+
+	tc filter add dev $h2 ingress chain 1protocol ip pref 1 handle 1102 \
+		flower dst_mac $h2mac action drop &> /dev/null
+	check_fail $? "Incorrectly succeded to insert filter which does not template"
+
+	tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1102 \
+		flower &> /dev/null
+	tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
+		flower &> /dev/null
+
+	tc filter del dev $h2 ingress protocol ip pref 1 handle 1102 \
+		flower &> /dev/null
+	tc filter del dev $h2 ingress protocol ip pref 1 handle 1101 \
+		flower &> /dev/null
+
+	tc chaintemplate del dev $h2 ingress chain 1
+	tc chaintemplate del dev $h2 ingress
+
+	log_test "template filter fits"
+}
+
+template_create_nonempty()
+{
+	RET=0
+
+	tc filter add dev $h2 ingress protocol ip pref 1 handle 1101 \
+		flower dst_mac $h2mac action drop
+	tc chaintemplate add dev $h2 ingress protocol ip \
+		flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
+	check_fail $? "Incorrectly succeded to create template for non-empty chain"
+
+	tc chaintemplate del dev $h2 ingress &> /dev/null
+	tc filter del dev $h2 ingress protocol ip pref 1 handle 1101 flower
+
+	log_test "template create non-empty"
+}
+
+template_destroy_nonempty()
+{
+	RET=0
+
+	tc chaintemplate add dev $h2 ingress protocol ip \
+		flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF
+	tc filter add dev $h2 ingress protocol ip pref 1 handle 1101 \
+		flower dst_mac $h2mac action drop
+
+	tc chaintemplate del dev $h2 ingress &> /dev/null
+	check_fail $? "Incorrectly succeded to destroy template for non-empty chain"
+	tc filter del dev $h2 ingress protocol ip pref 1 handle 1101 flower
+	tc chaintemplate del dev $h2 ingress &> /dev/null
+	check_err $? "Failed to destroy template for empty chain"
+
+	log_test "template destroy non-empty"
+}
+
+setup_prepare()
+{
+	h1=${NETIFS[p1]}
+	h2=${NETIFS[p2]}
+	h1mac=$(mac_get $h1)
+	h2mac=$(mac_get $h2)
+
+	vrf_prepare
+
+	h1_create
+	h2_create
+}
+
+cleanup()
+{
+	pre_cleanup
+
+	h2_destroy
+	h1_destroy
+
+	vrf_cleanup
+}
+
+check_tc_chaintemplate_support
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
-- 
2.14.4

  parent reply	other threads:[~2018-06-28 13:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 13:08 [patch net-next v2 0/9] net: sched: introduce chain templates support with offloading to mlxsw Jiri Pirko
2018-06-28 13:08 ` [patch net-next v2 1/9] net: sched: push ops lookup bits into tcf_proto_lookup_ops() Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 2/9] net: sched: introduce chain templates Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 3/9] net: sched: cls_flower: move key/mask dumping into a separate function Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 4/9] net: sched: cls_flower: change fl_init_dissector to accept mask and dissector Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 5/9] net: sched: cls_flower: implement chain templates Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 6/9] net: sched: cls_flower: propagate chain teplate creation and destruction to drivers Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 7/9] mlxsw: spectrum: Implement chain template hinting Jiri Pirko
2018-06-28 13:09 ` [patch net-next v2 8/9] selftests: forwarding: move shblock tc support check to a separate helper Jiri Pirko
2018-06-28 13:09 ` Jiri Pirko [this message]
2018-06-28 13:10 ` [patch iproute2/net-next v2] tc: introduce support for chain templates Jiri Pirko
2018-06-28 13:24 ` [patch net-next v2 0/9] net: sched: introduce chain templates support with offloading to mlxsw Jiri Pirko
2018-06-28 14:18 ` David Ahern
2018-06-28 14:29   ` Jiri Pirko
2018-06-28 15:10     ` David Ahern
2018-06-28 15:37       ` Jiri Pirko
2018-06-28 15:50         ` David Ahern
2018-06-28 16:08           ` Jiri Pirko
2018-06-28 22:25 ` Cong Wang
2018-06-29  8:39   ` Jiri Pirko
2018-06-29 12:12     ` Jamal Hadi Salim
2018-06-29 12:48       ` Jiri Pirko
2018-06-29 12:54         ` David Ahern
2018-06-29 13:05           ` Jiri Pirko
2018-06-29 17:06             ` Samudrala, Sridhar
2018-06-29 22:18               ` Cong Wang
2018-06-30 10:12                 ` Jiri Pirko
2018-07-02 19:33                   ` Cong Wang
2018-06-29 13:32           ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2018-06-26  7:59 Jiri Pirko
2018-06-26  8:00 ` [patch net-next v2 9/9] selftests: forwarding: add tests for TC chain templates Jiri Pirko

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=20180628130907.951-10-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jhs@mojatatu.com \
    --cc=john.hurley@netronome.com \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=simon.horman@netronome.com \
    --cc=sridhar.samudrala@intel.com \
    --cc=xiyou.wangcong@gmail.com \
    /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).