net: zperf: Make shell dependency optional
Now that we a proper API, shell is just optional, so, make the dependency optional by refactoring the code. Also, add a build test combination in twister. Signed-off-by: Krishna T <krishna.t@nordicsemi.no>
This commit is contained in:
parent
cbef00587b
commit
59842531d1
6 changed files with 138 additions and 109 deletions
|
@ -5,13 +5,16 @@ zephyr_library_named(zperf)
|
|||
zephyr_library_sources(
|
||||
zperf_common.c
|
||||
zperf_session.c
|
||||
zperf_shell.c
|
||||
zperf_udp_receiver.c
|
||||
zperf_udp_uploader.c
|
||||
zperf_tcp_receiver.c
|
||||
zperf_tcp_uploader.c
|
||||
)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_NET_SHELL
|
||||
zperf_shell.c
|
||||
)
|
||||
|
||||
zephyr_library_include_directories(
|
||||
${ZEPHYR_BASE}/subsys/net/ip
|
||||
)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
menuconfig NET_ZPERF
|
||||
bool "zperf shell utility"
|
||||
depends on SHELL
|
||||
select NET_CONTEXT_RCVTIMEO if NET_NATIVE_UDP
|
||||
help
|
||||
This option enables zperf shell utility, which allows to generate
|
||||
|
|
|
@ -10,15 +10,124 @@
|
|||
#include "zperf_internal.h"
|
||||
#include "zperf_session.h"
|
||||
|
||||
LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
|
||||
LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
|
||||
|
||||
#define ZPERF_WORK_Q_THREAD_PRIORITY K_LOWEST_APPLICATION_THREAD_PRIO
|
||||
#define ZPERF_WORK_Q_STACK_SIZE 2048
|
||||
/* Get some useful debug routings from net_private.h, requires
|
||||
* that NET_LOG_ENABLED is set.
|
||||
*/
|
||||
#define NET_LOG_ENABLED 1
|
||||
#include "net_private.h"
|
||||
|
||||
#include "ipv6.h" /* to get infinite lifetime */
|
||||
|
||||
static struct sockaddr_in6 in6_addr_my = {
|
||||
.sin6_family = AF_INET6,
|
||||
.sin6_port = htons(MY_SRC_PORT),
|
||||
};
|
||||
|
||||
static struct sockaddr_in in4_addr_my = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(MY_SRC_PORT),
|
||||
};
|
||||
|
||||
struct sockaddr_in6 *zperf_get_sin6(void)
|
||||
{
|
||||
return &in6_addr_my;
|
||||
}
|
||||
|
||||
struct sockaddr_in *zperf_get_sin(void)
|
||||
{
|
||||
return &in4_addr_my;
|
||||
}
|
||||
|
||||
K_THREAD_STACK_DEFINE(zperf_work_q_stack, ZPERF_WORK_Q_STACK_SIZE);
|
||||
|
||||
static struct k_work_q zperf_work_q;
|
||||
|
||||
int zperf_get_ipv6_addr(char *host, char *prefix_str, struct in6_addr *addr)
|
||||
{
|
||||
struct net_if_ipv6_prefix *prefix;
|
||||
struct net_if_addr *ifaddr;
|
||||
int prefix_len;
|
||||
int ret;
|
||||
|
||||
if (!host) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_addr_pton(AF_INET6, host, addr);
|
||||
if (ret < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
prefix_len = strtoul(prefix_str, NULL, 10);
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(net_if_get_default(),
|
||||
addr, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
NET_ERR("Cannot set IPv6 address %s", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
prefix = net_if_ipv6_prefix_add(net_if_get_default(),
|
||||
addr, prefix_len,
|
||||
NET_IPV6_ND_INFINITE_LIFETIME);
|
||||
if (!prefix) {
|
||||
NET_ERR("Cannot set IPv6 prefix %s", prefix_str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int zperf_get_ipv4_addr(char *host, struct in_addr *addr)
|
||||
{
|
||||
struct net_if_addr *ifaddr;
|
||||
int ret;
|
||||
|
||||
if (!host) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_addr_pton(AF_INET, host, addr);
|
||||
if (ret < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv4_addr_add(net_if_get_default(),
|
||||
addr, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
NET_ERR("Cannot set IPv4 address %s", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const struct in_addr *zperf_get_default_if_in4_addr(void)
|
||||
{
|
||||
#if CONFIG_NET_IPV4
|
||||
return net_if_ipv4_select_src_addr(NULL,
|
||||
net_ipv4_unspecified_address());
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
const struct in6_addr *zperf_get_default_if_in6_addr(void)
|
||||
{
|
||||
#if CONFIG_NET_IPV6
|
||||
return net_if_ipv6_select_src_addr(NULL,
|
||||
net_ipv6_unspecified_address());
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
int zperf_prepare_upload_sock(const struct sockaddr *peer_addr, int tos,
|
||||
int proto)
|
||||
{
|
||||
|
@ -119,7 +228,10 @@ static int zperf_init(const struct device *unused)
|
|||
zperf_tcp_receiver_init();
|
||||
|
||||
zperf_session_init();
|
||||
zperf_shell_init();
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_SHELL)) {
|
||||
zperf_shell_init();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,12 @@
|
|||
|
||||
#define PACKET_SIZE_MAX CONFIG_NET_ZPERF_MAX_PACKET_SIZE
|
||||
|
||||
#define MY_SRC_PORT 50000
|
||||
#define DEF_PORT 5001
|
||||
#define DEF_PORT_STR STRINGIFY(DEF_PORT)
|
||||
|
||||
#define ZPERF_VERSION "1.1"
|
||||
|
||||
struct zperf_udp_datagram {
|
||||
int32_t id;
|
||||
uint32_t tv_sec;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
|
||||
LOG_MODULE_DECLARE(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
@ -31,7 +31,6 @@ LOG_MODULE_REGISTER(net_zperf, CONFIG_NET_ZPERF_LOG_LEVEL);
|
|||
|
||||
#include "ipv6.h" /* to get infinite lifetime */
|
||||
|
||||
#define DEVICE_NAME "zperf shell"
|
||||
|
||||
static const char *CONFIG =
|
||||
"unified"
|
||||
|
@ -49,14 +48,6 @@ static const char *CONFIG =
|
|||
#endif
|
||||
"";
|
||||
|
||||
#define MY_SRC_PORT 50000
|
||||
#define DEF_PORT 5001
|
||||
#define DEF_PORT_STR STRINGIFY(DEF_PORT)
|
||||
|
||||
#define ZPERF_VERSION "1.1"
|
||||
|
||||
static struct in6_addr ipv6;
|
||||
|
||||
static struct sockaddr_in6 in6_addr_my = {
|
||||
.sin6_family = AF_INET6,
|
||||
.sin6_port = htons(MY_SRC_PORT),
|
||||
|
@ -67,22 +58,21 @@ static struct sockaddr_in6 in6_addr_dst = {
|
|||
.sin6_port = htons(DEF_PORT),
|
||||
};
|
||||
|
||||
struct sockaddr_in6 *zperf_get_sin6(void)
|
||||
{
|
||||
return &in6_addr_my;
|
||||
}
|
||||
|
||||
static struct in_addr ipv4;
|
||||
static struct sockaddr_in in4_addr_dst = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(DEF_PORT),
|
||||
};
|
||||
|
||||
static struct sockaddr_in in4_addr_my = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(MY_SRC_PORT),
|
||||
};
|
||||
|
||||
static struct sockaddr_in in4_addr_dst = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(DEF_PORT),
|
||||
};
|
||||
static struct in6_addr ipv6;
|
||||
|
||||
static struct in_addr ipv4;
|
||||
|
||||
#define DEVICE_NAME "zperf shell"
|
||||
|
||||
const uint32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 };
|
||||
const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" };
|
||||
|
@ -136,11 +126,6 @@ static long parse_number(const char *string, const uint32_t *divisor_arr,
|
|||
return (*divisor == 0U) ? dec : dec * *divisor;
|
||||
}
|
||||
|
||||
struct sockaddr_in *zperf_get_sin(void)
|
||||
{
|
||||
return &in4_addr_my;
|
||||
}
|
||||
|
||||
static int parse_ipv6_addr(const struct shell *sh, char *host, char *port,
|
||||
struct sockaddr_in6 *addr)
|
||||
{
|
||||
|
@ -167,42 +152,6 @@ static int parse_ipv6_addr(const struct shell *sh, char *host, char *port,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int zperf_get_ipv6_addr(char *host, char *prefix_str, struct in6_addr *addr)
|
||||
{
|
||||
struct net_if_ipv6_prefix *prefix;
|
||||
struct net_if_addr *ifaddr;
|
||||
int prefix_len;
|
||||
int ret;
|
||||
|
||||
if (!host) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_addr_pton(AF_INET6, host, addr);
|
||||
if (ret < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
prefix_len = strtoul(prefix_str, NULL, 10);
|
||||
|
||||
ifaddr = net_if_ipv6_addr_add(net_if_get_default(),
|
||||
addr, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
NET_ERR("Cannot set IPv6 address %s", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
prefix = net_if_ipv6_prefix_add(net_if_get_default(),
|
||||
addr, prefix_len,
|
||||
NET_IPV6_ND_INFINITE_LIFETIME);
|
||||
if (!prefix) {
|
||||
NET_ERR("Cannot set IPv6 prefix %s", prefix_str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_ipv4_addr(const struct shell *sh, char *host, char *port,
|
||||
struct sockaddr_in *addr)
|
||||
{
|
||||
|
@ -229,50 +178,6 @@ static int parse_ipv4_addr(const struct shell *sh, char *host, char *port,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int zperf_get_ipv4_addr(char *host, struct in_addr *addr)
|
||||
{
|
||||
struct net_if_addr *ifaddr;
|
||||
int ret;
|
||||
|
||||
if (!host) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = net_addr_pton(AF_INET, host, addr);
|
||||
if (ret < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ifaddr = net_if_ipv4_addr_add(net_if_get_default(),
|
||||
addr, NET_ADDR_MANUAL, 0);
|
||||
if (!ifaddr) {
|
||||
NET_ERR("Cannot set IPv4 address %s", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct in_addr *zperf_get_default_if_in4_addr(void)
|
||||
{
|
||||
#if CONFIG_NET_IPV4
|
||||
return net_if_ipv4_select_src_addr(NULL,
|
||||
net_ipv4_unspecified_address());
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
const struct in6_addr *zperf_get_default_if_in6_addr(void)
|
||||
{
|
||||
#if CONFIG_NET_IPV6
|
||||
return net_if_ipv6_select_src_addr(NULL,
|
||||
net_ipv6_unspecified_address());
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int cmd_setip(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
int start = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue