72ec6aea8881b9b4346b1af6b6656b10ef8cd170
[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   [AT_CHECK([check_logs $1])
86    AT_CHECK([ovs-appctl -t ovs-vtep exit])
87    AT_CHECK([ovs-appctl -t ovn-northd exit])
88    AT_CHECK([ovs-appctl -t ovn-controller-vtep exit])
89    # makes sure ovn-controller-vtep exits.
90    OVS_WAIT_UNTIL([test ! -f ovn-controller-vtep.pid])
91    AT_CHECK([ovs-appctl -t ovsdb-server exit])
92    AT_CHECK([ovs-appctl -t ovs-vswitchd exit])])
93
94 # Adds logical port for a vtep gateway chassis in ovn-nb database.
95 #
96 # $1: logical switch name in ovn-nb database
97 # $2: logical port name
98 # $3: physical vtep gateway name
99 # $4: logical switch name on vtep gateway chassis
100 m4_define([OVN_NB_ADD_VTEP_PORT], [
101 AT_CHECK([ovn-nbctl lport-add $1 $2])
102 AT_CHECK([ovn-nbctl lport-set-type $2 vtep])
103 AT_CHECK([ovn-nbctl lport-set-options $2 vtep-physical-switch=$3 vtep-logical-switch=$4])
104 ])
105
106 ##############################################
107
108 # tests chassis related updates.
109 AT_SETUP([ovn-controller-vtep - test chassis])
110 OVN_CONTROLLER_VTEP_START
111
112 # verifies the initial ovn-sb db configuration.
113 AT_CHECK([ovn-sbctl show], [0], [dnl
114 Chassis br-vtep
115     Encap vxlan
116         ip: "1.2.3.4"
117 ])
118
119 # deletes the chassis via ovn-sbctl and check that it is readded back
120 # with the log.
121 AT_CHECK([ovn-sbctl chassis-del br-vtep])
122 OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
123 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log], [0], [dnl
124 |WARN|Chassis for VTEP physical switch (br-vtep) disappears, maybe deleted by ovn-sbctl, adding it back
125 ])
126 # this removal of chassis could cause 'Broken pipe' warning in the ovsdb-server.log,
127 # due to the race between 'ovn-sbctl' exiting and 'ovn-controller-vtep' adding
128 # the chassis back.  so just removes the 'Broken pipe' warning from ovsdb-server.log.
129 AT_CHECK([sed -i '/Broken pipe/d' ovsdb-server.log])
130
131 # changes the tunnel_ip on physical switch, watches the update of chassis's
132 # encap.
133 AT_CHECK([vtep-ctl set Physical_Switch br-vtep tunnel_ips=1.2.3.5])
134 OVS_WAIT_UNTIL([test -n "`ovn-sbctl show | grep 1\.2\.3\.5`"])
135 AT_CHECK([ovn-sbctl --columns=ip list Encap | cut -d ':' -f2 | tr -d ' '], [0], [dnl
136 "1.2.3.5"
137 ])
138
139 # adds vlan_bindings to physical ports.
140 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])
141 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch0`"])
142 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
143 [["lswitch0"]]
144 ])
145
146 # adds another logical switch and new vlan_bindings.
147 AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 300 lswitch1])
148 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Chassis | grep -- lswitch1`"])
149 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
150 [["lswitch0","lswitch1"]]
151 ])
152
153 # unbinds one port from lswitch0, nothing should change.
154 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 200])
155 OVS_WAIT_UNTIL([test -z "`vtep-ctl --columns=vlan_bindings list physical_port p0 | grep -- '200='`"])
156 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
157 [["lswitch0","lswitch1"]]
158 ])
159
160 # unbinds all ports from lswitch0.
161 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 100 -- unbind-ls br-vtep p1 300])
162 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch0`"])
163 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' ' ], [0], [dnl
164 [["lswitch1"]]
165 ])
166
167 # unbinds all ports from lswitch1.
168 AT_CHECK([vtep-ctl unbind-ls br-vtep p0 300])
169 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch1`"])
170 AT_CHECK([ovn-sbctl --columns=vtep_logical_switches list Chassis | cut -d ':' -f2 | tr -d ' '], [0], [dnl
171 [[]]
172 ])
173
174 OVN_CONTROLLER_VTEP_STOP(["/Chassis for VTEP physical switch (br-vtep) disappears/d"])
175 AT_CLEANUP
176
177
178 # Tests binding updates.
179 AT_SETUP([ovn-controller-vtep - test binding 1])
180 OVN_CONTROLLER_VTEP_START
181
182 # adds logical switch 'lswitch0' and vlan_bindings.
183 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0 -- bind-ls br-vtep p1 300 lswitch0])
184 # adds lport in ovn-nb database, and sets the type and options.
185 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
186 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
187 # should see one binding, associated to chassis of 'br-vtep'.
188 chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
189 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
190 ${chassis_uuid}
191 ])
192
193 # adds another logical switch 'lswitch1' and vlan_bindings.
194 AT_CHECK([vtep-ctl add-ls lswitch1 -- bind-ls br-vtep p0 200 lswitch1])
195 # adds lport in ovn-nb database for lswitch1.
196 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch1], [br-vtep], [lswitch1])
197 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch1`"])
198 # This is allowed, but not recommended, to have two vlan_bindings (to different vtep logical switches)
199 # from one vtep gateway physical port in one ovn-nb logical swithch.
200 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
201
202 ${chassis_uuid}
203 ${chassis_uuid}
204 ])
205
206 # adds another lport in ovn-nb database for lswitch0.
207 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0_dup], [br-vtep], [lswitch0])
208 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding | grep -- br-vtep_lswitch0_dup`"])
209 # it is not allowed to have more than one ovn-nb logical port for the same
210 # vtep logical switch on a vtep gateway chassis, so should still see only
211 # two port_binding entries bound.
212 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort -d], [0], [dnl
213
214
215 [[]]
216 ${chassis_uuid}
217 ${chassis_uuid}
218 ])
219 # confirms the warning log.
220 AT_CHECK([sed -n 's/^.*\(|WARN|.*\)$/\1/p' ovn-controller-vtep.log | sed 's/([[-_0-9a-z]][[-_0-9a-z]]*)/()/g' | uniq], [0], [dnl
221 |WARN|logical switch (), on vtep gateway chassis () has already been associated with logical port (), ignore logical port ()
222 ])
223
224 # deletes physical ports from vtep.
225 AT_CHECK([ovs-vsctl del-port p0 -- del-port p1])
226 AT_CHECK([vtep-ctl del-port br-vtep p0 -- del-port br-vtep p1])
227 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Chassis | grep -- br-vtep_lswitch`"])
228 # should see empty chassis column in both binding entries.
229 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding | cut -d ':' -f2 | tr -d ' ' | sort], [0], [dnl
230
231
232 [[]]
233 [[]]
234 [[]]
235 ])
236
237 OVN_CONTROLLER_VTEP_STOP(["/has already been associated with logical port/d"])
238 AT_CLEANUP
239
240
241 # Tests corner case: Binding the vtep logical switch from two different
242 # datapath.
243 AT_SETUP([ovn-controller-vtep - test binding 2])
244 OVN_CONTROLLER_VTEP_START
245
246 # adds logical switch 'lswitch0' and vlan_bindings.
247 AT_CHECK([vtep-ctl add-ls lswitch0 -- bind-ls br-vtep p0 100 lswitch0])
248 # adds lport in ovn-nb database, and sets the type and options.
249 OVN_NB_ADD_VTEP_PORT([br-test], [br-vtep_lswitch0], [br-vtep], [lswitch0])
250 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep_lswitch0`"])
251
252 # adds another lswitch 'br-void' in ovn-nb database.
253 AT_CHECK([ovn-nbctl lswitch-add br-void])
254 # adds another vtep pswitch 'br-vtep-void' in vtep database.
255 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])
256 # adds a conflicting logical port (both br-vtep_lswitch0 and br-vtep-void_lswitch0
257 # are bound to the same logical switch, but they are on different datapath).
258 OVN_NB_ADD_VTEP_PORT([br-void], [br-vtep-void_lswitch0], [br-vtep-void], [lswitch0])
259 OVS_WAIT_UNTIL([test -n "`ovn-sbctl list Port_Binding  | grep br-vtep-void_lswitch0`"])
260 OVS_WAIT_UNTIL([test -n "`grep WARN ovn-controller-vtep.log`"])
261 # confirms the warning log.
262 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
263 |WARN|logical switch (), on vtep gateway chassis () has already been associated with logical datapath (), ignore logical port () which belongs to logical datapath ()
264 ])
265
266 # then deletes 'br-void' and 'br-vtep-void', should see 'br-vtep_lswitch0'
267 # bound correctly.
268 AT_CHECK([ovn-nbctl lswitch-del br-void])
269 # adds another vtep pswitch 'br-vtep-void' in vtep database.
270 AT_CHECK([vtep-ctl del-ps br-vtep-void])
271 OVS_WAIT_UNTIL([test -z "`ovn-sbctl list Port_Binding | grep br-vtep-void_lswitch0`"])
272 chassis_uuid=$(ovn-sbctl --columns=_uuid list Chassis br-vtep | cut -d ':' -f2 | tr -d ' ')
273 AT_CHECK_UNQUOTED([ovn-sbctl --columns=chassis list Port_Binding br-vtep_lswitch0 | cut -d ':' -f2 | tr -d ' '], [0], [dnl
274 ${chassis_uuid}
275 ])
276
277 OVN_CONTROLLER_VTEP_STOP(["/has already been associated with logical datapath/d"])
278 AT_CLEANUP