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.
19 from experimental_framework.benchmarks import benchmark_base_class as base
20 from experimental_framework.constants import framework_parameters as fp
21 from experimental_framework.constants import conf_file_sections as cfs
22 from experimental_framework.packet_generators import dpdk_packet_generator \
24 import experimental_framework.common as common
27 THROUGHPUT = 'throughput'
28 VLAN_SENDER = 'vlan_sender'
29 VLAN_RECEIVER = 'vlan_receiver'
30 PACKETS_FILE_NAME = 'packets.res'
31 PACKET_CHECKER_PROGRAM_NAME = 'test_sniff'
32 MULTICAST_GROUP = '224.192.16.1'
35 class InstantiationValidationBenchmark(base.BenchmarkBaseClass):
37 def __init__(self, name, params):
38 base.BenchmarkBaseClass.__init__(self, name, params)
39 self.base_dir = common.get_base_dir() + \
40 fp.EXPERIMENTAL_FRAMEWORK_DIR + fp.DPDK_PKTGEN_DIR
41 self.results_file = self.base_dir + PACKETS_FILE_NAME
42 self.lua_file = self.base_dir + 'constant_traffic.lua'
44 self.interface_name = ''
46 # Set the packet checker command
47 self.pkt_checker_command = common.get_base_dir()
48 self.pkt_checker_command += 'experimental_framework/libraries/'
49 self.pkt_checker_command += 'packet_checker/'
50 self.pkt_checker_command += PACKET_CHECKER_PROGRAM_NAME + ' '
54 Initialize the benchmark
61 Finalizes the benchmark
66 def get_features(self):
68 features['description'] = 'Instantiation Validation Benchmark'
69 features['parameters'] = [THROUGHPUT, VLAN_SENDER, VLAN_RECEIVER]
70 features['allowed_values'] = dict()
71 features['allowed_values'][THROUGHPUT] = map(str, range(0, 100))
72 features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096))
73 features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096))
74 features['default_values'] = dict()
75 features['default_values'][THROUGHPUT] = '1'
76 features['default_values'][VLAN_SENDER] = '-1'
77 features['default_values'][VLAN_RECEIVER] = '-1'
81 # Setup packet generator
84 traffic_rate_percentage = self.params[THROUGHPUT]
86 dpdk_pktgen_vars = common.get_dpdk_pktgen_vars()
87 # bus_address = dpdk_pktgen_vars[cfs.CFSP_DPDK_BUS_SLOT_NIC_2]
88 self.interface_name = dpdk_pktgen_vars[cfs.CFSP_DPDK_NAME_IF_2]
89 packetgen = dpdk.DpdkPacketGenerator()
90 self._configure_lua_file(traffic_rate_percentage, traffic_time)
91 packetgen.init_dpdk_pktgen(dpdk_interfaces=1,
92 pcap_file_0='packet_' + packet_size +
94 pcap_file_1='igmp.pcap',
95 lua_script='constant_traffic.lua',
96 vlan_0=self.params[VLAN_SENDER],
97 vlan_1=self.params[VLAN_RECEIVER])
99 self._init_packet_checker()
100 # Send constant traffic at a specified rate
101 common.LOG.debug('Start the packet generator')
102 packetgen.send_traffic()
103 common.LOG.debug('Stop the packet generator')
105 self._finalize_packet_checker()
106 self._reset_lua_file(traffic_rate_percentage, traffic_time)
107 return self._get_results()
109 def _configure_lua_file(self, traffic_rate_percentage, traffic_time):
111 Configure the packet gen to write the results into the right file
114 common.replace_in_file(self.lua_file, 'local out_file = ""',
115 'local out_file = "' +
116 self.results_file + '"')
117 common.replace_in_file(self.lua_file, 'local traffic_rate = 0',
118 'local traffic_rate = ' +
119 traffic_rate_percentage)
120 common.replace_in_file(self.lua_file, 'local traffic_delay = 0',
121 'local traffic_delay = ' + traffic_time)
123 def _reset_lua_file(self, traffic_rate_percentage, traffic_time):
125 Configure the packet gen to write the results into the right file
126 :param traffic_rate_percentage:
131 common.replace_in_file(self.lua_file, 'local out_file = "' +
132 self.results_file + '"',
133 'local out_file = ""')
134 common.replace_in_file(self.lua_file, 'local traffic_rate = ' +
135 traffic_rate_percentage,
136 'local traffic_rate = 0')
137 common.replace_in_file(self.lua_file, 'local traffic_delay = ' +
138 traffic_time, 'local traffic_delay = 0')
140 def _get_results(self):
142 packet_checker_res = 0
144 packet_checker_res = \
145 int(common.get_file_first_line(self.res_dir +
146 '/packet_checker.res'))
147 pkt_gen_res = int(common.get_file_first_line(self.results_file))
148 if pkt_gen_res <= packet_checker_res or \
149 (float(pkt_gen_res - packet_checker_res) / pkt_gen_res) <= 0.1:
150 ret_val['failure'] = '0'
152 ret_val['failure'] = '1'
155 def _init_packet_checker(self):
157 Sets up the multicast and starts the packet checker
160 # Kill any other process running from previous failed execution
161 self.res_dir = os.getcwd()
162 pids = self._get_pids()
164 os.kill(pid, signal.SIGTERM)
166 # initialization of the VLAN interface
167 command = "ip link add link "
168 command += self.interface_name
170 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
171 command += " type vlan id " + self.params[VLAN_RECEIVER]
172 common.run_command(command)
175 command = 'ifconfig ' + self.interface_name + '.' + \
176 self.params[VLAN_RECEIVER]
177 # An IP address is required for the interface to receive a multicast
178 # flow. The specific address is not important
179 command += ' 10.254.254.254 up'
180 common.run_command(command)
183 command = "echo 'mgroup from "
184 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
186 command += MULTICAST_GROUP
187 command += "' > /etc/smcroute.conf"
188 common.run_command(command)
190 # run smcroute on the interface
191 command = 'smcroute -d'
192 common.run_command(command)
194 # Start the packet checker
195 command = self.pkt_checker_command
196 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
199 common.run_command(command)
201 def _finalize_packet_checker(self):
203 Obtains the PID of the packet checker and sends an alarm to
207 pids = self._get_pids()
209 os.kill(pid, signal.SIGTERM)
211 # stop smcroute on the interface
212 command = 'smcroute -k'
213 common.run_command(command)
215 # finalization of the VLAN interface
216 command = "ip link delete "
217 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
218 common.run_command(command)
222 Returns a list of integers containing the pid or the pids of the
223 processes currently running on the host
224 :return: type: list of int
226 output = commands.getoutput("ps -ef |pgrep " +
227 PACKET_CHECKER_PROGRAM_NAME)
231 pids = map(int, output.split('\n'))