My take on Pico_Robustness_Test

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

Fork of Pico_Robustness_Test by TASS Belgium

Committer:
tass
Date:
Wed Jul 24 05:26:23 2013 +0000
Revision:
0:8ac2e5a7f731
Child:
1:97b1710fd9c3
PicoTCP Robustness Test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tass 0:8ac2e5a7f731 1 #include "mbed.h"
tass 0:8ac2e5a7f731 2 #include "EthernetInterface.h"
tass 0:8ac2e5a7f731 3
tass 0:8ac2e5a7f731 4 #define msgdbg(...)
tass 0:8ac2e5a7f731 5
tass 0:8ac2e5a7f731 6 //#define msgdbg printf
tass 0:8ac2e5a7f731 7
tass 0:8ac2e5a7f731 8
tass 0:8ac2e5a7f731 9 #define SENDING_RETRIES 5u
tass 0:8ac2e5a7f731 10 #define READING_RETRIES 5u
tass 0:8ac2e5a7f731 11 #define DHCP_RETRIES 10u
tass 0:8ac2e5a7f731 12 #define BUFFER_SIZE 256
tass 0:8ac2e5a7f731 13
tass 0:8ac2e5a7f731 14 #define NUMBER_OF_HOSTS 3u
tass 0:8ac2e5a7f731 15
tass 0:8ac2e5a7f731 16 #define MBED_HOST "www.mbed.org"
tass 0:8ac2e5a7f731 17 #define MBED_HOST_REQUEST "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"
tass 0:8ac2e5a7f731 18
tass 0:8ac2e5a7f731 19 #define MEDIAFAX_HOST "www.mediafax.ro"
tass 0:8ac2e5a7f731 20 #define MEDIAFAX_HOST_REQUEST "GET / HTTP/1.1\nHost: www.mediafax.ro\n\n"
tass 0:8ac2e5a7f731 21
tass 0:8ac2e5a7f731 22 #define NXP_HOST "www.nxp.com"
tass 0:8ac2e5a7f731 23 #define NXP_HOST_REQUEST "GET /documents/user_manual/UM10360.pdf HTTP/1.0\nHost: www.nxp.com\n\n"
tass 0:8ac2e5a7f731 24
tass 0:8ac2e5a7f731 25 int totalTime = 0;
tass 0:8ac2e5a7f731 26
tass 0:8ac2e5a7f731 27 struct WebStats
tass 0:8ac2e5a7f731 28 {
tass 0:8ac2e5a7f731 29 char request[70];
tass 0:8ac2e5a7f731 30 char host[20];
tass 0:8ac2e5a7f731 31 int avgDuration;
tass 0:8ac2e5a7f731 32 int maxReceived;
tass 0:8ac2e5a7f731 33 int minReceived;
tass 0:8ac2e5a7f731 34 int snapshots;
tass 0:8ac2e5a7f731 35 };
tass 0:8ac2e5a7f731 36
tass 0:8ac2e5a7f731 37 struct WebStats webStatistics[NUMBER_OF_HOSTS]=
tass 0:8ac2e5a7f731 38 {
tass 0:8ac2e5a7f731 39 {MBED_HOST_REQUEST,MBED_HOST,0,0,0x7FFFFFFF,0},
tass 0:8ac2e5a7f731 40 {MEDIAFAX_HOST_REQUEST,MEDIAFAX_HOST,0,0,0x7FFFFFFF,0},
tass 0:8ac2e5a7f731 41 {NXP_HOST_REQUEST,NXP_HOST,0,0,0x7FFFFFFF,0}
tass 0:8ac2e5a7f731 42 };
tass 0:8ac2e5a7f731 43
tass 0:8ac2e5a7f731 44 void printStatistics(void)
tass 0:8ac2e5a7f731 45 {
tass 0:8ac2e5a7f731 46 printf("\nTotal Time : %f seconds\n",(float)totalTime/1000.0f);
tass 0:8ac2e5a7f731 47 for(int i=0;i<NUMBER_OF_HOSTS;i++)
tass 0:8ac2e5a7f731 48 {
tass 0:8ac2e5a7f731 49 printf("Host number : %d | %s\n",i, webStatistics[i].host);
tass 0:8ac2e5a7f731 50 printf("MaxRecv : %d\n",webStatistics[i].maxReceived);
tass 0:8ac2e5a7f731 51 printf("MinRecv : %d\n",webStatistics[i].minReceived);
tass 0:8ac2e5a7f731 52 printf("Avg duration : %d ms\n",webStatistics[i].avgDuration);
tass 0:8ac2e5a7f731 53 printf("Total snapshots : %d\n\n",webStatistics[i].snapshots);
tass 0:8ac2e5a7f731 54 }
tass 0:8ac2e5a7f731 55
tass 0:8ac2e5a7f731 56 }
tass 0:8ac2e5a7f731 57
tass 0:8ac2e5a7f731 58 int main() {
tass 0:8ac2e5a7f731 59
tass 0:8ac2e5a7f731 60 int retries = 0;
tass 0:8ac2e5a7f731 61 EthernetInterface eth;
tass 0:8ac2e5a7f731 62 TCPSocketConnection client;
tass 0:8ac2e5a7f731 63
tass 0:8ac2e5a7f731 64 printf("Initialising...\n");
tass 0:8ac2e5a7f731 65
tass 0:8ac2e5a7f731 66 // use DHCP
tass 0:8ac2e5a7f731 67 eth.init();
tass 0:8ac2e5a7f731 68
tass 0:8ac2e5a7f731 69 // attempt DHCP and if timing out then try again
tass 0:8ac2e5a7f731 70 while (eth.connect()) {
tass 0:8ac2e5a7f731 71 retries++;
tass 0:8ac2e5a7f731 72 printf("[%d] DHCP timeout %d\n",PICO_TIME_MS(),retries);
tass 0:8ac2e5a7f731 73 if(retries >= DHCP_RETRIES)
tass 0:8ac2e5a7f731 74 {
tass 0:8ac2e5a7f731 75 printf("DHCP failed. Bailing out..\n");
tass 0:8ac2e5a7f731 76 goto failure;
tass 0:8ac2e5a7f731 77 }
tass 0:8ac2e5a7f731 78 };
tass 0:8ac2e5a7f731 79
tass 0:8ac2e5a7f731 80 printf("[%d] Starting the robustness test...\n",PICO_TIME_MS());
tass 0:8ac2e5a7f731 81
tass 0:8ac2e5a7f731 82 while(1)
tass 0:8ac2e5a7f731 83 {
tass 0:8ac2e5a7f731 84 for(int i=0;i<NUMBER_OF_HOSTS;i++,client.close())
tass 0:8ac2e5a7f731 85 {
tass 0:8ac2e5a7f731 86 int retries = 0;
tass 0:8ac2e5a7f731 87 int received = 0;
tass 0:8ac2e5a7f731 88 int time = 0;
tass 0:8ac2e5a7f731 89 char tmpBuffer[BUFFER_SIZE];
tass 0:8ac2e5a7f731 90 int ret;
tass 0:8ac2e5a7f731 91
tass 0:8ac2e5a7f731 92 printf("Mbed --> %s\n",webStatistics[i].host);
tass 0:8ac2e5a7f731 93
tass 0:8ac2e5a7f731 94 time = PICO_TIME_MS();
tass 0:8ac2e5a7f731 95 // connecting
tass 0:8ac2e5a7f731 96 if (client.connect(webStatistics[i].host, 80)) {
tass 0:8ac2e5a7f731 97 printf("Failed to connect to : %s\n",webStatistics[i].host);
tass 0:8ac2e5a7f731 98 continue;
tass 0:8ac2e5a7f731 99 }
tass 0:8ac2e5a7f731 100
tass 0:8ac2e5a7f731 101 retries = 0;
tass 0:8ac2e5a7f731 102
tass 0:8ac2e5a7f731 103 // sending request
tass 0:8ac2e5a7f731 104 while(1)
tass 0:8ac2e5a7f731 105 {
tass 0:8ac2e5a7f731 106 if( (ret = client.send_all(webStatistics[i].request,strlen(webStatistics[i].request))) <= 0)
tass 0:8ac2e5a7f731 107 {
tass 0:8ac2e5a7f731 108 printf("Retry sending no %d, return :%d, error code :%d\n",retries,ret,pico_err);
tass 0:8ac2e5a7f731 109 retries++;
tass 0:8ac2e5a7f731 110 }
tass 0:8ac2e5a7f731 111 else break;
tass 0:8ac2e5a7f731 112
tass 0:8ac2e5a7f731 113 if(retries == SENDING_RETRIES+1)
tass 0:8ac2e5a7f731 114 {
tass 0:8ac2e5a7f731 115 printf("Failed sending. Bailing out this connection\n");
tass 0:8ac2e5a7f731 116 continue;
tass 0:8ac2e5a7f731 117 }
tass 0:8ac2e5a7f731 118 }
tass 0:8ac2e5a7f731 119 retries = 0;
tass 0:8ac2e5a7f731 120
tass 0:8ac2e5a7f731 121 // start reading
tass 0:8ac2e5a7f731 122 while(true)
tass 0:8ac2e5a7f731 123 {
tass 0:8ac2e5a7f731 124 if( (ret = client.receive(tmpBuffer,sizeof(tmpBuffer))) <= 0)
tass 0:8ac2e5a7f731 125 retries++;
tass 0:8ac2e5a7f731 126 else
tass 0:8ac2e5a7f731 127 received += ret;
tass 0:8ac2e5a7f731 128
tass 0:8ac2e5a7f731 129 if(retries == READING_RETRIES)
tass 0:8ac2e5a7f731 130 break;
tass 0:8ac2e5a7f731 131 }
tass 0:8ac2e5a7f731 132
tass 0:8ac2e5a7f731 133 //Snapshot!
tass 0:8ac2e5a7f731 134 time = PICO_TIME_MS() - time;
tass 0:8ac2e5a7f731 135
tass 0:8ac2e5a7f731 136 if(webStatistics[i].maxReceived < received)
tass 0:8ac2e5a7f731 137 {
tass 0:8ac2e5a7f731 138 webStatistics[i].maxReceived = received;
tass 0:8ac2e5a7f731 139 }
tass 0:8ac2e5a7f731 140
tass 0:8ac2e5a7f731 141 if(webStatistics[i].minReceived > received)
tass 0:8ac2e5a7f731 142 {
tass 0:8ac2e5a7f731 143 webStatistics[i].minReceived = received;
tass 0:8ac2e5a7f731 144 }
tass 0:8ac2e5a7f731 145 printf("Received : %d bytes\n",received);
tass 0:8ac2e5a7f731 146 webStatistics[i].avgDuration = ((webStatistics[i].avgDuration *(webStatistics[i].snapshots++) ) + time)/webStatistics[i].snapshots;
tass 0:8ac2e5a7f731 147 totalTime += time;
tass 0:8ac2e5a7f731 148 }
tass 0:8ac2e5a7f731 149
tass 0:8ac2e5a7f731 150 printStatistics();
tass 0:8ac2e5a7f731 151 Thread::wait(500);
tass 0:8ac2e5a7f731 152 }
tass 0:8ac2e5a7f731 153 failure:
tass 0:8ac2e5a7f731 154 printf("Fatal error. Main thread is inactive\n");
tass 0:8ac2e5a7f731 155 while(1);
tass 0:8ac2e5a7f731 156 }