示例#1
0
    def test_generated_profiles(self):
        exclude_list = [
            'imix_wlc.py',  # expects tunables
            'udp_1pkt_vxlan.py',  # uses custom Scapy layer
        ]
        exclude_dict = {}.fromkeys(exclude_list)
        output_file = os.path.join(self.generated_path, 'exported_to_code.py')
        stl_files = glob.glob(os.path.join(self.profiles_path, '*.py'))
        hlt_files = glob.glob(os.path.join(self.profiles_path, 'hlt', '*.py'))
        assert stl_files and hlt_files

        print('\nChecking %s normal profiles and %s hlt profiles' %
              (len(stl_files), len(hlt_files)))

        for input_file in stl_files + hlt_files:
            basename = os.path.basename(input_file)
            if basename in exclude_dict:
                continue

            profile = STLProfile.load_py(input_file)
            profile.dump_to_code(output_file)
            orig_json = profile.to_json()
            gen_json = STLProfile.load_py(output_file).to_json()

            if not compare_dicts_round(orig_json, gen_json):
                print('Original JSON:')
                pprint(orig_json)
                print('Generated JSON:')
                pprint(gen_json)
                raise Exception(
                    'Generated file differs from original (%s) in JSON.' %
                    basename)
示例#2
0
    def test_generated_profiles(self):
        exclude_list = [
            'imix_wlc.py',  # expects tunables
            'udp_1pkt_vxlan.py',  # uses custom Scapy layer
            'icmpv6_fix_cs.py',  # cannot parse layer name from offset correctly (ICMPv6ND_NS classname and layer name do not match)
            'udp_1pkt_src_ip_split_latency_ieee_1588.py',  # cannot be tested on sim as IEEE 1588 is only supported on specific NICs
            'tpg_tags_conf.py'  # Tagged Packet Group Tag Configuration, this is not a profile.
        ]
        exclude_dict = {}.fromkeys(exclude_list)
        output_file = os.path.join(self.generated_path, 'exported_to_code.py')
        stl_files = glob.glob(os.path.join(self.profiles_path, '*.py'))
        hlt_files = glob.glob(os.path.join(self.profiles_path, 'hlt', '*.py'))
        assert stl_files and hlt_files

        print('\nChecking %s normal profiles and %s hlt profiles' %
              (len(stl_files), len(hlt_files)))

        for input_file in stl_files + hlt_files:
            basename = os.path.basename(input_file)
            if basename in exclude_dict:
                continue

            profile = STLProfile.load_py(input_file)
            profile.dump_to_code(output_file)
            orig_json = profile.to_json()
            gen_json = STLProfile.load_py(output_file).to_json()

            if not compare_dicts_round(orig_json, gen_json):
                print('Original JSON:')
                pprint(orig_json)
                print('Generated JSON:')
                pprint(gen_json)
                raise Exception(
                    'Generated file differs from original (%s) in JSON.' %
                    basename)
示例#3
0
    def do_start(self, client_ids, file_path, multiplier, tunables,
                 total_mult):
        '''Start traffic on behalf on client(s).'''
        if not client_ids:
            clients = self.ap_manager.clients
        else:
            clients = set(
                [self.ap_manager._get_client_by_id(id) for id in client_ids])
            if len(client_ids) != len(clients):
                raise TRexError('Client IDs should be unique')
        if not clients:
            raise TRexError('No clients to start traffic on behalf of them!')
        ports = list(set([client.ap.port_id for client in clients]))

        # stop ports if needed
        active_ports = list_intersect(self.trex_client.get_active_ports(),
                                      ports)
        if active_ports:
            self.trex_client.stop(active_ports)

        # remove all streams
        self.trex_client.remove_all_streams(ports)

        # pack the profile
        try:
            tunables = tunables or {}
            for client in clients:
                profile = STLProfile.load(file_path,
                                          direction=tunables.get(
                                              'direction',
                                              client.ap.port_id % 2),
                                          port_id=client.ap.port_id,
                                          **tunables)

                self.ap_manager.add_streams(client, profile.get_streams())

        except TRexError as e:
            msg = bold("\nError loading profile '%s'" % file_path)
            self.ap_manager.log(msg + '\n')
            self.ap_manager.log(e.brief() + "\n")

        self.trex_client.start(ports=ports,
                               mult=multiplier,
                               force=True,
                               total=total_mult)

        return RC_OK()
示例#4
0
    def run_py_profile_path(self,
                            profile,
                            options,
                            silent=False,
                            do_no_remove=False,
                            compare=True,
                            test_generated=True,
                            do_no_remove_generated=False,
                            tunables=None):

        print('\nTesting profile: %s' % profile)
        output_cap = "generated/a.pcap"
        input_file = os.path.join('stl/', profile)
        golden_file = os.path.join(
            'exp',
            os.path.basename(profile).split('.')[0] + '.pcap')
        if os.path.exists(output_cap):
            os.unlink(output_cap)
        try:
            rc = self.run_sim(yaml=input_file,
                              output=output_cap,
                              options=options,
                              silent=silent,
                              tunables=tunables)
            assert_equal(rc, True,
                         'Simulation on profile %s failed.' % profile)
            #s='cp  '+output_cap+' '+golden_file;
            #print s
            #os.system(s)

            if compare:
                compare_caps(output_cap, golden_file)
        finally:
            if not do_no_remove:
                os.unlink(output_cap)

        if test_generated:
            try:
                generated_filename = input_file.replace(
                    '.py', '_GENERATED.py').replace('.yaml', '_GENERATED.py')
                print('Generating %s' % generated_filename)
                if input_file.endswith('.py'):
                    profile = STLProfile.load_py(
                        input_file, **(tunables if tunables else {}))
                elif input_file.endswith('.yaml'):
                    profile = STLProfile.load_yaml(input_file)

                profile.dump_to_code(generated_filename)

                if compare:
                    orig_json = profile.to_json()
                    gen_json = STLProfile.load_py(generated_filename).to_json()
                    if not compare_dicts_round(orig_json, gen_json):
                        print('Original JSON:')
                        pprint(orig_json)
                        print('Generated JSON:')
                        pprint(gen_json)
                        raise Exception(
                            'Generated file differs from original in JSON.')

            finally:
                if not do_no_remove_generated:
                    if os.path.exists(generated_filename):
                        os.unlink(generated_filename)
                    # python 3 does not generate PYC under the same dir
                    if os.path.exists(generated_filename + 'c'):
                        os.unlink(generated_filename + 'c')