TCP Official Tx Benchmark

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

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

The mbed board is sending one Megabyte to the other side and we measure how fast it does that.

The result:
PicoTCP TX Throughput: 1048576 bytes in < 1 seconds (10.097)Mbits/s

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

#!/usr/bin/python
import sys, socket
import random, string
import select
from time import time

ECHO_SERVER_ADDRESS = "192.168.100.12"
ECHO_SERVER_PORT = 7
N_PACKETS = 1024
LEN_PACKET = 1024

TOT_BITS = (LEN_PACKET * N_PACKETS * 8) # TX bits 
PACKET = ''.join(random.choice(string.ascii_uppercase+string.digits) for _ in range(LEN_PACKET))
MEGA = 1024 * 1024.
UPDATE_STEP = (N_PACKETS/20) # Make the update step such as one step = 5%
UPDATE_R_STEP = (N_PACKETS/100) #Make the update step such as one step = 1%
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT))
start = time()
rx_total = 0
tx_total = 0
data = ''
i = 0
lp = []
p = select.poll()
while(True): # keeping this in for robustness testing, when the test will run for days
	#Stage II - receving data from the mbed board
	print "Started receiving data...."
	while(len(data) < N_PACKETS * LEN_PACKET):	
		p.register(s, select.POLLIN)
		lp = p.poll(1)
		if(len(lp) > 0):
		    r = s.recv(LEN_PACKET)
		    if (r != ''):
		      data += r
		      if (len(data) / LEN_PACKET) % UPDATE_R_STEP: print "recvd %d/%d (%.2f%%)" % (len(data)/LEN_PACKET, N_PACKETS, float(len(data))/ float(N_PACKETS * LEN_PACKET) * 100.)
		    else:
		      print "Error receiving !"
		      sys.exit(1)

	print "Test was finished!"
	break;	

t = time() - start
s.close()
print "PicoTCP TX Throughput: %d bytes in %d seconds (%.3f)Mbits/s" % (TOT_BITS / 8, t, ((TOT_BITS / t) / MEGA))

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:
Wed Oct 02 07:51:01 2013 +0000
Revision:
0:5c0efd6f5ec6
TCP Official Tx Benchmark

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 0:5c0efd6f5ec6 1 #include <mbed.h>
tass 0:5c0efd6f5ec6 2 #include <stdarg.h>
tass 0:5c0efd6f5ec6 3 #include "EthernetInterface.h"
tass 0:5c0efd6f5ec6 4
tass 0:5c0efd6f5ec6 5 #define ECHO_SERVER_PORT 7
tass 0:5c0efd6f5ec6 6 #define BUFFER_QUANTITY (1024*1024)
tass 0:5c0efd6f5ec6 7 #define BUFFER_SIZE (1024)
tass 0:5c0efd6f5ec6 8
tass 0:5c0efd6f5ec6 9
tass 0:5c0efd6f5ec6 10 EthernetInterface eth;
tass 0:5c0efd6f5ec6 11
tass 0:5c0efd6f5ec6 12 int main()
tass 0:5c0efd6f5ec6 13 {
tass 0:5c0efd6f5ec6 14 TCPSocketServer server;
tass 0:5c0efd6f5ec6 15
tass 0:5c0efd6f5ec6 16 printf("Started PicoTCP Tx Benchmark....\n");
tass 0:5c0efd6f5ec6 17
tass 0:5c0efd6f5ec6 18 eth.init();
tass 0:5c0efd6f5ec6 19 printf("Waiting for DHCP server to give IP...\n");
tass 0:5c0efd6f5ec6 20
tass 0:5c0efd6f5ec6 21 while(eth.connect() != 0);
tass 0:5c0efd6f5ec6 22 printf("IP address assigned : %s\n",eth.getIPAddress());
tass 0:5c0efd6f5ec6 23
tass 0:5c0efd6f5ec6 24 server.bind(ECHO_SERVER_PORT);
tass 0:5c0efd6f5ec6 25 server.listen();
tass 0:5c0efd6f5ec6 26 printf("Local server listening on port : %d\n",ECHO_SERVER_PORT);
tass 0:5c0efd6f5ec6 27
tass 0:5c0efd6f5ec6 28
tass 0:5c0efd6f5ec6 29 while (true) {
tass 0:5c0efd6f5ec6 30 printf("\n>>> You can start PicoTCP_Official_TCP_Tx_Benchmark.py\n");
tass 0:5c0efd6f5ec6 31
tass 0:5c0efd6f5ec6 32 TCPSocketConnection client;
tass 0:5c0efd6f5ec6 33 server.accept(client);
tass 0:5c0efd6f5ec6 34 client.set_blocking(false, 1500); // Timeout after (1.5)s
tass 0:5c0efd6f5ec6 35
tass 0:5c0efd6f5ec6 36 char buffer[BUFFER_SIZE];
tass 0:5c0efd6f5ec6 37 int dataSent = 0;
tass 0:5c0efd6f5ec6 38 while(dataSent < BUFFER_QUANTITY)
tass 0:5c0efd6f5ec6 39 {
tass 0:5c0efd6f5ec6 40 int n = client.send_all(buffer, sizeof(buffer));
tass 0:5c0efd6f5ec6 41 if (n <= 0) {
tass 0:5c0efd6f5ec6 42 break;
tass 0:5c0efd6f5ec6 43 }
tass 0:5c0efd6f5ec6 44 dataSent += n;
tass 0:5c0efd6f5ec6 45 }
tass 0:5c0efd6f5ec6 46
tass 0:5c0efd6f5ec6 47 if(dataSent == BUFFER_QUANTITY)
tass 0:5c0efd6f5ec6 48 {
tass 0:5c0efd6f5ec6 49 printf("You can read the Tx Throughput now \n");
tass 0:5c0efd6f5ec6 50 }
tass 0:5c0efd6f5ec6 51 else
tass 0:5c0efd6f5ec6 52 {
tass 0:5c0efd6f5ec6 53 printf("Benchmark failed !\n");
tass 0:5c0efd6f5ec6 54 }
tass 0:5c0efd6f5ec6 55 }
tass 0:5c0efd6f5ec6 56 }