|
@@ -5,6 +5,7 @@ import os
|
|
|
import time
|
|
|
import ID2TLib.libpcapreader as pr
|
|
|
import matplotlib
|
|
|
+import numpy
|
|
|
|
|
|
matplotlib.use('Agg')
|
|
|
import matplotlib.pyplot as plt
|
|
@@ -597,7 +598,7 @@ class Statistics:
|
|
|
filtered_entries.append((p1[0], p1[1] + p2[1]))
|
|
|
done.append(p1)
|
|
|
done.append(p2)
|
|
|
- print("duplicate found:", p1, " and ", p2)
|
|
|
+ # print("duplicate found:", p1, " and ", p2)
|
|
|
added = True
|
|
|
break
|
|
|
|
|
@@ -1168,6 +1169,7 @@ class Statistics:
|
|
|
|
|
|
# compute plot data
|
|
|
for i, row in enumerate(result):
|
|
|
+ print(row)
|
|
|
addr1, addr2 = "%s:%d" % (row[0], row[1]), "%s:%d" % (row[2], row[3])
|
|
|
# adjust the justification of strings to improve appearance
|
|
|
len_max = max(len(addr1), len(addr2))
|
|
@@ -1177,16 +1179,35 @@ class Statistics:
|
|
|
graphy.append("%s\n%s" % (addr1, addr2))
|
|
|
graphx.append(row[4])
|
|
|
|
|
|
- # compute plot height in inches
|
|
|
- dist_mult_height, dist_mult_width = 0.55, 0.07 # these values turned out to work well
|
|
|
- plt_height, plt_width = len(graphy) * dist_mult_height, max(graphx) * dist_mult_width
|
|
|
- title_distance = 1 + 0.012*52.8/plt_height # orginally, a good title distance turned out to be 1.012 with a plot height of 52.8
|
|
|
|
|
|
# have x axis and its label appear at the top (instead of bottom)
|
|
|
fig, ax = plt.subplots()
|
|
|
ax.xaxis.tick_top()
|
|
|
ax.xaxis.set_label_position("top")
|
|
|
|
|
|
+ # compute plot height in inches for scaling the plot
|
|
|
+ dist_mult_height, dist_mult_width = 0.55, 0.07 # these values turned out to work well
|
|
|
+
|
|
|
+ # use static scale along the conversation axis, if there are too little entries to use dynamic scaling numbers
|
|
|
+ if len(graphy) < 10:
|
|
|
+ plt_height = 7.5
|
|
|
+ # otherwise use the numbers above
|
|
|
+ else:
|
|
|
+ plt_height = len(graphy) * dist_mult_height
|
|
|
+
|
|
|
+ # use static scale along the x axis, if the x values are all 0
|
|
|
+ if max(graphx) < 200:
|
|
|
+ plt_width = 7.5 # 7.5 as static width worked well
|
|
|
+ if max(graphx) == 0:
|
|
|
+ ax.set_xlim(0, 10)
|
|
|
+ # otherwise use the numbers above
|
|
|
+ else:
|
|
|
+ plt_width = max(graphx) * dist_mult_width
|
|
|
+
|
|
|
+ title_distance = 1 + 0.012*52.8/plt_height # orginally, a good title distance turned out to be 1.012 with a plot height of 52.8
|
|
|
+
|
|
|
+ plt.gcf().set_size_inches(plt_width, plt_height) # set plot size
|
|
|
+
|
|
|
# set additional plot parameters
|
|
|
plt.title(title, y=title_distance)
|
|
|
plt.xlabel(xlabel)
|
|
@@ -1194,16 +1215,15 @@ class Statistics:
|
|
|
width = 0.5
|
|
|
plt.grid(True)
|
|
|
plt.gca().margins(y=0) # removes the space between data and x-axis within the plot
|
|
|
- plt.gcf().set_size_inches(plt_width, plt_height) # set plot size
|
|
|
|
|
|
# plot the above data, first use plain numbers as graphy to maintain sorting
|
|
|
- plt.barh(range(len(graphy)), graphx, width, align='center', linewidth=1, color='red', edgecolor='red')
|
|
|
+ plt.barh(range(len(graphy)), graphx, width, align='center', linewidth=0.5, color='red', edgecolor='red')
|
|
|
# now change the y numbers to the respective address labels
|
|
|
plt.yticks(range(len(graphy)), graphy)
|
|
|
# try to use tight layout to cut off unnecessary space
|
|
|
try:
|
|
|
plt.tight_layout(pad=4)
|
|
|
- except ValueError:
|
|
|
+ except (ValueError, numpy.linalg.linalg.LinAlgError):
|
|
|
pass
|
|
|
|
|
|
# save created figure
|
|
@@ -1253,6 +1273,34 @@ class Statistics:
|
|
|
# plot data and return outpath
|
|
|
return plot_big_comm_interval_stat("avgTimeBetweenIntervals", "comm_interval_statistics", title, 'Average time between intervals', suffix)
|
|
|
|
|
|
+ def plot_avg_comm_interval_time(file_ending: str):
|
|
|
+ """
|
|
|
+ Plots the average duration of a communication interval of every connection.
|
|
|
+
|
|
|
+ :param file_ending: The file extension for the output file containing the plot
|
|
|
+ :return: A filepath to the file containing the created plot
|
|
|
+ """
|
|
|
+
|
|
|
+ title = 'Average duration of a communication interval in seconds'
|
|
|
+ suffix = '_plot-Avg Duration Communication Interval Distribution' + file_ending
|
|
|
+
|
|
|
+ # plot data and return outpath
|
|
|
+ return plot_big_comm_interval_stat("avgIntervalTime", "comm_interval_statistics", title, 'Average interval time', suffix)
|
|
|
+
|
|
|
+ def plot_total_comm_duration(file_ending: str):
|
|
|
+ """
|
|
|
+ Plots the total communication duration of every connection.
|
|
|
+
|
|
|
+ :param file_ending: The file extension for the output file containing the plot
|
|
|
+ :return: A filepath to the file containing the created plot
|
|
|
+ """
|
|
|
+
|
|
|
+ title = 'Total communication duration in seconds'
|
|
|
+ suffix = '_plot-Total Communication Duration Distribution' + file_ending
|
|
|
+
|
|
|
+ # plot data and return outpath
|
|
|
+ return plot_big_comm_interval_stat("totalCommDuration", "comm_interval_statistics", title, 'Duration', suffix)
|
|
|
+
|
|
|
|
|
|
ttl_out_path = plot_ttl('.' + format)
|
|
|
mss_out_path = plot_mss('.' + format)
|
|
@@ -1274,6 +1322,8 @@ class Statistics:
|
|
|
plot_in_degree = plot_in_degree('.' + format)
|
|
|
plot_avg_pkts_per_comm_interval_out = plot_avg_pkts_per_comm_interval('.' + format)
|
|
|
plot_avg_time_between_comm_interval_out = plot_avg_time_between_comm_interval('.' + format)
|
|
|
+ plot_avg_comm_interval_time_out = plot_avg_comm_interval_time("." + format)
|
|
|
+ plot_total_comm_duration_out = plot_total_comm_duration("." + format)
|
|
|
|
|
|
## Time consuming plot
|
|
|
# port_out_path = plot_port('.' + format)
|