1 # Copyright 2016-2017 Spirent Communications, 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 """RFC2889 Traffic Controller implementation.
16 from core.traffic_controller import TrafficController
17 from core.results.results import IResults
18 from conf import settings
21 class TrafficControllerRFC2889(TrafficController, IResults):
22 """Traffic controller for RFC2889 traffic
24 Used to setup and control a traffic generator for an RFC2889 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().__init__(traffic_gen_class)
34 self._type = 'rfc2889'
37 def configure(self, traffic):
38 """See TrafficController for description
40 super().configure(traffic)
41 self._trials = int(settings.getValue('TRAFFICGEN_RFC2889_TRIALS'))
43 def send_traffic(self, traffic):
44 """See TrafficController for description
46 if not self.traffic_required():
49 super().send_traffic(traffic)
51 for packet_size in self._packet_sizes:
52 # Merge framesize with the default traffic definition
54 traffic['l2'] = dict(traffic['l2'],
55 **{'framesize': packet_size})
57 traffic['l2'] = {'framesize': packet_size}
59 if traffic['traffic_type'] == 'rfc2889_caching':
60 result = self._traffic_gen_class.send_rfc2889_caching(
61 traffic, tests=self._trials, duration=self._duration)
62 elif traffic['traffic_type'] == 'rfc2889_learning':
63 result = self._traffic_gen_class.send_rfc2889_learning(
64 traffic, tests=self._trials, duration=self._duration)
65 elif traffic['traffic_type'] == 'rfc2889_forwarding':
66 result = self._traffic_gen_class.send_rfc2889_forwarding(
67 traffic, tests=self._trials, duration=self._duration)
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():
78 super().send_traffic_async(traffic, function)
80 for packet_size in self._packet_sizes:
81 traffic['l2'] = {'framesize': packet_size}
82 self._traffic_gen_class.start_rfc2889_forwarding(
85 duration=self._duration)
86 self._traffic_started = True
88 function['function'](function['args'])
90 function['function']()
91 result = self._traffic_gen_class.wait_rfc2889_forwarding(
92 traffic, trials=self._trials, duration=self._duration)
93 result = self._append_results(result, packet_size)
94 self._results.append(result)