datapath-windows: Fix broken build.
[cascardo/ovs.git] / tests / ovn-controller-vtep.at
1 AT_BANNER([ovn_controller_vtep])
2
3 # OVN_CONTROLLER_VTEP_START
4 #
5 # Starts the test with a setup with vtep device.  Each test case must first
6 # call this macro.
7 #
8 # Uses vtep-ovs to simulate the vtep switch 'br-vtep' with two physical ports
9 # 'p0', 'p1'.
10 #
11 # Configures ovn-nb with a logical switch 'br-test'.
12 #
13 #
14 m4_define([OVN_CONTROLLER_VTEP_START],
15   [
16    # this will cause skip when 'make check' using Windows setup.
17    AT_SKIP_IF([test $HAVE_PYTHON = no])
18
19    OVS_RUNDIR=`pwd`; export OVS_RUNDIR
20    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
21    OVS_DBDIR=`pwd`; export OVS_DBDIR
22    OVS_SYSCONFDIR=`pwd`; export OVS_SYSCONFDIR
23
24    dnl Create databases (ovn-nb, ovn-sb, vtep).
25    AT_CHECK([ovsdb-tool create vswitchd.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
26    for daemon in ovn-nb ovn-sb vtep; do
27       AT_CHECK([ovsdb-tool create $daemon.db $abs_top_srcdir/${daemon%%-*}/${daemon}.ovsschema])
28    done
29
30    dnl Start ovsdb-server.
31    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock vswitchd.db vtep.db ovn-nb.db ovn-sb.db], [0], [], [stderr])
32     ON_EXIT_UNQUOTED([kill `cat ovsdb-server.pid`])
33    AT_CHECK([[sed < stderr '
34 /vlog|INFO|opened log file/d
35 /ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
36    AT_CAPTURE_FILE([ovsdb-server.log])
37
38    dnl Start ovs-vswitchd.
39    AT_CHECK([ovs-vswitchd --enable-dummy --disable-system --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif], [0], [], [stderr])
40    AT_CAPTURE_FILE([ovs-vswitchd.log])
41    ON_EXIT_UNQUOTED([kill `cat ovs-vswitchd.pid`])
42    AT_CHECK([[sed < stderr '
43 /ovs_numa|INFO|Discovered /d
44 /vlog|INFO|opened log file/d
45 /vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
46 /reconnect|INFO|/d
47 /ofproto|INFO|using datapath ID/d
48 /ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
49    AT_CHECK([ovs-vsctl -- add-br br-vtep \
50               -- set bridge br-vtep datapath-type=dummy other-config:datapath-id=fedcba9876543210 other-config:hwaddr=aa:55:aa:55:00:00 protocols=[[OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15]] fail-mode=secure \
51               -- add-port br-vtep p0 -- set Interface p0 type=dummy ofport_request=1 \
52               -- add-port br-vtep p1 -- set Interface p1 type=dummy ofport_request=2])
53
54    dnl Start ovs-vtep.
55    AT_CHECK([vtep-ctl add-ps br-vtep -- set Physical_Switch br-vtep tunnel_ips=1.2.3.4])
56    AT_CHECK([ovs-vtep --log-file=ovs-vtep.log --pidfile=ovs-vtep.pid --detach br-vtep \], [0], [], [stderr])
57    ON_EXIT_UNQUOTED([kill `cat ovs-vtep.pid`])
58    AT_CHECK([[sed < stderr '
59 /vlog|INFO|opened log file/d']])
60    # waits until ovs-vtep starts up.
61    OVS_WAIT_UNTIL([test -n "`vtep-ctl show | grep Physical_Port`"])
62
63    dnl Start ovn-northd.
64    AT_CHECK([ovn-nbctl lswitch-add br-test])
65    AT_CHECK([ovn-northd --detach --pidfile --log-file --ovnnb-db=unix:$OVS_RUNDIR/db.sock --ovnsb-db=unix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
66    ON_EXIT_UNQUOTED([kill `cat ovn-northd.pid`])
67    AT_CHECK([[sed < stderr '
68 /vlog|INFO|opened log file/d']])
69    AT_CAPTURE_FILE([ovn-northd.log])
70
71    dnl Start ovn-controllger-vtep.
72    AT_CHECK([ovn-controller-vtep --detach --pidfile --log-file --vtep-db=unix:$OVS_RUNDIR/db.sock --ovnsb-db=unix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
73    AT_CAPTURE_FILE([ovn-controller-vtep.log])
74    ON_EXIT_UNQUOTED([kill `cat ovn-controller-vtep.pid`])
75    AT_CHECK([[sed < stderr '
76 /vlog|INFO|opened log file/d
77 /reconnect|INFO|/d']])
78 ])
79
80 # OVN_CONTROLLER_VTEP_STOP
81 #
82 # So many exits... Yeah, we started a lot daemons~
83 #
84 m4_define([OVN_CONTROLLER_VTEP_STOP],
85   [# removes all 'Broken pipe' warning logs from ovsdb-server.log.  this is in
86    # that *ctl command (e.g. ovn-nbctl) exits right after committing the change
87    # to database.  however, in reaction, some daemon (e.g. ovn-controller-vtep)
88    # may immediately update the database.  this later update may cause database
89    # sending update back to *ctl command if *ctl has not proceeded to exit yet.
90    # and if *ctl command exits before database calling send, the send from
91    # database will fail with 'Broken pipe' error.
92    AT_CHECK([check_logs "$1
93 /Broken pipe/d"])
94    AT_CHECK([ovs-appctl -t ovs-vtep exit])
95    AT_CHECK([ovs-appctl -t ovn-northd exit])
96    AT_CHECK([ovs-appctl -t ovn-controller-vtep exit])
97    # makes sure ovn-controller-vtep exits.
98    OVS_WAIT_UNTIL([test ! -f ovn-controller-vtep.pid])
99    AT_CHECK([ovs-appctl -t ovsdb-server exit])
100    AT_CHECK([ovs-appctl -t ovs-vswitchd exit])])
101
102 # Adds logical port for a vtep gateway chassis in ovn-nb database.
103 #
104 # $1: logical switch name in ovn-nb database
105 # $2: logical port name
106 # $3: physical vtep gateway name
107 # $4: logical switch name on vtep gateway chassis
108 m4_define([OVN_NB_ADD_VTEP_PORT], [
109 AT_CHECK([ovn-nbctl lport-add $1 $2])
110 AT_CHECK([ovn-nbctl lport-set-type $2 vtep])
111 AT_CHECK([ovn-nbctl lport-set-options $2 vtep-physical-switch=$3 vtep-logical-switch=$4])
112 ])
113
114 ##############################################
115
116 # tests chassis related updates.
117 AT_SETUP([ovn-controller-vtep - test chassis])
118 OVN_CONTROLLER_VTEP_START
119
120 # verifies the initial ovn-sb db configuration.
121 AT_CHECK([ovn-sbctl show], [0], [dnl
122 Chassis br-vtep
123     Encap vxlan
124         ip: "1.2.3.4"
125 ])
126
127 # deletes the chassis via ovn-sbctl and check that it is readded back
128 # with the log.
129 AT_CHECK([ovn-sbctl chassis-del br-vtep])
130 OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
131 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log], [0], [dnl
132 |WARN|Chassis for VTEP physical switch (br-vtep) disappears, maybe deleted by ovn-sbctl, adding it back
133 ])
134
135 # changes the tunnel_ip on physical switch, watches the update of chassis's
136 # encap.
137 AT_CHECK([vtep-ctl set Physical_Switch br-vtep tunnel_ips=1.2.3.5])
138 OVS_WAIT_UNTIL([test -n "`ovn-sbctl show | grep 1\.2\.3\.5`"])
139 AT_CHECK([ovn-sbctl --columns=ip list Encap | cut -d ':' -f2 | tr -d ' '], [0], [dnl
140 "1.2.3.5"
141 ])
142
143 # adds vlan_bindings to physical ports.
144 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p0 200 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
145 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch0`"])
146 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
147 [["lswitch0"]]
148 ])
149
150 # adds another logical switch and new vlan_bindings.
151 AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 300 lswitch1])
152 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch1`"])
153 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
154 [["lswitch0","lswitch1"]]
155 ])
156
157 # unbinds one port from lswitch0, nothing should change.
158 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 200])
159 OVS_WAIT_UNTIL([test -z "`vtep-ctl --columns=vlan_bindings list physical_port p0 | grep -- '200='`"])
160 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
161 [["lswitch0","lswitch1"]]
162 ])
163
164 # unbinds all ports from lswitch0.
165 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 100 -- unbind-ls br-vtep p1 300])
166 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch0`"])
167 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
168 [["lswitch1"]]
169 ])
170
171 # unbinds all ports from lswitch1.
172 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 300])
173 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch1`"])
174 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
175 [[]]
176 ])
177
178 OVN_CONTROLLER_VTEP_STOP([/Chassis for VTEP physical switch (br-vtep) disappears/d])
179 AT_CLEANUP
180
181
182 # Tests binding updates.
183 AT_SETUP([ovn-controller-vtep - test binding 1])
184 OVN_CONTROLLER_VTEP_START
185
186 # adds logical switch 'lswitch0' and vlan_bindings.
187 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
188 # adds lport in ovn-nb database, and sets the type and options.
189 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
190 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
191 # should see one binding, associated to chassis of 'br-vtep'.
192 chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
193 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
194 ${chassis_uuid}
195 ])
196
197 # adds another logical switch 'lswitch1' and vlan_bindings.
198 AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 200 lswitch1])
199 # adds lport in ovn-nb database for lswitch1.
200 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch1], [br-vtep], [lswitch1])
201 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch1`"])
202 # This is allowed, but not recommended, to have two vlan_bindings (to different vtep logical switches)
203 # from one vtep gateway physical port in one ovn-nb logical swithch.
204 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
205
206 ${chassis_uuid}
207 ${chassis_uuid}
208 ])
209
210 # adds another lport in ovn-nb database for lswitch0.
211 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0_dup], [br-vtep], [lswitch0])
212 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch0_dup`"])
213 # it is not allowed to have more than one ovn-nb logical port for the same
214 # vtep logical switch on a vtep gateway chassis, so should still see only
215 # two port_binding entries bound.
216 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
217
218
219 [[]]
220 ${chassis_uuid}
221 ${chassis_uuid}
222 ])
223 # confirms the warning log.
224 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log | sed 's/([[-_0-9a-z]][[-_0-9a-z]]*)/()/g' | uniq], [0], [dnl
225 |WARN|logical switch (), on vtep gateway chassis () has already been associated with logical port (), ignore logical port ()
226 ])
227
228 # deletes physical ports from vtep.
229 AT_CHECK([ovs-vsctl del-port p0 -- del-port p1])
230 AT_CHECK([vtep-ctl del-port br-vtep p0 -- del-port br-vtep p1])
231 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch`"])
232 # should see empty chassis column in both binding entries.
233 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort], [0], [dnl
234
235
236 [[]]
237 [[]]
238 [[]]
239 ])
240
241 OVN_CONTROLLER_VTEP_STOP([/has already been associated with logical port/d])
242 AT_CLEANUP
243
244
245 # Tests corner case: Binding the vtep logical switch from two different
246 # datapath.
247 AT_SETUP([ovn-controller-vtep - test binding 2])
248 OVN_CONTROLLER_VTEP_START
249
250 # adds logical switch 'lswitch0' and vlan_bindings.
251 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0])
252 # adds lport in ovn-nb database, and sets the type and options.
253 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
254 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
255
256 # adds another lswitch 'br-void' in ovn-nb database.
257 AT_CHECK([ovn-nbctl lswitch-add br-void])
258 # adds another vtep pswitch 'br-vtep-void' in vtep database.
259 AT_CHECK([vtep-ctl add-ps br-vtep-void -- add-port br-vtep-void p0-void -- bind-ls br-vtep-void p0-void 100 lswitch0])
260 # adds a conflicting logical port (both br-vtep_lswitch0 and br-vtep-void_lswitch0
261 # are bound to the same logical switch, but they are on different datapath).
262 OVN_NB_ADD_VTEP_PORT([br-void], [br-vtep-void_lswitch0], [br-vtep-void], [lswitch0])
263 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep-void_lswitch0`"])
264 OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
265 # confirms the warning log.
266 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log | sed 's/([[-_0-9a-z]][[-_0-9a-z]]*)/()/g;s/(with tunnel key [[0-9]][[0-9]]*)/()/g' | uniq], [0], [dnl
267 |WARN|logical switch (), on vtep gateway chassis () has already been associated with logical datapath (), ignore logical port () which belongs to logical datapath ()
268 ])
269
270 # then deletes 'br-void' and 'br-vtep-void', should see 'br-vtep_lswitch0'
271 # bound correctly.
272 AT_CHECK([ovn-nbctl lswitch-del br-void])
273 # adds another vtep pswitch 'br-vtep-void' in vtep database.
274 AT_CHECK([vtep-ctl del-ps br-vtep-void])
275 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Port_Binding | grep br-vtep-void_lswitch0`"])
276 chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
277 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
278 ${chassis_uuid}
279 ])
280
281 OVN_CONTROLLER_VTEP_STOP([/has already been associated with logical datapath/d])
282 AT_CLEANUP