1 # Copyright (c) 2018 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.common import constants
21 from yardstick.common import exceptions
22 from yardstick.common import utils
23 from yardstick.network_services.vnf_generic.vnf import base as vnf_base
26 LOG = logging.getLogger(__name__)
29 class PktgenTrafficGen(vnf_base.GenericTrafficGen,
30 vnf_base.GenericVNFEndpoint):
31 """DPDK Pktgen traffic generator
33 Website: http://pktgen-dpdk.readthedocs.io/en/latest/index.html
38 def __init__(self, name, vnfd, task_id):
39 vnf_base.GenericTrafficGen.__init__(self, name, vnfd, task_id)
40 self.queue = multiprocessing.Queue()
41 self._id = uuid.uuid1().int
42 self._mq_producer = self._setup_mq_producer(self._id)
43 vnf_base.GenericVNFEndpoint.__init__(self, self._id, [task_id],
45 self._consumer = vnf_base.GenericVNFConsumer([task_id], self)
46 self._consumer.start_rpc_server()
47 self._traffic_profile = None
48 self._node_ip = vnfd['mgmt-interface'].get('ip')
49 self._lua_node_port = self._get_lua_node_port(
50 vnfd['mgmt-interface'].get('service_ports', []))
53 def instantiate(self, scenario_cfg, context_cfg): # pragma: no cover
56 def run_traffic(self, traffic_profile):
57 self._traffic_profile = traffic_profile
58 self._traffic_profile.init(self._node_ip, self._lua_node_port)
59 utils.wait_until_true(self._is_running, timeout=self.TIMEOUT,
62 def terminate(self): # pragma: no cover
65 def collect_kpi(self): # pragma: no cover
68 def scale(self, flavor=''): # pragma: no cover
71 def wait_for_instantiate(self): # pragma: no cover
74 def runner_method_start_iteration(self, ctxt, **kwargs):
76 LOG.debug('Start method')
77 # NOTE(ralonsoh): 'rate' should be modified between iterations. The
78 # current implementation is just for testing.
80 self._traffic_profile.start()
81 self._traffic_profile.rate(self._rate)
83 self._traffic_profile.stop()
84 self._mq_producer.tg_method_iteration(1, 1, {})
86 def runner_method_stop_iteration(self, ctxt, **kwargs): # pragma: no cover
88 LOG.debug('Stop method')
91 def _get_lua_node_port(service_ports):
92 for port in (port for port in service_ports if
93 int(port['port']) == constants.LUA_PORT):
94 return int(port['node_port'])
95 # NOTE(ralonsoh): in case LUA port is not present, an exception should
98 def _is_running(self):
100 self._traffic_profile.help()
102 except exceptions.PktgenActionError: