46#define IPERF_TYPE IPERF_UDP_SERVER
49#ifndef IPERF_TIME_AMOUNT
55#define IPERF_TIME_AMOUNT -10
57#ifndef IPERF_SERVER_PORT
59#define IPERF_SERVER_PORT 5001
65static const char units[] = {
' ',
'K',
'M',
'G',
'T'};
84 while (bytes >= 1000 && *unit_index < 4)
106 uint8_t bytes_transferred_unit_index = 0;
108 &bytes_transferred_unit_index);
110 printf(
"\nIperf Report\n");
113 printf(
" Transferred: %lu %cBytes, duration: %lu ms, bandwidth: %lu kbps\n",
114 bytes_transferred_formatted,
units[bytes_transferred_unit_index],
121 printf(
"Waiting for client to connect...\n");
128 uint32_t server_port = 0;
140 printf(
"Failed to retrieve IP config\n");
149 printf(
"Attempting to connect to %s:%d over TCP\n", args.
server_addr,
162 printf(
"\nIperf TCP client started, waiting for completion...\n");
168 uint32_t server_port = 0;
180 printf(
"Failed to retrieve IP config\n");
189 printf(
"Attempting to connect to %s:%d over UDP\n", args.
server_addr,
202 printf(
"\nIperf UDP client started, waiting for completion...\n");
217 if (iperf_handle == NULL)
219 printf(
"Failed to get local address\n");
222 printf(
"\nIperf TCP server started, waiting for client to connect...\n");
228 printf(
"Execute cmd on AP 'iperf -c %s -p %u -i 1' for IPv4\n",
236 printf(
"Execute cmd on AP 'iperf -c %s%%wlan0 -p %u -i 1 -V' for IPv6\n",
253 if (iperf_handle == NULL)
255 printf(
"Failed to start iperf server\n");
259 printf(
"\nIperf UDP server started, waiting for client to connect...\n");
265 printf(
"Execute cmd on AP 'iperf -c %s -p %u -i 1 -u -b 20M' for IPv4\n",
273 printf(
"Execute cmd on AP 'iperf -c %s%%wlan0 -p %u -i 1 -V -u -b 20M' for IPv6\n",
284 printf(
"\n\nMorse Iperf Demo (Built " __DATE__
" " __TIME__
")\n\n");
291 char iperf_mode_str[32];
294 if (strncmp(iperf_mode_str,
"udp_server",
sizeof(iperf_mode_str)) == 0)
298 else if (strncmp(iperf_mode_str,
"tcp_server",
sizeof(iperf_mode_str)) == 0)
302 else if (strncmp(iperf_mode_str,
"tcp_client",
sizeof(iperf_mode_str)) == 0)
306 else if (strncmp(iperf_mode_str,
"udp_client",
sizeof(iperf_mode_str)) == 0)
312 printf(
"Unsupported iperf mode: %s\n", iperf_mode_str);
int mmconfig_read_string(const char *key, char *buffer, int bufsize)
Returns the persistent store string value identified by the key.
int mmconfig_read_int(const char *key, int *value)
Returns the integer stored in persistent store identified by the key.
int mmconfig_read_uint32(const char *key, uint32_t *value)
Returns the unsigned integer stored in persistent store identified by the key.
enum mmipal_status mmipal_get_ip6_config(struct mmipal_ip6_config *config)
Get the IP configurations.
#define MMIPAL_IP_CONFIG_DEFAULT
Initializer for mmipal_ip_config.
mmipal_status
Enumeration of status codes returned by MMIPAL functions.
enum mmipal_status mmipal_get_ip_config(struct mmipal_ip_config *config)
Get the IP configurations.
@ MMIPAL_SUCCESS
Completed successfully.
mmiperf_handle_t mmiperf_start_tcp_client(const struct mmiperf_client_args *args)
Start a TCP iperf client.
#define MMIPERF_CLIENT_ARGS_DEFAULT
Initializer for mmiperf_client_args.
mmiperf_handle_t mmiperf_start_udp_client(const struct mmiperf_client_args *args)
Start a UDP iperf client.
mmiperf_handle_t mmiperf_start_udp_server(const struct mmiperf_server_args *args)
Start a UDP iperf server.
#define MMIPERF_DEFAULT_PORT
Default port for TCP and UDP iperf.
#define MMIPERF_SERVER_ARGS_DEFAULT
Initializer for mmiperf_server_args.
struct mmiperf_state * mmiperf_handle_t
Iperf client/server handle.
mmiperf_handle_t mmiperf_start_tcp_server(const struct mmiperf_server_args *args)
Start a TCP iperf server.
@ MMIPERF_UDP_DONE_SERVER
The server side test is done.
@ MMIPERF_TCP_DONE_SERVER
The server side test is done.
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
static void start_tcp_client(void)
Start iperf as a TCP client.
static const char units[]
Array of power of 10 unit specifiers.
static void start_udp_client(void)
Start iperf as a UDP client.
static void start_tcp_server(void)
Start iperf as a TCP server.
iperf_type
Iperf configurations.
@ IPERF_TCP_SERVER
TCP server (RX)
@ IPERF_TCP_CLIENT
TCP client (TX)
@ IPERF_UDP_CLIENT
UDP client (TX)
@ IPERF_UDP_SERVER
UDP server (RX)
static void iperf_report_handler(const struct mmiperf_report *report, void *arg, mmiperf_handle_t handle)
Handle a report at the end of an iperf transfer.
#define IPERF_SERVER_PORT
Specifies the port to listen on in server mode.
static uint32_t format_bytes(uint64_t bytes, uint8_t *unit_index)
Function to format a given number of bytes into an appropriate SI base.
static void start_udp_server(void)
Start iperf as a UDP server.
#define IPERF_TIME_AMOUNT
Duration for client transfers specified either in seconds or bytes.
#define IPERF_TYPE
Type of iperf instance to start.
void app_init(void)
Main entry point to the application.
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_wlan_init(void)
Initializes the WLAN interface (and dependencies) using settings specified in the config store.
void app_wlan_start(void)
Starts the WLAN interface and connects to Wi-Fi using settings specified in the config store.
IPv6 configuration structure.
mmipal_ip_addr_t ip6_addr[MMIPAL_MAX_IPV6_ADDRESSES]
Array of IPv6 addresses.
IPv4 configuration structure.
mmipal_ip_addr_t gateway_addr
Gateway address.
mmipal_ip_addr_t ip_addr
local IP address
Iperf client arguments data structure.
char server_addr[MMIPERF_IPADDR_MAXLEN]
IP address of iperf server to communicate with (as a string).
mmiperf_report_fn report_fn
Report callback function to invoke on completion/abort.
int32_t amount
If positive specifies how many bytes to transfer; if negative the absolute value specifies the durati...
uint16_t server_port
Port on iperf server to communicate with.
enum mmiperf_report_type report_type
Type of report.
char local_addr[MMIPERF_IPADDR_MAXLEN]
Local address (as string).
uint16_t local_port
Local port.
uint16_t remote_port
Remote port.
uint32_t bandwidth_kbitpsec
Average throughput in kbps.
char remote_addr[MMIPERF_IPADDR_MAXLEN]
Remote address (as string).
uint64_t bytes_transferred
Number of bytes of data transferred during test.
uint32_t duration_ms
Duration of the test in milliseconds.
Iperf server arguments data structure.
mmiperf_report_fn report_fn
Report callback function to invoke on completion/abort.
uint16_t local_port
Local port to listen on.