bfd: Implement forwarding_if_rx.
[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 bfd:decay_min_rx=3000 -- \
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 local session state to go from down to up.
264 for i in `seq 0 1`; do ovs-appctl time/warp 500; done
265 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [init], [No Diagnostic])
266
267
268 # Test-1 BFD decay: decay to decay_min_rx
269 # bfd:decay_min_rx is set to 3000ms after the local state of p0 goes up,
270 # so for the first 2500ms, there should be no change.
271 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
272 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
273 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
274 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
275
276 # advance the clock by 500ms.
277 ovs-appctl time/warp 500
278 # now at 3000ms, min_rx should decay to 3000ms and there should be
279 # poll sequence flags.
280 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
281 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
282 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
283 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
284
285 # since the tx_min of p0 is still 500ms, after 500ms from decay,
286 # the control message will be sent from p0 to p1, and p1 'flag'
287 # will go back to none.
288 ovs-appctl time/warp 500
289 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
290
291 # the rx_min of p0 is 3000ms now, and p1 will send next control message
292 # 3000ms after decay. so, advance clock by 2500ms to make that happen.
293 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
294 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
295 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
296 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
297 # End of Test-1 ###############################################################
298
299
300 # Test-2 BFD decay: go back to cfg_min_rx when there is traffic
301 # receive packet at 1/100ms rate for 3000ms.
302 for i in `seq 0 30`
303 do
304     ovs-appctl time/warp 100
305     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
306              [0], [stdout], [])
307 done
308 # after a decay interval (3000ms), the p0 min_rx will go back to
309 # cfg_min_rx. there should be poll sequence flags.
310 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
311 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
312 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
313 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
314
315 # 500ms later, both direction will send control messages,
316 # and their 'flag' will go back to none.
317 ovs-appctl time/warp 500
318 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
319 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
320 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
321 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
322 # End of Test-2 ###############################################################
323
324
325 # Test-3 BFD decay: go back to cfg_min_rx when decay_min_rx is changed
326 # advance the clock by 2500ms to 3000m after restore of
327 # min_rx. p0 is decayed, and there should be the poll sequence flags.
328 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
329 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
330 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
331 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
332 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
333
334 # advance the clock, to make 'flag' go back to none.
335 for i in `seq 0 5`; do ovs-appctl time/warp 500; done
336 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
337 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
338
339 # change decay_min_rx to 1000ms.
340 # for decay_min_rx < 2000ms, the decay detection time is set to 2000ms.
341 # this should firstly reset the min_rx and start poll sequence.
342 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=1000])
343 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
344 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
345 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
346 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
347
348 # for the following 1500ms, there should be no decay,
349 # since the decay_detect_time is set to 2000ms.
350 for i in `seq 0 2`
351 do
352     ovs-appctl time/warp 500
353     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
354     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
355     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
356     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
357 done
358
359 ovs-appctl time/warp 500
360 # at 2000ms, decay should happen and there should be the poll sequence flags.
361 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
362 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
363 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
364 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
365 # advance the clock, so 'flag' go back to none.
366 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
367 # End of Test-3 ###############################################################
368
369
370 # Test-4 BFD decay: set min_rx to 800ms.
371 # this should firstly reset the min_rx and then re-decay to 1000ms.
372 AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=800])
373 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
374 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
375 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
376 BFD_CHECK_RX([p0], [800ms], [800ms], [500ms])
377
378 # for the following 1600ms, there should be no decay,
379 # since the decay detection time is set to 2000ms.
380 for i in `seq 0 1`
381 do
382     ovs-appctl time/warp 800
383     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
384     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
385     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
386     BFD_CHECK_RX([p0], [800ms], [800ms], [500ms])
387 done
388
389 ovs-appctl time/warp 400
390 # at 2000ms, decay should happen and there should be the poll sequence flags.
391 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
392 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
393 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
394 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
395 # advance the clock, so 'flag' go back to none.
396 for i in `seq 0 4`; do ovs-appctl time/warp 500; done
397 # End of Test-4 ###############################################################
398
399
400 # Test-5 BFD decay: set min_rx to 300ms and decay_min_rx to 5000ms together.
401 AT_CHECK([ovs-vsctl set Interface p0 bfd:min_rx=300 bfd:decay_min_rx=5000])
402 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
403 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
404 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
405 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
406
407 # for decay_min_rx > 2000ms, the decay detection time is set to
408 # decay_min_rx (5000ms).
409 # for the following 4500ms, there should be no decay,
410 # since the decay detection time is set to 5000ms.
411 for i in `seq 0 8`
412 do
413     ovs-appctl time/warp 500
414     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
415     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
416     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
417     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
418 done
419
420 ovs-appctl time/warp 500
421 # at 5000ms, decay should happen and there should be the poll sequence flags.
422 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
423 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
424 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
425 BFD_CHECK_RX([p0], [5000ms], [5000ms], [500ms])
426 # advance the clock, to make 'flag' go back to none.
427 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
428 # End of Test-5 ###############################################################
429
430
431 # Test-6 BFD decay: set decay_min_rx to 0 to disable bfd decay.
432 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=0])
433 # min_rx is reset, and there should be the poll sequence flags.
434 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
435 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
436 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
437 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
438 for i in `seq 0 20`
439 do
440     ovs-appctl time/warp 500
441     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
442     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
443     BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
444     BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
445 done
446 # End of Test-6 ################################################################
447
448
449 # Test-7 BFD decay: rmt_min_tx is greater than decay_min_rx
450 AT_CHECK([ovs-vsctl set Interface p0 bfd:decay_min_rx=3000 -- set interface p1 bfd:min_tx=5000])
451 # there will be poll sequences from both sides. and it is hard to determine the
452 # order. so just skip 10000ms and check the RX/TX. at that time, p0 should be in decay already.
453 for i in `seq 0 19`; do echo $i; ovs-appctl bfd/show; ovs-appctl time/warp 500; done
454 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
455 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
456 BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
457 BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
458 # then, there should be no change of status,
459 for i in `seq 0 9`
460 do
461     ovs-appctl time/warp 500
462     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
463     BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
464     BFD_CHECK_TX([p0], [500ms], [300ms], [5000ms])
465     BFD_CHECK_RX([p0], [5000ms], [3000ms], [500ms])
466 done
467 # reset the p1's min_tx to 500ms.
468 AT_CHECK([ovs-vsctl set Interface p1 bfd:min_tx=500])
469 # check the poll sequence. since p0 has been in decay, now the RX will show 3000ms.
470 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
471 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
472 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
473 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
474 # advance the clock by 3000ms, at that time, p1 will send the control packets.
475 # then there will be no poll flags.
476 for i in `seq 0 5`; do ovs-appctl time/warp 500; done
477 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
478 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
479 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
480 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
481 # End of Test-7 ###############################################################
482
483
484 # Test-8 BFD decay: state up->down->up.
485 # turn bfd off on p1
486 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false])
487
488 # check the state change of bfd on p0. After 9000 ms (3 min_rx intervals)
489 for i in `seq 0 8`; do ovs-appctl time/warp 1000; done
490 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
491 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
492 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
493
494 # resume the bfd on p1. the bfd should not go to decay mode direclty.
495 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true])
496 for i in `seq 0 1`; do ovs-appctl time/warp 500; done
497 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
498 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
499 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
500
501 # since the decay_min_rx is still 3000ms, so after 3000ms, there should be the decay and poll sequence.
502 for i in `seq 0 5`; do ovs-appctl time/warp 500; done
503 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [final], [up], [No Diagnostic])
504 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [Control Detection Time Expired])
505 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
506 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
507 # End of Test-8 ################################################################
508
509 OVS_VSWITCHD_STOP
510 AT_CLEANUP
511
512 # Tests below are for bfd forwarding_if_rx feature.
513 # forwarding_if_rx Test1: bfd is enabled on one end of link.
514 AT_SETUP([bfd - bfd forwarding_if_rx 1])
515 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
516                     add-port br1 p1 -- set Interface p1 type=patch \
517                     options:peer=p0 ofport_request=2 -- \
518                     add-port br0 p0 -- set Interface p0 type=patch \
519                     options:peer=p1 ofport_request=1 -- \
520                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
521                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
522
523 ovs-appctl time/stop
524 # check the inital status.
525 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
526 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
527 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
528
529 # enable forwarding_if_rx.
530 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
531
532 # there should be no change of forwarding flag, since
533 # there is no traffic.
534 for i in `seq 0 3`
535 do
536     ovs-appctl time/warp 500
537     BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
538 done
539
540 # receive one packet.
541 AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
542              [0], [stdout], [])
543 for i in `seq 0 14`
544 do
545     ovs-appctl time/warp 100
546     # the forwarding flag should be true, since there is data received.
547     BFD_CHECK([p0], [true], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
548     BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
549     BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
550 done
551
552 # Stop sending packets for 1000ms.
553 for i in `seq 0 9`; do ovs-appctl time/warp 100; done
554 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
555 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
556 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
557
558 # receive packet at 1/100ms rate for 1000ms.
559 for i in `seq 0 9`
560 do
561     ovs-appctl time/warp 100
562     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
563              [0], [stdout], [])
564 done
565 # the forwarding flag should be true, since there is data received.
566 BFD_CHECK([p0], [true], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
567 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
568 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
569
570 # reset bfd forwarding_if_rx.
571 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false], [0])
572 # forwarding flag should turn to false since the STATE is DOWN.
573 BFD_CHECK([p0], [false], [false], [none], [down], [No Diagnostic], [none], [down], [No Diagnostic])
574 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
575 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
576
577 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
578 AT_CLEANUP
579
580 # forwarding_if_rx Test2: bfd is enabled on both ends of link.
581 AT_SETUP([bfd - bfd forwarding_if_rx 2])
582 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
583                     add-port br1 p1 -- set Interface p1 type=patch \
584                     options:peer=p0 ofport_request=2 -- \
585                     add-port br0 p0 -- set Interface p0 type=patch \
586                     options:peer=p1 ofport_request=1 -- \
587                     set Interface p0 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500 -- \
588                     set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 -- \
589                     add-port br1 p2 -- set Interface p2 type=internal ofport_request=3])
590
591 ovs-appctl time/stop
592 # advance the clock, to stablize the states.
593 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
594
595 # enable forwarding_if_rx.
596 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
597
598 # there should be no change of the forwarding flag, since
599 # the bfd on both ends is already up.
600 for i in `seq 0 5`
601 do
602     ovs-appctl time/warp 500
603     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
604 done
605
606 # stop the bfd on one side.
607 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
608 # for within 1500ms, the detection timer is not out.
609 # there is no change to status.
610 for i in `seq 0 1`
611 do
612     ovs-appctl time/warp 500
613     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
614     for i in `seq 0 5`
615     do
616         AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
617                  [0], [stdout], [])
618     done
619 done
620
621 # at 1500ms, the STATE should go DOWN, due to Control Detection Time Expired.
622 # but forwarding flag should be still true.
623 ovs-appctl time/warp 500
624 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
625
626 # receive packet at 1/100ms rate for 1000ms.
627 for i in `seq 0 9`
628 do
629     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
630              [0], [stdout], [])
631     ovs-appctl time/warp 100
632     # the forwarding flag should always be true during this time.
633     BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
634 done
635
636 # reset bfd forwarding_if_rx.
637 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false], [0])
638 # forwarding flag should turn to false since the STATE is DOWN.
639 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
640 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
641 BFD_CHECK_RX([p0], [500ms], [500ms], [1ms])
642
643 # re-enable bfd on the other end. the states should be up.
644 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
645 # advance the clock, to stablize the states.
646 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
647 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
648 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
649 BFD_CHECK_TX([p0], [500ms], [500ms], [300ms])
650 BFD_CHECK_RX([p0], [500ms], [500ms], [300ms])
651
652 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
653 AT_CLEANUP
654
655 # forwarding_if_rx Test3: bfd is enabled on both ends of link and decay is enabled.
656 AT_SETUP([bfd - bfd forwarding_if_rx 3])
657 OVS_VSWITCHD_START([add-br br1 -- set bridge br1 datapath-type=dummy -- \
658                     add-port br1 p1 -- set Interface p1 type=patch \
659                     options:peer=p0 ofport_request=2 -- \
660                     add-port br0 p0 -- set Interface p0 type=patch \
661                     options:peer=p1 ofport_request=1 -- \
662                     set Interface p0 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300 bfd:decay_min_rx=3000 -- \
663                     set Interface p1 bfd:enable=true bfd:min_tx=500 bfd:min_rx=500])
664
665 ovs-appctl time/stop
666 # advance the clock, to stablize the states.
667 for i in `seq 0 19`; do ovs-appctl time/warp 500; done
668 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
669 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
670 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
671 BFD_CHECK_RX([p0], [3000ms], [3000ms], [500ms])
672
673 # enable forwarding_if_rx.
674 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true], [0])
675
676 # there should be no change of the forwarding flag, since
677 # the bfd on both ends is already up.
678 for i in `seq 0 9`
679 do
680     ovs-appctl time/warp 500
681     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
682 done
683
684 # reconfigure the decay_min_rx to 1000ms. check the poll sequence.
685 AT_CHECK([ovs-vsctl set interface p0 bfd:decay_min_rx=1000])
686 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
687 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
688 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
689 BFD_CHECK_RX([p0], [500ms], [300ms], [500ms])
690
691 # wait for 2000ms to decay.
692 for i in `seq 0 3`; do ovs-appctl time/warp 500; done
693 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [final], [up], [No Diagnostic])
694 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [poll], [up], [No Diagnostic])
695 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
696 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
697
698 # wait for 1000ms, so that the flags will go back to none.
699 for i in `seq 0 1`; do ovs-appctl time/warp 500; done
700 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
701 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
702 BFD_CHECK_TX([p0], [500ms], [300ms], [500ms])
703 BFD_CHECK_RX([p0], [1000ms], [1000ms], [500ms])
704
705 # stop the bfd on one side.
706 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=false], [0])
707 # for within 2500ms, the detection timer is not out.
708 # there is no change to status.
709 for i in `seq 0 4`
710 do
711     ovs-appctl time/warp 500
712     BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
713     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
714              [0], [stdout], [])
715 done
716
717 # at 3000ms, the STATE should go DOWN, due to Control Detection Time Expired.
718 # but forwarding flag should be still true.
719 ovs-appctl time/warp 500
720 BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
721
722 # receive packet at 1/100ms rate for 1000ms.
723 for i in `seq 0 9`
724 do
725     AT_CHECK([ovs-ofctl packet-out br1 3 2  "90e2ba01475000101856b2e80806000108000604000100101856b2e80202020300000000000002020202"],
726              [0], [stdout], [])
727     ovs-appctl time/warp 100
728     # the forwarding flag should always be true during this time.
729     BFD_CHECK([p0], [true], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
730 done
731
732 # stop receiving for 2000ms.
733 for i in `seq 0 19`; do ovs-appctl time/warp 100; done
734 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
735
736 # reset bfd forwarding_if_rx.
737 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=false])
738 # forwarding flag should turn to false since the STATE is DOWN.
739 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
740 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
741 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
742
743 # re-enable bfd forwarding_if_rx.
744 AT_CHECK([ovs-vsctl set Interface p0 bfd:forwarding_if_rx=true])
745 # there should be no change.
746 BFD_CHECK([p0], [false], [false], [none], [down], [Control Detection Time Expired], [none], [down], [No Diagnostic])
747 BFD_CHECK_TX([p0], [1000ms], [1000ms], [0ms])
748 BFD_CHECK_RX([p0], [300ms], [300ms], [1ms])
749
750 # re-enable bfd on the other end. the states should be up.
751 AT_CHECK([ovs-vsctl set Interface p1 bfd:enable=true bfd:min_tx=300 bfd:min_rx=300])
752 # advance the clock, to stablize the states.
753 for i in `seq 0 9`; do ovs-appctl time/warp 500; done
754 BFD_CHECK([p0], [true], [false], [none], [up], [Control Detection Time Expired], [none], [up], [No Diagnostic])
755 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [Control Detection Time Expired])
756 BFD_CHECK_TX([p0], [300ms], [300ms], [300ms])
757 BFD_CHECK_RX([p0], [1000ms], [1000ms], [300ms])
758
759 AT_CHECK([ovs-vsctl del-br br1], [0], [ignore])
760 AT_CLEANUP