author | xiaofeya |
Tue, 17 Apr 2018 23:27:41 -0700 | |
changeset 49799 | 33dcb9c42f55 |
parent 47216 | 71c04702a3d5 |
child 54903 | 5a211ee83bf1 |
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 |
|
27 |
* @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
|
28 |
* @library /test/lib |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
29 |
* @build jdk.test.lib.NetworkConfiguration |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
30 |
* jdk.test.lib.Platform |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
31 |
* @run main UdpTest |
2 | 32 |
*/ |
33 |
||
49799
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
34 |
import java.net.DatagramPacket; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
35 |
import java.net.DatagramSocket; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
36 |
import java.net.Inet4Address; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
37 |
import java.net.Inet6Address; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
38 |
import java.net.InetAddress; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
39 |
import java.net.PortUnreachableException; |
33dcb9c42f55
8194260: Point-to-point interface should be excluded from java/net/ipv6tests/*
xiaofeya
parents:
47216
diff
changeset
|
40 |
import java.net.SocketTimeoutException; |
2 | 41 |
|
42 |
public class UdpTest extends Tests { |
|
43 |
static DatagramSocket c3, s1, s2, s3; |
|
44 |
static InetAddress s1peer, s2peer; |
|
45 |
||
46 |
static InetAddress ia4any; |
|
47 |
static InetAddress ia6any; |
|
48 |
static Inet6Address ia6addr; |
|
49 |
static InetAddress ia6bad; /* a global 6to4 IPv6 address, which cant be connected to */ |
|
50 |
static InetAddress ia6rem1; |
|
51 |
static Inet4Address ia4addr; |
|
52 |
||
53 |
static { |
|
54 |
try { |
|
55 |
ia4any = InetAddress.getByName ("0.0.0.0"); |
|
56 |
ia6any = InetAddress.getByName ("::0"); |
|
57 |
try { |
|
58 |
ia6bad = InetAddress.getByName ("2002:819c:dc29:1:1322:33ff:fe44:5566%net0"); |
|
59 |
} catch (Exception e) { |
|
60 |
ia6bad = InetAddress.getByName ("2002:819c:dc29:1:1322:33ff:fe44:5566"); |
|
61 |
} |
|
62 |
//ia6rem1 = InetAddress.getByName ("fe80::a00:20ff:feed:b08d%eth0"); |
|
63 |
//ia6rem1 = InetAddress.getByName ("129.156.220.63"); |
|
64 |
} catch (Exception e) { |
|
65 |
e.printStackTrace(); |
|
66 |
} |
|
67 |
ia6addr = getFirstLocalIPv6Address (); |
|
68 |
ia4addr = getFirstLocalIPv4Address (); |
|
69 |
} |
|
70 |
||
71 |
public static void main (String[] args) throws Exception { |
|
72 |
checkDebug(args); |
|
73 |
if (ia6addr == null) { |
|
74 |
System.out.println ("No local IPv6 addresses: exiting now"); |
|
75 |
return; |
|
76 |
} |
|
77 |
dprintln ("Local Addresses"); |
|
78 |
dprintln (ia4addr.toString()); |
|
79 |
dprintln (ia6addr.toString()); |
|
80 |
test1 (); |
|
81 |
test2 (); |
|
82 |
if (!isLinux()) { |
|
83 |
test3 (); |
|
84 |
} |
|
85 |
test4 (); |
|
86 |
} |
|
87 |
||
88 |
/* basic UDP connectivity test using IPv6 only and IPv4/IPv6 together */ |
|
89 |
||
90 |
static void test1 () throws Exception { |
|
91 |
s1 = new DatagramSocket (); |
|
92 |
s2 = new DatagramSocket (); |
|
93 |
simpleDataExchange (s1, ia4addr, s2, ia4addr); |
|
94 |
s1.close (); s2.close (); |
|
95 |
||
96 |
/* IPv6 */ |
|
97 |
s1 = new DatagramSocket (); |
|
98 |
s2 = new DatagramSocket (); |
|
99 |
simpleDataExchange (s1, ia6addr, s2, ia6addr); |
|
100 |
s1.close (); s2.close (); |
|
101 |
||
102 |
/* IPv6 only */ |
|
103 |
s1 = new DatagramSocket (0, ia6addr); |
|
104 |
s2 = new DatagramSocket (0, ia6addr); |
|
105 |
simpleDataExchange (s1, ia6addr, s2, ia6addr); |
|
106 |
s1.close (); s2.close (); |
|
107 |
||
108 |
/* IPv6 and IPv4 */ |
|
109 |
s1 = new DatagramSocket (); |
|
110 |
s2 = new DatagramSocket (); |
|
111 |
simpleDataExchange (s1, ia6addr, s2, ia4addr); |
|
112 |
s1.close (); s2.close (); |
|
113 |
||
114 |
/* listen on anyaddr and check receive from IPv4 and IPv6 */ |
|
115 |
||
116 |
s1 = new DatagramSocket (); |
|
117 |
s2 = new DatagramSocket (0, ia6addr); |
|
118 |
s3 = new DatagramSocket (0, ia4addr); |
|
119 |
datagramEcho (s2, s1, ia6addr); |
|
120 |
datagramEcho (s3, s1, ia4addr); |
|
121 |
s1.close (); s2.close (); s3.close(); |
|
122 |
||
123 |
System.out.println ("Test1: OK"); |
|
124 |
} |
|
125 |
||
126 |
/* check timeouts on receive */ |
|
127 |
||
128 |
static void test2 () throws Exception { |
|
129 |
s1 = new DatagramSocket (); |
|
130 |
s2 = new DatagramSocket (); |
|
131 |
s1.setSoTimeout (4000); |
|
132 |
long t1 = System.currentTimeMillis(); |
|
133 |
try { |
|
134 |
s1.receive (new DatagramPacket (new byte [128], 128)); |
|
135 |
throw new Exception ("expected receive timeout "); |
|
136 |
} catch (SocketTimeoutException e) { |
|
137 |
} |
|
138 |
checkTime (System.currentTimeMillis() - t1, 4000); |
|
139 |
||
140 |
/* check data can be exchanged now */ |
|
141 |
||
142 |
simpleDataExchange (s1, ia6addr, s2, ia4addr); |
|
143 |
||
144 |
/* double check timeout still works */ |
|
145 |
t1 = System.currentTimeMillis(); |
|
146 |
try { |
|
147 |
s1.receive (new DatagramPacket (new byte [128], 128)); |
|
148 |
throw new Exception ("expected receive timeout "); |
|
149 |
} catch (SocketTimeoutException e) { |
|
150 |
} |
|
151 |
checkTime (System.currentTimeMillis() - t1, 4000); |
|
152 |
||
153 |
/* check receive works after a delay < timeout */ |
|
154 |
||
155 |
final DatagramSocket s = s2; |
|
156 |
final InetAddress ia6 = ia6addr; |
|
157 |
final int port = s1.getLocalPort(); |
|
158 |
||
22294
1e3a7c70240c
8031666: TEST_BUG: java/net/ipv6tests/UdpTest.java failed because of SocketTimeoutException
tyan
parents:
5506
diff
changeset
|
159 |
s1.setSoTimeout(10000); |
2 | 160 |
runAfter (2000, new Runnable () { |
161 |
public void run () { |
|
162 |
try { |
|
163 |
DatagramPacket p = new DatagramPacket ("Hello 123".getBytes(), 0, 8, ia6, port); |
|
164 |
s.send (p); |
|
165 |
} catch (Exception e) {} |
|
166 |
} |
|
167 |
}); |
|
168 |
t1 = System.currentTimeMillis(); |
|
169 |
s1.receive (new DatagramPacket (new byte [128], 128)); |
|
41887
61839a1a7e62
8143097: java/net/ipv6tests/UdpTest.java fails intermittently with "checkTime failed: got 1998 expected 4000"
amlu
parents:
36238
diff
changeset
|
170 |
checkTime (System.currentTimeMillis() - t1, 2000, 10000); |
2 | 171 |
s1.close (); |
172 |
s2.close (); |
|
173 |
System.out.println ("Test2: OK"); |
|
174 |
} |
|
175 |
||
176 |
/* check connected sockets */ |
|
177 |
||
178 |
static void test3 () throws Exception { |
|
179 |
s1 = new DatagramSocket (); |
|
180 |
s2 = new DatagramSocket (); |
|
181 |
s1.connect (ia6addr, s2.getLocalPort()); |
|
182 |
datagramEcho (s1, s2, null); |
|
183 |
s1.close (); s2.close(); |
|
184 |
System.out.println ("Test3: OK"); |
|
185 |
} |
|
186 |
||
187 |
/* check PortUnreachable */ |
|
188 |
||
189 |
static void test4 () throws Exception { |
|
190 |
s1 = new DatagramSocket (); |
|
191 |
s1.connect (ia6addr, 5000); |
|
192 |
s1.setSoTimeout (3000); |
|
193 |
try { |
|
194 |
DatagramPacket p = new DatagramPacket ("HelloWorld".getBytes(), "HelloWorld".length()); |
|
195 |
s1.send (p); |
|
196 |
p = new DatagramPacket (new byte[128], 128); |
|
197 |
s1.receive (p); |
|
198 |
} catch (PortUnreachableException e) { |
|
199 |
System.out.println ("Test4: OK"); |
|
200 |
return; |
|
201 |
} catch (SocketTimeoutException e) { |
|
202 |
System.out.println ("Test4: failed. Never mind, it's an OS bug"); |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
} |