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.

Committer:
tass
Date:
Fri Jul 26 11:30:50 2013 +0000
Revision:
0:28a7ae57d114
Child:
1:81060ee2ac04
PicoTCP test to measure the number of frames received per second.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 0:28a7ae57d114 1 #include "mbed.h"
tass 0:28a7ae57d114 2 #include "EthernetInterface.h"
tass 0:28a7ae57d114 3
tass 0:28a7ae57d114 4 #define BUFFER_SIZE 1024
tass 0:28a7ae57d114 5 #define NUMBER_OF_SECONDS (20*1000u) // 20 seconds
tass 0:28a7ae57d114 6
tass 0:28a7ae57d114 7 #define REMOTE_IP "192.168.100.2"
tass 0:28a7ae57d114 8 #define REMOTE_PORT 2327
tass 0:28a7ae57d114 9 #define NUMBER_OF_FRAMES 1000
tass 0:28a7ae57d114 10
tass 0:28a7ae57d114 11 struct UDPStat
tass 0:28a7ae57d114 12 {
tass 0:28a7ae57d114 13 int BytesReceived;
tass 0:28a7ae57d114 14 int FramesReceived;
tass 0:28a7ae57d114 15 };
tass 0:28a7ae57d114 16
tass 0:28a7ae57d114 17 struct UDPStat UDP_Statistics;
tass 0:28a7ae57d114 18
tass 0:28a7ae57d114 19 int main() {
tass 0:28a7ae57d114 20
tass 0:28a7ae57d114 21 EthernetInterface eth;
tass 0:28a7ae57d114 22 eth.init();
tass 0:28a7ae57d114 23 eth.connect();
tass 0:28a7ae57d114 24
tass 0:28a7ae57d114 25 printf("Started UDP Fast Test...\n");
tass 0:28a7ae57d114 26
tass 0:28a7ae57d114 27 UDPSocket server;
tass 0:28a7ae57d114 28 Endpoint endp;
tass 0:28a7ae57d114 29
tass 0:28a7ae57d114 30 printf("Remote endpoint @ %s:%d\n",REMOTE_IP,REMOTE_PORT);
tass 0:28a7ae57d114 31 endp.set_address(REMOTE_IP,REMOTE_PORT);
tass 0:28a7ae57d114 32
tass 0:28a7ae57d114 33 printf("Binding result :%d\n", server.bind(REMOTE_PORT));
tass 0:28a7ae57d114 34
tass 0:28a7ae57d114 35 server.set_blocking(false,1000);
tass 0:28a7ae57d114 36 char buffer[BUFFER_SIZE];
tass 0:28a7ae57d114 37
tass 0:28a7ae57d114 38 while(true)
tass 0:28a7ae57d114 39 {
tass 0:28a7ae57d114 40 unsigned int time = PICO_TIME_MS();
tass 0:28a7ae57d114 41
tass 0:28a7ae57d114 42 memset(&UDP_Statistics,0x0,sizeof(struct UDPStat));
tass 0:28a7ae57d114 43 while( (time + NUMBER_OF_SECONDS) >= (unsigned int)PICO_TIME_MS())
tass 0:28a7ae57d114 44 {
tass 0:28a7ae57d114 45 int size;
tass 0:28a7ae57d114 46 size = server.receiveFrom(endp,buffer,sizeof(buffer));
tass 0:28a7ae57d114 47 if(size <= 0)
tass 0:28a7ae57d114 48 {
tass 0:28a7ae57d114 49 if(!size)
tass 0:28a7ae57d114 50 printf("Receive timeout\n");
tass 0:28a7ae57d114 51 else
tass 0:28a7ae57d114 52 printf("Receive returned error\n");
tass 0:28a7ae57d114 53 }
tass 0:28a7ae57d114 54 else
tass 0:28a7ae57d114 55 {
tass 0:28a7ae57d114 56 UDP_Statistics.BytesReceived += size;
tass 0:28a7ae57d114 57 UDP_Statistics.FramesReceived++;
tass 0:28a7ae57d114 58 }
tass 0:28a7ae57d114 59 }
tass 0:28a7ae57d114 60 time = PICO_TIME_MS() - time;
tass 0:28a7ae57d114 61 time = time/1000;
tass 0:28a7ae57d114 62
tass 0:28a7ae57d114 63 printf("Connection statistics for 20 seconds :\n");
tass 0:28a7ae57d114 64 printf("Total bytes received : %d\n",UDP_Statistics.BytesReceived);
tass 0:28a7ae57d114 65 printf("Average bytes received :%.2f per sec\n",(float)(UDP_Statistics.BytesReceived)/time);
tass 0:28a7ae57d114 66
tass 0:28a7ae57d114 67 printf("Total frames received :%d\n",UDP_Statistics.FramesReceived);
tass 0:28a7ae57d114 68 printf("Average frames received :%.2f per sec\n",(float)(UDP_Statistics.FramesReceived)/time);
tass 0:28a7ae57d114 69
tass 0:28a7ae57d114 70 printf("Loss percentage: %.2f %%\n\n\n",((NUMBER_OF_FRAMES - (float)UDP_Statistics.FramesReceived/time)/NUMBER_OF_FRAMES)*100);
tass 0:28a7ae57d114 71 }
tass 0:28a7ae57d114 72
tass 0:28a7ae57d114 73 server.close();
tass 0:28a7ae57d114 74 }