1 ===================================
2 Traffic Generator Integration Guide
3 ===================================
8 This document is intended to aid those who want to integrate new traffic
9 generator into the vsperf code. It is expected, that reader has already
10 read generic part of `VSPERF Design Document
11 <http://artifacts.opnfv.org/vswitchperf/docs/design/index.html>`__.
13 Let us create a sample traffic generator called **sample_tg**, step by step.
15 Step 1 - create a directory
16 ===========================
18 Implementation of trafficgens is located at tools/pkt_gen/ directory,
19 where every implementation has its dedicated sub-directory. It is
20 required to create a new directory for new traffic generator
25 .. code-block:: console
27 $ mkdir tools/pkt_gen/sample_tg
29 Step 2 - create a trafficgen module
30 ===================================
32 Every trafficgen class must inherit from generic **ITrafficGenerator**
33 interface class. VSPERF during its initialization scans content of pkt_gen
34 directory for all python modules, that inherit from **ITrafficGenerator**. These
35 modules are automatically added into the list of supported traffic generators.
39 Let us create a draft of tools/pkt_gen/sample_tg/sample_tg.py module.
41 .. code-block:: python
43 from tools.pkt_gen import trafficgen
45 class SampleTG(trafficgen.ITrafficGenerator):
47 A sample traffic generator implementation
51 VSPERF is immediately aware of the new class:
53 .. code-block:: console
55 $ ./vsperf --list-trafficgen
57 Output should look like:
59 .. code-block:: console
61 Classes derived from: ITrafficGenerator
64 * Ixia: A wrapper around the IXIA traffic generator.
66 * IxNet: A wrapper around IXIA IxNetwork applications.
68 * Dummy: A dummy traffic generator whose data is generated by the user.
70 * SampleTG: A sample traffic generator implementation
72 * TestCenter: Spirent TestCenter
75 Step 3 - configuration
76 ======================
78 All configuration values, required for correct traffic generator function, are passed
79 from VSPERF to the traffic generator in a dictionary. Default values shared among
80 all traffic generators are defined in **tools/pkt_gen/trafficgen/trafficgenhelper.py**
81 as **TRAFFIC_DEFAULTS** dictionary. Default values are loaded by **ITrafficGenerator**
82 interface class automatically, so it is not needed to load them explicitly. In case
83 that there are any traffic generator specific default values, then they should
84 be set within class specific **__init__** function.
86 VSPERF passes test specific configuration within **traffic** dictionary to every
87 start and send function. So implementation of these functions must ensure,
88 that default values are updated with the testcase specific values. Proper merge
89 of values is assured by call of **merge_spec** function from **trafficgenhelper**
92 Example of **merge_spec** usage in **tools/pkt_gen/sample_tg/sample_tg.py** module:
94 .. code-block:: python
96 from tools.pkt_gen.trafficgen.trafficgenhelper import merge_spec
98 def start_rfc2544_throughput(self, traffic=None, duration=30):
100 self._params['traffic'] = self.traffic_defaults.copy()
102 self._params['traffic'] = trafficgen.merge_spec(
103 self._params['traffic'], traffic)
106 Step 4 - generic functions
107 ==========================
109 There are some generic functions, which every traffic generator should provide.
110 Although these functions are mainly optional, at least empty implementation must
111 be provided. This is required, so that developer is explicitly aware of these
114 The **connect** function is called from the traffic generator controller from its
115 **__enter__** method. This function should assure proper connection initialization
116 between DUT and traffic generator. In case, that such implementation is not needed,
117 empty implementation is required.
119 The **disconnect** function should perform clean up of any connection specific
120 actions called from the **connect** function.
122 Example in **tools/pkt_gen/sample_tg/sample_tg.py** module:
124 .. code-block:: python
129 def disconnect(self):
132 Step 5 - supported traffic types
133 ================================
135 Currently VSPERF supports three different types of tests for traffic generators,
136 these are identified in vsperf through the traffic type, which include:
138 * RFC2544 throughput - Send fixed size packets at different rates, using
139 traffic configuration, until minimum rate at which no packet loss is
140 detected is found. Methods with its implementation have suffix
141 **_rfc2544_throughput**.
143 * RFC2544 back2back - Send fixed size packets at a fixed rate, using traffic
144 configuration, for specified time interval. Methods with its
145 implementation have suffix **_rfc2544_back2back**.
147 * continuous flow - Send fixed size packets at given framerate, using traffic
148 configuration, for specified time interval. Methods with its
149 implementation have suffix **_cont_traffic**.
151 In general, both synchronous and asynchronous interfaces must be implemented
152 for each traffic type. Synchronous functions start with prefix **send_**.
153 Asynchronous with prefixes **start_** and **wait_** in case of throughput
154 and back2back and **start_** and **stop_** in case of continuous traffic type.
156 Example of synchronous interfaces:
158 .. code-block:: python
160 def send_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
161 lossrate=0.0, multistream=False):
162 def send_rfc2544_back2back(self, traffic=None, trials=1, duration=20,
164 def send_cont_traffic(self, traffic=None, duration=20, multistream=False):
166 Example of asynchronous interfaces:
168 .. code-block:: python
170 def start_rfc2544_throughput(self, traffic=None, trials=3, duration=20,
172 def wait_rfc2544_throughput(self):
174 def start_rfc2544_back2back(self, traffic=None, trials=1, duration=20,
176 def wait_rfc2544_back2back(self):
178 def start_cont_traffic(self, traffic=None, duration=20, multistream=False):
179 def stop_cont_traffic(self):
181 Description of parameters used by **send**, **start**, **wait** and **stop**
184 * param **trials**: Number of trials to execute
185 * param **duration**: Duration of continuous test or per iteration duration
186 in case of RFC2544 throughput or back2back traffic types.
187 * param **lossrate**: Acceptable lossrate percentage.
188 * param **multistream**: Enable or disable multistream feature.
190 Step 6 - passing back results
191 =============================
193 It is expected that methods **send**, **wait** and **stop** will return
194 values measured by traffic generator within a dictionary. Dictionary keys
195 are defined in **ResultsConstants** implemented in
196 **core/results/results_constants.py**. Please check sections for RFC2544
197 Throughput & Continuous and for Back2Back. The same key names should
198 be used by all traffic generator implementations.