[ovs-dev] [PATCH 2/2] tests: Add tests for the ofproto/trace command

Alex Wang <alexw@nicira.com > alexw at nicira.com
Tue May 7 00:34:04 UTC 2013


From: Alex Wang <alexw at nicira.com>

Three testcases are added to the testsuite, which test the three command
formats and the corresponding corner cases.

Signed-off-by: Alex Wang <alexw at nicira.com>
---
 tests/ofproto-dpif.at |  209 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 209 insertions(+)

diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
index 8cbbd80..3406b01 100644
--- a/tests/ofproto-dpif.at
+++ b/tests/ofproto-dpif.at
@@ -1043,6 +1043,215 @@ AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
+# Three testcases for the ofproto/trace command
+# The first one tests the normal input and corner cases
+# of the "ofproto/trace [datapath_name] datapath_flow"
+# and the "ofproto/trace bridge_name openflow_flow"
+AT_SETUP([ofproto-dpif - ofproto/trace command 1])
+OVS_VSWITCHD_START
+ADD_OF_PORTS([br0], 1, 2)
+
+AT_DATA([flows.txt], [dnl
+in_port=1 actions=output:2
+in_port=2 actions=output:1
+])
+AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
+
+dp_flow="in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)"
+of_flow="in_port=1,dl_src=50:54:00:00:00:05,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=1,nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0"
+# Test command: ofproto/trace dp_flow
+AT_CHECK([ovs-appctl ofproto/trace "$dp_flow"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Test command: ofproto/trace dp_name dp_flow
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$dp_flow"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Test incorrect command: ofproto/trace wrong_name dp_flow
+AT_CHECK([ovs-appctl ofproto/trace wrong_name "$dp_flow"],
+  [2], [], [stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Unknown bridge or datapath name
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+# Test incorrect command: ofproto/trace nonexist_dp_name dp_flow
+AT_CHECK([ovs-appctl ofproto/trace ovs-system "$dp_flow"],
+  [2], [], [stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Cannot find datapath of this name
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+# Test incorrect command: ofproto/trace br_name dp_flow
+AT_CHECK([ovs-appctl ofproto/trace br0 "$dp_flow"],
+  [2], [], [stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Cannot parse the openflow flow
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+# Add another bridge
+AT_CHECK([ovs-vsctl add-br br1 -- set bridge br1 datapath-type=netdev \
+          -- set bridge br1 fail-mode=secure])
+
+# Test incorrect command: ofproto/trace dp_flow, since there is more than one dp
+AT_CHECK([ovs-appctl ofproto/trace "$dp_flow"], [2], [], [stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Must specify datapath name, there is more than one type of datapath
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+# Test command: ofproto/trace dp_name dp_flow
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$dp_flow"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Delete the added bridge
+AT_CHECK([ovs-vsctl del-br br1])
+
+# Test command: ofproto/trace dp_flow
+AT_CHECK([ovs-appctl ofproto/trace "$dp_flow"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Test commmand: ofproto/trace br_name of_flow
+AT_CHECK([ovs-appctl ofproto/trace br0 "$of_flow"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Test incorrect command: ofproto/trace dp_flow
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$of_flow"],
+  [2], [], [stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Bad datapath flow syntax
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+OVS_VSWITCHD_STOP(["/couldn't open old datapath ovs-dummy to remove it/d; /obtaining netdev stats via vport failed/d"])
+AT_CLEANUP
+
+# The second test tests the -generate option
+AT_SETUP([ofproto-dpif - ofproto/trace command 2])
+OVS_VSWITCHD_START([set bridge br0 fail-mode=standalone])
+ADD_OF_PORTS([br0], 1, 2, 3)
+
+dp_flow='in_port(3),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff)'
+of_flow='arp,metadata=0,in_port=3,vlan_tci=0x0000,dl_src=50:54:00:00:00:05,dl_dst=ff:ff:ff:ff:ff:ff'
+
+# Test command: ofproto/trace dp_flow
+AT_CHECK([ovs-appctl ofproto/trace "$dp_flow"], [0], [stdout])
+
+# Check for no MAC learning entry.
+AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [dnl
+ port  VLAN  MAC                Age
+])
+
+# Test command: ofproto/trace br_name of_flow
+AT_CHECK([ovs-appctl ofproto/trace br0 "$of_flow"], [0], [stdout])
+
+# Check for no MAC learning entry.
+AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [dnl
+ port  VLAN  MAC                Age
+])
+
+# Test command: ofproto/trace dp_flow -generate
+AT_CHECK([ovs-appctl ofproto/trace "$dp_flow" -generate], [0], [stdout])
+
+# Check for the MAC learning entry.
+AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [dnl
+ port  VLAN  MAC                Age
+    3     0  50:54:00:00:00:05    ?
+])
+
+# Test command: ofproto/trace dp_name dp_flow -generate
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy \
+  "in_port(1),eth(src=50:54:00:00:00:06,dst=50:54:00:00:00:05)" \
+  -generate], [0], [stdout])
+
+# Check for both MAC learning entries.
+AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [dnl
+ port  VLAN  MAC                Age
+    3     0  50:54:00:00:00:05    ?
+    1     0  50:54:00:00:00:06    ?
+])
+
+# Test command: ofproto/trace br_name of_flow -generate
+AT_CHECK([ovs-appctl ofproto/trace br0 \
+  "in_port=2,dl_src=50:54:00:00:00:07,dl_dst=50:54:00:00:00:06" \
+  -generate], [0], [stdout])
+
+# Check for both MAC learning entries.
+AT_CHECK_UNQUOTED([ovs-appctl fdb/show br0 | sed 's/[[0-9]]\{1,\}$/?/'], [0], [dnl
+ port  VLAN  MAC                Age
+    3     0  50:54:00:00:00:05    ?
+    1     0  50:54:00:00:00:06    ?
+    2     0  50:54:00:00:00:07    ?
+])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
+
+# The thrid test tests the command:
+# ofproto/trace [dpname] <metadata> ... <metadata> <packet>
+AT_SETUP([ofproto-dpif - ofproto/trace command 3])
+OVS_VSWITCHD_START([set bridge br0 fail-mode=standalone])
+ADD_OF_PORTS([br0], 1, 2)
+
+# The ovs-tcpundump of packets between port1 and port2
+pkt1to2=50540000000250540000000108064500001C000100004001F98CC0A80001C0A800020800F7FF00000000
+pkt2to1=50540000000150540000000208064500001C000100004001F98CC0A80002C0A800010800F7FF00000000
+
+# Construct the MAC learning table
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy \
+  "in_port(1),eth(src=50:54:00:00:00:01,dst=ff:ff:ff:ff:ff:ff)" \
+  -generate], [0], [stdout])
+
+# Construct the MAC learning table
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy \
+  "in_port(2),eth(src=50:54:00:00:00:02,dst=ff:ff:ff:ff:ff:ff)" \
+  -generate], [0], [stdout])
+
+# Test command: ofproto/trace dpname priority tun_id in_port mark packet
+AT_CHECK([ovs-appctl ofproto/trace ovs-dummy \
+  0, 0, 1, 0, "$pkt1to2"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 2
+])
+
+# Test command: ofproto/trace priority tun_id in_port mark packet
+AT_CHECK([ovs-appctl ofproto/trace \
+  0, 0, 2, 0, "$pkt2to1"], [0], [stdout])
+AT_CHECK([tail -1 stdout], [0], [dnl
+Datapath actions: 1
+])
+
+# Test incorrect command: ofproto/trace br0 priority tun_id in_port mark packet
+AT_CHECK([ovs-appctl ofproto/trace br0 \
+  0, 0, 1, 0, "$pkt1to2"], [2], [stdout],[stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+Incorrect datapath name
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+# Test incorrect command: ofproto/trace with 7 arguments
+AT_CHECK([ovs-appctl ofproto/trace \
+  arg1, arg2, arg3, arg4, arg5, arg6, arg7], [2], [stdout],[stderr])
+AT_CHECK([tail -2 stderr], [0], [dnl
+"ofproto/trace" command takes at most 6 arguments
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
+
 m4_define([OFPROTO_TRACE],
   [flow="$2"
    AT_CHECK([ovs-appctl ofproto/trace $1 "$flow" $3], [0], [stdout])
-- 
1.7.9.5




More information about the dev mailing list