瀏覽代碼

Realistic Timestamp bugfixes in MembersMgmtCommAttack

Marcel Juschak 6 年之前
父節點
當前提交
4d2effbc45
共有 1 個文件被更改,包括 17 次插入6 次删除
  1. 17 6
      code/Attack/MembersMgmtCommAttack.py

+ 17 - 6
code/Attack/MembersMgmtCommAttack.py

@@ -415,7 +415,12 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         # this is the timestamp at which the first packet should be injected, the packets have to be shifted to the beginning of the
         # pcap file (INJECT_AT_TIMESTAMP) and then the offset of the packets have to be compensated to start at the given point in time
         zero_reference = self.get_param_value(Param.INJECT_AT_TIMESTAMP) - messages[0].time
+
         updated_msgs = []
+        last_response = {}      # Dict, takes a tuple of 2 Bot_IDs as a key (requester, responder), returns the time of the last response, the requester received
+                                # necessary in order to make sure, that additional requests are sent only after the response to the last one was received
+        for msg in messages:    # init
+            last_response[(msg.src, msg.dst)] = -1
 
         # calculate the average delay values for local and external responses
         avg_delay_local, avg_delay_external = self.statistics.get_avg_delay_local_ext()
@@ -423,20 +428,25 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         # update all timestamps
         for req_msg in messages:
 
-            if(req_msg.msg_id in updated_msgs):
+            if(req_msg in updated_msgs):
                 # message already updated
                 continue
 
-            ## update req_msg timestamp with a variation of up to 50ms
-            req_msg.time = zero_reference + req_msg.time + uniform(-0.05, 0.05)
-            updated_msgs.append(req_msg)
+            # if req_msg.timestamp would be before the timestamp of the response to the last request, req_msg needs to be sent later (else branch)
+            if last_response[(req_msg.src, req_msg.dst)] == -1 or last_response[(req_msg.src, req_msg.dst)] < (zero_reference + req_msg.time - 0.05):
+                ## update req_msg timestamp with a variation of up to 50ms
+                req_msg.time = zero_reference + req_msg.time + uniform(-0.05, 0.05)
+                updated_msgs.append(req_msg)
+
+            else:
+                req_msg.time = last_response[(req_msg.src, req_msg.dst)] + 0.06 + uniform(-0.05, 0.05)
 
             # update response if necessary
-            if(req_msg.msg_id != -1):
+            if req_msg.refer_msg_id != -1:
                 respns_msg = messages[req_msg.refer_msg_id]
 
                 # check for local or external communication and update response timestamp with the respective avg delay
-                if(req_msg.msg_id in external_ids or respns_msg.msg_id in external_ids):
+                if req_msg.src in external_ids or req_msg.dst in external_ids:
                     #external communication
                     respns_msg.time = req_msg.time + avg_delay_external + uniform(-0.1*avg_delay_external, 0.1*avg_delay_external)
                 
@@ -445,6 +455,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                     respns_msg.time = req_msg.time + avg_delay_local + uniform(-0.1*avg_delay_local, 0.1*avg_delay_local)
 
                 updated_msgs.append(respns_msg)
+                last_response[(req_msg.src, req_msg.dst)] = respns_msg.time
 
         # create port configurations for the bots
         for bot in bot_configs: