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:
- 1:81060ee2ac04
- Parent:
- 0:28a7ae57d114
diff -r 28a7ae57d114 -r 81060ee2ac04 main.cpp --- a/main.cpp Fri Jul 26 11:30:50 2013 +0000 +++ b/main.cpp Thu Oct 03 07:05:52 2013 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "EthernetInterface.h" +#define MEGA (1024*1024) #define BUFFER_SIZE 1024 #define NUMBER_OF_SECONDS (20*1000u) // 20 seconds @@ -12,6 +13,7 @@ { int BytesReceived; int FramesReceived; + int LostPackets; }; struct UDPStat UDP_Statistics; @@ -38,36 +40,34 @@ 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) + if(size > 0) { - if(!size) - printf("Receive timeout\n"); - else - printf("Receive returned error\n"); - } - else - { + 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("Connection statistics for 20 seconds :\n"); + printf("20 seconds Rx statistics\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); + 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();