Morse Micro IoT SDK  2.9.7
iperf.c File Reference

Detailed Description

Throughput measurement using iperf.

Note
It is assumed that you have followed the steps in the Getting Started guide and are therefore familiar with how to build, flash, and monitor an application using the MM-IoT-SDK framework.

This file demonstrates how to run iperf using the Morse Micro WLAN API.

This file loads the required Wi-Fi and iperf parameters like SSID and password from the config store to initialize the wlan interface.

See Application helper routines for Wireless LAN interface for details of WLAN and IP stack configuration. Additional configuration options for this application can be found in the config.hjson file.

Definition in file iperf.c.

#include <string.h>
#include "mmosal.h"
#include "mmwlan.h"
#include "mmconfig.h"
#include "mmiperf.h"
#include "mmipal.h"
#include "mm_app_common.h"
Include dependency graph for iperf.c:

Go to the source code of this file.

Macros

#define IPERF_TYPE   IPERF_UDP_SERVER
 Type of iperf instance to start. More...
 
#define IPERF_TIME_AMOUNT   -10
 Duration for client transfers specified either in seconds or bytes. More...
 
#define IPERF_SERVER_PORT   5001
 Specifies the port to listen on in server mode. More...
 

Enumerations

enum  iperf_type { IPERF_TCP_SERVER , IPERF_UDP_SERVER , IPERF_TCP_CLIENT , IPERF_UDP_CLIENT }
 Iperf configurations. More...
 

Functions

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. More...
 
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. More...
 
static void start_tcp_client (void)
 Start iperf as a TCP client. More...
 
static void start_udp_client (void)
 Start iperf as a UDP client. More...
 
static void start_tcp_server (void)
 Start iperf as a TCP server. More...
 
static void start_udp_server (void)
 Start iperf as a UDP server. More...
 
void app_init (void)
 Main entry point to the application. More...
 

Variables

static const char units [] = {' ', 'K', 'M', 'G', 'T'}
 Array of power of 10 unit specifiers. More...
 

Macro Definition Documentation

◆ IPERF_SERVER_PORT

#define IPERF_SERVER_PORT   5001

Specifies the port to listen on in server mode.

Definition at line 59 of file iperf.c.

◆ IPERF_TIME_AMOUNT

#define IPERF_TIME_AMOUNT   -10

Duration for client transfers specified either in seconds or bytes.

If this is negative, it specifies a time in seconds; if positive, it specifies the number of bytes to transmit.

Definition at line 55 of file iperf.c.

◆ IPERF_TYPE

#define IPERF_TYPE   IPERF_UDP_SERVER

Type of iperf instance to start.

Definition at line 46 of file iperf.c.

Enumeration Type Documentation

◆ iperf_type

enum iperf_type

Iperf configurations.

Enumerator
IPERF_TCP_SERVER 

TCP server (RX)

IPERF_UDP_SERVER 

UDP server (RX)

IPERF_TCP_CLIENT 

TCP client (TX)

IPERF_UDP_CLIENT 

UDP client (TX)

Definition at line 36 of file iperf.c.

Function Documentation

◆ app_init()

void app_init ( void  )

Main entry point to the application.

This will be invoked in a thread once operating system and hardware initialization has completed. It may return, but it does not have to.

Definition at line 282 of file iperf.c.

◆ format_bytes()

static uint32_t format_bytes ( uint64_t  bytes,
uint8_t *  unit_index 
)
static

Function to format a given number of bytes into an appropriate SI base.

I.e if you give it 1400 it will return 1 with unit_index set to 1 for Kilo.

Warning
This uses power of 10 units (kilo, mega, giga, etc). Not to be confused with power of 2 units (kibi, mebi, gibi, etc).
Parameters
[in]bytesOriginal number of bytes
[out]unit_indexIndex into the units array. Must not be NULL
Returns
Number of bytes formatted to the appropriate unit given by the unit index.

Definition at line 79 of file iperf.c.

◆ iperf_report_handler()

static void iperf_report_handler ( const struct mmiperf_report report,
void *  arg,
mmiperf_handle_t  handle 
)
static

Handle a report at the end of an iperf transfer.

Parameters
reportThe iperf report.
argOpaque argument specified when iperf was started.
handleThe iperf instance handle returned when iperf was started.

Definition at line 100 of file iperf.c.

◆ start_tcp_client()

static void start_tcp_client ( void  )
static

Start iperf as a TCP client.

Definition at line 126 of file iperf.c.

◆ start_tcp_server()

static void start_tcp_server ( void  )
static

Start iperf as a TCP server.

Definition at line 206 of file iperf.c.

◆ start_udp_client()

static void start_udp_client ( void  )
static

Start iperf as a UDP client.

Definition at line 166 of file iperf.c.

◆ start_udp_server()

static void start_udp_server ( void  )
static

Start iperf as a UDP server.

Definition at line 242 of file iperf.c.

Variable Documentation

◆ units

const char units[] = {' ', 'K', 'M', 'G', 'T'}
static

Array of power of 10 unit specifiers.

Definition at line 65 of file iperf.c.