2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

tests: Verify flows in ofp-actions are parseable.

Create a small helper script and check that flows used in ofp-actions.at
are parseable.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Acked-by: Mike Pattrick <mkp@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Adrian Moreno 2022-12-19 17:13:50 +01:00 committed by Ilya Maximets
parent c395e9810e
commit fc3f918cb5
3 changed files with 65 additions and 0 deletions

View File

@ -19,6 +19,7 @@ EXTRA_DIST += \
$(OVSDB_CLUSTER_TESTSUITE) \ $(OVSDB_CLUSTER_TESTSUITE) \
tests/atlocal.in \ tests/atlocal.in \
$(srcdir)/package.m4 \ $(srcdir)/package.m4 \
$(srcdir)/tests/test-ofparse.py \
$(srcdir)/tests/testsuite \ $(srcdir)/tests/testsuite \
$(srcdir)/tests/testsuite.patch $(srcdir)/tests/testsuite.patch
@ -522,6 +523,7 @@ CHECK_PYFILES = \
tests/test-json.py \ tests/test-json.py \
tests/test-jsonrpc.py \ tests/test-jsonrpc.py \
tests/test-l7.py \ tests/test-l7.py \
tests/test-ofparse.py \
tests/test-ovsdb.py \ tests/test-ovsdb.py \
tests/test-reconnect.py \ tests/test-reconnect.py \
tests/test-stream.py \ tests/test-stream.py \

View File

