t_rtable.sh revision 1.5 1 # $NetBSD: t_rtable.sh,v 1.5 2019/05/31 15:36:10 gson Exp $
2 #
3 # Copyright (c) 2017 Internet Initiative Japan Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 SOCK1=unix://commsock1
29 SOCK2=unix://commsock2
30 SOCK3=unix://commsock3
31 IP1=10.0.0.1
32 IP2=10.0.0.2
33
34 DEBUG=${DEBUG:-false}
35 TIMEOUT=5
36
37 setup_endpoint()
38 {
39 local sock=${1}
40 local addr=${2}
41 local bus=${3}
42 local mode=${4}
43
44 rump_server_add_iface $sock shmif0 $bus
45 export RUMP_SERVER=${sock}
46 if [ $mode = "ipv6" ]; then
47 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
48 else
49 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
50 fi
51
52 atf_check -s exit:0 rump.ifconfig shmif0 up
53 $DEBUG && rump.ifconfig shmif0
54 }
55
56 setup_bridge_server()
57 {
58
59 rump_server_add_iface $SOCK2 shmif0 bus1
60 rump_server_add_iface $SOCK2 shmif1 bus2
61 export RUMP_SERVER=$SOCK2
62 atf_check -s exit:0 rump.ifconfig shmif0 up
63 atf_check -s exit:0 rump.ifconfig shmif1 up
64 }
65
66 setup()
67 {
68
69 rump_server_start $SOCK1 bridge
70 rump_server_start $SOCK2 bridge
71 rump_server_start $SOCK3 bridge
72
73 setup_endpoint $SOCK1 $IP1 bus1 ipv4
74 setup_endpoint $SOCK3 $IP2 bus2 ipv4
75 setup_bridge_server
76 }
77
78 setup_bridge()
79 {
80
81 export RUMP_SERVER=$SOCK2
82 atf_check -s exit:0 rump.ifconfig bridge0 create
83 atf_check -s exit:0 rump.ifconfig bridge0 up
84
85 export LD_PRELOAD=/usr/lib/librumphijack.so
86 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif0
87 atf_check -s exit:0 /sbin/brconfig bridge0 add shmif1
88 /sbin/brconfig bridge0
89 unset LD_PRELOAD
90 rump.ifconfig shmif0
91 rump.ifconfig shmif1
92 }
93
94 get_number_of_caches()
95 {
96
97 export RUMP_SERVER=$SOCK2
98 export LD_PRELOAD=/usr/lib/librumphijack.so
99 echo $(/sbin/brconfig bridge0 addr |wc -l)
100 unset LD_PRELOAD
101 }
102
103
104 atf_test_case bridge_rtable_basic cleanup
105 bridge_rtable_basic_head()
106 {
107
108 atf_set "descr" "Tests basic opearaions of bridge's learning table"
109 atf_set "require.progs" "rump_server"
110 }
111
112 bridge_rtable_basic_body()
113 {
114 local addr1= addr3=
115
116 setup
117 setup_bridge
118
119 # Get MAC addresses of the endpoints.
120 addr1=$(get_macaddr $SOCK1 shmif0)
121 addr3=$(get_macaddr $SOCK3 shmif0)
122
123 # Confirm there is no MAC address caches.
124 export RUMP_SERVER=$SOCK2
125 export LD_PRELOAD=/usr/lib/librumphijack.so
126 $DEBUG && /sbin/brconfig bridge0
127 atf_check -s exit:0 -o not-match:"$addr1" /sbin/brconfig bridge0
128 atf_check -s exit:0 -o not-match:"$addr3" /sbin/brconfig bridge0
129 unset LD_PRELOAD
130
131 # Make the bridge learn the MAC addresses of the endpoints.
132 export RUMP_SERVER=$SOCK1
133 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
134 unset RUMP_SERVER
135
136 # Tests the addresses are in the cache.
137 export RUMP_SERVER=$SOCK2
138 export LD_PRELOAD=/usr/lib/librumphijack.so
139 $DEBUG && /sbin/brconfig bridge0
140 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
141 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
142
143 # Tests brconfig deladdr
144 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr1"
145 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
146 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 deladdr "$addr3"
147 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
148 unset LD_PRELOAD
149
150 rump_server_destroy_ifaces
151 }
152
153 bridge_rtable_basic_cleanup()
154 {
155
156 $DEBUG && dump
157 cleanup
158 }
159
160
161 atf_test_case bridge_rtable_flush cleanup
162 bridge_rtable_flush_head()
163 {
164
165 atf_set "descr" "Tests brconfig flush"
166 atf_set "require.progs" "rump_server"
167 }
168
169 bridge_rtable_flush_body()
170 {
171 local addr1= addr3=
172 local n=
173
174 setup
175 setup_bridge
176
177 # Get MAC addresses of the endpoints.
178 addr1=$(get_macaddr $SOCK1 shmif0)
179 addr3=$(get_macaddr $SOCK3 shmif0)
180
181 # Make the bridge learn the MAC addresses of the endpoints.
182 export RUMP_SERVER=$SOCK1
183 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
184 unset RUMP_SERVER
185
186 # Tests the addresses are in the cache.
187 export RUMP_SERVER=$SOCK2
188 export LD_PRELOAD=/usr/lib/librumphijack.so
189 $DEBUG && /sbin/brconfig bridge0
190 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
191 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
192
193 # Tests brconfig flush.
194 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
195 atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
196 atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
197 unset LD_PRELOAD
198
199 # Add extra interfaces and addresses
200 export RUMP_SERVER=$SOCK1
201 rump_server_add_iface $SOCK1 shmif1 bus1
202 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24
203 atf_check -s exit:0 rump.ifconfig -w 10
204
205 export RUMP_SERVER=$SOCK3
206 rump_server_add_iface $SOCK3 shmif1 bus2
207 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.12/24
208 atf_check -s exit:0 rump.ifconfig -w 10
209
210 # Let cache entries
211 export RUMP_SERVER=$SOCK1
212 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 10.0.0.12
213 export RUMP_SERVER=$SOCK3
214 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 10.0.0.11
215
216 export RUMP_SERVER=$SOCK2
217 export LD_PRELOAD=/usr/lib/librumphijack.so
218 $DEBUG && /sbin/brconfig bridge0
219 n=$(get_number_of_caches)
220 atf_check_equal $n 4
221
222 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 flush
223 n=$(get_number_of_caches)
224 atf_check_equal $n 0
225 unset LD_PRELOAD
226
227 rump_server_destroy_ifaces
228 }
229
230 bridge_rtable_flush_cleanup()
231 {
232
233 $DEBUG && dump
234 cleanup
235 }
236
237
238 atf_test_case bridge_rtable_timeout cleanup
239 bridge_rtable_timeout_head()
240 {
241
242 atf_set "descr" "Tests cache timeout of bridge's learning table"
243 atf_set "require.progs" "rump_server"
244 }
245
246 bridge_rtable_timeout_body()
247 {
248 local addr1= addr3=
249 local timeout=5
250
251 setup
252 setup_bridge
253
254 # Get MAC addresses of the endpoints.
255 addr1=$(get_macaddr $SOCK1 shmif0)
256 addr3=$(get_macaddr $SOCK3 shmif0)
257
258 # Tests brconfig timeout.
259 export RUMP_SERVER=$SOCK2
260 export LD_PRELOAD=/usr/lib/librumphijack.so
261 atf_check -s exit:0 -o match:"timeout: 1200" /sbin/brconfig bridge0
262 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 timeout $timeout
263 atf_check -s exit:0 -o match:"timeout: $timeout" /sbin/brconfig bridge0
264 unset LD_PRELOAD
265
266 # Make the bridge learn the MAC addresses of the endpoints.
267 export RUMP_SERVER=$SOCK1
268 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
269 unset RUMP_SERVER
270
271 # Tests the addresses are in the cache.
272 export RUMP_SERVER=$SOCK2
273 export LD_PRELOAD=/usr/lib/librumphijack.so
274 $DEBUG && /sbin/brconfig bridge0
275 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
276 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
277
278 # TODO: cache expiration
279 # The initial timeout value of a cache is changed to $timeout and
280 # after $timeout elapsed the cache is ready to be sweeped. However,
281 # the GC of rtable runs every 5 minutes and the cache remains until
282 # then. Should we have a sysctl to change the period?
283
284 #sleep $(($timeout + 2))
285 #
286 ## Tests the addresses are not in the cache.
287 #export RUMP_SERVER=$SOCK2
288 #export LD_PRELOAD=/usr/lib/librumphijack.so
289 #$DEBUG && /sbin/brconfig bridge0
290 #atf_check -s exit:0 -o not-match:"$addr1 shmif0" /sbin/brconfig bridge0
291 #atf_check -s exit:0 -o not-match:"$addr3 shmif1" /sbin/brconfig bridge0
292
293 rump_server_destroy_ifaces
294 }
295
296 bridge_rtable_timeout_cleanup()
297 {
298
299 $DEBUG && dump
300 cleanup
301 }
302
303
304 atf_test_case bridge_rtable_maxaddr cleanup
305 bridge_rtable_maxaddr_head()
306 {
307
308 atf_set "descr" "Tests brconfig maxaddr"
309 atf_set "require.progs" "rump_server"
310 }
311
312 bridge_rtable_maxaddr_body()
313 {
314 local addr1= addr3=
315
316 setup
317 setup_bridge
318
319 # Get MAC addresses of the endpoints.
320 addr1=$(get_macaddr $SOCK1 shmif0)
321 addr3=$(get_macaddr $SOCK3 shmif0)
322
323 # Fill the MAC addresses of the endpoints.
324 export RUMP_SERVER=$SOCK1
325 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
326 export RUMP_SERVER=$SOCK2
327 export LD_PRELOAD=/usr/lib/librumphijack.so
328 /sbin/brconfig bridge0
329 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
330 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
331
332 # Check the default # of caches is 100
333 atf_check -s exit:0 -o match:"max cache: 100" /sbin/brconfig bridge0
334
335 # Test two MAC addresses are cached
336 n=$(get_number_of_caches)
337 atf_check_equal $n 2
338
339 # Limit # of caches to one
340 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1
341 atf_check -s exit:0 -o match:"max cache: 1" /sbin/brconfig bridge0
342 /sbin/brconfig bridge0
343
344 # Test just one address is cached
345 n=$(get_number_of_caches)
346 atf_check_equal $n 1
347
348 # Increase # of caches to two
349 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 2
350 atf_check -s exit:0 -o match:"max cache: 2" /sbin/brconfig bridge0
351 unset LD_PRELOAD
352
353 # Test we can cache two addresses again
354 export RUMP_SERVER=$SOCK1
355 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP2
356 export RUMP_SERVER=$SOCK2
357 export LD_PRELOAD=/usr/lib/librumphijack.so
358 /sbin/brconfig bridge0
359 atf_check -s exit:0 -o match:"$addr1 shmif0" /sbin/brconfig bridge0
360 atf_check -s exit:0 -o match:"$addr3 shmif1" /sbin/brconfig bridge0
361 unset LD_PRELOAD
362
363 rump_server_destroy_ifaces
364 }
365
366 bridge_rtable_maxaddr_cleanup()
367 {
368
369 $DEBUG && dump
370 cleanup
371 }
372
373
374 atf_test_case bridge_rtable_delete_member cleanup
375 bridge_rtable_delete_member_head()
376 {
377
378 atf_set "descr" "Tests belonging rtable entries are removed on deleting an interface"
379 atf_set "require.progs" "rump_server"
380 }
381
382 bridge_rtable_delete_member_body()
383 {
384 local addr10= addr30= addr11= addr31=
385 local n=
386
387 setup
388 setup_bridge
389
390 # Add extra interfaces and addresses
391 export RUMP_SERVER=$SOCK1
392 rump_server_add_iface $SOCK1 shmif1 bus1
393 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24
394 atf_check -s exit:0 rump.ifconfig -w 10
395
396 export RUMP_SERVER=$SOCK3
397 rump_server_add_iface $SOCK3 shmif1 bus2
398 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.12/24
399 atf_check -s exit:0 rump.ifconfig -w 10
400
401 # Get MAC addresses of the endpoints.
402 addr10=$(get_macaddr $SOCK1 shmif0)
403 addr30=$(get_macaddr $SOCK3 shmif0)
404 addr11=$(get_macaddr $SOCK1 shmif1)
405 addr31=$(get_macaddr $SOCK3 shmif1)
406
407 # Make the bridge learn the MAC addresses of the endpoints.
408 export RUMP_SERVER=$SOCK1
409 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 10.0.0.12
410 export RUMP_SERVER=$SOCK3
411 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 10.0.0.11
412
413 export RUMP_SERVER=$SOCK2
414 export LD_PRELOAD=/usr/lib/librumphijack.so
415 $DEBUG && /sbin/brconfig bridge0
416 atf_check -s exit:0 -o match:"$addr10 shmif0" /sbin/brconfig bridge0
417 atf_check -s exit:0 -o match:"$addr11 shmif0" /sbin/brconfig bridge0
418 atf_check -s exit:0 -o match:"$addr30 shmif1" /sbin/brconfig bridge0
419 atf_check -s exit:0 -o match:"$addr31 shmif1" /sbin/brconfig bridge0
420
421 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 delete shmif0
422 atf_check -s exit:0 -o not-match:"$addr10 shmif0" /sbin/brconfig bridge0
423 atf_check -s exit:0 -o not-match:"$addr11 shmif0" /sbin/brconfig bridge0
424 atf_check -s exit:0 -o match:"$addr30 shmif1" /sbin/brconfig bridge0
425 atf_check -s exit:0 -o match:"$addr31 shmif1" /sbin/brconfig bridge0
426
427 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 delete shmif1
428 atf_check -s exit:0 -o not-match:"$addr10 shmif0" /sbin/brconfig bridge0
429 atf_check -s exit:0 -o not-match:"$addr11 shmif0" /sbin/brconfig bridge0
430 atf_check -s exit:0 -o not-match:"$addr30 shmif1" /sbin/brconfig bridge0
431 atf_check -s exit:0 -o not-match:"$addr31 shmif1" /sbin/brconfig bridge0
432
433 rump_server_destroy_ifaces
434 }
435
436 bridge_rtable_delete_member_cleanup()
437 {
438
439 $DEBUG && dump
440 cleanup
441 }
442
443
444 atf_test_case bridge_rtable_manyaddrs cleanup
445 bridge_rtable_manyaddrs_head()
446 {
447
448 atf_set "descr" "Tests brconfig addr under many MAC addresses"
449 atf_set "require.progs" "rump_server"
450 atf_set "timeout" "1200"
451 }
452
453 bridge_rtable_manyaddrs_body()
454 {
455 local addr=
456
457 setup
458 setup_bridge
459
460 export RUMP_SERVER=$SOCK2
461 export LD_PRELOAD=/usr/lib/librumphijack.so
462 atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1024
463
464 # Fill the MAC addresses
465 for i in 1 2 3 4; do
466 for j in $(seq 0 255); do
467 addr="00:11:22:33:4$i:$(printf "%02x" $j)"
468 atf_check -s exit:0 -o empty \
469 /sbin/brconfig bridge0 static shmif0 $addr
470 done
471
472 n=$(get_number_of_caches)
473 atf_check_equal $n $((i * 256))
474 done
475
476
477 rump_server_destroy_ifaces
478 }
479
480 bridge_rtable_manyaddrs_cleanup()
481 {
482
483 $DEBUG && dump
484 cleanup
485 }
486
487
488 atf_init_test_cases()
489 {
490
491 atf_add_test_case bridge_rtable_basic
492 atf_add_test_case bridge_rtable_flush
493 atf_add_test_case bridge_rtable_timeout
494 atf_add_test_case bridge_rtable_maxaddr
495 atf_add_test_case bridge_rtable_delete_member
496 atf_add_test_case bridge_rtable_manyaddrs
497 # TODO: brconfig static/flushall/discover/learn
498 }
499