/* * Copyright (c) 2009, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Tests bind, bindAddress, unbindAddress, getLocalAddress, and * getAllLocalAddresses.
*/ publicclass Bind { void test(String[] args) { if (!Util.isSCTPSupported()) {
out.println("SCTP protocol is not supported");
out.println("Test cannot be run"); return;
}
/* Simply bind tests */
testBind();
/* Test unconnected */
testBindUnbind(false);
/* Test connected */ /* Adding/Removing addresses from a connected association is optional. * This test can be run on systems that support dynamic address
* reconfiguration */ //testBindUnbind(true);
}
/* TEST 1: empty set if channel is not bound */
check(channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned non empty set for unbound channel");
/* TEST 2: null to bind the channel to an automatically assigned
* socket address */
channel.bind(null);
/* TEST 3: non empty set if the channel is bound */
check(!channel.getAllLocalAddresses().isEmpty(), "getAllLocalAddresses returned empty set for bound channel");
debug("getAllLocalAddresses on channel bound to the wildcard:\n"
+ channel.getAllLocalAddresses());
/* TEST 4: AlreadyBoundException if this channel is already bound */ try { channel.bind(null); } catch (AlreadyBoundException unused) { pass(); } catch (IOException ioe) { unexpected(ioe); }
/* TEST 5: UnsupportedAddressTypeException */ try {
channel.close(); /* open a new unbound channel for test */
channel = SctpChannel.open();
channel.bind(new UnsupportedSocketAddress());
fail("UnsupportedSocketAddress expected");
} catch (UnsupportedAddressTypeException unused) { pass();
} catch (IOException ioe) { unexpected(ioe); }
/* TEST 6: AlreadyConnectedException */ try {
channel.close(); /* open a new unbound channel for test */
channel = SctpChannel.open(); try (var peer = connectChannel(channel)) {
channel.bind(null);
fail("AlreadyConnectedException expected");
}
} catch (AlreadyConnectedException unused) { pass();
} catch (IOException ioe) { unexpected(ioe); }
/* TEST 7: ClosedChannelException - If this channel is closed */ try {
channel.close(); /* open a new unbound channel for test */
channel = SctpChannel.open();
channel.close();
channel.bind(null);
fail("ClosedChannelException expected");
} catch (ClosedChannelException unused) { pass();
} catch (IOException ioe) { unexpected(ioe); }
List<InetAddress> addresses = Util.getAddresses(true, false);
Iterator iterator = addresses.iterator();
InetSocketAddress a = new InetSocketAddress((InetAddress)iterator.next(), 0);
debug("channel.bind( " + a + ")");
channel.bind(a); while (iterator.hasNext()) {
InetAddress ia = (InetAddress)iterator.next();
debug("channel.bindAddress(" + ia + ")");
channel.bindAddress(ia);
} if (debug) {Util.dumpAddresses(channel, out);}
if (connected) { /* Test with connected channel */
peerChannel = connectChannel(channel);
}
/* TEST 1: bind/unbindAddresses on the system addresses */
debug("bind/unbindAddresses on the system addresses");
List<InetAddress> addrs = Util.getAddresses(true, false); for (InetAddress addr : addrs) { try {
debug("unbindAddress: " + addr);
check(boundAddress(channel, addr), "trying to remove address that is not bound");
channel.unbindAddress(addr); if (debug) {Util.dumpAddresses(channel, out);}
check(!boundAddress(channel, addr), "address was not removed");
debug("bindAddress: " + addr);
channel.bindAddress(addr); if (debug) {Util.dumpAddresses(channel, out);}
check(boundAddress(channel, addr), "address is not bound");
} catch (IOException ioe) {
unexpected(ioe);
}
}
/* TEST 3: bind non local address */ try {
InetAddress nla = InetAddress.getByName("123.123.123.123");
debug("bind non local address " + nla);
channel.bindAddress(nla);
} catch (IOException ioe) {
debug("Informative only " + ioe);
}
/* TEST 4: unbind address that is not bound */ try {
debug("unbind address that is not bound " + againAddress); /* remove address first then again */
channel.unbindAddress(againAddress);
channel.unbindAddress(againAddress);
} catch (IllegalUnbindException unused) {
debug("Caught IllegalUnbindException - OK");
pass();
} catch (IOException ioe) {
unexpected(ioe);
}
/* TEST 5: unbind address that is not bound */ try {
InetAddress nla = InetAddress.getByName("123.123.123.123");
debug("unbind address that is not bound " + nla);
channel.unbindAddress(nla);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.