From: Ben Pfaff Date: Fri, 26 Aug 2011 00:00:45 +0000 (-0700) Subject: ofproto-dpif: Add tests for VLAN handling. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04c956fc029bb97de17b62cb6d243b50f0bc9f58;p=openvswitch ofproto-dpif: Add tests for VLAN handling. These tests would have caught the bug fixed in the previous commit "ofproto-dpif: Fix behavior when a subset of VLANs is trunked." --- diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index a4fb737b..957d7c71 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -79,3 +79,82 @@ AT_CHECK([tail -1 stdout], [0], ]) OFPROTO_STOP AT_CLEANUP + +AT_SETUP([ofproto-dpif - trunks]) +OVS_VSWITCHD_START( + [add-port br0 p1 trunks=10,12 -- set Interface p1 type=dummy -- \ + add-port br0 p2 tag=10 -- set Interface p2 type=dummy -- \ + add-port br0 p3 tag=12 -- set Interface p3 type=dummy -- \ + add-port br0 p4 tag=12 -- set Interface p4 type=dummy]) + +AT_CHECK( + [ovs-vsctl \ + -- get Interface p1 ofport \ + -- get Interface p2 ofport \ + -- get Interface p3 ofport \ + -- get Interface p4 ofport], + [0], [stdout]) +set `cat stdout` +br0=0 p1=$1 p2=$2 p3=$3 p4=$4 + +dnl Each of these specifies an in_port, a VLAN VID (or "none"), and one +dnl or more sets of valid datapath actions. (The order of datapath +dnl actions is somewhat unpredictable, hence the ability to specify more +dnl than one set.) +for tuple in \ + "$br0 none drop" \ + "$br0 0 drop" \ + "$br0 10 $p1,strip_vlan,$p2" \ + "$br0 11 drop" \ + "$br0 12 $p1,strip_vlan,$p3,$p4 $p1,strip_vlan,$p4,$p3" \ + "$p1 none drop" \ + "$p1 0 drop" \ + "$p1 10 $br0,strip_vlan,$p2" \ + "$p1 11 drop" \ + "$p1 12 $br0,strip_vlan,$p4,$p3 $br0,strip_vlan,$p3,$p4" \ + "$p2 none set_tci(vid=10,pcp=0),$br0,$p1 set_tci(vid=10,pcp=0),$p1,$br0" \ + "$p2 0 set_tci(vid=10,pcp=1),$br0,$p1 set_tci(vid=10,pcp=1),$p1,$br0" \ + "$p2 10 drop" \ + "$p2 11 drop" \ + "$p2 12 drop" \ + "$p3 none $p4,set_tci(vid=12,pcp=0),$br0,$p1 $p4,set_tci(vid=12,pcp=0),$p1,$br0" \ + "$p3 0 $p4,set_tci(vid=12,pcp=1),$br0,$p1 $p4,set_tci(vid=12,pcp=1),$p1,$br0" \ + "$p3 10 drop" \ + "$p3 11 drop" \ + "$p3 12 drop" \ + "$p4 none $p3,set_tci(vid=12,pcp=0),$br0,$p1 $p3,set_tci(vid=12,pcp=0),$p1,$br0" \ + "$p4 0 $p3,set_tci(vid=12,pcp=1),$br0,$p1 $p3,set_tci(vid=12,pcp=1),$p1,$br0" \ + "$p4 10 drop" \ + "$p4 11 drop" \ + "$p4 12 drop" +do + set $tuple + in_port=$1 + vlan=$2 + shift; shift + + if test $vlan = none; then + flow="in_port($in_port),eth(src=50:54:00:00:00:01,dst=ff:ff:ff:ff:ff:ff),eth_type(0xabcd)" + else + flow="in_port($in_port),eth(src=50:54:00:00:00:01,dst=ff:ff:ff:ff:ff:ff),vlan(vid=$vlan,pcp=1),eth_type(0xabcd)" + fi + + AT_CHECK( + [echo "-- $tuple" + echo "-- br0=$br0 p1=$p1 p2=$p2 p3=$p3 p4=$p4" + ovs-appctl ofproto/trace br0 "$flow"], + [0], [stdout]) + + actions=`tail -1 stdout | sed 's/Datapath actions: //'` + no_match=: + for pattern + do + if test X"$actions" = X"$pattern"; then + no_match=false + fi + done + AT_FAIL_IF([$no_match]) +done + +OVS_VSWITCHD_STOP +AT_CLEANUP diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index 24cb45a7..229e014b 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -21,3 +21,46 @@ m4_define([OFPROTO_START], m4_define([OFPROTO_STOP], [AT_CHECK([ovs-appctl -t test-openflowd exit]) trap '' 0]) + +m4_define([OVS_VSWITCHD_START], + [dnl Skip this test if running as root. Otherwise ovs-vswitchd will tear + dnl down any existing datapaths if the kernel module is loaded. + AT_SKIP_IF([test "`id -u`" = 0]) + + OVS_RUNDIR=$PWD; export OVS_RUNDIR + OVS_LOGDIR=$PWD; export OVS_LOGDIR + OVS_SYSCONFDIR=$PWD; export OVS_SYSCONFDIR + trap 'kill `cat ovsdb-server.pid ovs-vswitchd.pid`' 0 + + dnl Create database. + mkdir openvswitch + touch openvswitch/.conf.db.~lock~ + AT_CHECK([ovsdb-tool create openvswitch/conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema]) + + dnl Start ovsdb-server. + AT_CHECK([ovsdb-server --detach --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr]) + AT_CHECK([[sed < stderr '/vlog|INFO|opened log file/d']]) + AT_CAPTURE_FILE([ovsdb-server.log]) + + dnl Initialize database. + AT_CHECK([ovs-vsctl --no-wait init]) + + dnl Start ovs-vswitchd. + AT_CHECK([ovs-vswitchd --detach --pidfile --enable-dummy --log-file], [0], [], [stderr]) + AT_CAPTURE_FILE([ovs-vswitchd.log]) + AT_CHECK([[sed < stderr ' +/vlog|INFO|opened log file/d +/reconnect|INFO|/d +/dpif_linux|ERR|Generic Netlink family.*does not exist/d +/dpif|WARN|failed to enumerate system datapaths: No such file or directory/d +/ofproto|INFO|using datapath ID/d +/ofproto|INFO|datapath ID changed to fedcba9876543210/d']]) + + dnl Add bridges, ports, etc. + AT_CHECK([ovs-vsctl -- add-br br0 -- set bridge br0 datapath-type=dummy other-config:datapath-id=fedcba9876543210 -- $1]) +]) + +m4_define([OVS_VSWITCHD_STOP], + [AT_CHECK([ovs-appctl -t ovs-vswitchd exit]) + AT_CHECK([ovs-appctl -t ovsdb-server exit]) + trap '' 0])