From 3bffc610fa3ae08fa837f6bd0bf7a2deebdd0970 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 4 Aug 2011 16:20:34 -0700 Subject: odp-util: New function odp_flow_key_from_string(). This will be used in upcoming commits. --- tests/automake.mk | 7 +++++ tests/odp.at | 40 +++++++++++++++++++++++++ tests/test-odp.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 1 + 4 files changed, 133 insertions(+) create mode 100644 tests/odp.at create mode 100644 tests/test-odp.c (limited to 'tests') diff --git a/tests/automake.mk b/tests/automake.mk index 33307ccc3..eb6351f62 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -15,6 +15,7 @@ TESTSUITE_AT = \ tests/daemon-py.at \ tests/ofp-print.at \ tests/ovs-ofctl.at \ + tests/odp.at \ tests/multipath.at \ tests/autopath.at \ tests/vconn.at \ @@ -80,6 +81,7 @@ lcov_wrappers = \ tests/lcov/test-list \ tests/lcov/test-lockfile \ tests/lcov/test-multipath \ + tests/lcov/test-odp \ tests/lcov/test-ovsdb \ tests/lcov/test-packets \ tests/lcov/test-random \ @@ -133,6 +135,7 @@ valgrind_wrappers = \ tests/valgrind/test-list \ tests/valgrind/test-lockfile \ tests/valgrind/test-multipath \ + tests/valgrind/test-odp \ tests/valgrind/test-openflowd \ tests/valgrind/test-ovsdb \ tests/valgrind/test-packets \ @@ -261,6 +264,10 @@ noinst_PROGRAMS += tests/test-unix-socket tests_test_unix_socket_SOURCES = tests/test-unix-socket.c tests_test_unix_socket_LDADD = lib/libopenvswitch.a +noinst_PROGRAMS += tests/test-odp +tests_test_odp_SOURCES = tests/test-odp.c +tests_test_odp_LDADD = lib/libopenvswitch.a + noinst_PROGRAMS += tests/test-ovsdb tests_test_ovsdb_SOURCES = \ tests/test-ovsdb.c \ diff --git a/tests/odp.at b/tests/odp.at new file mode 100644 index 000000000..53eb59383 --- /dev/null +++ b/tests/odp.at @@ -0,0 +1,40 @@ +AT_SETUP([ODP parsing and formatting - valid forms]) +AT_DATA([odp-base.txt], [dnl +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x1234) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=5,tos=128) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=6,tos=0),tcp(src=80,dst=8080) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=17,tos=0),udp(src=81,dst=6632) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=1,tos=0),icmp(type=1,code=2) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=10,tos=112) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=6,tos=0),tcp(src=80,dst=8080) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=17,tos=0),udp(src=6630,dst=22) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0),icmpv6(type=1,code=2) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0),icmpv6(type=135,code=0),nd(target=::3) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0),icmpv6(type=135,code=0),nd(target=::3,sll=00:05:06:07:08:09) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0),icmpv6(type=136,code=0),nd(target=::3,tll=00:0a:0b:0c:0d:0e) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0),icmpv6(type=136,code=0),nd(target=::3,sll=00:05:06:07:08:09,tll=00:0a:0b:0c:0d:0e) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0806),arp(sip=1.2.3.4,tip=5.6.7.8,op=1,sha=00:0f:10:11:12:13,tha=00:14:15:16:17:18) +]) + +(echo '# Valid forms without tun_id or VLAN header.' + cat odp-base.txt + + echo + echo '# Valid forms with tun_id header.' + sed 's/^/tun_id(0x7f10354),/' odp-base.txt + + echo + echo '# Valid forms with VLAN header.' + sed 's/eth([[^)]]*)/&,vlan(vid=99,pcp=7)/' odp-base.txt + + echo + echo '# Valid forms with tun_id and VLAN headers.' + sed 's/^/tun_id(0xfedcba9876543210),/ +s/eth([[^)]]*)/&,vlan(vid=99,pcp=7)/' odp-base.txt) > odp.txt +AT_CAPTURE_FILE([odp.txt]) +AT_CHECK_UNQUOTED([test-odp < odp.txt], [0], [`cat odp.txt` +]) +AT_CLEANUP + +dnl We could add a test for invalid forms, but that's less important. diff --git a/tests/test-odp.c b/tests/test-odp.c new file mode 100644 index 000000000..9db27bf53 --- /dev/null +++ b/tests/test-odp.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2011 Nicira Networks. + * + * 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. + */ + +#include + +#include + +#include "dynamic-string.h" +#include "flow.h" +#include "odp-util.h" +#include "ofpbuf.h" + +int +main(void) +{ + struct ds in; + + ds_init(&in); + while (!ds_get_line(&in, stdin)) { + struct ofpbuf odp_key; + struct flow flow; + struct ds out; + int error; + char *s; + + /* Delete comments, skip blank lines. */ + s = ds_cstr(&in); + if (*s == '#') { + puts(s); + continue; + } + if (strchr(s, '#')) { + *strchr(s, '#') = '\0'; + } + if (s[strspn(s, " ")] == '\0') { + putchar('\n'); + continue; + } + + /* Convert string to ODP key. */ + ofpbuf_init(&odp_key, 0); + error = odp_flow_key_from_string(ds_cstr(&in), &odp_key); + if (error) { + printf("odp_flow_key_from_string: error\n"); + goto next; + } + + /* Convert odp_key to flow. */ + error = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow); + if (error) { + printf("odp_flow_key_to_flow: error\n"); + goto next; + } + + /* Convert cls_rule back to odp_key. */ + ofpbuf_uninit(&odp_key); + ofpbuf_init(&odp_key, 0); + odp_flow_key_from_flow(&odp_key, &flow); + + /* Convert odp_key to string. */ + ds_init(&out); + odp_flow_key_format(odp_key.data, odp_key.size, &out); + puts(ds_cstr(&out)); + ds_destroy(&out); + + next: + ofpbuf_uninit(&odp_key); + } + ds_destroy(&in); + + return 0; +} diff --git a/tests/testsuite.at b/tests/testsuite.at index 6ec77f8cf..c22ece71a 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -46,6 +46,7 @@ m4_include([tests/daemon.at]) m4_include([tests/daemon-py.at]) m4_include([tests/ofp-print.at]) m4_include([tests/ovs-ofctl.at]) +m4_include([tests/odp.at]) m4_include([tests/multipath.at]) m4_include([tests/autopath.at]) m4_include([tests/vconn.at]) -- cgit v1.2.1