Simple text for Tx bandwidth of ethernet
Revision 0:f1fc262e9984, committed 2011-02-24
- Comitter:
- simon
- Date:
- Thu Feb 24 18:37:28 2011 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r f1fc262e9984 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 24 18:37:28 2011 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" + +Ethernet eth; + +#define NPACKETS 100000 +#define NBYTES 1000 + +__packed struct EthPkt { + char dest[6]; + char src[6]; + unsigned short type; +}; + +unsigned short htons(unsigned short n) { // Host short to network short byte swapping + return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); +} + +char data[NBYTES]; + + + + + +int main() { + printf("Hello Ethernet Tx Benchmark!\n"); + + // fill the data with ascending pattern, inc packet header + for(int i=0; i<NBYTES; i++) { + data[i] = i; + } + EthPkt *pkt = (EthPkt*)&data[0]; + eth.address(pkt->src); // note, this call goes to the mbed interface, so takes a while + for(int i = 0; i<6; i++) { + pkt->dest[i] = 0xFF; + } + + while(!eth.link()); + + printf("Sending %d packets of %d bytes...\n", NPACKETS, NBYTES); + + Timer t; + t.start(); + for(int i = 0; i < NPACKETS; i++) { + eth.write(data, NBYTES); + eth.send(); + } + t.stop(); + + printf("Time = %.2f seconds\n", t.read()); + + float bw = NPACKETS * NBYTES * 8 / t.read(); + printf("bandwidth = %.2f kbps\n", bw / 1024.0); + +}