/* * Copyright (c) 2007 Xilinx, Inc. All rights reserved. * * Xilinx, Inc. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. * */ #include #include #include "lwip/err.h" #include "lwip/tcp.h" #ifdef __arm__ #include "xil_printf.h" #endif static unsigned rxperf_port = 5001; /* iperf default port */ static unsigned rxperf_server_running = 0; static unsigned txperf_server_running = 0; extern struct tcp_pcb *connected_pcb; void print_rxperf_app_header(); err_t txperf_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len); int transfer_rxperf_data() { return 0; } static err_t rxperf_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { /* close socket if the peer has sent the FIN packet */ if (p == NULL) { xil_printf("Connection closed\n"); tcp_close(tpcb); return ERR_OK; } /* all we do is say we've received the packet */ /* we don't actually make use of it */ tcp_recved(tpcb, p->tot_len); //xil_printf("p tot len: %d\n", p->tot_len); pbuf_free(p); return ERR_OK; } err_t rxperf_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err) { xil_printf("rxperf: Connection Accepted\r\n"); tcp_recv(newpcb, rxperf_recv_callback); return ERR_OK; } int start_rxperf_application() { struct tcp_pcb *pcb; err_t err; /* create new TCP PCB structure */ pcb = tcp_new(); if (!pcb) { xil_printf("rxperf: Error creating PCB. Out of Memory\r\n"); return -1; } /* bind to iperf @port */ err = tcp_bind(pcb, IP_ADDR_ANY, rxperf_port); if (err != ERR_OK) { xil_printf("rxperf: Unable to bind to port %d: err = %d\r\n", rxperf_port, err); return -2; } /* we do not need any arguments to callback functions :) */ tcp_arg(pcb, NULL); /* listen for connections */ pcb = tcp_listen(pcb); if (!pcb) { xil_printf("rxperf: Out of memory while tcp_listen\r\n"); return -3; } /* specify callback to use for incoming connections */ tcp_accept(pcb, rxperf_accept_callback); print_rxperf_app_header(); rxperf_server_running = 1; return 0; } void print_rxperf_app_header() { xil_printf("%20s %6d %s\r\n", "rxperf server", rxperf_port, "$ iperf -c -i 5 -t 50 -w 64k"); }