1 # Copyright 2015 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 """Abstract "traffic generator" model.
16 This is an abstract class for traffic generators.
19 #TODO update Back2Back method description when Result implementation will
22 from tools.pkt_gen.trafficgen.trafficgenhelper import TRAFFIC_DEFAULTS
24 class ITrafficGenerator(object):
25 """Model of a traffic generator device.
27 _traffic_defaults = TRAFFIC_DEFAULTS.copy()
30 def traffic_defaults(self):
31 """Default traffic values.
33 These can be expected to be constant across traffic generators,
34 so no setter is provided. Changes to the structure or contents
35 will likely break traffic generator implementations or tests
38 return self._traffic_defaults
41 """Connect to the traffic generator.
43 Provide a context manager interface to the traffic generators.
44 This simply calls the :func:`connect` function.
48 def __exit__(self, type_, value, traceback):
49 """Disconnect from the traffic generator.
51 Provide a context manager interface to the traffic generators.
52 This simply calls the :func:`disconnect` function.
57 """Connect to the traffic generator.
59 This is an optional function, designed for traffic generators
60 which must be "connected to" (i.e. via SSH or an API) before
61 they can be used. If not required, simply do nothing here.
63 Where implemented, this function should raise an exception on
68 raise NotImplementedError('Please call an implementation.')
71 """Disconnect from the traffic generator.
73 As with :func:`connect`, this function is optional.
75 Where implemented, this function should raise an exception on
80 raise NotImplementedError('Please call an implementation.')
82 def send_burst_traffic(self, traffic=None, numpkts=100, duration=20):
83 """Send a burst of traffic.
85 Send a ``numpkts`` packets of traffic, using ``traffic``
86 configuration, for ``duration`` seconds.
89 :param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
90 :param numpkts: Number of packets to send
91 :param duration: Time to wait to receive packets
93 :returns: dictionary of strings with following data:
97 - List of List of Rx Bytes,
98 - Payload Errors and Sequence Errors.
100 raise NotImplementedError('Please call an implementation.')
102 def send_cont_traffic(self, traffic=None, duration=20, multistream=False):
103 """Send a continuous flow of traffic.
105 Send packets at given framerate, using ``traffic`` configuration,
106 for ``duration`` seconds..
108 :param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
110 :param duration: Duration to transmit traffic.
111 :param multistream: Enable multistream output by overriding the
113 :returns: dictionary of strings with following data:
114 - Tx Throughput (fps),
115 - Rx Throughput (fps),
116 - Tx Throughput (mbps),
117 - Rx Throughput (mbps),
118 - Tx Throughput (% linerate),
119 - Rx Throughput (% linerate),
124 raise NotImplementedError('Please call an implementation.')
126 def start_cont_traffic(self, traffic=None, duration=30):
127 """Non-blocking version of 'send_cont_traffic'.
129 Start transmission and immediately return. Do not wait for
132 raise NotImplementedError('Please call an implementation.')
134 def stop_cont_traffic(self):
135 """Stop continuous transmission and return results.
137 raise NotImplementedError('Please call an implementation.')
139 def send_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
140 lossrate=0.0, multistream=False):
141 """Send traffic per RFC2544 throughput test specifications.
143 Send packets at a variable rate, using ``traffic``
144 configuration, until minimum rate at which no packet loss is
147 :param traffic: Detailed "traffic" spec, i.e. IP address, VLAN tags
148 :param trials: Number of trials to execute
149 :param duration: Per iteration duration
150 :param lossrate: Acceptable lossrate percentage
151 :param multistream: Enable multistream output by overriding the
152 UDP port number in ``traffic`` with values
154 :returns: dictionary of strings with following data:
155 - Tx Throughput (fps),
156 - Rx Throughput (fps),
157 - Tx Throughput (mbps),
158 - Rx Throughput (mbps),
159 - Tx Throughput (% linerate),
160 - Rx Throughput (% linerate),
165 raise NotImplementedError('Please call an implementation.')
167 def start_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
169 """Non-blocking version of 'send_rfc2544_throughput'.
171 Start transmission and immediately return. Do not wait for
174 raise NotImplementedError('Please call an implementation.')
176 def wait_rfc2544_throughput(self):
177 """Wait for and return results of RFC2544 test.
179 raise NotImplementedError('Please call an implementation.')
181 def send_rfc2544_back2back(self, traffic=None, trials=1, duration=20,
183 """Send traffic per RFC2544 back2back test specifications.
185 Send packets at a fixed rate, using ``traffic``
186 configuration, for duration seconds.
188 :param traffic: Detailed "traffic" spec, i.e. IP address, VLAN
190 :param trials: Number of trials to execute
191 :param duration: Per iteration duration
192 :param lossrate: Acceptable loss percentage
193 :param multistream: Enable multistream output by overriding the
194 UDP port number in ``traffic`` with values from 1 to 64,000
196 :returns: Named tuple of Rx Throughput (fps), Rx Throughput (mbps),
197 Tx Rate (% linerate), Rx Rate (% linerate), Tx Count (frames),
198 Back to Back Count (frames), Frame Loss (frames), Frame Loss (%)
199 :rtype: :class:`Back2BackResult`
201 raise NotImplementedError('Please call an implementation.')
203 def start_rfc2544_back2back(self, traffic=None, trials=1, duration=20,
205 """Non-blocking version of 'send_rfc2544_back2back'.
207 Start transmission and immediately return. Do not wait for
210 raise NotImplementedError('Please call an implementation.')
212 def wait_rfc2544_back2back(self):
213 """Wait and set results of RFC2544 test.
215 raise NotImplementedError('Please call an implementation.')