@ -329,6 +329,7 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow10 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow10 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
AT_SETUP([OpenFlow 1.0 "instruction" translations]) AT_SETUP([OpenFlow 1.0 "instruction" translations])
@ -359,6 +360,7 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-instructions OpenFlow10 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-instructions OpenFlow10 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
AT_SETUP([OpenFlow 1.1 action translation]) AT_SETUP([OpenFlow 1.1 action translation])
@ -502,6 +504,7 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow11 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow11 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
AT_SETUP([OpenFlow 1.1 instruction translation]) AT_SETUP([OpenFlow 1.1 instruction translation])
@ -737,6 +740,7 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow12 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow12 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
dnl Our primary goal here is to verify OpenFlow 1.3-specific changes, dnl Our primary goal here is to verify OpenFlow 1.3-specific changes,
@ -798,6 +802,7 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow13 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow13 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
dnl Our primary goal here is to verify that OpenFlow 1.5-specific changes, dnl Our primary goal here is to verify that OpenFlow 1.5-specific changes,
@ -827,17 +832,20 @@ AT_CAPTURE_FILE([experr])
AT_CHECK( AT_CHECK(
[ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow15 < input.txt], [ovs-ofctl '-vPATTERN:console:%c|%p|%m' parse-actions OpenFlow15 < input.txt],
[0], [expout], [experr]) [0], [expout], [experr])
AT_CHECK([cat expout | grep 'actions=' | test-ofparse.py])
AT_CLEANUP AT_CLEANUP
AT_SETUP([ofp-actions - inconsistent MPLS actions]) AT_SETUP([ofp-actions - inconsistent MPLS actions])
OVS_VSWITCHD_START OVS_VSWITCHD_START
dnl OK: Use fin_timeout action on TCP flow dnl OK: Use fin_timeout action on TCP flow
AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=fin_timeout(idle_timeout=1)']) AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=fin_timeout(idle_timeout=1)'])
AT_CHECK([echo 'tcp actions=fin_timeout(idle_timeout=1)' | test-ofparse.py])
dnl Bad: Use fin_timeout action on TCP flow that has been converted to MPLS dnl Bad: Use fin_timeout action on TCP flow that has been converted to MPLS
AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=push_mpls:0x8847,fin_timeout(idle_timeout=1)'], AT_CHECK([ovs-ofctl -O OpenFlow11 -vwarn add-flow br0 'tcp actions=push_mpls:0x8847,fin_timeout(idle_timeout=1)'],
[1], [], [dnl [1], [], [dnl
ovs-ofctl: none of the usable flow formats (OpenFlow10,NXM) is among the allowed flow formats (OpenFlow11) ovs-ofctl: none of the usable flow formats (OpenFlow10,NXM) is among the allowed flow formats (OpenFlow11)
]) ])
AT_CHECK([echo 'tcp actions=push_mpls:0x8847,fin_timeout(idle_timeout=1)' | test-ofparse.py])
OVS_VSWITCHD_STOP OVS_VSWITCHD_STOP
AT_CLEANUP AT_CLEANUP
@ -853,6 +861,8 @@ AT_CHECK([ovs-ofctl -O OpenFlow10 dump-flows br0 | ofctl_strip], [0], [dnl
NXST_FLOW reply: NXST_FLOW reply:
mpls actions=load:0xa->OXM_OF_MPLS_LABEL[[]] mpls actions=load:0xa->OXM_OF_MPLS_LABEL[[]]
]) ])
AT_CHECK([echo 'mpls actions=set_field:10->mpls_label' | test-ofparse.py])
AT_CHECK([echo 'mpls actions=load:0xa->OXM_OF_MPLS_LABEL[[]]'| test-ofparse.py])
OVS_VSWITCHD_STOP OVS_VSWITCHD_STOP
AT_CLEANUP AT_CLEANUP
@ -862,14 +872,17 @@ OVS_VSWITCHD_START
dnl OpenFlow 1.0 has an "enqueue" action. For OpenFlow 1.1+, we translate dnl OpenFlow 1.0 has an "enqueue" action. For OpenFlow 1.1+, we translate
dnl it to a series of actions that accomplish the same thing. dnl it to a series of actions that accomplish the same thing.
AT_CHECK([ovs-ofctl -O OpenFlow10 add-flow br0 'actions=enqueue(123,456)']) AT_CHECK([ovs-ofctl -O OpenFlow10 add-flow br0 'actions=enqueue(123,456)'])
AT_CHECK([echo 'actions=enqueue(123,456)' | test-ofparse.py])
AT_CHECK([ovs-ofctl -O OpenFlow10 dump-flows br0 | ofctl_strip], [0], [dnl AT_CHECK([ovs-ofctl -O OpenFlow10 dump-flows br0 | ofctl_strip], [0], [dnl
NXST_FLOW reply: NXST_FLOW reply:
actions=enqueue:123:456 actions=enqueue:123:456
]) ])
AT_CHECK([echo 'actions=enqueue:123:456' | test-ofparse.py])
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-flows br0 | ofctl_strip], [0], [dnl AT_CHECK([ovs-ofctl -O OpenFlow13 dump-flows br0 | ofctl_strip], [0], [dnl
OFPST_FLOW reply (OF1.3): OFPST_FLOW reply (OF1.3):
reset_counts actions=set_queue:456,output:123,pop_queue reset_counts actions=set_queue:456,output:123,pop_queue
]) ])
AT_CHECK([echo 'actions=set_queue:456,output:123,pop_queue' | test-ofparse.py])
OVS_VSWITCHD_STOP OVS_VSWITCHD_STOP
AT_CLEANUP AT_CLEANUP
@ -887,6 +900,8 @@ AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [dnl
OFPST_FLOW reply (OF1.1): OFPST_FLOW reply (OF1.1):
ip actions=mod_nw_ttl:123 ip actions=mod_nw_ttl:123
]) ])
AT_CHECK([echo 'ip,actions=mod_nw_ttl:123' | test-ofparse.py])
AT_CHECK([echo 'ip actions=load:0x7b->NXM_NX_IP_TTL[[]]' | test-ofparse.py])
OVS_VSWITCHD_STOP OVS_VSWITCHD_STOP
AT_CLEANUP AT_CLEANUP
@ -898,10 +913,12 @@ dnl OpenFlow 1.1, but no other version, has a "mod_nw_ecn" action.
dnl Check that we translate it properly for OF1.0 and OF1.2. dnl Check that we translate it properly for OF1.0 and OF1.2.
dnl (OF1.3+ should be the same as OF1.2.) dnl (OF1.3+ should be the same as OF1.2.)
AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 'ip,actions=mod_nw_ecn:2']) AT_CHECK([ovs-ofctl -O OpenFlow11 add-flow br0 'ip,actions=mod_nw_ecn:2'])
AT_CHECK([echo 'ip,actions=mod_nw_ecn:2' | test-ofparse.py])
AT_CHECK([ovs-ofctl -O OpenFlow10 dump-flows br0 | ofctl_strip], [0], [dnl AT_CHECK([ovs-ofctl -O OpenFlow10 dump-flows br0 | ofctl_strip], [0], [dnl
NXST_FLOW reply: NXST_FLOW reply:
ip actions=load:0x2->NXM_NX_IP_ECN[[]] ip actions=load:0x2->NXM_NX_IP_ECN[[]]
]) ])
AT_CHECK([echo 'ip actions=load:0x2->NXM_NX_IP_ECN[[]]' | test-ofparse.py])
AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [dnl AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip], [0], [dnl
OFPST_FLOW reply (OF1.1): OFPST_FLOW reply (OF1.1):
ip actions=mod_nw_ecn:2 ip actions=mod_nw_ecn:2
@ -910,6 +927,7 @@ AT_CHECK([ovs-ofctl -O OpenFlow12 dump-flows br0 | ofctl_strip], [0], [dnl
OFPST_FLOW reply (OF1.2): OFPST_FLOW reply (OF1.2):
ip actions=set_field:2->nw_ecn ip actions=set_field:2->nw_ecn
]) ])
AT_CHECK([echo 'ip actions=set_field:2->nw_ecn' | test-ofparse.py])
dnl Check that OF1.2+ set_field to set ECN is translated into the OF1.1 dnl Check that OF1.2+ set_field to set ECN is translated into the OF1.1
dnl mod_nw_ecn action. dnl mod_nw_ecn action.

45
tests/test-ofparse.py Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
# Copyright (c) 2022 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""test-ofparse reads flows from stdin and tries to parse them using
the python flow parsing library.
"""
import fileinput
import sys
try:
from ovs.flow.ofp import OFPFlow
except ImportError:
sys.exit(0)
def main():
for flow in fileinput.input():
try:
result_flow = OFPFlow(flow)
if flow != str(result_flow):
print("in: {}".format(flow))
print("out: {}".format(str(result_flow)))
raise ValueError("Flow conversion back to string failed")
except Exception as e:
print("Error parsing flow {}: {}".format(flow, e))
return 1
return 0
if __name__ == "__main__":
sys.exit(main())