Tue Oct 4 03:41:33 2016 UTC ()
Add tests for sysctl net.inet6.ip6.dad_count

From suzu-ken@IIJ


(ozaki-r)
diff -r1.7 -r1.8 src/tests/net/ndp/t_dad.sh

cvs diff -r1.7 -r1.8 src/tests/net/ndp/t_dad.sh (expand / switch to unified diff)

--- src/tests/net/ndp/t_dad.sh 2016/09/16 00:50:43 1.7
+++ src/tests/net/ndp/t_dad.sh 2016/10/04 03:41:33 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_dad.sh,v 1.7 2016/09/16 00:50:43 ozaki-r Exp $ 1# $NetBSD: t_dad.sh,v 1.8 2016/10/04 03:41:33 ozaki-r Exp $
2# 2#
3# Copyright (c) 2015 The NetBSD Foundation, Inc. 3# Copyright (c) 2015 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
@@ -29,39 +29,46 @@ inetserver="rump_server -lrumpnet -lrump @@ -29,39 +29,46 @@ inetserver="rump_server -lrumpnet -lrump
29inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif" 29inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif"
30inetserver="$inetserver -lrumpdev" 30inetserver="$inetserver -lrumpdev"
31HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes" 31HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
32 32
33SOCKLOCAL=unix://commsock1 33SOCKLOCAL=unix://commsock1
34SOCKPEER=unix://commsock2 34SOCKPEER=unix://commsock2
35 35
36DEBUG=false 36DEBUG=false
37 37
38duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]" 38duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]"
39 39
40atf_test_case dad_basic cleanup 40atf_test_case dad_basic cleanup
41atf_test_case dad_duplicated cleanup 41atf_test_case dad_duplicated cleanup
 42atf_test_case dad_count cleanup
42 43
43dad_basic_head() 44dad_basic_head()
44{ 45{
45 atf_set "descr" "Tests for IPv6 DAD basic behavior" 46 atf_set "descr" "Tests for IPv6 DAD basic behavior"
46 atf_set "require.progs" "rump_server" 47 atf_set "require.progs" "rump_server"
47} 48}
48 49
49dad_duplicated_head() 50dad_duplicated_head()
50{ 51{
51 atf_set "descr" "Tests for IPv6 DAD duplicated state" 52 atf_set "descr" "Tests for IPv6 DAD duplicated state"
52 atf_set "require.progs" "rump_server" 53 atf_set "require.progs" "rump_server"
53} 54}
54 55
 56dad_count_head()
 57{
 58 atf_set "descr" "Tests for IPv6 DAD count behavior"
 59 atf_set "require.progs" "rump_server"
 60}
 61
