Changeset 4eec8dc for tools/tracereport/nlp_report.c
- Timestamp:
- 02/22/07 13:48:08 (15 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- b5dc60d
- Parents:
- 013d3692
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereport/nlp_report.c
rd4336d5 r4eec8dc 6 6 #include "tracereport.h" 7 7 8 static stat_t nlp_stat[4][65536] = {{{0,0}}} ; 9 static bool suppress[4] = {true,true,true,true}; 8 static stat_t nlp_stat[3][65536] = {{{0,0}}} ; 10 9 11 10 void nlp_per_packet(struct libtrace_packet_t *packet) 12 11 { 13 unsigned char *p=trace_get_link(packet); 14 uint16_t a; 12 char *link=(char *)trace_get_link(packet); 13 uint16_t type = htons(*(uint16_t*)(link+12)); 14 libtrace_direction_t dir = trace_get_direction(packet); 15 16 if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING) 17 dir = TRACE_DIR_OTHER; 15 18 16 p += 12; 17 a = *p; 18 a *= 256; 19 a += p[1]; 20 int dir = trace_get_direction(packet); 21 if(dir < 0 || dir > 1) 22 dir = 2; 23 24 nlp_stat[dir][a].count++; 25 nlp_stat[dir][a].bytes+=trace_get_wire_length(packet); 26 suppress[dir] = false; 27 } 28 29 void nlp_suppress() 30 { 31 int i; 32 printf("%-20s","Direction:"); 33 //printf("%20s", " "); 34 for(i=0;i<4;i++){ 35 if(!suppress[i]){ 36 switch(i){ 37 case 0: 38 printf("\t%24s", "Outbound "); 39 break; 40 case 1: 41 printf("\t%24s", "Inbound "); 42 break; 43 case 2: 44 printf("\t%24s", "Undefined "); 45 break; 46 default: 47 break; 48 } 49 } 50 } 51 printf("\n"); 52 printf("%-20s","NLP"); 53 for(i=0;i<4;i++){ 54 if(!suppress[i]){ 55 printf("\t%12s\t%12s", "bytes","packets"); 56 } 57 } 58 printf("\n"); 19 nlp_stat[dir][type].count++; 20 nlp_stat[dir][type].bytes+=trace_get_wire_length(packet); 59 21 } 60 22 61 23 void nlp_report(void){ 62 printf("# Network Layer Protocol breakdown:\n");63 nlp_suppress();64 24 int i,j; 65 25 26 FILE *out = fopen("nlp.out", "w"); 27 if (!out) { 28 perror("fopen"); 29 return; 30 } 31 32 /* Put some headings up for human-readability */ 33 fprintf(out, "%-12s\t%8s\t%12s\t%12s\n", 34 "NETWORK LAYER", 35 "DIRECTION", 36 "BYTES", 37 "PACKETS"); 66 38 for(i = 0; i < 65536; i++){ 67 39 if (nlp_stat[0][i].count==0 && … … 70 42 switch(i){ 71 43 case 0x0800: 72 printf("%20s", "IPv4");44 fprintf(out, "%12s", "IPv4 |"); 73 45 break; 74 46 case 0x0806: 75 printf("%20s", "ARP");47 fprintf(out, "%12s", "ARP |"); 76 48 break; 77 case 0x8137: 78 printf("%20s", "IPX");49 case 0x8137: 50 fprintf(out, "%12s", "IPX |"); 79 51 break; 80 52 case 0x814C: 81 printf("%20s", "SNMP");53 fprintf(out, "%12s", "SNMP |"); 82 54 break; 83 55 case 0x86DD: 84 printf("%20s", "IPv6");56 fprintf(out, "%12s", "IPv6 |"); 85 57 break; 86 58 case 0x880B: 87 printf("%20s", "PPP");59 fprintf(out, "%12s", "PPP |"); 88 60 break; 89 61 default: 90 printf("%20i:",i);62 fprintf(out, "%10i |",i); 91 63 } 92 for(j=0;j<4;j++){ 93 if (nlp_stat[j][i].count==0){ 94 if(!suppress[j]) 95 printf("\t%24s"," "); 96 continue; 64 for(j=0;j<3;j++){ 65 if (j != 0) { 66 fprintf(out, "%12s", " |"); 97 67 } 98 printf("\t%12" PRIu64 "\t%12" PRIu64, 68 69 switch (j) { 70 case 0: 71 fprintf(out, "\t%8s", "Outbound"); 72 break; 73 case 1: 74 fprintf(out, "\t%8s", "Inbound"); 75 break; 76 case 2: 77 fprintf(out, "\t%8s", "Unknown"); 78 break; 79 } 80 81 fprintf(out, "\t%12llu %12llu\n", 99 82 nlp_stat[j][i].bytes, 100 83 nlp_stat[j][i].count); 101 84 } 102 printf("\n");103 85 } 86 fclose(out); 104 87 }
Note: See TracChangeset
for help on using the changeset viewer.