bugfix: Trafficgen Ixia does not work
[vswitchperf.git] / core / traffic_controller_rfc2889.py
1 # Copyright 2016 Spirent Communications, 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 """RFC2889 Traffic Controller implementation.
15 """
16 from core.traffic_controller import TrafficController
17 from core.results.results import IResults
18 from conf import get_test_param
19
20
21 class TrafficControllerRFC2889(TrafficController, IResults):
22     """Traffic controller for RFC2889 traffic
23
24     Used to setup and control a traffic generator for an RFC2889 deployment
25     traffic scenario.
26     """
27
28     def __init__(self, traffic_gen_class):
29         """Initialise the trafficgen and store.
30
31         :param traffic_gen_class: The traffic generator class to be used.
32         """
33         super(TrafficControllerRFC2889, self).__init__(traffic_gen_class)
34         self._type = 'rfc2889'
35         self._trials = int(get_test_param('rfc2889_trials', 1))
36
37     def send_traffic(self, traffic):
38         """See TrafficController for description
39         """
40         if not self.traffic_required():
41             return
42         self._logger.debug('send_traffic with ' +
43                            str(self._traffic_gen_class))
44
45         for packet_size in self._packet_sizes:
46             # Merge framesize with the default traffic definition
47             if 'l2' in traffic:
48                 traffic['l2'] = dict(traffic['l2'],
49                                      **{'framesize': packet_size})
50             else:
51                 traffic['l2'] = {'framesize': packet_size}
52
53             if traffic['traffic_type'] == 'caching':
54                 result = self._traffic_gen_class.send_rfc2889_caching(
55                     traffic, trials=self._trials, duration=self._duration)
56             elif traffic['traffic_type'] == 'congestion':
57                 result = self._traffic_gen_class.send_rfc2889_congestion(
58                     traffic, duration=self._duration)
59             else:
60                 result = self._traffic_gen_class.send_rfc2889_forwarding(
61                     traffic, tests=self._trials, duration=self._duration)
62
63             result = self._append_results(result, packet_size)
64             self._results.append(result)
65
66     def send_traffic_async(self, traffic, function):
67         """See TrafficController for description
68         """
69         if not self.traffic_required():
70             return
71         self._logger.debug('send_traffic_async with ' +
72                            str(self._traffic_gen_class))
73
74         for packet_size in self._packet_sizes:
75             traffic['l2'] = {'framesize': packet_size}
76             self._traffic_gen_class.start_rfc2889_forwarding(
77                 traffic,
78                 trials=self._trials,
79                 duration=self._duration)
80             self._traffic_started = True
81             if len(function['args']) > 0:
82                 function['function'](function['args'])
83             else:
84                 function['function']()
85             result = self._traffic_gen_class.wait_rfc2889_forwarding(
86                         traffic, trials=self._trials, duration=self._duration)
87             result = self._append_results(result, packet_size)
88             self._results.append(result)
89