2 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from experimental_framework.benchmarks import benchmark_base_class
17 from experimental_framework.packet_generators \
18 import dpdk_packet_generator as dpdk
19 import experimental_framework.common as common
20 from experimental_framework.constants import framework_parameters as fp
23 PACKET_SIZE = 'packet_size'
24 VLAN_SENDER = 'vlan_sender'
25 VLAN_RECEIVER = 'vlan_receiver'
28 class RFC2544ThroughputBenchmark(benchmark_base_class.BenchmarkBaseClass):
30 Calculates the throughput of the VNF under test according to the RFC2544.
33 def __init__(self, name, params):
34 benchmark_base_class.BenchmarkBaseClass.__init__(self, name, params)
35 self.base_dir = common.get_base_dir() + \
36 fp.EXPERIMENTAL_FRAMEWORK_DIR + fp.DPDK_PKTGEN_DIR
37 self.results_file = self.base_dir + 'experiment.res'
38 self.lua_file = self.base_dir + 'rfc2544.lua'
42 Initialize the benchmark
53 def get_features(self):
55 Returns the features associated to the benchmark
59 features['description'] = 'RFC 2544 Throughput calculation'
60 features['parameters'] = [PACKET_SIZE, VLAN_SENDER, VLAN_RECEIVER]
61 features['allowed_values'] = dict()
62 features['allowed_values'][PACKET_SIZE] = ['64', '128', '256', '512',
63 '1024', '1280', '1514']
64 features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096))
65 features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096))
66 features['default_values'] = dict()
67 features['default_values'][PACKET_SIZE] = '1280'
68 features['default_values'][VLAN_SENDER] = '1007'
69 features['default_values'][VLAN_RECEIVER] = '1006'
74 Sends and receive traffic according to the RFC methodology in order
75 to measure the throughput of the workload
76 :return: Results of the testcase (type: dict)
78 packet_size = self._extract_packet_size_from_params()
80 # Packetgen management
81 packetgen = dpdk.DpdkPacketGenerator()
82 self._configure_lua_file()
83 packetgen.init_dpdk_pktgen(dpdk_interfaces=2,
84 pcap_file_0='packet_' +
85 packet_size + '.pcap',
86 pcap_file_1='igmp.pcap',
87 lua_script='rfc2544.lua',
88 vlan_0=self.params[VLAN_SENDER],
89 vlan_1=self.params[VLAN_RECEIVER])
90 common.LOG.debug('Start the packet generator - packet size: ' +
92 packetgen.send_traffic()
93 common.LOG.debug('Stop the packet generator')
95 return self._get_results()
97 def _extract_packet_size_from_params(self):
99 Extracts packet sizes from parameters
100 :return: packet_sizes (list)
102 packet_size = '1280' # default value
103 if PACKET_SIZE in self.params.keys() and \
104 isinstance(self.params[PACKET_SIZE], str):
105 packet_size = self.params[PACKET_SIZE]
108 def _configure_lua_file(self):
110 Configure the packet gen to write the results into the right file
113 common.replace_in_file(self.lua_file, 'local out_file = ""',
114 'local out_file = "' +
115 self.results_file + '"')
117 def _reset_lua_file(self):
119 Sets back the configuration of the local file var to the default
122 common.replace_in_file(self.lua_file, 'local out_file = "' +
123 self.results_file + '"',
124 'local out_file = ""')
126 def _get_results(self):
128 Returns the results of the experiment
131 throughput = common.get_file_first_line(self.results_file)
134 ret_val['throughput'] = int(throughput)
136 ret_val['throughput'] = 0