diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/ndpiReader.c | 38 | ||||
-rw-r--r-- | example/reader_util.c | 13 | ||||
-rw-r--r-- | example/reader_util.h | 2 |
3 files changed, 53 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 4acaea4bb..ef74a5a99 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -2916,6 +2916,9 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us } cumulative_stats.ndpi_flow_count += ndpi_thread_info[thread_id].workflow->stats.ndpi_flow_count; + cumulative_stats.flow_count[0] += ndpi_thread_info[thread_id].workflow->stats.flow_count[0]; + cumulative_stats.flow_count[1] += ndpi_thread_info[thread_id].workflow->stats.flow_count[1]; + cumulative_stats.flow_count[2] += ndpi_thread_info[thread_id].workflow->stats.flow_count[2]; cumulative_stats.tcp_count += ndpi_thread_info[thread_id].workflow->stats.tcp_count; cumulative_stats.udp_count += ndpi_thread_info[thread_id].workflow->stats.udp_count; cumulative_stats.mpls_count += ndpi_thread_info[thread_id].workflow->stats.mpls_count; @@ -2925,6 +2928,10 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us for(i = 0; i < sizeof(cumulative_stats.packet_len)/sizeof(cumulative_stats.packet_len[0]); i++) cumulative_stats.packet_len[i] += ndpi_thread_info[thread_id].workflow->stats.packet_len[i]; cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len; + + cumulative_stats.dpi_packet_count[0] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[0]; + cumulative_stats.dpi_packet_count[1] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[1]; + cumulative_stats.dpi_packet_count[2] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[2]; } if(cumulative_stats.total_wire_bytes == 0) @@ -2996,8 +3003,39 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us if(enable_protocol_guess) printf("\tGuessed flow protos: %-13u\n", cumulative_stats.guessed_flow_protocols); + + if(cumulative_stats.flow_count[0]) + printf("\tDPI Packets (TCP): %-13llu (%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[0], + cumulative_stats.dpi_packet_count[0] / (float)cumulative_stats.flow_count[0]); + if(cumulative_stats.flow_count[1]) + printf("\tDPI Packets (UDP): %-13llu (%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[1], + cumulative_stats.dpi_packet_count[1] / (float)cumulative_stats.flow_count[1]); + if(cumulative_stats.flow_count[2]) + printf("\tDPI Packets (other): %-13llu (%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[2], + cumulative_stats.dpi_packet_count[2] / (float)cumulative_stats.flow_count[2]); } + if(results_file) { + if(enable_protocol_guess) + fprintf(results_file, "Guessed flow protos:\t%u\n\n", cumulative_stats.guessed_flow_protocols); + + if(cumulative_stats.flow_count[0]) + fprintf(results_file, "DPI Packets (TCP):\t%llu\t(%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[0], + cumulative_stats.dpi_packet_count[0] / (float)cumulative_stats.flow_count[0]); + if(cumulative_stats.flow_count[1]) + fprintf(results_file, "DPI Packets (UDP):\t%llu\t(%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[1], + cumulative_stats.dpi_packet_count[1] / (float)cumulative_stats.flow_count[1]); + if(cumulative_stats.flow_count[2]) + fprintf(results_file, "DPI Packets (other):\t%llu\t(%.2f pkts/flow)\n", + (long long unsigned int)cumulative_stats.dpi_packet_count[2], + cumulative_stats.dpi_packet_count[2] / (float)cumulative_stats.flow_count[2]); + fprintf(results_file, "\n"); + } if(!quiet_mode) printf("\n\nDetected protocols:\n"); for(i = 0; i <= ndpi_get_num_supported_protocols(ndpi_thread_info[0].workflow->ndpi_struct); i++) { diff --git a/example/reader_util.c b/example/reader_util.c index a1c11532e..89a3fcfff 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -893,6 +893,12 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow ndpi_tsearch(newflow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp); /* Add */ workflow->stats.ndpi_flow_count++; + if(*proto == IPPROTO_TCP) + workflow->stats.flow_count[0]++; + else if(*proto == IPPROTO_UDP) + workflow->stats.flow_count[1]++; + else + workflow->stats.flow_count[2]++; *src = newflow->src_id, *dst = newflow->dst_id; newflow->entropy.src2dst_pkt_len[newflow->entropy.src2dst_pkt_count] = l4_data_len; @@ -1511,6 +1517,13 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow, printf("%s()\n", __FUNCTION__); #endif + if(proto == IPPROTO_TCP) + workflow->stats.dpi_packet_count[0]++; + else if(proto == IPPROTO_UDP) + workflow->stats.dpi_packet_count[1]++; + else + workflow->stats.dpi_packet_count[2]++; + flow->detected_protocol = ndpi_detection_process_packet(workflow->ndpi_struct, ndpi_flow, iph ? (uint8_t *)iph : (uint8_t *)iph6, ipsize, time_ms, src, dst); diff --git a/example/reader_util.h b/example/reader_util.h index 5175e868d..28ea6029e 100644 --- a/example/reader_util.h +++ b/example/reader_util.h @@ -256,10 +256,12 @@ typedef struct ndpi_stats { u_int64_t protocol_counter_bytes[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1]; u_int32_t protocol_flows[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1]; u_int32_t ndpi_flow_count; + u_int32_t flow_count[3]; u_int64_t tcp_count, udp_count; u_int64_t mpls_count, pppoe_count, vlan_count, fragmented_count; u_int64_t packet_len[6]; u_int16_t max_packet_len; + u_int64_t dpi_packet_count[3]; } ndpi_stats_t; |