Skip to contentSkip to conversation

Add Multipath TCP (MPTCP) Support to the Java Networking API

DISCUSSION Geliang Tang 1 participant 5 messages Sep 5, 2025 – Sep 23, 2025 2 messages not in the archive Networking MPTCP

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

Hi OpenJDK maintainers,

I hope this message finds you well. The purpose of this letter is to propose the integration of Multipath TCP (MPTCP) support into OpenJDK. We have developed a set of patches to enable this functionality and are eager to submit it for upstream inclusion. We would greatly appreciate your feedback and opinions on this contribution.

1. Introduction

Multipath TCP (MPTCP), as standardized in RFC 8684, is a major evolution of the TCP protocol. It enables a transport connection to use multiple network paths simultaneously for redundancy, resilience, and bandwidth aggregation. Since its introduction in Linux kernel v5.6, it has become a key technology for modern networking, particularly on mobile devices with multiple interfaces (e.g., Wi-Fi and cellular).

Key benefits include:

Bandwidth Aggregation: Combine the bandwidth of multiple network
links.

Seamless Handover: Maintain connections when switching networks
without dropping the session.

Improved Resilience: Traffic is automatically rerouted if one path
fails.

For more details, see the project website: https://mptcp.dev.

2. Technical Background

On a supporting system like Linux, an MPTCP socket is created by specifying the IPPROTO_MPTCP protocol in the socket() system call instead of IPPROTO_TCP (or 0):

    int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);

This creates a socket that looks like a standard TCP socket to the application but uses the MPTCP protocol stack underneath.

With the Java API, it is possible to create "stream" sockets, but it is not possible to change the last argument, which blocks apps to ask to use MPTCP.

3. Proposed Java API Changes

The goal is to allow Java applications to opt-in to using MPTCP when creating sockets, without breaking existing code. The proposed changes are additive and backward-compatible.

The core idea is to add a boolean mptcp parameter through the API layers, from the public Socket class down to the native system call.

4. Implementation Plan

The implementation involves changes across four layers of the JDK:

JNI Layer (sun.nio.ch.Net):

Modify Java_sun_nio_ch_Net_socket0 to accept a new jboolean mptcp parameter.

    The native implementation will be updated to use this parameter:

    int protocol = mptcp == JNI_TRUE ? IPPROTO_MPTCP : 0;
    fd = socket(domain, type, protocol);

NIO Layer (sun.nio.ch):

Add the mptcp parameter to the Net.socket() and Net.serverSocket()
methods.

Propagate the parameter down to the JNI call.

Socket Implementation Layer (java.net):

Add the mptcp parameter to the constructor of NioSocketImpl.

Within NioSocketImpl, pass the parameter to the Net.socket() or
Net.serverSocket() calls.

Public API Layer (java.net.Socket & java.net.ServerSocket):

Add new constructors that accept the mptcp parameter.

Example:

// Proposed new constructor
public Socket(String host, int port, boolean stream, boolean

mptcp) throws IOException {
            // ... implementation that passes 'mptcp' to NioSocketImpl
        }

5. Full Implementation

The complete working implementation for this proposal is available for review:

https://github.com/openjdk/jdk/compare/master...geliangtang:jdk:master

We look forward to your valuable feedback and suggestions on this proposal.

We can create a new issue for this feature, and submit a proper pull request after if that's OK for you. We didn't do that yet because we noticed that it is recommended to send more explanations to this list first.

Best regards,
MPTCP Upstream Developers

A message that is not in the archive (sent off-list or not yet received): [email protected]

author reviewer
#2 lore raw

Hi Alan,

Thanks for your reply.

Quoted 19 lines · Alan Bateman


On 05/09/2025 09:43, Geliang Tang wrote:

Quoted 11 lines


:

3. Proposed Java API Changes

The goal is to allow Java applications to opt-in to using MPTCP when
creating sockets, without breaking existing code. The proposed changes
are additive and backward-compatible.

Quoted 4 lines

The core idea is to add a boolean mptcp parameter through the API layers, from the public Socket class down to the native system call.

