iperf3测试IPsec offload

发布于:2024-05-31 ⋅ 阅读:(161) ⋅ 点赞:(0)
diff --git a/src/iperf_api.c b/src/iperf_api.c
index dd0abe8..ab6491d 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -2168,16 +2168,20 @@ iperf_exchange_results(struct iperf_test *test)
 {
     if (test->role == 'c') {
         /* Send results to server. */
+        printf("Send results to server\n");
 	if (send_results(test) < 0)
             return -1;
         /* Get server results. */
+        printf("Get server results\n");
         if (get_results(test) < 0)
             return -1;
     } else {
         /* Get client results. */
+        printf("Get client results\n");
         if (get_results(test) < 0)
             return -1;
         /* Send results to client. */
+        printf("Send results to client\n");
 	if (send_results(test) < 0)
             return -1;
     }
@@ -2525,6 +2529,7 @@ get_results(struct iperf_test *test)
     int retransmits;
     struct iperf_stream *sp;
 
+    printf("%s: ctrl_sck\n", __func__);
     j = JSON_read(test->ctrl_sck);
     if (j == NULL) {
 	i_errno = IERECVRESULTS;
@@ -2702,11 +2707,14 @@ JSON_write(int fd, cJSON *json)
 	if (Nwrite(fd, (char*) &nsize, sizeof(nsize), Ptcp) < 0)
 	    r = -1;
 	else {
+            printf("%s: fd: %d r: %d, hsize: %d, nsize: %d\n", __func__, fd, r, hsize, nsize);
 	    if (Nwrite(fd, str, hsize, Ptcp) < 0)
 		r = -1;
+            printf("%s: r: %d, hsize: %d, str: %s\n", __func__, r, hsize, str);
 	}
 	cJSON_free(str);
     }
+    printf("%s: r: %d\n", __func__, r);
     return r;
 }
 
@@ -2728,12 +2736,14 @@ JSON_read(int fd)
      */
     if (Nread(fd, (char*) &nsize, sizeof(nsize), Ptcp) >= 0) {
 	hsize = ntohl(nsize);
+        printf("%s: fd: %d, port: %d, hsize: %d\n", __func__, fd, Ptcp, hsize);
 	/* Allocate a buffer to hold the JSON */
 	strsize = hsize + 1;              /* +1 for trailing NULL */
 	if (strsize) {
 	str = (char *) calloc(sizeof(char), strsize);
 	if (str != NULL) {
 	    rc = Nread(fd, str, hsize, Ptcp);
+            printf("%s: rc: %d fd: %d, port: %d, str: %s\n", __func__, rc, fd, Ptcp, str);
 	    if (rc >= 0) {
 		/*
 		 * We should be reading in the number of bytes corresponding to the
diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c
index 7ad4c93..7a8af94 100644
--- a/src/iperf_client_api.c
+++ b/src/iperf_client_api.c
@@ -299,6 +299,7 @@ iperf_handle_message_client(struct iperf_test *test)
         }
     }
 
+    printf("%s: state: %d\n", __func__, test->state);
     switch (test->state) {
         case PARAM_EXCHANGE:
             if (iperf_exchange_parameters(test) < 0)
@@ -397,9 +398,11 @@ iperf_connect(struct iperf_test *test)
     make_cookie(test->cookie);
 
     /* Create and connect the control channel */
-    if (test->ctrl_sck < 0)
+    if (test->ctrl_sck < 0) {
 	// Create the control channel using an ephemeral port
 	test->ctrl_sck = netdial(test->settings->domain, Ptcp, test->bind_address, test->bind_dev, 0, test->server_hostname, test->server_port, test->settings->connect_timeout);
+        printf("%s: netdial test->ctrl_sck: %d\n", __func__, test->ctrl_sck);
+    }
     if (test->ctrl_sck < 0) {
         i_errno = IECONNECT;
         return -1;
@@ -412,6 +415,12 @@ iperf_connect(struct iperf_test *test)
         return -1;
     }
 
+    printf("%s: set ctrl_sck mss: %d\n", __func__, test->settings->mss);
+    opt = test->settings->mss;
+    if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt)) < 0) {
+        printf("%s: failed to set ctrl_sck mss: %d\n", __func__, test->settings->mss);
+    }
+
 #if defined(HAVE_TCP_USER_TIMEOUT)
     if ((opt = test->settings->snd_timeout)) {
         if (setsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_USER_TIMEOUT, &opt, sizeof(opt)) < 0) {
@@ -431,11 +440,13 @@ iperf_connect(struct iperf_test *test)
 
     len = sizeof(opt);
     if (getsockopt(test->ctrl_sck, IPPROTO_TCP, TCP_MAXSEG, &opt, &len) < 0) {
+        printf("%s: ctrl_sck mss: %d\n", __func__, len);
         test->ctrl_sck_mss = 0;
     }
     else {
         if (opt > 0 && opt <= MAX_UDP_BLOCKSIZE) {
             test->ctrl_sck_mss = opt;
+            printf("%s: ctrl_sck mss 2: %d\n", __func__, opt);
         }
         else {
             char str[WARN_STR_LEN];
@@ -444,6 +455,7 @@ iperf_connect(struct iperf_test *test)
             warning(str);
 
             test->ctrl_sck_mss = 0;
+            printf("%s: ctrl_sck mss 3: %d\n", __func__, test->ctrl_sck_mss);
         }
     }
 
diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c
index 77e9c35..3b9cf01 100644
--- a/src/iperf_server_api.c
+++ b/src/iperf_server_api.c
@@ -118,7 +118,7 @@ iperf_server_listen(struct iperf_test *test)
             test->server_test_number +=1;
         if (test->debug || test->server_last_run_rc != 2) {
 	    iperf_printf(test, "-----------------------------------------------------------\n");
-	    iperf_printf(test, "Server listening on %d (test #%d)\n", test->server_port, test->server_test_number);
+	    iperf_printf(test, "Server listening on %d (test #%d), s: %d\n", test->server_port, test->server_test_number, test->listener);
 	    iperf_printf(test, "-----------------------------------------------------------\n");
 	    if (test->forceflush)
 	        iflush(test);
@@ -229,6 +229,7 @@ iperf_handle_message_server(struct iperf_test *test)
         }
     }
 
+    printf("%s: state: %d\n", __func__, test->state);
     switch(test->state) {
         case TEST_START:
             break;
@@ -690,6 +691,7 @@ iperf_run_server(struct iperf_test *test)
 			cleanup_server(test);
                         return -1;
 		    }
+                    printf("%s: s: %d\n", __func__, s);
 
 		    /* apply other common socket options */
                     if (iperf_common_sockopts(test, s) < 0)
diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c
index ce6a522..d0eb9d4 100644
--- a/src/iperf_tcp.c
+++ b/src/iperf_tcp.c
@@ -126,6 +126,7 @@ iperf_tcp_accept(struct iperf_test * test)
         i_errno = IESTREAMCONNECT;
         return -1;
     }
+    printf("%s: s: %d\n", __func__, s);
 
     if (Nread(s, cookie, COOKIE_SIZE, Ptcp) < 0) {
         i_errno = IERECVCOOKIE;
@@ -211,8 +212,16 @@ iperf_tcp_listen(struct iperf_test *test)
                 return -1;
             }
         }
+
+            if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d, s: %d\n", __func__, opt, s);
+	     }
+
         // XXX: Setting MSS is very buggy!
         if ((opt = test->settings->mss)) {
+	        printf("%s: set fd: %d, TCP_MAXSEG: %d\n", __func__, s, opt);
             if (setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt)) < 0) {
 		saved_errno = errno;
 		close(s);
@@ -222,6 +231,15 @@ iperf_tcp_listen(struct iperf_test *test)
                 return -1;
             }
         }
+
+     if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d\n", __func__, opt);
+	     }
+
+
+
         if ((opt = test->settings->socket_bufsize)) {
             if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt)) < 0) {
 		saved_errno = errno;
@@ -393,6 +411,12 @@ iperf_tcp_connect(struct iperf_test *test)
             return -1;
         }
     }
+            if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d\n", __func__, opt);
+	     }
+
     if ((opt = test->settings->mss)) {
         if (setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt)) < 0) {
 	    saved_errno = errno;
@@ -403,6 +427,15 @@ iperf_tcp_connect(struct iperf_test *test)
             return -1;
         }
     }
