Skip to content

Commit 918423f

Browse files
apconolePaolo Abeni
authored andcommitted
selftests: openvswitch: add an initial flow programming case
The openvswitch self-tests can test much of the control side of the module (ie: what a vswitchd implementation would process), but the actual packet forwarding cases aren't supported, making the testing of limited value. Add some flow parsing and an initial ARP based test case using arping utility. This lets us display flows, add some basic output flows with simple matches, and test against a known good forwarding case. Signed-off-by: Aaron Conole <[email protected]> Reviewed-by: Adrian Moreno <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent ce650a1 commit 918423f

File tree

2 files changed

+458
-0
lines changed

2 files changed

+458
-0
lines changed

tools/testing/selftests/net/openvswitch/openvswitch.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ VERBOSE=0
1111
TRACING=0
1212

1313
tests="
14+
arp_ping eth-arp: Basic arp ping between two NS
1415
netlink_checks ovsnl: validate netlink attrs and settings
1516
upcall_interfaces ovs: test the upcall interfaces"
1617

@@ -127,6 +128,16 @@ ovs_add_netns_and_veths () {
127128
return 0
128129
}
129130

131+
ovs_add_flow () {
132+
info "Adding flow to DP: sbx:$1 br:$2 flow:$3 act:$4"
133+
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-flow "$2" "$3" "$4"
134+
if [ $? -ne 0 ]; then
135+
echo "Flow [ $3 : $4 ] failed" >> ${ovs_dir}/debug.log
136+
return 1
137+
fi
138+
return 0
139+
}
140+
130141
usage() {
131142
echo
132143
echo "$0 [OPTIONS] [TEST]..."
@@ -141,6 +152,46 @@ usage() {
141152
exit 1
142153
}
143154

155+
# arp_ping test
156+
# - client has 1500 byte MTU
157+
# - server has 1500 byte MTU
158+
# - send ARP ping between two ns
159+
test_arp_ping () {
160+
161+
which arping >/dev/null 2>&1 || return $ksft_skip
162+
163+
sbx_add "test_arp_ping" || return $?
164+
165+
ovs_add_dp "test_arp_ping" arpping || return 1
166+
167+
info "create namespaces"
168+
for ns in client server; do
169+
ovs_add_netns_and_veths "test_arp_ping" "arpping" "$ns" \
170+
"${ns:0:1}0" "${ns:0:1}1" || return 1
171+
done
172+
173+
# Setup client namespace
174+
ip netns exec client ip addr add 172.31.110.10/24 dev c1
175+
ip netns exec client ip link set c1 up
176+
HW_CLIENT=`ip netns exec client ip link show dev c1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
177+
info "Client hwaddr: $HW_CLIENT"
178+
179+
# Setup server namespace
180+
ip netns exec server ip addr add 172.31.110.20/24 dev s1
181+
ip netns exec server ip link set s1 up
182+
HW_SERVER=`ip netns exec server ip link show dev s1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
183+
info "Server hwaddr: $HW_SERVER"
184+
185+
ovs_add_flow "test_arp_ping" arpping \
186+
"in_port(1),eth(),eth_type(0x0806),arp(sip=172.31.110.10,tip=172.31.110.20,sha=$HW_CLIENT,tha=ff:ff:ff:ff:ff:ff)" '2' || return 1
187+
ovs_add_flow "test_arp_ping" arpping \
188+
"in_port(2),eth(),eth_type(0x0806),arp()" '1' || return 1
189+
190+
ovs_sbx "test_arp_ping" ip netns exec client arping -I c1 172.31.110.20 -c 1 || return 1
191+
192+
return 0
193+
}
194+
144195
# netlink_validation
145196
# - Create a dp
146197
# - check no warning with "old version" simulation

0 commit comments

Comments
 (0)