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@1:81060ee2ac04, 2013-10-03 (annotated)
- Committer:
- tass
- Date:
- Thu Oct 03 07:05:52 2013 +0000
- Revision:
- 1:81060ee2ac04
- Parent:
- 0:28a7ae57d114
UDP Rx Official Benchmark
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 0:28a7ae57d114 | 1 | #include "mbed.h" |
tass | 0:28a7ae57d114 | 2 | #include "EthernetInterface.h" |
tass | 0:28a7ae57d114 | 3 | |
tass | 1:81060ee2ac04 | 4 | #define MEGA (1024*1024) |
tass | 0:28a7ae57d114 | 5 | #define BUFFER_SIZE 1024 |
tass | 0:28a7ae57d114 | 6 | #define NUMBER_OF_SECONDS (20*1000u) // 20 seconds |
tass | 0:28a7ae57d114 | 7 | |
tass | 0:28a7ae57d114 | 8 | #define REMOTE_IP "192.168.100.2" |
tass | 0:28a7ae57d114 | 9 | #define REMOTE_PORT 2327 |
tass | 0:28a7ae57d114 | 10 | #define NUMBER_OF_FRAMES 1000 |
tass | 0:28a7ae57d114 | 11 | |
tass | 0:28a7ae57d114 | 12 | struct UDPStat |
tass | 0:28a7ae57d114 | 13 | { |
tass | 0:28a7ae57d114 | 14 | int BytesReceived; |
tass | 0:28a7ae57d114 | 15 | int FramesReceived; |
tass | 1:81060ee2ac04 | 16 | int LostPackets; |
tass | 0:28a7ae57d114 | 17 | }; |
tass | 0:28a7ae57d114 | 18 | |
tass | 0:28a7ae57d114 | 19 | struct UDPStat UDP_Statistics; |
tass | 0:28a7ae57d114 | 20 | |
tass | 0:28a7ae57d114 | 21 | int main() { |
tass | 0:28a7ae57d114 | 22 | |
tass | 0:28a7ae57d114 | 23 | EthernetInterface eth; |
tass | 0:28a7ae57d114 | 24 | eth.init(); |
tass | 0:28a7ae57d114 | 25 | eth.connect(); |
tass | 0:28a7ae57d114 | 26 | |
tass | 0:28a7ae57d114 | 27 | printf("Started UDP Fast Test...\n"); |
tass | 0:28a7ae57d114 | 28 | |
tass | 0:28a7ae57d114 | 29 | UDPSocket server; |
tass | 0:28a7ae57d114 | 30 | Endpoint endp; |
tass | 0:28a7ae57d114 | 31 | |
tass | 0:28a7ae57d114 | 32 | printf("Remote endpoint @ %s:%d\n",REMOTE_IP,REMOTE_PORT); |
tass | 0:28a7ae57d114 | 33 | endp.set_address(REMOTE_IP,REMOTE_PORT); |
tass | 0:28a7ae57d114 | 34 | |
tass | 0:28a7ae57d114 | 35 | printf("Binding result :%d\n", server.bind(REMOTE_PORT)); |
tass | 0:28a7ae57d114 | 36 | |
tass | 0:28a7ae57d114 | 37 | server.set_blocking(false,1000); |
tass | 0:28a7ae57d114 | 38 | char buffer[BUFFER_SIZE]; |
tass | 0:28a7ae57d114 | 39 | |
tass | 0:28a7ae57d114 | 40 | while(true) |
tass | 0:28a7ae57d114 | 41 | { |
tass | 0:28a7ae57d114 | 42 | unsigned int time = PICO_TIME_MS(); |
tass | 1:81060ee2ac04 | 43 | int index = -1; |
tass | 0:28a7ae57d114 | 44 | |
tass | 0:28a7ae57d114 | 45 | memset(&UDP_Statistics,0x0,sizeof(struct UDPStat)); |
tass | 0:28a7ae57d114 | 46 | while( (time + NUMBER_OF_SECONDS) >= (unsigned int)PICO_TIME_MS()) |
tass | 0:28a7ae57d114 | 47 | { |
tass | 0:28a7ae57d114 | 48 | int size; |
tass | 0:28a7ae57d114 | 49 | size = server.receiveFrom(endp,buffer,sizeof(buffer)); |
tass | 1:81060ee2ac04 | 50 | if(size > 0) |
tass | 0:28a7ae57d114 | 51 | { |
tass | 1:81060ee2ac04 | 52 | int _index; |
tass | 0:28a7ae57d114 | 53 | UDP_Statistics.BytesReceived += size; |
tass | 0:28a7ae57d114 | 54 | UDP_Statistics.FramesReceived++; |
tass | 1:81060ee2ac04 | 55 | _index = *((int *)buffer); |
tass | 1:81060ee2ac04 | 56 | |
tass | 1:81060ee2ac04 | 57 | if(index>0) |
tass | 1:81060ee2ac04 | 58 | { |
tass | 1:81060ee2ac04 | 59 | UDP_Statistics.LostPackets+= _index-index-1; |
tass | 1:81060ee2ac04 | 60 | } |
tass | 1:81060ee2ac04 | 61 | index = _index; |
tass | 0:28a7ae57d114 | 62 | } |
tass | 0:28a7ae57d114 | 63 | } |
tass | 0:28a7ae57d114 | 64 | time = PICO_TIME_MS() - time; |
tass | 0:28a7ae57d114 | 65 | time = time/1000; |
tass | 0:28a7ae57d114 | 66 | |
tass | 1:81060ee2ac04 | 67 | printf("20 seconds Rx statistics\n"); |
tass | 0:28a7ae57d114 | 68 | printf("Total bytes received : %d\n",UDP_Statistics.BytesReceived); |
tass | 1:81060ee2ac04 | 69 | printf("UDP Speed :%.3f Mbit/s\n",(UDP_Statistics.BytesReceived *8.0)/(20.0*MEGA)); |
tass | 1:81060ee2ac04 | 70 | printf("Loss percentage: %.2f %%\n\n\n",(UDP_Statistics.LostPackets*100.0)/(UDP_Statistics.LostPackets+UDP_Statistics.FramesReceived)); |
tass | 0:28a7ae57d114 | 71 | } |
tass | 0:28a7ae57d114 | 72 | |
tass | 0:28a7ae57d114 | 73 | server.close(); |
tass | 0:28a7ae57d114 | 74 | } |