Microchip® Advanced Software Framework

ttcp.c File Reference
#include "lwip/opt.h"
#include "lwip/mem.h"
#include "lwip/raw.h"
#include "lwip/icmp.h"
#include "lwip/netif.h"
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "lwip/inet_chksum.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include <net/ttcp.h>
#include <ports/avr32/timer.h>
#include <util/util.h>
#include <net/lwip_setup.h>
#include "getopt.h"
#include <wl/cmd_wl.h>

Data Structures

struct  ttcp
 

Macros

#define TTCP_MODE_RECEIVE   1
 
#define TTCP_MODE_TRANSMIT   0
 

Typedefs

typedef void( ttcp_done_cb_t )(void *opaque, int result)
 

Functions

cmd_state_t cmd_ttcp (int argc, char *argv[], void *ctx)
 
static err_t tcp_accept_cb (void *arg, struct tcp_pcb *newpcb, err_t err)
 Only used in TCP mode. More...
 
static void tcp_conn_err_cb (void *arg, err_t err)
 Only used in TCP mode. More...
 
static err_t tcp_connect_cb (void *arg, struct tcp_pcb *tpcb, err_t err)
 Only used in TCP mode. More...
 
static err_t tcp_recv_cb (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 Only used in TCP mode. More...
 
static void tcp_send_data (struct ttcp *ttcp)
 Only used in TCP mode. More...
 
static int tcp_start (struct ttcp *ttcp)
 Start TCP transfer. More...
 
static void tcp_timeout_cb (void *ctx)
 Only used in TCP mode. More...
 
static void ttcp_destroy (struct ttcp *ttcp)
 Clean up and free the ttcp structure. More...
 
static void ttcp_done (struct ttcp *ttcp, int result)
 Invoked when transfer is done or aborted (non-zero result). More...
 
static void ttcp_print_stats (struct ttcp *ttcp)
 Calculate bitrate based on number of bytes transmitted and elapsed time. More...
 
int ttcp_start (struct ip_addr addr, uint16_t port, void *opaque, ttcp_done_cb_t *done_cb, int mode, uint16_t nbuf, uint16_t buflen, int udp, int verbose)
 Start a new ttcp transfer. More...
 
static void udp_recv_cb (void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
 Only used in UDP mode. More...
 
static int udp_send_bytes (struct ttcp *ttcp, uint32_t len)
 
static void udp_send_data (struct ttcp *ttcp)
 Only used in UDP mode. More...
 
static int udp_start (struct ttcp *ttcp)
 Start UDP transfer. More...
 
static void udp_timeout_cb (void *ctx)
 Only used in UDP mode. More...
 

Variables

char usage []
 

#define TTCP_MODE_RECEIVE   1

Referenced by cmd_ttcp(), and ttcp_start().

#define TTCP_MODE_TRANSMIT   0

typedef void( ttcp_done_cb_t)(void *opaque, int result)

static err_t tcp_accept_cb ( void *  arg,
struct tcp_pcb *  newpcb,
err_t  err 
)
static

Only used in TCP mode.

References arg, ERR_OK, printk(), ttcp::start_time, tcp_conn_err_cb(), tcp_recv_cb(), timer_get_ms(), and ttcp::tpcb.

Referenced by tcp_start().

static void tcp_conn_err_cb ( void *  arg,
err_t  err 
)
static

Only used in TCP mode.

References arg, NULL, printk(), ttcp::tpcb, and ttcp_done().

Referenced by tcp_accept_cb(), and tcp_start().

static err_t tcp_connect_cb ( void *  arg,
struct tcp_pcb *  tpcb,
err_t  err 
)
static

Only used in TCP mode.

References arg, ERR_OK, printk(), ttcp::start_time, tcp_send_data(), and timer_get_ms().

Referenced by tcp_start().

static err_t tcp_recv_cb ( void *  arg,
struct tcp_pcb *  pcb,
struct pbuf p,
err_t  err 
)
static
static void tcp_send_data ( struct ttcp ttcp)
static

Only used in TCP mode.

Will transmit a maximum of pbuf->tot_len bytes. Called upon connect and when there's space available in the TCP send window

References ttcp::buflen, ERR_MEM, ERR_OK, ttcp::left, ttcp::payload, printk(), tcp_timeout_cb(), ttcp::tid, TIMEOUT_ONESHOT, timer_sched_timeout_cb(), and ttcp::tpcb.

Referenced by tcp_connect_cb(), and tcp_timeout_cb().

static int tcp_start ( struct ttcp ttcp)
static
static void tcp_timeout_cb ( void *  ctx)
static

Only used in TCP mode.

Scheduled by tcp_send_data(). tcp_sent() is not used for performance reasons.

References ctx, ttcp::left, ttcp::print_cnt, printk(), tcp_send_data(), ttcp::tid, TIMEOUT_ONESHOT, timer_sched_timeout_cb(), ttcp::tpcb, ttcp_done(), and ttcp::verbose.

Referenced by tcp_send_data().

static void ttcp_destroy ( struct ttcp ttcp)
static

Clean up and free the ttcp structure.

References ttcp::lpcb, NULL, ttcp::payload, ttcp::tid, timer_cancel_timeout(), ttcp::tpcb, and ttcp::upcb.

Referenced by ttcp_done(), and ttcp_start().

static void ttcp_done ( struct ttcp ttcp,
int  result 
)
static

Invoked when transfer is done or aborted (non-zero result).

References ttcp::done_cb, ttcp::opaque, ttcp_destroy(), and ttcp_print_stats().

Referenced by tcp_conn_err_cb(), tcp_recv_cb(), tcp_timeout_cb(), udp_recv_cb(), and udp_send_data().

static void ttcp_print_stats ( struct ttcp ttcp)
static

Calculate bitrate based on number of bytes transmitted and elapsed time.

References ttcp::buflen, ttcp::mode, ttcp::nbuf, printk(), ttcp::recved, ttcp::start_time, timer_get_ms(), TTCP_MODE_TRANSMIT, ttcp::udp, and ttcp::verbose.

Referenced by ttcp_done().

int ttcp_start ( struct ip_addr  addr,
uint16_t  port,
void *  opaque,
ttcp_done_cb_t done_cb,
int  mode,
uint16_t  nbuf,
uint16_t  buflen,
int  udp,
int  verbose 
)

Start a new ttcp transfer.

It should be possible to call this function multiple times in order to get multiple ttcp streams. done_cb() will be invoked upon completion.

References ttcp::addr, ttcp::buflen, ttcp::done_cb, ttcp::left, ttcp::mode, ttcp::nbuf, NULL, ttcp::opaque, ttcp::port, printk(), status, tcp_start(), ttcp_destroy(), TTCP_MODE_RECEIVE, TTCP_MODE_TRANSMIT, ttcp::udp, udp_start(), and ttcp::verbose.

Referenced by cmd_ttcp().

static void udp_recv_cb ( void *  arg,
struct udp_pcb *  upcb,
struct pbuf p,
struct ip_addr *  addr,
u16_t  port 
)
static

Only used in UDP mode.

Will finalize the ttcp process when an end marker is seen.

References arg, out, pbuf_free(), ttcp::print_cnt, printk(), ttcp::recved, ttcp::start_time, timer_get_ms(), pbuf::tot_len, ttcp_done(), ttcp::udp_started, and ttcp::verbose.

Referenced by udp_start().

static int udp_send_bytes ( struct ttcp ttcp,
uint32_t  len 
)
static
static void udp_send_data ( struct ttcp ttcp)
static

Only used in UDP mode.

First call will send the start marker. When all ttcp data has been sent, a number of end markers will be sent. After end marker transmission, this function will complete the ttcp process.

References ttcp::buflen, ttcp::left, ttcp::start_time, ttcp::tid, TIMEOUT_ONESHOT, timer_get_ms(), timer_sched_timeout_cb(), ttcp_done(), ttcp::udp_end_marker_left, udp_send_bytes(), ttcp::udp_started, and udp_timeout_cb().

Referenced by udp_start(), and udp_timeout_cb().

static int udp_start ( struct ttcp ttcp)
static
static void udp_timeout_cb ( void *  ctx)
static

Only used in UDP mode.

Scheduled after data has been sent in udp_send_data() if we have more data to send.

References ctx, and udp_send_data().

Referenced by udp_send_data().

char usage[]
Initial value:
= "Usage: ttcp -t/-r [-options] host\n\
-l length of bufs written to network (default 1024)\n\
-n number of bufs written to network (default 1024)\n\
-p port number to send to (default 2000)\n\
-u udp\n\
-v verbose\n"