From 10a1d2e33a110a091f539bdf3de5e5c69e5887f8 Mon Sep 17 00:00:00 2001 From: ichebyki Date: Tue, 20 Dec 2016 12:57:59 +0700 Subject: Add support for predefined packet templates. Change-Id: Ib2bdcbe6ea18933394527f06be001607344c75e4 Signed-off-by: Igor Chebykin --- .../services/scapy_server/unit_tests/basetest.py | 9 +++++ .../scapy_server/unit_tests/test_scapy_service.py | 40 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests') diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/basetest.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/basetest.py index e48880e8..9836c794 100644 --- a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/basetest.py +++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/basetest.py @@ -88,3 +88,12 @@ def adapt_json_protocol_fields(protocols_array): # change structure for easier if protocol.get("fields"): protocol["fields"] = fields_to_map(protocol["fields"]) + +def get_templates(): + return pass_result(service.get_templates(v_handler)) + + + +def get_template(t): + return pass_result(service.get_template(v_handler, t)) + diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py index e1094a79..1ece5d1e 100644 --- a/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py +++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py @@ -289,3 +289,43 @@ def test_generate_vm_instructions(): ttl_instruction = res['field_engine']['instructions']['instructions'][2] assert(ttl_instruction['min_value'] == 32) assert(ttl_instruction['max_value'] == 64) + + +def test_get_templates(): + tt = get_templates() + assert(tt[0]['id']) + assert(tt[7]["meta"]['name']) + try: + assert(tt[9]['id']) + except: + pass + + +def test_get_template(): + tt = get_templates() + t = tt[0] + res = get_template(t) + res2 = base64.b64decode(res) + obj = json.loads(res2) + assert(obj['packet'][0]['id'] == 'Ether') + assert(obj['packet'][1]['id'] == 'IP') + assert(obj['packet'][2]['id'] == 'ICMP') + + +def test_get_template2(): + tt = get_templates() + t = tt[7] + res = get_template(t) + res2 = base64.b64decode(res) + obj = json.loads(res2) + assert(obj['packet'][0]['id'] == 'Ether') + assert(obj['packet'][1]['id'] == 'IPv6') + assert(obj['packet'][2]['id'] == 'UDP') + + +def test_get_template3(): + tt = get_templates() + t = tt[7] + t["id"] = "../../" + t["id"] + res = get_template(t) + assert(res == '') -- cgit 1.2.3-korg