1 # Copyright (c) 2016-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 utils
19 from yardstick.network_services.vnf_generic.vnf import sample_vnf
20 from yardstick.network_services.vnf_generic.vnf import tg_trex
23 LOGGING = logging.getLogger(__name__)
26 class TrexRfcResourceHelper(tg_trex.TrexResourceHelper):
31 def __init__(self, setup_helper):
32 super(TrexRfcResourceHelper, self).__init__(setup_helper)
33 self.rfc2544_helper = sample_vnf.Rfc2544ResourceHelper(
36 def _run_traffic_once(self, traffic_profile):
37 self.client_started.value = 1
38 ports, port_pg_id = traffic_profile.execute_traffic(self)
41 timeout = int(traffic_profile.config.duration) - self.TRANSIENT_PERIOD
42 time.sleep(self.TRANSIENT_PERIOD)
43 for _ in utils.Timer(timeout=timeout):
44 samples.append(self._get_samples(ports, port_pg_id=port_pg_id))
45 time.sleep(self.SAMPLING_PERIOD)
47 traffic_profile.stop_traffic(self)
48 completed, output = traffic_profile.get_drop_percentage(
49 samples, self.rfc2544_helper.tolerance_low,
50 self.rfc2544_helper.tolerance_high,
51 self.rfc2544_helper.correlated_traffic)
52 self._queue.put(output)
55 def start_client(self, ports, mult=None, duration=None, force=True):
56 self.client.start(ports=ports, mult=mult, duration=duration, force=force)
58 def clear_client_stats(self, ports):
59 self.client.clear_stats(ports=ports)
62 class TrexTrafficGenRFC(tg_trex.TrexTrafficGen):
64 This class handles mapping traffic profile and generating
65 traffic for rfc2544 testcase.
68 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
69 if resource_helper_type is None:
70 resource_helper_type = TrexRfcResourceHelper
72 super(TrexTrafficGenRFC, self).__init__(name, vnfd, setup_env_helper_type,