X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FDropRateSearch.py;h=d090306cc5ffdbf8182f3de3f6f667319d29e7e2;hb=1999c2ecc15760a57bdf34498635432ddb0321e0;hp=2de8e3c174052910a93ed55d32aa7d7e40d82d98;hpb=4c75804c85ffa7ef236fff24ea8d159ca2dc73b7;p=csit.git diff --git a/resources/libraries/python/DropRateSearch.py b/resources/libraries/python/DropRateSearch.py index 2de8e3c174..d090306cc5 100644 --- a/resources/libraries/python/DropRateSearch.py +++ b/resources/libraries/python/DropRateSearch.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -125,7 +125,7 @@ class DropRateSearch(object): :type traffic_type: str :type traffic_type: bool :returns: Drop threshold exceeded? (True/False) - :rtype bool + :rtype: bool """ pass @@ -137,7 +137,7 @@ class DropRateSearch(object): :type max_rate: float :type min_rate: float :returns: nothing - :raises: ValueError if min rate is lower than 0 and higher than max rate + :raises ValueError: If min rate is lower than 0 or higher than max rate. """ if float(min_rate) <= 0: raise ValueError("min_rate must be higher than 0") @@ -153,7 +153,7 @@ class DropRateSearch(object): :param loss_acceptance: Loss acceptance treshold for PDR search. :type loss_acceptance: str :returns: nothing - :raises: ValueError if loss acceptance is lower than zero + :raises ValueError: If loss acceptance is lower than zero. """ if float(loss_acceptance) < 0: raise ValueError("Loss acceptance must be higher or equal 0") @@ -227,7 +227,7 @@ class DropRateSearch(object): :param rate_type: Type of rate to set. :type rate_type: RateType :returns: nothing - :raises: Exception if rate type is unknown + :raises Exception: If rate type is unknown. """ if rate_type not in RateType: raise Exception("rate_type unknown: {}".format(rate_type)) @@ -282,7 +282,7 @@ class DropRateSearch(object): :returns: String representation of rate type. :rtype: str - :raises: ValueError if rate type is unknown + :raises ValueError: If rate type is unknown. """ if self._rate_type == RateType.PERCENTAGE: return "%" @@ -299,7 +299,7 @@ class DropRateSearch(object): :param max_attempts: Number of traffic runs. :type max_attempts: int :returns: nothing - :raises: ValueError if max attempts is lower than zero + :raises ValueError: If max attempts is lower than zero. """ if int(max_attempts) > 0: self._max_attempts = int(max_attempts) @@ -334,7 +334,7 @@ class DropRateSearch(object): :param search_type: Type of search result evaluation to set. :type search_type: SearchResultType :returns: nothing - :raises: ValueError if search type is unknown + :raises ValueError: If search type is unknown. """ if search_type not in SearchResultType: raise ValueError("search_type unknown: {}".format(search_type)) @@ -372,7 +372,7 @@ class DropRateSearch(object): :type res_list: list :returns: Boolean based on search result type. :rtype: boolean - :raises: ValueError if search result type is unknown + :raises ValueError: If search result type is unknown. """ if self._search_result_type == SearchResultType.BEST_OF_N: return self._get_best_of_n(res_list) @@ -389,7 +389,7 @@ class DropRateSearch(object): :type start_rate: float :type traffic_type: str :returns: nothing - :raises: ValueError if start rate is not in range + :raises ValueError: If start rate is not in range. """ if not self._rate_min <= float(start_rate) <= self._rate_max: @@ -403,44 +403,13 @@ class DropRateSearch(object): while True: res = [] for dummy in range(self._max_attempts): - res.append(self.measure_loss(rate, self._frame_size, - self._loss_acceptance, - self._loss_acceptance_type, - traffic_type)) + res.append(self.measure_loss( + rate, self._frame_size, self._loss_acceptance, + self._loss_acceptance_type, traffic_type)) res = self._get_res_based_on_search_type(res) - if self._search_linear_direction == SearchDirection.BOTTOM_UP: - # loss occurred and it was above acceptance criteria - if not res: - # if this is first run then we didn't find drop rate - if prev_rate is None: - self._search_result = SearchResults.FAILURE - self._search_result_rate = None - # else we found the rate, which is value from previous run - else: - self._search_result = SearchResults.SUCCESS - self._search_result_rate = prev_rate - return - # there was no loss / loss below acceptance criteria - elif res: - prev_rate = rate - rate += self._rate_linear_step - if rate > self._rate_max: - if prev_rate != self._rate_max: - # one last step with rate set to _rate_max - rate = self._rate_max - continue - else: - self._search_result = SearchResults.SUCCESS - self._search_result_rate = prev_rate - return - else: - continue - else: - raise RuntimeError("Unknown search result") - - elif self._search_linear_direction == SearchDirection.TOP_DOWN: + if self._search_linear_direction == SearchDirection.TOP_DOWN: # loss occurred, decrease rate if not res: prev_rate = rate @@ -466,20 +435,17 @@ class DropRateSearch(object): else: raise Exception("Unknown search direction") - raise Exception("Wrong codepath") - def verify_search_result(self): """Fail if search was not successful. :returns: Result rate and latency stats. :rtype: tuple - :raises: Exception if search failed + :raises Exception: If search failed. """ - if self._search_result == SearchResults.FAILURE: - raise Exception('Search FAILED') - elif self._search_result in [SearchResults.SUCCESS, - SearchResults.SUSPICIOUS]: + if self._search_result in [ + SearchResults.SUCCESS, SearchResults.SUSPICIOUS]: return self._search_result_rate, self.get_latency() + raise Exception('Search FAILED') def binary_search(self, b_min, b_max, traffic_type, skip_max_rate=False, skip_warmup=False): @@ -496,7 +462,7 @@ class DropRateSearch(object): :type skip_max_rate: bool :type skip_warmup: bool :returns: nothing - :raises: ValueError if input values are not valid + :raises ValueError: If input values are not valid. """ if not self._rate_min <= float(b_min) <= self._rate_max: @@ -546,7 +512,7 @@ class DropRateSearch(object): :type start_rate: float :type traffic_type: str :returns: nothing - :raises: RuntimeError if linear search failed + :raises RuntimeError: If linear search failed. """ self.linear_search(start_rate, traffic_type) @@ -596,7 +562,7 @@ class DropRateSearch(object): :returns: Returns True if num_a is close in value to num_b or equal. False otherwise. :rtype: boolean - :raises: ValueError if input values are not valid + :raises ValueError: If input values are not valid. """ if num_a == num_b: