- Timestamp:
- 02/21/07 14:39:26 (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:
- 09be643
- Parents:
- c14602f
- Location:
- tools/tracereport
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/tracereport/Makefile.am
rdeab767f rd4336d5 1 ## Process this file with automake to produce Makefile.in 2 3 ## Created by Anjuta - will be overwritten 4 ## If you don't want it to overwrite it, 5 ## Please disable it in the Anjuta project configuration 6 7 man_MANS = tracereport.1 8 EXTRA_DIST = $(man_MANS) 9 include ../Makefile.tools 1 10 bin_PROGRAMS = tracereport 2 man_MANS=tracereport.13 11 4 include ../Makefile.tools 5 tracereport_SOURCES = tracereport.c tracereport.h report.h \ 6 contain.c contain.h \ 7 ttl_report.c tos_report.c port_report.c error_report.c \ 8 flow_report.c dir_report.c protocol_report.c 12 tracereport_SOURCES = \ 13 tracereport.c\ 14 contain.c\ 15 dir_report.c\ 16 error_report.c\ 17 flow_report.c\ 18 port_report.c\ 19 protocol_report.c\ 20 tos_report.c\ 21 ttl_report.c\ 22 tcpopt_report.c\ 23 nlp_report.c\ 24 ecn_report.c\ 25 tcpsegment_report.c\ 26 contain.h\ 27 report.h\ 28 tracereport.h 9 29 30 tracereport_LDFLAGS = 31 32 tracereport_LDADD = \ 33 -ltrace 34 -
tools/tracereport/dir_report.c
r870e501 rd4336d5 5 5 #include "libtrace.h" 6 6 #include "tracereport.h" 7 #include "report.h"8 7 9 8 static uint64_t dir_bytes[8]; … … 12 11 void dir_per_packet(struct libtrace_packet_t *packet) 13 12 { 14 if (trace_get_direction(packet)== ~0U)13 if (trace_get_direction(packet)==-1) 15 14 return; 16 15 dir_bytes[trace_get_direction(packet)]+=trace_get_wire_length(packet); -
tools/tracereport/flow_report.c
ra7282fb rd4336d5 7 7 #include "tracereport.h" 8 8 #include "contain.h" 9 #include "report.h"10 9 11 10 static uint64_t flow_count=0; -
tools/tracereport/port_report.c
ra7282fb rd4336d5 8 8 #include "tracereport.h" 9 9 #include "contain.h" 10 #include "report.h"11 10 12 stat_t ports[ 256][65536]={{{0,0}}};11 stat_t ports[4][256][65536]={{{{0,0}}}}; 13 12 char protn[256]={0}; 13 static bool suppress[4] = {true,true,true,true}; 14 14 15 15 void port_per_packet(struct libtrace_packet_t *packet) … … 17 17 uint8_t proto; 18 18 int port; 19 19 int dir = trace_get_direction(packet); 20 if(dir < 0 || dir > 1) 21 dir = 2; 20 22 if(trace_get_transport(packet,&proto,NULL)==NULL) 21 23 return; … … 27 29 : trace_get_destination_port(packet); 28 30 29 ports[ proto][port].bytes+=trace_get_wire_length(packet);30 ports[ proto][port].count++;31 ports[dir][proto][port].bytes+=trace_get_wire_length(packet); 32 ports[dir][proto][port].count++; 31 33 protn[proto]=1; 34 suppress[dir] = false; 32 35 } 33 36 34 static void port_port(int i,char *prot, int j) 37 void port_suppress() 38 { 39 int i; 40 printf("%-20s","Direction:"); 41 //printf("%20s", " "); 42 for(i=0;i<4;i++){ 43 if(!suppress[i]){ 44 switch(i){ 45 case 0: 46 printf("\t%24s", "Outbound "); 47 break; 48 case 1: 49 printf("\t%24s", "Inbound "); 50 break; 51 case 2: 52 printf("\t%24s", "Undefined "); 53 break; 54 default: 55 break; 56 } 57 } 58 } 59 printf("\n"); 60 printf("%-20s","Port"); 61 for(i=0;i<4;i++){ 62 if(!suppress[i]){ 63 printf("\t%12s\t%12s", "bytes","packets"); 64 } 65 } 66 printf("\n"); 67 } 68 69 void port_port(int i,char *prot, int j) 35 70 { 36 71 struct servent *ent = getservbyport(htons(j),prot); 37 if(ent) 38 printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", 39 ent->s_name, 40 ports[i][j].bytes, 41 ports[i][j].count 72 int k; 73 74 if(ent){ 75 printf("%20s:",ent->s_name); 76 for(k=0;k<4;k++){ 77 if (ports[k][i][j].count==0){ 78 if(!suppress[k]) 79 printf("\t%24s"," "); 80 continue; 81 } 82 printf("\t%12" PRIu64 "\t%12" PRIu64, 83 ports[k][i][j].bytes, 84 ports[k][i][j].count 42 85 ); 43 else 44 printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n", 45 j, 46 ports[i][j].bytes, 47 ports[i][j].count 86 } 87 } 88 else{ 89 printf("%20i:",j); 90 for(k=0;k<4;k++){ 91 if (ports[k][i][j].count==0){ 92 if(!suppress[k]) 93 printf("\t%24s"," "); 94 continue; 95 } 96 printf("\t%12" PRIu64 "\t%12" PRIu64, 97 ports[k][i][j].bytes, 98 ports[k][i][j].count 48 99 ); 100 } 101 } 102 printf("\n"); 49 103 } 50 104 51 staticvoid port_protocol(int i)105 void port_protocol(int i) 52 106 { 53 int j ;107 int j,k; 54 108 struct protoent *ent = getprotobynumber(i); 55 109 printf("Protocol: %i %s%s%s\n",i, 56 110 ent?"(":"",ent?ent->p_name:"",ent?")":""); 57 111 for(j=0;j<65536;++j) { 58 if (ports[i][j].count) { 59 port_port(i,ent?ent->p_name:"",j); 112 for(k=0;k<4;k++){ 113 if (ports[k][i][j].count) { 114 port_port(i,ent?ent->p_name:"",j); 115 break; 116 } 60 117 } 61 118 } … … 66 123 int i; 67 124 printf("# Port breakdown:\n"); 68 p rintf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets");125 port_suppress(); 69 126 setservent(1); 70 127 setprotoent(1); … … 76 133 endprotoent(); 77 134 endservent(); 135 136 int total, j,k; 137 for(i=0;i<4;i++){ 138 total = 0; 139 for(j=0;j<256;j++) 140 for(k=0;k<65536;k++) 141 total += ports[i][j][k].count; 142 //printf("%s: %i\n", "Total", total); 143 } 78 144 } -
tools/tracereport/protocol_report.c
r938dbd9 rd4336d5 7 7 #include "report.h" 8 8 9 static stat_t prot_stat[256] = { {0,0} } ; 9 static stat_t prot_stat[4][256] = {{{0,0}}} ; 10 static bool suppress[4] = {true,true,true,true}; 10 11 11 12 void protocol_per_packet(struct libtrace_packet_t *packet) 12 13 { 13 14 uint8_t proto; 15 int dir = trace_get_direction(packet); 16 if(dir < 0 || dir > 1) 17 dir = 2; 14 18 if (trace_get_transport(packet,&proto,NULL)==NULL) 15 19 return; 16 20 17 prot_stat[proto].count++; 18 prot_stat[proto].bytes+=trace_get_wire_length(packet); 21 prot_stat[dir][proto].count++; 22 prot_stat[dir][proto].bytes+=trace_get_wire_length(packet); 23 suppress[dir] = false; 24 } 25 26 void protocol_suppress() 27 { 28 int i; 29 printf("%-20s","Direction:"); 30 //printf("%20s", " "); 31 for(i=0;i<4;i++){ 32 if(!suppress[i]){ 33 switch(i){ 34 case 0: 35 printf("\t%24s", "Outbound "); 36 break; 37 case 1: 38 printf("\t%24s", "Inbound "); 39 break; 40 case 2: 41 printf("\t%24s", "Undefined "); 42 break; 43 default: 44 break; 45 } 46 } 47 } 48 printf("\n"); 49 printf("%-20s","Protocol"); 50 for(i=0;i<4;i++){ 51 if(!suppress[i]){ 52 printf("\t%12s\t%12s", "bytes","packets"); 53 } 54 } 55 printf("\n"); 19 56 } 20 57 21 58 void protocol_report(void) 22 59 { 23 int i ;60 int i,j; 24 61 printf("# Protocol breakdown:\n"); 25 pr intf("%-20s \t%12s\t%12s\n","Protocol","bytes","packets");62 protocol_suppress(); 26 63 setprotoent(1); 27 64 for(i=0;i<256;++i) { 28 65 struct protoent *prot; 29 if (prot_stat[i].count==0) 66 if (prot_stat[0][i].count==0 && 67 prot_stat[1][i].count==0 && prot_stat[2][i].count==0) 30 68 continue; 31 69 prot = getprotobynumber(i); 32 70 if (prot) { 33 printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n", 34 prot->p_name, 35 prot_stat[i].bytes, 36 prot_stat[i].count); 71 printf("%20s",prot->p_name); 72 for(j=0;j<4;j++){ 73 if (prot_stat[j][i].count==0){ 74 if(!suppress[j]) 75 printf("\t%24s"," "); 76 continue; 77 } 78 printf("\t%12" PRIu64 "\t%12" PRIu64, 79 prot_stat[j][i].bytes, 80 prot_stat[j][i].count); 81 } 37 82 } 38 83 else { 39 printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n", 40 i, 41 prot_stat[i].bytes, 42 prot_stat[i].count); 43 84 printf("%20i:",i); 85 for(j=0;j<4;j++){ 86 if (prot_stat[j][i].count==0){ 87 if(!suppress[j]) 88 printf("\t%24s"," "); 89 continue; 90 } 91 printf("\t%12" PRIu64 "\t%12" PRIu64, 92 prot_stat[j][i].bytes, 93 prot_stat[j][i].count); 94 } 44 95 } 96 printf("\n"); 45 97 } 46 98 setprotoent(0); 99 100 int total; 101 for(i=0;i<4;i++){ 102 total = 0; 103 for(j=0;j<256;j++) 104 total += prot_stat[i][j].count; 105 //printf("%s: %i\n", "Total", total); 106 } 47 107 } -
tools/tracereport/report.h
r73ef8ce rd4336d5 9 9 void tos_per_packet(struct libtrace_packet_t *packet); 10 10 void ttl_per_packet(struct libtrace_packet_t *packet); 11 void tcpopt_per_packet(struct libtrace_packet_t *packet); 12 void nlp_per_packet(struct libtrace_packet_t *packet); 13 void ecn_per_packet(struct libtrace_packet_t *packet); 14 void tcpseg_per_packet(struct libtrace_packet_t *packet); 11 15 12 16 void dir_report(void); … … 17 21 void tos_report(void); 18 22 void ttl_report(void); 23 void tcpopt_report(void); 24 void nlp_report(void); 25 void ecn_report(void); 26 void tcpseg_report(void); 19 27 20 28 #endif -
tools/tracereport/tos_report.c
ra7282fb rd4336d5 5 5 #include "libtrace.h" 6 6 #include "tracereport.h" 7 #include "report.h"8 7 9 static stat_t tos_stat[256] = { {0,0} } ; 8 static stat_t tos_stat[4][256] = {{{0,0}}} ; 9 static bool suppress[4] = {true,true,true,true}; 10 10 11 11 void tos_per_packet(struct libtrace_packet_t *packet) 12 12 { 13 13 struct libtrace_ip *ip = trace_get_ip(packet); 14 14 15 if (!ip) 15 16 return; 17 int dir = trace_get_direction(packet); 18 if(dir < 0 || dir > 1) 19 dir = 2; 20 tos_stat[dir][ip->ip_tos].count++; 21 tos_stat[dir][ip->ip_tos].bytes+=trace_get_wire_length(packet); 22 suppress[dir] = false; 23 } 16 24 17 tos_stat[ip->ip_tos].count++; 18 tos_stat[ip->ip_tos].bytes+=trace_get_wire_length(packet); 25 void tos_suppress() 26 { 27 int i; 28 printf("%-20s","Direction:"); 29 //printf("%20s", " "); 30 for(i=0;i<4;i++){ 31 if(!suppress[i]){ 32 switch(i){ 33 case 0: 34 printf("\t%24s", "Outbound "); 35 break; 36 case 1: 37 printf("\t%24s", "Inbound "); 38 break; 39 case 2: 40 printf("\t%24s", "Undefined "); 41 break; 42 default: 43 break; 44 } 45 } 46 } 47 printf("\n"); 48 printf("%-20s","ToS"); 49 for(i=0;i<4;i++){ 50 if(!suppress[i]){ 51 printf("\t%12s\t%12s", "bytes","packets"); 52 } 53 } 54 printf("\n"); 19 55 } 20 56 21 57 void tos_report(void) 22 58 { 23 int i ;59 int i,j; 24 60 printf("# TOS breakdown:\n"); 25 printf("%-20s \t%12s\t%12s\n","ToS","bytes","packets");61 tos_suppress(); 26 62 for(i=0;i<256;++i) { 27 if (tos_stat[i].count==0) 63 if (tos_stat[0][i].count==0 && 64 tos_stat[1][i].count==0 && tos_stat[2][i].count==0) 28 65 continue; 29 printf("%16s0x%02x:\t%12" PRIu64 ":\t%12" PRIu64 "\n", 30 " ", 31 i, 32 tos_stat[i].bytes, 33 tos_stat[i].count); 66 printf("%20i:",i); 67 for(j=0;j<4;j++){ 68 if (tos_stat[j][i].count==0){ 69 if(!suppress[j]) 70 printf("\t%24s"," "); 71 continue; 72 } 73 printf("\t%12" PRIu64 "\t%12" PRIu64, 74 tos_stat[j][i].bytes, 75 tos_stat[j][i].count); 76 } 77 printf("\n"); 78 } 79 80 int total; 81 for(i=0;i<4;i++){ 82 total = 0; 83 for(j=0;j<256;j++) 84 total += tos_stat[i][j].count; 85 //printf("%s: %i\n", "Total", total); 34 86 } 35 87 } -
tools/tracereport/tracereport.c
rd5a27e8 rd4336d5 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 200 7The University of Waikato, Hamilton, New Zealand.4 * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. 5 5 * Authors: Daniel Lawson 6 6 * Perry Lorier 7 * Josef Vodanovich 7 8 * 8 9 * All rights reserved. … … 50 51 #include <getopt.h> 51 52 #include <inttypes.h> 52 #include "lt_inttypes.h"53 //#include "lt_inttypes.h" 53 54 54 55 #include "libtrace.h" … … 59 60 60 61 /* Process a trace, counting packets that match filter(s) */ 61 staticvoid run_trace(char *uri, libtrace_filter_t *filter, int count)62 void run_trace(char *uri, libtrace_filter_t *filter, int count) 62 63 { 63 64 struct libtrace_packet_t *packet = trace_create_packet(); 64 65 65 66 fprintf(stderr,"%s:\n",uri); 66 67 trace = trace_create(uri); 67 trace = trace_create(uri); 68 68 69 if (trace_is_err(trace)) { 69 70 trace_perror(trace,"trace_create"); … … 80 81 } 81 82 82 83 for (;;) { 83 84 int psize; 84 85 if (count--<1) 85 86 break; 86 if ((psize = trace_read_packet(trace, packet)) <1) { 87 break; 88 } 89 87 if ((psize = trace_read_packet(trace, packet)) <1) { 88 break; 89 } 90 90 error_per_packet(packet); 91 91 port_per_packet(packet); … … 94 94 ttl_per_packet(packet); 95 95 flow_per_packet(packet); 96 tcpopt_per_packet(packet); 97 nlp_per_packet(packet); 96 98 dir_per_packet(packet); 97 98 } 99 100 99 //ecn_per_packet(packet); 100 //tcpseg_per_packet(packet); 101 } 102 trace_destroy(trace); 101 103 } 102 104 103 staticvoid usage(char *argv0)105 void usage(char *argv0) 104 106 { 105 107 fprintf(stderr,"Usage:\n" 106 108 "%s flags traceuri [traceuri...]\n" 107 "-f --filter 109 "-f --filter=bpf Apply BPF filter. Can be specified multiple times\n" 108 110 "-H --libtrace-help Print libtrace runtime documentation\n" 109 111 ,argv0); … … 113 115 int main(int argc, char *argv[]) { 114 116 115 libtrace_filter_t *filter = NULL;117 int i; 116 118 117 if (argc<2) 118 usage(argv[0]); 119 /*char *filterstring="host 130.197.127.210"; */ 119 120 120 while(1) { 121 int option_index; 122 struct option long_options[] = { 123 { "filter", 1, 0, 'f' }, 124 { "libtrace-help", 0, 0, 'H' }, 125 {NULL, 0, 0, 0 }, 126 }; 127 int c = getopt_long(argc, argv, "f:H", 128 long_options, &option_index); 129 if (c == -1) 130 break; 131 switch(c) { 132 case 'f': 133 if (filter != NULL) { 134 fprintf(stderr,"You can only have one filter\n"); 135 usage(argv[0]); 136 } 137 filter=trace_create_filter(optarg); 138 break; 139 case 'H': 140 trace_help(); 141 exit(1); 142 break; 143 default: 144 printf("Unknown option: %c\n", c); 145 usage(argv[0]); 146 } 147 } 121 libtrace_filter_t *filter = NULL;/*trace_bpf_setfilter(filterstring); */ 148 122 149 while(optind < argc) {150 run_trace(argv[ optind++],filter,(1<<30));123 for(i=1;i<argc;++i) { 124 run_trace(argv[i],filter,(1<<30)); 151 125 } 152 126 … … 157 131 port_report(); 158 132 ttl_report(); 133 tcpopt_report(); 134 nlp_report(); 159 135 dir_report(); 160 161 return 0; 136 //ecn_report(); 137 //tcpseg_report(); 138 return 0; 162 139 } -
tools/tracereport/ttl_report.c
ra7282fb rd4336d5 5 5 #include "libtrace.h" 6 6 #include "tracereport.h" 7 #include "report.h"8 7 9 static stat_t ttl_stat[256] = { {0,0} } ; 8 static stat_t ttl_stat[4][256] = {{{0,0}}} ; 9 static bool suppress[4] = {true,true,true,true}; 10 10 11 11 void ttl_per_packet(struct libtrace_packet_t *packet) … … 14 14 if (!ip) 15 15 return; 16 int dir = trace_get_direction(packet); 17 if(dir < 0 || dir > 1) 18 dir = 2; 19 ttl_stat[dir][ip->ip_ttl].count++; 20 ttl_stat[dir][ip->ip_ttl].bytes+=trace_get_wire_length(packet); 21 suppress[dir] = false; 22 } 16 23 17 ttl_stat[ip->ip_ttl].count++; 18 ttl_stat[ip->ip_ttl].bytes+=trace_get_wire_length(packet); 24 void ttl_suppress() 25 { 26 int i; 27 printf("%-20s","Direction:"); 28 //printf("%20s", " "); 29 for(i=0;i<4;i++){ 30 if(!suppress[i]){ 31 switch(i){ 32 case 0: 33 printf("\t%24s", "Outbound "); 34 break; 35 case 1: 36 printf("\t%24s", "Inbound "); 37 break; 38 case 2: 39 printf("\t%24s", "Undefined "); 40 break; 41 default: 42 break; 43 } 44 } 45 } 46 printf("\n"); 47 printf("%-20s","TTL"); 48 for(i=0;i<4;i++){ 49 if(!suppress[i]){ 50 printf("\t%12s\t%12s", "bytes","packets"); 51 } 52 } 53 printf("\n"); 19 54 } 20 55 21 56 void ttl_report(void) 22 57 { 23 int i ;58 int i,j; 24 59 printf("# TTL breakdown:\n"); 25 printf("%-20s \t%12s\t%12s\n","TTL","bytes","packets");60 ttl_suppress(); 26 61 for(i=0;i<256;++i) { 27 if (ttl_stat[i].count==0) 62 if (ttl_stat[0][i].count==0 && 63 ttl_stat[1][i].count==0 && ttl_stat[2][i].count==0) 28 64 continue; 29 printf("%20i:\t%12" PRIu64 ":\t%12" PRIu64 "\n", 30 i, 31 ttl_stat[i].bytes, 32 ttl_stat[i].count); 65 printf("%20i:",i); 66 for(j=0;j<4;j++){ 67 if (ttl_stat[j][i].count==0){ 68 if(!suppress[j]) 69 printf("\t%24s"," "); 70 continue; 71 } 72 printf("\t%12" PRIu64 "\t%12" PRIu64, 73 ttl_stat[j][i].bytes, 74 ttl_stat[j][i].count); 75 } 76 printf("\n"); 77 } 78 79 int total; 80 for(i=0;i<4;i++){ 81 total = 0; 82 for(j=0;j<256;j++) 83 total += ttl_stat[i][j].count; 84 //printf("%s: %i\n", "Total", total); 33 85 } 34 86 }
Note: See TracChangeset
for help on using the changeset viewer.