コード例 #1
0
    def test_rx_check_http_negative(self):
        if self.is_loopback:
            self.skip('This test uses NAT, not relevant for loopback')

        if not CTRexScenario.router_cfg['no_dut_config']:
            self.router.configure_basic_interfaces()
            self.router.config_pbr(mode="config")

        core = self.get_benchmark_param('cores')
        mult = self.get_benchmark_param('multiplier')
        sample_rate = self.get_benchmark_param('rx_sample_rate')

        ret = self.trex.start_trex(c=core,
                                   m=mult,
                                   p=True,
                                   rx_check=sample_rate,
                                   d=60,
                                   f='cap2/http_simple.yaml',
                                   l=1000,
                                   k=10,
                                   learn_verify=True,
                                   l_pkt_mode=2)

        print('Run for 40 seconds, expect no errors')
        trex_res = self.trex.sample_x_seconds(40)
        print("\nLATEST RESULT OBJECT:")
        print(trex_res)
        self.check_general_scenario_results(trex_res)
        self.check_CPU_benchmark(trex_res)
        self.check_rx_errors(trex_res)

        print('Run until finish, expect errors')
        old_errors = copy.deepcopy(self.fail_reasons)
        nat_dict = self.get_benchmark_param('nat_dict',
                                            test_name='test_nat_simple_mode1')
        nat_obj = CNatConfig(nat_dict)
        self.router.config_nat(nat_obj)
        self.router.config_zbf()
        trex_res = self.trex.sample_until_finish()
        self.router.config_no_zbf()
        self.router.config_no_nat(nat_obj)
        #self.router.clear_nat_translations()
        print("\nLATEST RESULT OBJECT:")
        print(trex_res)
        self.check_rx_errors(trex_res, allow_error_tolerance=False)
        if self.fail_reasons == old_errors:
            self.fail('Expected errors here, got none.')
        else:
            print('Got errors as expected.')
            self.fail_reasons = old_errors
コード例 #2
0
ファイル: trex_nat_test.py プロジェクト: wshen0123/trex-core
    def nat_simple_helper(self, learn_mode=1):
        # test initializtion
        self.router.configure_basic_interfaces()

        stat_route_dict = self.get_benchmark_param('stat_route_dict')
        stat_route_obj = CStaticRouteConfig(stat_route_dict)
        self.router.config_static_routing(stat_route_obj, mode="config")

        nat_dict = self.get_benchmark_param('nat_dict')
        nat_obj = CNatConfig(nat_dict)
        self.router.config_nat(nat_obj)

        #       self.trex.set_yaml_file('cap2/http_simple.yaml')
        mult = self.get_benchmark_param('multiplier')
        core = self.get_benchmark_param('cores')

        #       trex_res = self.trex.run(nc=False,multiplier = mult, cores = core, duration = 100, l = 1000, learn = True)
        ret = self.trex.start_trex(c=core,
                                   m=mult,
                                   learn_mode=learn_mode,
                                   d=100,
                                   f='cap2/http_simple.yaml',
                                   l=1000)

        trex_res = self.trex.sample_to_run_finish()

        print("\nLATEST RESULT OBJECT:")
        print(trex_res)
        print("\nLATEST DUMP:")
        print(trex_res.get_latest_dump())

        trex_nat_stats = trex_res.get_last_value(
            "trex-global.data", ".*nat.*")  # extract all nat data
        if self.get_benchmark_param('allow_timeout_dev'):
            nat_timeout_ratio = float(trex_nat_stats['m_total_nat_time_out']
                                      ) / trex_nat_stats['m_total_nat_open']
            if nat_timeout_ratio > 0.005:
                self.fail('TRex nat_timeout ratio %f > 0.5%%' %
                          nat_timeout_ratio)
        else:
            self.check_results_eq(trex_nat_stats, 'm_total_nat_time_out', 0.0)
        self.check_results_eq(trex_nat_stats, 'm_total_nat_no_fid', 0.0)
        self.check_results_gt(trex_nat_stats, 'm_total_nat_open', 6000)

        self.check_general_scenario_results(
            trex_res, check_latency=False)  # NAT can cause latency
        ##       test_norm_cpu = 2*(trex_res.result['total-tx']/(core*trex_res.result['cpu_utilization']))
        #        trex_tx_pckt  = trex_res.get_last_value("trex-global.data.m_total_tx_bps")
        #        cpu_util = int(trex_res.get_last_value("trex-global.data.m_cpu_util"))
        #        test_norm_cpu = 2*(trex_tx_pckt/(core*cpu_util))
        #        print "test_norm_cpu is: ", test_norm_cpu

        self.check_CPU_benchmark(trex_res, minimal_cpu=10, maximal_cpu=85)

        #if ( abs((test_norm_cpu/self.get_benchmark_param('cpu_to_core_ratio')) - 1) > 0.03):
        #    raiseraise AbnormalResultError('Normalized bandwidth to CPU utilization ratio exceeds 3%')

        nat_stats = self.router.get_nat_stats()
        print(nat_stats)

        self.assert_gt(nat_stats['total_active_trans'], 5000,
                       'total active translations is not high enough')
        self.assert_gt(nat_stats['dynamic_active_trans'], 5000,
                       'total dynamic active translations is not high enough')
        self.assertEqual(
            nat_stats['static_active_trans'], 0,
            "NAT statistics nat_stats['static_active_trans'] should be zero")
        self.assert_gt(nat_stats['num_of_hits'], 50000,
                       'total nat hits is not high enough')