net: zperf: Add shell command to stop TCP/UDP server

Add zperf shell command to stop TCP/UDP server.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2022-11-30 15:00:27 +01:00 committed by Carles Cufí
commit dd3fb692fe

View file

@ -367,6 +367,22 @@ static void udp_session_cb(enum zperf_status status,
}
}
static int cmd_udp_download_stop(const struct shell *sh, size_t argc,
char *argv[])
{
int ret;
ret = zperf_udp_download_stop();
if (ret < 0) {
shell_fprintf(sh, SHELL_WARNING, "UDP server not running!\n");
return -ENOEXEC;
}
shell_fprintf(sh, SHELL_NORMAL, "UDP server stopped\n");
return 0;
}
static int cmd_udp_download(const struct shell *sh, size_t argc,
char *argv[])
{
@ -1055,6 +1071,22 @@ static void tcp_session_cb(enum zperf_status status,
}
}
static int cmd_tcp_download_stop(const struct shell *sh, size_t argc,
char *argv[])
{
int ret;
ret = zperf_tcp_download_stop();
if (ret < 0) {
shell_fprintf(sh, SHELL_WARNING, "TCP server not running!\n");
return -ENOEXEC;
}
shell_fprintf(sh, SHELL_NORMAL, "TCP server stopped\n");
return 0;
}
static int cmd_tcp_download(const struct shell *sh, size_t argc,
char *argv[])
{
@ -1162,6 +1194,11 @@ static void zperf_init(const struct shell *sh)
zperf_session_init();
}
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
);
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp,
SHELL_CMD(upload, NULL,
"[<options>] <dest ip> <dest port> <duration> <packet size>[K]\n"
@ -1199,13 +1236,18 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_tcp,
#endif
,
cmd_tcp_upload2),
SHELL_CMD(download, NULL,
SHELL_CMD(download, &zperf_cmd_tcp_download,
"[<port>]\n"
"Example: tcp download 5001\n",
cmd_tcp_download),
SHELL_SUBCMD_SET_END
);
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
);
SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp,
SHELL_CMD(upload, NULL,
"[<options>] <dest ip> [<dest port> <duration> <packet size>[K] "
@ -1246,7 +1288,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(zperf_cmd_udp,
#endif
,
cmd_udp_upload2),
SHELL_CMD(download, NULL,
SHELL_CMD(download, &zperf_cmd_udp_download,
"[<port>]\n"
"Example: udp download 5001\n",
cmd_udp_download),