UDP Tx Official Benchmark

Dependencies:   PicoTCP lpc1768-picotcp-eth mbed-rtos mbed

This project represents a the official UDP Tx speed Benchmark for the PicoTCP library.

The mbed board is sending 5 frames per milisecond (each frame has 1024 bytes of payload) to a linux host(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 Tx Statistics
Total bytes received : 102404096
UDP Speed : 39.064 Mbit/s
Packet loss : 0.000000 %

The python script used (which you should rename it to PicoTCP_Official_UDP_Tx_Benchmark.py)

import socket
from struct import unpack
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))

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 receiving data...."
print "Time : %d " % time()

while True:
	start = time()
	counter = 0
	size = 0
	lost_packets = 0
	index = -1
	
	while start + NUMBER_OF_SECONDS > time():
		data, addr = s.recvfrom(LEN_PACKET)
		counter+=1
		size += len(data)
		_index = unpack("<I",data[:4])
	        if _index[0] > 0 and index > 0:
			lost_packets += _index[0] - index -1
		index = _index[0]
						

	print "20 seconds Tx Statistics"
	print "Total bytes received : %d" % size
	print "UDP Speed : %.3f Mbit/s" % ((size*8.)/(MEGA * NUMBER_OF_SECONDS))
	print "Packet loss : %.6f %%" % (100. * lost_packets/(lost_packets+counter))

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:
Thu Oct 03 06:22:54 2013 +0000
Revision:
0:ce982aead3d2
UDP Tx Official Benchmark

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 0:ce982aead3d2 1 #include "mbed.h"
tass 0:ce982aead3d2 2 #include "EthernetInterface.h"
tass 0:ce982aead3d2 3
tass 0:ce982aead3d2 4 #define BUFFER_SIZE 1024
tass 0:ce982aead3d2 5 #define NUMBER_OF_SECONDS (20*1000u) // 20 seconds
tass 0:ce982aead3d2 6
tass 0:ce982aead3d2 7 #define REMOTE_IP "192.168.100.2"
tass 0:ce982aead3d2 8 #define REMOTE_PORT 2327
tass 0:ce982aead3d2 9 #define NUMBER_OF_FRAMES 1000
tass 0:ce982aead3d2 10
tass 0:ce982aead3d2 11 int main() {
tass 0:ce982aead3d2 12
tass 0:ce982aead3d2 13 EthernetInterface eth;
tass 0:ce982aead3d2 14 eth.init();
tass 0:ce982aead3d2 15 eth.connect();
tass 0:ce982aead3d2 16
tass 0:ce982aead3d2 17 printf("Started UDP Fast Test...\n");
tass 0:ce982aead3d2 18
tass 0:ce982aead3d2 19 UDPSocket server;
tass 0:ce982aead3d2 20 Endpoint endp;
tass 0:ce982aead3d2 21 char buffer[BUFFER_SIZE];
tass 0:ce982aead3d2 22
tass 0:ce982aead3d2 23 printf("Remote endpoint @ %s:%d\n",REMOTE_IP,REMOTE_PORT);
tass 0:ce982aead3d2 24 endp.set_address(REMOTE_IP,REMOTE_PORT);
tass 0:ce982aead3d2 25
tass 0:ce982aead3d2 26 printf("Binding result :%d\n", server.bind(REMOTE_PORT));
tass 0:ce982aead3d2 27
tass 0:ce982aead3d2 28 server.bind(REMOTE_PORT);
tass 0:ce982aead3d2 29 server.set_blocking(false,1000);
tass 0:ce982aead3d2 30
tass 0:ce982aead3d2 31 printf("Started sending packet flood...\n");
tass 0:ce982aead3d2 32
tass 0:ce982aead3d2 33 while(true)
tass 0:ce982aead3d2 34 {
tass 0:ce982aead3d2 35 int cnt = 0;
tass 0:ce982aead3d2 36 static uint32_t counter = 0;
tass 0:ce982aead3d2 37 while(cnt<5)
tass 0:ce982aead3d2 38 {
tass 0:ce982aead3d2 39 memcpy(buffer,&counter,sizeof(counter));
tass 0:ce982aead3d2 40 int size = server.sendTo(endp,buffer,sizeof(buffer));
tass 0:ce982aead3d2 41 counter++;
tass 0:ce982aead3d2 42 cnt++;
tass 0:ce982aead3d2 43 }
tass 0:ce982aead3d2 44 Thread::wait(1);
tass 0:ce982aead3d2 45 }
tass 0:ce982aead3d2 46
tass 0:ce982aead3d2 47 server.close();
tass 0:ce982aead3d2 48 }
tass 0:ce982aead3d2 49