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 """ Fixed traffic profile definitions """
16 from __future__ import absolute_import
22 from yardstick.network_services.traffic_profile.prox_profile import ProxProfile
23 from yardstick.network_services import constants
24 from yardstick.common import constants as overall_constants
26 LOG = logging.getLogger(__name__)
28 STATUS_SUCCESS = "Success"
29 STATUS_FAIL = "Failure"
30 STATUS_RESULT = "Result"
31 STEP_CONFIRM = "Confirm retry"
32 STEP_INCREASE_LOWER = "Increase lower"
33 STEP_DECREASE_LOWER = "Decrease lower"
34 STEP_DECREASE_UPPER = "Decrease upper"
37 class ProxBinSearchProfile(ProxProfile):
39 This profile adds a single stream at the beginning of the traffic session
42 def __init__(self, tp_config):
43 super(ProxBinSearchProfile, self).__init__(tp_config)
44 self.current_lower = self.lower_bound
45 self.current_upper = self.upper_bound
49 return self.current_upper - self.current_lower
53 return (self.current_lower + self.current_upper) / 2
55 def bounds_iterator(self, logger=None):
56 self.current_lower = self.lower_bound
57 self.current_upper = self.upper_bound
59 test_value = self.current_upper
60 while abs(self.delta) >= self.precision:
62 logger.debug("New interval [%s, %s), precision: %d", self.current_lower,
63 self.current_upper, self.step_value)
64 logger.info("Testing with value %s", test_value)
67 test_value = self.mid_point
70 return self.done.is_set()
72 def run_test_with_pkt_size(self, traffic_gen, pkt_size, duration):
73 """Run the test for a single packet size.
75 :param traffic_gen: traffic generator instance
76 :type traffic_gen: TrafficGen
77 :param pkt_size: The packet size to test with.
79 :param duration: The duration for each try.
84 LOG.info("Testing with packet size %d", pkt_size)
86 # Binary search assumes the lower value of the interval is
87 # successful and the upper value is a failure.
88 # The first value that is tested, is the maximum value. If that
89 # succeeds, no more searching is needed. If it fails, a regular
90 # binary search is performed.
92 # The test_value used for the first iteration of binary search
93 # is adjusted so that the delta between this test_value and the
94 # upper bound is a power-of-2 multiple of precision. In the
95 # optimistic situation where this first test_value results in a
96 # success, the binary search will complete on an integer multiple
97 # of the precision, rather than on a fraction of it.
99 theor_max_thruput = 0.0
104 "test_duration": traffic_gen.scenario_helper.scenario_cfg["runner"]["duration"],
105 "test_precision": self.params["traffic_profile"]["test_precision"],
106 "tolerated_loss": self.params["traffic_profile"]["tolerated_loss"],
109 self.prev_time = time.time()
111 # throughput and packet loss from the most recent successful test
112 successful_pkt_loss = 0.0
113 line_speed = traffic_gen.scenario_helper.all_options.get(
114 "interface_speed_gbps", constants.NIC_GBPS_DEFAULT) * constants.ONE_GIGABIT_IN_BITS
116 ok_retry = traffic_gen.scenario_helper.scenario_cfg["runner"].get("confirmation", 0)
117 for step_id, test_value in enumerate(self.bounds_iterator(LOG)):
122 LOG.info("Checking MAX %s MIN %s TEST %s", self.current_upper,
123 self.lower_bound, test_value)
125 while (pos_retry <= ok_retry) and (neg_retry <= ok_retry):
127 total_retry = total_retry + 1
129 result, port_samples = self._profile_helper.run_test(pkt_size, duration,
134 if (total_retry > (ok_retry * 3)) and (ok_retry is not 0):
136 next_step = STEP_DECREASE_LOWER
137 successful_pkt_loss = result.pkt_loss
138 self.current_upper = test_value
139 neg_retry = total_retry
141 if (pos_retry < ok_retry) and (ok_retry is not 0):
142 status = STATUS_SUCCESS
143 next_step = STEP_CONFIRM
144 successful_pkt_loss = result.pkt_loss
147 status = STATUS_SUCCESS
148 next_step = STEP_INCREASE_LOWER
149 self.current_lower = test_value
150 successful_pkt_loss = result.pkt_loss
152 pos_retry = pos_retry + 1
155 if (neg_retry < ok_retry) and (ok_retry is not 0):
157 next_step = STEP_CONFIRM
161 next_step = STEP_DECREASE_UPPER
162 self.current_upper = test_value
164 neg_retry = neg_retry + 1
167 "Status = '%s' Next_Step = '%s'", status, next_step)
169 samples = result.get_samples(pkt_size, successful_pkt_loss, port_samples)
171 if theor_max_thruput < samples["TxThroughput"]:
172 theor_max_thruput = samples['TxThroughput']
173 samples['theor_max_throughput'] = theor_max_thruput
175 samples["rx_total"] = int(result.rx_total)
176 samples["tx_total"] = int(result.tx_total)
177 samples["can_be_lost"] = int(result.can_be_lost)
178 samples["drop_total"] = int(result.drop_total)
179 samples["RxThroughput_gbps"] = \
180 (samples["RxThroughput"] / 1000) * ((pkt_size + 20) * 8)
181 samples['Status'] = status
182 samples['Next_Step'] = next_step
183 samples["MAX_Rate"] = self.current_upper
184 samples["MIN_Rate"] = self.current_lower
185 samples["Test_Rate"] = test_value
186 samples["Step_Id"] = step_id
187 samples["Confirmation_Retry"] = total_retry
189 samples.update(test_data)
191 if status == STATUS_SUCCESS and next_step == STEP_INCREASE_LOWER:
192 # Store success samples for result samples
193 result_samples = samples
195 LOG.info(">>>##>>Collect TG KPIs %s %s", datetime.datetime.now(), samples)
197 self.queue.put(samples, True, overall_constants.QUEUE_PUT_TIMEOUT)
200 ">>>##>> Result Reached PktSize %s Theor_Max_Thruput %s Actual_throughput %s",
201 pkt_size, theor_max_thruput, result_samples.get("RxThroughput", 0.0))
202 result_samples["Status"] = STATUS_RESULT
203 result_samples["Next_Step"] = ""
204 result_samples["Actual_throughput"] = result_samples.get("RxThroughput", 0.0)
205 result_samples["theor_max_throughput"] = theor_max_thruput
206 self.queue.put(result_samples)