test/jdk/com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
author chegar
Thu, 21 Nov 2019 12:14:29 +0000
changeset 59205 afcc8af048e6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     1
/*
24037
49aa856e6f38 8039816: Some tests depend on internal API sun.security.action.GetPropertyAction
shurailine
parents: 14342
diff changeset
     2
 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     4
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     8
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    13
 * accompanied this code).
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    14
 *
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4675
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4675
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4675
diff changeset
    21
 * questions.
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    22
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    23
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    24
/* @test
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    25
 * @bug 4927640
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    26
 * @summary Tests the SCTP protocol implementation
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    27
 * @author chegar
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    28
 */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    29
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    30
import java.io.IOException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    31
import java.util.Set;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    32
import java.net.InetSocketAddress;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    33
import java.net.SocketAddress;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    34
import java.util.List;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    35
import java.util.Arrays;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    36
import java.util.Iterator;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    37
import java.nio.channels.ClosedChannelException;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    38
import com.sun.nio.sctp.SctpChannel;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    39
import com.sun.nio.sctp.SctpServerChannel;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    40
import com.sun.nio.sctp.SctpSocketOption;
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    41
import java.security.AccessController;
24037
49aa856e6f38 8039816: Some tests depend on internal API sun.security.action.GetPropertyAction
shurailine
parents: 14342
diff changeset
    42
import java.security.PrivilegedAction;
9679
d98ae8bc45fc 7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents: 7668
diff changeset
    43
import static com.sun.nio.sctp.SctpStandardSocketOptions.*;
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    44
import static java.lang.System.out;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    45
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    46
public class SocketOptionTests {
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    47
    final String osName = AccessController.doPrivileged(
24037
49aa856e6f38 8039816: Some tests depend on internal API sun.security.action.GetPropertyAction
shurailine
parents: 14342
diff changeset
    48
                    (PrivilegedAction<String>)() -> System.getProperty("os.name"));
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
    49
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    50
    <T> void checkOption(SctpChannel sc, SctpSocketOption<T> name,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    51
            T expectedValue) throws IOException {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    52
        T value = sc.getOption(name);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    53
        check(value.equals(expectedValue), name + ": value (" + value +
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    54
                ") not as expected (" + expectedValue + ")");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    55
       }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    56
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    57
    <T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    58
            T value) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    59
        try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    60
            sc.setOption(name, value);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    61
            checkOption(sc, name, value);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    62
        } catch (IOException e) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    63
            /* Informational only, not all options have native support */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    64
            out.println(name + " not supported. " + e);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    65
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    66
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    67
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    68
    void test(String[] args) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    69
        if (!Util.isSCTPSupported()) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    70
            out.println("SCTP protocol is not supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    71
            out.println("Test cannot be run");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    72
            return;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    73
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    74
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
    75
        try (SctpChannel sc = SctpChannel.open()) {
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    76
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    77
            /* check supported options */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    78
            Set<SctpSocketOption<?>> options = sc.supportedOptions();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    79
            List<? extends SctpSocketOption<?>> expected = Arrays.<SctpSocketOption<?>>asList(
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    80
                    SCTP_DISABLE_FRAGMENTS, SCTP_EXPLICIT_COMPLETE,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    81
                    SCTP_FRAGMENT_INTERLEAVE, SCTP_INIT_MAXSTREAMS,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    82
                    SCTP_NODELAY, SCTP_PRIMARY_ADDR, SCTP_SET_PEER_PRIMARY_ADDR,
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    83
                    SO_SNDBUF, SO_RCVBUF, SO_LINGER);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    84
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    85
            for (SctpSocketOption opt: expected) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    86
                if (!options.contains(opt))
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    87
                    fail(opt.name() + " should be supported");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    88
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    89
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    90
            InitMaxStreams streams = InitMaxStreams.create(1024, 1024);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    91
            sc.setOption(SCTP_INIT_MAXSTREAMS, streams);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    92
            checkOption(sc, SCTP_INIT_MAXSTREAMS, streams);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    93
            streams = sc.getOption(SCTP_INIT_MAXSTREAMS);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    94
            check(streams.maxInStreams() == 1024, "Max in streams: value: "
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    95
                    + streams.maxInStreams() + ", expected 1024 ");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    96
            check(streams.maxOutStreams() == 1024, "Max out streams: value: "
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    97
                    + streams.maxOutStreams() + ", expected 1024 ");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    98
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
    99
            optionalSupport(sc, SCTP_DISABLE_FRAGMENTS, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   100
            optionalSupport(sc, SCTP_EXPLICIT_COMPLETE, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   101
            optionalSupport(sc, SCTP_FRAGMENT_INTERLEAVE, 1);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   102
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   103
            sc.setOption(SCTP_NODELAY, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   104
            checkOption(sc, SCTP_NODELAY, true);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   105
            sc.setOption(SO_SNDBUF, 16*1024);
4675
68f287672813 6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents: 3072
diff changeset
   106
            checkOption(sc, SO_SNDBUF, 16*1024);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   107
            sc.setOption(SO_RCVBUF, 16*1024);
4675
68f287672813 6916922: (sctp) SO_RCVBUF & SO_SNDBUF returns twice the value set
chegar
parents: 3072
diff changeset
   108
            checkOption(sc, SO_RCVBUF, 16*1024);
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   109
            checkOption(sc, SO_LINGER, -1);  /* default should be negative */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   110
            sc.setOption(SO_LINGER, 2000);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   111
            checkOption(sc, SO_LINGER, 2000);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   112
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   113
            /* SCTP_PRIMARY_ADDR */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   114
            sctpPrimaryAddr();
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   115
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   116
            /* NullPointerException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   117
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   118
                sc.setOption(null, "value");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   119
                fail("NullPointerException not thrown for setOption");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   120
            } catch (NullPointerException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   121
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   122
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   123
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   124
               sc.getOption(null);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   125
               fail("NullPointerException not thrown for getOption");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   126
            } catch (NullPointerException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   127
               pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   128
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   129
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   130
            /* ClosedChannelException */
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   131
            sc.close();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   132
            try {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   133
               sc.setOption(SCTP_INIT_MAXSTREAMS, streams);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   134
               fail("ClosedChannelException not thrown");
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   135
            } catch (ClosedChannelException unused) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   136
                pass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   137
            }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   138
        } catch (IOException ioe) {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   139
            unexpected(ioe);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   140
        }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   141
    }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   142
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   143
    /* SCTP_PRIMARY_ADDR */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   144
    void sctpPrimaryAddr() throws IOException {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   145
        System.out.println("TESTING SCTP_PRIMARY_ADDR");
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   146
        SctpChannel sc = SctpChannel.open();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   147
        SctpServerChannel ssc = SctpServerChannel.open().bind(null);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   148
        Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   149
        if (addrs.isEmpty())
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   150
            debug("addrs should not be empty");
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   151
        debug("Listening on " + addrs);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   152
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   153
        InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   154
        debug("connecting to " + serverAddr);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   155
        sc.connect(serverAddr);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   156
        SctpChannel peerChannel = ssc.accept();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   157
        ssc.close();
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   158
        Set<SocketAddress> remoteAddresses = sc.getRemoteAddresses();
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   159
        debug("Remote Addresses: ");
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   160
        for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   161
            InetSocketAddress addr = (InetSocketAddress)it.next();
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   162
            debug("\t" + addr);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   163
        }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   164
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   165
        /* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   166
        if ("SunOS".equals(osName)) {
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   167
            /* For now do not set this option. There is a bug on Solaris 10 pre Update 5
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   168
             * where setting this option returns Invalid argument */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   169
            //debug("Set SCTP_PRIMARY_ADDR with " + addrToSet);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   170
            //sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   171
            return;
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   172
        } else { /* Linux */
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   173
            SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   174
            System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr);
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   175
            /* Verify that this is one of the remote addresses */
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   176
            check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!");
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   177
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   178
            for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) {
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   179
                InetSocketAddress addrToSet = (InetSocketAddress) it.next();
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   180
                System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet);
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   181
                sc.setOption(SCTP_PRIMARY_ADDR, addrToSet);
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   182
                System.out.println("SCTP_PRIMARY_ADDR set to    : " + addrToSet);
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   183
                primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR);
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   184
                System.out.println("SCTP_PRIMARY_ADDR returned  : " + primaryAddr);
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   185
                check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly");
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   186
            }
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   187
        }
