Browse Source

Merge branch 'rng_seed_refactor' of stefan.schmidt/ID2T-toolkit into master

Carlos Garcia 6 years ago
parent
commit
ed15b76fee
3 changed files with 11 additions and 8 deletions
  1. 5 5
      code/CLI.py
  2. 2 2
      code/Core/AttackController.py
  3. 4 1
      code/Core/Controller.py

+ 5 - 5
code/CLI.py

@@ -66,7 +66,7 @@ class CLI(object):
                             help='perform extra tests on the input pcap file, including calculating IP entropy'
                                  'in interval-wise, TCP checksum, and checking payload availability.',
                             action='store_true')
-        parser.add_argument('-S', '--randomSeed', action='append', help='sets random seed for testing or benchmarking',
+        parser.add_argument('-S', '--rngSeed', action='append', help='sets rng seed for testing or benchmarking',
                             nargs='+', default=[])
         parser.add_argument('-T', '--time', help='measures packet generation time', action='store_true', default=False)
         parser.add_argument('-V', '--non-verbose', help='reduces terminal clutter', action='store_true', default=False)
@@ -152,14 +152,14 @@ class CLI(object):
                 do_entropy = True
             controller.create_statistics_plot(self.args.plot, do_entropy)
 
-        # Check random seed
-        if not isinstance(self.args.randomSeed, list):
-            self.args.randomSeed = [self.args.randomSeed]
+        # Check rng seed
+        if not isinstance(self.args.rngSeed, list):
+            self.args.rngSeed = [self.args.rngSeed]
 
         # Process attack(s) with given attack params
         if self.args.attack is not None:
             # If attack is present, load attack with params
-            controller.process_attacks(self.args.attack, self.args.randomSeed, self.args.time)
+            controller.process_attacks(self.args.attack, self.args.rngSeed, self.args.time)
 
         # Parameter -q without arguments was given -> go into query loop
         if self.args.query == [None]:

+ 2 - 2
code/Core/AttackController.py

@@ -31,9 +31,9 @@ class AttackController:
 
     def set_seed(self, seed: int):
         """
-        Sets global seed.
+        Sets rng seed.
 
-        :param seed: random seed
+        :param seed: rng seed
         """
         self.seed = seed
 

+ 4 - 1
code/Core/Controller.py

@@ -67,7 +67,10 @@ class Controller:
         i = 0
         for attack in attacks_config:
             if seeds is not None and len(seeds) > i:
-                self.attack_controller.set_seed(seed=seeds[i][0])
+                rng_seed = seeds[i][0]
+            else:
+                rng_seed = os.urandom(16)
+            self.attack_controller.set_seed(seed=rng_seed)
             temp_attack_pcap, duration = self.attack_controller.process_attack(attack[0], attack[1:], time)
             self.durations.append(duration)
             self.added_packets += self.attack_controller.total_packets