1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
20 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
21 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
23 LOG = logging.getLogger(__name__)
26 class ProxApproxVnf(SampleVNF):
30 PROX_MODE = "Workload"
31 VNF_PROMPT = "PROX started"
32 LUA_PARAMETER_NAME = "sut"
34 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
35 if setup_env_helper_type is None:
36 setup_env_helper_type = ProxDpdkVnfSetupEnvHelper
38 if resource_helper_type is None:
39 resource_helper_type = ProxResourceHelper
41 super(ProxApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
44 def _vnf_up_post(self):
45 self.resource_helper.up_post()
47 def vnf_execute(self, cmd, *args, **kwargs):
48 # try to execute with socket commands
49 # ignore socket errors, e.g. when using force_quit
50 ignore_errors = kwargs.pop("_ignore_errors", False)
52 return self.resource_helper.execute(cmd, *args, **kwargs)
54 if ignore_errors and e.errno in {errno.EPIPE, errno.ESHUTDOWN}:
59 def collect_kpi(self):
60 if self.resource_helper is None:
65 "collect_stats": {"core": {}},
69 if len(self.vnfd_helper.interfaces) not in {1, 2, 4}:
70 raise RuntimeError("Failed ..Invalid no of ports .. "
71 "1, 2 or 4 ports only supported at this time")
73 port_stats = self.vnf_execute('port_stats', range(len(self.vnfd_helper.interfaces)))
75 rx_total = port_stats[6]
76 tx_total = port_stats[7]
78 LOG.error("port_stats parse fail %s", port_stats)
79 # return empty dict so we don't mess up existing KPIs
83 "packets_in": tx_total,
84 "packets_dropped": (tx_total - rx_total),
85 "packets_fwd": rx_total,
86 "collect_stats": self.resource_helper.collect_kpi(),
88 LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
92 # this should be standardized for all VNFs or removed
93 self.setup_helper.rebind_drivers()
96 # try to quit with socket commands
97 self.vnf_execute("stop_all")
98 self.vnf_execute("quit")
99 # hopefully quit succeeds and socket closes, so ignore force_quit socket errors
100 self.vnf_execute("force_quit", _ignore_errors=True)
101 if self._vnf_process:
102 self._vnf_process.terminate()
103 self.setup_helper.kill_vnf()
105 self.resource_helper.stop_collect()
107 def instantiate(self, scenario_cfg, context_cfg):
108 # build config in parent process so we can access
109 # config from TG subprocesses
110 self.scenario_helper.scenario_cfg = scenario_cfg
111 self.setup_helper.build_config_file()
112 super(ProxApproxVnf, self).instantiate(scenario_cfg, context_cfg)