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
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue