Skip to content

Commit 76035fd

Browse files
apconoledavem330
authored andcommitted
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: 4242029 ("selftests: openvswitch: add explicit drop testcase") Signed-off-by: Aaron Conole <aconole@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent af846af commit 76035fd

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ ovs_add_flow () {
144144
return 0
145145
}
146146

147+
ovs_del_flows () {
148+
info "Deleting all flows from DP: sbx:$1 br:$2"
149+
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-flows "$2"
150+
return 0
151+
}
152+
147153
ovs_drop_record_and_run () {
148154
local sbx=$1
149155
shift
@@ -200,6 +206,17 @@ test_drop_reason() {
200206
ip netns exec server ip addr add 172.31.110.20/24 dev s1
201207
ip netns exec server ip link set s1 up
202208

209+
# Check if drop reasons can be sent
210+
ovs_add_flow "test_drop_reason" dropreason \
211+
'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(10)' 2>/dev/null
212+
if [ $? == 1 ]; then
213+
info "no support for drop reasons - skipping"
214+
ovs_exit_sig
215+
return $ksft_skip
216+
fi
217+
218+
ovs_del_flows "test_drop_reason" dropreason
219+
203220
# Allow ARP
204221
ovs_add_flow "test_drop_reason" dropreason \
205222
'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1

tools/testing/selftests/net/openvswitch/ovs-dpctl.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,32 @@ def add_flow(self, dpifindex, flowmsg):
19061906
raise ne
19071907
return reply
19081908

1909+
def del_flows(self, dpifindex):
1910+
"""
1911+
Send a del message to the kernel that will drop all flows.
1912+
1913+
dpifindex should be a valid datapath obtained by calling
1914+
into the OvsDatapath lookup
1915+
"""
1916+
1917+
flowmsg = OvsFlow.ovs_flow_msg()
1918+
flowmsg["cmd"] = OVS_FLOW_CMD_DEL
1919+
flowmsg["version"] = OVS_DATAPATH_VERSION
1920+
flowmsg["reserved"] = 0
1921+
flowmsg["dpifindex"] = dpifindex
1922+
1923+
try:
1924+
reply = self.nlm_request(
1925+
flowmsg,
1926+
msg_type=self.prid,
1927+
msg_flags=NLM_F_REQUEST | NLM_F_ACK,
1928+
)
1929+
reply = reply[0]
1930+
except NetlinkError as ne:
1931+
print(flowmsg)
1932+
raise ne
1933+
return reply
1934+
19091935
def dump(self, dpifindex, flowspec=None):
19101936
"""
19111937
Returns a list of messages containing flows.
@@ -2068,6 +2094,9 @@ def main(argv):
20682094
addflcmd.add_argument("flow", help="Flow specification")
20692095
addflcmd.add_argument("acts", help="Flow actions")
20702096

2097+
delfscmd = subparsers.add_parser("del-flows")
2098+
delfscmd.add_argument("flsbr", help="Datapath name")
2099+
20712100
args = parser.parse_args()
20722101

20732102
if args.verbose > 0:
@@ -2151,6 +2180,11 @@ def main(argv):
21512180
flow = OvsFlow.ovs_flow_msg()
21522181
flow.parse(args.flow, args.acts, rep["dpifindex"])
21532182
ovsflow.add_flow(rep["dpifindex"], flow)
2183+
elif hasattr(args, "flsbr"):
2184+
rep = ovsdp.info(args.flsbr, 0)
2185+
if rep is None:
2186+
print("DP '%s' not found." % args.flsbr)
2187+
ovsflow.del_flows(rep["dpifindex"])
21542188

21552189
return 0
21562190

0 commit comments

Comments
 (0)