summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/unit_tests/outer_packages.py
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-15 11:19:59 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-15 11:19:59 +0200
commitb4e85e57cf825684acd24ff1bd54f3512f4aad6f (patch)
treef430365e7d512674a3539ffd3bbadee1f7dc0cf6 /scripts/automation/trex_control_plane/unit_tests/outer_packages.py
parentaf80e6693e416abbc63a5b15e838a04479c53227 (diff)
update sock.py script: adapt to Python2/3, use Scapy lib instead of removed dpkt, works with IPv4/6, TCP/UDP, in case of TCP checks for out of order and retransmissions.
Change-Id: Iab0b7473d915950c834397e365457ecb6f6a8a24 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/unit_tests/outer_packages.py')
-rw-r--r--scripts/automation/trex_control_plane/unit_tests/outer_packages.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/unit_tests/outer_packages.py b/scripts/automation/trex_control_plane/unit_tests/outer_packages.py
new file mode 100644
index 00000000..77bfd11b
--- /dev/null
+++ b/scripts/automation/trex_control_plane/unit_tests/outer_packages.py
@@ -0,0 +1,48 @@
+import sys
+import os
+import platform
+
+EXT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'external_libs'))
+if not os.path.exists(EXT_PATH):
+ raise Exception('Wrong path to external libs: %s' % EXT_PATH)
+
+CLIENT_UTILS_MODULES = [
+ {'name': 'scapy-2.3.1', 'py-dep': True},
+ {'name': 'texttable-0.8.4'},
+ ]
+
+
+def generate_module_path (module, is_python3, is_64bit, is_ucs2):
+ platform_path = [module['name']]
+
+ if module.get('py-dep'):
+ platform_path.append('python3' if is_python3 else 'python2')
+
+ if module.get('arch-dep'):
+ platform_path.append('ucs2' if is_ucs2 else 'ucs4')
+ platform_path.append('64bit' if is_64bit else '32bit')
+
+ return os.path.normcase(os.path.join(EXT_PATH, *platform_path))
+
+
+def import_module_list(modules_list):
+
+ # platform data
+ is_64bit = platform.architecture()[0] == '64bit'
+ is_python3 = (sys.version_info >= (3, 0))
+ is_ucs2 = (sys.maxunicode == 65535)
+
+ # regular modules
+ for p in modules_list:
+ full_path = generate_module_path(p, is_python3, is_64bit, is_ucs2)
+
+ if not os.path.exists(full_path):
+ print("Unable to find required module library: '{0}'".format(p['name']))
+ print("Please provide the correct path using TREX_STL_EXT_PATH variable")
+ print("current path used: '{0}'".format(full_path))
+ exit(1)
+ if full_path not in sys.path:
+ sys.path.insert(1, full_path)
+
+
+import_module_list(CLIENT_UTILS_MODULES)