]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/net/t_ipv6_lifetime.sh
MFC r305358,r305449,r305451,r306367,r306397,r309474:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / net / t_ipv6_lifetime.sh
1 #       $NetBSD: t_ipv6_lifetime.sh,v 1.2 2016/08/10 21:33:52 kre 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
28 INET6SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpdev"
29 INET6SERVER="$INET6SERVER -lrumpnet_netinet6 -lrumpnet_shmif"
30
31 SOCK=unix://sock
32 BUS=./bus
33
34 DEBUG=false
35
36 atf_test_case basic cleanup
37
38 basic_head()
39 {
40         atf_set "descr" "Tests for IPv6 address lifetime"
41         atf_set "require.progs" "rump_server"
42 }
43
44 basic_body()
45 {
46         local time=5
47         local bonus=2
48         local ip="fc00::1"
49
50         atf_check -s exit:0 ${INET6SERVER} $SOCK
51         export RUMP_SERVER=$SOCK
52
53         atf_check -s exit:0 rump.ifconfig shmif0 create
54         atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
55         atf_check -s exit:0 rump.ifconfig shmif0 up
56
57         # A normal IP address doesn't contain preferred/valid lifetime
58         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
59         $DEBUG && rump.ifconfig -L shmif0
60         atf_check -s exit:0 -o not-match:'pltime' rump.ifconfig -L shmif0
61         atf_check -s exit:0 -o not-match:'vltime' rump.ifconfig -L shmif0
62         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip delete
63
64         # Setting only a preferred lifetime
65         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip pltime $time
66         $DEBUG && rump.ifconfig -L shmif0
67         atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0
68         atf_check -s exit:0 -o match:'vltime infty' rump.ifconfig -L shmif0
69         atf_check -s exit:0 sleep $(($time + $bonus))
70         $DEBUG && rump.ifconfig -L shmif0
71         # Should remain but marked as deprecated
72         atf_check -s exit:0 -o match:'deprecated' rump.ifconfig -L shmif0
73         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip delete
74
75         # Setting only a valid lifetime (invalid)
76         atf_check -s not-exit:0 -e match:'Invalid argument' \
77             rump.ifconfig shmif0 inet6 $ip vltime $time
78
79         # Setting both preferred and valid lifetimes (same value)
80         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip \
81             pltime $time vltime $time
82         $DEBUG && rump.ifconfig -L shmif0
83         atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0
84         atf_check -s exit:0 -o match:'vltime' rump.ifconfig -L shmif0
85         atf_check -s exit:0 sleep $(($time + $bonus))
86         $DEBUG && rump.ifconfig -L shmif0
87         # Shouldn't remain anymore
88         atf_check -s exit:0 -o not-match:"$ip" rump.ifconfig -L shmif0
89
90         # Setting both preferred and valid lifetimes (pltime < vltime)
91         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip \
92             pltime $time vltime $((time * 2))
93         $DEBUG && rump.ifconfig -L shmif0
94         atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0
95         atf_check -s exit:0 -o match:'vltime' rump.ifconfig -L shmif0
96         atf_check -s exit:0 sleep $(($time + $bonus))
97         $DEBUG && rump.ifconfig -L shmif0
98         # Should remain but marked as deprecated
99         atf_check -s exit:0 -o match:'deprecated' rump.ifconfig -L shmif0
100         atf_check -s exit:0 sleep $(($time + $bonus))
101         $DEBUG && rump.ifconfig -L shmif0
102         # Shouldn't remain anymore
103         atf_check -s exit:0 -o not-match:"$ip" rump.ifconfig -L shmif0
104
105         # Setting both preferred and valid lifetimes (pltime > vltime)
106         atf_check -s not-exit:0 -e match:'Invalid argument' rump.ifconfig \
107             shmif0 inet6 $ip pltime $(($time * 2)) vltime $time
108
109         return 0
110 }
111
112 cleanup()
113 {
114         env RUMP_SERVER=$SOCK rump.halt
115 }
116
117 dump()
118 {
119         env RUMP_SERVER=$SOCK rump.ifconfig
120         env RUMP_SERVER=$SOCK rump.netstat -nr
121         shmif_dumpbus -p - $BUS 2>/dev/null| tcpdump -n -e -r -
122 }
123
124 basic_cleanup()
125 {
126         $DEBUG && dump
127         cleanup
128 }
129
130 atf_init_test_cases()
131 {
132         atf_add_test_case basic
133 }