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.
main.cpp
- Committer:
- tass
- Date:
- 2013-10-03
- Revision:
- 1:81060ee2ac04
- Parent:
- 0:28a7ae57d114
File content as of revision 1:81060ee2ac04:
#include "mbed.h" #include "EthernetInterface.h" #define MEGA (1024*1024) #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; int LostPackets; }; 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(); int index = -1; 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) { int _index; UDP_Statistics.BytesReceived += size; UDP_Statistics.FramesReceived++; _index = *((int *)buffer); if(index>0) { UDP_Statistics.LostPackets+= _index-index-1; } index = _index; } } time = PICO_TIME_MS() - time; time = time/1000; printf("20 seconds Rx statistics\n"); printf("Total bytes received : %d\n",UDP_Statistics.BytesReceived); printf("UDP Speed :%.3f Mbit/s\n",(UDP_Statistics.BytesReceived *8.0)/(20.0*MEGA)); printf("Loss percentage: %.2f %%\n\n\n",(UDP_Statistics.LostPackets*100.0)/(UDP_Statistics.LostPackets+UDP_Statistics.FramesReceived)); } server.close(); }