author | xiaofeya |
Tue, 17 Apr 2018 23:27:41 -0700 | |
changeset 49799 | 33dcb9c42f55 |
parent 47216 | 71c04702a3d5 |
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 ScopeTests |
2 | 32 |
*/ |
33 |
||
34 |
import java.net.*; |
|
35 |
import java.util.*; |
|
36 |
||
37 |
public class ScopeTests extends Tests { |
|
38 |
||
39 |
public static void main (String[] args) throws Exception { |
|
40 |
checkDebug (args); |
|
41 |
simpleTests(); |
|
42 |
complexTests(); |
|
43 |
System.out.println ("Tests passed: OK"); |
|
44 |
} |
|
45 |
||
46 |
static void sassert (boolean condition, String msg) throws Exception { |
|
47 |
if (!condition) { |
|
48 |
throw new Exception (msg); |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
static void checkAddress (String a, int numeric) throws Exception { |
|
53 |
Inet6Address addr = (Inet6Address) InetAddress.getByName (a); |
|
54 |
if (addr.getScopeId () != numeric) { |
|
55 |
throw new Exception ("wroing numeric scopeid"); |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
static void checkAddress (String a, String str) throws Exception { |
|
60 |
Inet6Address addr = (Inet6Address) InetAddress.getByName (a); |
|
61 |
if (!addr.getScopedInterface().getName().equals (str)) { |
|
62 |
throw new Exception ("wroing scoped interface name"); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
/* These tests check generic API functionality that is not |
|
67 |
* dependent on scoping being implemented in the platform |
|
68 |
*/ |
|
69 |
static void simpleTests () throws Exception { |
|
70 |
checkAddress ("fe80::%1", 1); |
|
71 |
checkAddress ("fe80::1%1", 1); |
|
72 |
checkAddress ("fec0::1:a00:20ff:feed:b08d%0", 0); |
|
73 |
checkAddress ("fec0::1:a00:20ff:feed:b08d%1", 1); |
|
74 |
checkAddress ("fec0::1:a00:20ff:feed:b08d%99", 99); |
|
75 |
checkAddress ("fe80::", 0); |
|
76 |
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0); |
|
77 |
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0); |
|
78 |
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0); |
|
79 |
} |
|
80 |
||
81 |
/* These tests check the NetworkInterfaces for the actual scopeids |
|
82 |
* configured on the system and do tests using that information |
|
83 |
*/ |
|
84 |
static void complexTests () throws Exception { |
|
85 |
dprintln ("ComplexTests"); |
|
86 |
Enumeration e = NetworkInterface.getNetworkInterfaces(); |
|
87 |
while (e.hasMoreElements()) { |
|
88 |
NetworkInterface nif = (NetworkInterface)e.nextElement(); |
|
89 |
String name = nif.getName(); |
|
90 |
Enumeration addrs = nif.getInetAddresses(); |
|
91 |
while (addrs.hasMoreElements()) { |
|
92 |
InetAddress addr = (InetAddress) addrs.nextElement(); |
|
93 |
dprintln ("ComplexTests: "+addr); |
|
94 |
if (addr instanceof Inet6Address) { |
|
95 |
Inet6Address ia6 = (Inet6Address) addr; |
|
96 |
if (ia6.getScopeId() != 0) { |
|
97 |
System.out.println ("Testing interface: " + name + |
|
98 |
" and address: " + ia6); |
|
99 |
ctest1 (name, ia6); |
|
100 |
ctest2 (name, ia6); |
|
101 |
} else { |
|
102 |
System.out.println ("Interface: " + name + |
|
103 |
" Address: "+ ia6 + |
|
104 |
" does not support scope"); |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
||
112 |
/* check the scoped name on the Inet6Address is the same as |
|
113 |
* the interface it is attached to |
|
114 |
*/ |
|
115 |
static void ctest1 (String ifname, Inet6Address ia6) throws Exception { |
|
116 |
System.out.println ("ctest1:" + ia6); |
|
117 |
String s = ia6.getScopedInterface().getName(); |
|
118 |
int scope = ia6.getScopeId(); |
|
119 |
sassert (ifname.equals (s), "ctest1:"+ifname+":"+s); |
|
120 |
||
121 |
} |
|
122 |
||
123 |
/* create an Inet6Adddress by all three methods using the ifname |
|
124 |
* compare the numeric scope id with that of the Inet6Address passed in |
|
125 |
*/ |
|
126 |
static void ctest2 (String ifname, Inet6Address ia6) throws Exception { |
|
127 |
System.out.println ("ctest2:" + ia6); |
|
128 |
String s = ia6.getScopedInterface().getName(); |
|
129 |
int scope = ia6.getScopeId(); |
|
130 |
String s1 = ia6.getHostAddress(); |
|
131 |
if (s1.indexOf('%') != -1) { |
|
132 |
s1 = s1.substring (0, s1.indexOf ('%')); |
|
133 |
} |
|
134 |
Inet6Address add = (Inet6Address) InetAddress.getByName (s1+"%"+ifname); |
|
135 |
sassert (add.getScopeId() == scope, "ctest2:1:" +scope); |
|
136 |
} |
|
137 |
} |