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
22 from yardstick.network_services.vnf_generic.vnf.tg_trex import TrexTrafficGen
23 from yardstick.network_services.vnf_generic.vnf.sample_vnf import Rfc2544ResourceHelper
24 from yardstick.network_services.vnf_generic.vnf.tg_trex import TrexResourceHelper
26 LOGGING = logging.getLogger(__name__)
29 class TrexRfc2544ResourceHelper(Rfc2544ResourceHelper):
32 return self.latency and self.iteration.value > 10
35 class TrexRfcResourceHelper(TrexResourceHelper):
37 LATENCY_TIME_SLEEP = 120
41 def __init__(self, setup_helper, rfc_helper_type=None):
42 super(TrexRfcResourceHelper, self).__init__(setup_helper)
44 if rfc_helper_type is None:
45 rfc_helper_type = TrexRfc2544ResourceHelper
47 self.rfc2544_helper = rfc_helper_type(self.scenario_helper)
49 def _run_traffic_once(self, traffic_profile):
50 if self._terminated.value:
53 traffic_profile.execute_traffic(self)
54 self.client_started.value = 1
55 time.sleep(self.RUN_DURATION)
56 self.client.stop(traffic_profile.ports)
57 time.sleep(self.WAIT_TIME)
58 samples = traffic_profile.get_drop_percentage(self)
59 self._queue.put(samples)
61 if not self.rfc2544_helper.is_done():
64 self.client.stop(traffic_profile.ports)
65 self.client.reset(ports=traffic_profile.ports)
66 self.client.remove_all_streams(traffic_profile.ports)
67 traffic_profile.execute_traffic_latency(samples=samples)
68 multiplier = traffic_profile.calculate_pps(samples)[1]
70 time.sleep(self.LATENCY_TIME_SLEEP)
71 self.client.stop(traffic_profile.ports)
72 time.sleep(self.WAIT_TIME)
73 last_res = self.client.get_stats(traffic_profile.ports)
74 if not isinstance(last_res, Mapping):
75 self._terminated.value = 1
77 self.generate_samples(traffic_profile.ports, 'latency', {})
78 self._queue.put(samples)
79 self.client.start(mult=str(multiplier),
80 ports=traffic_profile.ports,
81 duration=120, force=True)
83 def start_client(self, ports, mult=None, duration=None, force=True):
84 self.client.start(ports=ports, mult=mult, duration=duration, force=force)
86 def clear_client_stats(self, ports):
87 self.client.clear_stats(ports=ports)
89 def collect_kpi(self):
90 self.rfc2544_helper.iteration.value += 1
91 return super(TrexRfcResourceHelper, self).collect_kpi()
94 class TrexTrafficGenRFC(TrexTrafficGen):
96 This class handles mapping traffic profile and generating
97 traffic for rfc2544 testcase.
100 def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
101 if resource_helper_type is None:
102 resource_helper_type = TrexRfcResourceHelper
104 super(TrexTrafficGenRFC, self).__init__(name, vnfd, setup_env_helper_type,
105 resource_helper_type)