X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fnetwork_services%2Ftraffic_profile%2Fbase.py;h=ea3f17874a971865bcd5711546adefadc6091c22;hb=51cf862dbca0718be394a30ab346821698d835d3;hp=f4b5b178caec96acbe06912f97cec5cf429f00fd;hpb=d64760d051ec14002847352a20da02774a8bda05;p=yardstick.git diff --git a/yardstick/network_services/traffic_profile/base.py b/yardstick/network_services/traffic_profile/base.py index f4b5b178c..ea3f17874 100644 --- a/yardstick/network_services/traffic_profile/base.py +++ b/yardstick/network_services/traffic_profile/base.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re + from yardstick.common import exceptions from yardstick.common import utils @@ -21,10 +23,12 @@ class TrafficProfileConfig(object): This object will parse and validate the traffic profile information. """ - DEFAULT_SCHEMA = 'nsb:traffic_profile:0.1' - DEFAULT_FRAME_RATE = 100 + DEFAULT_FRAME_RATE = '100' DEFAULT_DURATION = 30 + RATE_FPS = 'fps' + RATE_PERCENTAGE = '%' + RATE_REGEX = re.compile(r'([0-9]*\.[0-9]+|[0-9]+)\s*(fps|%)*(.*)') def __init__(self, tp_config): self.schema = tp_config.get('schema', self.DEFAULT_SCHEMA) @@ -32,13 +36,36 @@ class TrafficProfileConfig(object): self.description = tp_config.get('description') tprofile = tp_config['traffic_profile'] self.traffic_type = tprofile.get('traffic_type') - self.frame_rate = tprofile.get('frame_rate', self.DEFAULT_FRAME_RATE) + self.frame_rate, self.rate_unit = self._parse_rate( + tprofile.get('frame_rate', self.DEFAULT_FRAME_RATE)) self.test_precision = tprofile.get('test_precision') self.packet_sizes = tprofile.get('packet_sizes') self.duration = tprofile.get('duration', self.DEFAULT_DURATION) self.lower_bound = tprofile.get('lower_bound') self.upper_bound = tprofile.get('upper_bound') self.step_interval = tprofile.get('step_interval') + self.enable_latency = tprofile.get('enable_latency', False) + + def _parse_rate(self, rate): + """Parse traffic profile rate + + The line rate can be defined in fps or percentage over the maximum line + rate: + - frame_rate = 5000 (by default, unit is 'fps') + - frame_rate = 5000fps + - frame_rate = 25% + + :param rate: (string, int) line rate in fps or % + :return: (tuple: int, string) line rate number and unit + """ + match = self.RATE_REGEX.match(str(rate)) + if not match: + exceptions.TrafficProfileRate() + rate = float(match.group(1)) + unit = match.group(2) if match.group(2) else self.RATE_FPS + if match.group(3): + raise exceptions.TrafficProfileRate() + return rate, unit class TrafficProfile(object): @@ -70,6 +97,9 @@ class TrafficProfile(object): self.params = tp_config self.config = TrafficProfileConfig(tp_config) + def is_ended(self): + return False + def execute_traffic(self, traffic_generator, **kawrgs): """ This methods defines the behavior of the traffic generator. It will be called in a loop until the traffic generator exits.