From 2be77287b324ff37fbb3f97d96a6b894e30da732 Mon Sep 17 00:00:00 2001 From: zhangwenxu Date: Fri, 30 Jul 2021 15:55:37 +0800 Subject: [PATCH] openthread: add iperf example for ot-network test --- components/openthread/Kconfig | 6 + .../openthread-core-esp32x-ftd-config.h | 2 +- .../ble_mesh_wifi_coexist/main/cmd_wifi.c | 39 +- .../common_components/iperf/include/iperf.h | 29 +- examples/common_components/iperf/iperf.c | 479 ++++++++++-------- examples/ethernet/iperf/main/cmd_ethernet.c | 26 +- examples/openthread/ot_cli/CMakeLists.txt | 2 + examples/openthread/ot_cli/Makefile | 2 + examples/openthread/ot_cli/README.md | 85 +++- .../openthread/ot_cli/main/CMakeLists.txt | 2 +- examples/openthread/ot_cli/main/esp_ot_cli.c | 18 +- .../ot_cli/main/esp_ot_cli_extension.c | 20 +- .../ot_cli/main/esp_ot_cli_extension.h | 20 +- .../openthread/ot_cli/main/esp_ot_config.h | 18 +- .../openthread/ot_cli/main/esp_ot_iperf.c | 98 ++++ .../openthread/ot_cli/main/esp_ot_iperf.h | 20 + .../ot_cli/main/esp_ot_tcp_socket.c | 22 +- .../ot_cli/main/esp_ot_tcp_socket.h | 18 +- .../ot_cli/main/esp_ot_udp_socket.c | 27 +- .../ot_cli/main/esp_ot_udp_socket.h | 18 +- examples/openthread/ot_cli/sdkconfig.defaults | 1 + examples/wifi/iperf/main/cmd_wifi.c | 117 +++-- 22 files changed, 673 insertions(+), 396 deletions(-) create mode 100644 examples/openthread/ot_cli/main/esp_ot_iperf.c create mode 100644 examples/openthread/ot_cli/main/esp_ot_iperf.h diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 7803240730..cdee2a0222 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -91,4 +91,10 @@ menu "OpenThread" help Override the shipped libopenthread_br.a and libopenthread_port.a, for internal builds. + config OPENTHREAD_NUM_MESSAGE_BUFFERS + int "The number of openthread message buffers" + depends on OPENTHREAD_ENABLED + default 65 + range 50 100 + endmenu diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index 07a6bdc754..cc9bb2cd8d 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -95,7 +95,7 @@ * * The number of message buffers in buffer pool */ -#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS 50 +#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS CONFIG_OPENTHREAD_NUM_MESSAGE_BUFFERS /** * @def OPENTHREAD_CONFIG_COAP_API_ENABLE diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/cmd_wifi.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/cmd_wifi.c index 40e67a3281..f496e7f2c2 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/cmd_wifi.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/cmd_wifi.c @@ -23,7 +23,9 @@ typedef struct { struct arg_str *ip; struct arg_lit *server; struct arg_lit *udp; + struct arg_lit *version; struct arg_int *port; + struct arg_int *length; struct arg_int *interval; struct arg_int *time; struct arg_lit *abort; @@ -51,8 +53,8 @@ static const char *TAG = "iperf"; static EventGroupHandle_t wifi_event_group; const int CONNECTED_BIT = BIT0; const int DISCONNECTED_BIT = BIT1; -static esp_netif_t * sta_netif = NULL; -static esp_netif_t * ap_netif = NULL; +static esp_netif_t *sta_netif = NULL; +static esp_netif_t *ap_netif = NULL; static void scan_done_handler(void) { @@ -75,8 +77,8 @@ static void scan_done_handler(void) free(ap_list_buffer); } -static void wifi_event_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) +static void wifi_event_handler(void *arg, esp_event_base_t event_base, + int32_t event_id, void *event_data) { switch (event_id) { case WIFI_EVENT_SCAN_DONE: @@ -102,8 +104,8 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, return; } -static void ip_event_handler(void* arg, esp_event_base_t event_base, - int32_t event_id, void* event_data) +static void ip_event_handler(void *arg, esp_event_base_t event_base, + int32_t event_id, void *event_data) { switch (event_id) { case IP_EVENT_STA_GOT_IP: @@ -292,7 +294,7 @@ static int wifi_cmd_query(int argc, char **argv) static uint32_t wifi_get_local_ip(void) { int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); - esp_netif_t * ifx = ap_netif; + esp_netif_t *ifx = ap_netif; esp_netif_ip_info_t ip_info; wifi_mode_t mode; @@ -323,6 +325,9 @@ static int wifi_cmd_iperf(int argc, char **argv) memset(&cfg, 0, sizeof(cfg)); + // wifi iperf only support IPV4 address + cfg.type = IPERF_IP_TYPE_IPV4; + if ( iperf_args.abort->count != 0) { iperf_stop(); return 0; @@ -337,15 +342,21 @@ static int wifi_cmd_iperf(int argc, char **argv) if (iperf_args.ip->count == 0) { cfg.flag |= IPERF_FLAG_SERVER; } else { - cfg.dip = esp_ip4addr_aton(iperf_args.ip->sval[0]); + cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]); cfg.flag |= IPERF_FLAG_CLIENT; } - cfg.sip = wifi_get_local_ip(); - if (cfg.sip == 0) { + cfg.source_ip4 = wifi_get_local_ip(); + if (cfg.source_ip4 == 0) { return 0; } + if (iperf_args.length->count == 0) { + cfg.len_send_buf = 0; + } else { + cfg.len_send_buf = iperf_args.length->ival[0]; + } + if (iperf_args.udp->count == 0) { cfg.flag |= IPERF_FLAG_TCP; } else { @@ -386,8 +397,10 @@ static int wifi_cmd_iperf(int argc, char **argv) ESP_LOGI(TAG, "mode=%s-%s sip=%d.%d.%d.%d:%d, dip=%d.%d.%d.%d:%d, interval=%d, time=%d", cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp", cfg.flag & IPERF_FLAG_SERVER ? "server" : "client", - cfg.sip & 0xFF, (cfg.sip >> 8) & 0xFF, (cfg.sip >> 16) & 0xFF, (cfg.sip >> 24) & 0xFF, cfg.sport, - cfg.dip & 0xFF, (cfg.dip >> 8) & 0xFF, (cfg.dip >> 16) & 0xFF, (cfg.dip >> 24) & 0xFF, cfg.dport, + cfg.source_ip4 & 0xFF, (cfg.source_ip4 >> 8) & 0xFF, (cfg.source_ip4 >> 16) & 0xFF, + (cfg.source_ip4 >> 24) & 0xFF, cfg.sport, + cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF, (cfg.destination_ip4 >> 16) & 0xFF, + (cfg.destination_ip4 >> 24) & 0xFF, cfg.dport, cfg.interval, cfg.time); iperf_start(&cfg); @@ -471,7 +484,9 @@ void register_wifi(void) iperf_args.ip = arg_str0("c", "client", "", "run in client mode, connecting to "); iperf_args.server = arg_lit0("s", "server", "run in server mode"); iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP"); + iperf_args.version = arg_lit0("V", "ipv6_domain", "use IPV6 address rather than IPV4"); iperf_args.port = arg_int0("p", "port", "", "server port to listen on/connect to"); + iperf_args.length = arg_int0("l", "len", "", "set read/write buffer size"); iperf_args.interval = arg_int0("i", "interval", "", "seconds between periodic bandwidth reports"); iperf_args.time = arg_int0("t", "time", "