tests: Relax the requirement of bfd tests on timing.
[sliver-openvswitch.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 AT_SETUP([bfd - basic config on different bridges])
38 #Create 2 bridges connected by patch ports and enable BFD
39 OVS_VSWITCHD_START(
40    [add-br br1 -- \
41        set bridge br1 datapath-type=dummy \
42        other-config:hwaddr=aa:55:aa:56:00:00 -- \
43     add-port br1 p1 -- set Interface p1 type=patch \
44        options:peer=p0 -- \
45     add-port br0 p0 -- set Interface p0 type=patch \
46        options:peer=p1 -- \
47     set Interface p0 bfd:enable=true -- \
48     set Interface p1 bfd:enable=true ])
49 ovs-appctl time/stop
50 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
51
52 #Verify that BFD has been enabled on both interfaces.
53 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
54 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
55
56 AT_CHECK([ ovs-vsctl set interface p0 bfd:enable=false])
57 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
58 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
59
60 AT_CHECK([ ovs-vsctl set interface p0 bfd:enable=true])
61 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
62 BFD_CHECK([p1], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
63 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
64
65 ovs-vsctl del-br br0
66 AT_CHECK([ovs-appctl bfd/show p0], [2],[ignore], [no such bfd object
67 ovs-appctl: ovs-vswitchd: server returned an error
68 ])
69 ovs-vsctl del-br br1
70 #Check that the entries are gone.
71 AT_CHECK([ovs-appctl bfd/show p1], [2],[ignore], [no such bfd object
72 ovs-appctl: ovs-vswitchd: server returned an error
73 ])
74
75 OVS_VSWITCHD_STOP
76 AT_CLEANUP
77
78
79 AT_SETUP([bfd - Verify tunnel down detection])
80 #Create 3 bridges - br-bfd0, br-bfd1 and br-sw which is midway between the two. br2 is
81 #connected to br-bfd0 and br-bfd1 through patch ports p0-2 and p1-2. Enable BFD on
82 #interfaces in br-bfd0 and br-bfd1. When br-sw is dropping all packets, BFD should detect
83 # that the tunnel is down, and come back up when br-sw is working fine.
84
85 OVS_VSWITCHD_START(
86    [add-br br-bfd0 -- \
87        set bridge br-bfd0 datapath-type=dummy \
88        other-config:hwaddr=aa:55:aa:56:00:00 -- \
89     add-br br-bfd1 -- \
90        set bridge br-bfd1 datapath-type=dummy \
91        other-config:hwaddr=aa:55:aa:57:00:00 -- \
92     add-br br-sw -- \
93        set bridge br-sw datapath-type=dummy \
94        other-config:hwaddr=aa:55:aa:58:00:00 -- \
95     add-port br-sw p1-sw -- set Interface p1-sw type=patch \
96        options:peer=p1 -- \
97     add-port br-sw p0-sw -- set Interface p0-sw type=patch \
98        options:peer=p0 -- \
99     add-port br-bfd1 p1 -- set Interface p1 type=patch \
100        options:peer=p1-sw bfd:enable=true -- \
101     add-port br-bfd0 p0 -- set Interface p0 type=patch \
102        options:peer=p0-sw bfd:enable=true --])
103
104 ovs-appctl time/stop
105
106 #Create 2 bridges connected by patch ports and enable BFD
107
108 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
109 #Verify that BFD is enabled.
110 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
111 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
112 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
113
114 #Drop all packets in the br-sw bridge so that the tunnel is down.
115 AT_CHECK([ ovs-ofctl add-flow br-sw 'priority=5,actions=drop' ])
116 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
117 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
118 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
119
120 #Delete the added flow
121 AT_CHECK([ovs-ofctl del-flows br-sw], [0])
122 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
123 #Verify that BFD is back up again.
124 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
125
126 BFD_CHECK([p1], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [Control Detection Time Expired])
127 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [Control Detection Time Expired])
128
129 #Now, Verify one-side tunnel down detection
130 #When br-sw is dropping packets from one end, BFD should detect
131 # that the tunnel is down, and come back up when br-sw is working fine.
132
133 #Bring down the br-bfd1 - br-sw link. So BFD packets will be sent from p0,
134 # but not received by p1. p0 will receive all BFD packets from p1.
135
136 AT_CHECK([ ovs-ofctl add-flow br-sw 'in_port=1,priority=5,actions=drop'])
137 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
138 # Make sure p1 BFD state is down since it received no BFD packets.
139 BFD_CHECK([p1], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
140 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
141 # p0 will be in init state once it receives "down" BFD message from p1.
142 BFD_CHECK([p0], [false], [false], [none], [init], [Neighbor Signaled Session Down], [none], [down], [Control Detection Time Expired])
143
144 AT_CHECK([ovs-ofctl del-flows br-sw])
145 AT_CHECK([ovs-ofctl add-flow br-sw 'priority=0,actions=NORMAL'])
146 #Ensure that BFD is back up again.
147
148 for i in `seq 0 10`; do ovs-appctl time/warp 100; done
149 #Bring down the br-bfd0 - br-sw link
150 AT_CHECK([ ovs-ofctl add-flow br-sw 'in_port=2,priority=5,actions=drop'])
151 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
152 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
153 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
154 BFD_CHECK([p1], [false], [false], [none], [init], [Neighbor Signaled Session Down], [none], [down], [Control Detection Time Expired])
155 OVS_VSWITCHD_STOP
156 AT_CLEANUP
157
158
159 AT_SETUP([bfd - concatenated path down])
160 #Create 2 bridges connected by patch ports and enable BFD
161 OVS_VSWITCHD_START()
162 ovs-appctl time/stop
163 AT_CHECK([ ovs-vsctl -- add-br br1 -- \
164            set bridge br1 datapath-type=dummy \
165            other-config:hwaddr=aa:55:aa:56:00:00 ])
166 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
167            options:peer=p0 ])
168 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
169            options:peer=p1 ])
170 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
171 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
172 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
173
174 #Verify that BFD has been enabled on both interfaces.
175 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
176 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
177
178 #Set cpath_down to true on one interface, make sure the remote interface updates its values.
179 AT_CHECK([ovs-vsctl set interface p0 bfd:cpath_down=true])
180 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
181 BFD_CHECK([p1], [false], [false], [none], [up], [No Diagnostic], [none], [up], [Concatenated Path Down])
182 OVS_VSWITCHD_STOP
183 AT_CLEANUP
184
185
186 AT_SETUP([bfd - Edit the Min Tx/Rx values])
187 #Create 2 bridges connected by patch ports and enable BFD
188 OVS_VSWITCHD_START()
189 ovs-appctl time/stop
190 AT_CHECK([ ovs-vsctl -- add-br br1 -- \
191            set bridge br1 datapath-type=dummy ])
192 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
193            options:peer=p0 ])
194 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
195            options:peer=p1 ])
196 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
197 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
198 for i in `seq 0 30`; do ovs-appctl time/warp 100; done
199 #Verify that BFD has been enabled on both interfaces.
200 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
201 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
202 #Edit the min Tx value.
203 AT_CHECK([ovs-vsctl set interface p0 bfd:min_tx=200])
204 for i in `seq 0 20`; do ovs-appctl time/warp 100; done
205 BFD_CHECK_TX([p0], [1000ms], [200ms], [100ms])
206 BFD_CHECK_TX([p1], [1000ms], [100ms], [200ms])
207
208 #Edit the min Rx value.
209 AT_CHECK([ovs-vsctl set interface p1 bfd:min_rx=300])
210 for i in `seq 0 20`; do ovs-appctl time/warp 100; done
211 BFD_CHECK_RX([p1], [300ms], [300ms], [1000ms])
212 BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
213
214 OVS_VSWITCHD_STOP
215 AT_CLEANUP
216
217 AT_SETUP([bfd - check_tnl_key])
218 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
219                     options:remote_ip=2.2.2.2 options:key=1 ofport_request=1 -- \
220                     set interface p1 bfd:enable=true -- \
221                     set bridge br0 fail-mode=standalone])
222
223 # by default check_tnl_key is false. so we should process a bfd packet with tun_id=1.
224 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,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/0xff),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
225 # check that the packet should be handled as BFD packet.
226 AT_CHECK([tail -2 stdout], [0], [dnl
227 This flow is handled by the userspace slow path because it:
228         - Consists of BFD packets.
229 ], [])
230
231 # turn on the check_tnl_key.
232 AT_CHECK([ovs-vsctl set interface p1 bfd:check_tnl_key=true])
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,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/0xff),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
234 # check that the packet should be handled as normal packet.
235 AT_CHECK([tail -1 stdout], [0],[dnl
236 Datapath actions: 100
237 ], [])
238
239 # set the tunnel key to 0.
240 AT_CHECK([ovs-vsctl set interface p1 options:key=0])
241 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,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/0xff),udp(src=49152/0,dst=3784/0xffff)' -generate], [0], [stdout])
242 # check that the packet should be handled as BFD packet.
243 AT_CHECK([tail -2 stdout], [0], [dnl
244 This flow is handled by the userspace slow path because it:
245         - Consists of BFD packets.
246 ], [])
247
248 OVS_VSWITCHD_STOP
249 AT_CLEANUP
250
251 # Tests below are for bfd decay features.
252 AT_SETUP([bfd - bfd decay])
253 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
254                     add-port br1 p1 -- set Interface p1 type=patch \
255                     options:peer=p0 ofport_request=2 -- \
256                     add-port br0 p0 -- set Interface p0 type=patch \
257                     options:peer=p1 ofport_request=1 -- \
258                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \
259                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
260
261 ovs-appctl time/stop
262
263 # wait for a while to stablize everything.
264 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
265 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
266 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
267 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
268 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
269
270 # Test-1 BFD decay: decay to decay_min_rx
271 AT_CHECK([ovs-vsctl set interface p0 bfd:decay_min_rx=3000])
272 # set the bfd:decay_min_rx of p0 to 3000ms.
273 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
274 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
275
276 # bfd:decay_min_rx is set to 3000ms after the local state of p0 goes up,
277 # so for the first 2500ms, there should be no change.
278 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
279 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
280 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
281 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
282
283 # advance the clock by 2000ms.
284 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
285 # now, min_rx should decay to 3000ms.
286 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
287 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
288
289 # the rx_min of p0 is 3000ms now, and p1 will send next control message
290 # 3000ms after decay. so, advance clock by 5000ms to make that happen.
291 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
292 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
293 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
294 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
295 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
296 # End of Test-1 ###############################################################
297
298
299 # Test-2 BFD decay: go back to cfg_min_rx when there is traffic
300 # receive packet at 1/100ms rate for 5000ms.
301 for i in `seq 0 49`
302 do
303     ovs-appctl time/warp 100
304     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
305              [0], [stdout], [])
306 done
307 # after a decay interval (3000ms), the p0 min_rx will go back to
308 # cfg_min_rx.
309 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
310 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
311 # End of Test-2 ###############################################################
312
313
314 # Test-3 BFD decay: go back to cfg_min_rx when decay_min_rx is changed
315 # advance the clock by 5000m. p0 shoud decay.
316 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
317 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
318 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
319
320 # advance the clock, to make 'flag' go back to none.
321 for i in `seq 0 5`; do ovs-appctl time/warp 500; done
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
325 # change decay_min_rx to 1000ms.
326 # for decay_min_rx < 2000ms, the decay detection time is set to 2000ms.
327 # this should reset the min_rx.
328 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=1000])
329 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
330 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
331
332 # for the following 1500ms, there should be no decay,
333 # since the decay_detect_time is set to 2000ms.
334 for i in `seq 0 2`
335 do
336     ovs-appctl time/warp 500
337     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
338     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
339     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
340     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
341 done
342
343 # advance the clock by 2000ms, decay should have happened.
344 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
345 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
346 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
347 # advance the clock, so 'flag' go back to none.
348 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
349 # End of Test-3 ###############################################################
350
351
352 # Test-4 BFD decay: set min_rx to 800ms.
353 # this should firstly reset the min_rx and then re-decay to 1000ms.
354 AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=800])
355 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
356 BFD_CHECK_RX([p0], [800ms], [800ms], [500ms])
357
358 # for the following 1600ms, there should be no decay,
359 # since the decay detection time is set to 2000ms.
360 for i in `seq 0 1`
361 do
362     ovs-appctl time/warp 800
363     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
364     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
365     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
366     BFD_CHECK_RX([p0], [800ms], [800ms], [500ms])
367 done
368
369 # advance the clock by 2000ms, decay should have happened.
370 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
371 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
372 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
373 # advance the clock, so 'flag' go back to none.
374 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
375 # End of Test-4 ###############################################################
376
377
378 # Test-5 BFD decay: set min_rx to 300ms and decay_min_rx to 5000ms together.
379 AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=300 bfd:decay_min_rx=5000])
380 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
381 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
382
383 # for decay_min_rx > 2000ms, the decay detection time is set to
384 # decay_min_rx (5000ms).
385 # for the following 4500ms, there should be no decay,
386 # since the decay detection time is set to 5000ms.
387 for i in `seq 0 8`
388 do
389     ovs-appctl time/warp 500
390     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
391     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
392     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
393     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
394 done
395
396 # advance the clock by 2000ms, decay should have happened.
397 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
398 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
399 BFD_CHECK_RX([p0], [5000ms], [5000ms], [500ms])
400 # advance the clock, to make 'flag' go back to none.
401 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
402 # End of Test-5 ###############################################################
403
404
405 # Test-6 BFD decay: set decay_min_rx to 0 to disable bfd decay.
406 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=0])
407 # min_rx is reset.
408 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
409 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
410 for i in `seq 0 20`
411 do
412     ovs-appctl time/warp 500
413     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
414     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
415     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
416     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
417 done
418 # End of Test-6 ################################################################
419
420
421 # Test-7 BFD decay: rmt_min_tx is greater than decay_min_rx
422 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=3000 -- set interface p1 bfd:min_tx=5000])
423 # there will be poll sequences from both sides. and it is hard to determine the
424 # order. so just skip 10000ms and check the RX/TX. at that time, p0 should be in decay already.
425 for i in `seq 0 19`; do ovs-appctl time/warp 500; done
426 BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
427 BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
428 # then, there should be no change of status,
429 for i in `seq 0 9`
430 do
431     ovs-appctl time/warp 500
432     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
433     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
434     BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
435     BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
436 done
437 # reset the p1's min_tx to 500ms.
438 AT_CHECK([ovs-vsctl set Interface p1 bfd:min_tx=500])
439 # since p0 has been in decay, now the RX will show 3000ms.
440 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
441 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
442 # End of Test-7 ###############################################################
443
444
445 # Test-8 BFD decay: state up->down->up.
446 # turn bfd off on p1
447 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false])
448
449 # check the state change of bfd on p0. After 15000 ms (> 3 min_rx intervals)
450 for i in `seq 0 14`; do ovs-appctl time/warp 1000; done
451 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
452 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
453 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
454
455 # resume the bfd on p1. the bfd should not go to decay mode direclty.
456 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true])
457 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
458 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
459 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
460
461 # since the decay_min_rx is still 3000ms, so after 5000ms, p0 should have decayed.
462 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
463 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
464 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
465 # End of Test-8 ################################################################
466
467 OVS_VSWITCHD_STOP
468 AT_CLEANUP
469
470 # Tests below are for bfd forwarding_if_rx feature.
471 # forwarding_if_rx Test1: bfd is enabled on one end of link.
472 AT_SETUP([bfd - bfd forwarding_if_rx 1])
473 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
474                     add-port br1 p1 -- set Interface p1 type=patch \
475                     options:peer=p0 ofport_request=2 -- \
476                     add-port br0 p0 -- set Interface p0 type=patch \
477                     options:peer=p1 ofport_request=1 -- \
478                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
479                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
480
481 ovs-appctl time/stop
482 # check the inital status.
483 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
484 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
485 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
486
487 # enable forwarding_if_rx.
488 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
489
490 # there should be no change of forwarding flag, since
491 # there is no traffic.
492 for i in `seq 0 3`
493 do
494     ovs-appctl time/warp 500
495     BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
496 done
497
498 # receive one packet.
499 AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
500              [0], [stdout], [])
501 # wait for 1000ms
502 for i in `seq 0 14`; do ovs-appctl time/warp 100; done
503 # the forwarding flag should turn to true sometime in this 1000ms, since there is data received.
504 BFD_CHECK([p0], [true], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
505 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
506 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
507
508 # Stop sending packets for 2000ms.
509 for i in `seq 0 19`; do ovs-appctl time/warp 100; done
510 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
511 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
512 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
513
514 # receive packet at 1/100ms rate for 2000ms.
515 for i in `seq 0 19`
516 do
517     ovs-appctl time/warp 100
518     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
519              [0], [stdout], [])
520 done
521 # the forwarding flag should be true, since there is data received.
522 BFD_CHECK([p0], [true], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
523 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
524 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
525
526 # reset bfd forwarding_if_rx.
527 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false], [0])
528 # forwarding flag should turn to false since the STATE is DOWN.
529 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
530 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
531 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
532
533 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
534 AT_CLEANUP
535
536 # forwarding_if_rx Test2: bfd is enabled on both ends of link.
537 AT_SETUP([bfd - bfd forwarding_if_rx 2])
538 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
539                     add-port br1 p1 -- set Interface p1 type=patch \
540                     options:peer=p0 ofport_request=2 -- \
541                     add-port br0 p0 -- set Interface p0 type=patch \
542                     options:peer=p1 ofport_request=1 -- \
543                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
544                     set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \
545                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
546
547 ovs-appctl time/stop
548 # advance the clock, to stablize the states.
549 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
550
551 # enable forwarding_if_rx.
552 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
553
554 # there should be no change of the forwarding flag, since
555 # the bfd on both ends is already up.
556 for i in `seq 0 5`
557 do
558     ovs-appctl time/warp 500
559     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
560 done
561
562 # stop the bfd on one side.
563 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
564 # for within 1500ms, the detection timer is not out.
565 # there is no change to status.
566 for i in `seq 0 1`
567 do
568     ovs-appctl time/warp 500
569     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
570     for i in `seq 0 4`
571     do
572         AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
573                  [0], [stdout], [])
574     done
575 done
576
577 # at 1500ms, the STATE should go DOWN, due to Control Detection Time Expired.
578 # but forwarding flag should be still true.
579 ovs-appctl time/warp 500
580 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
581
582 # receive packet at 1/100ms rate for 1000ms.
583 for i in `seq 0 9`
584 do
585     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
586              [0], [stdout], [])
587     ovs-appctl time/warp 100
588     # the forwarding flag should always be true during this time.
589     BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
590 done
591
592 # reset bfd forwarding_if_rx.
593 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false], [0])
594 # forwarding flag should turn to false since the STATE is DOWN.
595 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
596 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
597 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
598
599 # re-enable bfd on the other end. the states should be up.
600 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
601 # advance the clock, to stablize the states.
602 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
603 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
604 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
605 BFD_CHECK_TX([p0], [500ms], [500ms], [300ms])
606 BFD_CHECK_RX([p0], [500ms], [500ms], [300ms])
607
608 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
609 AT_CLEANUP
610
611 # forwarding_if_rx Test3: bfd is enabled on both ends of link and decay is enabled.
612 AT_SETUP([bfd - bfd forwarding_if_rx 3])
613 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
614                     add-port br1 p1 -- set Interface p1 type=patch \
615                     options:peer=p0 ofport_request=2 -- \
616                     add-port br0 p0 -- set Interface p0 type=patch \
617                     options:peer=p1 ofport_request=1 -- \
618                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 bfd:decay_min_rx=3000 -- \
619                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
620
621 ovs-appctl time/stop
622 # advance the clock, to stablize the states.
623 for i in `seq 0 19`; do ovs-appctl time/warp 500; done
624 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
625 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
626 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
627 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
628
629 # enable forwarding_if_rx.
630 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
631
632 # there should be no change of the forwarding flag, since
633 # the bfd on both ends is already up.
634 for i in `seq 0 9`
635 do
636     ovs-appctl time/warp 500
637     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
638 done
639
640 # reconfigure the decay_min_rx to 1000ms.
641 AT_CHECK([ovs-vsctl set interface p0 bfd:decay_min_rx=1000])
642 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
643 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
644
645 # wait for 5000ms to decay.
646 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
647 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
648 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
649
650 # stop the bfd on one side.
651 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
652
653 # advance clock by 4000ms, while receiving packets.
654 # the STATE should go DOWN, due to Control Detection Time Expired.
655 # but forwarding flag should be still true.
656 for i in `seq 0 7`
657 do
658     ovs-appctl time/warp 500
659     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
660              [0], [stdout], [])
661 done
662 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
663
664 # receive packet at 1/100ms rate for 1000ms.
665 for i in `seq 0 9`
666 do
667     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
668              [0], [stdout], [])
669     ovs-appctl time/warp 100
670     # the forwarding flag should always be true during this time.
671     BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
672 done
673
674 # stop receiving for 3000ms.
675 for i in `seq 0 29`; do ovs-appctl time/warp 100; done
676 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
677
678 # reset bfd forwarding_if_rx.
679 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false])
680 # forwarding flag should turn to false since the STATE is DOWN.
681 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
682 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
683 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
684
685 # re-enable bfd forwarding_if_rx.
686 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true])
687 # there should be no change.
688 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
689 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
690 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
691
692 # re-enable bfd on the other end. the states should be up.
693 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
694 # advance the clock, to stablize the states.
695 for i in `seq 0 19`; do ovs-appctl time/warp 500; done
696 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
697 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
698 BFD_CHECK_TX([p0], [300ms], [300ms], [300ms])
699 BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
700
701 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
702 AT_CLEANUP