Skip to content

Commit

Permalink
Added iperf client to test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Lacamera committed Feb 3, 2015
1 parent ca8f614 commit 5609878
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $(PREFIX)/examples/udp_client.o \
$(PREFIX)/examples/udp_echo.o \
$(PREFIX)/examples/udpnat.o \
$(PREFIX)/examples/udp_sendto_test.o \
$(PREFIX)/examples/iperfc.o \


all: $(OBJS)
126 changes: 126 additions & 0 deletions test/examples/iperfc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "pico_stack.h"
#include "pico_socket.h"

#define DURATION 30

struct iperf_hdr {
int32_t flags; /* 0 */
int32_t numThreads; /* 1 */
int32_t mPort; /* 5001 */
int32_t bufferlen; /* 0 */
int32_t mWinBand; /* 0 */
int32_t mAmount; /* 0xfffffc18 */
};

#define IPERF_PORT 5001
#define MTU 1444
#define SEND_BUF_SIZ (1024 * 2048)

char *cpy_arg(char **dst, char *str);
extern int IPV6_MODE;

static pico_time deadline;

static void panic(void)
{
for(;;);
}

static char buf[MTU] = {};

static void buf_paint(void)
{
char paint[11] = "0123456789";
int i;
for (i = 0; i < MTU; i++) {
buf[i] = paint[i % 10];
}
}

static void send_hdr(struct pico_socket *s)
{
struct iperf_hdr hdr = {} ;
hdr.numThreads = long_be(1);
hdr.mPort = long_be(5001);
hdr.mAmount = long_be(0xfffffc18);
pico_socket_write(s, &hdr, sizeof(hdr));
deadline = PICO_TIME_MS() + DURATION * 1000;
}

static void iperf_cb(uint16_t ev, struct pico_socket *s)
{
int r;
if (ev & PICO_SOCK_EV_CONN) {
send_hdr(s);
return;
}

if (ev & PICO_SOCK_EV_WR) {
if (PICO_TIME_MS() > deadline) {
pico_socket_close(s);
return;
}
pico_socket_write(s, buf, MTU);
}
}

static void iperfc_socket_setup(union pico_address *addr, uint16_t family)
{
int yes = 1;
uint16_t send_port = 0;
struct pico_socket *s = NULL;
uint32_t bufsize = SEND_BUF_SIZ;
send_port = short_be(5001);
s = pico_socket_open(family, PICO_PROTO_TCP, &iperf_cb);
pico_socket_setoption(s, PICO_SOCKET_OPT_SNDBUF, &bufsize);
pico_socket_connect(s, addr, send_port);
}

void app_iperfc(char *arg)
{
struct pico_ip4 my_eth_addr, netmask;
struct pico_device *pico_dev_eth;
char *daddr = NULL, *dport = NULL;
char *nxt = arg;
uint16_t send_port = 0, listen_port = short_be(5001);
int i = 0, ret = 0, yes = 1;
struct pico_socket *s = NULL;
uint16_t family = PICO_PROTO_IPV4;
union pico_address dst = {
.ip4 = {0}, .ip6 = {{0}}
};
union pico_address inaddr_any = {
.ip4 = {0}, .ip6 = {{0}}
};

/* start of argument parsing */
if (nxt) {
nxt = cpy_arg(&daddr, arg);
if (daddr) {
if (!IPV6_MODE)
pico_string_to_ipv4(daddr, &dst.ip4.addr);

#ifdef PICO_SUPPORT_IPV6
else {
pico_string_to_ipv6(daddr, dst.ip6.addr);
family = PICO_PROTO_IPV6;
}
#endif
} else {
goto out;
}
} else {
/* missing dest_addr */
goto out;
}

iperfc_socket_setup(&dst, family);
return;
out:
dbg("Error parsing options!\n");
exit(1);
}

3 changes: 3 additions & 0 deletions test/picoapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void app_slaacv4(char *args);
void app_udpecho(char *args);
void app_sendto_test(char *args);
void app_noop(void);
void app_iperfc(char *args);


struct pico_ip4 ZERO_IP4 = {
Expand Down Expand Up @@ -611,6 +612,8 @@ int main(int argc, char **argv)
#endif
} else IF_APPNAME("udp_sendto_test") {
app_sendto_test(args);
} else IF_APPNAME("iperfc") {
app_iperfc(args);
} else {
fprintf(stderr, "Unknown application %s\n", name);
usage(argv[0]);
Expand Down

0 comments on commit 5609878

Please sign in to comment.