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