| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /********************************************************************* |
| 2 | * |
||
| 3 | * TCP Performance Test |
||
| 4 | * Module for Microchip TCP/IP Stack |
||
| 5 | * -Establishes a connection and then sends out dummy packets |
||
| 6 | * from ROM memory |
||
| 7 | * -Reference: None. This is for testing only. |
||
| 8 | * |
||
| 9 | ********************************************************************* |
||
| 10 | * FileName: TCPPerformanceTest.c |
||
| 11 | * Dependencies: TCP |
||
| 12 | * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32 |
||
| 13 | * Compiler: Microchip C32 v1.05 or higher |
||
| 14 | * Microchip C30 v3.12 or higher |
||
| 15 | * Microchip C18 v3.30 or higher |
||
| 16 | * HI-TECH PICC-18 PRO 9.63PL2 or higher |
||
| 17 | * Company: Microchip Technology, Inc. |
||
| 18 | * |
||
| 19 | * Software License Agreement |
||
| 20 | * |
||
| 21 | * Copyright (C) 2002-2009 Microchip Technology Inc. All rights |
||
| 22 | * reserved. |
||
| 23 | * |
||
| 24 | * Microchip licenses to you the right to use, modify, copy, and |
||
| 25 | * distribute: |
||
| 26 | * (i) the Software when embedded on a Microchip microcontroller or |
||
| 27 | * digital signal controller product ("Device") which is |
||
| 28 | * integrated into Licensee's product; or |
||
| 29 | * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h, |
||
| 30 | * ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device |
||
| 31 | * used in conjunction with a Microchip ethernet controller for |
||
| 32 | * the sole purpose of interfacing with the ethernet controller. |
||
| 33 | * |
||
| 34 | * You should refer to the license agreement accompanying this |
||
| 35 | * Software for additional information regarding your rights and |
||
| 36 | * obligations. |
||
| 37 | * |
||
| 38 | * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT |
||
| 39 | * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT |
||
| 40 | * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
||
| 41 | * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
| 42 | * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR |
||
| 43 | * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF |
||
| 44 | * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS |
||
| 45 | * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE |
||
| 46 | * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER |
||
| 47 | * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT |
||
| 48 | * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. |
||
| 49 | * |
||
| 50 | * |
||
| 51 | * Author Date Comment |
||
| 52 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 53 | * Howard Schlunder 01/29/07 Original |
||
| 54 | ********************************************************************/ |
||
| 55 | #define __TCPPERFORMANCETEST_C |
||
| 56 | |||
| 57 | #include "TCPIPConfig.h" |
||
| 58 | |||
| 59 | #if defined(STACK_USE_TCP_PERFORMANCE_TEST) |
||
| 60 | |||
| 61 | #include "TCPIP Stack/TCPIP.h" |
||
| 62 | |||
| 63 | |||
| 64 | // The TCP port to listen on for TCP transmit tests |
||
| 65 | #define TX_PERFORMANCE_PORT 9762 |
||
| 66 | |||
| 67 | // The TCP port to listen on for TCP receive tests |
||
| 68 | #define RX_PERFORMANCE_PORT 9763 |
||
| 69 | |||
| 70 | void TCPTXPerformanceTask(void); |
||
| 71 | void TCPRXPerformanceTask(void); |
||
| 72 | |||
| 73 | /***************************************************************************** |
||
| 74 | Function: |
||
| 75 | void TCPPerformanceTask(void) |
||
| 76 | |||
| 77 | Summary: |
||
| 78 | Tests the performance of the TCP module. |
||
| 79 | |||
| 80 | Description: |
||
| 81 | This function calls both TCPTXPerformanceTask and TCPRXPerformanceTask |
||
| 82 | to perform the performance task functions. Refer to the documentation |
||
| 83 | for each of those functions for details. |
||
| 84 | |||
| 85 | Precondition: |
||
| 86 | TCP is initialized. |
||
| 87 | |||
| 88 | Parameters: |
||
| 89 | None |
||
| 90 | |||
| 91 | Returns: |
||
| 92 | None |
||
| 93 | ***************************************************************************/ |
||
| 94 | void TCPPerformanceTask(void) |
||
| 95 | { |
||
| 96 | TCPTXPerformanceTask(); |
||
| 97 | TCPRXPerformanceTask(); |
||
| 98 | } |
||
| 99 | |||
| 100 | /***************************************************************************** |
||
| 101 | Function: |
||
| 102 | void TCPTXPerformanceTask(void) |
||
| 103 | |||
| 104 | Summary: |
||
| 105 | Tests the transmit performance of the TCP module. |
||
| 106 | |||
| 107 | Description: |
||
| 108 | This function tests the transmit performance of the TCP module. To use, |
||
| 109 | open a telnet connection to the device on TX_PERFORMANCE_PORT (9762 by |
||
| 110 | default). The board will rapidly transmit data and report its performance |
||
| 111 | to the telnet client. |
||
| 112 | |||
| 113 | TCP performance is affected by many factors, including round-trip time |
||
| 114 | and the TCP buffer size. For faster results, increase the size of the |
||
| 115 | TX buffer size for the TCP_PURPOSE_TCP_PERFORMANCE_TX socket in |
||
| 116 | TCPIPConfig.h. Round-trip time is affected by the distance to the |
||
| 117 | device, so across the desk will be orders of magnitude faster than |
||
| 118 | across the Internet. |
||
| 119 | |||
| 120 | This function is particularly useful after development to determine the |
||
| 121 | impact of your application code on the stack's performance. A before and |
||
| 122 | after comparison will indicate if your application is unacceptably |
||
| 123 | blocking the processor or taking too long to execute. |
||
| 124 | |||
| 125 | Precondition: |
||
| 126 | TCP is initialized. |
||
| 127 | |||
| 128 | Parameters: |
||
| 129 | None |
||
| 130 | |||
| 131 | Returns: |
||
| 132 | None |
||
| 133 | ***************************************************************************/ |
||
| 134 | void TCPTXPerformanceTask(void) |
||
| 135 | { |
||
| 136 | static TCP_SOCKET MySocket = INVALID_SOCKET; |
||
| 137 | static DWORD dwTimeStart; |
||
| 138 | static DWORD dwBytesSent; |
||
| 139 | static DWORD_VAL dwVLine; |
||
| 140 | BYTE vBuffer[10]; |
||
| 141 | static BYTE vBytesPerSecond[12]; |
||
| 142 | WORD w; |
||
| 143 | DWORD dw; |
||
| 144 | QWORD qw; |
||
| 145 | |||
| 146 | // Start the TCP server, listening on PERFORMANCE_PORT |
||
| 147 | if(MySocket == INVALID_SOCKET) |
||
| 148 | { |
||
| 149 | MySocket = TCPOpen(0, TCP_OPEN_SERVER, TX_PERFORMANCE_PORT, TCP_PURPOSE_TCP_PERFORMANCE_TX); |
||
| 150 | |||
| 151 | // Abort operation if no TCP socket of type TCP_PURPOSE_TCP_PERFORMANCE_TEST is available |
||
| 152 | // If this ever happens, you need to go add one to TCPIPConfig.h |
||
| 153 | if(MySocket == INVALID_SOCKET) |
||
| 154 | return; |
||
| 155 | |||
| 156 | // Initialize cumulative line transmission counter |
||
| 157 | dwVLine.Val = 0; |
||
| 158 | } |
||
| 159 | |||
| 160 | // See how many bytes we can write to the TX FIFO |
||
| 161 | // If we can't fit a single line of data in, then |
||
| 162 | // lets just wait for now. |
||
| 163 | w = TCPIsPutReady(MySocket); |
||
| 164 | if(w < 12+27+5+32u) |
||
| 165 | return; |
||
| 166 | |||
| 167 | // Upon connection initialize timer and byte count variables |
||
| 168 | if(TCPIsConnected(MySocket)) |
||
| 169 | { |
||
| 170 | if(TCPWasReset(MySocket)) |
||
| 171 | { |
||
| 172 | dwTimeStart = TickGet(); |
||
| 173 | dwBytesSent = 0; |
||
| 174 | vBytesPerSecond[0] = 0; // Initialize empty string right now |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | vBuffer[0] = '0'; |
||
| 179 | vBuffer[1] = 'x'; |
||
| 180 | |||
| 181 | // Transmit as much data as the TX FIFO will allow |
||
| 182 | while(w >= 12+27+5+32u) |
||
| 183 | { |
||
| 184 | dwVLine.Val = TickGet(); |
||
| 185 | |||
| 186 | // Convert line counter to ASCII hex string |
||
| 187 | vBuffer[2] = btohexa_high(dwVLine.v[3]); |
||
| 188 | vBuffer[3] = btohexa_low(dwVLine.v[3]); |
||
| 189 | vBuffer[4] = btohexa_high(dwVLine.v[2]); |
||
| 190 | vBuffer[5] = btohexa_low(dwVLine.v[2]); |
||
| 191 | vBuffer[6] = btohexa_high(dwVLine.v[1]); |
||
| 192 | vBuffer[7] = btohexa_low(dwVLine.v[1]); |
||
| 193 | vBuffer[8] = btohexa_high(dwVLine.v[0]); |
||
| 194 | vBuffer[9] = btohexa_low(dwVLine.v[0]); |
||
| 195 | |||
| 196 | dwVLine.Val++; |
||
| 197 | |||
| 198 | // Place all data in the TCP TX FIFO |
||
| 199 | TCPPutArray(MySocket, vBuffer, sizeof(vBuffer)); |
||
| 200 | TCPPutROMString(MySocket, (ROM BYTE*)": We are currently achieving "); |
||
| 201 | TCPPutROMArray(MySocket, (ROM BYTE*)" ", 5-strlen((char*)vBytesPerSecond)); |
||
| 202 | TCPPutString(MySocket, vBytesPerSecond); |
||
| 203 | TCPPutROMString(MySocket, (ROM BYTE*)"00 bytes/second TX throughput.\r\n"); |
||
| 204 | |||
| 205 | w -= 12+27+5+32; |
||
| 206 | dwBytesSent += 12+27+5+32; |
||
| 207 | } |
||
| 208 | |||
| 209 | // Send everything immediately |
||
| 210 | TCPFlush(MySocket); |
||
| 211 | |||
| 212 | // Calculate exact bytes/second, less truncation |
||
| 213 | dw = TickGet() - dwTimeStart; |
||
| 214 | if(dw > TICK_SECOND/10) |
||
| 215 | { |
||
| 216 | // qw = ((QWORD)dwBytesSent) * (TICK_SECOND/100/8); |
||
| 217 | // qw = ((QWORD)dwBytesSent) * (TICK_SECOND/100); |
||
| 218 | // qw /= dw; |
||
| 219 | qw = ((QWORD)dwBytesSent)*(TICK_SECOND/100) + (dw>>1); |
||
| 220 | qw /= dw; |
||
| 221 | ultoa((DWORD)qw, vBytesPerSecond); |
||
| 222 | dwTimeStart += dw; |
||
| 223 | |||
| 224 | dwBytesSent = 0; |
||
| 225 | //dwBytesSent -= dwBytesSent>>4; |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | /***************************************************************************** |
||
| 230 | Function: |
||
| 231 | void TCPRXPerformanceTask(void) |
||
| 232 | |||
| 233 | Summary: |
||
| 234 | Tests the receive performance of the TCP module. |
||
| 235 | |||
| 236 | Description: |
||
| 237 | This function tests the receive performance of the TCP module. To use, |
||
| 238 | open a telnet connection to the device on RX_PERFORMANCE_PORT (9763 by |
||
| 239 | default). Then use your telnet utility to upload a large file to the |
||
| 240 | device. Each second the board will report back how many bytes were |
||
| 241 | received in the previous second. |
||
| 242 | |||
| 243 | TCP performance is affected by many factors, including round-trip time |
||
| 244 | and the TCP buffer size. For faster results, increase the size of the |
||
| 245 | RX buffer size for the TCP_PURPOSE_TCP_PERFORMANCE_RX socket in |
||
| 246 | TCPIPConfig.h. Round-trip time is affected by the distance to the |
||
| 247 | device, so across the desk will be orders of magnitude faster than |
||
| 248 | across the Internet. |
||
| 249 | |||
| 250 | This function is particularly useful after development to determine the |
||
| 251 | impact of your application code on the stack's performance. A before and |
||
| 252 | after comparison will indicate if your application is unacceptably |
||
| 253 | blocking the processor or taking too long to execute. |
||
| 254 | |||
| 255 | Precondition: |
||
| 256 | TCP is initialized. |
||
| 257 | |||
| 258 | Parameters: |
||
| 259 | None |
||
| 260 | |||
| 261 | Returns: |
||
| 262 | None |
||
| 263 | ***************************************************************************/ |
||
| 264 | void TCPRXPerformanceTask(void) |
||
| 265 | { |
||
| 266 | static TCP_SOCKET MySocket = INVALID_SOCKET; |
||
| 267 | static DWORD dwTimeStart; |
||
| 268 | static DWORD dwBytesRead; |
||
| 269 | BYTE vBuffer[12]; |
||
| 270 | WORD w, wGetLen; |
||
| 271 | DWORD dw; |
||
| 272 | QWORD qw; |
||
| 273 | |||
| 274 | // Start the TCP server, listening on RX_PERFORMANCE_PORT |
||
| 275 | if(MySocket == INVALID_SOCKET) |
||
| 276 | { |
||
| 277 | MySocket = TCPOpen(0, TCP_OPEN_SERVER, RX_PERFORMANCE_PORT, TCP_PURPOSE_TCP_PERFORMANCE_RX); |
||
| 278 | |||
| 279 | // Abort operation if no TCP socket of type TCP_PURPOSE_TCP_PERFORMANCE_TEST_RX is available |
||
| 280 | // If this ever happens, you need to go add one to TCPIPConfig.h |
||
| 281 | if(MySocket == INVALID_SOCKET) |
||
| 282 | return; |
||
| 283 | |||
| 284 | dwTimeStart = TickGet(); |
||
| 285 | dwBytesRead = 0; |
||
| 286 | } |
||
| 287 | |||
| 288 | // Read all data out of the TCP RX FIFO |
||
| 289 | w = TCPIsGetReady(MySocket); |
||
| 290 | if(w == 0u) |
||
| 291 | return; |
||
| 292 | |||
| 293 | dwBytesRead += w; |
||
| 294 | wGetLen = sizeof(vBuffer); |
||
| 295 | while(w) |
||
| 296 | { |
||
| 297 | if(w < sizeof(vBuffer)) |
||
| 298 | wGetLen = w; |
||
| 299 | TCPGetArray(MySocket, vBuffer, wGetLen); |
||
| 300 | w -= wGetLen; |
||
| 301 | } |
||
| 302 | |||
| 303 | dw = TickGet() - dwTimeStart; |
||
| 304 | if(dw > TICK_SECOND) |
||
| 305 | { |
||
| 306 | if(TCPIsPutReady(MySocket) < 40u) |
||
| 307 | return; |
||
| 308 | |||
| 309 | dwTimeStart = TickGet(); |
||
| 310 | |||
| 311 | // Calculate exact bytes/second, with rounding |
||
| 312 | qw = (QWORD)dwBytesRead * TICK_SECOND; |
||
| 313 | qw += dw>>1; |
||
| 314 | qw /= dw; |
||
| 315 | ultoa((DWORD)qw, vBuffer); |
||
| 316 | TCPPutString(MySocket, vBuffer); |
||
| 317 | TCPPutROMString(MySocket, (ROM BYTE*)" bytes/second\r\n"); |
||
| 318 | |||
| 319 | dwBytesRead = 0; |
||
| 320 | } |
||
| 321 | |||
| 322 | |||
| 323 | } |
||
| 324 | |||
| 325 | #endif //#if defined(STACK_USE_TCP_PERFORMANCE_TEST) |
Powered by WebSVN v2.8.3