author | msheppar |
Thu, 11 May 2017 15:05:32 +0100 | |
changeset 45122 | 8cfb711b103b |
parent 30810 | cbb29036f026 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45122
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
2 |
* Copyright (c) 2007, 2017, 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 4742177 |
|
27 |
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code |
|
28 |
*/ |
|
29 |
import java.net.*; |
|
30 |
import java.util.*; |
|
31 |
||
32 |
||
33 |
public class SetOutgoingIf { |
|
34 |
private static int PORT = 9001; |
|
35 |
private static String osname; |
|
36 |
||
37 |
static boolean isWindows() { |
|
38 |
if (osname == null) |
|
39 |
osname = System.getProperty("os.name"); |
|
40 |
return osname.contains("Windows"); |
|
41 |
} |
|
42 |
||
45122
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
43 |
static boolean isMacOS() { |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
44 |
return System.getProperty("os.name").contains("OS X"); |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
45 |
} |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
46 |
|
2 | 47 |
private static boolean hasIPv6() throws Exception { |
48 |
List<NetworkInterface> nics = Collections.list( |
|
49 |
NetworkInterface.getNetworkInterfaces()); |
|
50 |
for (NetworkInterface nic : nics) { |
|
51 |
List<InetAddress> addrs = Collections.list(nic.getInetAddresses()); |
|
52 |
for (InetAddress addr : addrs) { |
|
53 |
if (addr instanceof Inet6Address) |
|
54 |
return true; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
return false; |
|
59 |
} |
|
60 |
||
61 |
public static void main(String[] args) throws Exception { |
|
62 |
if (isWindows()) { |
|
63 |
System.out.println("The test only run on non-Windows OS. Bye."); |
|
64 |
return; |
|
65 |
} |
|
66 |
||
67 |
if (!hasIPv6()) { |
|
68 |
System.out.println("No IPv6 available. Bye."); |
|
69 |
return; |
|
70 |
} |
|
71 |
||
72 |
// We need 2 or more network interfaces to run the test |
|
73 |
// |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
74 |
List<NetIf> netIfs = new ArrayList<NetIf>(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
75 |
int index = 1; |
2 | 76 |
for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) { |
3945 | 77 |
// we should use only network interfaces with multicast support which are in "up" state |
45122
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
78 |
if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp() && !isTestExcludedInterface(nic)) { |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
79 |
NetIf netIf = NetIf.create(nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
80 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
81 |
// now determine what (if any) type of addresses are assigned to this interface |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
82 |
for (InetAddress addr : Collections.list(nic.getInetAddresses())) { |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
83 |
if (addr.isAnyLocalAddress()) |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
84 |
continue; |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
85 |
|
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
86 |
System.out.println(" addr " + addr); |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
87 |
if (addr instanceof Inet4Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
88 |
netIf.ipv4Address(true); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
89 |
} else if (addr instanceof Inet6Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
90 |
netIf.ipv6Address(true); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
91 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
92 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
93 |
if (netIf.ipv4Address() || netIf.ipv6Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
94 |
netIf.index(index++); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
95 |
netIfs.add(netIf); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
96 |
debug("Using: " + nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
97 |
} |
45122
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
98 |
} else { |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
99 |
System.out.println("Ignore NetworkInterface nic == " + nic); |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
100 |
} |
2 | 101 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
102 |
if (netIfs.size() <= 1) { |
2 | 103 |
System.out.println("Need 2 or more network interfaces to run. Bye."); |
104 |
return; |
|
105 |
} |
|
106 |
||
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
107 |
// We will send packets to one ipv4, and one ipv6 |
2 | 108 |
// multicast group using each network interface :- |
109 |
// 224.1.1.1 --| |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
110 |
// ff02::1:1 --|--> using network interface #1 |
2 | 111 |
// 224.1.2.1 --| |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
112 |
// ff02::1:2 --|--> using network interface #2 |
2 | 113 |
// and so on. |
114 |
// |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
115 |
for (NetIf netIf : netIfs) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
116 |
int NetIfIndex = netIf.index(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
117 |
List<InetAddress> groups = new ArrayList<InetAddress>(); |
2 | 118 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
119 |
if (netIf.ipv4Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
120 |
InetAddress groupv4 = InetAddress.getByName("224.1." + NetIfIndex + ".1"); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
121 |
groups.add(groupv4); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
122 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
123 |
if (netIf.ipv6Address()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
124 |
InetAddress groupv6 = InetAddress.getByName("ff02::1:" + NetIfIndex); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
125 |
groups.add(groupv6); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
126 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
127 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
128 |
debug("Adding " + groups + " groups for " + netIf.nic().getName()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
129 |
netIf.groups(groups); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
130 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
131 |
// use a separated thread to send to those 2 groups |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
132 |
Thread sender = new Thread(new Sender(netIf, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
133 |
groups, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
134 |
PORT)); |
2 | 135 |
sender.setDaemon(true); // we want sender to stop when main thread exits |
136 |
sender.start(); |
|
137 |
} |
|
138 |
||
139 |
// try to receive on each group, then check if the packet comes |
|
140 |
// from the expected network interface |
|
141 |
// |
|
142 |
byte[] buf = new byte[1024]; |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
143 |
for (NetIf netIf : netIfs) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
144 |
NetworkInterface nic = netIf.nic(); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
145 |
for (InetAddress group : netIf.groups()) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
146 |
MulticastSocket mcastsock = new MulticastSocket(PORT); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
147 |
mcastsock.setSoTimeout(5000); // 5 second |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
148 |
DatagramPacket packet = new DatagramPacket(buf, 0, buf.length); |
2 | 149 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
150 |
// the interface supports the IP multicast group |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
151 |
debug("Joining " + group + " on " + nic.getName()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
152 |
mcastsock.joinGroup(new InetSocketAddress(group, PORT), nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
153 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
154 |
try { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
155 |
mcastsock.receive(packet); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
156 |
debug("received packet on " + packet.getAddress()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
157 |
} catch (Exception e) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
158 |
// test failed if any exception |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
159 |
throw new RuntimeException(e); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
160 |
} |
2 | 161 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
162 |
// now check which network interface this packet comes from |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
163 |
NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
164 |
NetworkInterface shouldbe = nic; |
30810
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
165 |
if (from != null) { |
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
166 |
if (!from.equals(shouldbe)) { |
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
167 |
System.out.println("Packets on group " |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
168 |
+ group + " should come from " |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
169 |
+ shouldbe.getName() + ", but came from " |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
170 |
+ from.getName()); |
30810
cbb29036f026
8077377: java/net/MulticastSocket/SetOutgoingIf.java fails intermittently with NullPointerException
msheppar
parents:
7668
diff
changeset
|
171 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
172 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
173 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
174 |
mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nic); |
2 | 175 |
} |
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
176 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
177 |
} |
2 | 178 |
|
45122
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
179 |
private static boolean isTestExcludedInterface(NetworkInterface nif) { |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
180 |
if (isMacOS() && nif.getName().contains("awdl")) |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
181 |
return true; |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
182 |
String dName = nif.getDisplayName(); |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
183 |
if (isWindows() && dName != null && dName.contains("Teredo")) |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
184 |
return true; |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
185 |
return false; |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
186 |
} |
8cfb711b103b
7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
msheppar
parents:
30810
diff
changeset
|
187 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
188 |
private static boolean debug = true; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
189 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
190 |
static void debug(String message) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
191 |
if (debug) |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
192 |
System.out.println(message); |
2 | 193 |
} |
194 |
} |
|
195 |
||
196 |
class Sender implements Runnable { |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
197 |
private NetIf netIf; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
198 |
private List<InetAddress> groups; |
2 | 199 |
private int port; |
200 |
||
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
201 |
public Sender(NetIf netIf, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
202 |
List<InetAddress> groups, |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
203 |
int port) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
204 |
this.netIf = netIf; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
205 |
this.groups = groups; |
2 | 206 |
this.port = port; |
207 |
} |
|
208 |
||
209 |
public void run() { |
|
210 |
try { |
|
211 |
MulticastSocket mcastsock = new MulticastSocket(); |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
212 |
mcastsock.setNetworkInterface(netIf.nic()); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
213 |
List<DatagramPacket> packets = new LinkedList<DatagramPacket>(); |
2 | 214 |
|
215 |
byte[] buf = "hello world".getBytes(); |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
216 |
for (InetAddress group : groups) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
217 |
packets.add(new DatagramPacket(buf, buf.length, new InetSocketAddress(group, port))); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
218 |
} |
2 | 219 |
|
220 |
for (;;) { |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
221 |
for (DatagramPacket packet : packets) |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
222 |
mcastsock.send(packet); |
2 | 223 |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
224 |
Thread.sleep(1000); // sleep 1 second |
2 | 225 |
} |
226 |
} catch (Exception e) { |
|
227 |
throw new RuntimeException(e); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
3962
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
231 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
232 |
@SuppressWarnings("unchecked") |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
233 |
class NetIf { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
234 |
private boolean ipv4Address; //false |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
235 |
private boolean ipv6Address; //false |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
236 |
private int index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
237 |
List<InetAddress> groups = Collections.EMPTY_LIST; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
238 |
private final NetworkInterface nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
239 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
240 |
private NetIf(NetworkInterface nic) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
241 |
this.nic = nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
242 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
243 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
244 |
static NetIf create(NetworkInterface nic) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
245 |
return new NetIf(nic); |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
246 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
247 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
248 |
NetworkInterface nic() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
249 |
return nic; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
250 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
251 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
252 |
boolean ipv4Address() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
253 |
return ipv4Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
254 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
255 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
256 |
void ipv4Address(boolean ipv4Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
257 |
this.ipv4Address = ipv4Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
258 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
259 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
260 |
boolean ipv6Address() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
261 |
return ipv6Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
262 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
263 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
264 |
void ipv6Address(boolean ipv6Address) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
265 |
this.ipv6Address = ipv6Address; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
266 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
267 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
268 |
int index() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
269 |
return index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
270 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
271 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
272 |
void index(int index) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
273 |
this.index = index; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
274 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
275 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
276 |
List<InetAddress> groups() { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
277 |
return groups; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
278 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
279 |
|
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
280 |
void groups(List<InetAddress> groups) { |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
281 |
this.groups = groups; |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
282 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
283 |
} |
cf907ac8ca4c
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
chegar
parents:
3945
diff
changeset
|
284 |