Quoted 12 lines


 (moving the discussion to nio-dev and net-dev).

 Adding new constructors to legacy Socket/ServerSocket may work for your initial prototype but would be problematic to propose as it would bake non-standard features into the standard API. Also many high performance servers use SocketChannel rather than Socket.
 One suggestion for a next prototype is to model the enablement of MultiPath TCP as as a JDK-specific socket option (see jdk.net.ExtendingSocketOptions). All of the standard APIs for networking sockets define a setOption method for setting socket

I was initially concerned that calling setOption() after Socket() creation to convert TCP to MPTCP was too late. Creating an MPTCP socket must be done during the socket() system call.

Quoted 2 lines

options. If modeled as a socket option then enabling can create a new AF_INET6/SOCK_STREAM/IPPROTO_MPTCP socket and then dup2 it into place

Until I saw here, it should be feasible if the socket can be created again and dup when calling setOption().

I will try to reimplement MPTCP support using jdk.net.ExtendingSocketOptions soon and give you feedback.

Thanks,
-Geliang

Quoted 10 lines

so that the original AF_INET6/SOCK_STREAM/0 socket is closed. Enabling can be made to fail if the socket is already bound. It could copy over existing socket options if needed. Look at the built-in (and no longer used) SDP support for an example that does similar with AF_INET_SDP/SOCK_STREAM/0. The only API surface would be a socket option defined in jdk.net.ExtendingSocketOptions.

 -Alan

author reviewer
#3 lore raw
In reply to a message not in the archive

Hi Alan,

Thanks for your reply.

Quoted 19 lines · Alan Bateman


On 05/09/2025 09:43, Geliang Tang wrote:

Quoted 11 lines


:

3. Proposed Java API Changes

The goal is to allow Java applications to opt-in to using MPTCP when
creating sockets, without breaking existing code. The proposed changes
are additive and backward-compatible.

Quoted 4 lines

The core idea is to add a boolean mptcp parameter through the API layers, from the public Socket class down to the native system call.

Quoted 12 lines


 (moving the discussion to nio-dev and net-dev).

 Adding new constructors to legacy Socket/ServerSocket may work for your initial prototype but would be problematic to propose as it would bake non-standard features into the standard API. Also many high performance servers use SocketChannel rather than Socket.
 One suggestion for a next prototype is to model the enablement of MultiPath TCP as as a JDK-specific socket option (see jdk.net.ExtendingSocketOptions). All of the standard APIs for networking sockets define a setOption method for setting socket

I was initially concerned that calling setOption() after Socket() creation to convert TCP to MPTCP was too late. Creating an MPTCP socket must be done during the socket() system call.

Quoted 2 lines

options. If modeled as a socket option then enabling can create a new AF_INET6/SOCK_STREAM/IPPROTO_MPTCP socket and then dup2 it into place

Until I saw here, it should be feasible if the socket can be created again and dup when calling setOption().

I will try to reimplement MPTCP support using jdk.net.ExtendingSocketOptions soon and give you feedback.

Thanks,
-Geliang

Quoted 10 lines

so that the original AF_INET6/SOCK_STREAM/0 socket is closed. Enabling can be made to fail if the socket is already bound. It could copy over existing socket options if needed. Look at the built-in (and no longer used) SDP support for an example that does similar with AF_INET_SDP/SOCK_STREAM/0. The only API surface would be a socket option defined in jdk.net.ExtendingSocketOptions.

 -Alan

author reviewer
#4 lore raw

Hi Alan,

Quoted 47 lines · Geliang Tang

Hi Alan,

Thanks for your reply.

Quoted 19 lines · Alan Bateman


On 05/09/2025 09:43, Geliang Tang wrote:

Quoted 11 lines


:

3. Proposed Java API Changes

The goal is to allow Java applications to opt-in to using MPTCP when
creating sockets, without breaking existing code. The proposed changes
are additive and backward-compatible.

Quoted 4 lines

The core idea is to add a boolean mptcp parameter through the API layers, from the public Socket class down to the native system call.

Quoted 12 lines


 (moving the discussion to nio-dev and net-dev).

 Adding new constructors to legacy Socket/ServerSocket may work for your initial prototype but would be problematic to propose as it would bake non-standard features into the standard API. Also many high performance servers use SocketChannel rather than Socket.
 One suggestion for a next prototype is to model the enablement of MultiPath TCP as as a JDK-specific socket option (see jdk.net.ExtendingSocketOptions). All of the standard APIs for networking sockets define a setOption method for setting socket

