|
@@ -7,6 +7,7 @@ from operator import itemgetter
|
|
|
# TODO: double check this import
|
|
|
# does it complain because libpcapreader is not a .py?
|
|
|
import ID2TLib.libpcapreader as pr
|
|
|
+from ID2TLib.IPv4 import IPAddress
|
|
|
import matplotlib
|
|
|
|
|
|
import Core.StatsDatabase as statsDB
|
|
@@ -605,6 +606,52 @@ class Statistics:
|
|
|
sql_return.remove(result[i])
|
|
|
return result
|
|
|
|
|
|
+ def get_avg_delay_local_ext(self):
|
|
|
+ """
|
|
|
+ Calculates the average delay of a packet for external and local communication, based on the tcp handshakes
|
|
|
+ :return: tuple consisting of avg delay for local and external communication, (local, external)
|
|
|
+ """
|
|
|
+
|
|
|
+ conv_delays = self.stats_db.process_user_defined_query("SELECT ipAddressA, ipAddressB, avgDelay FROM conv_statistics")
|
|
|
+ if(conv_delays):
|
|
|
+ external_conv = []
|
|
|
+ local_conv = []
|
|
|
+
|
|
|
+ for conv in conv_delays:
|
|
|
+ IPA = IPAddress.parse(conv[0])
|
|
|
+ IPB = IPAddress.parse(conv[1])
|
|
|
+
|
|
|
+ #split into local and external conversations
|
|
|
+ if(not IPA.is_private() or not IPB.is_private()):
|
|
|
+ external_conv.append(conv)
|
|
|
+ else:
|
|
|
+ local_conv.append(conv)
|
|
|
+
|
|
|
+ # calculate avg local and external delay by summing up the respective delays and dividing them by the number of conversations
|
|
|
+ avg_delay_external = 0.0
|
|
|
+ avg_delay_local = 0.0
|
|
|
+
|
|
|
+ if(local_conv):
|
|
|
+ for conv in local_conv:
|
|
|
+ avg_delay_local += conv[2]
|
|
|
+ avg_delay_local = (avg_delay_local/len(local_conv)) * 0.001 #ms
|
|
|
+ else:
|
|
|
+ # no local conversations in statistics found
|
|
|
+ avg_delay_local = 0.06
|
|
|
+
|
|
|
+ if(external_conv):
|
|
|
+ for conv in external_conv:
|
|
|
+ avg_delay_external += conv[2]
|
|
|
+ avg_delay_external = (avg_delay_external/len(external_conv)) * 0.001 #ms
|
|
|
+ else:
|
|
|
+ # no external conversations in statistics found
|
|
|
+ avg_delay_external = 0.15
|
|
|
+ else:
|
|
|
+ #if no statistics were found, use these numbers
|
|
|
+ avg_delay_external = 0.15
|
|
|
+ avg_delay_local = 0.06
|
|
|
+ return avg_delay_local, avg_delay_external
|
|
|
+
|
|
|
def get_statistics_database(self):
|
|
|
"""
|
|
|
:return: A reference to the statistics database object
|