]> www.infradead.org Git - users/willy/xarray.git/commitdiff
selftests: openvswitch: Skip drop testing on older kernels
authorAaron Conole <aconole@redhat.com>
Wed, 11 Oct 2023 19:49:38 +0000 (15:49 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sun, 15 Oct 2023 19:02:51 +0000 (20:02 +0100)
Kernels that don't have support for openvswitch drop reasons also
won't have the drop counter reasons, so we should skip the test
completely.  It previously wasn't possible to build a test case
for this without polluting the datapath, so we introduce a mechanism
to clear all the flows from a datapath allowing us to test for
explicit drop actions, and then clear the flows to build the
original test case.

Fixes: 4242029164d6 ("selftests: openvswitch: add explicit drop testcase")
Signed-off-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/openvswitch/openvswitch.sh
tools/testing/selftests/net/openvswitch/ovs-dpctl.py

index 2a0112be7ead588894904883a13dea1057d3438e..f8499d4c87f3f763e774619666e00ce6a17d333b 100755 (executable)
@@ -144,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
@@ -200,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
index e4c24d5edf20cb02b0521a1ab240c5974ef97aa6..10b8f31548f840f35bcda890b2d369abd850e794 100644 (file)
@@ -1906,6 +1906,32 @@ class OvsFlow(GenericNetlinkSocket):
             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.
@@ -2068,6 +2094,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:
@@ -2151,6 +2180,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