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.
16 import multiprocessing
20 from yardstick.network_services.vnf_generic.vnf.base import QueueFileWrapper
21 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper
22 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
23 from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNF
25 LOG = logging.getLogger(__name__)
28 class ProxApproxVnf(SampleVNF):
32 PROX_MODE = "Workload"
33 VNF_PROMPT = "PROX started"
34 LUA_PARAMETER_NAME = "sut"
36 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
37 if setup_env_helper_type is None:
38 setup_env_helper_type = ProxDpdkVnfSetupEnvHelper
40 if resource_helper_type is None:
41 resource_helper_type = ProxResourceHelper
43 super(ProxApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
46 self._terminated = multiprocessing.Value('i', 0)
47 self._queue = multiprocessing.Value('i', 0)
49 def instantiate(self, scenario_cfg, context_cfg):
50 LOG.info("printing .........prox instantiate ")
52 self.scenario_helper.scenario_cfg = scenario_cfg
54 # this won't work we need 1GB hugepages at boot
55 self.setup_helper.setup_vnf_environment()
57 # self.connection.run("cat /proc/cpuinfo")
59 prox_args, prox_path, remote_path = self.resource_helper.get_process_args()
61 self.q_in = multiprocessing.Queue()
62 self.q_out = multiprocessing.Queue()
63 self.queue_wrapper = QueueFileWrapper(self.q_in, self.q_out, "PROX started")
64 self._vnf_process = multiprocessing.Process(target=self._run_prox,
65 args=(remote_path, prox_path, prox_args))
66 self._vnf_process.start()
68 def _vnf_up_post(self):
69 self.resource_helper.up_post()
71 def _run_prox(self, file_wrapper, config_path, prox_path, prox_args):
72 # This runs in a different process and should not share an SSH connection
73 # with the rest of the object
74 self.ssh_helper.drop_connection()
76 time.sleep(self.WAIT_TIME)
78 args = " ".join(" ".join([k, v if v else ""]) for k, v in prox_args.items())
80 cmd_template = "sudo bash -c 'cd {}; {} -o cli {} -f {} '"
81 prox_cmd = cmd_template.format(os.path.dirname(prox_path), prox_path, args, config_path)
84 self.ssh_helper.run(prox_cmd, stdin=file_wrapper, stdout=file_wrapper,
85 keep_stdin_open=True, pty=False)
87 def vnf_execute(self, cmd, wait_time=2):
88 # try to execute with socket commands
89 self.resource_helper.execute(cmd)
91 def collect_kpi(self):
92 if self.resource_helper is None:
97 "collect_stats": {"core": {}},
101 if len(self.vnfd_helper.interfaces) not in {2, 4}:
102 raise RuntimeError("Failed ..Invalid no of ports .. "
103 "2 or 4 ports only supported at this time")
105 port_stats = self.resource_helper.execute('port_stats', self.vnfd_helper.interfaces)
106 rx_total = port_stats[6]
107 tx_total = port_stats[7]
109 "packets_in": tx_total,
110 "packets_dropped": (tx_total - rx_total),
111 "packets_fwd": rx_total,
112 "collect_stats": self.resource_helper.collect_kpi(),
116 def _tear_down(self):
117 self.setup_helper.rebind_drivers()