Simple test for PicoTCP's UDP receiver.
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
This project represents the official UDP Rx speed Benchmark for the PicoTCP library.
The linux host is sending 5 frames per milisecond (each frame has 1024 bytes of payload) to a the mbed board(directly connected).
Each time we send a packet, a counter is increased and sent to the receiver, so it can measure the number of packets that were lost during transmission.
The result:
20 seconds Rx statistics
Total bytes received : 47557632
UDP Speed :18.142 Mbit/s
Loss percentage: 36.65 %
The python script used (which you should rename it to PicoTCP_Official_UDP_Rx_Benchmark.py)
import struct import socket import fcntl, os import errno import random, string from time import time, sleep ECHO_SERVER_ADDRESS = "192.168.100.12" NUMBER_OF_SECONDS = 20 LOCAL_SERVER_PORT = 2327 MEGA = 1024*1024. LEN_PACKET = 1024 data = ''.join('\0' for _ in range(LEN_PACKET)) counter = 0 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,socket.IPPROTO_UDP) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('', LOCAL_SERVER_PORT)) print "Started sending data...." print "Time : %d " % time() while True: start = time() cnt = 0 while cnt < 5: list_data = list(data) list_data[3] = chr(counter>>24 & 0xFF) list_data[2] = chr(counter>>16 & 0xFF) list_data[1] = chr(counter>>8 & 0xFF) list_data[0] = chr(counter & 0xFF) data = ''.join(list_data) s.sendto(data, (ECHO_SERVER_ADDRESS, LOCAL_SERVER_PORT)) cnt+=1 counter+=1 sleep(0.001)
This test is based on the following libraries
Import librarylpc1768-picotcp-eth
A PicoTCP driver for the lpc1768 mbed board
Import libraryPicoTCP
Free (GPLv2) TCP/IP stack developed by TASS Belgium
Import librarymbed-rtos
Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Diff: main.cpp
- Revision:
- 0:28a7ae57d114
- Child:
- 1:81060ee2ac04
diff -r 000000000000 -r 28a7ae57d114 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jul 26 11:30:50 2013 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "EthernetInterface.h" + +#define BUFFER_SIZE 1024 +#define NUMBER_OF_SECONDS (20*1000u) // 20 seconds + +#define REMOTE_IP "192.168.100.2" +#define REMOTE_PORT 2327 +#define NUMBER_OF_FRAMES 1000 + +struct UDPStat +{ + int BytesReceived; + int FramesReceived; +}; + +struct UDPStat UDP_Statistics; + +int main() { + + EthernetInterface eth; + eth.init(); + eth.connect(); + + printf("Started UDP Fast Test...\n"); + + UDPSocket server; + Endpoint endp; + + printf("Remote endpoint @ %s:%d\n",REMOTE_IP,REMOTE_PORT); + endp.set_address(REMOTE_IP,REMOTE_PORT); + + printf("Binding result :%d\n", server.bind(REMOTE_PORT)); + + server.set_blocking(false,1000); + char buffer[BUFFER_SIZE]; + + while(true) + { + unsigned int time = PICO_TIME_MS(); + + memset(&UDP_Statistics,0x0,sizeof(struct UDPStat)); + while( (time + NUMBER_OF_SECONDS) >= (unsigned int)PICO_TIME_MS()) + { + int size; + size = server.receiveFrom(endp,buffer,sizeof(buffer)); + if(size <= 0) + { + if(!size) + printf("Receive timeout\n"); + else + printf("Receive returned error\n"); + } + else + { + UDP_Statistics.BytesReceived += size; + UDP_Statistics.FramesReceived++; + } + } + time = PICO_TIME_MS() - time; + time = time/1000; + + printf("Connection statistics for 20 seconds :\n"); + printf("Total bytes received : %d\n",UDP_Statistics.BytesReceived); + printf("Average bytes received :%.2f per sec\n",(float)(UDP_Statistics.BytesReceived)/time); + + printf("Total frames received :%d\n",UDP_Statistics.FramesReceived); + printf("Average frames received :%.2f per sec\n",(float)(UDP_Statistics.FramesReceived)/time); + + printf("Loss percentage: %.2f %%\n\n\n",((NUMBER_OF_FRAMES - (float)UDP_Statistics.FramesReceived/time)/NUMBER_OF_FRAMES)*100); + } + + server.close(); +}