diff options
Diffstat (limited to 'scripts/automation')
7 files changed, 92 insertions, 21 deletions
diff --git a/scripts/automation/regression/aggregate_results.py b/scripts/automation/regression/aggregate_results.py index 2a21b4be..8a3d0e4c 100755 --- a/scripts/automation/regression/aggregate_results.py +++ b/scripts/automation/regression/aggregate_results.py @@ -17,11 +17,10 @@ ERROR_CATEGORY = 'Error' def pad_tag(text, tag): return '<%s>%s</%s>' % (tag, text, tag) -def add_color_string(text, color, is_bold = False): - string = '<font color=%s>%s</font>' % (color, text) - if is_bold: - return pad_tag(string, 'b') - return string +def mark_string(text, color, condition): + if condition: + return '<font color=%s><b>%s</b></font>' % (color, text) + return text def is_functional_test_name(testname): @@ -328,11 +327,12 @@ if __name__ == '__main__': failure_tests_count = int(aggregated_root.attrib.get('failures', 0)) skipped_tests_count = int(aggregated_root.attrib.get('skip', 0)) passed_tests_count = total_tests_count - error_tests_count - failure_tests_count - skipped_tests_count - tests_count_string = 'Total: %s, ' % total_tests_count - tests_count_string += add_color_string('Passed: %s' % passed_tests_count, 'green', error_tests_count + failure_tests_count > 0) + ', ' - tests_count_string += add_color_string('Error: %s' % error_tests_count, 'red', error_tests_count > 0) + ', ' - tests_count_string += add_color_string('Failure: %s' % failure_tests_count, 'red', failure_tests_count > 0) + ', ' - tests_count_string += add_color_string('Skipped: %s' % skipped_tests_count, 'blue') + + tests_count_string = mark_string('Total: %s' % total_tests_count, 'red', total_tests_count == 0) + ', ' + tests_count_string += mark_string('Passed: %s' % passed_tests_count, 'red', error_tests_count + failure_tests_count > 0) + ', ' + tests_count_string += mark_string('Error: %s' % error_tests_count, 'red', error_tests_count > 0) + ', ' + tests_count_string += mark_string('Failure: %s' % failure_tests_count, 'red', failure_tests_count > 0) + ', ' + tests_count_string += 'Skipped: %s' % skipped_tests_count ##### save output xml diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 506decfe..ebc9a6ad 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -929,7 +929,7 @@ class STLClient(object): def get_stats (self, ports = None, async_barrier = True): # by default use all ports if ports == None: - ports = self.get_all_ports() + ports = self.get_acquired_ports() else: ports = self.__ports(ports) @@ -1306,7 +1306,6 @@ class STLClient(object): try: streams_db = CStreamsDB() stream_list = streams_db.load_yaml_file(filename) - # convert to new style stream object streams = [HACKSTLStream(stream) for stream in stream_list.compiled] except YAMLError: diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py index bfc3a932..d980932a 100644 --- a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py @@ -116,8 +116,8 @@ class STLSim(object): return module.register().get_streams() - except (AttributeError, ImportError): - pass + except (AttributeError, ImportError) as e: + print "specific error: {0}".format(e) raise STLError("bad format input file '{0}'".format(input_file)) diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder.py b/scripts/automation/trex_control_plane/client_utils/packet_builder.py index 5ad6cd7a..f9031436 100755 --- a/scripts/automation/trex_control_plane/client_utils/packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder.py @@ -14,7 +14,9 @@ from abc import ABCMeta, abstractmethod from collections import namedtuple import base64 -class CTRexPktBuilder(object): +from packet_builder_interface import CTrexPktBuilderInterface + +class CTRexPktBuilder(CTrexPktBuilderInterface): """ This class defines the TRex API of building a packet using dpkt package. Using this class the user can also define how TRex will handle the packet by specifying the VM setting. @@ -480,6 +482,9 @@ class CTRexPktBuilder(object): def get_vm_data(self): return self.vm.dump() + def compile (self): + pass + def dump_pkt(self, encode = True): """ Dumps the packet as a decimal array of bytes (each item x gets value between 0-255) diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py b/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py new file mode 100644 index 00000000..b6e7c026 --- /dev/null +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder_interface.py @@ -0,0 +1,43 @@ + +# base object class for a packet builder +class CTrexPktBuilderInterface(object): + + def compile (self): + """ + Compiles the packet and VM + """ + raise Exception("implement me") + + + def dump_pkt(self): + """ + Dumps the packet as a decimal array of bytes (each item x gets value between 0-255) + + :parameters: + None + + :return: + + packet representation as array of bytes + + :raises: + + :exc:`CTRexPktBuilder.EmptyPacketError`, in case packet is empty. + + """ + + raise Exception("implement me") + + + def get_vm_data(self): + """ + Dumps the instructions + + :parameters: + None + + :return: + + json object of instructions + + """ + + raise Exception("implement me") + diff --git a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py index d3a5605b..30383469 100644 --- a/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/scapy_packet_builder.py @@ -8,6 +8,7 @@ import yaml import binascii import base64 +from packet_builder_interface import CTrexPktBuilderInterface from scapy.all import * @@ -482,7 +483,7 @@ def check_for_int (val): class CTRexVmDescFlowVar(CTRexVmDescBase): - def __init__(self, name, init_value=0, min_value=0, max_value=255, size=4, op="inc"): + def __init__(self, name, init_value=None, min_value=0, max_value=255, size=4, op="inc"): super(CTRexVmDescFlowVar, self).__init__() self.name = name; assert type(name)==str, 'type of name is not str' @@ -490,6 +491,11 @@ class CTRexVmDescFlowVar(CTRexVmDescBase): valid_fv_size(size) self.op =op valid_fv_ops (op) + + # choose default value for init val + if init_value == None: + init_value = max_value if op == "dec" else min_value + self.init_value = convert_val (init_value) self.min_value = convert_val (min_value); self.max_value = convert_val (max_value) @@ -581,13 +587,13 @@ class CTRexVmDescTupleGen(CTRexVmDescBase): ################################################################################################ -class CScapyTRexPktBuilder(object): +class CScapyTRexPktBuilder(CTrexPktBuilderInterface): """ This class defines the TRex API of building a packet using dpkt package. Using this class the user can also define how TRex will handle the packet by specifying the VM setting. """ - def __init__(self): + def __init__(self, pkt = None, vm = None): """ Instantiate a CTRexPktBuilder object @@ -596,11 +602,27 @@ class CScapyTRexPktBuilder(object): """ super(CScapyTRexPktBuilder, self).__init__() - self.pkt = None # scapy packet + + self.pkt = None self.vm_scripts = [] # list of high level instructions self.vm_low_level = None self.metadata="" + + # process packet + if pkt != None: + if not isinstance(pkt, Packet): + raise CTRexPacketBuildException(-14, "bad value for variable pkt") + self.set_packet(pkt) + + # process VM + if vm != None: + if not isinstance(vm, (CTRexScRaw, list)): + raise CTRexPacketBuildException(-14, "bad value for variable pkt") + + self.add_command(vm if isinstance(vm, CTRexScRaw) else CTRexScRaw(vm)) + + def dump_vm_data_as_yaml(self): print yaml.dump(self.get_vm_data(), default_flow_style=False) @@ -689,7 +711,6 @@ class CScapyTRexPktBuilder(object): var_names = desc.get_var_name() if var_names : - print var_names for var_name in var_names: if vars.has_key(var_name): raise CTRexPacketBuildException(-11,("variable %s define twice ") % (var_name) ); diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index 9b10995b..238c89f3 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -1,6 +1,7 @@ #!/router/bin/python import external_packages +from client_utils.packet_builder_interface import CTrexPktBuilderInterface from client_utils.packet_builder import CTRexPktBuilder from collections import OrderedDict, namedtuple from client_utils.yaml_utils import * @@ -422,7 +423,7 @@ class STLStream(object): if not isinstance(mode, STLTXMode): raise STLArgumentError('mode', mode) - if not isinstance(packet, CTRexPktBuilder): + if not isinstance(packet, CTrexPktBuilderInterface): raise STLArgumentError('packet', packet) if not isinstance(enabled, bool): @@ -452,6 +453,8 @@ class STLStream(object): # mode self.fields['mode'] = mode.to_json() + packet.compile() + # packet and VM self.fields['packet'] = packet.dump_pkt() self.fields['vm'] = packet.get_vm_data() |