+
+            if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d\n", __func__, opt);
+	     }
+
+
+
     if ((opt = test->settings->socket_bufsize)) {
         if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt)) < 0) {
 	    saved_errno = errno;
diff --git a/src/net.c b/src/net.c
index c82caff..e8ce425 100644
--- a/src/net.c
+++ b/src/net.c
@@ -263,6 +263,7 @@ netannounce(int domain, int proto, const char *local, const char *bind_dev, int
     struct addrinfo hints, *res;
     char portstr[6];
     int s, opt, saved_errno;
+    socklen_t optlen;
 
     snprintf(portstr, 6, "%d", port);
     memset(&hints, 0, sizeof(hints));
@@ -295,6 +296,26 @@ netannounce(int domain, int proto, const char *local, const char *bind_dev, int
         return -1;
     }
 
+
+
+            if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d\n", __func__, opt);
+	     }
+
+        opt = 1300;
+        if (setsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, sizeof(opt)) < 0) {
+            return -1;
+        }
+
+            if (getsockopt(s, IPPROTO_TCP, TCP_MAXSEG, &opt, &optlen) < 0) {
+	        printf("%s: faild to get TCP_MAXSEG\n", __func__);
+            } else {
+	        printf("%s: get TCP_MAXSEG: %d\n", __func__, opt);
+	     }
+
+
     if (bind_dev) {
 #if defined(HAVE_SO_BINDTODEVICE)
         if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE,
@@ -362,6 +383,7 @@ netannounce(int domain, int proto, const char *local, const char *bind_dev, int
         }
     }
 
+    printf("%s: s: %d\n", __func__, s);
     return s;
 }
 
[root@c-237-169-100-104 ~]# /workspace/iperf/src/iperf3 -s
netannounce: get TCP_MAXSEG: 0
netannounce: get TCP_MAXSEG: 1300
netannounce: s: 3
-----------------------------------------------------------
Server listening on 5201 (test #1), s: 3
-----------------------------------------------------------
JSON_read: fd: 4, port: 1, hsize: 125
JSON_read: rc: 125 fd: 4, port: 1, str: {"tcp":true,"omit":0,"time":10,"num":0,"blockcount":0,"parallel":1,"len":131072,"pacing_timer":1000,"client_version":"3.16+"}
Accepted connection from 192.168.1.3, port 53534
iperf_tcp_accept: s: 5
iperf_run_server: s: 5
[  5] local 192.168.1.4 port 5201 connected to 192.168.1.3 port 53550
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec   203 MBytes  1.70 Gbits/sec
[  5]   1.00-2.00   sec   206 MBytes  1.73 Gbits/sec
[  5]   2.00-3.00   sec   206 MBytes  1.72 Gbits/sec
[  5]   3.00-4.00   sec   205 MBytes  1.72 Gbits/sec
[  5]   4.00-5.00   sec   205 MBytes  1.72 Gbits/sec
[  5]   5.00-6.00   sec   205 MBytes  1.72 Gbits/sec
[  5]   6.00-7.00   sec   206 MBytes  1.73 Gbits/sec
[  5]   7.00-8.00   sec   206 MBytes  1.73 Gbits/sec
[  5]   8.00-9.00   sec   206 MBytes  1.73 Gbits/sec
[  5]   9.00-10.00  sec   206 MBytes  1.73 Gbits/sec
iperf_handle_message_server: state: 4
[  5]  10.00-10.01  sec   896 KBytes  1.64 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.01  sec  2.01 GBytes  1.72 Gbits/sec                  receiver
Get client results
get_results: ctrl_sck
JSON_read: fd: 4, port: 1, hsize: 329
JSON_read: rc: 329 fd: 4, port: 1, str: {"cpu_util_total":6.0726089431515984,"cpu_util_user":0.039192696424528571,"cpu_util_system":6.03341624672707,"sender_has_retransmits":1,"congestion_used":"cubic","streams":[{"id":1,"bytes":2157445120,"retransmits":186,"jitter":0,"errors":0,"omitted_errors":0,"packets":0,"omitted_packets":0,"start_time":0,"end_time":10.001935}]}
Send results to client
JSON_write: fd: 4 r: 0, hsize: 329, nsize: 1224802304
JSON_write: r: 0, hsize: 329, str: {"cpu_util_total":12.95389038478433,"cpu_util_user":0.35044630832538859,"cpu_util_system":12.603444076458942,"sender_has_retransmits":-1,"congestion_used":"cubic","streams":[{"id":1,"bytes":2155741184,"retransmits":-1,"jitter":0,"errors":0,"omitted_errors":0,"packets":0,"omitted_packets":0,"start_time":0,"end_time":10.005497}]}
JSON_write: r: 0
iperf_handle_message_server: state: 16
netannounce: get TCP_MAXSEG: 0
netannounce: get TCP_MAXSEG: 1300
netannounce: s: 3
[root@c-237-169-100-103 ~]# /workspace/iperf/src/iperf3 -c 192.168.1.4 -P 1
iperf_connect: netdial test->ctrl_sck: 4
iperf_connect: set ctrl_sck mss: 0
iperf_connect: ctrl_sck mss 2: 1288
iperf_handle_message_client: state: 9
JSON_write: fd: 4 r: 0, hsize: 125, nsize: 2097152000
JSON_write: r: 0, hsize: 125, str: {"tcp":true,"omit":0,"time":10,"num":0,"blockcount":0,"parallel":1,"len":131072,"pacing_timer":1000,"client_version":"3.16+"}
JSON_write: r: 0
Connecting to host 192.168.1.4, port 5201
iperf_handle_message_client: state: 10
iperf_tcp_connect: get TCP_MAXSEG: 0
iperf_tcp_connect: get TCP_MAXSEG: 0
[  5] local 192.168.1.3 port 53550 connected to 192.168.1.4 port 5201
iperf_handle_message_client: state: 1
iperf_handle_message_client: state: 2
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec   205 MBytes  1.72 Gbits/sec   12    635 KBytes
[  5]   1.00-2.00   sec   206 MBytes  1.73 Gbits/sec    0    750 KBytes
[  5]   2.00-3.00   sec   205 MBytes  1.72 Gbits/sec   26    741 KBytes
[  5]   3.00-4.00   sec   206 MBytes  1.73 Gbits/sec   40    732 KBytes
[  5]   4.00-5.00   sec   205 MBytes  1.72 Gbits/sec   24    723 KBytes
[  5]   5.00-6.00   sec   205 MBytes  1.72 Gbits/sec   12    716 KBytes
[  5]   6.00-7.00   sec   207 MBytes  1.73 Gbits/sec    9    709 KBytes
[  5]   7.00-8.00   sec   206 MBytes  1.72 Gbits/sec   33    698 KBytes
[  5]   8.00-9.00   sec   206 MBytes  1.73 Gbits/sec   21    693 KBytes
iperf_handle_message_client: state: 13
Send results to server
JSON_write: fd: 4 r: 0, hsize: 329, nsize: 1224802304
JSON_write: r: 0, hsize: 329, str: {"cpu_util_total":6.0726089431515984,"cpu_util_user":0.039192696424528571,"cpu_util_system":6.03341624672707,"sender_has_retransmits":1,"congestion_used":"cubic","streams":[{"id":1,"bytes":2157445120,"retransmits":186,"jitter":0,"errors":0,"omitted_errors":0,"packets":0,"omitted_packets":0,"start_time":0,"end_time":10.001935}]}
JSON_write: r: 0
Get server results
get_results: ctrl_sck
JSON_read: fd: 4, port: 1, hsize: 329
JSON_read: rc: 329 fd: 4, port: 1, str: {"cpu_util_total":12.95389038478433,"cpu_util_user":0.35044630832538859,"cpu_util_system":12.603444076458942,"sender_has_retransmits":-1,"congestion_used":"cubic","streams":[{"id":1,"bytes":2155741184,"retransmits":-1,"jitter":0,"errors":0,"omitted_errors":0,"packets":0,"omitted_packets":0,"start_time":0,"end_time":10.005497}]}
iperf_handle_message_client: state: 14
[  5]   9.00-10.00  sec   206 MBytes  1.73 Gbits/sec    9    689 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  2.01 GBytes  1.73 Gbits/sec  186             sender
[  5]   0.00-10.01  sec  2.01 GBytes  1.72 Gbits/sec                  receiver

iperf Done.

最近发现用iperf3测试IPsec offload的时候,最后会出现超时的错误。那是因为没有设置ctrl_sck的TCP_MAXSEG,IPsec offload并不支持fragment。打上上面的diff后,可以把mss设置小点。然后就没有问题了。

上面的例子hsize是329,并不会有问题。当线程数多于8后,hsize会大于1500,就会出问题了。


网站公告

今日签到

点亮在社区的每一天
去签到