scapy: Fix conflict of scapy libraries 73/54373/2
authorMartin Klozik <martinx.klozik@intel.com>
Fri, 23 Mar 2018 05:34:24 +0000 (05:34 +0000)
committerMartin Klozik <martinx.klozik@intel.com>
Mon, 26 Mar 2018 06:43:54 +0000 (07:43 +0100)
T-Rex requires a modified version of SCAPY library for python3
to function properly. It doesn't work with vanilla version of
scapy-python3 module, which is installed within vsperf environment by
pip for Xena. Currently vanilla scapy is imported by Xena and
enforced to T-Rex too, which causes following issues:

* missing implementation of Dot1AD causes failures
* broken multistream feature in T-Rex

VSPERF loads all Traffic Generator classes and thus all
imports performed at module level are performed. The solution
would be to import SCAPY module by Xena only in case, that Xena
traffic generator is really used. Please see JIRA for additional
information.

JIRA: VSPERF-566

Change-Id: I8018bc0126e752cc9f966252d17dadb6a5554b37
Signed-off-by: Martin Klozik <martinx.klozik@intel.com>
Reviewed-by: Al Morton <acmorton@att.com>
Reviewed-by: Christian Trautman <ctrautma@redhat.com>
Reviewed-by: Sridhar Rao <sridhar.rao@spirent.com>
tools/pkt_gen/xena/json/xena_json.py
tools/pkt_gen/xena/xena.py

index b1eed72..90b61d8 100644 (file)
@@ -28,8 +28,6 @@ import locale
 import logging
 import os
 
-import scapy.layers.inet as inet
-
 from tools.pkt_gen.xena.json import json_utilities
 
 _LOGGER = logging.getLogger(__name__)
@@ -51,6 +49,9 @@ class XenaJSON(object):
          two module ports with each port having its own stream config profile.
         :return: XenaJSON object
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
         self.json_data = json_utilities.read_json_file(json_path)
 
         self.packet_data = OrderedDict()
@@ -279,6 +280,10 @@ class XenaJSON(object):
         :param kwargs: Extra params per scapy usage.
         :return: None
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
+
         self.packet_data['layer2'] = [
             inet.Ether(dst=dst_mac, src=src_mac, **kwargs),
             inet.Ether(dst=src_mac, src=dst_mac, **kwargs)]
@@ -293,6 +298,10 @@ class XenaJSON(object):
         :param kwargs: Extra params per scapy usage
         :return: None
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
+
         self.packet_data['layer3'] = [
             inet.IP(src=src_ip, dst=dst_ip, proto=protocol.lower(), **kwargs),
             inet.IP(src=dst_ip, dst=src_ip, proto=protocol.lower(), **kwargs)]
@@ -305,6 +314,10 @@ class XenaJSON(object):
         :param kwargs: Extra params per scapy usage
         :return: None
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
+
         self.packet_data['layer4'] = [
             inet.UDP(sport=source_port, dport=destination_port, **kwargs),
             inet.UDP(sport=source_port, dport=destination_port, **kwargs)]
@@ -316,6 +329,10 @@ class XenaJSON(object):
         :param kwargs: Extra params per scapy usage
         :return: None
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
+
         self.packet_data['vlan'] = [
             inet.Dot1Q(vlan=vlan_id, **kwargs),
             inet.Dot1Q(vlan=vlan_id, **kwargs)]
index 19b44f0..b465b2d 100755 (executable)
@@ -32,8 +32,6 @@ import xml.etree.ElementTree as ET
 from collections import OrderedDict
 from time import sleep
 
-import scapy.layers.inet as inet
-
 from conf import merge_spec
 from conf import settings
 from core.results.results_constants import ResultsConstants
@@ -149,6 +147,10 @@ class Xena(ITrafficGenerator):
         :param reverse: Swap source and destination info when building header
         :return: packet header in hex
         """
+        # import can't be performed at module level, because it conflicts with import
+        # of customized scapy version by T-Rex
+        import scapy.layers.inet as inet
+
         srcmac = self._params['traffic']['l2'][
             'srcmac'] if not reverse else self._params['traffic']['l2'][
                 'dstmac']