1 /* |
1 /* |
2 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* @test |
24 /* @test |
25 * @bug 4527345 7026376 6633549 |
25 * @bug 4527345 7026376 6633549 8233435 |
26 * @summary Unit test for DatagramChannel's multicast support |
26 * @summary Unit test for DatagramChannel's multicast support |
27 * @library /test/lib |
27 * @library /test/lib |
28 * @build jdk.test.lib.NetworkConfiguration |
28 * @build jdk.test.lib.NetworkConfiguration |
29 * jdk.test.lib.Platform |
29 * jdk.test.lib.Platform |
|
30 * jdk.test.lib.net.IPSupport |
30 * MulticastSendReceiveTests |
31 * MulticastSendReceiveTests |
31 * @run main MulticastSendReceiveTests |
32 * @run main MulticastSendReceiveTests |
32 * @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests |
33 * @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests |
33 * @key randomness |
34 * @key randomness |
34 */ |
35 */ |
39 import static java.net.StandardProtocolFamily.*; |
40 import static java.net.StandardProtocolFamily.*; |
40 import java.util.*; |
41 import java.util.*; |
41 import java.io.IOException; |
42 import java.io.IOException; |
42 import java.util.stream.Collectors; |
43 import java.util.stream.Collectors; |
43 |
44 |
|
45 import jdk.test.lib.Platform; |
44 import jdk.test.lib.NetworkConfiguration; |
46 import jdk.test.lib.NetworkConfiguration; |
45 import jdk.test.lib.net.IPSupport; |
47 import jdk.test.lib.net.IPSupport; |
46 |
48 |
47 public class MulticastSendReceiveTests { |
49 public class MulticastSendReceiveTests { |
48 |
50 |
240 } |
242 } |
241 |
243 |
242 public static void main(String[] args) throws IOException { |
244 public static void main(String[] args) throws IOException { |
243 IPSupport.throwSkippedExceptionIfNonOperational(); |
245 IPSupport.throwSkippedExceptionIfNonOperational(); |
244 |
246 |
|
247 // IPv4 and IPv6 interfaces that support multicasting |
245 NetworkConfiguration config = NetworkConfiguration.probe(); |
248 NetworkConfiguration config = NetworkConfiguration.probe(); |
|
249 List<NetworkInterface> ip4MulticastInterfaces = config.ip4MulticastInterfaces() |
|
250 .collect(Collectors.toList()); |
|
251 List<NetworkInterface> ip6MulticastInterfaces = config.ip6MulticastInterfaces() |
|
252 .collect(Collectors.toList()); |
246 |
253 |
247 // multicast groups used for the test |
254 // multicast groups used for the test |
248 InetAddress ip4Group = InetAddress.getByName("225.4.5.6"); |
255 InetAddress ip4Group = InetAddress.getByName("225.4.5.6"); |
249 InetAddress ip6Group = InetAddress.getByName("ff02::a"); |
256 InetAddress ip6Group = InetAddress.getByName("ff02::a"); |
250 for (NetworkInterface nif: config.ip4MulticastInterfaces() |
257 |
251 .collect(Collectors.toList())) { |
258 // Platforms that allow dual sockets join IPv4 multicast groups |
|
259 boolean canIPv6JoinIPv4Group = |
|
260 Platform.isLinux() || |
|
261 Platform.isOSX() || |
|
262 Platform.isSolaris() || |
|
263 Platform.isWindows(); |
|
264 |
|
265 for (NetworkInterface nif : ip4MulticastInterfaces) { |
252 InetAddress source = config.ip4Addresses(nif).iterator().next(); |
266 InetAddress source = config.ip4Addresses(nif).iterator().next(); |
|
267 test(UNSPEC, nif, ip4Group, source); |
253 test(INET, nif, ip4Group, source); |
268 test(INET, nif, ip4Group, source); |
254 test(UNSPEC, nif, ip4Group, source); |
269 if (IPSupport.hasIPv6() && canIPv6JoinIPv4Group) { |
255 } |
270 test(INET6, nif, ip4Group, source); |
256 |
271 } |
257 for (NetworkInterface nif: config.ip6MulticastInterfaces() |
272 } |
258 .collect(Collectors.toList())) { |
273 |
|
274 for (NetworkInterface nif : ip6MulticastInterfaces) { |
259 InetAddress source = config.ip6Addresses(nif).iterator().next(); |
275 InetAddress source = config.ip6Addresses(nif).iterator().next(); |
|
276 test(UNSPEC, nif, ip6Group, source); |
260 test(INET6, nif, ip6Group, source); |
277 test(INET6, nif, ip6Group, source); |
261 test(UNSPEC, nif, ip6Group, source); |
|
262 } |
278 } |
263 } |
279 } |
264 } |
280 } |