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