55setup_server() 62setup_server()
56{ 63{
57 local sock=$1 64 local sock=$1
58 local ip=$2 65 local ip=$2
59 66
60 export RUMP_SERVER=$sock 67 export RUMP_SERVER=$sock
61 68
62 atf_check -s exit:0 rump.ifconfig shmif0 create 69 atf_check -s exit:0 rump.ifconfig shmif0 create
63 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1 70 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
64 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip 71 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
65 atf_check -s exit:0 rump.ifconfig shmif0 up 72 atf_check -s exit:0 rump.ifconfig shmif0 up
66 atf_check -s exit:0 rump.ifconfig -w 10 73 atf_check -s exit:0 rump.ifconfig -w 10
67 74
@@ -192,26 +199,83 @@ dad_duplicated_body() @@ -192,26 +199,83 @@ dad_duplicated_body()
192 atf_check -s exit:0 sleep 1 199 atf_check -s exit:0 sleep 1
193 200
194 # The new address is marked as duplicated 201 # The new address is marked as duplicated
195 atf_check -s exit:0 -o match:"$peerip.+$duplicated" \ 202 atf_check -s exit:0 -o match:"$peerip.+$duplicated" \
196 rump.ifconfig shmif0 203 rump.ifconfig shmif0
197 204
198 # A unique address isn't marked as duplicated 205 # A unique address isn't marked as duplicated
199 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2 206 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
200 atf_check -s exit:0 sleep 1 207 atf_check -s exit:0 sleep 1
201 atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \ 208 atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \
202 rump.ifconfig shmif0 209 rump.ifconfig shmif0
203} 210}
204 211
 212dad_count_test()
 213{
 214 local pkt=
 215 local count=$1
 216 local id=$2
 217 local target=$3
 218
 219 #
 220 # Set DAD count to $count
 221 #
 222 atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count
 223
 224 # Add a new address
 225 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target
 226
 227 # Waiting for DAD complete
 228 atf_check -s exit:0 rump.ifconfig -w 20
 229
 230 # Check the number of DAD probe packets (Neighbor Solicitation Message)
 231 atf_check -s exit:0 sleep 2
 232 extract_new_packets > ./out
 233 $DEBUG && cat ./out
 234 pkt=$(make_ns_pkt_str $id $target)
 235 atf_check -s exit:0 -o match:"$count" \
 236 -x "cat ./out |grep '$pkt' | wc -l | tr -d ' '"
 237}
 238
 239dad_count_body()
 240{
 241 local localip1=fc00::1
 242 local localip2=fc00::2
 243
 244 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
 245 export RUMP_SERVER=$SOCKLOCAL
 246
 247 # Check default value
 248 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count
 249
 250 # Setup interface
 251 atf_check -s exit:0 rump.ifconfig shmif0 create
 252 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
 253 atf_check -s exit:0 rump.ifconfig shmif0 up
 254 atf_check -s exit:0 sleep 2
 255 rump.ifconfig shmif0 > ./out
 256 $DEBUG && cat ./out
 257
 258 #
 259 # Set and test DAD count (count=1)
 260 #
 261 dad_count_test 1 1 $localip1
 262
 263 #
 264 # Set and test DAD count (count=8)
 265 #
 266 dad_count_test 8 2 $localip2
 267}
 268
205cleanup() 269cleanup()
206{ 270{
207 gdb -ex bt /usr/bin/rump_server rump_server.core 271 gdb -ex bt /usr/bin/rump_server rump_server.core
208 gdb -ex bt /usr/sbin/arp arp.core 272 gdb -ex bt /usr/sbin/arp arp.core
209 env RUMP_SERVER=$SOCKLOCAL rump.halt 273 env RUMP_SERVER=$SOCKLOCAL rump.halt
210 env RUMP_SERVER=$SOCKPEER rump.halt 274 env RUMP_SERVER=$SOCKPEER rump.halt
211} 275}
212 276
213dump_local() 277dump_local()
214{ 278{
215 export RUMP_SERVER=$SOCKLOCAL 279 export RUMP_SERVER=$SOCKLOCAL
216 rump.netstat -nr 280 rump.netstat -nr
217 rump.arp -n -a 281 rump.arp -n -a
@@ -238,18 +302,26 @@ dump() @@ -238,18 +302,26 @@ dump()
238dad_basic_cleanup() 302dad_basic_cleanup()
239{ 303{
240 $DEBUG && dump_local 304 $DEBUG && dump_local
241 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - 305 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
242 env RUMP_SERVER=$SOCKLOCAL rump.halt 306 env RUMP_SERVER=$SOCKLOCAL rump.halt
243} 307}
244 308
245dad_duplicated_cleanup() 309dad_duplicated_cleanup()
246{ 310{
247 $DEBUG && dump 311 $DEBUG && dump
248 cleanup 312 cleanup
249} 313}
250 314
 315dad_count_cleanup()
 316{
 317 $DEBUG && dump_local
 318 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
 319 env RUMP_SERVER=$SOCKLOCAL rump.halt
 320}
 321
251atf_init_test_cases() 322atf_init_test_cases()
252{ 323{
253 atf_add_test_case dad_basic 324 atf_add_test_case dad_basic
254 atf_add_test_case dad_duplicated 325 atf_add_test_case dad_duplicated
 326 atf_add_test_case dad_count
255} 327}