samples: net: zperf: Fix UDP uploader

Try to construct a proper iperf client header to the payload
as the server expects that. It is not sure if this is proper
way to do the iperf header as there is no documentation about
iPerf protocol anyway (except the iPerf source code).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-03-19 17:20:50 +02:00 committed by Anas Nashif
commit cbeeb510c0
3 changed files with 47 additions and 5 deletions

View file

@ -69,6 +69,15 @@ struct zperf_udp_datagram {
u32_t tv_usec;
};
struct zperf_client_hdr_v1 {
s32_t flags;
s32_t num_of_threads;
s32_t port;
s32_t buffer_len;
s32_t bandwidth;
s32_t num_of_bytes;
};
struct zperf_server_hdr {
s32_t flags;
s32_t total_len1;
@ -97,6 +106,7 @@ struct sockaddr_in *zperf_get_sin(void);
extern void zperf_udp_upload(const struct shell *shell,
struct net_context *context,
int port,
unsigned int duration_in_ms,
unsigned int packet_size,
unsigned int rate_in_kbps,

View file

@ -536,6 +536,7 @@ static int execute_upload(const struct shell *shell,
struct sockaddr_in6 *ipv6,
struct sockaddr_in *ipv4,
bool is_udp,
int port,
char *argv0,
unsigned int duration_in_ms,
unsigned int packet_size,
@ -584,7 +585,7 @@ static int execute_upload(const struct shell *shell,
goto out;
}
zperf_udp_upload(shell, context6, duration_in_ms,
zperf_udp_upload(shell, context6, port, duration_in_ms,
packet_size, rate_in_kbps, &results);
shell_udp_upload_print_stats(shell, &results);
}
@ -603,7 +604,7 @@ static int execute_upload(const struct shell *shell,
goto out;
}
zperf_udp_upload(shell, context4, duration_in_ms,
zperf_udp_upload(shell, context4, port, duration_in_ms,
packet_size, rate_in_kbps, &results);
shell_udp_upload_print_stats(shell, &results);
}
@ -812,7 +813,7 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
}
return execute_upload(shell, context6, context4, family, &ipv6, &ipv4,
is_udp, argv[start], duration_in_ms,
is_udp, port, argv[start], duration_in_ms,
packet_size, rate_in_kbps);
}
@ -931,7 +932,7 @@ static int shell_cmd_upload2(const struct shell *shell, size_t argc,
}
return execute_upload(shell, context6, context4, family, &in6_addr_dst,
&in4_addr_dst, is_udp, argv[start],
&in4_addr_dst, is_udp, port, argv[start],
duration_in_ms, packet_size, rate_in_kbps);
}

View file

@ -18,7 +18,9 @@ LOG_MODULE_DECLARE(net_zperf_sample, LOG_LEVEL_DBG);
#include "zperf.h"
#include "zperf_internal.h"
static u8_t sample_packet[sizeof(struct zperf_udp_datagram) + PACKET_SIZE_MAX];
static u8_t sample_packet[sizeof(struct zperf_udp_datagram) +
sizeof(struct zperf_client_hdr_v1) +
PACKET_SIZE_MAX];
static inline void zperf_upload_decode_stat(const struct shell *shell,
struct net_pkt *pkt,
@ -78,6 +80,7 @@ static inline void zperf_upload_fin(const struct shell *shell,
{
struct net_pkt *stat = NULL;
struct zperf_udp_datagram *datagram;
struct zperf_client_hdr_v1 *hdr;
int loop = 2;
int ret;
@ -90,6 +93,22 @@ static inline void zperf_upload_fin(const struct shell *shell,
datagram->tv_usec = htonl(HW_CYCLES_TO_USEC(end_time) %
USEC_PER_SEC);
hdr = (struct zperf_client_hdr_v1 *)(sample_packet +
sizeof(*datagram));
/* According to iperf documentation (in include/Settings.hpp),
* if the flags == 0, then the other values are ignored.
* But even if the values in the header are ignored, try
* to set there some meaningful values.
*/
hdr->flags = 0;
hdr->num_of_threads = htonl(1);
hdr->port = 0;
hdr->buffer_len = sizeof(sample_packet) -
sizeof(*datagram) - sizeof(*hdr);
hdr->bandwidth = 0;
hdr->num_of_bytes = htonl(packet_size);
/* Send the packet */
ret = net_context_send(context, sample_packet, packet_size,
NULL, K_NO_WAIT, NULL);
@ -138,6 +157,7 @@ static inline void zperf_upload_fin(const struct shell *shell,
void zperf_udp_upload(const struct shell *shell,
struct net_context *context,
int port,
unsigned int duration_in_ms,
unsigned int packet_size,
unsigned int rate_in_kbps,
@ -173,6 +193,7 @@ void zperf_udp_upload(const struct shell *shell,
do {
struct zperf_udp_datagram *datagram;
struct zperf_client_hdr_v1 *hdr;
u32_t loop_time;
s32_t adjust;
int ret;
@ -206,6 +227,16 @@ void zperf_udp_upload(const struct shell *shell,
datagram->tv_usec =
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
hdr = (struct zperf_client_hdr_v1 *)(sample_packet +
sizeof(*datagram));
hdr->flags = 0;
hdr->num_of_threads = htonl(1);
hdr->port = htonl(port);
hdr->buffer_len = sizeof(sample_packet) -
sizeof(*datagram) - sizeof(*hdr);
hdr->bandwidth = htonl(rate_in_kbps);
hdr->num_of_bytes = htonl(packet_size);
/* Send the packet */
ret = net_context_send(context, sample_packet, packet_size,
NULL, K_NO_WAIT, NULL);