netutils/iperf: Support RPMsg socket test
Usage: iperf -s --rpmsg <name> iperf -c <cpu> --rpmsg <name> Note: RPMsg with SOCK_DGRAM (`-u`) doesn't have server mode (bind) yet, iperf may not work in this case before rpsock is enhanced. Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
213219f30a
commit
f2819b71e5
@ -26,6 +26,7 @@
|
||||
#include <assert.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netpacket/rpmsg.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdbool.h>
|
||||
@ -232,6 +233,15 @@ static void iperf_print_addr(FAR const char *str, FAR struct sockaddr *addr)
|
||||
return;
|
||||
}
|
||||
|
||||
case AF_RPMSG:
|
||||
{
|
||||
FAR struct sockaddr_rpmsg *rpaddr =
|
||||
(FAR struct sockaddr_rpmsg *)addr;
|
||||
printf("%s: cpu=%s,name=%s\n", str,
|
||||
rpaddr->rp_cpu, rpaddr->rp_name);
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false); /* shouldn't happen */
|
||||
}
|
||||
@ -391,6 +401,18 @@ static int iperf_run_server(FAR struct iperf_ctrl_t *ctrl,
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strlcpy(addr.sun_path, ctrl->cfg.path, sizeof(addr.sun_path));
|
||||
|
||||
return server_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr),
|
||||
(FAR struct sockaddr *)&remote_addr);
|
||||
}
|
||||
else if (ctrl->cfg.flag & IPERF_FLAG_RPMSG)
|
||||
{
|
||||
struct sockaddr_rpmsg addr;
|
||||
struct sockaddr_rpmsg remote_addr;
|
||||
|
||||
addr.rp_family = AF_RPMSG;
|
||||
strlcpy(addr.rp_cpu, ctrl->cfg.host, sizeof(addr.rp_cpu));
|
||||
strlcpy(addr.rp_name, ctrl->cfg.path, sizeof(addr.rp_name));
|
||||
|
||||
return server_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr),
|
||||
(FAR struct sockaddr *)&remote_addr);
|
||||
}
|
||||
@ -426,6 +448,16 @@ static int iperf_run_client(FAR struct iperf_ctrl_t *ctrl,
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strlcpy(addr.sun_path, ctrl->cfg.path, sizeof(addr.sun_path));
|
||||
|
||||
return client_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
else if (ctrl->cfg.flag & IPERF_FLAG_RPMSG)
|
||||
{
|
||||
struct sockaddr_rpmsg addr;
|
||||
|
||||
addr.rp_family = AF_RPMSG;
|
||||
strlcpy(addr.rp_cpu, ctrl->cfg.host, sizeof(addr.rp_cpu));
|
||||
strlcpy(addr.rp_name, ctrl->cfg.path, sizeof(addr.rp_name));
|
||||
|
||||
return client_func(ctrl, (FAR struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
else
|
||||
|
@ -49,6 +49,7 @@ extern "C"
|
||||
#define IPERF_FLAG_TCP (1 << 2)
|
||||
#define IPERF_FLAG_UDP (1 << 3)
|
||||
#define IPERF_FLAG_LOCAL (1 << 4)
|
||||
#define IPERF_FLAG_RPMSG (1 << 5)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@ -63,6 +64,7 @@ struct iperf_cfg_t
|
||||
uint16_t sport;
|
||||
uint32_t interval;
|
||||
uint32_t time;
|
||||
FAR const char *host; /* host name (dip) or rpmsg cpu */
|
||||
FAR const char *path; /* local path or rpmsg name */
|
||||
};
|
||||
|
||||
|
@ -57,6 +57,7 @@ struct wifi_iperf_t
|
||||
FAR struct arg_lit *server;
|
||||
FAR struct arg_lit *udp;
|
||||
FAR struct arg_str *local;
|
||||
FAR struct arg_str *rpmsg;
|
||||
FAR struct arg_int *port;
|
||||
FAR struct arg_int *interval;
|
||||
FAR struct arg_int *time;
|
||||
@ -79,8 +80,8 @@ struct wifi_iperf_t
|
||||
static void iperf_showusage(FAR const char *progname,
|
||||
FAR struct wifi_iperf_t *args, int exitcode)
|
||||
{
|
||||
printf("USAGE: %s [-sua] [-c <ip>] [-p <port>] [-i <interval>] "
|
||||
"[-t <time>] [--local <path>]\n", progname);
|
||||
printf("USAGE: %s [-sua] [-c <ip|cpu>] [-p <port>] [-i <interval>] "
|
||||
"[-t <time>] [--local <path>] [--rpmsg <name>]\n", progname);
|
||||
printf("iperf command:\n");
|
||||
arg_print_glossary(stdout, (FAR void **)args, NULL);
|
||||
|
||||
@ -99,7 +100,8 @@ static void iperf_showusage(FAR const char *progname,
|
||||
static void iperf_printcfg(FAR struct iperf_cfg_t *cfg)
|
||||
{
|
||||
printf("\n mode=%s%s-%s ",
|
||||
cfg->flag & IPERF_FLAG_LOCAL ? "local-":"",
|
||||
cfg->flag & IPERF_FLAG_LOCAL ? "local-":
|
||||
cfg->flag & IPERF_FLAG_RPMSG ? "rpmsg-":"",
|
||||
cfg->flag & IPERF_FLAG_TCP ? "tcp":"udp",
|
||||
cfg->flag & IPERF_FLAG_SERVER ? "server":"client");
|
||||
|
||||
@ -107,6 +109,10 @@ static void iperf_printcfg(FAR struct iperf_cfg_t *cfg)
|
||||
{
|
||||
printf("path=%s, ", cfg->path);
|
||||
}
|
||||
else if (cfg->flag & IPERF_FLAG_RPMSG)
|
||||
{
|
||||
printf("cpu=%s, name=%s, ", cfg->host, cfg->path);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("sip=%" PRId32 ".%" PRId32 ".%" PRId32 ".%" PRId32 ":%d,"
|
||||
@ -141,6 +147,7 @@ int main(int argc, FAR char *argv[])
|
||||
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.local = arg_str0(NULL, "local", "<path>", "use local socket");
|
||||
iperf_args.rpmsg = arg_str0(NULL, "rpmsg", "<name>", "use RPMsg socket");
|
||||
iperf_args.port = arg_int0("p", "port", "<port>",
|
||||
"server port to listen on/connect to");
|
||||
iperf_args.interval = arg_int0("i", "interval", "<interval>",
|
||||
@ -177,11 +184,13 @@ int main(int argc, FAR char *argv[])
|
||||
|
||||
if (iperf_args.ip->count == 0)
|
||||
{
|
||||
cfg.host = "";
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
}
|
||||
else
|
||||
{
|
||||
cfg.dip = inet_addr(iperf_args.ip->sval[0]);
|
||||
cfg.dip = inet_addr(iperf_args.ip->sval[0]);
|
||||
cfg.host = iperf_args.ip->sval[0];
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
@ -206,6 +215,11 @@ int main(int argc, FAR char *argv[])
|
||||
iperf_showusage(argv[0], &iperf_args, 0);
|
||||
}
|
||||
}
|
||||
else if (iperf_args.rpmsg->count > 0)
|
||||
{
|
||||
cfg.flag |= IPERF_FLAG_RPMSG;
|
||||
cfg.path = iperf_args.rpmsg->sval[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
netlib_get_ipv4addr(DEVNAME, &addr);
|
||||
|
Loading…
Reference in New Issue
Block a user