Browse Source

add injected_packets to labels

Jens Keim 5 years ago
parent
commit
96a4684c7b
3 changed files with 11 additions and 3 deletions
  1. 1 1
      code/Core/AttackController.py
  2. 4 0
      code/Core/LabelManager.py
  3. 6 2
      code/ID2TLib/Label.py

+ 1 - 1
code/Core/AttackController.py

@@ -190,7 +190,7 @@ class AttackController:
 
         # Store label into LabelManager
         label = Label.Label(attack, self.get_attack_start_utime(), self.get_attack_end_utime(),
-                            self.seed, self.current_attack.params, attack_note)
+                            self.total_packets, self.seed, self.current_attack.params, attack_note)
         self.label_mgr.add_labels(label)
 
         return temp_attack_pcap_path, duration

+ 4 - 0
code/Core/LabelManager.py

@@ -18,6 +18,7 @@ class LabelManager:
     TAG_ATTACK_NAME = 'name'
     TAG_ATTACK_NOTE = 'note'
     TAG_ATTACK_SEED = 'seed'
+    TAG_ATTACK_PACKETS = 'injected_packets'
     TAG_TIMESTAMP_START = 'timestamp_start'
     TAG_TIMESTAMP_END = 'timestamp_end'
     TAG_TIMESTAMP = 'timestamp'
@@ -152,6 +153,9 @@ class LabelManager:
             attack_seed = doc.createElement(self.TAG_ATTACK_SEED)
             attack_seed.appendChild(doc.createTextNode(str(label.seed)))
             xml_tree.appendChild(attack_seed)
+            injected_packets = doc.createElement(self.TAG_ATTACK_PACKETS)
+            injected_packets.appendChild(doc.createTextNode(str(label.injected_packets)))
+            xml_tree.appendChild(injected_packets)
 
             # add timestamp_start to XML tree
             xml_tree.appendChild(get_subtree_timestamp(self.TAG_TIMESTAMP_START, label.timestamp_start))

+ 6 - 2
code/ID2TLib/Label.py

@@ -3,19 +3,22 @@ import functools
 
 @functools.total_ordering
 class Label:
-    def __init__(self, attack_name, timestamp_start, timestamp_end, seed, parameters, attack_note=""):
+    def __init__(self, attack_name, timestamp_start, timestamp_end, injected_packets, seed, parameters, attack_note=""):
         """
         Creates a new attack label
 
         :param attack_name: The name of the associated attack
         :param timestamp_start: The timestamp as unix time of the first attack packet
         :param timestamp_end: The timestamp as unix time of the last attack packet
+        :param injected_packets: The number of packets injected by the attack
+        :param seed: The seed used for randomization
         :param parameters: The list of parameters used to run the attack
         :param attack_note: A note associated to the attack (optional)
         """
         self.attack_name = attack_name
         self.timestamp_start = timestamp_start
         self.timestamp_end = timestamp_end
+        self.injected_packets = injected_packets
         self.seed = seed
         self.attack_note = attack_note
         self.parameters = parameters
@@ -30,6 +33,7 @@ class Label:
         return self.timestamp_start > other.timestamp_start
 
     def __str__(self):
+        # FIXME: maybe add self.parameters as well?
         return ''.join(
             ['(', self.attack_name, ',', self.attack_note, ',', str(self.timestamp_start), ',', str(self.timestamp_end),
-             ')'])
+             str(self.injected_packets), ',', str(self.seed), ')'])