author | chegar |
Tue, 19 Jun 2018 09:13:58 +0100 | |
branch | http-client-branch |
changeset 56771 | 73a6534bce94 |
parent 49799 | 33dcb9c42f55 |
child 54746 | 61049e91eae5 |
child 57308 | f22d38b23756 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49799
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4868820 |
|
36432
cb9e462e049a
8151260: Mark URLPermission/URLTest.java and ipv6tests/TcpTest.java as intermittently failing
amlu
parents:
34888
diff
changeset
|
27 |
* @key intermittent |
2 | 28 |
* @summary IPv6 support for Windows XP and 2003 server |
49799
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
29 |
* @library /test/lib |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
30 |
* @build jdk.test.lib.NetworkConfiguration |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
31 |
* jdk.test.lib.Platform |
47017 | 32 |
* @run main TcpTest -d |
2 | 33 |
*/ |
34 |
||
35 |
import java.net.*; |
|
36 |
import java.io.*; |
|
37 |
||
38 |
public class TcpTest extends Tests { |
|
39 |
static ServerSocket server, server1, server2; |
|
40 |
static Socket c1, c2, c3, s1, s2, s3; |
|
41 |
static InetAddress s1peer, s2peer; |
|
42 |
||
43 |
static InetAddress ia4any; |
|
44 |
static InetAddress ia6any; |
|
45 |
static Inet6Address ia6addr; |
|
46 |
static Inet4Address ia4addr; |
|
47 |
||
48 |
static { |
|
49 |
ia6addr = getFirstLocalIPv6Address (); |
|
50 |
ia4addr = getFirstLocalIPv4Address (); |
|
51 |
try { |
|
52 |
ia4any = InetAddress.getByName ("0.0.0.0"); |
|
53 |
ia6any = InetAddress.getByName ("::0"); |
|
54 |
} catch (Exception e) { |
|
55 |
e.printStackTrace(); |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
public static void main (String[] args) throws Exception { |
|
60 |
checkDebug(args); |
|
61 |
if (ia6addr == null) { |
|
62 |
System.out.println ("No IPV6 addresses: exiting test"); |
|
63 |
return; |
|
64 |
} |
|
65 |
dprintln ("Local Addresses"); |
|
66 |
dprintln (ia4addr.toString()); |
|
67 |
dprintln (ia6addr.toString()); |
|
34888
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
68 |
test1(); |
2 | 69 |
test2(); |
70 |
test3(); |
|
71 |
test4(); |
|
72 |
} |
|
73 |
||
74 |
/* basic TCP connectivity test using IPv6 only and IPv4/IPv6 together */ |
|
75 |
||
34888
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
76 |
static void test1 () throws Exception { |
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
77 |
server = new ServerSocket (0); |
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
78 |
int port = server.getLocalPort(); |
2 | 79 |
// try Ipv6 only |
80 |
c1 = new Socket ("::1", port); |
|
81 |
s1 = server.accept (); |
|
82 |
simpleDataExchange (c1, s1); |
|
83 |
s1.close (); |
|
84 |
c1.close(); |
|
85 |
// try with both IPv4 and Ipv6 |
|
86 |
c1 = new Socket ("127.0.0.1", port); |
|
87 |
c2 = new Socket ("::1", port); |
|
88 |
s1 = server.accept(); |
|
89 |
s2 = server.accept(); |
|
90 |
s1peer = s1.getInetAddress(); |
|
91 |
s2peer = s2.getInetAddress(); |
|
92 |
if (s1peer instanceof Inet6Address) { |
|
93 |
t_assert ((s2peer instanceof Inet4Address)); |
|
94 |
simpleDataExchange (c2, s1); |
|
95 |
simpleDataExchange (c1, s2); |
|
96 |
} else { |
|
97 |
t_assert ((s2peer instanceof Inet6Address)); |
|
98 |
simpleDataExchange (c1, s1); |
|
99 |
simpleDataExchange (c2, s2); |
|
100 |
} |
|
101 |
c1.close(); |
|
102 |
c2.close(); |
|
103 |
s1.close(); |
|
104 |
s2.close(); |
|
105 |
server.close (); |
|
106 |
System.out.println ("Test1: OK"); |
|
107 |
} |
|
108 |
||
109 |
/** bind tests: |
|
110 |
* 1. bind to specific address IPv4 only (any port) |
|
111 |
* 2. bind to specific address IPv6 only (any port) |
|
34888
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
112 |
* 3. bind to any address IPv4 (test collision) |
2 | 113 |
*/ |
114 |
||
115 |
static void test2 () throws Exception { |
|
116 |
||
117 |
server = new ServerSocket (); |
|
118 |
InetSocketAddress sadr = new InetSocketAddress (ia4addr, 0); |
|
119 |
server.bind (sadr); |
|
120 |
dprintln ("server bound to " + sadr); |
|
121 |
int port = server.getLocalPort(); |
|
122 |
InetSocketAddress sadr6 = new InetSocketAddress (ia6addr, port); |
|
123 |
||
124 |
c1 = new Socket (ia4addr, port); |
|
125 |
try { |
|
126 |
dprintln ("connecting to " + ia6addr); |
|
127 |
c2 = new Socket (); |
|
128 |
c2.connect (sadr6, 1000); |
|
129 |
throw new RuntimeException ("connect to IPv6 address should be refused"); |
|
130 |
} catch (IOException e) { } |
|
131 |
server.close (); |
|
132 |
c1.close (); |
|
47017 | 133 |
if (c2 != null) { |
134 |
c2.close(); |
|
135 |
} |
|
2 | 136 |
|
137 |
/* now try IPv6 only */ |
|
138 |
||
139 |
server = new ServerSocket (); |
|
140 |
sadr = new InetSocketAddress (ia6addr, 0); |
|
141 |
dprintln ("binding to " + sadr); |
|
142 |
server.bind (sadr); |
|
143 |
port = server.getLocalPort(); |
|
144 |
||
145 |
c1 = new Socket (ia6addr, port); |
|
146 |
try { |
|
47017 | 147 |
dprintln ("connecting to " + ia4addr); |
2 | 148 |
c2 = new Socket (ia4addr, port); |
149 |
throw new RuntimeException ("connect to IPv4 address should be refused"); |
|
150 |
} catch (IOException e) { } |
|
151 |
server.close (); |
|
152 |
c1.close (); |
|
47017 | 153 |
if (c2 != null) { |
154 |
c2.close(); |
|
155 |
} |
|
2 | 156 |
|
157 |
System.out.println ("Test2: OK"); |
|
158 |
} |
|
159 |
||
160 |
/* Test timeouts on accept(), connect() */ |
|
161 |
||
162 |
static void test3 () throws Exception { |
|
163 |
server = new ServerSocket (0); |
|
164 |
server.setSoTimeout (5000); |
|
165 |
int port = server.getLocalPort(); |
|
166 |
long t1 = System.currentTimeMillis(); |
|
167 |
try { |
|
168 |
server.accept (); |
|
169 |
throw new RuntimeException ("accept should not have returned"); |
|
170 |
} catch (SocketTimeoutException e) {} |
|
171 |
t1 = System.currentTimeMillis() - t1; |
|
172 |
checkTime (t1, 5000); |
|
173 |
||
174 |
c1 = new Socket (); |
|
175 |
c1.connect (new InetSocketAddress (ia4addr, port), 1000); |
|
176 |
s1 = server.accept (); |
|
177 |
simpleDataExchange (c1,s1); |
|
178 |
c2 = new Socket (); |
|
179 |
c2.connect (new InetSocketAddress (ia6addr, port), 1000); |
|
180 |
s2 = server.accept (); |
|
181 |
simpleDataExchange (c2,s2); |
|
182 |
c3 = new Socket (); |
|
183 |
c3.connect (new InetSocketAddress (ia6addr, port), 1000); |
|
184 |
s3 = server.accept (); |
|
185 |
c2.close (); s2.close(); |
|
186 |
server.close(); |
|
187 |
simpleDataExchange (c3,s3); |
|
188 |
c1.close (); c2.close(); |
|
189 |
s1.close (); s2.close(); |
|
190 |
||
191 |
System.out.println ("Test3: OK"); |
|
192 |
} |
|
193 |
||
194 |
/* Test: connect to IPv4 mapped address */ |
|
195 |
||
196 |
static void test4 () throws Exception { |
|
197 |
server = new ServerSocket (0); |
|
198 |
int port = server.getLocalPort(); |
|
199 |
||
200 |
/* create an IPv4 mapped address corresponding to local host */ |
|
201 |
||
202 |
byte[] b = {0,0,0,0,0,0,0,0,0,0,(byte)0xff,(byte)0xff,0,0,0,0}; |
|
203 |
byte[] ia4 = ia4addr.getAddress(); |
|
204 |
b[12] = ia4[0]; |
|
205 |
b[13] = ia4[1]; |
|
206 |
b[14] = ia4[2]; |
|
207 |
b[15] = ia4[3]; |
|
208 |
||
209 |
InetAddress dest = InetAddress.getByAddress (b); |
|
210 |
c1 = new Socket (dest, port); |
|
211 |
s1 = server.accept (); |
|
212 |
simpleDataExchange (c1,s1); |
|
213 |
c1.close (); |
|
214 |
s1.close (); |
|
215 |
server.close (); |
|
216 |
System.out.println ("Test4: OK"); |
|
217 |
} |
|
218 |
} |
|
34888
e3161752067f
8140472: java/net/ipv6tests/TcpTest.java failed intermittently with java.net.BindException: Address already in use: NET_Bind
xiaofeya
parents:
7668
diff
changeset
|
219 |