Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
7ecc454b
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7ecc454b
编写于
10月 07, 2009
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6887364: SetOutgoingIf.java fails if run on multihomed machine without PIv6 on all interfaces
Reviewed-by: alanb
上级
c50d911e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
149 addition
and
67 deletion
+149
-67
jdk/test/java/net/MulticastSocket/SetOutgoingIf.java
jdk/test/java/net/MulticastSocket/SetOutgoingIf.java
+149
-67
未找到文件。
jdk/test/java/net/MulticastSocket/SetOutgoingIf.java
浏览文件 @
7ecc454b
...
...
@@ -27,7 +27,6 @@
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
*/
import
java.net.*
;
import
java.util.concurrent.*
;
import
java.util.*
;
...
...
@@ -68,38 +67,61 @@ public class SetOutgoingIf {
// We need 2 or more network interfaces to run the test
//
List
<
NetworkInterface
>
nics
=
new
ArrayList
<
NetworkInterface
>();
List
<
NetIf
>
netIfs
=
new
ArrayList
<
NetIf
>();
int
index
=
1
;
for
(
NetworkInterface
nic
:
Collections
.
list
(
NetworkInterface
.
getNetworkInterfaces
()))
{
// we should use only network interfaces with multicast support which are in "up" state
if
(!
nic
.
isLoopback
()
&&
nic
.
supportsMulticast
()
&&
nic
.
isUp
())
nics
.
add
(
nic
);
if
(!
nic
.
isLoopback
()
&&
nic
.
supportsMulticast
()
&&
nic
.
isUp
())
{
NetIf
netIf
=
NetIf
.
create
(
nic
);
// now determine what (if any) type of addresses are assigned to this interface
for
(
InetAddress
addr
:
Collections
.
list
(
nic
.
getInetAddresses
()))
{
if
(
addr
instanceof
Inet4Address
)
{
netIf
.
ipv4Address
(
true
);
}
else
if
(
addr
instanceof
Inet6Address
)
{
netIf
.
ipv6Address
(
true
);
}
}
if
(
netIf
.
ipv4Address
()
||
netIf
.
ipv6Address
())
{
netIf
.
index
(
index
++);
netIfs
.
add
(
netIf
);
debug
(
"Using: "
+
nic
);
}
}
}
if
(
n
ic
s
.
size
()
<=
1
)
{
if
(
n
etIf
s
.
size
()
<=
1
)
{
System
.
out
.
println
(
"Need 2 or more network interfaces to run. Bye."
);
return
;
}
// We will send packets to one ipv4,
one ipv4-mapped,
and one ipv6
// We will send packets to one ipv4, and one ipv6
// multicast group using each network interface :-
// 224.1.1.1 --|
// ::ffff:224.1.1.2 -----> using network interface #1
// ff02::1:1 --|
// ff02::1:1 --|--> using network interface #1
// 224.1.2.1 --|
// ::ffff:224.1.2.2 -----> using network interface #2
// ff02::1:2 --|
// ff02::1:2 --|--> using network interface #2
// and so on.
//
List
<
InetAddress
>
groups
=
new
ArrayList
<
InetAddress
>();
for
(
int
i
=
0
;
i
<
nics
.
size
();
i
++)
{
InetAddress
groupv4
=
InetAddress
.
getByName
(
"224.1."
+
(
i
+
1
)
+
".1"
);
InetAddress
groupv4mapped
=
InetAddress
.
getByName
(
"::ffff:224.1."
+
(
i
+
1
)
+
".2"
);
InetAddress
groupv6
=
InetAddress
.
getByName
(
"ff02::1:"
+
(
i
+
1
));
groups
.
add
(
groupv4
);
groups
.
add
(
groupv4mapped
);
groups
.
add
(
groupv6
);
// use a separated thread to send to those 3 groups
Thread
sender
=
new
Thread
(
new
Sender
(
nics
.
get
(
i
),
groupv4
,
groupv4mapped
,
groupv6
,
PORT
));
for
(
NetIf
netIf
:
netIfs
)
{
int
NetIfIndex
=
netIf
.
index
();
List
<
InetAddress
>
groups
=
new
ArrayList
<
InetAddress
>();
if
(
netIf
.
ipv4Address
())
{
InetAddress
groupv4
=
InetAddress
.
getByName
(
"224.1."
+
NetIfIndex
+
".1"
);
groups
.
add
(
groupv4
);
}
if
(
netIf
.
ipv6Address
())
{
InetAddress
groupv6
=
InetAddress
.
getByName
(
"ff02::1:"
+
NetIfIndex
);
groups
.
add
(
groupv6
);
}
debug
(
"Adding "
+
groups
+
" groups for "
+
netIf
.
nic
().
getName
());
netIf
.
groups
(
groups
);
// use a separated thread to send to those 2 groups
Thread
sender
=
new
Thread
(
new
Sender
(
netIf
,
groups
,
PORT
));
sender
.
setDaemon
(
true
);
// we want sender to stop when main thread exits
sender
.
start
();
}
...
...
@@ -108,75 +130,135 @@ public class SetOutgoingIf {
// from the expected network interface
//
byte
[]
buf
=
new
byte
[
1024
];
for
(
InetAddress
group
:
groups
)
{
MulticastSocket
mcastsock
=
new
MulticastSocket
(
PORT
);
mcastsock
.
setSoTimeout
(
5000
);
// 5 second
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
0
,
buf
.
length
);
mcastsock
.
joinGroup
(
new
InetSocketAddress
(
group
,
PORT
),
nics
.
get
(
groups
.
indexOf
(
group
)
/
3
));
try
{
mcastsock
.
receive
(
packet
);
}
catch
(
Exception
e
)
{
// test failed if any exception
throw
new
RuntimeException
(
e
);
}
for
(
NetIf
netIf
:
netIfs
)
{
NetworkInterface
nic
=
netIf
.
nic
();
for
(
InetAddress
group
:
netIf
.
groups
())
{
MulticastSocket
mcastsock
=
new
MulticastSocket
(
PORT
);
mcastsock
.
setSoTimeout
(
5000
);
// 5 second
DatagramPacket
packet
=
new
DatagramPacket
(
buf
,
0
,
buf
.
length
);
// now check which network interface this packet comes from
NetworkInterface
from
=
NetworkInterface
.
getByInetAddress
(
packet
.
getAddress
());
NetworkInterface
shouldbe
=
nics
.
get
(
groups
.
indexOf
(
group
)
/
3
);
if
(!
from
.
equals
(
shouldbe
))
{
System
.
out
.
println
(
"Packets on group "
+
group
+
" should come from "
+
shouldbe
.
getName
()
+
", but came from "
+
from
.
getName
());
//throw new RuntimeException("Test failed.");
}
// the interface supports the IP multicast group
debug
(
"Joining "
+
group
+
" on "
+
nic
.
getName
());
mcastsock
.
joinGroup
(
new
InetSocketAddress
(
group
,
PORT
),
nic
);
try
{
mcastsock
.
receive
(
packet
);
debug
(
"received packet on "
+
packet
.
getAddress
());
}
catch
(
Exception
e
)
{
// test failed if any exception
throw
new
RuntimeException
(
e
);
}
// now check which network interface this packet comes from
NetworkInterface
from
=
NetworkInterface
.
getByInetAddress
(
packet
.
getAddress
());
NetworkInterface
shouldbe
=
nic
;
if
(!
from
.
equals
(
shouldbe
))
{
System
.
out
.
println
(
"Packets on group "
+
group
+
" should come from "
+
shouldbe
.
getName
()
+
", but came from "
+
from
.
getName
());
//throw new RuntimeException("Test failed.");
}
mcastsock
.
leaveGroup
(
new
InetSocketAddress
(
group
,
PORT
),
nics
.
get
(
groups
.
indexOf
(
group
)
/
3
));
mcastsock
.
leaveGroup
(
new
InetSocketAddress
(
group
,
PORT
),
nic
);
}
}
}
private
static
boolean
debug
=
true
;
static
void
debug
(
String
message
)
{
if
(
debug
)
System
.
out
.
println
(
message
);
}
}
class
Sender
implements
Runnable
{
private
NetworkInterface
nic
;
private
InetAddress
group1
;
private
InetAddress
group2
;
private
InetAddress
group3
;
private
NetIf
netIf
;
private
List
<
InetAddress
>
groups
;
private
int
port
;
public
Sender
(
NetworkInterface
nic
,
InetAddress
groupv4
,
InetAddress
groupv4mapped
,
InetAddress
groupv6
,
int
port
)
{
this
.
nic
=
nic
;
group1
=
groupv4
;
group2
=
groupv4mapped
;
group3
=
groupv6
;
public
Sender
(
NetIf
netIf
,
List
<
InetAddress
>
groups
,
int
port
)
{
this
.
netIf
=
netIf
;
this
.
groups
=
groups
;
this
.
port
=
port
;
}
public
void
run
()
{
try
{
MulticastSocket
mcastsock
=
new
MulticastSocket
();
mcastsock
.
setNetworkInterface
(
nic
);
mcastsock
.
setNetworkInterface
(
netIf
.
nic
());
List
<
DatagramPacket
>
packets
=
new
LinkedList
<
DatagramPacket
>();
byte
[]
buf
=
"hello world"
.
getBytes
();
DatagramPacket
packet1
=
new
DatagramPacket
(
buf
,
buf
.
length
,
new
InetSocketAddress
(
group1
,
port
));
DatagramPacket
packet2
=
new
DatagramPacket
(
buf
,
buf
.
length
,
new
InetSocketAddress
(
group2
,
port
));
DatagramPacket
packet3
=
new
DatagramPacket
(
buf
,
buf
.
length
,
new
InetSocketAddress
(
group3
,
port
));
for
(
InetAddress
group
:
groups
)
{
packets
.
add
(
new
DatagramPacket
(
buf
,
buf
.
length
,
new
InetSocketAddress
(
group
,
port
)));
}
for
(;;)
{
mcastsock
.
send
(
packet1
);
mcastsock
.
send
(
packet2
);
mcastsock
.
send
(
packet3
);
for
(
DatagramPacket
packet
:
packets
)
mcastsock
.
send
(
packet
);
Thread
.
currentThread
().
sleep
(
1000
);
// sleep 1 second
Thread
.
sleep
(
1000
);
// sleep 1 second
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
@SuppressWarnings
(
"unchecked"
)
class
NetIf
{
private
boolean
ipv4Address
;
//false
private
boolean
ipv6Address
;
//false
private
int
index
;
List
<
InetAddress
>
groups
=
Collections
.
EMPTY_LIST
;
private
final
NetworkInterface
nic
;
private
NetIf
(
NetworkInterface
nic
)
{
this
.
nic
=
nic
;
}
static
NetIf
create
(
NetworkInterface
nic
)
{
return
new
NetIf
(
nic
);
}
NetworkInterface
nic
()
{
return
nic
;
}
boolean
ipv4Address
()
{
return
ipv4Address
;
}
void
ipv4Address
(
boolean
ipv4Address
)
{
this
.
ipv4Address
=
ipv4Address
;
}
boolean
ipv6Address
()
{
return
ipv6Address
;
}
void
ipv6Address
(
boolean
ipv6Address
)
{
this
.
ipv6Address
=
ipv6Address
;
}
int
index
()
{
return
index
;
}
void
index
(
int
index
)
{
this
.
index
=
index
;
}
List
<
InetAddress
>
groups
()
{
return
groups
;
}
void
groups
(
List
<
InetAddress
>
groups
)
{
this
.
groups
=
groups
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录