Skip to content

Commit

Permalink
Merge branch 'ovs-selftests'
Browse files Browse the repository at this point in the history
From: Aaron Conole <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
	[email protected], Pravin B Shelar <[email protected]>,
	"David S. Miller" <[email protected]>,
	Eric Dumazet <[email protected]>,
	Jakub Kicinski <[email protected]>, Paolo Abeni <[email protected]>,
	Adrian Moreno <[email protected]>,
	Eelco Chaudron <[email protected]>,
	[email protected]
Subject: [PATCH net v2 0/4] selftests: openvswitch: Minor fixes for some systems
Date: Wed, 11 Oct 2023 15:49:35 -0400	[thread overview]
Message-ID: <[email protected]> (raw)

A number of corner cases were caught when trying to run the selftests on
older systems.  Missed skip conditions, some error cases, and outdated
python setups would all report failures but the issue would actually be
related to some other condition rather than the selftest suite.

Address these individual cases.
====================

Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Oct 15, 2023
2 parents fc8b2a6 + 8eff0e0 commit 883f0dc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
21 changes: 20 additions & 1 deletion tools/testing/selftests/net/openvswitch/openvswitch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# OVS kernel module self tests

trap ovs_exit_sig EXIT TERM INT ERR

# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4

Expand Down Expand Up @@ -142,6 +144,12 @@ ovs_add_flow () {
return 0
}

ovs_del_flows () {
info "Deleting all flows from DP: sbx:$1 br:$2"
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-flows "$2"
return 0
}

ovs_drop_record_and_run () {
local sbx=$1
shift
Expand Down Expand Up @@ -198,6 +206,17 @@ test_drop_reason() {
ip netns exec server ip addr add 172.31.110.20/24 dev s1
ip netns exec server ip link set s1 up

# Check if drop reasons can be sent
ovs_add_flow "test_drop_reason" dropreason \
'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(10)' 2>/dev/null
if [ $? == 1 ]; then
info "no support for drop reasons - skipping"
ovs_exit_sig
return $ksft_skip
fi

ovs_del_flows "test_drop_reason" dropreason

# Allow ARP
ovs_add_flow "test_drop_reason" dropreason \
'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
Expand Down Expand Up @@ -525,7 +544,7 @@ run_test() {
fi

if python3 ovs-dpctl.py -h 2>&1 | \
grep "Need to install the python" >/dev/null 2>&1; then
grep -E "Need to (install|upgrade) the python" >/dev/null 2>&1; then
stdbuf -o0 printf "TEST: %-60s [PYLIB]\n" "${tdesc}"
return $ksft_skip
fi
Expand Down
48 changes: 46 additions & 2 deletions tools/testing/selftests/net/openvswitch/ovs-dpctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
from pyroute2.netlink import nlmsg_atoms
from pyroute2.netlink.exceptions import NetlinkError
from pyroute2.netlink.generic import GenericNetlinkSocket
import pyroute2

except ModuleNotFoundError:
print("Need to install the python pyroute2 package.")
print("Need to install the python pyroute2 package >= 0.6.")
sys.exit(0)


Expand Down Expand Up @@ -1117,12 +1119,14 @@ class ovs_key_ct_tuple_ipv4(ovs_key_proto):
"src",
lambda x: str(ipaddress.IPv4Address(x)),
int,
convert_ipv4,
),
(
"dst",
"dst",
lambda x: str(ipaddress.IPv6Address(x)),
lambda x: str(ipaddress.IPv4Address(x)),
int,
convert_ipv4,
),
("tp_src", "tp_src", "%d", int),
("tp_dst", "tp_dst", "%d", int),
Expand Down Expand Up @@ -1904,6 +1908,32 @@ def add_flow(self, dpifindex, flowmsg):
raise ne
return reply

def del_flows(self, dpifindex):
"""
Send a del message to the kernel that will drop all flows.
dpifindex should be a valid datapath obtained by calling
into the OvsDatapath lookup
"""

flowmsg = OvsFlow.ovs_flow_msg()
flowmsg["cmd"] = OVS_FLOW_CMD_DEL
flowmsg["version"] = OVS_DATAPATH_VERSION
flowmsg["reserved"] = 0
flowmsg["dpifindex"] = dpifindex

try:
reply = self.nlm_request(
flowmsg,
msg_type=self.prid,
msg_flags=NLM_F_REQUEST | NLM_F_ACK,
)
reply = reply[0]
except NetlinkError as ne:
print(flowmsg)
raise ne
return reply

def dump(self, dpifindex, flowspec=None):
"""
Returns a list of messages containing flows.
Expand Down Expand Up @@ -1998,6 +2028,12 @@ def main(argv):
nlmsg_atoms.ovskey = ovskey
nlmsg_atoms.ovsactions = ovsactions

# version check for pyroute2
prverscheck = pyroute2.__version__.split(".")
if int(prverscheck[0]) == 0 and int(prverscheck[1]) < 6:
print("Need to upgrade the python pyroute2 package to >= 0.6.")
sys.exit(0)

parser = argparse.ArgumentParser()
parser.add_argument(
"-v",
Expand Down Expand Up @@ -2060,6 +2096,9 @@ def main(argv):
addflcmd.add_argument("flow", help="Flow specification")
addflcmd.add_argument("acts", help="Flow actions")

delfscmd = subparsers.add_parser("del-flows")
delfscmd.add_argument("flsbr", help="Datapath name")

args = parser.parse_args()

if args.verbose > 0:
Expand Down Expand Up @@ -2143,6 +2182,11 @@ def main(argv):
flow = OvsFlow.ovs_flow_msg()
flow.parse(args.flow, args.acts, rep["dpifindex"])
ovsflow.add_flow(rep["dpifindex"], flow)
elif hasattr(args, "flsbr"):
rep = ovsdp.info(args.flsbr, 0)
if rep is None:
print("DP '%s' not found." % args.flsbr)
ovsflow.del_flows(rep["dpifindex"])

return 0

Expand Down

0 comments on commit 883f0dc

Please sign in to comment.