浏览代码

Implemented saving and loading of seeds in label files

Stefan Schmidt 6 年之前
父节点
当前提交
a4f95d6907
共有 3 个文件被更改,包括 11 次插入4 次删除
  1. 2 2
      code/Core/AttackController.py
  2. 7 1
      code/Core/LabelManager.py
  3. 2 1
      code/ID2TLib/Label.py

+ 2 - 2
code/Core/AttackController.py

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

+ 7 - 1
code/Core/LabelManager.py

@@ -11,6 +11,7 @@ class LabelManager:
     TAG_ATTACK = 'attack'
     TAG_ATTACK_NAME = 'name'
     TAG_ATTACK_NOTE = 'note'
+    TAG_ATTACK_SEED = 'seed'
     TAG_TIMESTAMP_START = 'timestamp_start'
     TAG_TIMESTAMP_END = 'timestamp_end'
     TAG_TIMESTAMP = 'timestamp'
@@ -119,6 +120,9 @@ class LabelManager:
             attack_note = doc.createElement(self.TAG_ATTACK_NOTE)
             attack_note.appendChild(doc.createTextNode(str(label.attack_note)))
             xml_tree.appendChild(attack_note)
+            attack_seed = doc.createElement(self.TAG_ATTACK_SEED)
+            attack_seed.appendChild(doc.createTextNode(str(label.seed)))
+            xml_tree.appendChild(attack_seed)
 
             # add timestamp_start to XML tree
             xml_tree.appendChild(get_subtree_timestamp(self.TAG_TIMESTAMP_START, label.timestamp_start))
@@ -186,6 +190,7 @@ class LabelManager:
             attack_note = get_value_from_node(a, self.TAG_ATTACK_NOTE, 0)
             timestamp_start = get_value_from_node(a, self.TAG_TIMESTAMP_START, 1, 0)
             timestamp_end = get_value_from_node(a, self.TAG_TIMESTAMP_END, 1, 0)
+            attack_seed = get_value_from_node(a, self.TAG_ATTACK_SEED, 0)
 
             # Instantiate this attack to create a parameter list with the correct types
             attack_module = importlib.import_module("Attack." + attack_name)
@@ -204,7 +209,8 @@ class LabelManager:
                     attack.add_param_value(param_name, param_value, param_userspecified)
 
             # Create the label from the data read
-            label = Label.Label(attack_name, float(timestamp_start), float(timestamp_end), attack.params, attack_note)
+            label = Label.Label(attack_name, float(timestamp_start), float(timestamp_end), attack_seed, attack.params,
+                                attack_note)
             self.labels.append(label)
             count_labels += 1
 

+ 2 - 1
code/ID2TLib/Label.py

@@ -3,7 +3,7 @@ import functools
 
 @functools.total_ordering
 class Label:
-    def __init__(self, attack_name, timestamp_start, timestamp_end, parameters, attack_note=""):
+    def __init__(self, attack_name, timestamp_start, timestamp_end, seed, parameters, attack_note=""):
         """
         Creates a new attack label
 
@@ -16,6 +16,7 @@ class Label:
         self.attack_name = attack_name
         self.timestamp_start = timestamp_start
         self.timestamp_end = timestamp_end
+        self.seed = seed
         self.attack_note = attack_note
         self.parameters = parameters