1 # Copyright (c) 2016-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.
14 """ Trex traffic generation definitions which implements rfc2544 """
16 from __future__ import absolute_import
17 from __future__ import print_function
20 from collections import Mapping
21 from itertools import chain
23 from yardstick.network_services.helpers.samplevnf_helper import MultiPortConfig
24 from yardstick.network_services.vnf_generic.vnf.tg_trex import TrexTrafficGen
25 from yardstick.network_services.vnf_generic.vnf.sample_vnf import Rfc2544ResourceHelper
26 from yardstick.network_services.vnf_generic.vnf.tg_trex import TrexResourceHelper
28 LOGGING = logging.getLogger(__name__)
31 class TrexRfc2544ResourceHelper(Rfc2544ResourceHelper):
34 return self.latency and self.iteration.value > 10
37 class TrexRfcResourceHelper(TrexResourceHelper):
39 LATENCY_TIME_SLEEP = 120
43 def __init__(self, setup_helper, rfc_helper_type=None):
44 super(TrexRfcResourceHelper, self).__init__(setup_helper)
46 if rfc_helper_type is None:
47 rfc_helper_type = TrexRfc2544ResourceHelper
49 self.rfc2544_helper = rfc_helper_type(self.scenario_helper)
50 # self.tg_port_pairs = []
52 def _build_ports(self):
53 self.tg_port_pairs, self.networks = MultiPortConfig.get_port_pairs(
54 self.vnfd_helper.interfaces)
55 self.priv_ports = [int(x[0][-1]) for x in self.tg_port_pairs]
56 self.pub_ports = [int(x[1][-1]) for x in self.tg_port_pairs]
57 self.my_ports = list(set(chain(self.priv_ports, self.pub_ports)))
59 def _run_traffic_once(self, traffic_profile):
60 if self._terminated.value:
63 traffic_profile.execute(self)
64 self.client_started.value = 1
65 time.sleep(self.RUN_DURATION)
66 self.client.stop(self.my_ports)
67 time.sleep(self.WAIT_TIME)
68 samples = traffic_profile.get_drop_percentage(self)
69 self._queue.put(samples)
71 if not self.rfc2544_helper.is_done():
74 self.client.stop(self.my_ports)
75 self.client.reset(ports=self.my_ports)
76 self.client.remove_all_streams(self.my_ports)
77 traffic_profile.execute_latency(samples=samples)
78 multiplier = traffic_profile.calculate_pps(samples)[1]
80 time.sleep(self.LATENCY_TIME_SLEEP)
81 self.client.stop(self.my_ports)
82 time.sleep(self.WAIT_TIME)
83 last_res = self.client.get_stats(self.my_ports)
84 if not isinstance(last_res, Mapping):
85 self._terminated.value = 1
87 self.generate_samples('latency', {})
88 self._queue.put(samples)
89 self.client.start(mult=str(multiplier),
91 duration=120, force=True)
93 def start_client(self, mult, duration, force=True):
94 self.client.start(ports=self.my_ports, mult=mult, duration=duration, force=force)
96 def clear_client_stats(self):
97 self.client.clear_stats(ports=self.my_ports)
99 def collect_kpi(self):
100 self.rfc2544_helper.iteration.value += 1
101 super(TrexRfcResourceHelper, self).collect_kpi()
104 class TrexTrafficGenRFC(TrexTrafficGen):
106 This class handles mapping traffic profile and generating
107 traffic for rfc2544 testcase.
110 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
111 if resource_helper_type is None:
112 resource_helper_type = TrexRfcResourceHelper
114 super(TrexTrafficGenRFC, self).__init__(name, vnfd, setup_env_helper_type,
115 resource_helper_type)