1# $NetBSD: t_dad.sh,v 1.13 2016/11/25 08:51:16 ozaki-r Exp $ 2# 3# Copyright (c) 2015 The NetBSD Foundation, 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 28SOCKLOCAL=unix://commsock1 29SOCKPEER=unix://commsock2 30 31DEBUG=${DEBUG:-false} 32 33atf_test_case dad_basic cleanup 34atf_test_case dad_duplicated cleanup 35 36dad_basic_head() 37{ 38 atf_set "descr" "Tests for IPv4 DAD basic behavior" 39 atf_set "require.progs" "rump_server" 40} 41 42dad_duplicated_head() 43{ 44 atf_set "descr" "Tests for IPv4 DAD duplicated state" 45 atf_set "require.progs" "rump_server" 46} 47 48setup_server() 49{ 50 local sock=$1 51 local ip=$2 52 53 rump_server_add_iface $sock shmif0 bus1 54 55 export RUMP_SERVER=$sock 56 atf_check -s exit:0 rump.ifconfig shmif0 inet $ip/24 57 atf_check -s exit:0 rump.ifconfig shmif0 up 58 atf_check -s exit:0 rump.ifconfig -w 10 59 60 $DEBUG && rump.ifconfig shmif0 61} 62 63make_pkt_str() 64{ 65 local target=$1 66 local sender=$2 67 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:" 68 pkt="$pkt Request who-has $target tell $sender, length 28" 69 echo $pkt 70} 71 72dad_basic_body() 73{ 74 local pkt= 75 76 rump_server_start $SOCKLOCAL 77 rump_server_add_iface $SOCKLOCAL shmif0 bus1 78 79 export RUMP_SERVER=$SOCKLOCAL 80 81 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24 82 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias 83 $DEBUG && rump.ifconfig shmif0 84 85 atf_check -s exit:0 rump.ifconfig shmif0 up 86 rump.ifconfig shmif0 > ./out 87 $DEBUG && cat ./out 88 89 # The primary address doesn't start with tentative state 90 atf_check -s not-exit:0 -x "cat ./out |grep 10.0.0.1 |grep -iq tentative" 91 # The alias address starts with tentative state 92 # XXX we have no stable way to check this, so skip for now 93 #atf_check -s exit:0 -x "cat ./out |grep 10.0.0.2 |grep -iq tentative" 94 95 atf_check -s exit:0 sleep 2 96 extract_new_packets bus1 > ./out 97 $DEBUG && cat ./out 98 99 # Check DAD probe packets 100 pkt=$(make_pkt_str 10.0.0.2 0.0.0.0) 101 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 102 # No DAD for the primary address 103 pkt=$(make_pkt_str 10.0.0.1 0.0.0.0) 104 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'" 105 106 # Waiting for DAD complete 107 atf_check -s exit:0 rump.ifconfig -w 10 108 # Give a chance to send a DAD announce packet 109 atf_check -s exit:0 sleep 1 110 extract_new_packets bus1 > ./out 111 $DEBUG && cat ./out 112 113 # Check the DAD announce packet 114 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2) 115 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 116 # The alias address left tentative 117 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -iq tentative" 118 119 # 120 # Add a new address on the fly 121 # 122 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias 123 124 # The new address starts with tentative state 125 # XXX we have no stable way to check this, so skip for now 126 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative" 127 128 # Check DAD probe packets 129 atf_check -s exit:0 sleep 2 130 extract_new_packets bus1 > ./out 131 $DEBUG && cat ./out 132 pkt=$(make_pkt_str 10.0.0.3 0.0.0.0) 133 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 134 135 # Waiting for DAD complete 136 atf_check -s exit:0 rump.ifconfig -w 10 137 # Give a chance to send a DAD announce packet 138 atf_check -s exit:0 sleep 1 139 extract_new_packets bus1 > ./out 140 $DEBUG && cat ./out 141 142 # Check the DAD announce packet 143 pkt=$(make_pkt_str 10.0.0.3 10.0.0.3) 144 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 145 # The new address left tentative 146 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative" 147 148 rump_server_destroy_ifaces 149} 150 151dad_duplicated_body() 152{ 153 local localip1=10.0.1.1 154 local localip2=10.0.1.11 155 local peerip=10.0.1.2 156 157 rump_server_start $SOCKLOCAL 158 rump_server_start $SOCKPEER 159 160 setup_server $SOCKLOCAL $localip1 161 setup_server $SOCKPEER $peerip 162 163 export RUMP_SERVER=$SOCKLOCAL 164 165 # The primary address isn't marked as duplicated 166 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -iq duplicated" 167 168 # 169 # Add a new address duplicated with the peer server 170 # 171 atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias 172 atf_check -s exit:0 sleep 1 173 174 # The new address is marked as duplicated 175 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -iq duplicated" 176 177 # A unique address isn't marked as duplicated 178 atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias 179 atf_check -s exit:0 sleep 1 180 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -iq duplicated" 181 182 rump_server_destroy_ifaces 183} 184 185dad_basic_cleanup() 186{ 187 $DEBUG && dump 188 cleanup 189} 190 191dad_duplicated_cleanup() 192{ 193 $DEBUG && dump 194 cleanup 195} 196 197atf_init_test_cases() 198{ 199 atf_add_test_case dad_basic 200 atf_add_test_case dad_duplicated 201} 202