59205
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   188
        sc.close();
afcc8af048e6 8233847: (sctp) Flx link-local IPv6 scope handling and test cleanup
chegar
parents: 47216
diff changeset
   189
        peerChannel.close();
3072
a801b122142f 6855335: Several changes in the SCTP implementation.
chegar
parents: 2542
diff changeset
   190
    }
2542
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   191
            //--------------------- Infrastructure ---------------------------
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   192
    boolean debug = true;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   193
    volatile int passed = 0, failed = 0;
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   194
    void pass() {passed++;}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   195
    void fail() {failed++; Thread.dumpStack();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   196
    void fail(String msg) {System.err.println(msg); fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   197
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   198
    void check(boolean cond) {if (cond) pass(); else fail();}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   199
    void check(boolean cond, String failMessage) {if (cond) pass(); else fail(failMessage);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   200
    void debug(String message) {if(debug) { System.out.println(message); }  }
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   201
    public static void main(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   202
        Class<?> k = new Object(){}.getClass().getEnclosingClass();
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   203
        try {k.getMethod("instanceMain",String[].class)
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   204
                .invoke( k.newInstance(), (Object) args);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   205
        catch (Throwable e) {throw e.getCause();}}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   206
    public void instanceMain(String[] args) throws Throwable {
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   207
        try {test(args);} catch (Throwable t) {unexpected(t);}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   208
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   209
        if (failed > 0) throw new AssertionError("Some tests failed");}
d859108aea12 4927640: Implementation of the sctp protocol
chegar
parents:
diff changeset
   210
}