1 # Copyright 2015-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 """RFC2544 Traffic Controller implementation.
16 from core.traffic_controller import TrafficController
17 from core.results.results import IResults
18 from conf import settings
21 class TrafficControllerRFC2544(TrafficController, IResults):
22 """Traffic controller for RFC2544 traffic
24 Used to setup and control a traffic generator for an RFC2544 deployment
28 def __init__(self, traffic_gen_class):
29 """Initialise the trafficgen and store.
31 :param traffic_gen_class: The traffic generator class to be used.
33 super(TrafficControllerRFC2544, self).__init__(traffic_gen_class)
34 self._type = 'rfc2544'
35 self._tests = int(settings.getValue('TRAFFICGEN_RFC2544_TESTS'))
37 def send_traffic(self, traffic):
38 """See TrafficController for description
40 if not self.traffic_required():
42 self._logger.debug('send_traffic with ' +
43 str(self._traffic_gen_class))
45 # update type with detailed traffic value
46 self._type = traffic['traffic_type']
48 for packet_size in self._packet_sizes:
49 # Merge framesize with the default traffic definition
51 traffic['l2'] = dict(traffic['l2'],
52 **{'framesize': packet_size})
54 traffic['l2'] = {'framesize': packet_size}
56 if traffic['traffic_type'] == 'rfc2544_back2back':
57 result = self._traffic_gen_class.send_rfc2544_back2back(
58 traffic, tests=self._tests, duration=self._duration, lossrate=self._lossrate)
59 elif traffic['traffic_type'] == 'rfc2544_continuous':
60 result = self._traffic_gen_class.send_cont_traffic(
61 traffic, duration=self._duration)
62 elif traffic['traffic_type'] == 'rfc2544_throughput':
63 result = self._traffic_gen_class.send_rfc2544_throughput(
64 traffic, tests=self._tests, duration=self._duration, lossrate=self._lossrate)
66 raise RuntimeError("Unsupported traffic type {} was "
67 "detected".format(traffic['traffic_type']))
69 result = self._append_results(result, packet_size)
70 self._results.append(result)
72 def send_traffic_async(self, traffic, function):
73 """See TrafficController for description
75 if not self.traffic_required():
77 self._logger.debug('send_traffic_async with ' +
78 str(self._traffic_gen_class))
80 # update type with detailed traffic value
81 self._type = traffic['traffic_type']
83 for packet_size in self._packet_sizes:
84 traffic['l2'] = {'framesize': packet_size}
85 self._traffic_gen_class.start_rfc2544_throughput(
88 duration=self._duration)
89 self._traffic_started = True
90 if len(function['args']) > 0:
91 function['function'](function['args'])
93 function['function']()
94 result = self._traffic_gen_class.wait_rfc2544_throughput()
95 result = self._append_results(result, packet_size)
96 self._results.append(result)