net: lib: zperf: optional server support

Make the zperf server support optional, if only upload throughput
testing is required. This reduces the resources required to operate.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2025-04-17 15:57:04 +10:00 committed by Benjamin Cabé
commit 82d767585d
5 changed files with 42 additions and 5 deletions

View file

@ -296,6 +296,10 @@ Networking
:c:macro:`HTTPS_SERVICE_DEFINE_EMPTY`, :c:macro:`HTTP_SERVICE_DEFINE` and
:c:macro:`HTTPS_SERVICE_DEFINE`.
* :kconfig:option:`NET_ZPERF` no longer includes server support by default. To use
the server commands, enable :kconfig:option:`NET_ZPERF_SERVER`. If server support
is not needed, :kconfig:option:`ZVFS_POLL_MAX` can possibly be reduced.
SPI
===

View file

@ -4,13 +4,16 @@ zephyr_library_named(zperf)
zephyr_library_sources(
zperf_common.c
zperf_session.c
zperf_udp_receiver.c
zperf_udp_uploader.c
zperf_tcp_receiver.c
zperf_tcp_uploader.c
)
if(CONFIG_NET_ZPERF_SERVER)
zephyr_library_sources(zperf_session.c)
zephyr_library_sources(zperf_udp_receiver.c)
zephyr_library_sources(zperf_tcp_receiver.c)
endif()
zephyr_library_sources_ifdef(CONFIG_NET_SHELL
zperf_shell.c
)

View file

@ -5,7 +5,6 @@
menuconfig NET_ZPERF
bool "zperf library"
select NET_CONTEXT_RCVTIMEO if NET_NATIVE_UDP
select NET_SOCKETS_SERVICE
select NET_SOCKETS
help
This option enables zperf library, which allows to generate
@ -47,8 +46,15 @@ config NET_ZPERF_MAX_PACKET_SIZE
help
Upper size limit for packets sent by zperf.
config NET_ZPERF_SERVER
bool "zperf server support"
select NET_SOCKETS_SERVICE
help
Support running a zperf server for testing downloads from the application
config NET_ZPERF_MAX_SESSIONS
int "Maximum number of zperf sessions"
depends on NET_ZPERF_SERVER
default 4
help
Upper size limit for connections handled by zperf.

View file

@ -237,7 +237,9 @@ static int zperf_init(void)
zperf_udp_uploader_init();
zperf_tcp_uploader_init();
if (IS_ENABLED(CONFIG_NET_ZPERF_SERVER)) {
zperf_session_init();
}
if (IS_ENABLED(CONFIG_NET_SHELL)) {
zperf_shell_init();

View file

@ -200,6 +200,8 @@ static int parse_ipv4_addr(const struct shell *sh, char *host, char *port,
return 0;
}
#ifdef CONFIG_NET_ZPERF_SERVER
static int zperf_bind_host(const struct shell *sh,
size_t argc, char *argv[],
struct zperf_download_params *param)
@ -233,6 +235,8 @@ static int zperf_bind_host(const struct shell *sh,
return 0;
}
#endif
static int cmd_setip(const struct shell *sh, size_t argc, char *argv[])
{
int start = 0;
@ -311,6 +315,8 @@ static int cmd_setip(const struct shell *sh, size_t argc, char *argv[])
return 0;
}
#ifdef CONFIG_NET_ZPERF_SERVER
static void udp_session_cb(enum zperf_status status,
struct zperf_results *result,
void *user_data)
@ -475,6 +481,8 @@ static int cmd_udp_download(const struct shell *sh, size_t argc,
}
}
#endif
static void shell_udp_upload_print_stats(const struct shell *sh,
struct zperf_results *results)
{
@ -1291,6 +1299,8 @@ static int cmd_connectap(const struct shell *sh, size_t argc, char *argv[])
return 0;
}
#ifdef CONFIG_NET_ZPERF_SERVER
static void tcp_session_cb(enum zperf_status status,
struct zperf_results *result,
void *user_data)
@ -1395,6 +1405,8 @@ static int cmd_tcp_download(const struct shell *sh, size_t argc,
}
}
#endif
static int cmd_version(const struct shell *sh, size_t argc, char *argv[])
{
shell_fprintf(sh, SHELL_NORMAL, "Version: %s\nConfig: %s\n",
@ -1454,11 +1466,15 @@ void zperf_shell_init(void)
}
}
#ifdef CONFIG_NET_ZPERF_SERVER
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp_download,
SHELL_CMD(stop, NULL, "Stop TCP server\n", cmd_tcp_download_stop),
SHELL_SUBCMD_SET_END
);
#endif
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp,
SHELL_CMD(upload, NULL,
"[<options>] <dest ip> <dest port> <duration> <packet size>[K]\n"
@ -1510,18 +1526,22 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp,
#endif
,
cmd_tcp_upload2),
#ifdef CONFIG_NET_ZPERF_SERVER
SHELL_CMD(download, &zperf_cmd_tcp_download,
"[<port>]: Server port to listen on/connect to\n"
"[<host>]: Bind to <host>, an interface address\n"
"Example: tcp download 5001 192.168.0.1\n",
cmd_tcp_download),
#endif
SHELL_SUBCMD_SET_END
);
#ifdef CONFIG_NET_ZPERF_SERVER
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp_download,
SHELL_CMD(stop, NULL, "Stop UDP server\n", cmd_udp_download_stop),
SHELL_SUBCMD_SET_END
);
#endif
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp,
SHELL_CMD(upload, NULL,
@ -1577,6 +1597,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp,
#endif
,
cmd_udp_upload2),
#ifdef CONFIG_NET_ZPERF_SERVER
SHELL_CMD(download, &zperf_cmd_udp_download,
"[<options>] command options (optional): [-I eth0]\n"
"[<port>]: Server port to listen on/connect to\n"
@ -1585,6 +1606,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp,
"-I <interface name>: Specify host interface name\n"
"Example: udp download 5001 192.168.0.1\n",
cmd_udp_download),
#endif
SHELL_SUBCMD_SET_END
);