Browse Source

realistic timestamps rework (statistic function)

added a function, that is used to create realistic timestamps
Marcel Juschak 6 years ago
parent
commit
0d954197f5
1 changed files with 47 additions and 0 deletions
  1. 47 0
      code/ID2TLib/Statistics.py

+ 47 - 0
code/ID2TLib/Statistics.py

@@ -618,6 +618,53 @@ class Statistics:
 
         return out_degree
 
+    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)
+            else:
+                # no local conversations in statistics found
+                avg_delay_local = 120.0
+
+            if(external_conv):
+                for conv in external_conv:
+                    avg_delay_external += conv[2]
+                avg_delay_external = avg_delay_external/len(external_conv)
+            else:
+                # no external conversations in statistics found
+                avg_delay_external = 8000.0
+        else:
+            #if no statistics were found, use these numbers
+            avg_delay_external = 8000.0
+            avg_delay_local = 120.0
+
+        return avg_delay_local, avg_delay_external
+
     def filter_multiples(self, entries):
         """
         helper function, for get_out_degree and get_in_degree