summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2020-05-06 07:48:37 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2020-05-06 07:48:37 +0000
commit768c98a737ef957ee26afd30d5e2a7e83b97e34f (patch)
tree37942b93865d3502895a7466f17b859c6bbc293c /tests
parent6fd36c3b7af51a7af730edd9fa5bff04c493abf9 (diff)
downloadsrc-test-768c98a737ef957ee26afd30d5e2a7e83b97e34f.tar.gz
src-test-768c98a737ef957ee26afd30d5e2a7e83b97e34f.zip
Add basic routing LPM tests.
Differential Revision: https://reviews.freebsd.org/D24684
Notes
Notes: svn path=/head/; revision=360685
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/netinet/Makefile2
-rwxr-xr-xtests/sys/netinet/lpm.sh179
-rw-r--r--tests/sys/netinet6/Makefile3
-rwxr-xr-xtests/sys/netinet6/lpm6.sh199
4 files changed, 381 insertions, 2 deletions
diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index d873f61130908..53de955cc31ef 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -9,7 +9,7 @@ ATF_TESTS_C= ip_reass_test \
so_reuseport_lb_test \
socket_afinet
-ATF_TESTS_SH= carp fibs_test redirect divert forward output
+ATF_TESTS_SH= carp fibs_test redirect divert forward output lpm
PROGS= udp_dontroute tcp_user_cookie
diff --git a/tests/sys/netinet/lpm.sh b/tests/sys/netinet/lpm.sh
new file mode 100755
index 0000000000000..148e53391819e
--- /dev/null
+++ b/tests/sys/netinet/lpm.sh
@@ -0,0 +1,179 @@
+#!/usr/bin/env atf-sh
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2020 Alexander V. Chernikov
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+. $(atf_get_srcdir)/../common/vnet.subr
+
+setup_networking()
+{
+ jname="$1"
+ lo_dst="$2"
+ epair0="$3"
+ epair1="$4"
+
+ vnet_mkjail ${jname}a ${epair0}a ${epair1}a
+ # Setup transit IPv4 networks
+ jexec ${jname}a ifconfig ${epair0}a up
+ jexec ${jname}a ifconfig ${epair0}a inet 203.0.113.1/30
+ jexec ${jname}a ifconfig ${epair1}a up
+ jexec ${jname}a ifconfig ${epair1}a inet 203.0.113.5/30
+
+ vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
+ jexec ${jname}b ifconfig ${epair0}b up
+ jexec ${jname}b ifconfig ${epair0}b inet 203.0.113.2/30
+ jexec ${jname}b ifconfig ${epair1}b up
+ jexec ${jname}b ifconfig ${epair1}b inet 203.0.113.6/30
+ jexec ${jname}b ifconfig ${lo_dst} up
+
+}
+
+atf_test_case "lpm_test1_success" "cleanup"
+lpm_test1_success_head()
+{
+
+ atf_set descr 'Test IPv4 LPM for /30 and /31'
+ atf_set require.user root
+}
+
+lpm_test1_success_body()
+{
+
+ vnet_init
+
+ jname="v4t-lpm_test1_success"
+
+ lo_dst=$(vnet_mkloopback)
+ epair0=$(vnet_mkepair)
+ epair1=$(vnet_mkepair)
+
+ setup_networking ${jname} ${lo_dst} ${epair0} ${epair1}
+
+ jexec ${jname}b ifconfig ${lo_dst} inet 198.51.100.0/32
+ jexec ${jname}b ifconfig ${lo_dst} alias 198.51.100.2/32
+
+ # Add routes
+ # A -> towards B via epair0a
+ jexec ${jname}a route add -4 -net 198.51.100.0/30 203.0.113.2
+ # A -> towards B via epair1a
+ jexec ${jname}a route add -4 -net 198.51.100.0/31 203.0.113.6
+
+ count=20
+ valid_message="${count} packets transmitted, ${count} packets received"
+
+ # Check that 198.51.100.0 goes via epair1
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping -f -nc${count} 198.51.100.0
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_1} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})"
+ exit 1
+ fi
+
+ # Check that 198.51.100.2 goes via epair0
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping -f -nc${count} 198.51.100.2
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_0} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}"
+ exit 1
+ fi
+
+ echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
+}
+
+lpm_test1_success_cleanup()
+{
+ vnet_cleanup
+}
+
+atf_test_case "lpm_test2_success" "cleanup"
+lpm_test2_success_head()
+{
+
+ atf_set descr 'Test IPv4 LPM for the host routes'
+ atf_set require.user root
+}
+
+lpm_test2_success_body()
+{
+
+ vnet_init
+
+ jname="v4t-lpm_test2_success"
+
+ lo_dst=$(vnet_mkloopback)
+ epair0=$(vnet_mkepair)
+ epair1=$(vnet_mkepair)
+
+ setup_networking ${jname} ${lo_dst} ${epair0} ${epair1}
+
+ jexec ${jname}b ifconfig ${lo_dst} inet 198.51.100.0/32
+ jexec ${jname}b ifconfig ${lo_dst} alias 198.51.100.1/32
+
+ # Add routes
+ # A -> towards B via epair0a
+ jexec ${jname}a route add -4 -host 198.51.100.0 203.0.113.2
+ # A -> towards B via epair1a
+ jexec ${jname}a route add -4 -host 198.51.100.1 203.0.113.6
+
+ count=20
+ valid_message="${count} packets transmitted, ${count} packets received"
+
+ # Check that 198.51.100.0 goes via epair0
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping -f -nc${count} 198.51.100.0
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_0} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}"
+ exit 1
+ fi
+
+ # Check that 198.51.100.1 goes via epair1
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping -f -nc${count} 198.51.100.1
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_1} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})"
+ exit 1
+ fi
+
+ echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
+}
+
+lpm_test2_success_cleanup()
+{
+ vnet_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "lpm_test1_success"
+ atf_add_test_case "lpm_test2_success"
+}
+
diff --git a/tests/sys/netinet6/Makefile b/tests/sys/netinet6/Makefile
index e9f77bca1a7b0..49ccd23f05023 100644
--- a/tests/sys/netinet6/Makefile
+++ b/tests/sys/netinet6/Makefile
@@ -12,7 +12,8 @@ ATF_TESTS_SH= \
redirect \
divert \
forward6 \
- output6
+ output6 \
+ lpm6
${PACKAGE}FILES+= exthdr.py
${PACKAGE}FILES+= mld.py
diff --git a/tests/sys/netinet6/lpm6.sh b/tests/sys/netinet6/lpm6.sh
new file mode 100755
index 0000000000000..937fd83d167b8
--- /dev/null
+++ b/tests/sys/netinet6/lpm6.sh
@@ -0,0 +1,199 @@
+#!/usr/bin/env atf-sh
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2020 Alexander V. Chernikov
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+
+. $(atf_get_srcdir)/../common/vnet.subr
+
+setup_networking()
+{
+ jname="$1"
+ lo_dst="$2"
+ epair0="$3"
+ epair1="$4"
+
+ vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src}
+ # enable link-local IPv6
+ jexec ${jname}a ndp -i ${epair0}a -- -disabled
+ jexec ${jname}a ifconfig ${epair0}a up
+ jexec ${jname}a ndp -i ${epair1}a -- -disabled
+ jexec ${jname}a ifconfig ${epair1}a up
+ jexec ${jname}a ifconfig ${lo_src} up
+
+ vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst}
+ jexec ${jname}b ndp -i ${epair0}b -- -disabled
+ jexec ${jname}b ifconfig ${epair0}b up
+ jexec ${jname}b ndp -i ${epair1}b -- -disabled
+ jexec ${jname}b ifconfig ${epair1}b up
+ jexec ${jname}b ifconfig ${lo_dst} up
+
+ # wait for DAD to complete
+ while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
+ sleep 0.1
+ done
+ while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
+ sleep 0.1
+ done
+}
+
+
+atf_test_case "lpm6_test1_success" "cleanup"
+lpm6_test1_success_head()
+{
+
+ atf_set descr 'Test IPv6 LPM for the host routes'
+ atf_set require.user root
+}
+
+lpm6_test1_success_body()
+{
+
+ vnet_init
+
+ net_dst="2001:db8:"
+
+ jname="v6t-lpm6_test1_success"
+
+ epair0=$(vnet_mkepair)
+ epair1=$(vnet_mkepair)
+ lo_dst=$(vnet_mkloopback)
+
+ setup_networking ${jname} ${lo_dst} ${epair0} ${epair1}
+
+ jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:0/128
+ jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:1/128
+
+ # Add routes
+ # A -> towards B via epair0a LL
+ ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
+ jexec ${jname}a route add -6 -host ${net_dst}:2:0 ${ll}%${epair0}a
+ # A -> towards B via epair1a LL
+ ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
+ jexec ${jname}a route add -6 -host ${net_dst}:2:1 ${ll}%${epair1}a
+
+ count=20
+ valid_message="${count} packets transmitted, ${count} packets received"
+
+ # Check that ${net_dst}:2:0 goes via epair0
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -f -nc${count} ${net_dst}:2:0
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_0} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}"
+ exit 1
+ fi
+
+ # Check that ${net_dst}:2:1 goes via epair1
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -f -nc${count} ${net_dst}:2:1
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_1} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})"
+ exit 1
+ fi
+
+ echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
+}
+
+lpm6_test1_success_cleanup()
+{
+ vnet_cleanup
+}
+
+atf_test_case "lpm6_test2_success" "cleanup"
+lpm6_test2_success_head()
+{
+
+ atf_set descr 'Test IPv6 LPM for /126 and /127'
+ atf_set require.user root
+}
+
+lpm6_test2_success_body()
+{
+
+ vnet_init
+
+ net_dst="2001:db8:"
+
+ jname="v6t-lpm6_test2_success"
+
+ epair0=$(vnet_mkepair)
+ epair1=$(vnet_mkepair)
+ lo_dst=$(vnet_mkloopback)
+
+ setup_networking ${jname} ${lo_dst} ${epair0} ${epair1}
+
+ jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:0/128
+ jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:2/128
+
+ # Add routes
+ # A -> towards B via epair0a LL
+ ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
+ jexec ${jname}a route add -6 -net ${net_dst}:2:0/126 ${ll}%${epair0}a
+ # A -> towards B via epair1a LL
+ ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
+ jexec ${jname}a route add -6 -net ${net_dst}:2:0/127 ${ll}%${epair1}a
+
+ count=20
+ valid_message="${count} packets transmitted, ${count} packets received"
+
+ # Check that ${net_dst}:2:0 goes via epair1
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -f -nc${count} ${net_dst}:2:0
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_1} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})"
+ exit 1
+ fi
+
+ # Check that ${net_dst}:2:2 goes via epair0
+ atf_check -o match:"${valid_message}" jexec ${jname}a ping6 -f -nc${count} ${net_dst}:2:2
+ pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'`
+ pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'`
+ if [ ${pkt_0} -le ${count} ]; then
+ echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}"
+ exit 1
+ fi
+
+ echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}"
+}
+
+lpm6_test2_success_cleanup()
+{
+ vnet_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case "lpm6_test1_success"
+ atf_add_test_case "lpm6_test2_success"
+}
+
+# end
+
+