Commit 76035fd1 authored by Aaron Conole's avatar Aaron Conole Committed by David S. Miller
Browse files

selftests: openvswitch: Skip drop testing on older kernels



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: 42420291 ("selftests: openvswitch: add explicit drop testcase")
Signed-off-by: default avatarAaron Conole <aconole@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent af846afa
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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
+34 −0
Original line number Diff line number Diff line
@@ -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