add yardstick iruya 9.0.0 release notes
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / tg_pktgen.py
1 # Copyright (c) 2018-2019 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import logging
16 import time
17
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
22
23
24 LOG = logging.getLogger(__name__)
25
26
27 class PktgenTrafficGen(vnf_base.GenericTrafficGen):
28     """DPDK Pktgen traffic generator
29
30     Website: http://pktgen-dpdk.readthedocs.io/en/latest/index.html
31     """
32
33     TIMEOUT = 30
34
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', []))
41         self._rate = 1
42
43     def instantiate(self, scenario_cfg, context_cfg):  # pragma: no cover
44         pass
45
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,
50                               sleep=2)
51
52     def terminate(self):  # pragma: no cover
53         pass
54
55     def collect_kpi(self):  # pragma: no cover
56         pass
57
58     def scale(self, flavor=''):  # pragma: no cover
59         pass
60
61     def wait_for_instantiate(self):  # pragma: no cover
62         pass
63
64     def runner_method_start_iteration(self):
65         # pragma: no cover
66         LOG.debug('Start method')
67         # NOTE(ralonsoh): 'rate' should be modified between iterations. The
68         # current implementation is just for testing.
69         self._rate += 1
70         self._traffic_profile.start()
71         self._traffic_profile.rate(self._rate)
72         time.sleep(4)
73         self._traffic_profile.stop()
74
75     @staticmethod
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
81         # be raised.
82
83     def _is_running(self):
84         try:
85             self._traffic_profile.help()
86             return True
87         except exceptions.PktgenActionError:
88             return False