Added flow duration and goodput in output (-v and -c)

This commit is contained in:
Luca Deri
2019-11-21 13:31:56 +01:00
parent f91f2c57ef
commit a58c838c4c
3 changed files with 59 additions and 41 deletions
+34 -17
View File
@@ -565,9 +565,9 @@ void extcap_capture() {
void printCSVHeader() { void printCSVHeader() {
if(!csv_fp) return; if(!csv_fp) return;
fprintf(csv_fp, "#flow_id,protocol,first_seen,last_seen,src_ip,src_port,dst_ip,dst_port,ndpi_proto_num,ndpi_proto,"); fprintf(csv_fp, "#flow_id,protocol,first_seen,last_seen,duration,src_ip,src_port,dst_ip,dst_port,ndpi_proto_num,ndpi_proto,");
fprintf(csv_fp, "src2dst_packets,src2dst_bytes,dst2src_packets,dst2src_bytes,"); fprintf(csv_fp, "src2dst_packets,src2dst_bytes,src2dst_goodput_bytes,dst2src_packets,dst2src_bytes,dst2src_goodput_bytes,");
fprintf(csv_fp, "data_ratio,str_data_ratio,"); fprintf(csv_fp, "data_ratio,str_data_ratio,src2dst_goodput_ratio,dst2src_goodput_ratio,");
/* IAT (Inter Arrival Time) */ /* IAT (Inter Arrival Time) */
fprintf(csv_fp, "iat_flow_min,iat_flow_avg,iat_flow_max,iat_flow_stddev,"); fprintf(csv_fp, "iat_flow_min,iat_flow_avg,iat_flow_max,iat_flow_stddev,");
@@ -801,19 +801,22 @@ static void parseOptions(int argc, char **argv) {
} }
} }
if(_pcap_file[0] == NULL)
help(0);
#ifndef USE_DPDK #ifndef USE_DPDK
if(strchr(_pcap_file[0], ',')) { /* multiple ingress interfaces */ if(strchr(_pcap_file[0], ',')) { /* multiple ingress interfaces */
num_threads = 0; /* setting number of threads = number of interfaces */ num_threads = 0; /* setting number of threads = number of interfaces */
__pcap_file = strtok(_pcap_file[0], ","); __pcap_file = strtok(_pcap_file[0], ",");
while(__pcap_file != NULL && num_threads < MAX_NUM_READER_THREADS) { while(__pcap_file != NULL && num_threads < MAX_NUM_READER_THREADS) {
_pcap_file[num_threads++] = __pcap_file; _pcap_file[num_threads++] = __pcap_file;
__pcap_file = strtok(NULL, ","); __pcap_file = strtok(NULL, ",");
}
} else {
if(num_threads > MAX_NUM_READER_THREADS) num_threads = MAX_NUM_READER_THREADS;
for(thread_id = 1; thread_id < num_threads; thread_id++)
_pcap_file[thread_id] = _pcap_file[0];
} }
} else {
if(num_threads > MAX_NUM_READER_THREADS) num_threads = MAX_NUM_READER_THREADS;
for(thread_id = 1; thread_id < num_threads; thread_id++)
_pcap_file[thread_id] = _pcap_file[0];
}
#ifdef linux #ifdef linux
for(thread_id = 0; thread_id < num_threads; thread_id++) for(thread_id = 0; thread_id < num_threads; thread_id++)
@@ -970,10 +973,11 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
/* PLEASE KEEP IN SYNC WITH printCSVHeader() */ /* PLEASE KEEP IN SYNC WITH printCSVHeader() */
fprintf(csv_fp, "%u,%u,%.3f,%.3f,%s,%u,%s,%u,", fprintf(csv_fp, "%u,%u,%.3f,%.3f,%.3f,%s,%u,%s,%u,",
flow->flow_id, flow->flow_id,
flow->protocol, flow->protocol,
f/1000.0, l/1000.0, f/1000.0, l/1000.0,
(l-f)/1000.0,
flow->src_name, ntohs(flow->src_port), flow->src_name, ntohs(flow->src_port),
flow->dst_name, ntohs(flow->dst_port) flow->dst_name, ntohs(flow->dst_port)
); );
@@ -983,9 +987,13 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct,
flow->detected_protocol, buf, sizeof(buf))); flow->detected_protocol, buf, sizeof(buf)));
fprintf(csv_fp, "%u,%llu,", flow->src2dst_packets, (long long unsigned int) flow->src2dst_bytes); fprintf(csv_fp, "%u,%llu,%llu,", flow->src2dst_packets,
fprintf(csv_fp, "%u,%llu,", flow->dst2src_packets, (long long unsigned int) flow->dst2src_bytes); (long long unsigned int) flow->src2dst_bytes, (long long unsigned int) flow->src2dst_goodput_bytes);
fprintf(csv_fp, "%u,%llu,%llu,", flow->dst2src_packets,
(long long unsigned int) flow->dst2src_bytes, (long long unsigned int) flow->dst2src_goodput_bytes);
fprintf(csv_fp, "%.3f,%s,", data_ratio, ndpi_data_ratio2str(data_ratio)); fprintf(csv_fp, "%.3f,%s,", data_ratio, ndpi_data_ratio2str(data_ratio));
fprintf(csv_fp, "%.1f,%.1f", 100.0*((float)flow->src2dst_goodput_bytes / (float)(flow->src2dst_bytes+1)),
100.0*((float)flow->dst2src_goodput_bytes / (float)(flow->dst2src_bytes+1)));
/* IAT (Inter Arrival Time) */ /* IAT (Inter Arrival Time) */
fprintf(csv_fp, "%u,%.1f,%u,%.1f,", fprintf(csv_fp, "%u,%.1f,%u,%.1f,",
@@ -1071,6 +1079,15 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
(flow->dst2src_packets > 0) ? "<->" : "->", (flow->dst2src_packets > 0) ? "<->" : "->",
flow->dst2src_packets, (long long unsigned int) flow->dst2src_bytes); flow->dst2src_packets, (long long unsigned int) flow->dst2src_bytes);
fprintf(out, "[Goodput ratio: %.1f/%.1f]",
100.0*((float)flow->src2dst_goodput_bytes / (float)(flow->src2dst_bytes+1)),
100.0*((float)flow->dst2src_goodput_bytes / (float)(flow->dst2src_bytes+1)));
if(flow->last_seen > flow->first_seen)
fprintf(out, "[%.2f sec]", ((float)(flow->last_seen - flow->first_seen))/(float)1000);
else
fprintf(out, "[< 1 sec]");
if(flow->telnet.username[0] != '\0') fprintf(out, "[Username: %s]", flow->telnet.username); if(flow->telnet.username[0] != '\0') fprintf(out, "[Username: %s]", flow->telnet.username);
if(flow->host_server_name[0] != '\0') fprintf(out, "[Host: %s]", flow->host_server_name); if(flow->host_server_name[0] != '\0') fprintf(out, "[Host: %s]", flow->host_server_name);
+2 -2
View File
@@ -1138,7 +1138,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
} }
ndpi_data_add_value(flow->pktlen_c_to_s, rawsize); ndpi_data_add_value(flow->pktlen_c_to_s, rawsize);
flow->src2dst_packets++, flow->src2dst_bytes += rawsize; flow->src2dst_packets++, flow->src2dst_bytes += rawsize, flow->src2dst_goodput_bytes += payload_len;
memcpy(&flow->entropy.src2dst_last_pkt_time, &when, sizeof(when)); memcpy(&flow->entropy.src2dst_last_pkt_time, &when, sizeof(when));
} else { } else {
if(flow->entropy.dst2src_last_pkt_time.tv_sec && (!begin_or_end_tcp)) { if(flow->entropy.dst2src_last_pkt_time.tv_sec && (!begin_or_end_tcp)) {
@@ -1152,7 +1152,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
} }
ndpi_data_add_value(flow->pktlen_s_to_c, rawsize); ndpi_data_add_value(flow->pktlen_s_to_c, rawsize);
flow->dst2src_packets++, flow->dst2src_bytes += rawsize; flow->dst2src_packets++, flow->dst2src_bytes += rawsize, flow->dst2src_goodput_bytes += payload_len;
memcpy(&flow->entropy.dst2src_last_pkt_time, &when, sizeof(when)); memcpy(&flow->entropy.dst2src_last_pkt_time, &when, sizeof(when));
} }
+1
View File
@@ -166,6 +166,7 @@ typedef struct ndpi_flow_info {
u_int8_t ip_version; u_int8_t ip_version;
u_int64_t first_seen, last_seen; u_int64_t first_seen, last_seen;
u_int64_t src2dst_bytes, dst2src_bytes; u_int64_t src2dst_bytes, dst2src_bytes;
u_int64_t src2dst_goodput_bytes, dst2src_goodput_bytes;
u_int32_t src2dst_packets, dst2src_packets; u_int32_t src2dst_packets, dst2src_packets;
u_int32_t has_human_readeable_strings; u_int32_t has_human_readeable_strings;
char human_readeable_string_buffer[32]; char human_readeable_string_buffer[32];