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()
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()
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
def test_terminate(self, ssh, mock_socket, mock_time): mock_ssh(ssh) prox_approx_vnf = ProxApproxVnf(NAME, self.VNFD0) prox_approx_vnf._vnf_process = mock.MagicMock() prox_approx_vnf._vnf_process.terminate = mock.Mock() prox_approx_vnf.ssh_helper = mock.MagicMock() prox_approx_vnf.setup_helper = mock.Mock() prox_approx_vnf.resource_helper = mock.MagicMock() self.assertIsNone(prox_approx_vnf.terminate())