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)))
74 rx_total = port_stats[6]
75 tx_total = port_stats[7]
77 "packets_in": tx_total,
78 "packets_dropped": (tx_total - rx_total),
79 "packets_fwd": rx_total,
80 "collect_stats": self.resource_helper.collect_kpi(),
82 LOG.debug("%s collect KPIs %s", self.APP_NAME, result)
86 # this should be standardized for all VNFs or removed
87 self.setup_helper.rebind_drivers()
90 # try to quit with socket commands
91 self.vnf_execute("stop_all")
92 self.vnf_execute("quit")
93 # hopefully quit succeeds and socket closes, so ignore force_quit socket errors
94 self.vnf_execute("force_quit", _ignore_errors=True)
96 self._vnf_process.terminate()
97 self.setup_helper.kill_vnf()
99 self.resource_helper.stop_collect()
101 def instantiate(self, scenario_cfg, context_cfg):
102 # build config in parent process so we can access
103 # config from TG subprocesses
104 self.scenario_helper.scenario_cfg = scenario_cfg
105 self.setup_helper.build_config_file()
106 super(ProxApproxVnf, self).instantiate(scenario_cfg, context_cfg)