PROX VNF and TG
[yardstick.git] / yardstick / network_services / traffic_profile / prox_profile.py
1 # Copyright (c) 2016-2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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 """
15
16 from __future__ import absolute_import
17
18 import logging
19
20 from yardstick.network_services.traffic_profile.base import TrafficProfile
21
22 LOG = logging.getLogger(__name__)
23
24
25 class ProxProfile(TrafficProfile):
26     """
27     This profile adds a single stream at the beginning of the traffic session
28     """
29
30     @staticmethod
31     def fill_samples(samples, traffic_gen):
32         for vpci_idx, intf in enumerate(traffic_gen.vpci_if_name_ascending):
33             name = intf[1]
34             # TODO: VNFDs KPIs values needs to be mapped to TRex structure
35             xe_port = traffic_gen.resource_helper.sut.port_stats([vpci_idx])
36             samples[name] = {
37                 "in_packets": xe_port[6],
38                 "out_packets": xe_port[7],
39             }
40
41     def __init__(self, tp_config):
42         super(ProxProfile, self).__init__(tp_config)
43         self.queue = None
44         self.done = False
45         self.results = []
46
47         # TODO: get init values from tp_config
48         self.prox_config = tp_config["traffic_profile"]
49         self.pkt_sizes = [int(x) for x in self.prox_config.get("packet_sizes", [])]
50         self.pkt_size_iterator = iter(self.pkt_sizes)
51         self.duration = int(self.prox_config.get("duration", 5))
52         self.precision = float(self.prox_config.get('test_precision', 1.0))
53         self.tolerated_loss = float(self.prox_config.get('tolerated_loss', 0.0))
54
55         # TODO: is this ever a function of packet size?
56         self.lower_bound = float(self.prox_config.get('lower_bound', 10.0))
57         self.upper_bound = float(self.prox_config.get('upper_bound', 100.0))
58         self.step_value = float(self.prox_config.get('step_value', 10.0))
59
60     def init(self, queue):
61         self.pkt_size_iterator = iter(self.pkt_sizes)
62         self.queue = queue
63
64     def bounds_iterator(self, logger=None):
65         if logger:
66             logger.debug("Interval [%s, %s), step: %d", self.lower_bound,
67                          self.upper_bound, self.step_value)
68
69         test_value = self.lower_bound
70         while test_value <= self.upper_bound:
71             if logger:
72                 logger.info("Testing with value %s", test_value)
73             yield test_value
74             test_value += self.step_value
75
76     @property
77     def min_pkt_size(self):
78         """Return the minimum required packet size for the test.
79
80         Defaults to 64. Individual test must override this method if they have
81         other requirements.
82
83         Returns:
84             int. The minimum required packet size for the test.
85         """
86         return 64
87
88     def run_test_with_pkt_size(self, traffic_generator, pkt_size, duration):
89         raise NotImplementedError
90
91     def execute(self, traffic_generator):
92         try:
93             pkt_size = next(self.pkt_size_iterator)
94         except StopIteration:
95             self.done = True
96             return
97
98         # Adjust packet size upwards if it's less than the minimum
99         # required packet size for the test.
100         if pkt_size < self.min_pkt_size:
101             pkt_size += self.min_pkt_size - 64
102
103         duration = self.duration
104         self.run_test_with_pkt_size(traffic_generator, pkt_size, duration)