I was initially concerned that calling setOption() after Socket() creation to convert TCP to MPTCP was too late. Creating an MPTCP socket
must be done during the socket() system call.

Quoted 4 lines

options. If modeled as a socket option then enabling can create a new
AF_INET6/SOCK_STREAM/IPPROTO_MPTCP socket and then dup2 it into place

Quoted 5 lines

Until I saw here, it should be feasible if the socket can be created again and dup when calling setOption().

I will try to reimplement MPTCP support using jdk.net.ExtendingSocketOptions soon and give you feedback.

I have completed the implementation. Thanks to Xiang Gao and Gang Yan for their help. I added a new option named TCP_MPTCPIFY in jdk.net.ExtendedSocketOptions (the name was chosen to align with 'mptcpize' tool in mptcpd and 'mptcpify' in BCC). When this option is set, it calls the JNI function mptcpify0.

Following your suggestion, mptcpify0 is implemented by referencing Java_sun_net_sdp_SdpSupport_convert0. It creates a new MPTCP socket, uses dup2 to duplicate it, and then closes the redundant socket.

I have added your tag in the patch:

I also included a test example for this option. All modifications can be found here:

https://github.com/openjdk/jdk/compare/master...geliangtang:jdk:master

Please provide any feedback or suggestions. As for the next steps, should I create a new issue for this feature and submit a proper pull request?

Thanks,
-Geliang

Quoted 15 lines

Thanks,
-Geliang

Quoted 11 lines

so that the original AF_INET6/SOCK_STREAM/0 socket is closed. Enabling can be made to fail if the socket is already bound. It could
copy over existing socket options if needed. Look at the built-in (and no longer used) SDP support for an example that does similar with AF_INET_SDP/SOCK_STREAM/0. The only API surface would be a socket option defined in jdk.net.ExtendingSocketOptions.
 -Alan

A message that is not in the archive (sent off-list or not yet received): [email protected]

author reviewer
#6 lore raw

Hi Alan,

Thanks for your reply.

Quoted 47 lines · Alan Bateman


On 18/09/2025 08:36, Geliang Tang wrote:

Quoted 22 lines


I have completed the implementation. Thanks to Xiang Gao and Gang Yan
for their help. I added a new option named TCP_MPTCPIFY in jdk.net.ExtendedSocketOptions (the name was chosen to align with 'mptcpize' tool in mptcpd and 'mptcpify' in BCC). When this option is
set, it calls the JNI function mptcpify0.

Following your suggestion, mptcpify0 is implemented by referencing Java_sun_net_sdp_SdpSupport_convert0. It creates a new MPTCP socket,
uses dup2 to duplicate it, and then closes the redundant socket.

I have added your tag in the patch:

I also included a test example for this option. All modifications can
be found here:

Quoted 7 lines

https://github.com/openjdk/jdk/compare/master...geliangtang:jdk:master

Please provide any feedback or suggestions. As for the next steps, should I create a new issue for this feature and submit a proper pull
request?


 Thanks for confirming that the direction suggested works. This at least demonstrates a feasible direction that does not impact the standard API.

 As regards next steps then I think start a thread on net-dev to try to get input. I think it would be useful to show potential scenarios where it would be useful and what performance benefits might come from it. I think also useful to talk about whether this is something that an application has to opt into, maybe there are other configuration approaches that would not require application changes?
 I think it would be useful to discuss testing. If this feature were integrated into the JDK then how would it be tested? Who would test and maintain it? There is a JDK release every 6 months, is someone

Quoted 8 lines

going test it with each release?

 If it goes ahead then there the name of the extended socket option and its API docs will need discussion. Details around state will need to be specified, would it be supported to set TCP_MPTCP when bound or connected, does it make sense to ever attempt to set it to false after setting it to true (these are just examples of the details that will need to be specified, they are not important right now).

Following your suggestion, I have started a new thread on net-dev:

Add Extended MPTCP (Multipath TCP) Socket Option Support to OpenJDK
https://mail.openjdk.org/pipermail/net-dev/2025-September/028085.html

Thanks,
-Geliang

Quoted 4 lines


 -Alan.