BFD: Unit tests for BFD.
[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 1000ms
24         Local Minimum TX Interval: $2
25         Remote Minimum TX Interval: $3
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: $2
34         Remote Minimum RX Interval: $3
35 ])
36 ])
37 AT_SETUP([bfd - basic config on different bridges])
38 ovs-appctl time/stop
39 #Create 2 bridges connected by patch ports and enable BFD
40 OVS_VSWITCHD_START(
41    [add-br br1 -- \
42        set bridge br1 datapath-type=dummy \
43        other-config:hwaddr=aa:55:aa:56:00:00 -- \
44     add-port br1 p1 -- set Interface p1 type=patch \
45        options:peer=p0 -- \
46     add-port br0 p0 -- set Interface p0 type=patch \
47        options:peer=p1 -- \
48     set Interface p0 bfd:enable=true -- \
49     set Interface p1 bfd:enable=true ])
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-appctl time/stop
86 OVS_VSWITCHD_START(
87    [add-br br-bfd0 -- \
88        set bridge br-bfd0 datapath-type=dummy \
89        other-config:hwaddr=aa:55:aa:56:00:00 -- \
90     add-br br-bfd1 -- \
91        set bridge br-bfd1 datapath-type=dummy \
92        other-config:hwaddr=aa:55:aa:57:00:00 -- \
93     add-br br-sw -- \
94        set bridge br-sw datapath-type=dummy \
95        other-config:hwaddr=aa:55:aa:58:00:00 -- \
96     add-port br-sw p1-sw -- set Interface p1-sw type=patch \
97        options:peer=p1 -- \
98     add-port br-sw p0-sw -- set Interface p0-sw type=patch \
99        options:peer=p0 -- \
100     add-port br-bfd1 p1 -- set Interface p1 type=patch \
101        options:peer=p1-sw bfd:enable=true -- \
102     add-port br-bfd0 p0 -- set Interface p0 type=patch \
103        options:peer=p0-sw bfd:enable=true --])
104
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-appctl time/stop
162 OVS_VSWITCHD_START()
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 ovs-appctl time/stop
167 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
168            options:peer=p0 ])
169 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
170            options:peer=p1 ])
171 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
172 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
173 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
174
175 #Verify that BFD has been enabled on both interfaces.
176 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
177 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
178
179 #Set cpath_down to true on one interface, make sure the remote interface updates its values.
180 AT_CHECK([ovs-vsctl set interface p0 bfd:cpath_down=true])
181 for i in `seq 0 40`; do ovs-appctl time/warp 100; done
182 BFD_CHECK([p1], [false], [false], [none], [up], [No Diagnostic], [none], [up], [Concatenated Path Down])
183 OVS_VSWITCHD_STOP
184 AT_CLEANUP
185
186
187 AT_SETUP([bfd - Edit the Min Tx/Rx values])
188 #Create 2 bridges connected by patch ports and enable BFD
189 ovs-appctl time/stop
190 ovs-appctl vlog/set bfd:dbg
191 OVS_VSWITCHD_START()
192 AT_CHECK([ ovs-vsctl -- add-br br1 -- \
193            set bridge br1 datapath-type=dummy ])
194 AT_CHECK([ ovs-vsctl -- add-port br1 p1 -- set Interface p1 type=patch \
195            options:peer=p0 ])
196 AT_CHECK([ ovs-vsctl -- add-port br0 p0 -- set Interface p0 type=patch \
197            options:peer=p1 ])
198 AT_CHECK([ ovs-vsctl -- set interface p0 bfd:enable=true ])
199 AT_CHECK([ ovs-vsctl -- set interface p1 bfd:enable=true ])
200 for i in `seq 0 20`; do ovs-appctl time/warp 100; done
201 #Verify that BFD has been enabled on both interfaces.
202 BFD_CHECK([p1], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
203 BFD_CHECK([p0], [true], [false], [none], [up], [No Diagnostic], [none], [up], [No Diagnostic])
204 #Edit the min Tx value.
205 AT_CHECK([ovs-vsctl set interface p0 bfd:min_tx=200])
206 for i in `seq 0 20`; do ovs-appctl time/warp 100; done
207 BFD_CHECK_TX([p0], [200ms], [100ms])
208 BFD_CHECK_TX([p1], [100ms], [200ms])
209
210 #Edit the min Rx value.
211 AT_CHECK([ovs-vsctl set interface p1 bfd:min_rx=300])
212 for i in `seq 0 20`; do ovs-appctl time/warp 100; done
213 BFD_CHECK_RX([p1], [300ms], [1000ms])
214 BFD_CHECK_RX([p0], [1000ms], [300ms])
215
216 OVS_VSWITCHD_STOP
217 AT_CLEANUP