Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Mar 2021 15:17:53 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 5b8932427605 - stable/12 - bridge test: spanning tree
Message-ID:  <202103021517.122FHr1R039705@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=5b893242760570495abb09974455ab32a8fd6b95

commit 5b893242760570495abb09974455ab32a8fd6b95
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2020-03-10 06:28:45 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-03-02 13:03:06 +0000

    bridge test: spanning tree
    
    Basic test case where we create a bridge loop, verify that we really are
    looping and then enable spanning tree to resolve the loop.
    
    Reviewed by:    philip
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D23959
    
    (cherry picked from commit 6f0a65b080aac1b3144c7489b020b26b345d1a1b)
---
 tests/sys/net/if_bridge_test.sh | 69 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tests/sys/net/if_bridge_test.sh b/tests/sys/net/if_bridge_test.sh
index c51321187018..afb260a86cc3 100755
--- a/tests/sys/net/if_bridge_test.sh
+++ b/tests/sys/net/if_bridge_test.sh
@@ -67,7 +67,76 @@ bridge_transmit_ipv4_unicast_cleanup()
 	vnet_cleanup
 }
 
+atf_test_case "stp" "cleanup"
+stp_head()
+{
+	atf_set descr 'Spanning tree test'
+	atf_set require.user root
+	atf_set require.progs jq
+}
+
+stp_body()
+{
+	vnet_init
+
+	epair_one=$(vnet_mkepair)
+	epair_two=$(vnet_mkepair)
+	bridge_a=$(vnet_mkbridge)
+	bridge_b=$(vnet_mkbridge)
+
+	vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
+	vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
+
+	jexec a ifconfig ${bridge_a} up
+	jexec a ifconfig ${epair_one}a up
+	jexec a ifconfig ${epair_two}a up
+	jexec a ifconfig ${bridge_a} addm ${epair_one}a
+	jexec a ifconfig ${bridge_a} addm ${epair_two}a
+
+	jexec b ifconfig ${bridge_b} up
+	jexec b ifconfig ${epair_one}b up
+	jexec b ifconfig ${epair_two}b up
+	jexec b ifconfig ${bridge_b} addm ${epair_one}b
+	jexec b ifconfig ${bridge_b} addm ${epair_two}b
+
+	jexec a ifconfig ${bridge_a} 192.0.2.1/24
+
+	# Give the interfaces some time to come up and pass some traffic
+	sleep 5
+
+	# Confirm that there's looping traffic
+	nbr=$(jexec a netstat -I ${bridge_a} --libxo json \
+		| jq ".statistics.interface[0].\"received-packets\"")
+	if [ ${nbr} -lt 100 ]
+	then
+		atf_fail "Expected bridging loop, but found very few packets."
+	fi
+
+	# Enable spanning tree
+	jexec a ifconfig ${bridge_a} stp ${epair_one}a
+	jexec a ifconfig ${bridge_a} stp ${epair_two}a
+	jexec b ifconfig ${bridge_b} stp ${epair_one}b
+	jexec b ifconfig ${bridge_b} stp ${epair_two}b
+
+	# Give STP time to do its thing
+	sleep 5
+
+	a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
+	b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
+
+	if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
+	then
+		atf_fail "STP failed to detect bridging loop"
+	fi
+}
+
+stp_cleanup()
+{
+	vnet_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case "bridge_transmit_ipv4_unicast"
+	atf_add_test_case "stp"
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103021517.122FHr1R039705>