8207404: MulticastSocket tests failing on AIX

Reviewed-by: chegar, sgroeger
This commit is contained in:
Christoph Langer 2019-01-21 06:55:59 +00:00
parent 0622059445
commit bc651663e3
5 changed files with 248 additions and 219 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,7 +21,15 @@
* questions.
*/
/*
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import jdk.test.lib.NetworkConfiguration;
/**
* @test
* @bug 4091811 4148753 4102731
* @summary Test java.net.MulticastSocket joinGroup and leaveGroup
@ -29,18 +37,11 @@
* @build jdk.test.lib.NetworkConfiguration
* jdk.test.lib.Platform
* @run main JoinLeave
* @run main/othervm -Djava.net.preferIPv4Stack=true JoinLeave
*/
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import jdk.test.lib.NetworkConfiguration;
public class JoinLeave {
public static void main(String args[]) throws IOException {
public static void main(String args[]) throws IOException {
InetAddress ip4Group = InetAddress.getByName("224.80.80.80");
InetAddress ip6Group = InetAddress.getByName("ff02::a");
@ -49,8 +50,7 @@ public class JoinLeave {
nc.ip6MulticastInterfaces().forEach(nic -> joinLeave(ip6Group, nic));
}
static void joinLeave(InetAddress group, NetworkInterface nif)
{
static void joinLeave(InetAddress group, NetworkInterface nif) {
System.out.println("Joining:" + group + " on " + nif);
try (MulticastSocket soc = new MulticastSocket()) {
soc.setNetworkInterface(nif);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,105 +21,50 @@
* questions.
*/
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
/*
import jdk.test.lib.NetworkConfiguration;
/**
* @test
* @bug 6458027
* @summary Disabling IPv6 on a specific network interface causes problems.
*
*/
import java.io.IOException;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Enumeration;
public class SetGetNetworkInterfaceTest {
* @library /test/lib
* @build jdk.test.lib.NetworkConfiguration
* jdk.test.lib.Platform
* @run main SetGetNetworkInterfaceTest
* @run main/othervm -Djava.net.preferIPv4Stack=true SetGetNetworkInterfaceTest
*/
public class SetGetNetworkInterfaceTest {
public static void main(String[] args) throws Exception {
boolean passed = true;
try {
MulticastSocket ms = new MulticastSocket();
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface netIf = networkInterfaces.nextElement();
if (isNetworkInterfaceTestable(netIf)) {
printNetIfDetails(netIf);
ms.setNetworkInterface(netIf);
NetworkInterface msNetIf = ms.getNetworkInterface();
if (netIf.equals(msNetIf)) {
System.out.println(" OK");
} else {
System.out.println("FAILED!!!");
printNetIfDetails(msNetIf);
passed = false;
}
System.out.println("------------------");
}
}
NetworkConfiguration nc = NetworkConfiguration.probe();
try (MulticastSocket ms = new MulticastSocket()) {
nc.multicastInterfaces(true).forEach(nif -> setGetNetworkInterface(ms, nif));
} catch (IOException e) {
e.printStackTrace();
passed = false;
}
if (!passed) {
throw new RuntimeException("Test Fail");
}
System.out.println("Test passed ");
System.out.println("Test passed.");
}
private static boolean isNetworkInterfaceTestable(NetworkInterface netIf) throws Exception {
System.out.println("checking netif == " + netIf.getName());
return (netIf.isUp() && netIf.supportsMulticast() && isIpAddrAvailable(netIf));
}
private static boolean isIpAddrAvailable (NetworkInterface netIf) {
boolean ipAddrAvailable = false;
byte[] nullIpAddr = {'0', '0', '0', '0'};
byte[] testIpAddr = null;
Enumeration<InetAddress> ipAddresses = netIf.getInetAddresses();
while (ipAddresses.hasMoreElements()) {
InetAddress testAddr = ipAddresses.nextElement();
testIpAddr = testAddr.getAddress();
if ((testIpAddr != null) && (!Arrays.equals(testIpAddr, nullIpAddr))) {
ipAddrAvailable = true;
break;
static void setGetNetworkInterface(MulticastSocket ms, NetworkInterface nif) {
try {
System.out.println(NetworkConfiguration.interfaceInformation(nif));
ms.setNetworkInterface(nif);
NetworkInterface msNetIf = ms.getNetworkInterface();
if (nif.equals(msNetIf)) {
System.out.println(" OK");
} else {
System.out.println("ignore netif " + netIf.getName());
System.out.println("FAILED!!!");
System.out.println(NetworkConfiguration.interfaceInformation(msNetIf));
throw new RuntimeException("Test Fail");
}
System.out.println("------------------");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return ipAddrAvailable;
}
private static void printNetIfDetails(NetworkInterface ni)
throws SocketException {
System.out.println("Name " + ni.getName() + " index " + ni.getIndex());
Enumeration<InetAddress> en = ni.getInetAddresses();
while (en.hasMoreElements()) {
System.out.println(" InetAdress: " + en.nextElement());
}
System.out.println("HardwareAddress: " + createMacAddrString(ni));
System.out.println("loopback: " + ni.isLoopback() + "; pointToPoint: "
+ ni.isPointToPoint() + "; virtual: " + ni.isVirtual()
+ "; MTU: " + ni.getMTU());
}
private static String createMacAddrString(NetworkInterface netIf)
throws SocketException {
byte[] macAddr = netIf.getHardwareAddress();
StringBuilder sb = new StringBuilder();
if (macAddr != null) {
for (int i = 0; i < macAddr.length; i++) {
sb.append(String.format("%02X%s", macAddr[i],
(i < macAddr.length - 1) ? "-" : ""));
}
}
return sb.toString();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,25 +21,31 @@
* questions.
*/
/*
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketTimeoutException;
import jdk.test.lib.NetworkConfiguration;
/**
* @test
* @bug 4488458
* @summary IPv4 and IPv6 multicasting broken on Linux
* @library /test/lib
* @build jdk.test.lib.NetworkConfiguration
* jdk.test.lib.Platform
* @run main Test
* @run main/othervm -Djava.net.preferIPv4Stack=true Test
*/
import java.net.*;
import java.io.IOException;
import java.util.Enumeration;
public class Test {
static int count = 0;
static int failures = 0;
static boolean isSolaris = System.getProperty("os.name")
.toLowerCase()
.startsWith("sunos");
void doTest(String address) throws Exception {
void doTest(String address) throws IOException {
boolean failed = false;
InetAddress ia = InetAddress.getByName(address);
@ -65,7 +71,7 @@ public class Test {
/* packets should be received */
for (int j=0; j<2; j++) {
for (int j = 0; j < 2; j++) {
p.setAddress(ia);
p.setPort(port);
@ -127,67 +133,26 @@ public class Test {
}
}
static boolean isValidIpv6Address(InetAddress addr) {
if (! (addr instanceof Inet6Address))
return false;
if (!isSolaris)
return true;
return !(addr.isAnyLocalAddress() || addr.isLoopbackAddress());
}
void allTests() throws IOException {
NetworkConfiguration nc = NetworkConfiguration.probe();
void allTests() throws Exception {
/*
* Assume machine has IPv4 address
*/
// unconditionally test IPv4 address
doTest("224.80.80.80");
/*
* Check if IPv6 is enabled and the scope of the addresses
*/
boolean has_ipv6 = false;
boolean has_siteaddress = false;
boolean has_linklocaladdress = false;
boolean has_globaladdress = false;
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface)nifs.nextElement();
Enumeration addrs = ni.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress ia = (InetAddress)addrs.nextElement();
if (isValidIpv6Address(ia)) {
has_ipv6 = true;
if (ia.isLinkLocalAddress()) has_linklocaladdress = true;
if (ia.isSiteLocalAddress()) has_siteaddress = true;
if (!ia.isLinkLocalAddress() &&
!ia.isSiteLocalAddress() &&
!ia.isLoopbackAddress()) {
has_globaladdress = true;
}
}
}
}
/*
* If IPv6 is enabled perform multicast tests with various scopes
*/
if (has_ipv6) {
// If IPv6 is enabled perform multicast tests with various scopes
if (nc.hasTestableIPv6Address()) {
doTest("ff01::a");
}
if (has_linklocaladdress) {
if (nc.hasLinkLocalAddress()) {
doTest("ff02::a");
}
if (has_siteaddress) {
if (nc.hasSiteLocalAddress()) {
doTest("ff05::a");
}
if (has_globaladdress) {
if (nc.has_globaladdress()) {
doTest("ff0e::a");
}
}
@ -198,7 +163,7 @@ public class Test {
if (args.length == 0) {
t.allTests();
} else {
for (int i=0; i<args.length; i++) {
for (int i = 0; i < args.length; i++) {
t.doTest(args[i]);
}
}