70 out.println("SCTP protocol is not supported"); |
70 out.println("SCTP protocol is not supported"); |
71 out.println("Test cannot be run"); |
71 out.println("Test cannot be run"); |
72 return; |
72 return; |
73 } |
73 } |
74 |
74 |
75 try { |
75 try (SctpChannel sc = SctpChannel.open()) { |
76 SctpChannel sc = SctpChannel.open(); |
|
77 |
76 |
78 /* check supported options */ |
77 /* check supported options */ |
79 Set<SctpSocketOption<?>> options = sc.supportedOptions(); |
78 Set<SctpSocketOption<?>> options = sc.supportedOptions(); |
80 List<? extends SctpSocketOption<?>> expected = Arrays.<SctpSocketOption<?>>asList( |
79 List<? extends SctpSocketOption<?>> expected = Arrays.<SctpSocketOption<?>>asList( |
81 SCTP_DISABLE_FRAGMENTS, SCTP_EXPLICIT_COMPLETE, |
80 SCTP_DISABLE_FRAGMENTS, SCTP_EXPLICIT_COMPLETE, |
141 } |
140 } |
142 } |
141 } |
143 |
142 |
144 /* SCTP_PRIMARY_ADDR */ |
143 /* SCTP_PRIMARY_ADDR */ |
145 void sctpPrimaryAddr() throws IOException { |
144 void sctpPrimaryAddr() throws IOException { |
146 SocketAddress addrToSet = null;; |
|
147 |
|
148 System.out.println("TESTING SCTP_PRIMARY_ADDR"); |
145 System.out.println("TESTING SCTP_PRIMARY_ADDR"); |
149 SctpChannel sc = SctpChannel.open(); |
146 SctpChannel sc = SctpChannel.open(); |
150 SctpServerChannel ssc = SctpServerChannel.open().bind(null); |
147 SctpServerChannel ssc = SctpServerChannel.open().bind(null); |
151 Set<SocketAddress> addrs = ssc.getAllLocalAddresses(); |
148 Set<SocketAddress> addrs = ssc.getAllLocalAddresses(); |
152 if (addrs.isEmpty()) |
149 if (addrs.isEmpty()) |
156 InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next(); |
153 InetSocketAddress serverAddr = (InetSocketAddress) addrs.iterator().next(); |
157 debug("connecting to " + serverAddr); |
154 debug("connecting to " + serverAddr); |
158 sc.connect(serverAddr); |
155 sc.connect(serverAddr); |
159 SctpChannel peerChannel = ssc.accept(); |
156 SctpChannel peerChannel = ssc.accept(); |
160 ssc.close(); |
157 ssc.close(); |
161 Set<SocketAddress> peerAddrs = peerChannel.getAllLocalAddresses(); |
158 Set<SocketAddress> remoteAddresses = sc.getRemoteAddresses(); |
162 debug("Peer local Addresses: "); |
159 debug("Remote Addresses: "); |
163 for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) { |
160 for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) { |
164 InetSocketAddress addr = (InetSocketAddress)it.next(); |
161 InetSocketAddress addr = (InetSocketAddress)it.next(); |
165 debug("\t" + addr); |
162 debug("\t" + addr); |
166 addrToSet = addr; // any of the peer addresses will do! |
|
167 } |
163 } |
168 |
164 |
169 /* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */ |
165 /* retrieval of SCTP_PRIMARY_ADDR is not supported on Solaris */ |
170 if ("SunOS".equals(osName)) { |
166 if ("SunOS".equals(osName)) { |
171 /* For now do not set this option. There is a bug on Solaris 10 pre Update 5 |
167 /* For now do not set this option. There is a bug on Solaris 10 pre Update 5 |
174 //sc.setOption(SCTP_PRIMARY_ADDR, addrToSet); |
170 //sc.setOption(SCTP_PRIMARY_ADDR, addrToSet); |
175 return; |
171 return; |
176 } else { /* Linux */ |
172 } else { /* Linux */ |
177 SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR); |
173 SocketAddress primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR); |
178 System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr); |
174 System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr); |
179 /* Verify that this is one of the peer addresses */ |
175 /* Verify that this is one of the remote addresses */ |
180 boolean found = false; |
176 check(remoteAddresses.contains(primaryAddr), "SCTP_PRIMARY_ADDR returned bogus address!"); |
181 addrToSet = primaryAddr; // may not have more than one addr |
177 |
182 for (Iterator<SocketAddress> it = peerAddrs.iterator(); it.hasNext(); ) { |
178 for (Iterator<SocketAddress> it = remoteAddresses.iterator(); it.hasNext(); ) { |
183 InetSocketAddress addr = (InetSocketAddress)it.next(); |
179 InetSocketAddress addrToSet = (InetSocketAddress) it.next(); |
184 if (addr.equals(primaryAddr)) { |
180 System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet); |
185 found = true; |
181 sc.setOption(SCTP_PRIMARY_ADDR, addrToSet); |
186 } |
182 System.out.println("SCTP_PRIMARY_ADDR set to : " + addrToSet); |
187 addrToSet = addr; |
183 primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR); |
188 } |
184 System.out.println("SCTP_PRIMARY_ADDR returned : " + primaryAddr); |
189 check(found, "SCTP_PRIMARY_ADDR returned bogus address!"); |
185 check(addrToSet.equals(primaryAddr), "SCTP_PRIMARY_ADDR not set correctly"); |
190 |
186 } |
191 System.out.println("SCTP_PRIMARY_ADDR try set to: " + addrToSet); |
187 } |
192 sc.setOption(SCTP_PRIMARY_ADDR, addrToSet); |
188 sc.close(); |
193 System.out.println("SCTP_PRIMARY_ADDR set to: " + addrToSet); |
189 peerChannel.close(); |
194 primaryAddr = sc.getOption(SCTP_PRIMARY_ADDR); |
|
195 System.out.println("SCTP_PRIMARY_ADDR returned: " + primaryAddr); |
|
196 check(addrToSet.equals(primaryAddr),"SCTP_PRIMARY_ADDR not set correctly"); |
|
197 } |
|
198 } |
190 } |
199 //--------------------- Infrastructure --------------------------- |
191 //--------------------- Infrastructure --------------------------- |
200 boolean debug = true; |
192 boolean debug = true; |
201 volatile int passed = 0, failed = 0; |
193 volatile int passed = 0, failed = 0; |
202 void pass() {passed++;} |
194 void pass() {passed++;} |