author | iignatyev |
Mon, 12 Jun 2017 12:43:26 -0700 | |
changeset 45467 | 99c87a16a8e4 |
parent 45186 | 387a39577f09 |
permissions | -rw-r--r-- |
1152 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13363
diff
changeset
|
2 |
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
1152 | 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. |
|
1152 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
25 |
* @bug 4527345 7026376 6633549 |
1152 | 26 |
* @summary Unit test for DatagramChannel's multicast support |
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
27 |
* @library /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
28 |
* @build jdk.test.lib.NetworkConfiguration |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
29 |
* jdk.test.lib.Platform |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45186
diff
changeset
|
30 |
* MulticastSendReceiveTests |
3424 | 31 |
* @run main MulticastSendReceiveTests |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
32 |
* @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests |
30046 | 33 |
* @key randomness |
1152 | 34 |
*/ |
35 |
||
36 |
import java.nio.ByteBuffer; |
|
37 |
import java.nio.channels.*; |
|
38 |
import java.net.*; |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
39 |
import static java.net.StandardProtocolFamily.*; |
1152 | 40 |
import java.util.*; |
41 |
import java.io.IOException; |
|
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
42 |
import java.util.stream.Collectors; |
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
43 |
|
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
44 |
import jdk.test.lib.NetworkConfiguration; |
1152 | 45 |
|
46 |
public class MulticastSendReceiveTests { |
|
47 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
48 |
static final Random rand = new Random(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
49 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
50 |
static final ProtocolFamily UNSPEC = new ProtocolFamily() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
51 |
public String name() { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
52 |
return "UNSPEC"; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
53 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
54 |
}; |
1152 | 55 |
|
56 |
/** |
|
57 |
* Send datagram from given local address to given multicast |
|
58 |
* group. |
|
59 |
*/ |
|
60 |
static int sendDatagram(InetAddress local, |
|
61 |
NetworkInterface nif, |
|
62 |
InetAddress group, |
|
63 |
int port) |
|
64 |
throws IOException |
|
65 |
{ |
|
66 |
ProtocolFamily family = (group instanceof Inet6Address) ? |
|
67 |
StandardProtocolFamily.INET6 : StandardProtocolFamily.INET; |
|
68 |
DatagramChannel dc = DatagramChannel.open(family) |
|
69 |
.bind(new InetSocketAddress(local, 0)) |
|
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
70 |
.setOption(StandardSocketOptions.IP_MULTICAST_IF, nif); |
1152 | 71 |
int id = rand.nextInt(); |
72 |
byte[] msg = Integer.toString(id).getBytes("UTF-8"); |
|
73 |
ByteBuffer buf = ByteBuffer.wrap(msg); |
|
74 |
System.out.format("Send message from %s -> group %s (id=0x%x)\n", |
|
75 |
local.getHostAddress(), group.getHostAddress(), id); |
|
76 |
dc.send(buf, new InetSocketAddress(group, port)); |
|
77 |
dc.close(); |
|
78 |
return id; |
|
79 |
} |
|
80 |
||
81 |
/** |
|
82 |
* Wait (with timeout) for datagram. |
|
83 |
* |
|
84 |
* @param expectedSender - expected sender address, or |
|
85 |
* null if no datagram expected |
|
86 |
* @param id - expected id of datagram |
|
87 |
*/ |
|
88 |
static void receiveDatagram(DatagramChannel dc, |
|
89 |
InetAddress expectedSender, |
|
90 |
int id) |
|
91 |
throws IOException |
|
92 |
{ |
|
93 |
Selector sel = Selector.open(); |
|
94 |
dc.configureBlocking(false); |
|
95 |
dc.register(sel, SelectionKey.OP_READ); |
|
96 |
ByteBuffer buf = ByteBuffer.allocateDirect(100); |
|
97 |
||
98 |
try { |
|
99 |
for (;;) { |
|
100 |
System.out.println("Waiting to receive message"); |
|
101 |
sel.select(5*1000); |
|
102 |
SocketAddress sa = dc.receive(buf); |
|
103 |
||
104 |
// no datagram received |
|
105 |
if (sa == null) { |
|
106 |
if (expectedSender != null) { |
|
29746
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
107 |
throw new RuntimeException("Expected message not received"); |
1152 | 108 |
} |
109 |
System.out.println("No message received (correct)"); |
|
110 |
return; |
|
111 |
} |
|
112 |
||
113 |
// datagram received |
|
114 |
||
115 |
InetAddress sender = ((InetSocketAddress)sa).getAddress(); |
|
116 |
buf.flip(); |
|
117 |
byte[] bytes = new byte[buf.remaining()]; |
|
118 |
buf.get(bytes); |
|
29746
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
119 |
String s = new String(bytes, "UTF-8"); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
120 |
int receivedId = -1; |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
121 |
try { |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
122 |
receivedId = Integer.parseInt(s); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
123 |
System.out.format("Received message from %s (id=0x%x)\n", |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
124 |
sender, receivedId); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
125 |
} catch (NumberFormatException x) { |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
126 |
System.out.format("Received message from %s (msg=%s)\n", sender, s); |
f0730dd3de62
8076644: MulticastSendReceiveTests.java fails with NumberFormatException due to network interference
chegar
parents:
14342
diff
changeset
|
127 |
} |
1152 | 128 |
|
129 |
if (expectedSender == null) { |
|
130 |
if (receivedId == id) |
|
131 |
throw new RuntimeException("Message not expected"); |
|
132 |
System.out.println("Message ignored (has wrong id)"); |
|
133 |
} else { |
|
134 |
if (sender.equals(expectedSender)) { |
|
135 |
System.out.println("Message expected"); |
|
136 |
return; |
|
137 |
} |
|
138 |
System.out.println("Message ignored (wrong sender)"); |
|
139 |
} |
|
140 |
||
141 |
sel.selectedKeys().clear(); |
|
142 |
buf.rewind(); |
|
143 |
} |
|
144 |
} finally { |
|
145 |
sel.close(); |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
||
150 |
/** |
|
151 |
* Exercise multicast send/receive on given group/interface |
|
152 |
*/ |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
153 |
static void test(ProtocolFamily family, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
154 |
NetworkInterface nif, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
155 |
InetAddress group, |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
156 |
InetAddress source) |
1152 | 157 |
throws IOException |
158 |
{ |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
159 |
System.out.format("\nTest DatagramChannel to %s socket\n", family.name()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
160 |
try (DatagramChannel dc = (family == UNSPEC) ? |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
161 |
DatagramChannel.open() : DatagramChannel.open(family)) { |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
9035
diff
changeset
|
162 |
dc.setOption(StandardSocketOptions.SO_REUSEADDR, true) |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
163 |
.bind(new InetSocketAddress(0)); |
1152 | 164 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
165 |
// join group |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
166 |
System.out.format("join %s @ %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
167 |
nif.getName()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
168 |
MembershipKey key; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
169 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
170 |
key = dc.join(group, nif); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
171 |
} catch (IllegalArgumentException iae) { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
172 |
if (family == UNSPEC) { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
173 |
System.out.println("Not supported"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
174 |
return; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
175 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
176 |
throw iae; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
177 |
} |
1152 | 178 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
179 |
// send message to group |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
180 |
int port = ((InetSocketAddress)dc.getLocalAddress()).getPort(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
181 |
int id = sendDatagram(source, nif, group, port); |
1152 | 182 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
183 |
// receive message and check id matches |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
184 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
185 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
186 |
// exclude-mode filtering |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
187 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
188 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
189 |
System.out.format("block %s\n", source.getHostAddress()); |
1152 | 190 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
191 |
// may throw UOE |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
192 |
key.block(source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
193 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
194 |
receiveDatagram(dc, null, id); |
1152 | 195 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
196 |
// unblock source, send message, message should be received |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
197 |
System.out.format("unblock %s\n", source.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
198 |
key.unblock(source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
199 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
200 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
201 |
} catch (UnsupportedOperationException x) { |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
202 |
String os = System.getProperty("os.name"); |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
203 |
// Exclude-mode filtering supported on these platforms so UOE should never be thrown |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
204 |
if (os.equals("SunOS") || os.equals("Linux")) |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
205 |
throw x; |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
206 |
System.out.println("Exclude-mode filtering not supported!"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
207 |
} |
1152 | 208 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
209 |
key.drop(); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
210 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
211 |
// include-mode filtering |
1152 | 212 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
213 |
InetAddress bogus = (group instanceof Inet6Address) ? |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
214 |
InetAddress.getByName("fe80::1234") : |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
215 |
InetAddress.getByName("1.2.3.4"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
216 |
System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
217 |
nif.getName(), bogus.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
218 |
try { |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
219 |
// may throw UOE |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
220 |
key = dc.join(group, nif, bogus); |
1152 | 221 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
222 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
223 |
receiveDatagram(dc, null, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
224 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
225 |
System.out.format("join %s @ %s only-source %s\n", group.getHostAddress(), |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
226 |
nif.getName(), source.getHostAddress()); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
227 |
key = dc.join(group, nif, source); |
1152 | 228 |
|
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
229 |
id = sendDatagram(source, nif, group, port); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
230 |
receiveDatagram(dc, source, id); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
231 |
} catch (UnsupportedOperationException x) { |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
232 |
String os = System.getProperty("os.name"); |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
233 |
// Include-mode filtering supported on these platforms so UOE should never be thrown |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
234 |
if (os.equals("SunOS") || os.equals("Linux")) |
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
9679
diff
changeset
|
235 |
throw x; |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
236 |
System.out.println("Include-mode filtering not supported!"); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
237 |
} |
1152 | 238 |
} |
239 |
} |
|
240 |
||
241 |
public static void main(String[] args) throws IOException { |
|
242 |
NetworkConfiguration config = NetworkConfiguration.probe(); |
|
243 |
||
244 |
// multicast groups used for the test |
|
245 |
InetAddress ip4Group = InetAddress.getByName("225.4.5.6"); |
|
246 |
InetAddress ip6Group = InetAddress.getByName("ff02::a"); |
|
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
247 |
for (NetworkInterface nif: config.ip4MulticastInterfaces() |
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
248 |
.collect(Collectors.toList())) { |
1152 | 249 |
InetAddress source = config.ip4Addresses(nif).iterator().next(); |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
250 |
test(INET, nif, ip4Group, source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
251 |
test(UNSPEC, nif, ip4Group, source); |
1152 | 252 |
} |
253 |
||
45186
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
254 |
for (NetworkInterface nif: config.ip6MulticastInterfaces() |
387a39577f09
8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
iignatyev
parents:
30046
diff
changeset
|
255 |
.collect(Collectors.toList())) { |
1152 | 256 |
InetAddress source = config.ip6Addresses(nif).iterator().next(); |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
257 |
test(INET6, nif, ip6Group, source); |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
5506
diff
changeset
|
258 |
test(UNSPEC, nif, ip6Group, source); |
1152 | 259 |
} |
260 |
} |
|
261 |
} |