8bf88f2cb149e35410bebee6a6fcaa180331d649
[cascardo/ovs.git] / tests / bfd.at
1 AT_BANNER([bfd])
2
3 m4_define([BFD_CHECK], [
4 AT_CHECK([ovs-appctl bfd/show $1 | sed -e '/Time:/d' | sed -e '/Discriminator/d' | sed -e '/Interval:/d'],[0],
5 [dnl
6         Forwarding: $2
7         Detect Multiplier: 3
8         Concatenated Path Down: $3
9
10         Local Flags: $4
11         Local Session State: $5
12         Local Diagnostic: $6
13
14         Remote Flags: $7
15         Remote Session State: $8
16         Remote Diagnostic: $9
17 ])
18 ])
19
20 m4_define([BFD_CHECK_TX], [
21 AT_CHECK([ovs-appctl bfd/show $1 | sed -n '/TX Interval/p'],[0],
22 [dnl
23         TX Interval: Approx $2
24         Local Minimum TX Interval: $3
25         Remote Minimum TX Interval: $4
26 ])
27 ])
28
29 m4_define([BFD_CHECK_RX], [
30 AT_CHECK([ovs-appctl bfd/show $1 | sed -n '/RX Interval/p'],[0],
31 [dnl
32         RX Interval: Approx $2
33         Local Minimum RX Interval: $3
34         Remote Minimum RX Interval: $4
35 ])
36 ])
37
38 m4_define([BFD_VSCTL_LIST_IFACE], [
39 AT_CHECK([ovs-vsctl list interface $1 | sed -n $2],[0],
40 [dnl
41 $3
42 ])
43 ])
44
45 AT_SETUP([bfd - basic config on different bridges])
46 #Create 2 bridges connected by patch ports and enable BFD
47 OVS_VSWITCHD_START(
48    [add-br br1 -- \
49        set bridge br1 datapath-type=dummy \
50        other-config:hwaddr=aa:55:aa:56:00:00 -- \
51     add-port br1 p1 -- set Interface p1 type=patch \
52        options:peer=p0 -- \
53     add-port br0 p0 -- set Interface p0 type=patch \
54        options:peer=p1 -- \
55     set Interface p0 bfd:enable=true -- \
56     set Interface p1 bfd:enable=true ])
57 ovs-appctl time/stop
58 ovs-appctl time/warp 4100 100
59
60 #Verify that BFD has been enabled on both interfaces.
61 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
62 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
63
64 AT_CHECK([ ovs-vsctl set interface p0 bfd:enable=false])
65 ovs-appctl time/warp 4100 100
66 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
67
68 AT_CHECK([ ovs-vsctl set interface p0 bfd:enable=true])
69 ovs-appctl time/warp 4100 100
70 BFD_CHECK([p1], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
71 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
72
73 ovs-vsctl del-br br0
74 AT_CHECK([ovs-appctl bfd/show p0], [2],[ignore], [no such bfd object
75 ovs-appctl: ovs-vswitchd: server returned an error
76 ])
77 ovs-vsctl del-br br1
78 #Check that the entries are gone.
79 AT_CHECK([ovs-appctl bfd/show p1], [2],[ignore], [no such bfd object
80 ovs-appctl: ovs-vswitchd: server returned an error
81 ])
82
83 OVS_VSWITCHD_STOP
84 AT_CLEANUP
85
86
87 AT_SETUP([bfd - Verify tunnel down detection])
88 #Create 3 bridges - br-bfd0, br-bfd1 and br-sw which is midway between the two. br2 is
89 #connected to br-bfd0 and br-bfd1 through patch ports p0-2 and p1-2. Enable BFD on
90 #interfaces in br-bfd0 and br-bfd1. When br-sw is dropping all packets, BFD should detect
91 # that the tunnel is down, and come back up when br-sw is working fine.
92
93 OVS_VSWITCHD_START(
94    [add-br br-bfd0 -- \
95        set bridge br-bfd0 datapath-type=dummy \
96        other-config:hwaddr=aa:55:aa:56:00:00 -- \
97     add-br br-bfd1 -- \
98        set bridge br-bfd1 datapath-type=dummy \
99        other-config:hwaddr=aa:55:aa:57:00:00 -- \
100     add-br br-sw -- \
101        set bridge br-sw datapath-type=dummy \
102        other-config:hwaddr=aa:55:aa:58:00:00 -- \
103     add-port br-sw p1-sw -- set Interface p1-sw type=patch \
104        options:peer=p1 ofport_request=2 -- \
105     add-port br-sw p0-sw -- set Interface p0-sw type=patch \
106        options:peer=p0 ofport_request=1 -- \
107     add-port br-bfd1 p1 -- set Interface p1 type=patch \
108        options:peer=p1-sw bfd:enable=true -- \
109     add-port br-bfd0 p0 -- set Interface p0 type=patch \
110        options:peer=p0-sw bfd:enable=true --])
111
112 ovs-appctl time/stop
113
114 #Create 2 bridges connected by patch ports and enable BFD
115
116 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
117 #Verify that BFD is enabled.
118 ovs-appctl time/warp 4100 100
119 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
120 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
121
122 #Drop all packets in the br-sw bridge so that the tunnel is down.
123 AT_CHECK([ ovs-ofctl add-flow br-sw 'priority=5,actions=drop' ])
124 ovs-appctl time/warp 4100 100
125 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
126 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
127
128 #Delete the added flow
129 AT_CHECK([ovs-ofctl del-flows br-sw], [0])
130 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
131 #Verify that BFD is back up again.
132 ovs-appctl time/warp 4100 100
133
134 BFD_CHECK([p1], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [Control Detection Time Expired])
135 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [Control Detection Time Expired])
136
137 #Now, Verify one-side tunnel down detection
138 #When br-sw is dropping packets from one end, BFD should detect
139 # that the tunnel is down, and come back up when br-sw is working fine.
140
141 #Bring down the br-bfd1 - br-sw link. So BFD packets will be sent from p0,
142 # but not received by p1. p0 will receive all BFD packets from p1.
143
144 AT_CHECK([ ovs-ofctl add-flow br-sw 'in_port=1,priority=5,actions=drop'])
145 ovs-appctl time/warp 4100 100
146 # Make sure p1 BFD state is down since it received no BFD packets.
147 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
148 ovs-appctl time/warp 4100 100
149
150 # p0 will be in init state once it receives "down" BFD message from p1.
151 BFD_CHECK([p0], [false], [false], [none], [init], [Neighbor Signaled Session Down], [none], [down], [Control Detection Time Expired])
152
153 AT_CHECK([ovs-ofctl del-flows br-sw])
154 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
155 #Ensure that BFD is back up again.
156
157 ovs-appctl time/warp 1100 100
158 #Bring down the br-bfd0 - br-sw link
159 AT_CHECK([ ovs-ofctl add-flow br-sw 'in_port=2,priority=5,actions=drop'])
160 ovs-appctl time/warp 4100 100
161 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
162 ovs-appctl time/warp 4100 100
163 BFD_CHECK([p1], [false], [false], [none], [init], [Neighbor Signaled Session Down], [none], [down], [Control Detection Time Expired])
164 OVS_VSWITCHD_STOP
165 AT_CLEANUP
166
167
168 AT_SETUP([bfd - concatenated path down])
169 #Create 2 bridges connected by patch ports and enable BFD
170 OVS_VSWITCHD_START()
171 ovs-appctl time/stop
172 AT_CHECK([ ovs-vsctl -- add-br br1 -- \
173            set bridge br1 datapath-type=dummy \
174            other-config:hwaddr=aa:55:aa:56:00:00 ])
175 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
176            options:peer=p0 ])
177 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
178            options:peer=p1 ])
179 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
180 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
181 ovs-appctl time/warp 4100 100
182
183 #Verify that BFD has been enabled on both interfaces.
184 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
185 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
186
187 #Set cpath_down to true on one interface, make sure the remote interface updates its values.
188 AT_CHECK([ovs-vsctl set interface p0 bfd:cpath_down=true])
189 ovs-appctl time/warp 4100 100
190 BFD_CHECK([p1], [false], [false], [none], [up], [No Diagnostic], [none], [up], [Concatenated Path Down])
191 OVS_VSWITCHD_STOP
192 AT_CLEANUP
193
194
195 AT_SETUP([bfd - Edit the Min Tx/Rx values])
196 #Create 2 bridges connected by patch ports and enable BFD
197 OVS_VSWITCHD_START()
198 ovs-appctl time/stop
199 AT_CHECK([ ovs-vsctl -- add-br br1 -- \
200            set bridge br1 datapath-type=dummy ])
201 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
202            options:peer=p0 ])
203 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
204            options:peer=p1 ])
205 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
206 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
207 ovs-appctl time/warp 3100 100
208 #Verify that BFD has been enabled on both interfaces.
209 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
210 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
211 #Edit the min Tx value.
212 AT_CHECK([ovs-vsctl set interface p0 bfd:min_tx=200])
213 ovs-appctl time/warp 2100 100
214 BFD_CHECK_TX([p0], [1000ms], [200ms], [100ms])
215 BFD_CHECK_TX([p1], [1000ms], [100ms], [200ms])
216
217 #Edit the min Rx value.
218 AT_CHECK([ovs-vsctl set interface p1 bfd:min_rx=300])
219 ovs-appctl time/warp 2100 100
220 BFD_CHECK_RX([p1], [300ms], [300ms], [1000ms])
221 BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
222
223 OVS_VSWITCHD_STOP
224 AT_CLEANUP
225
226 AT_SETUP([bfd - check_tnl_key])
227 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
228                     options:remote_ip=2.2.2.2 options:key=1 ofport_request=1 -- \
229                     set interface p1 bfd:enable=true -- \
230                     set bridge br0 fail-mode=standalone])
231
232 # by default check_tnl_key is false. so we should process a bfd packet with tun_id=1.
233 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x1,src=2.2.2.2,dst=2.2.2.1,tos=0x0,ttl=64,tp_src=0,tp_dst=0,flags(key)),in_port(1),skb_mark(0/0),eth(src=00:11:22:33:44:55,dst=00:23:20:00:00:01),eth_type(0x0800),ipv4(src=169.254.1.0/0.0.0.0,dst=169.254.1.1/0.0.0.0,proto=17/0xff,tos=0/0,ttl=255/0,frag=no),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
234 # check that the packet should be handled as BFD packet.
235 AT_CHECK([tail -2 stdout], [0], [dnl
236 This flow is handled by the userspace slow path because it:
237         - Consists of BFD packets.
238 ], [])
239
240 # turn on the check_tnl_key.
241 AT_CHECK([ovs-vsctl set interface p1 bfd:check_tnl_key=true])
242 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x1,src=2.2.2.2,dst=2.2.2.1,tos=0x0,ttl=64,tp_src=0,tp_dst=0,flags(key)),in_port(1),skb_mark(0/0),eth(src=00:11:22:33:44:55,dst=00:23:20:00:00:01),eth_type(0x0800),ipv4(src=169.254.1.0/0.0.0.0,dst=169.254.1.1/0.0.0.0,proto=17/0xff,tos=0/0,ttl=255/0,frag=no),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
243 # check that the packet should be handled as normal packet.
244 AT_CHECK([tail -1 stdout], [0],[dnl
245 Datapath actions: 100
246 ], [])
247
248 # set the tunnel key to 0.
249 AT_CHECK([ovs-vsctl set interface p1 options:key=0])
250 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'tunnel(tun_id=0x0,src=2.2.2.2,dst=2.2.2.1,tos=0x0,ttl=64,tp_src=0,tp_dst=0,flags(key)),in_port(1),skb_mark(0/0),eth(src=00:11:22:33:44:55,dst=00:23:20:00:00:01),eth_type(0x0800),ipv4(src=169.254.1.0/0.0.0.0,dst=169.254.1.1/0.0.0.0,proto=17/0xff,tos=0/0,ttl=255/0,frag=no),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
251 # check that the packet should be handled as BFD packet.
252 AT_CHECK([tail -2 stdout], [0], [dnl
253 This flow is handled by the userspace slow path because it:
254         - Consists of BFD packets.
255 ], [])
256
257 OVS_VSWITCHD_STOP
258 AT_CLEANUP
259
260 # Tests below are for bfd decay features.
261 AT_SETUP([bfd - bfd decay])
262 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
263                     add-port br1 p1 -- set Interface p1 type=patch \
264                     options:peer=p0 ofport_request=2 -- \
265                     add-port br0 p0 -- set Interface p0 type=patch \
266                     options:peer=p1 ofport_request=1 -- \
267                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \
268                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
269
270 ovs-appctl time/stop
271
272 # wait for a while to stablize everything.
273 ovs-appctl time/warp 10000 500
274 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
275 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
276 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
277 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
278
279 # Test-1 BFD decay: decay to decay_min_rx
280 AT_CHECK([ovs-vsctl set interface p0 bfd:decay_min_rx=3000])
281 # bfd:decay_min_rx is set to 3000ms after the local state of p0 goes up,
282 # so for the first 2000ms, there should be no change.
283 ovs-appctl time/warp 2000 500
284 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
285 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
286
287 # advance the clock by 5000ms.
288 ovs-appctl time/warp 5000 500
289 # now, min_rx should decay to 3000ms.
290 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
291 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
292
293 # advance clock by 5000ms and check the the flags are all 'none'.
294 ovs-appctl time/warp 5000 500
295 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
296 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
297 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
298 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
299 # End of Test-1 ###############################################################
300
301
302 # Test-2 BFD decay: go back to min_rx when there is traffic
303 # receive packet at 1/100ms rate for 5000ms.
304 for i in `seq 0 49`
305 do
306     ovs-appctl time/warp 100
307     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
308              [0], [stdout], [])
309 done
310 # after a decay interval (3000ms), the p0 min_rx will go back to
311 # min_rx.
312 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
313 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
314 # End of Test-2 ###############################################################
315
316
317 # Test-3 BFD decay: set decay_min_rx to 1000ms.
318 # this should firstly reset the min_rx and then re-decay to 1000ms.
319 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=1000])
320 # advance the clock by 10000ms, decay should have happened.
321 ovs-appctl time/warp 10000 500
322 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
323 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
324 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
325 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
326 # End of Test-3 ###############################################################
327
328
329 # Test-4 BFD decay: set decay_min_rx to 0 to disable bfd decay.
330 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=0])
331 # advance the clock by 5000ms.
332 ovs-appctl time/warp 10000 500
333 # min_rx is reset.
334 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
335 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
336
337 for i in `seq 0 20`
338 do
339     ovs-appctl time/warp 500
340     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
341     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
342     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
343     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
344 done
345 # End of Test-4 ################################################################
346
347
348 # Test-5 BFD decay: rmt_min_tx is greater than decay_min_rx
349 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=3000 -- set interface p1 bfd:min_tx=5000])
350 # advance the clock by 10000ms to stable everything.
351 ovs-appctl time/warp 10000 500
352 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
353 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
354 # p0 rx should show 5000ms even if it is in decay.
355 BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
356 BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
357 # then, there should be no change of status,
358 for i in `seq 0 19`
359 do
360     ovs-appctl time/warp 500
361     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
362     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
363     BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
364     BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
365 done
366 # reset the p1's min_tx to 500ms.
367 AT_CHECK([ovs-vsctl set Interface p1 bfd:min_tx=500])
368 # advance the clock by 20000ms to stable everything.
369 # since p0 has been in decay, now the RX will show 3000ms.
370 ovs-appctl time/warp 20000 500
371 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
372 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
373 # End of Test-5 ###############################################################
374
375
376 # Test-6 BFD decay: state up->down->up.
377 # turn bfd off on p1
378 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false])
379
380 # advance the clock by 15000ms to stable everything.
381 ovs-appctl time/warp 15000 1000
382 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
383 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
384 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
385
386 # resume the bfd on p1. the bfd should not go to decay mode direclty.
387 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true])
388 ovs-appctl time/warp 1500 500
389 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
390 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
391
392 # since the decay_min_rx is still 3000ms, so after 5000ms, p0 should have decayed.
393 ovs-appctl time/warp 5000 500
394 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
395 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
396 # End of Test-6 ################################################################
397
398 OVS_VSWITCHD_STOP
399 AT_CLEANUP
400
401 # Tests below are for bfd forwarding_if_rx feature.
402
403 # forwarding_if_rx Test1
404 # Test1 tests the case when bfd is only enabled on one end of the link.
405 # Under this situation, the forwarding flag should always be false, even
406 # though there is data packet received, since there is no bfd control
407 # packet received during the demand_rx_bfd interval.
408 AT_SETUP([bfd - bfd forwarding_if_rx - bfd on one side])
409 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
410                     add-port br1 p1 -- set Interface p1 type=patch \
411                     options:peer=p0 ofport_request=2 -- \
412                     add-port br0 p0 -- set Interface p0 type=patch \
413                     options:peer=p1 ofport_request=1 -- \
414                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
415                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
416
417 ovs-appctl time/stop
418 # check the inital status.
419 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
420 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
421 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
422
423 # enable forwarding_if_rx.
424 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
425
426 # there should be no change of forwarding flag, since
427 # there is no traffic.
428 for i in `seq 0 3`
429 do
430     ovs-appctl time/warp 500
431     BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
432 done
433
434 # receive packet at 1/100ms rate for 2000ms.
435 for i in `seq 0 19`
436 do
437     ovs-appctl time/warp 100
438     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
439              [0], [stdout], [])
440 done
441 # the forwarding flag should be false, due to the demand_rx_bfd.
442 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
443
444 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
445 AT_CLEANUP
446
447
448 # forwarding_if_rx Test2
449 # Test2 is for testing that the enable of forwarding_if_rx will not
450 # affect the normal bfd communication.  bfd is enabled on both ends of
451 # the link.
452 AT_SETUP([bfd - bfd forwarding_if_rx - bfd on both sides])
453 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
454                     add-port br1 p1 -- set Interface p1 type=patch \
455                     options:peer=p0 ofport_request=2 -- \
456                     add-port br0 p0 -- set Interface p0 type=patch \
457                     options:peer=p1 ofport_request=1 -- \
458                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
459                     set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \
460                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
461
462 ovs-appctl time/stop
463 # advance the clock, to stablize the states.
464 ovs-appctl time/warp 5000 500
465
466 # enable forwarding_if_rx.
467 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
468
469 # there should be no change of the forwarding flag, since
470 # the bfd on both ends is already up.
471 for i in `seq 0 5`
472 do
473     ovs-appctl time/warp 500
474     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
475 done
476
477 # stop the bfd on one side.
478 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
479 # for within 1500ms, the detection timer is not out.
480 # there is no change to status.
481 for i in `seq 0 1`
482 do
483     ovs-appctl time/warp 500
484     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
485     for i in `seq 0 4`
486     do
487         AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
488                  [0], [stdout], [])
489     done
490 done
491
492 # at 1500ms, the STATE should go DOWN, due to Control Detection Time Expired.
493 # but forwarding flag should be still true.
494 ovs-appctl time/warp 500
495 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
496
497 # reset bfd forwarding_if_rx.
498 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false], [0])
499 # forwarding flag should turn to false since the STATE is DOWN.
500 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
501
502 # re-enable bfd on the other end. the states should be up.
503 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
504 # advance the clock, to stablize the states.
505 ovs-appctl time/warp 5000 500
506 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
507 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
508 BFD_CHECK_TX([p0], [500ms], [500ms], [300ms])
509 BFD_CHECK_RX([p0], [500ms], [500ms], [300ms])
510
511 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
512 AT_CLEANUP
513
514 # forwarding_if_rx Test3
515 # Test3 is for testing that the enable of forwarding_if_rx will not
516 # affect the bfd decay feature.  bfd is enabled on both ends of the link.
517 AT_SETUP([bfd - bfd forwarding_if_rx - with bfd decay])
518 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
519                     add-port br1 p1 -- set Interface p1 type=patch \
520                     options:peer=p0 ofport_request=2 -- \
521                     add-port br0 p0 -- set Interface p0 type=patch \
522                     options:peer=p1 ofport_request=1 -- \
523                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 bfd:decay_min_rx=3000 -- \
524                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
525
526 ovs-appctl time/stop
527 # advance the clock, to stablize the states.
528 ovs-appctl time/warp 10000 500
529 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
530 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
531 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
532 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
533
534 # enable forwarding_if_rx.
535 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
536
537 # there should be no change of the forwarding flag, since
538 # the bfd on both ends is already up.
539 for i in `seq 0 9`
540 do
541     ovs-appctl time/warp 500
542     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
543 done
544
545 # reconfigure the decay_min_rx to 1000ms.
546 AT_CHECK([ovs-vsctl set interface p0 bfd:decay_min_rx=1000])
547
548 # wait for 5000ms to decay.
549 ovs-appctl time/warp 5000 500
550 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
551 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
552 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
553
554 # stop the bfd on one side.
555 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
556
557 # advance clock by 4000ms, while receiving packets.
558 # the STATE should go DOWN, due to Control Detection Time Expired.
559 # but forwarding flag should be still true.
560 for i in `seq 0 7`
561 do
562     ovs-appctl time/warp 500
563     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
564              [0], [stdout], [])
565 done
566 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
567
568 # receive packet at 1/100ms rate for 1000ms.
569 for i in `seq 0 9`
570 do
571     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
572              [0], [stdout], [])
573     ovs-appctl time/warp 100
574     # the forwarding flag should always be true during this time.
575     BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
576 done
577
578 # stop receiving for 5000ms.
579 ovs-appctl time/warp 5000 100
580 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
581
582 # reset bfd forwarding_if_rx.
583 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false])
584 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
585 # re-enable bfd forwarding_if_rx.
586 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true])
587 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
588
589 # re-enable bfd on the other end. the states should be up.
590 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
591 # advance the clock, to stablize the states.
592 ovs-appctl time/warp 10000 500
593 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
594 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
595 BFD_CHECK_TX([p0], [300ms], [300ms], [300ms])
596 BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
597
598 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
599 AT_CLEANUP
600
601 # forwarding_if_rx Test4
602 # Test4 is for testing the demand_rx_bfd feature.
603 # bfd is enabled on both ends of the link.
604 AT_SETUP([bfd - bfd forwarding_if_rx - demand_rx_bfd])
605 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
606                     add-port br1 p1 -- set Interface p1 type=patch \
607                     options:peer=p0 ofport_request=2 -- \
608                     add-port br0 p0 -- set Interface p0 type=patch \
609                     options:peer=p1 ofport_request=1 -- \
610                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 bfd:forwarding_if_rx=true -- \
611                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
612
613 ovs-appctl time/stop
614 # advance the clock, to stablize the states.
615 ovs-appctl time/warp 10000 500
616 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
617 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
618 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
619
620 # disable the bfd on p1.
621 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
622
623 # advance clock by 4000ms, while receiving packets.
624 # the STATE should go DOWN, due to Control Detection Time Expired.
625 # but forwarding flag should be still true.
626 for i in `seq 0 7`
627 do
628     ovs-appctl time/warp 500
629     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
630              [0], [stdout], [])
631 done
632 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
633
634 # advance clock long enough to trigger the demand_bfd_rx interval
635 # (100 * bfd->cfm_min_rx), forwarding flag should go down since there
636 # is no bfd control packet received during the demand_rx_bfd.
637 for i in `seq 0 120`
638 do
639     ovs-appctl time/warp 300
640     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
641              [0], [stdout], [])
642 done
643 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
644
645 # now enable the bfd on p1 again.
646 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true], [0])
647 # advance clock by 5000ms.  and p1 and p0 should be all up.
648 ovs-appctl time/warp 5000 500
649 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
650 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
651 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
652
653 # disable the bfd on p1 again.
654 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
655 # advance clock long enough to trigger the demand_rx_bfd,
656 # forwarding flag should go down since there is no bfd control packet
657 # received during the demand_rx_bfd.
658 for i in `seq 0 120`
659 do
660     ovs-appctl time/warp 300
661     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
662              [0], [stdout], [])
663 done
664 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
665
666 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
667 AT_CLEANUP
668
669 # test bfd:flap_count.
670 # This test contains three part:
671 # part 1. tests the flap_count on normal bfd monitored link.
672 # part 2. tests the flap_count when forwarding override is used.
673 # part 3. tests the flap_count when forwarding_if_rx is enabled.
674 AT_SETUP([bfd - flap_count])
675 #Create 2 bridges connected by patch ports and enable bfd
676 OVS_VSWITCHD_START([add-br br1 -- \
677                     set bridge br1 datapath-type=dummy \
678                     other-config:hwaddr=aa:55:aa:56:00:00 -- \
679                     add-port br1 p1 -- set Interface p1 type=patch \
680                     options:peer=p0 ofport_request=2 -- \
681                     add-port br0 p0 -- set Interface p0 type=patch \
682                     options:peer=p1 ofport_request=1 -- \
683                     set Interface p0 bfd:enable=true bfd:min_tx=100 bfd:min_rx=100 -- \
684                     set Interface p1 bfd:enable=true bfd:min_tx=100 bfd:min_rx=100])
685
686 ovs-appctl time/stop
687 # Disable the stats update to prevent the race between ovsdb updating
688 # stats and ovs-vsctl cmd closing the jsonrpc session.
689 AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:stats-update-interval=50000000])
690
691 # Part-1 wait for a while to stablize bfd.
692 ovs-appctl time/warp 10100 100
693 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
694 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
695 BFD_CHECK_TX([p0], [100ms], [100ms], [100ms])
696 BFD_CHECK_RX([p0], [100ms], [100ms], [100ms])
697 # both p0 and p1 should have flap_count = "1". since down->up.
698 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
699 BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
700
701 # turn bfd on p1 off, should increment the bfd:flap_count on p0.
702 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=false])
703 ovs-appctl time/warp 5000 100
704 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
705 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["2"])
706 AT_CHECK([ovs-vsctl list interface p1 | sed -n "s/^.*flap_count=\(.*\), forwarding.*$/\1/p"])
707
708 # turn bfd on p1 on again, should increment the bfd:flap_count on p0.
709 # p1 should still have flap_count = "1", since it is reset.
710 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=true])
711 ovs-appctl time/warp 5000 100
712 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["3"])
713 BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
714
715
716 # Part-2 now turn on the forwarding_override.
717 AT_CHECK([ovs-appctl bfd/set-forwarding p0 true], [0], [dnl
718 OK
719 ])
720
721 # turn bfd on p1 off, should not increment the bfd:flap_count on p0, since forwarding_override is on.
722 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=false])
723 ovs-appctl time/warp 5000 100
724 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
725 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["3"])
726 AT_CHECK([ovs-vsctl list interface p1 | sed -n "s/^.*flap_count=\(.*\), forwarding.*$/\1/p"])
727
728 # turn bfd on p1 on again, should not increment the bfd:flap_count on p0, since forwarding override is on.
729 # p1 should still have flap_count = "1", since it is reset.
730 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=true])
731 ovs-appctl time/warp 5000 100
732 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["3"])
733 BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
734
735 # turn the forwarding_override back to normal.
736 AT_CHECK([ovs-appctl bfd/set-forwarding p0 normal], [0], [dnl
737 OK
738 ])
739
740 # turn bfd on p1 off and on, should increment the bfd:flap_count on p0.
741 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=false])
742 ovs-appctl time/warp 5000 100
743 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=true])
744 ovs-appctl time/warp 5000 100
745 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["5"])
746 BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
747
748 # Part-3 now turn on forwarding_if_rx.
749 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
750 ovs-appctl time/warp 1100 100
751 # disable the bfd on p1.
752 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
753
754 # advance clock by 4000ms, while receiving packets.
755 # the STATE should go DOWN, due to Control Detection Time Expired.
756 # but forwarding flag should be true.
757 for i in `seq 0 39`
758 do
759     ovs-appctl time/warp 100
760     AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
761              [0], [stdout], [])
762 done
763 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
764 # flap_count should remain unchanged.
765 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["5"])
766
767 # stop the traffic for more than 100 * bfd->cfm_min_rx ms, the forwarding flag of p0 should turn false.
768 # and there should be the increment of flap_count.
769 ovs-appctl time/warp 12100 100
770 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
771 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["6"])
772
773 # advance clock by 4000ms, and resume the traffic.
774 for i in `seq 0 39`
775 do
776     ovs-appctl time/warp 100
777     AT_CHECK([ovs-ofctl packet-out br1 3 2 "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
778              [0], [stdout], [])
779 done
780 # forwarding should be false, since there is still no bfd control packet received.
781 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
782 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["6"])
783
784 # turn on the bfd on p1.
785 AT_CHECK([ovs-vsctl set interface p1 bfd:enable=true])
786 ovs-appctl time/warp 5000 100
787 # even though there is no data traffic, since p1 bfd is on again, should increment the flap_count.
788 BFD_VSCTL_LIST_IFACE([p0], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["7"])
789 BFD_VSCTL_LIST_IFACE([p1], ["s/^.*flap_count=\(.*\), forwarding.*$/\1/p"], ["1"])
790
791 OVS_VSWITCHD_STOP
792 AT_CLEANUP