def bad_test_instantiate(self, ssh, mock_time):
     prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
     prox_approx_vnf.scenario_helper = mock.MagicMock()
     prox_approx_vnf.setup_helper = mock.MagicMock()
     # we can't mock super
     prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
     prox_approx_vnf.setup_helper.build_config.assert_called_once()
Пример #2
0
class ProxTrafficGen(SampleVNFTrafficGen):

    APP_NAME = 'ProxTG'
    PROX_MODE = "Traffic Gen"
    LUA_PARAMETER_NAME = "gen"
    WAIT_TIME = 1

    def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
        # don't call superclass, use custom wrapper of ProxApproxVnf
        self._vnf_wrapper = ProxApproxVnf(name, vnfd, setup_env_helper_type, resource_helper_type)
        self.bin_path = get_nsb_option('bin_path', '')
        self.name = self._vnf_wrapper.name
        self.ssh_helper = self._vnf_wrapper.ssh_helper
        self.setup_helper = self._vnf_wrapper.setup_helper
        self.resource_helper = self._vnf_wrapper.resource_helper
        self.scenario_helper = self._vnf_wrapper.scenario_helper

        self.runs_traffic = True
        self.traffic_finished = False
        self._tg_process = None
        self._traffic_process = None

    def terminate(self):
        self._vnf_wrapper.terminate()
        super(ProxTrafficGen, self).terminate()

    def instantiate(self, scenario_cfg, context_cfg):
        self._vnf_wrapper.instantiate(scenario_cfg, context_cfg)
        self._tg_process = self._vnf_wrapper._vnf_process

    def wait_for_instantiate(self):
        self._vnf_wrapper.wait_for_instantiate()
Пример #3
0
class ProxTrafficGen(SampleVNFTrafficGen):

    APP_NAME = 'ProxTG'
    PROX_MODE = "Traffic Gen"
    LUA_PARAMETER_NAME = "gen"
    WAIT_TIME = 1

    @staticmethod
    def _sort_vpci(vnfd):
        """

        :param vnfd: vnfd.yaml
        :return: trex_cfg.yaml file
        """
        def key_func(interface):
            return interface["virtual-interface"]["vpci"], interface["name"]

        ext_intf = vnfd["vdu"][0]["external-interface"]
        return sorted(ext_intf, key=key_func)

    def __init__(self,
                 name,
                 vnfd,
                 setup_env_helper_type=None,
                 resource_helper_type=None):
        # don't call superclass, use custom wrapper of ProxApproxVnf
        self._vnf_wrapper = ProxApproxVnf(name, vnfd, setup_env_helper_type,
                                          resource_helper_type)
        self.bin_path = get_nsb_option('bin_path', '')
        self.name = self._vnf_wrapper.name
        self.ssh_helper = self._vnf_wrapper.ssh_helper
        self.setup_helper = self._vnf_wrapper.setup_helper
        self.resource_helper = self._vnf_wrapper.resource_helper
        self.scenario_helper = self._vnf_wrapper.scenario_helper

        self.runs_traffic = True
        self.traffic_finished = False
        self._tg_process = None
        self._traffic_process = None

        # used for generating stats
        self.vpci_if_name_ascending = self._sort_vpci(vnfd)
        self.resource_helper.vpci_if_name_ascending = self._sort_vpci(vnfd)

    def listen_traffic(self, traffic_profile):
        pass

    def terminate(self):
        self._vnf_wrapper.terminate()
        super(ProxTrafficGen, self).terminate()

    def instantiate(self, scenario_cfg, context_cfg):
        self._vnf_wrapper.instantiate(scenario_cfg, context_cfg)
        self._tg_process = self._vnf_wrapper._vnf_process

    def wait_for_instantiate(self):
        self._vnf_wrapper.wait_for_instantiate()
Пример #4
0
class ProxIrq(SampleVNFTrafficGen):
    def __init__(self,
                 name,
                 vnfd,
                 task_id,
                 setup_env_helper_type=None,
                 resource_helper_type=None):
        vnfd_cpy = copy.deepcopy(vnfd)
        super(ProxIrq, self).__init__(name, vnfd_cpy, task_id)

        self._vnf_wrapper = ProxApproxVnf(name, vnfd, task_id,
                                          setup_env_helper_type,
                                          resource_helper_type)
        self.bin_path = get_nsb_option('bin_path', '')
        self.name = self._vnf_wrapper.name
        self.ssh_helper = self._vnf_wrapper.ssh_helper
        self.setup_helper = self._vnf_wrapper.setup_helper
        self.resource_helper = self._vnf_wrapper.resource_helper
        self.scenario_helper = self._vnf_wrapper.scenario_helper
        self.irq_cores = None

    def terminate(self):
        self._vnf_wrapper.terminate()
        super(ProxIrq, self).terminate()

    def instantiate(self, scenario_cfg, context_cfg):
        self._vnf_wrapper.instantiate(scenario_cfg, context_cfg)
        self._tg_process = self._vnf_wrapper._vnf_process

    def wait_for_instantiate(self):
        self._vnf_wrapper.wait_for_instantiate()

    def get_irq_cores(self):
        cores = []
        mode = "irq"

        for section_name, section in self.setup_helper.prox_config_data:
            if not section_name.startswith("core"):
                continue
            irq_mode = task_present = False
            task_present_task = 0
            for key, value in section:
                if key == "mode" and value == mode:
                    irq_mode = True
                if key == "task":
                    task_present = True
                    task_present_task = int(value)

            if irq_mode:
                if not task_present:
                    task_present_task = 0
                core_tuple = CoreSocketTuple(section_name)
                core = core_tuple.core_id
                cores.append((core, task_present_task))

        return cores
Пример #5
0
    def test_instantiate(self, ssh, mock_find, mock_cpu_sys_cores, mock_time):
        mock_ssh(ssh)

        mock_cpu_sys_cores.get_core_socket.return_value = {'0': '01234'}

        prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0)
        prox_approx_vnf.ssh_helper = mock.MagicMock(
            **{"execute.return_value": (0, "", ""), "bin_path": ""})
        prox_approx_vnf.setup_helper._setup_resources = mock.MagicMock()
        prox_approx_vnf.setup_helper._find_used_drivers = mock.MagicMock()
        prox_approx_vnf.setup_helper.used_drivers = {}
        prox_approx_vnf.setup_helper.bound_pci = []
        prox_approx_vnf._run_prox = mock.MagicMock(return_value=0)
        prox_approx_vnf.resource_helper = mock.MagicMock()
        prox_approx_vnf.resource_helper.get_process_args.return_value = {
                    '-e': '',
                    '-t': '',
                }, 'configs/l3-gen-2.cfg', '/root/dppd-PROX-v035/build/prox'

        prox_approx_vnf.copy_to_target = mock.MagicMock()
        prox_approx_vnf.upload_prox_config = mock.MagicMock()
        prox_approx_vnf.generate_prox_config_file = mock.MagicMock()
        prox_approx_vnf.q_out.put("PROX started")
        prox_approx_vnf.WAIT_TIME = 0

        # if process it still running exitcode will be None
        expected = 0, None
        result = prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
        self.assertIn(result, expected)