1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
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.
15 from experimental_framework.benchmarks import benchmark_base_class
16 from experimental_framework.packet_generators \
17 import dpdk_packet_generator as dpdk
18 import experimental_framework.common as common
19 from experimental_framework.constants import framework_parameters as fp
22 PACKET_SIZE = 'packet_size'
23 VLAN_SENDER = 'vlan_sender'
24 VLAN_RECEIVER = 'vlan_receiver'
27 class RFC2544ThroughputBenchmark(benchmark_base_class.BenchmarkBaseClass):
29 Calculates the throughput of the VNF under test according to the RFC2544.
32 def __init__(self, name, params):
33 benchmark_base_class.BenchmarkBaseClass.__init__(self, name, params)
34 self.base_dir = common.get_base_dir() + \
35 fp.EXPERIMENTAL_FRAMEWORK_DIR + fp.DPDK_PKTGEN_DIR
36 self.results_file = self.base_dir + 'experiment.res'
37 self.lua_file = self.base_dir + 'rfc2544.lua'
41 Initialize the benchmark
52 def get_features(self):
54 Returns the features associated to the benchmark
58 features['description'] = 'RFC 2544 Throughput calculation'
59 features['parameters'] = [PACKET_SIZE, VLAN_SENDER, VLAN_RECEIVER]
60 features['allowed_values'] = dict()
61 features['allowed_values'][PACKET_SIZE] = ['64', '128', '256', '512',
62 '1024', '1280', '1514']
63 features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096))
64 features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096))
65 features['default_values'] = dict()
66 features['default_values'][PACKET_SIZE] = '1280'
67 features['default_values'][VLAN_SENDER] = '1007'
68 features['default_values'][VLAN_RECEIVER] = '1006'
73 Sends and receive traffic according to the RFC methodology in order
74 to measure the throughput of the workload
75 :return: Results of the testcase (type: dict)
78 packet_size = self._extract_packet_size_from_params()
79 ret_val[PACKET_SIZE] = packet_size
81 # Packetgen management
82 packetgen = dpdk.DpdkPacketGenerator()
83 self._configure_lua_file()
84 packetgen.init_dpdk_pktgen(dpdk_interfaces=2,
85 pcap_file_0='packet_' +
86 packet_size + '.pcap',
87 pcap_file_1='igmp.pcap',
88 lua_script='rfc2544.lua',
89 vlan_0=self.params[VLAN_SENDER],
90 vlan_1=self.params[VLAN_RECEIVER])
91 common.LOG.debug('Start the packet generator - packet size: ' +
93 packetgen.send_traffic()
94 common.LOG.debug('Stop the packet generator')
97 results = self._get_results()
98 for metric_name in results.keys():
99 ret_val[metric_name] = results[metric_name]
100 self._reset_lua_file()
103 def _extract_packet_size_from_params(self):
105 Extracts packet sizes from parameters
106 :return: packet_sizes (list)
108 packet_size = '1280' # default value
109 if PACKET_SIZE in self.params.keys() and \
110 isinstance(self.params[PACKET_SIZE], str):
111 packet_size = self.params[PACKET_SIZE]
114 def _configure_lua_file(self):
116 Configure the packet gen to write the results into the right file
119 common.replace_in_file(self.lua_file, 'local out_file = ""',
120 'local out_file = "' +
121 self.results_file + '"')
123 def _reset_lua_file(self):
125 Sets back the configuration of the local file var to the default
128 common.replace_in_file(self.lua_file, 'local out_file = "' +
129 self.results_file + '"',
130 'local out_file = ""')
132 def _get_results(self):
134 Returns the results of the experiment
137 throughput = common.get_file_first_line(self.results_file)
140 ret_val['throughput'] = int(throughput)
142 ret_val['throughput'] = 0