1 # Copyright (c) 2018-2019 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.
18 from yardstick.common import constants
19 from yardstick.common import exceptions
20 from yardstick.common import utils
21 from yardstick.network_services.vnf_generic.vnf import base as vnf_base
24 LOG = logging.getLogger(__name__)
27 class PktgenTrafficGen(vnf_base.GenericTrafficGen):
28 """DPDK Pktgen traffic generator
30 Website: http://pktgen-dpdk.readthedocs.io/en/latest/index.html
35 def __init__(self, name, vnfd):
36 vnf_base.GenericTrafficGen.__init__(self, name, vnfd)
37 self._traffic_profile = None
38 self._node_ip = vnfd['mgmt-interface'].get('ip')
39 self._lua_node_port = self._get_lua_node_port(
40 vnfd['mgmt-interface'].get('service_ports', []))
43 def instantiate(self, scenario_cfg, context_cfg): # pragma: no cover
46 def run_traffic(self, traffic_profile):
47 self._traffic_profile = traffic_profile
48 self._traffic_profile.init(self._node_ip, self._lua_node_port)
49 utils.wait_until_true(self._is_running, timeout=self.TIMEOUT,
52 def terminate(self): # pragma: no cover
55 def collect_kpi(self): # pragma: no cover
58 def scale(self, flavor=''): # pragma: no cover
61 def wait_for_instantiate(self): # pragma: no cover
64 def runner_method_start_iteration(self):
66 LOG.debug('Start method')
67 # NOTE(ralonsoh): 'rate' should be modified between iterations. The
68 # current implementation is just for testing.
70 self._traffic_profile.start()
71 self._traffic_profile.rate(self._rate)
73 self._traffic_profile.stop()
76 def _get_lua_node_port(service_ports):
77 for port in (port for port in service_ports if
78 int(port['port']) == constants.LUA_PORT):
79 return int(port['node_port'])
80 # NOTE(ralonsoh): in case LUA port is not present, an exception should
83 def _is_running(self):
85 self._traffic_profile.help()
87 except exceptions.PktgenActionError: