66#include <stdio.h>
77#include <string.h>
88#include <inttypes.h>
9+ #include <sys/socket.h>
910// #include "esp_idf_version.h"
1011#include "esp_log.h"
1112#include "esp_console.h"
1213#include "argtable3/argtable3.h"
14+ #include "esp_netif.h"
15+
1316#include "iperf.h"
1417
15- #include "esp_netif.h"
1618
1719#ifndef APP_TAG
1820#define APP_TAG "IPERF"
@@ -22,7 +24,9 @@ typedef struct {
2224 struct arg_str * ip ;
2325 struct arg_lit * server ;
2426 struct arg_lit * udp ;
25- // struct arg_lit *version6;
27+ #if IPERF_IPV6_ENABLED
28+ struct arg_lit * ipv6_domain ;
29+ #endif
2630 struct arg_int * port ;
2731 struct arg_int * length ;
2832 struct arg_int * interval ;
@@ -55,8 +59,13 @@ static int cmd_do_iperf(int argc, char **argv)
5559 }
5660
5761 memset (& cfg , 0 , sizeof (cfg ));
58- // now iperf-cmd only support IPV4 address
62+
5963 cfg .type = IPERF_IP_TYPE_IPV4 ;
64+ #if IPERF_IPV6_ENABLED
65+ if (iperf_args .ipv6_domain -> count > 0 ) {
66+ cfg .type = IPERF_IP_TYPE_IPV6 ;
67+ }
68+ #endif
6069
6170 if (((iperf_args .ip -> count == 0 ) && (iperf_args .server -> count == 0 )) ||
6271 ((iperf_args .ip -> count != 0 ) && (iperf_args .server -> count != 0 ))) {
@@ -67,12 +76,20 @@ static int cmd_do_iperf(int argc, char **argv)
6776 if (iperf_args .ip -> count == 0 ) {
6877 cfg .flag |= IPERF_FLAG_SERVER ;
6978 } else {
70- cfg .destination_ip4 = esp_ip4addr_aton (iperf_args .ip -> sval [0 ]);
7179 cfg .flag |= IPERF_FLAG_CLIENT ;
80+ #if IPERF_IPV6_ENABLED
81+ if (cfg .type == IPERF_IP_TYPE_IPV6 ) {
82+ /* TODO: Refactor iperf config structure in v1.0 */
83+ cfg .destination_ip6 = (char * )(iperf_args .ip -> sval [0 ]);
84+ }
85+ #endif
86+ #if IPERF_IPV4_ENABLED
87+ if (cfg .type == IPERF_IP_TYPE_IPV4 ) {
88+ cfg .destination_ip4 = esp_ip4addr_aton (iperf_args .ip -> sval [0 ]);
89+ }
90+ #endif
7291 }
7392
74- // NOTE: Do not bind local ip now
75-
7693 if (iperf_args .udp -> count == 0 ) {
7794 cfg .flag |= IPERF_FLAG_TCP ;
7895 } else {
@@ -137,15 +154,15 @@ static int cmd_do_iperf(int argc, char **argv)
137154 }
138155 }
139156
140- ESP_LOGI (APP_TAG , "mode=%s-%s sip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
141- dip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,\
142- interval=%" PRId32 ", time=%" PRId32 "" ,
157+ ESP_LOGI (APP_TAG , "mode=%s-%s sip=%s:%" PRId32 ", dip=%s:%" PRId32 ", interval=%" PRId32 ", time=%" PRId32 ,
143158 cfg .flag & IPERF_FLAG_TCP ? "tcp" : "udp" ,
144159 cfg .flag & IPERF_FLAG_SERVER ? "server" : "client" ,
145- cfg .source_ip4 & 0xFF , (cfg .source_ip4 >> 8 ) & 0xFF , (cfg .source_ip4 >> 16 ) & 0xFF ,
146- (cfg .source_ip4 >> 24 ) & 0xFF , cfg .sport ,
147- cfg .destination_ip4 & 0xFF , (cfg .destination_ip4 >> 8 ) & 0xFF ,
148- (cfg .destination_ip4 >> 16 ) & 0xFF , (cfg .destination_ip4 >> 24 ) & 0xFF , cfg .dport ,
160+ "localhost" , cfg .sport ,
161+ #if IPERF_IPV4_ENABLED
162+ cfg .type == IPERF_IP_TYPE_IPV6 ? cfg .destination_ip6 : inet_ntoa (cfg .destination_ip4 ), cfg .dport ,
163+ #else
164+ cfg .type == IPERF_IP_TYPE_IPV6 ? cfg .destination_ip6 : "0.0.0.0" , cfg .dport ,
165+ #endif
149166 cfg .interval , cfg .time );
150167
151168 iperf_start (& cfg );
@@ -159,9 +176,14 @@ esp_err_t app_register_iperf_commands(void)
159176 iperf_args .ip = arg_str0 ("c" , "client" , "<host>" , "run in client mode, connecting to <host>" );
160177 iperf_args .server = arg_lit0 ("s" , "server" , "run in server mode" );
161178 iperf_args .udp = arg_lit0 ("u" , "udp" , "use UDP rather than TCP" );
162- // #ifdef CONFIG_LWIP_IPV6
163- // iperf_args.version6 = arg_lit0("6", "version6", "Use IPv6 addresses");
164- // #endif
179+ #if IPERF_IPV6_ENABLED
180+ /*
181+ * NOTE: iperf2 uses -V(--ipv6_domain or --IPv6Version) for ipv6
182+ * iperf3 uses -6(--version6)
183+ * May add a new command "iperf3" in the future
184+ */
185+ iperf_args .ipv6_domain = arg_lit0 ("V" , "ipv6_domain" , "Set the domain to IPv6 (send packets over IPv6)" );
186+ #endif
165187 iperf_args .port = arg_int0 ("p" , "port" , "<port>" , "server port to listen on/connect to" );
166188 iperf_args .length = arg_int0 ("l" , "len" , "<length>" , "Set read/write buffer size" );
167189 iperf_args .interval = arg_int0 ("i" , "interval" , "<interval>" , "seconds between periodic bandwidth reports" );
0 commit comments