xref: /freebsd/contrib/netbsd-tests/net/arp/t_dad.sh (revision d370fd1cd8fc69e87dc63f4f4a82e5a8b4956c93)
1*cdebaff8SEnji Cooper#	$NetBSD: t_dad.sh,v 1.13 2016/11/25 08:51:16 ozaki-r Exp $
2640235e2SEnji Cooper#
3640235e2SEnji Cooper# Copyright (c) 2015 The NetBSD Foundation, Inc.
4640235e2SEnji Cooper# All rights reserved.
5640235e2SEnji Cooper#
6640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7640235e2SEnji Cooper# modification, are permitted provided that the following conditions
8640235e2SEnji Cooper# are met:
9640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13640235e2SEnji Cooper#    documentation and/or other materials provided with the distribution.
14640235e2SEnji Cooper#
15640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26640235e2SEnji Cooper#
27640235e2SEnji Cooper
28640235e2SEnji CooperSOCKLOCAL=unix://commsock1
29640235e2SEnji CooperSOCKPEER=unix://commsock2
30640235e2SEnji Cooper
31*cdebaff8SEnji CooperDEBUG=${DEBUG:-false}
32640235e2SEnji Cooper
33640235e2SEnji Cooperatf_test_case dad_basic cleanup
34640235e2SEnji Cooperatf_test_case dad_duplicated cleanup
35640235e2SEnji Cooper
36640235e2SEnji Cooperdad_basic_head()
37640235e2SEnji Cooper{
38640235e2SEnji Cooper	atf_set "descr" "Tests for IPv4 DAD basic behavior"
39640235e2SEnji Cooper	atf_set "require.progs" "rump_server"
40640235e2SEnji Cooper}
41640235e2SEnji Cooper
42640235e2SEnji Cooperdad_duplicated_head()
43640235e2SEnji Cooper{
44640235e2SEnji Cooper	atf_set "descr" "Tests for IPv4 DAD duplicated state"
45640235e2SEnji Cooper	atf_set "require.progs" "rump_server"
46640235e2SEnji Cooper}
47640235e2SEnji Cooper
48640235e2SEnji Coopersetup_server()
49640235e2SEnji Cooper{
50640235e2SEnji Cooper	local sock=$1
51640235e2SEnji Cooper	local ip=$2
52640235e2SEnji Cooper
53*cdebaff8SEnji Cooper	rump_server_add_iface $sock shmif0 bus1
54640235e2SEnji Cooper
55*cdebaff8SEnji Cooper	export RUMP_SERVER=$sock
56640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet $ip/24
57640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 up
58640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig -w 10
59640235e2SEnji Cooper
60640235e2SEnji Cooper	$DEBUG && rump.ifconfig shmif0
61640235e2SEnji Cooper}
62640235e2SEnji Cooper
63640235e2SEnji Coopermake_pkt_str()
64640235e2SEnji Cooper{
65640235e2SEnji Cooper	local target=$1
66640235e2SEnji Cooper	local sender=$2
67640235e2SEnji Cooper	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
68640235e2SEnji Cooper	pkt="$pkt Request who-has $target tell $sender, length 28"
69640235e2SEnji Cooper	echo $pkt
70640235e2SEnji Cooper}
71640235e2SEnji Cooper
72640235e2SEnji Cooperdad_basic_body()
73640235e2SEnji Cooper{
74640235e2SEnji Cooper	local pkt=
75640235e2SEnji Cooper
76*cdebaff8SEnji Cooper	rump_server_start $SOCKLOCAL
77*cdebaff8SEnji Cooper	rump_server_add_iface $SOCKLOCAL shmif0 bus1
78*cdebaff8SEnji Cooper
79640235e2SEnji Cooper	export RUMP_SERVER=$SOCKLOCAL
80640235e2SEnji Cooper
81640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
82640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
83640235e2SEnji Cooper	$DEBUG && rump.ifconfig shmif0
84640235e2SEnji Cooper
85640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 up
86640235e2SEnji Cooper	rump.ifconfig shmif0 > ./out
87640235e2SEnji Cooper	$DEBUG && cat ./out
88640235e2SEnji Cooper
89640235e2SEnji Cooper	# The primary address doesn't start with tentative state
90*cdebaff8SEnji Cooper	atf_check -s not-exit:0 -x "cat ./out |grep 10.0.0.1 |grep -iq tentative"
91640235e2SEnji Cooper	# The alias address starts with tentative state
92640235e2SEnji Cooper	# XXX we have no stable way to check this, so skip for now
93*cdebaff8SEnji Cooper	#atf_check -s exit:0 -x "cat ./out |grep 10.0.0.2 |grep -iq tentative"
94640235e2SEnji Cooper
95640235e2SEnji Cooper	atf_check -s exit:0 sleep 2
96*cdebaff8SEnji Cooper	extract_new_packets bus1 > ./out
97640235e2SEnji Cooper	$DEBUG && cat ./out
98640235e2SEnji Cooper
99640235e2SEnji Cooper	# Check DAD probe packets
100640235e2SEnji Cooper	pkt=$(make_pkt_str 10.0.0.2 0.0.0.0)
101640235e2SEnji Cooper	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
102640235e2SEnji Cooper	# No DAD for the primary address
103640235e2SEnji Cooper	pkt=$(make_pkt_str 10.0.0.1 0.0.0.0)
104640235e2SEnji Cooper	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
105640235e2SEnji Cooper
106640235e2SEnji Cooper	# Waiting for DAD complete
107640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig -w 10
108640235e2SEnji Cooper	# Give a chance to send a DAD announce packet
109640235e2SEnji Cooper	atf_check -s exit:0 sleep 1
110*cdebaff8SEnji Cooper	extract_new_packets bus1 > ./out
111640235e2SEnji Cooper	$DEBUG && cat ./out
112640235e2SEnji Cooper
113640235e2SEnji Cooper	# Check the DAD announce packet
114640235e2SEnji Cooper	pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
115640235e2SEnji Cooper	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
116640235e2SEnji Cooper	# The alias address left tentative
117*cdebaff8SEnji Cooper	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -iq tentative"
118640235e2SEnji Cooper
119640235e2SEnji Cooper	#
120640235e2SEnji Cooper	# Add a new address on the fly
121640235e2SEnji Cooper	#
122640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias
123640235e2SEnji Cooper
124640235e2SEnji Cooper	# The new address starts with tentative state
125640235e2SEnji Cooper	# XXX we have no stable way to check this, so skip for now
126*cdebaff8SEnji Cooper	#atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative"
127640235e2SEnji Cooper
128640235e2SEnji Cooper	# Check DAD probe packets
129640235e2SEnji Cooper	atf_check -s exit:0 sleep 2
130*cdebaff8SEnji Cooper	extract_new_packets bus1 > ./out
131640235e2SEnji Cooper	$DEBUG && cat ./out
132640235e2SEnji Cooper	pkt=$(make_pkt_str 10.0.0.3 0.0.0.0)
133640235e2SEnji Cooper	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
134640235e2SEnji Cooper
135640235e2SEnji Cooper	# Waiting for DAD complete
136640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig -w 10
137640235e2SEnji Cooper	# Give a chance to send a DAD announce packet
138640235e2SEnji Cooper	atf_check -s exit:0 sleep 1
139*cdebaff8SEnji Cooper	extract_new_packets bus1 > ./out
140640235e2SEnji Cooper	$DEBUG && cat ./out
141640235e2SEnji Cooper
142640235e2SEnji Cooper	# Check the DAD announce packet
143640235e2SEnji Cooper	pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
144640235e2SEnji Cooper	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
145640235e2SEnji Cooper	# The new address left tentative
146*cdebaff8SEnji Cooper	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative"
147*cdebaff8SEnji Cooper
148*cdebaff8SEnji Cooper	rump_server_destroy_ifaces
149640235e2SEnji Cooper}
150640235e2SEnji Cooper
151640235e2SEnji Cooperdad_duplicated_body()
152640235e2SEnji Cooper{
153640235e2SEnji Cooper	local localip1=10.0.1.1
154640235e2SEnji Cooper	local localip2=10.0.1.11
155640235e2SEnji Cooper	local peerip=10.0.1.2
156640235e2SEnji Cooper
157*cdebaff8SEnji Cooper	rump_server_start $SOCKLOCAL
158*cdebaff8SEnji Cooper	rump_server_start $SOCKPEER
159640235e2SEnji Cooper
160640235e2SEnji Cooper	setup_server $SOCKLOCAL $localip1
161640235e2SEnji Cooper	setup_server $SOCKPEER $peerip
162640235e2SEnji Cooper
163640235e2SEnji Cooper	export RUMP_SERVER=$SOCKLOCAL
164640235e2SEnji Cooper
165640235e2SEnji Cooper	# The primary address isn't marked as duplicated
166*cdebaff8SEnji Cooper	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -iq duplicated"
167640235e2SEnji Cooper
168640235e2SEnji Cooper	#
169640235e2SEnji Cooper	# Add a new address duplicated with the peer server
170640235e2SEnji Cooper	#
171640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias
172640235e2SEnji Cooper	atf_check -s exit:0 sleep 1
173640235e2SEnji Cooper
174640235e2SEnji Cooper	# The new address is marked as duplicated
175*cdebaff8SEnji Cooper	atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -iq duplicated"
176640235e2SEnji Cooper
177640235e2SEnji Cooper	# A unique address isn't marked as duplicated
178640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias
179640235e2SEnji Cooper	atf_check -s exit:0 sleep 1
180*cdebaff8SEnji Cooper	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -iq duplicated"
181640235e2SEnji Cooper
182*cdebaff8SEnji Cooper	rump_server_destroy_ifaces
183640235e2SEnji Cooper}
184640235e2SEnji Cooper
185640235e2SEnji Cooperdad_basic_cleanup()
186640235e2SEnji Cooper{
187*cdebaff8SEnji Cooper	$DEBUG && dump
188*cdebaff8SEnji Cooper	cleanup
189640235e2SEnji Cooper}
190640235e2SEnji Cooper
191640235e2SEnji Cooperdad_duplicated_cleanup()
192640235e2SEnji Cooper{
193640235e2SEnji Cooper	$DEBUG && dump
194640235e2SEnji Cooper	cleanup
195640235e2SEnji Cooper}
196640235e2SEnji Cooper
197640235e2SEnji Cooperatf_init_test_cases()
198640235e2SEnji Cooper{
199640235e2SEnji Cooper	atf_add_test_case dad_basic
200640235e2SEnji Cooper	atf_add_test_case dad_duplicated
201640235e2SEnji Cooper}
202