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 __future__ import absolute_import
21 from experimental_framework.benchmarks import benchmark_base_class as base
22 from experimental_framework.constants import framework_parameters as fp
23 from experimental_framework.constants import conf_file_sections as cfs
24 from experimental_framework.packet_generators import dpdk_packet_generator \
26 import experimental_framework.common as common
27 from six.moves import range
30 THROUGHPUT = 'throughput'
31 VLAN_SENDER = 'vlan_sender'
32 VLAN_RECEIVER = 'vlan_receiver'
33 PACKETS_FILE_NAME = 'packets.res'
34 PACKET_CHECKER_PROGRAM_NAME = 'test_sniff'
35 MULTICAST_GROUP = '224.192.16.1'
38 class InstantiationValidationBenchmark(base.BenchmarkBaseClass):
40 def __init__(self, name, params):
41 base.BenchmarkBaseClass.__init__(self, name, params)
42 self.base_dir = os.path.join(
43 common.get_base_dir(), fp.EXPERIMENTAL_FRAMEWORK_DIR,
45 self.results_file = self.base_dir + PACKETS_FILE_NAME
46 self.lua_file = self.base_dir + 'constant_traffic.lua'
48 self.interface_name = ''
50 # Set the packet checker command
51 self.pkt_checker_command = os.path.join(
52 common.get_base_dir(),
53 'experimental_framework/libraries/',
55 PACKET_CHECKER_PROGRAM_NAME + ' ')
59 Initialize the benchmark
66 Finalizes the benchmark
71 def get_features(self):
73 features['description'] = 'Instantiation Validation Benchmark'
74 features['parameters'] = [THROUGHPUT, VLAN_SENDER, VLAN_RECEIVER]
75 features['allowed_values'] = dict()
76 features['allowed_values'][THROUGHPUT] = [str(x) for x in range(100)]
77 features['allowed_values'][VLAN_SENDER] = [str(x) for x in
79 features['allowed_values'][VLAN_RECEIVER] = [str(x)
80 for x in range(-1, 4096)]
81 features['default_values'] = dict()
82 features['default_values'][THROUGHPUT] = '1'
83 features['default_values'][VLAN_SENDER] = '-1'
84 features['default_values'][VLAN_RECEIVER] = '-1'
88 # Setup packet generator
91 traffic_rate_percentage = self.params[THROUGHPUT]
93 dpdk_pktgen_vars = common.get_dpdk_pktgen_vars()
94 # bus_address = dpdk_pktgen_vars[cfs.CFSP_DPDK_BUS_SLOT_NIC_2]
95 self.interface_name = dpdk_pktgen_vars[cfs.CFSP_DPDK_NAME_IF_2]
96 packetgen = dpdk.DpdkPacketGenerator()
97 self._configure_lua_file(traffic_rate_percentage, traffic_time)
98 packetgen.init_dpdk_pktgen(dpdk_interfaces=1,
99 pcap_file_0='packet_' + packet_size +
101 pcap_file_1='igmp.pcap',
102 lua_script='constant_traffic.lua',
103 vlan_0=self.params[VLAN_SENDER],
104 vlan_1=self.params[VLAN_RECEIVER])
106 self._init_packet_checker()
107 # Send constant traffic at a specified rate
108 common.LOG.debug('Start the packet generator')
109 packetgen.send_traffic()
110 common.LOG.debug('Stop the packet generator')
112 self._finalize_packet_checker()
113 self._reset_lua_file(traffic_rate_percentage, traffic_time)
114 return self._get_results()
116 def _configure_lua_file(self, traffic_rate_percentage, traffic_time):
118 Configure the packet gen to write the results into the right file
121 common.replace_in_file(self.lua_file, 'local out_file = ""',
122 'local out_file = "' +
123 self.results_file + '"')
124 common.replace_in_file(self.lua_file, 'local traffic_rate = 0',
125 'local traffic_rate = ' +
126 traffic_rate_percentage)
127 common.replace_in_file(self.lua_file, 'local traffic_delay = 0',
128 'local traffic_delay = ' + traffic_time)
130 def _reset_lua_file(self, traffic_rate_percentage, traffic_time):
132 Configure the packet gen to write the results into the right file
133 :param traffic_rate_percentage:
138 common.replace_in_file(self.lua_file, 'local out_file = "' +
139 self.results_file + '"',
140 'local out_file = ""')
141 common.replace_in_file(self.lua_file, 'local traffic_rate = ' +
142 traffic_rate_percentage,
143 'local traffic_rate = 0')
144 common.replace_in_file(self.lua_file, 'local traffic_delay = ' +
145 traffic_time, 'local traffic_delay = 0')
147 def _get_results(self):
149 packet_checker_res = 0
151 packet_checker_res = \
152 int(common.get_file_first_line(self.res_dir +
153 'packet_checker.res'))
154 pkt_gen_res = int(common.get_file_first_line(self.results_file))
155 if pkt_gen_res <= packet_checker_res or \
156 (float(pkt_gen_res - packet_checker_res) / pkt_gen_res) <= 0.1:
157 ret_val['failure'] = '0'
159 ret_val['failure'] = '1'
162 def _init_packet_checker(self):
164 Sets up the multicast and starts the packet checker
167 # Kill any other process running from previous failed execution
168 self.res_dir = common.get_result_dir()
169 pids = self._get_pids()
171 # os.kill(pid, signal.SIGTERM)
172 command = 'sudo kill ' + str(pid)
173 common.run_command(command)
175 # initialization of the VLAN interface
176 command = "sudo ip link add link "
177 command += self.interface_name
179 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
180 command += " type vlan id " + self.params[VLAN_RECEIVER]
181 common.run_command(command)
184 command = 'sudo ifconfig ' + self.interface_name + '.' + \
185 self.params[VLAN_RECEIVER]
186 # An IP address is required for the interface to receive a multicast
187 # flow. The specific address is not important
188 command += ' 10.254.254.254 up netmask 255.255.255.248'
189 common.run_command(command)
191 command = "sudo ifconfig "
192 command += self.interface_name + "." + self.params[VLAN_RECEIVER]
193 command += " promisc"
194 common.run_command(command)
197 command = "sudo echo 'mgroup from "
198 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
200 command += MULTICAST_GROUP
201 command += "' > /etc/smcroute.conf"
202 common.run_command(command)
204 # run smcroute on the interface
205 command = 'sudo smcroute -d'
206 common.run_command(command)
209 # Start the packet checker
210 current_dir = os.path.dirname(os.path.realpath(__file__))
211 dir_list = self.pkt_checker_command.split('/')
212 directory = os.pathsep.join(dir_list[0:len(dir_list) - 1])
215 common.run_command(command)
216 os.chdir(current_dir)
218 command = "sudo chmod +x {}".format(self.pkt_checker_command)
219 common.run_command(command)
221 command = 'sudo ' + self.pkt_checker_command
222 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
225 common.run_command(command)
227 def _finalize_packet_checker(self):
229 Obtains the PID of the packet checker and sends an alarm to
233 pids = self._get_pids()
235 # os.kill(pid, signal.SIGTERM)
236 command = 'sudo kill ' + str(pid)
237 common.run_command(command)
239 # stop smcroute on the interface
240 command = 'sudo smcroute -k'
241 common.run_command(command)
243 # finalization of the VLAN interface
244 command = "sudo ip link delete "
245 command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
246 common.run_command(command)
250 Returns a list of integers containing the pid or the pids of the
251 processes currently running on the host
252 :return: type: list of int
254 output = subprocess.check_output(
255 'pgrep "{}"'.format(PACKET_CHECKER_PROGRAM_NAME))
259 pids = [int(x) for x in output.splitlines()]