summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/services
diff options
context:
space:
mode:
authorVyacheslav Ogai <vyacheslav.ogai@gmail.com>2016-10-05 16:03:37 +0300
committerHanoh Haim <hhaim@cisco.com>2016-12-19 16:04:07 +0200
commit9218477a913ddab4f01fb1b7754dc2ae69a32898 (patch)
tree1b69be930809828edd959f9982472c31c1860cc1 /scripts/automation/trex_control_plane/stl/services
parent82a9911f91c5190b3e76ab161d51a1b780fcbbb8 (diff)
Add instrucitons meta. Delete split_by_field field engine global parameter.
Signed-off-by: Vyacheslav Ogai <vyacheslav.ogai@gmail.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/services')
-rw-r--r--scripts/automation/trex_control_plane/stl/services/scapy_server/field_engine.json54
-rwxr-xr-xscripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py29
-rw-r--r--scripts/automation/trex_control_plane/stl/services/scapy_server/unit_tests/test_scapy_service.py26
3 files changed, 88 insertions, 21 deletions
diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/field_engine.json b/scripts/automation/trex_control_plane/stl/services/scapy_server/field_engine.json
index 082a6f32..9214f4c8 100644
--- a/scripts/automation/trex_control_plane/stl/services/scapy_server/field_engine.json
+++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/field_engine.json
@@ -1,4 +1,23 @@
{
+ "instructions": [
+ {
+ "id": "STLVmFlowVar",
+ "parameters": ["max_value","min_value","step","op"]
+ },
+ {
+ "id": "STLVmWrFlowVar",
+ "parameters": ["fv_name", "pkt_offset"]
+ },
+ {
+ "id": "STLVmFixIpv4",
+ "parameters": ["offset"]
+ },
+ {
+ "id": "STLVmFixChecksumHw",
+ "parameters": ["l3_offset","l4_offset","l4_type"]
+ }
+ ],
+
"instruction_params_meta": [
{
"id": "max_value",
@@ -28,6 +47,36 @@
"inc": "Increment",
"random": "Random"
}
+ },
+ {
+ "id": "fv_name",
+ "name": "Variable name",
+ "type": "STRING"
+ },
+ {
+ "id": "pkt_offset",
+ "name": "Offset",
+ "type": "STRING"
+ },
+ {
+ "id": "offset",
+ "name": "Offset",
+ "type": "STRING"
+ },
+ {
+ "id": "l3_offset",
+ "name": "L3 offset",
+ "type": "STRING"
+ },
+ {
+ "id": "l4_offset",
+ "name": "L4 offset",
+ "type": "STRING"
+ },
+ {
+ "id": "l4_type",
+ "name": "L4 type",
+ "type": "STRING"
}
],
"protocol_fields": {
@@ -47,11 +96,6 @@
},
"global_params_meta":[
{
- "id": "split_by_field",
- "name": "Split by",
- "type": "ENUM"
- },
- {
"id": "cache_size",
"name": "Cache size",
"type": "STRING",
diff --git a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
index aa5053d5..93ca7502 100755
--- a/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
+++ b/scripts/automation/trex_control_plane/stl/services/scapy_server/scapy_service.py
@@ -11,7 +11,7 @@ import hashlib
import base64
import numbers
import random
-import inspect
+from inspect import getdoc
import json
from pprint import pprint
@@ -397,9 +397,10 @@ class Scapy_service(Scapy_service_api):
self.protocol_fields_fe_aware = {}
self.instruction_parameter_meta_definitions = []
self.field_engine_parameter_meta_definitions = []
+ self.field_engine_instructions_meta = []
self.field_engine_instruction_expressions = []
self._load_definitions_from_json()
- self._load_instruction_parameter_definitions_from_json()
+ self._load_field_engine_meta_from_json()
def _load_definitions_from_json(self):
# load protocol definitions from a json file
@@ -409,19 +410,25 @@ class Scapy_service(Scapy_service_api):
for protocol in protocols:
self.protocol_definitions[ protocol['id'] ] = protocol
- def _load_instruction_parameter_definitions_from_json(self):
+ def _load_field_engine_meta_from_json(self):
# load protocol definitions from a json file
self.instruction_parameter_meta_definitions = []
self.protocol_fields_fe_aware = {}
self.field_engine_parameter_meta_definitions = []
with open('field_engine.json', 'r') as f:
metas = json.load(f)
- for meta in metas["instruction_params_meta"]:
- self.instruction_parameter_meta_definitions.append(meta)
+ self.instruction_parameter_meta_definitions = metas["instruction_params_meta"]
+ self.field_engine_instructions_meta = metas["instructions"]
+ self._append_intructions_help()
self.protocol_fields_fe_aware = metas["protocol_fields"]
self.field_engine_parameter_meta_definitions = metas["global_params_meta"]
+ def _append_intructions_help(self):
+ for instruction_meta in self.field_engine_instructions_meta:
+ clazz = eval(instruction_meta['id'])
+ instruction_meta['help'] = base64.b64encode(getdoc(clazz.__init__)).decode('ascii')
+
def _all_protocol_structs(self):
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
@@ -800,28 +807,23 @@ class Scapy_service(Scapy_service_api):
self.field_engine_instruction_expressions.append(expression)
fe_parameters = field_engine_model_descriptor['global_parameters']
- split_by_field = None
- if "split_by_field" in fe_parameters:
- split_by_field = str(fe_parameters['split_by_field'])
cache_size = None
if "cache_size" in fe_parameters:
cache_size = int(fe_parameters['cache_size'])
- self.field_engine_instruction_expressions += self._get_instruction_expressions_footer(split_by_field, cache_size)
+ self.field_engine_instruction_expressions += self._get_instruction_expressions_footer(cache_size)
- pkt_builder = STLPktBuilder(pkt=pkt, vm=STLScVmRaw(instructions, split_by_field=split_by_field, cache_size=cache_size))
+ pkt_builder = STLPktBuilder(pkt=pkt, vm=STLScVmRaw(instructions, cache_size=cache_size))
pkt_builder.compile()
return pkt_builder.get_vm_data()
def _get_instruction_expressions_header(self):
return {'free_form': "vm = STLScVmRaw(["}
- def _get_instruction_expressions_footer(self, split_by_field, cache_size):
+ def _get_instruction_expressions_footer(self, cache_size):
instructions = []
footer = ']'
- if split_by_field != None and split_by_field != "":
- footer += ',{0}="{1}"'.format("split_by_field", split_by_field)
if cache_size != None and cache_size > 0:
footer += ',{0}={1}'.format("cache_size", cache_size)
@@ -965,6 +967,7 @@ class Scapy_service(Scapy_service_api):
})
res = {"protocols": protocols,
"feInstructionParameters": self.instruction_parameter_meta_definitions,
+ "feInstructions": self.field_engine_instructions_meta,
"feParameters": self.field_engine_parameter_meta_definitions}
return res
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 ffc3b2b3..af3bfb43 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
@@ -112,11 +112,30 @@ def test_get_all():
def test_get_definitions_all():
get_definitions(None)
- def_classnames = [pdef['id'] for pdef in get_definitions(None)['protocols']]
+ defs = get_definitions(None)
+ def_classnames = [pdef['id'] for pdef in defs['protocols']]
assert("IP" in def_classnames)
assert("Dot1Q" in def_classnames)
assert("TCP" in def_classnames)
+ fe_parameter_metas = defs['feInstructionParameters']
+ assert(fe_parameter_metas[0]['id'] == "max_value")
+ assert(fe_parameter_metas[1]['id'] == "min_value")
+ assert(fe_parameter_metas[2]['id'] == "step")
+ assert(fe_parameter_metas[3]['id'] == "op")
+ assert(fe_parameter_metas[4]['id'] == "fv_name")
+ assert(fe_parameter_metas[5]['id'] == "pkt_offset")
+ assert(fe_parameter_metas[6]['id'] == "offset")
+ assert(fe_parameter_metas[7]['id'] == "l3_offset")
+ assert(fe_parameter_metas[8]['id'] == "l4_offset")
+ assert(fe_parameter_metas[9]['id'] == "l4_type")
+
+ # All instructions should have a help description.
+ fe_instructions = defs['feInstructions']
+ for instruction in fe_instructions:
+ print(instruction['help'])
+ assert("help" in instruction)
+
def test_get_definitions_ether():
res = get_definitions(["Ether"])
protocols = res['protocols']
@@ -255,8 +274,9 @@ def test_generate_vm_instructions():
layer_def("Ether"),
layer_def("IP", src="16.0.0.1", dst="48.0.0.1")
]
- ip_instructions_model = {"field_engine":{'global_parameters': {}, 'instructions': [{'id': "IP", 'fields': [{"fieldId": "src", 'parameters': {'min_value': "0", 'max_value': "16.0.0.255", 'step': "1", 'op': "inc"}},
- {"fieldId": "ttl", 'parameters': {'min_value': "1", 'max_value': "17", 'step': "1", 'op': "inc"}}]}]}}
+ ip_instructions_model = {"field_engine": {'global_parameters': {}, 'instructions': [{'id': "IP", 'fields': [
+ {"fieldId": "src", 'parameters': {'min_value': "0", 'max_value': "16.0.0.255", 'step': "1", 'op': "inc"}},
+ {"fieldId": "ttl", 'parameters': {'min_value': "1", 'max_value': "17", 'step': "1", 'op': "inc"}}]}]}}
res = build_pkt_ex(ip_pkt_model, ip_instructions_model)
src_instruction = res['vm_instructions']['instructions'][0]
assert(src_instruction['min_value'] == 0)