ovs-ofctl: Fix replace-flows.
[cascardo/ovs.git] / tests / ovn-controller.at
1 AT_BANNER([ovn-controller])
2
3 AT_SETUP([ovn-controller - ovn-bridge-mappings])
4 ovn_init_db ovn-sb
5 net_add n1
6 sim_add hv
7 as hv
8 ovs-vsctl \
9     -- add-br br-phys \
10     -- add-br br-eth0 \
11     -- add-br br-eth1 \
12     -- add-br br-eth2
13 ovn_attach n1 br-phys 192.168.0.1
14
15 # Waits until the OVS database contains exactly the specified patch ports.
16 # Each argument should be of the form BRIDGE PORT PEER.
17 check_patches () {
18     # Generate code to check that the set of patch ports is exactly as
19     # specified.
20     echo 'ovs-vsctl -f csv -d bare --no-headings --columns=name find Interface type=patch | sort' > query
21     for patch
22     do
23         echo $patch
24     done | cut -d' ' -f 2 | sort > expout
25
26     # Generate code to verify that the configuration of each patch
27     # port is correct.
28     for patch
29     do
30         set $patch; bridge=$1 port=$2 peer=$3
31         echo >>query "ovs-vsctl iface-to-br $port -- get Interface $port type options"
32         echo >>expout "$bridge
33 patch
34 {peer=$peer}"
35     done
36
37     # Run the query until we get the expected result (or until a timeout).
38     #
39     # (We use sed to drop all "s from output because ovs-vsctl quotes some
40     # of the port names but not others.)
41     AT_CAPTURE_FILE([query])
42     AT_CAPTURE_FILE([expout])
43     AT_CAPTURE_FILE([stdout])
44     OVS_WAIT_UNTIL([. ./query | sed 's/"//g' > stdout #"
45                     diff -u stdout expout >/dev/null])
46 }
47
48 # Initially there should be no patch ports.
49 check_patches
50
51 # Configure two ovn-bridge mappings to create two patch ports.
52 AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1])
53 check_patches \
54     'br-eth0 patch-br-eth0-to-br-int patch-br-int-to-br-eth0' \
55     'br-int  patch-br-int-to-br-eth0 patch-br-eth0-to-br-int' \
56     'br-eth1 patch-br-eth1-to-br-int patch-br-int-to-br-eth1' \
57     'br-int  patch-br-int-to-br-eth1 patch-br-eth1-to-br-int'
58
59 # Change the mapping and the patch ports should change.
60 AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth2,physnet2:br-eth1])
61 check_patches \
62     'br-eth2 patch-br-eth2-to-br-int patch-br-int-to-br-eth2' \
63     'br-int  patch-br-int-to-br-eth2 patch-br-eth2-to-br-int' \
64     'br-eth1 patch-br-eth1-to-br-int patch-br-int-to-br-eth1' \
65     'br-int  patch-br-int-to-br-eth1 patch-br-eth1-to-br-int'
66
67 # Add logical patch ports.
68 AT_CHECK([ovn-sbctl \
69     -- --id=@dp1 create Datapath_Binding tunnel_key=1 \
70     -- --id=@dp2 create Datapath_Binding tunnel_key=2 \
71     -- create Port_Binding datapath=@dp1 logical_port=foo tunnel_key=1 type=patch options:peer=bar \
72     -- create Port_Binding datapath=@dp2 logical_port=bar tunnel_key=2 type=patch options:peer=foo \
73 | ${PERL} $srcdir/uuidfilt.pl], [0], [<0>
74 <1>
75 <2>
76 <3>
77 ])
78 check_patches \
79     'br-eth2 patch-br-eth2-to-br-int patch-br-int-to-br-eth2' \
80     'br-int  patch-br-int-to-br-eth2 patch-br-eth2-to-br-int' \
81     'br-eth1 patch-br-eth1-to-br-int patch-br-int-to-br-eth1' \
82     'br-int  patch-br-int-to-br-eth1 patch-br-eth1-to-br-int' \
83     'br-int  patch-foo-to-bar        patch-bar-to-foo' \
84     'br-int  patch-bar-to-foo        patch-foo-to-bar'
85
86 # Delete the mapping and the ovn-bridge-mapping patch ports should go away;
87 # the ones from the logical patch port remain.
88 AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
89 check_patches \
90     'br-int patch-foo-to-bar patch-bar-to-foo' \
91     'br-int patch-bar-to-foo patch-foo-to-bar'
92
93 # Change name of logical patch port, check that the OVS patch ports
94 # get updated.
95 AT_CHECK([ovn-sbctl \
96     -- set Port_Binding foo logical_port=quux options:peer=baz \
97     -- set Port_Binding bar logical_port=baz  options:peer=quux])
98 check_patches \
99     'br-int patch-quux-to-baz patch-baz-to-quux' \
100     'br-int patch-baz-to-quux patch-quux-to-baz'
101
102 # Change the logical patch ports to VIFs and verify that the OVS patch
103 # ports disappear.
104 AT_CHECK([ovn-sbctl \
105     -- set Port_Binding quux type='""' options='{}' \
106     -- set Port_Binding baz type='""' options='{}'])
107 check_patches
108
109 AT_CLEANUP