Add MPTCP support to Java Networking API
Geliang Tang
reviewercover Add MPTCP support to Java Networking API
The Multipath TCP (MPTCP) protocol (v1 / RFC 8684) has been added in the upstream Linux kernel since v5.6.
This patch series introduces comprehensive Multipath TCP (MPTCP) support to the Java Networking API, enabling applications to leverage MPTCP's capabilities for improved reliability and throughput.
The implementation provides:
1. Core infrastructure for MPTCP socket creation (Patch 1)
2. Server and client socket creation APIs (Patches 2-3)
3. Integration with NIO socket implementation (Patch 4)
4. High-level Socket and ServerSocket support (Patches 5-6)
5. Comprehensive test cases (Patch 7)
Key features:
- Backward compatible API extensions
- Platform-independent implementation
- Explicit MPTCP enablement through new constructors
- Full integration with existing socket functionality
- Test coverage for basic MPTCP operations
The changes maintain all existing functionality while adding MPTCP capabilities. When MPTCP is not enabled or not supported by the system, the implementation gracefully falls back to regular TCP behavior.
This work enables Java applications to benefit from MPTCP's capabilities:
- Seamless handover between network interfaces
- Aggregated bandwidth from multiple paths
- Improved resilience to network failures
The implementation has been tested on Linux systems with MPTCP kernel support enabled.
https://github.com/openjdk/jdk
Geliang Tang (7):
Add MPTCP support for socket creation
Add MPTCP server socket creation support
Add MPTCP client socket creation support
Add MPTCP support to NioSocketImpl
Add MPTCP support to ServerSocket class
Add MPTCP support to Socket class
Add test cases for MPTCP socket functionality
.../share/classes/java/net/ServerSocket.java | 66 ++++++++++++++ .../share/classes/java/net/Socket.java | 88 +++++++++++++++++++ .../share/classes/java/net/SocketImpl.java | 8 ++ .../share/classes/sun/nio/ch/Net.java | 26 +++++- .../classes/sun/nio/ch/NioSocketImpl.java | 19 +++- src/java.base/unix/native/libnio/ch/Net.c | 5 +- src/java.base/windows/native/libnio/ch/Net.c | 2 +- .../java/net/ServerSocket/MPTCPServer.java | 58 ++++++++++++ test/jdk/java/net/Socket/MPTCPClient.java | 62 +++++++++++++ 9 files changed, 326 insertions(+), 8 deletions(-) create mode 100644 test/jdk/java/net/ServerSocket/MPTCPServer.java create mode 100644 test/jdk/java/net/Socket/MPTCPClient.java
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 1/7 Add MPTCP support for socket creation
This patch extends the socket creation functionality to support Multipath TCP (MPTCP) by adding a new 'mptcp' parameter to the native socket0 method. When enabled, the socket will be created with the IPPROTO_MPTCP protocol for stream sockets.
The changes include:
1. Added the 'mptcp' parameter to socket0 method declarations in Net.java
2. Modified the native implementations in both Unix and Windows Net.c files to handle the new parameter and set the appropriate protocol
3. Updated all call sites to pass 'false' for the new parameter to maintain existing behavior (MPTCP disabled by default)
--- src/java.base/share/classes/sun/nio/ch/Net.java | 6 +++--- src/java.base/unix/native/libnio/ch/Net.c | 5 +++-- src/java.base/windows/native/libnio/ch/Net.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)
src/java.base/share/classes/sun/nio/ch/Net.java +3 -3
@@ -488,7 +488,7 @@ static FileDescriptor socket() throws IOException { static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK)); + return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, false)); } static FileDescriptor serverSocket() {
@@ -498,12 +498,12 @@ static FileDescriptor serverSocket() { static FileDescriptor serverSocket(ProtocolFamily family) { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK)); + return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false)); } // Due to oddities SO_REUSEADDR on Windows reuse is ignored private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, - boolean fastLoopback); + boolean fastLoopback, boolean mptcp); public static void bind(FileDescriptor fd, InetAddress addr, int port) throws IOException
src/java.base/unix/native/libnio/ch/Net.c +3 -2
@@ -255,13 +255,14 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c JNIEXPORT jint JNICALLJava_sun_nio_ch_Net_socket0 (JNIEnv *env,jclass cl,jboolean preferIPv6, -jboolean stream,jboolean reuse,jboolean ignored) +jboolean stream,jboolean reuse,jboolean ignored,jboolean mptcp) {int fd;int type = (stream ?SOCK_STREAM :SOCK_DGRAM );int domain = (ipv6_available () && preferIPv6) ?AF_INET6 :AF_INET ; +int protocol = (stream && mptcp) ?IPPROTO_MPTCP :0 ; - fd =socket (domain, type,0 ); + fd =socket (domain, type, protocol);if (fd <0 ) {return handleSocketError (env, errno); }
src/java.base/windows/native/libnio/ch/Net.c +1 -1
@@ -152,7 +152,7 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c JNIEXPORT jint JNICALLJava_sun_nio_ch_Net_socket0 (JNIEnv *env,jclass cl,jboolean preferIPv6, -jboolean stream,jboolean reuse,jboolean fastLoopback) +jboolean stream,jboolean reuse,jboolean fastLoopback,jboolean mptcp) {SOCKET s;int domain = (preferIPv6) ?AF_INET6 :AF_INET ;
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 2/7 Add MPTCP server socket creation support
In reply to Geliang TangThis patch introduces new methods to create server sockets with Multipath TCP (MPTCP) support:
1. Added an overloaded 'serverSocket' method that accepts an 'mptcp' parameter to enable MPTCP
2. Added a convenience method 'mptcpServerSocket()' for creating MPTCP-enabled server sockets using the unspecified protocol family by default
The changes maintain backward compatibility while providing explicit MPTCP support for server socket creation. The new methods leverage the existing socket0 infrastructure with the MPTCP flag added in the previous patch.
--- src/java.base/share/classes/sun/nio/ch/Net.java | 10 ++++++++++ 1 file changed, 10 insertions(+)
src/java.base/share/classes/sun/nio/ch/Net.java +10 -0
@@ -501,6 +501,16 @@ static FileDescriptor serverSocket(ProtocolFamily family) { return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false)); } + static FileDescriptor serverSocket(ProtocolFamily family, boolean mptcp) { + boolean preferIPv6 = isIPv6Available() && + (family != StandardProtocolFamily.INET); + return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, mptcp)); + } + + static FileDescriptor mptcpServerSocket() { + return serverSocket(UNSPEC, true); + } + // Due to oddities SO_REUSEADDR on Windows reuse is ignored private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, boolean fastLoopback, boolean mptcp);
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 3/7 Add MPTCP client socket creation support
In reply to Geliang TangThis patch extends the socket creation API to support Multipath TCP (MPTCP) for client sockets:
1. Added an overloaded 'socket' method that accepts an 'mptcp' parameter to explicitly enable/disable MPTCP
2. Introduced a convenience method 'mptcpSocket()' for creating MPTCP-enabled client sockets using the unspecified protocol family by default
The changes maintain consistency with the existing socket API while providing first-class support for MPTCP client sockets. The implementation builds upon the foundation laid in previous patches, utilizing the socket0 infrastructure with MPTCP protocol support.
--- src/java.base/share/classes/sun/nio/ch/Net.java | 10 ++++++++++ 1 file changed, 10 insertions(+)
src/java.base/share/classes/sun/nio/ch/Net.java +10 -0
@@ -491,6 +491,16 @@ static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOExc return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, false)); } + static FileDescriptor socket(ProtocolFamily family, boolean stream, boolean mptcp) throws IOException { + boolean preferIPv6 = isIPv6Available() && + (family != StandardProtocolFamily.INET); + return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, mptcp)); + } + + static FileDescriptor mptcpSocket() throws IOException { + return socket(UNSPEC, true, true); + } + static FileDescriptor serverSocket() { return serverSocket(UNSPEC); }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 4/7 Add MPTCP support to NioSocketImpl
In reply to Geliang TangThis patch integrates MPTCP support into the core socket implementation by:
1. Adding a new createPlatformSocketImpl factory method that accepts an mptcp parameter
2. Extending NioSocketImpl to track MPTCP state with a new mptcp field
3. Modifying socket creation logic to use the appropriate MPTCP-enabled methods:
- Uses Net.mptcpServerSocket() for server sockets when MPTCP is enabled
- Uses Net.mptcpSocket() for client sockets when MPTCP is enabled
The changes maintain backward compatibility while adding first-class MPTCP support to the socket implementation layer. The implementation builds upon the MPTCP infrastructure added in previous patches.
--- .../share/classes/java/net/SocketImpl.java | 8 ++++++++ .../classes/sun/nio/ch/NioSocketImpl.java | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
src/java.base/share/classes/java/net/SocketImpl.java +8 -0
@@ -52,6 +52,14 @@ static <S extends SocketImpl & PlatformSocketImpl> S createPlatformSocketImpl(bo return (S) new NioSocketImpl(server); } + /** + * Creates an instance of platform's SocketImpl + */ + @SuppressWarnings("unchecked") + static <S extends SocketImpl & PlatformSocketImpl> S createPlatformSocketImpl(boolean server, boolean mptcp) { + return (S) new NioSocketImpl(server, mptcp); + } + /** * The file descriptor object for this socket. */
src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java +17 -2
@@ -86,6 +86,9 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp // true if this is a SocketImpl for a ServerSocket private final boolean server; + // true if this is a SocketImpl for a MptcpServerSocket + private final boolean mptcp; + // Lock held when reading (also used when accepting or connecting) private final ReentrantLock readLock = new ReentrantLock();
@@ -131,6 +134,18 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp */ public NioSocketImpl(boolean server) { this.server = server; + this.mptcp = false; + } + + /** + * @param mptcp enable MPTCP + * + * Creates an instance of this SocketImpl. + * @param server true if this is a SocketImpl for a ServerSocket + */ + public NioSocketImpl(boolean server, boolean mptcp) { + this.server = server; + this.mptcp = mptcp; } /**
@@ -468,9 +483,9 @@ protected void create(boolean stream) throws IOException { throw new IOException("Already created"); FileDescriptor fd; if (server) { - fd = Net.serverSocket(); + fd = mptcp ? Net.mptcpServerSocket() : Net.serverSocket(); } else { - fd = Net.socket(); + fd = mptcp ? Net.mptcpSocket() : Net.socket(); } Runnable closer = closerFor(fd); this.fd = fd;
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 5/7 Add MPTCP support to ServerSocket class
In reply to Geliang TangThis patch extends ServerSocket to support Multipath TCP (MPTCP) by:
1. Adding a new constructor that accepts an mptcp parameter to enable MPTCP
2. Introducing a new createImpl factory method that propagates the MPTCP setting to the underlying socket implementation
3. Maintaining all existing functionality while adding MPTCP capabilities
The new constructor follows the same pattern as existing ServerSocket constructors but adds the mptcp parameter to control protocol selection. When enabled, the implementation uses the MPTCP-enabled socket creation path established in previous patches.
--- .../share/classes/java/net/ServerSocket.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+)
src/java.base/share/classes/java/net/ServerSocket.java +66 -0
@@ -226,6 +226,57 @@ public ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOExcept } } + /** + * Create a server using <i>mptcp</i> (Multipath TCP) or TCP protocol with + * the specified port, listen backlog, and local IP address to bind to. + * The <i>bindAddr</i> argument can be used on a multi-homed host for a + * ServerSocket that will only accept connect requests to one of its addresses. + * If <i>bindAddr</i> is null, it will default accepting + * connections on any/all local addresses. + * The port must be between 0 and 65535, inclusive. + * A port number of {@code 0} means that the port number is + * automatically allocated, typically from an ephemeral port range. + * This port number can then be retrieved by calling + * {@link #getLocalPort getLocalPort}. + * + * The {@code backlog} argument is the requested maximum number of + * pending connections on the socket. Its exact semantics are implementation + * specific. In particular, an implementation may impose a maximum length + * or may choose to ignore the parameter altogether. The value provided + * should be greater than {@code 0}. If it is less than or equal to + * {@code 0}, then an implementation specific default will be used. + * + * The {@code mptcp} argument is used to control whether to create a socket + * with MPTCP or TCP protocol. + * + * @param port the port number, or {@code 0} to use a port + * number that is automatically allocated. + * @param backlog requested maximum length of the queue of incoming + * connections. + * @param bindAddr the local InetAddress the server will bind to + * @param mptcp create a socket with MPTCP or TCP protocol. + * + * @throws IOException if an I/O error occurs when opening the socket. + * @throws IllegalArgumentException if the port parameter is outside + * the specified range of valid port values, which is between + * 0 and 65535, inclusive. + */ + @SuppressWarnings("this-escape") + public ServerSocket(int port, int backlog, InetAddress bindAddr, boolean mptcp) throws IOException { + if (port < 0 || port > 0xFFFF) + throw new IllegalArgumentException("Port value out of range: " + port); + if (backlog < 1) + backlog = 50; + + this.impl = createImpl(mptcp); + try { + bind(new InetSocketAddress(bindAddr, port), backlog); + } catch (IOException e) { + close(); + throw e; + } + } + /** * Create a SocketImpl for a server socket. The SocketImpl is created * without an underlying socket.
@@ -239,6 +290,21 @@ private static SocketImpl createImpl() { } } + /** + * Create a SocketImpl for a server socket. The SocketImpl is created + * without an underlying socket. + * + * @param mptcp create a socket with MPTCP or TCP protocol. + */ + private static SocketImpl createImpl(boolean mptcp) { + SocketImplFactory factory = ServerSocket.factory; + if (factory != null) { + return factory.createSocketImpl(); + } else { + return SocketImpl.createPlatformSocketImpl(true, mptcp); + } + } + /** * Returns the {@code SocketImpl} for this ServerSocket, creating the * underlying socket if required.
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 6/7 Add MPTCP support to Socket class
In reply to Geliang TangThis patch extends the Socket class to support Multipath TCP (MPTCP) by:
1. Adding a new constructor that accepts an mptcp parameter to enable MPTCP
2. Introducing a new private Socket constructor variant that handles MPTCP connections
3. Adding a createImpl factory method that propagates the MPTCP setting to the underlying socket implementation
4. Maintaining backward compatibility while adding MPTCP capabilities
The implementation ensures MPTCP support is properly integrated with:
- Address resolution
- Socket binding
- Connection establishment
- Error handling
When MPTCP is enabled, the socket uses the MPTCP-enabled creation path established in previous patches, while maintaining all existing socket functionality for non-MPTCP cases.
--- .../share/classes/java/net/Socket.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+)
src/java.base/share/classes/java/net/Socket.java +88 -0
@@ -403,6 +403,39 @@ public Socket(String host, int port, boolean stream) throws IOException { (SocketAddress) null, stream); } + /** + * Creates a stream socket and connects it to the specified port + * number on the named host using Multipath TCP (MPTCP) or TCP + * protocol. + * <p> + * If the specified host is {@code null} it is the equivalent of + * specifying the address as + * {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}. + * In other words, it is equivalent to specifying an address of the + * loopback interface. </p> + * <p> + * If the application has specified a {@linkplain SocketImplFactory client + * socket implementation factory}, that factory's + * {@linkplain SocketImplFactory#createSocketImpl() createSocketImpl} + * method is called to create the actual socket implementation. Otherwise + * a system-default socket implementation is created. + * + * @param host the host name, or {@code null} for the loopback address. + * @param port the port number. + * @param stream must be true, false is not allowed. + * @param mptcp create a socket with MPTCP or TCP protocol. + * @throws IOException if an I/O error occurs when creating the socket. + * @throws IllegalArgumentException if the stream parameter is {@code false} + * or if the port parameter is outside the specified range of valid + * port values, which is between 0 and 65535, inclusive. + */ + @SuppressWarnings("this-escape") + public Socket(String host, int port, boolean stream, boolean mptcp) throws IOException { + this(host != null ? new InetSocketAddress(host, port) : + new InetSocketAddress(InetAddress.getByName(null), port), + (SocketAddress) null, stream, mptcp); + } + /** * Creates a socket and connects it to the specified port number at * the specified IP address.
@@ -483,6 +516,61 @@ private static SocketImpl createImpl() { } } + /** + * Initialize a new Socket that is connected to the given remote address. + * The MPTCP or TCP protocol socket is optionally bound to a local address + * before connecting. + * + * @param address the remote address to connect to + * @param localAddr the local address to bind to, can be null + * @param stream true for a stream socket, false for a datagram socket + * @param mptcp create a socket with MPTCP or TCP protocol + */ + private Socket(SocketAddress address, SocketAddress localAddr, boolean stream, boolean mptcp) + throws IOException + { + Objects.requireNonNull(address); + if (!stream) { + throw new IllegalArgumentException( + "Socket constructor does not support creation of datagram sockets"); + } + assert address instanceof InetSocketAddress; + + // create the SocketImpl and the underlying socket + SocketImpl impl = createImpl(mptcp); + impl.create(stream); + + this.impl = impl; + this.state = SOCKET_CREATED; + + try { + if (localAddr != null) { + bind(localAddr); + } + connect(address); + } catch (Throwable throwable) { + closeSuppressingExceptions(throwable); + throw throwable; + } + } + + /** + * Create a new SocketImpl for a connecting/client socket. The SocketImpl + * is created without an underlying socket. + * + * @param mptcp create a socket with MPTCP or TCP protocol. + */ + private static SocketImpl createImpl(boolean mptcp) { + SocketImplFactory factory = Socket.factory; + if (factory != null) { + return factory.createSocketImpl(); + } else { + // create a SOCKS SocketImpl that delegates to a platform SocketImpl + SocketImpl delegate = SocketImpl.createPlatformSocketImpl(false, mptcp); + return new SocksSocketImpl(delegate); + } + } + /** * Returns the {@code SocketImpl} for this Socket, creating it, and the * underlying socket, if required.
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH 7/7 Add test cases for MPTCP socket functionality
In reply to Geliang TangThis patch introduces comprehensive test coverage for the newly added MPTCP socket support by:
1. Adding MPTCPServer.java - A test server that:
- Creates an MPTCP-enabled ServerSocket
- Accepts client connections
- Echoes received messages back to clients
- Handles graceful shutdown
2. Adding MPTCPClient.java - A test client that:
- Connects to the MPTCP server
- Sends user input to server
- Displays server responses
- Supports graceful termination
The tests verify:
- Basic MPTCP socket creation and connection
- Bidirectional communication
- Proper stream handling
- Error conditions
- Clean resource management
Both test programs demonstrate the usage of the new MPTCP-enabled constructors added in previous patches.
--- .../java/net/ServerSocket/MPTCPServer.java | 58 +++++++++++++++++ test/jdk/java/net/Socket/MPTCPClient.java | 62 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 test/jdk/java/net/ServerSocket/MPTCPServer.java create mode 100644 test/jdk/java/net/Socket/MPTCPClient.java
test/jdk/java/net/ServerSocket/MPTCPServer.java new file +58 -0
@@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025, 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. + */ + +import java.io.*; +import java.net.*; + +public class MPTCPServer { + public static void main(String[] args) { + final int PORT = 12345; + + try (ServerSocket serverSocket = new ServerSocket(PORT, 50, null, true)) { + System.out.println("Server started, waiting for client connection ..."); + + Socket clientSocket = serverSocket.accept(); + System.out.println("Client connected: " + clientSocket.getInetAddress()); + + BufferedReader in = new BufferedReader( + new InputStreamReader(clientSocket.getInputStream())); + PrintWriter out = new PrintWriter( + clientSocket.getOutputStream(), true); + + String inputLine; + while ((inputLine = in.readLine()) != null) { + System.out.println("Received from client: " + inputLine); + out.println("Server response: " + inputLine); + + if ("exit".equalsIgnoreCase(inputLine)) { + break; + } + } + + clientSocket.close(); + System.out.println("Connection closed"); + } catch (IOException e) { + System.err.println("Server exception: " + e.getMessage()); + } + } +}
test/jdk/java/net/Socket/MPTCPClient.java new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.48.1
Matthieu Baerts
maintainerHi Geliang,
Quoted 6 lines · Geliang Tang
The Multipath TCP (MPTCP) protocol (v1 / RFC 8684) has been added in the upstream Linux kernel since v5.6.
This patch series introduces comprehensive Multipath TCP (MPTCP) support to the Java Networking API, enabling applications to leverage MPTCP's capabilities for improved reliability and throughput.
Thank you for having looked at that.
Quoted 14 lines
The implementation provides:
1. Core infrastructure for MPTCP socket creation (Patch 1)
2. Server and client socket creation APIs (Patches 2-3)
3. Integration with NIO socket implementation (Patch 4)
4. High-level Socket and ServerSocket support (Patches 5-6)
5. Comprehensive test cases (Patch 7)Key features:
- Backward compatible API extensions
- Platform-independent implementation
- Explicit MPTCP enablement through new constructors
- Full integration with existing socket functionality
- Test coverage for basic MPTCP operations
Quoted 3 lines
The changes maintain all existing functionality while adding MPTCP capabilities. When MPTCP is not enabled or not supported by the system, the implementation gracefully falls back to regular TCP behavior.
I don't think it is the case: if the system doesn't support it, an error will be returned.
If the other host doesn't support it or didn't request it, a fallback will be done.
Also, don't hesitate to share a link to https://mptcp.dev to help reviewers understanding what MPTCP is.
Quoted 9 lines
This work enables Java applications to benefit from MPTCP's capabilities:
- Seamless handover between network interfaces
- Aggregated bandwidth from multiple paths
- Improved resilience to network failuresThe implementation has been tested on Linux systems with MPTCP kernel support enabled.
I have a few comments, but I don't know the project, and I didn't code in Java for a while. Then, feel free to send this version or an updated one to the Java Net maintainers (not sure how, but I'm sure you will figure out :) ). Do not hesitate to share the link here.
Quoted 9 lines
Geliang Tang (7):
Add MPTCP support for socket creation
Add MPTCP server socket creation support
Add MPTCP client socket creation support
Add MPTCP support to NioSocketImpl
Add MPTCP support to ServerSocket class
Add MPTCP support to Socket class
Add test cases for MPTCP socket functionality
Quoted 13 lines
.../share/classes/java/net/ServerSocket.java | 66 ++++++++++++++ .../share/classes/java/net/Socket.java | 88 +++++++++++++++++++ .../share/classes/java/net/SocketImpl.java | 8 ++ .../share/classes/sun/nio/ch/Net.java | 26 +++++- .../classes/sun/nio/ch/NioSocketImpl.java | 19 +++- src/java.base/unix/native/libnio/ch/Net.c | 5 +- src/java.base/windows/native/libnio/ch/Net.c | 2 +- .../java/net/ServerSocket/MPTCPServer.java | 58 ++++++++++++ test/jdk/java/net/Socket/MPTCPClient.java | 62 +++++++++++++ 9 files changed, 326 insertions(+), 8 deletions(-) create mode 100644 test/jdk/java/net/ServerSocket/MPTCPServer.java create mode 100644 test/jdk/java/net/Socket/MPTCPClient.java
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 1/7] Add MPTCP support for socket creation
In reply to Geliang TangHi Geliang,
Quoted 54 lines · Geliang Tang
This patch extends the socket creation functionality to support Multipath TCP (MPTCP) by adding a new 'mptcp' parameter to the native socket0 method. When enabled, the socket will be created with the
IPPROTO_MPTCPprotocol for stream sockets.The changes include:
1. Added the 'mptcp' parameter to socket0 method declarations in Net.java
2. Modified the native implementations in both Unix and WindowsNet.cfiles to handle the new parameter and set the appropriate protocol
3. Updated all call sites to pass 'false' for the new parameter to maintain existing behavior (MPTCP disabled by default)Co-Developed-by Gang Yan <[email protected]>Signed-off-by Gang Yan <[email protected]>Signed-off-by Geliang Tang <[email protected]>--- src/java.base/share/classes/sun/nio/ch/Net.java | 6 +++--- src/java.base/unix/native/libnio/ch/Net.c | 5 +++-- src/java.base/windows/native/libnio/ch/Net.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)src/java.base/share/classes/sun/nio/ch/Net.java +3
-3@@ -488,7 +488,7 @@ static FileDescriptor socket() throws IOException { static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK)); + return IOUtil.newFD(socket0(preferIPv6, stream, false, FAST_LOOPBACK, false)); } static FileDescriptor serverSocket() {@@ -498,12 +498,12 @@ static FileDescriptor serverSocket() { static FileDescriptor serverSocket(ProtocolFamily family) { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); - return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK)); + return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false)); } // Due to oddities SO_REUSEADDR on Windows reuse is ignored private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, - boolean fastLoopback); + boolean fastLoopback, boolean mptcp); public static void bind(FileDescriptor fd, InetAddress addr, int port) throws IOExceptionsrc/java.base/unix/native/libnio/ch/Net.c +0
-0
src/java.base/unix/native/libnio/ch/Net.c Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c · line 258
Quoted 5 lines
src/java.base/unix/native/libnio/ch/Net.c +1
-1@@ -255,13 +255,14 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c JNIEXPORT jint JNICALLJava_sun_nio_ch_Net_socket0 (JNIEnv *env,jclass cl,jboolean preferIPv6, -jboolean stream,jboolean reuse,jboolean ignored) +jboolean stream,jboolean reuse,jboolean ignored,jboolean mptcp)
(I don't know if there is a limit for the number of chars per lines, maybe you need to go to the next line?)
src/java.base/unix/native/libnio/ch/Net.c Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c · line 263
Quoted 5 lines
src/java.base/unix/native/libnio/ch/Net.c +1
-0{int fd;int type = (stream ?SOCK_STREAM :SOCK_DGRAM );int domain = (ipv6_available () && preferIPv6) ?AF_INET6 :AF_INET ; +int protocol = (stream && mptcp) ?IPPROTO_MPTCP :0 ;
I guess you will still need to check if IPPROTO_MPTCP is defined for old systems, or the ones not using Linux. Something like that:
int protocol =
#ifdef IPPROTO_MPTCP
(stream && mptcp) ? IPPROTO_MPTCP :
#endif
0;(or another style, I don't know what is usually being used here.)
Quoted 11 lines
src/java.base/unix/native/libnio/ch/Net.c +1
-1- fd =socket (domain, type,0 ); + fd =socket (domain, type, protocol);if (fd <0 ) {return handleSocketError (env, errno); }src/java.base/windows/native/libnio/ch/Net.c +0
-0
src/java.base/windows/native/libnio/ch/Net.c Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c · line 158
Quoted 8 lines
src/java.base/windows/native/libnio/ch/Net.c +1
-1@@ -152,7 +152,7 @@ Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass c JNIEXPORT jint JNICALLJava_sun_nio_ch_Net_socket0 (JNIEnv *env,jclass cl,jboolean preferIPv6, -jboolean stream,jboolean reuse,jboolean fastLoopback) +jboolean stream,jboolean reuse,jboolean fastLoopback,jboolean mptcp) {SOCKET s;int domain = (preferIPv6) ?AF_INET6 :AF_INET ;
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 2/7] Add MPTCP server socket creation support
In reply to Geliang TangHi Geliang,
Quoted 25 lines · Geliang Tang
This patch introduces new methods to create server sockets with Multipath TCP (MPTCP) support:
1. Added an overloaded 'serverSocket' method that accepts an 'mptcp' parameter to enable MPTCP
2. Added a convenience method 'mptcpServerSocket()' for creating MPTCP-enabled server sockets using the unspecified protocol family by defaultThe changes maintain backward compatibility while providing explicit MPTCP support for server socket creation. The new methods leverage the existing socket0 infrastructure with the MPTCP flag added in the previous patch.
Co-Developed-by Gang Yan <[email protected]>Signed-off-by Gang Yan <[email protected]>Signed-off-by Geliang Tang <[email protected]>--- src/java.base/share/classes/sun/nio/ch/Net.java | 10 ++++++++++ 1 file changed, 10 insertions(+)src/java.base/share/classes/sun/nio/ch/Net.java +0
-0
src/java.base/share/classes/sun/nio/ch/Net.java static FileDescriptor serverSocket(ProtocolFamily family) { · line 510
Quoted 10 lines
src/java.base/share/classes/sun/nio/ch/Net.java +7
-0@@ -501,6 +501,16 @@ static FileDescriptor serverSocket(ProtocolFamily family) { return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, false)); } + static FileDescriptor serverSocket(ProtocolFamily family, boolean mptcp) { + boolean preferIPv6 = isIPv6Available() && + (family != StandardProtocolFamily.INET); + return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK, mptcp)); + } + + static FileDescriptor mptcpServerSocket() {
I didn't check what is usually being done, but is this new helper really needed? Is it not enough with the new serverSocket() extension?
Also, could you not have serverSocket(ProtocolFamily family) calling the new serverSocket(family, false) instead of duplicating the code above?
src/java.base/share/classes/sun/nio/ch/Net.java static FileDescriptor serverSocket(ProtocolFamily family) { · line 516
Quoted 6 lines
src/java.base/share/classes/sun/nio/ch/Net.java +3
-0+ return serverSocket(UNSPEC, true); + } + // Due to oddities SO_REUSEADDR on Windows reuse is ignored private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, boolean fastLoopback, boolean mptcp);
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 5/7] Add MPTCP support to ServerSocket class
In reply to Geliang TangHi Geliang,
Quoted 8 lines · Geliang Tang
This patch extends ServerSocket to support Multipath TCP (MPTCP) by:
1. Adding a new constructor that accepts an mptcp parameter to enable MPTCP
2. Introducing a new createImpl factory method that propagates the MPTCP setting to the underlying socket implementation
3. Maintaining all existing functionality while adding MPTCP capabilities
Quoted 4 lines
The new constructor follows the same pattern as existing ServerSocket constructors but adds the mptcp parameter to control protocol selection. When enabled, the implementation uses the MPTCP-enabled socket creation path established in previous patches.
Similar to my comment in patch 2/7, I don't know what is best in this project, but maybe instead of duplicating helpers, you could have the previous helper calling the new extension?
So ServerSocket(int port, int backlog, InetAddress bindAddr) would call the new one with 'mptcp' as new parameter? Same for createImpl()?
But not sure what the Java maintainers prefer. Maybe they are OK with what you suggested.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 6/7] Add MPTCP support to Socket class
In reply to Geliang TangHi Geliang,
Quoted 8 lines · Geliang Tang
This patch extends the Socket class to support Multipath TCP (MPTCP) by:
1. Adding a new constructor that accepts an mptcp parameter to enable MPTCP
2. Introducing a new private Socket constructor variant that handles MPTCP connections
3. Adding a createImpl factory method that propagates the MPTCP setting to the underlying socket implementation
4. Maintaining backward compatibility while adding MPTCP capabilities
Same here: the new helper could be called from the existing Socket() one instead of duplicating the code.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 7/7] Add test cases for MPTCP socket functionality
In reply to Geliang TangHi Geliang,
Quoted 22 lines · Geliang Tang
This patch introduces comprehensive test coverage for the newly added MPTCP socket support by:
1. Adding MPTCPServer.java - A test server that:
- Creates an MPTCP-enabled ServerSocket
- Accepts client connections
- Echoes received messages back to clients
- Handles graceful shutdown2. Adding MPTCPClient.java - A test client that:
- Connects to the MPTCP server
- Sends user input to server
- Displays server responses
- Supports graceful terminationThe tests verify:
- Basic MPTCP socket creation and connection
- Bidirectional communication
- Proper stream handling
- Error conditions
- Clean resource management
Quoted 2 lines
Both test programs demonstrate the usage of the new MPTCP-enabled constructors added in previous patches.
I don't know what is usually being done here, but these tests will not be used by a CI I guess. Is it an issue?
If that's normal, no need to add something like a README to explain how to test that?
Also, these tests don't check if MPTCP is being used, nor have pre-check to see if the system supports MPTCP (otherwise the test will fail).
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerHi Matt,
Quoted 54 lines · Matthieu Baerts
Hi Geliang,
Quoted 9 lines · Geliang Tang
The Multipath TCP (MPTCP) protocol (v1 / RFC 8684) has been added in
the upstream Linux kernel since v5.6.This patch series introduces comprehensive Multipath TCP (MPTCP) support
to the Java Networking API, enabling applications to leverage MPTCP's
capabilities for improved reliability and throughput.Thank you for having looked at that.
Quoted 14 lines
The implementation provides:
1. Core infrastructure for MPTCP socket creation (Patch 1)
2. Server and client socket creation APIs (Patches 2-3)
3. Integration with NIO socket implementation (Patch 4)
4. High-level Socket and ServerSocket support (Patches 5-6)
5. Comprehensive test cases (Patch 7)Key features:
- Backward compatible API extensions
- Platform-independent implementation
- Explicit MPTCP enablement through new constructors
- Full integration with existing socket functionality
- Test coverage for basic MPTCP operationsQuoted 4 lines
The changes maintain all existing functionality while adding MPTCP capabilities. When MPTCP is not enabled or not supported by the system, the
implementation gracefully falls back to regular TCP behavior.I don't think it is the case: if the system doesn't support it, an error
will be returned.If the other host doesn't support it or didn't request it, a fallback will be done.
Also, don't hesitate to share a link to https://mptcp.dev to help reviewers understanding what MPTCP is.
Quoted 10 lines
This work enables Java applications to benefit from MPTCP's capabilities:
- Seamless handover between network interfaces
- Aggregated bandwidth from multiple paths
- Improved resilience to network failuresThe implementation has been tested on Linux systems with MPTCP kernel
support enabled.
Quoted 7 lines
Quoted 1 line
I have a few comments, but I don't know the project, and I didn't code
in Java for a while. Then, feel free to send this version or an updated
one to the Java Net maintainers (not sure how, but I'm sure you will figure out :) ). Do not hesitate to share the link here.
How about I submit a pull request to openjdk?
Quoted 27 lines
Quoted 20 lines
Geliang Tang (7):
Add MPTCP support for socket creation
Add MPTCP server socket creation support
Add MPTCP client socket creation support
Add MPTCP support to NioSocketImpl
Add MPTCP support to ServerSocket class
Add MPTCP support to Socket class
Add test cases for MPTCP socket functionality.../share/classes/java/net/ServerSocket.java | 66 ++++++++++++++ .../share/classes/java/net/Socket.java | 88
+++++++++++++++++++
.../share/classes/java/net/SocketImpl.java | 8 ++ .../share/classes/sun/nio/ch/Net.java | 26 +++++- .../classes/sun/nio/ch/NioSocketImpl.java | 19 +++- src/java.base/unix/native/libnio/ch/Net.c | 5 +- src/java.base/windows/native/libnio/ch/Net.c | 2 +- .../java/net/ServerSocket/MPTCPServer.java | 58 ++++++++++++ test/jdk/java/net/Socket/MPTCPClient.java | 62 +++++++++++++Quoted 4 lines
9 files changed, 326 insertions(+), 8 deletions(-)create mode 100644 test/jdk/java/net/ServerSocket/MPTCPServer.java create mode 100644 test/jdk/java/net/Socket/MPTCPClient.java
Cheers,
Matt
Matthieu Baerts
maintainerHi Geliang,
Quoted 58 lines · Geliang Tang
Hi Matt,
Quoted 55 lines · Matthieu Baerts
Hi Geliang,
Quoted 9 lines · Geliang Tang
The Multipath TCP (MPTCP) protocol (v1 / RFC 8684) has been added in
the upstream Linux kernel since v5.6.This patch series introduces comprehensive Multipath TCP (MPTCP) support
to the Java Networking API, enabling applications to leverage MPTCP's
capabilities for improved reliability and throughput.Thank you for having looked at that.
Quoted 14 lines
The implementation provides:
1. Core infrastructure for MPTCP socket creation (Patch 1)
2. Server and client socket creation APIs (Patches 2-3)
3. Integration with NIO socket implementation (Patch 4)
4. High-level Socket and ServerSocket support (Patches 5-6)
5. Comprehensive test cases (Patch 7)Key features:
- Backward compatible API extensions
- Platform-independent implementation
- Explicit MPTCP enablement through new constructors
- Full integration with existing socket functionality
- Test coverage for basic MPTCP operationsQuoted 4 lines
The changes maintain all existing functionality while adding MPTCP capabilities. When MPTCP is not enabled or not supported by the system, the
implementation gracefully falls back to regular TCP behavior.I don't think it is the case: if the system doesn't support it, an error
will be returned.If the other host doesn't support it or didn't request it, a fallback will be done.
Also, don't hesitate to share a link to https://mptcp.dev to help reviewers understanding what MPTCP is.
Quoted 11 lines
This work enables Java applications to benefit from MPTCP's capabilities:
- Seamless handover between network interfaces
- Aggregated bandwidth from multiple paths
- Improved resilience to network failuresThe implementation has been tested on Linux systems with MPTCP kernel
support enabled.
Quoted 8 lines
Quoted 6 lines
I have a few comments, but I don't know the project, and I didn't code
in Java for a while. Then, feel free to send this version or an updated
one to the Java Net maintainers (not sure how, but I'm sure you will figure out :) ). Do not hesitate to share the link here.How about I submit a pull request to openjdk?
I don't think that is that simple... Apparently you need to sign the OCA, create a bug report, then later on, send a PR:
https://openjdk.org/guide/#i-have-a-patch-what-do-i-do
Not that easy to contribute...
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.