teststeps: Improvements and bugfixing of teststeps
[vswitchperf.git] / tools / pkt_gen / ixnet / ixnet.py
index 6262a10..b8fb187 100755 (executable)
@@ -1,4 +1,4 @@
-# Copyright 2015-2016 Intel Corporation.
+# Copyright 2015-2017 Intel Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -78,7 +78,6 @@ does not give any feedback as to the status of tests. As such, it can
 be expected that the user have access to the IxNetwork machine should
 this trafficgen need to be debugged.
 """
-
 import tkinter
 import logging
 import os
@@ -88,6 +87,7 @@ import csv
 from collections import OrderedDict
 from tools.pkt_gen import trafficgen
 from conf import settings
+from conf import merge_spec
 from core.results.results_constants import ResultsConstants
 
 _ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -121,18 +121,15 @@ def _build_set_cmds(values, prefix='dict set'):
     for key in values:
         value = values[key]
 
-        # Not allowing derived dictionary types for now
-        # pylint: disable=unidiomatic-typecheck
-        if type(value) == dict:
+        if isinstance(value, dict):
             _prefix = ' '.join([prefix, key]).strip()
             for subkey in _build_set_cmds(value, _prefix):
                 yield subkey
             continue
 
-        # pylint: disable=unidiomatic-typecheck
         # tcl doesn't recognise the strings "True" or "False", only "1"
         # or "0". Special case to convert them
-        if type(value) == bool:
+        if isinstance(value, bool):
             value = str(int(value))
         else:
             value = str(value)
@@ -155,9 +152,9 @@ class IxNet(trafficgen.ITrafficGenerator):
     def __init__(self):
         """Initialize IXNET members
         """
-        self._script = os.path.join(settings.getValue('TRAFFICGEN_IXIA_3RD_PARTY'),
-                                    settings.getValue('TRAFFICGEN_IXNET_TCL_SCRIPT'))
+        super().__init__()
         self._tclsh = tkinter.Tcl()
+        self._script = None
         self._cfg = None
         self._logger = logging.getLogger(__name__)
         self._params = None
@@ -176,9 +173,11 @@ class IxNet(trafficgen.ITrafficGenerator):
 
         return output.split()
 
-    def connect(self):
+    def configure(self):
         """Configure system for IxNetwork.
         """
+        self._script = os.path.join(settings.getValue('TRAFFICGEN_IXIA_3RD_PARTY'),
+                                    settings.getValue('TRAFFICGEN_IXNET_TCL_SCRIPT'))
         self._cfg = {
             'lib_path': settings.getValue('TRAFFICGEN_IXNET_LIB_PATH'),
             # IxNetwork machine configuration
@@ -196,7 +195,10 @@ class IxNet(trafficgen.ITrafficGenerator):
 
         self._logger.debug('IXIA configuration configuration : %s', self._cfg)
 
-        return self
+    def connect(self):
+        """Connect to IxNetwork - nothing to be done here
+        """
+        pass
 
     def disconnect(self):
         """Disconnect from Ixia chassis.
@@ -213,6 +215,7 @@ class IxNet(trafficgen.ITrafficGenerator):
     def start_cont_traffic(self, traffic=None, duration=30):
         """Start transmission.
         """
+        self.configure()
         self._bidir = traffic['bidir']
         self._params = {}
 
@@ -223,11 +226,13 @@ class IxNet(trafficgen.ITrafficGenerator):
             'multipleStreams': traffic['multistream'],
             'streamType': traffic['stream_type'],
             'rfc2544TestType': 'throughput',
+            'flowControl': "True" if traffic['flow_control'] else "False",
+            'learningFrames': "True" if traffic['learning_frames'] else "False",
         }
         self._params['traffic'] = self.traffic_defaults.copy()
 
         if traffic:
-            self._params['traffic'] = trafficgen.merge_spec(
+            self._params['traffic'] = merge_spec(
                 self._params['traffic'], traffic)
         self._cfg['bidir'] = self._bidir
 
@@ -266,6 +271,7 @@ class IxNet(trafficgen.ITrafficGenerator):
                                  lossrate=0.0):
         """Start transmission.
         """
+        self.configure()
         self._bidir = traffic['bidir']
         self._params = {}
 
@@ -277,11 +283,13 @@ class IxNet(trafficgen.ITrafficGenerator):
             'multipleStreams': traffic['multistream'],
             'streamType': traffic['stream_type'],
             'rfc2544TestType': 'throughput',
+            'flowControl': "True" if traffic['flow_control'] else "False",
+            'learningFrames': "True" if traffic['learning_frames'] else "False",
         }
         self._params['traffic'] = self.traffic_defaults.copy()
 
         if traffic:
-            self._params['traffic'] = trafficgen.merge_spec(
+            self._params['traffic'] = merge_spec(
                 self._params['traffic'], traffic)
         self._cfg['bidir'] = self._bidir
 
@@ -403,6 +411,7 @@ class IxNet(trafficgen.ITrafficGenerator):
                                 lossrate=0.0):
         """Start transmission.
         """
+        self.configure()
         self._bidir = traffic['bidir']
         self._params = {}
 
@@ -414,11 +423,13 @@ class IxNet(trafficgen.ITrafficGenerator):
             'multipleStreams': traffic['multistream'],
             'streamType': traffic['stream_type'],
             'rfc2544TestType': 'back2back',
+            'flowControl': "True" if traffic['flow_control'] else "False",
+            'learningFrames': "True" if traffic['learning_frames'] else "False",
         }
         self._params['traffic'] = self.traffic_defaults.copy()
 
         if traffic:
-            self._params['traffic'] = trafficgen.merge_spec(
+            self._params['traffic'] = merge_spec(
                 self._params['traffic'], traffic)
         self._cfg['bidir'] = self._bidir
 
@@ -509,6 +520,8 @@ class IxNet(trafficgen.ITrafficGenerator):
 
         return parse_ixnet_rfc_results(parse_result_string(output[0]))
 
+    def send_burst_traffic(self, traffic=None, numpkts=100, duration=20):
+        return NotImplementedError('IxNet does not implement send_burst_traffic')
 
 if __name__ == '__main__':
     TRAFFIC = {