From: Dmytro Shytyi <dmytro@shytyi.net>
To: mptcp@lists.linux.dev
Cc: Dmytro Shytyi <dmytro@shytyi.net>
Subject: [RFC PATCH mptcp-next v5 10/10] MPTFO tests: these are examples that probably are going to be integrated to the mptcp_connect.* selftests
Date: Wed, 14 Sep 2022 13:31:51 +0200 [thread overview]
Message-ID: <20220914113151.9898-10-dmytro@shytyi.net> (raw)
In-Reply-To: <20220914113151.9898-1-dmytro@shytyi.net>
MPTFO tests: these are examples that
probably are going to be integrated to the mptcp_connect.* selftests
Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
---
tools/testing/selftests/net/mptcp/mptfo.sh | 13 +++
.../selftests/net/mptcp/mptfo_initiator.c | 41 ++++++++
.../selftests/net/mptcp/mptfo_listener.c | 98 +++++++++++++++++++
3 files changed, 152 insertions(+)
create mode 100644 tools/testing/selftests/net/mptcp/mptfo.sh
create mode 100644 tools/testing/selftests/net/mptcp/mptfo_initiator.c
create mode 100644 tools/testing/selftests/net/mptcp/mptfo_listener.c
diff --git a/tools/testing/selftests/net/mptcp/mptfo.sh b/tools/testing/selftests/net/mptcp/mptfo.sh
new file mode 100644
index 000000000000..9ed0cb281094
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/mptfo.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+#This is an example of environmen that was used to generate wireshark
+sudo ip netns add server
+sudo ip netns add client
+sudo ip link add veth0 type veth peer name veth1
+sudo ip link set veth1 netns server
+sudo ip link set veth0 netns client
+sudo ip netns exec client ip a a 10.10.0.1/24 dev veth0
+sudo ip netns exec server ip a a 10.10.0.2/24 dev veth1
+sudo ip netns exec client ip link set dev veth0 up
+sudo ip netns exec server ip link set dev veth1 up
+sudo ip netns exec server bash -c "echo 2 > /proc/sys/net/ipv4/tcp_fastopen"
+sudo ip netns exec client bash -c "echo 1 > /proc/sys/net/ipv4/tcp_fastopen"
diff --git a/tools/testing/selftests/net/mptcp/mptfo_initiator.c b/tools/testing/selftests/net/mptcp/mptfo_initiator.c
new file mode 100644
index 000000000000..e23b88693fb0
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/mptfo_initiator.c
@@ -0,0 +1,41 @@
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <netinet/tcp.h>
+#include <string.h>
+#include <signal.h>
+
+#define SERVER_PORT 7003
+
+int main(int argc, char *argv[])
+{
+ unsigned char valsyn[3] = "abc";
+ struct sockaddr_in daddr;
+ char *valend = "fff";
+ char *val1 = "zz1";
+ char *val2 = "zz2";
+ char *val3 = "zz3";
+ int sock_fd = -1;
+ int ret;
+
+ memset(&daddr, 0, sizeof(daddr));
+ inet_pton(AF_INET, "10.10.0.2", &daddr.sin_addr);
+ daddr.sin_family = AF_INET;
+ daddr.sin_port = htons(SERVER_PORT);
+
+ sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);
+
+ ret = sendto(sock_fd, valsyn, 3, MSG_FASTOPEN, (struct sockaddr *) &daddr, sizeof(daddr));
+ ret = write(sock_fd, val1, 3);
+ ret = write(sock_fd, val2, 3);
+ ret = write(sock_fd, val2, 3);
+ ret = write(sock_fd, val2, 3);
+ ret = write(sock_fd, val3, 3);
+ ret = write(sock_fd, valend, 3);
+
+ close(sock_fd);
+ return EXIT_SUCCESS;
+}
diff --git a/tools/testing/selftests/net/mptcp/mptfo_listener.c b/tools/testing/selftests/net/mptcp/mptfo_listener.c
new file mode 100644
index 000000000000..7e3de8d1d08c
--- /dev/null
+++ b/tools/testing/selftests/net/mptcp/mptfo_listener.c
@@ -0,0 +1,98 @@
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <linux/in.h>
+#include <netinet/tcp.h>
+
+#define CLIENT_QUEUE_LEN 10
+#define SERVER_PORT 7003
+
+int main(void)
+{
+ int listen_sock_fd = -1, client_sock_fd = -1;
+ char str_addr[INET6_ADDRSTRLEN];
+ struct sockaddr_in server_addr;
+ int ret, flag;
+ int qlen = 5;
+ char ch;
+
+ server_addr.sin_family = AF_INET;
+ inet_pton(AF_INET, "10.10.0.2", &server_addr.sin_addr);
+ server_addr.sin_port = htons(SERVER_PORT);
+
+ /* Create socket for listening (client requests) */
+ listen_sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);
+ if (listen_sock_fd == -1) {
+ perror("socket()server");
+ return EXIT_FAILURE;
+ }
+
+ /* Set socket to reuse address */
+ flag = 1;
+ ret = setsockopt(listen_sock_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
+ if (ret == -1) {
+ perror("setsockopt()");
+ return EXIT_FAILURE;
+ }
+
+ ret = setsockopt(listen_sock_fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen));
+ if (ret == -1) {
+ perror("setsockopt()TCP_FASTOPEN");
+ return EXIT_FAILURE;
+ }
+
+ /* Bind address and socket together */
+ ret = bind(listen_sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
+ if (ret == -1) {
+ perror("bind()");
+ close(listen_sock_fd);
+ return EXIT_FAILURE;
+ }
+
+ /* Create listening queue (client requests) */
+ ret = listen(listen_sock_fd, CLIENT_QUEUE_LEN);
+ if (ret == -1) {
+ perror("listen()");
+ close(listen_sock_fd);
+ return EXIT_FAILURE;
+ }
+ perror("Server listening");
+ while (1) {
+ /* Do TCP handshake with client */
+ client_sock_fd = accept(listen_sock_fd,
+ NULL,
+ 0);
+ if (client_sock_fd == -1) {
+ perror("accept()");
+ close(listen_sock_fd);
+ return EXIT_FAILURE;
+ } else {
+ perror("ACCEPT_SUCCESS");
+ }
+
+ char rb[1024];
+
+ while (1) {
+ ret = read(client_sock_fd, rb, 3);
+
+ if (ret == -1) {
+ perror("SERVVERread()");
+ close(client_sock_fd);
+ break;
+ } else {
+ fprintf(stderr, "received %c%c%c from client", rb[0], rb[1], rb[2]);
+ }
+ if (rb[0] == 'f' && rb[1] == 'f' && rb[2] == 'f') {
+ close(client_sock_fd);
+ break;
+ }
+
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
--
2.25.1
prev parent reply other threads:[~2022-09-14 11:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 11:31 [RFC PATCH mptcp-next v5 01/10] mptcp: Fast Open Mechanism Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 02/10] Initiator: MSG_FASTOPEN in sendto triggers the mptcp_sendsmg_fastopen. It requests a MPTFO cookie. Suggestion @palbeni(JAN 17): 'split the patch in several small one, clearly documenting in the individual commit message what each patch is doing and why' Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 03/10] Initiator: mptcp_sendmsg_fastopen. Usage of lock_sock() / release_sock() leads to hangup' Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 04/10] Treat a socket option TCP_FASTOPEN on Lister side. Suggestion @mmartineau(MAY 22): 'Need to use ssk instead of sk in these several lines' (1 AUG): 'Since fastopen is only relevant for the initial subflow (and never with MP_JOIN). __mptcp_nmpc_socket() should give the initial subflow' Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 05/10] This fixes the unexpected value of subflow->map_seq for the second packet that leads to packet discard and further retransmit Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 06/10] This commit introduces mptfo variables for msk and options. Also fixes the infinite retransmissions in the end of second session. Suggestion @palbeni (SEP 1) during the meting to 'look at data_ack' Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 07/10] Add the received skb on the listener side to msk and set flag mptfo to 1 to treat some parts only in MPTFO case. This function is called from the functions presented in the next patch Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 08/10] This is temporary modification and will be adressed in the new version of the patch: Remove OPTIONS_TS from the options. See disscusion in the mailing list (JAN 18) [PATCH v2] fastopen with @palbeni Dmytro Shytyi
2022-09-14 11:31 ` [RFC PATCH mptcp-next v5 09/10] These 2 functions are from protocol.c. Cannot import as not in protocol.h. Should I leave them like this? Or add prototypes in protocol.h and reuse? Dmytro Shytyi
2022-09-14 11:31 ` Dmytro Shytyi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220914113151.9898-10-dmytro@shytyi.net \
--to=dmytro@shytyi.net \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).