Browse Source

BaseAttack.add_param_value: Moved check for statistics object since we require it earlier already

Stefan Schmidt 6 years ago
parent
commit
8dbaace1b2
1 changed files with 5 additions and 5 deletions
  1. 5 5
      code/Attack/BaseAttack.py

+ 5 - 5
code/Attack/BaseAttack.py

@@ -371,6 +371,11 @@ class BaseAttack(metaclass=abc.ABCMeta):
         # Get parameter type of attack's required_params
         # Get parameter type of attack's required_params
         param_type = self.supported_params.get(param_name)
         param_type = self.supported_params.get(param_name)
 
 
+        # This function call is valid only if there is a statistics object available.
+        if self.statistics is None:
+            raise RuntimeError(
+                'Error: Statistics-dependent attack parameter added without setting a statistics object first.')
+
         # Verify validity of given value with respect to parameter type
         # Verify validity of given value with respect to parameter type
         if param_type is None:
         if param_type is None:
             print('Parameter ' + str(param_name) + ' not available for chosen attack. Skipping parameter.')
             print('Parameter ' + str(param_name) + ' not available for chosen attack. Skipping parameter.')
@@ -412,11 +417,6 @@ class BaseAttack(metaclass=abc.ABCMeta):
         elif param_type == atkParam.ParameterTypes.TYPE_BOOLEAN:
         elif param_type == atkParam.ParameterTypes.TYPE_BOOLEAN:
             is_valid, value = self._is_boolean(value)
             is_valid, value = self._is_boolean(value)
         elif param_type == atkParam.ParameterTypes.TYPE_PACKET_POSITION:
         elif param_type == atkParam.ParameterTypes.TYPE_PACKET_POSITION:
-            # This function call is valid only if there is a statistics object available.
-            if self.statistics is None:
-                raise RuntimeError(
-                    'Error: Statistics-dependent attack parameter added without setting a statistics object first.')
-
             ts = pr.pcap_processor(self.statistics.pcap_filepath, "False", Util.RESOURCE_DIR).get_timestamp_mu_sec(int(value))
             ts = pr.pcap_processor(self.statistics.pcap_filepath, "False", Util.RESOURCE_DIR).get_timestamp_mu_sec(int(value))
             if 0 <= int(value) <= self.statistics.get_packet_count() and ts >= 0:
             if 0 <= int(value) <= self.statistics.get_packet_count() and ts >= 0:
                 is_valid = True
                 is_valid = True