Official TCP Full speed benchmark
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
This project represents a the official TCP Full speed Benchmark for the PicoTCP library.
The mbed board is sending and receiving one Megabyte from/to the other side and we measure how fast it does that.
The result:
TX+RX Throughput: 2097152 bytes in 1 seconds (12.410)Mbits/s
The python script used (which you should rename it to PicoTCP_Official_TCP_Full_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) * 2. # TX bits + RX 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 print "Started echoing data...." for i in range(N_PACKETS): if (i % UPDATE_STEP) == 0: print "%.2f%%" % (float(i)/float(N_PACKETS) * 100.) s.sendall(PACKET) data = s.recv(LEN_PACKET) if (len(data) != LEN_PACKET): print "Error echoing !" sys.exit(1) print "Test was finished!" break; t = time() - start s.close() print "TX+RX 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.
main.cpp@1:1996535d99e9, 2013-10-07 (annotated)
- Committer:
- tass
- Date:
- Mon Oct 07 07:06:11 2013 +0000
- Revision:
- 1:1996535d99e9
- Parent:
- 0:a90d7f1c17bc
Update to the latest picotcp lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 0:a90d7f1c17bc | 1 | #include <mbed.h> |
tass | 0:a90d7f1c17bc | 2 | #include <stdarg.h> |
tass | 0:a90d7f1c17bc | 3 | #include "EthernetInterface.h" |
tass | 0:a90d7f1c17bc | 4 | |
tass | 0:a90d7f1c17bc | 5 | #define ECHO_SERVER_PORT 7 |
tass | 0:a90d7f1c17bc | 6 | #define BUFFER_QUANTITY (1024*1024) |
tass | 0:a90d7f1c17bc | 7 | #define BUFFER_SIZE (1024) |
tass | 0:a90d7f1c17bc | 8 | |
tass | 0:a90d7f1c17bc | 9 | EthernetInterface eth; |
tass | 0:a90d7f1c17bc | 10 | |
tass | 0:a90d7f1c17bc | 11 | int main() |
tass | 0:a90d7f1c17bc | 12 | { |
tass | 0:a90d7f1c17bc | 13 | TCPSocketServer server; |
tass | 0:a90d7f1c17bc | 14 | |
tass | 0:a90d7f1c17bc | 15 | printf("Started PicoTCP Full Benchmark....\n"); |
tass | 0:a90d7f1c17bc | 16 | |
tass | 0:a90d7f1c17bc | 17 | eth.init(); |
tass | 0:a90d7f1c17bc | 18 | printf("Waiting for DHCP server to give IP...\n"); |
tass | 0:a90d7f1c17bc | 19 | |
tass | 0:a90d7f1c17bc | 20 | while(eth.connect() != 0); |
tass | 0:a90d7f1c17bc | 21 | printf("IP address assigned : %s\n",eth.getIPAddress()); |
tass | 0:a90d7f1c17bc | 22 | |
tass | 0:a90d7f1c17bc | 23 | server.bind(ECHO_SERVER_PORT); |
tass | 0:a90d7f1c17bc | 24 | server.listen(); |
tass | 0:a90d7f1c17bc | 25 | printf("Local server listening on port : %d\n",ECHO_SERVER_PORT); |
tass | 0:a90d7f1c17bc | 26 | |
tass | 0:a90d7f1c17bc | 27 | |
tass | 0:a90d7f1c17bc | 28 | while (true) { |
tass | 0:a90d7f1c17bc | 29 | printf("\n>>> You can start PicoTCP_Official_TCP_Full_Benchmark.py\n"); |
tass | 0:a90d7f1c17bc | 30 | |
tass | 0:a90d7f1c17bc | 31 | TCPSocketConnection client; |
tass | 0:a90d7f1c17bc | 32 | server.accept(client); |
tass | 1:1996535d99e9 | 33 | client.set_blocking(true, 1500); // Timeout after (1.5)s |
tass | 0:a90d7f1c17bc | 34 | char buffer[BUFFER_SIZE]; |
tass | 0:a90d7f1c17bc | 35 | int dataSent = 0, dataReceived = 0; |
tass | 0:a90d7f1c17bc | 36 | while(dataSent < BUFFER_QUANTITY) |
tass | 0:a90d7f1c17bc | 37 | { |
tass | 0:a90d7f1c17bc | 38 | while((dataReceived+dataSent) < 2*BUFFER_QUANTITY) |
tass | 0:a90d7f1c17bc | 39 | { |
tass | 0:a90d7f1c17bc | 40 | int n = client.receive(buffer, sizeof(buffer)); |
tass | 0:a90d7f1c17bc | 41 | if (n <= 0) { |
tass | 0:a90d7f1c17bc | 42 | break; |
tass | 0:a90d7f1c17bc | 43 | } |
tass | 0:a90d7f1c17bc | 44 | dataReceived += n; |
tass | 0:a90d7f1c17bc | 45 | |
tass | 0:a90d7f1c17bc | 46 | n = client.send_all(buffer, n); |
tass | 0:a90d7f1c17bc | 47 | if (n <= 0) { |
tass | 0:a90d7f1c17bc | 48 | break; |
tass | 0:a90d7f1c17bc | 49 | } |
tass | 0:a90d7f1c17bc | 50 | dataSent += n; |
tass | 0:a90d7f1c17bc | 51 | } |
tass | 0:a90d7f1c17bc | 52 | } |
tass | 0:a90d7f1c17bc | 53 | |
tass | 0:a90d7f1c17bc | 54 | if((dataSent+dataReceived) == 2*BUFFER_QUANTITY) |
tass | 0:a90d7f1c17bc | 55 | { |
tass | 0:a90d7f1c17bc | 56 | printf("You can read the Rx+Tx Throughput now \n"); |
tass | 0:a90d7f1c17bc | 57 | } |
tass | 0:a90d7f1c17bc | 58 | else |
tass | 0:a90d7f1c17bc | 59 | { |
tass | 0:a90d7f1c17bc | 60 | printf("Benchmark failed !\n"); |
tass | 0:a90d7f1c17bc | 61 | } |
tass | 0:a90d7f1c17bc | 62 | } |
tass | 0:a90d7f1c17bc | 63 | } |