summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rwxr-xr-xci/yardstick-verify13
-rw-r--r--tests/unit/cmd/__init__.py0
-rw-r--r--tests/unit/cmd/commands/__init__.py0
-rw-r--r--tests/unit/cmd/commands/test_task.py38
-rwxr-xr-xyardstick/cmd/commands/task.py16
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py19
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py31
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py336
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_pktgen/constant_traffic.lua74
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/igmp.pcapbin0 -> 172 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1024.pcapbin0 -> 1064 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_128.pcapbin0 -> 168 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1280.pcapbin0 -> 1320 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1514.pcapbin0 -> 1632 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1518.pcapbin0 -> 1558 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_256.pcapbin0 -> 295 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_512.pcapbin0 -> 553 bytes
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_64.pcapbin0 -> 104 bytes
-rwxr-xr-xyardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/vlan_tag.sh6
-rw-r--r--yardstick/vTC/apexlake/tests/base_packet_generator_test.py29
-rw-r--r--yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py705
22 files changed, 1269 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 5614ae866..162687f8d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,6 @@ pep8.log
test.log
.testrepository/
cover/
+.*.sw?
+/output/
+/releng/
diff --git a/ci/yardstick-verify b/ci/yardstick-verify
index be1c1250e..1b045cdd3 100755
--- a/ci/yardstick-verify
+++ b/ci/yardstick-verify
@@ -76,6 +76,8 @@ cleanup()
echo "Deleting image $image..."
glance image-delete $image || true
done
+
+ nova flavor-delete yardstick-flavor &> /dev/null || true
}
exitcode=""
@@ -122,6 +124,16 @@ build_yardstick_image()
fi
}
+create_nova_flavor()
+{
+ if ! nova flavor-list | grep -q yardstick-flavor; then
+ echo
+ echo "========== Create nova flavor =========="
+ # Create the nova flavor used by some sample test cases
+ nova flavor-create yardstick-flavor 100 512 3 1
+ fi
+}
+
load_cirros_image()
{
echo
@@ -291,6 +303,7 @@ main()
build_yardstick_image
load_yardstick_image
load_cirros_image
+ create_nova_flavor
run_test
}
diff --git a/tests/unit/cmd/__init__.py b/tests/unit/cmd/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/cmd/__init__.py
diff --git a/tests/unit/cmd/commands/__init__.py b/tests/unit/cmd/commands/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/cmd/commands/__init__.py
diff --git a/tests/unit/cmd/commands/test_task.py b/tests/unit/cmd/commands/test_task.py
new file mode 100644
index 000000000..89813cb98
--- /dev/null
+++ b/tests/unit/cmd/commands/test_task.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.cmd.commands.task
+
+import mock
+import unittest
+
+from yardstick.cmd.commands import task
+
+
+class TaskCommandsTestCase(unittest.TestCase):
+
+ @mock.patch('yardstick.cmd.commands.task.Context')
+ def test_parse_nodes_host_target_same_context(self, mock_context):
+ nodes = {
+ "host": "node1.LF",
+ "target": "node2.LF"
+ }
+ scenario_cfg = {"nodes": nodes}
+ server_info = {
+ "ip": "10.20.0.3",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ mock_context.get_server.return_value = server_info
+ context_cfg = task.parse_nodes_with_context(scenario_cfg)
+
+ self.assertEqual(context_cfg["host"], server_info)
+ self.assertEqual(context_cfg["target"], server_info)
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index 0d7e9e66d..d6cd6984c 100755
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -287,7 +287,8 @@ def run_one_scenario(scenario_cfg, output_file):
# TODO support get multi hosts/vms info
context_cfg = {}
- context_cfg['host'] = Context.get_server(scenario_cfg["host"])
+ if "host" in scenario_cfg:
+ context_cfg['host'] = Context.get_server(scenario_cfg["host"])
if "target" in scenario_cfg:
if is_ip_addr(scenario_cfg["target"]):
@@ -303,6 +304,8 @@ def run_one_scenario(scenario_cfg, output_file):
context_cfg["target"]["ipaddr"] = \
context_cfg["target"]["ip"]
+ if "nodes" in scenario_cfg:
+ context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg)
runner = base_runner.Runner.get(runner_cfg)
print "Starting runner of type '%s'" % runner_cfg["type"]
@@ -311,6 +314,17 @@ def run_one_scenario(scenario_cfg, output_file):
return runner
+def parse_nodes_with_context(scenario_cfg):
+ '''paras the 'nodes' fields in scenario '''
+ nodes = scenario_cfg["nodes"]
+
+ nodes_cfg = {}
+ for nodename in nodes:
+ nodes_cfg[nodename] = Context.get_server(nodes[nodename])
+
+ return nodes_cfg
+
+
def runner_join(runner):
'''join (wait for) a runner, exit process at runner failure'''
status = runner.join()
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py
new file mode 100644
index 000000000..a7c96a842
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+'''
+Packet generators
+'''
+
+__author__ = 'vmriccox'
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py
new file mode 100644
index 000000000..4d2c6fe72
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import abc
+
+
+class BasePacketGenerator:
+
+ def __init__(self):
+ pass
+
+ @abc.abstractmethod
+ def send_traffic(self):
+ """
+ Starts the traffic generation.
+ According to the specific packet generator it requires prior
+ initialization
+ :return: None
+ """
+ raise NotImplementedError("Subclass must implement abstract method")
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py
new file mode 100644
index 000000000..ae54502e9
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py
@@ -0,0 +1,336 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import base_packet_generator
+import experimental_framework.common as common
+from experimental_framework.constants import conf_file_sections as conf_file
+from experimental_framework.constants import framework_parameters as fp
+
+
+class DpdkPacketGenerator(base_packet_generator.BasePacketGenerator):
+
+ def __init__(self):
+ base_packet_generator.BasePacketGenerator.__init__(self)
+ self.command = ''
+ self.directory = ''
+ self.program_name = ''
+ self.command_options = list()
+ self.dpdk_interfaces = -1
+
+ def send_traffic(self):
+ '''
+ Calls the packet generator and starts to send traffic
+ Blocking call
+ '''
+ current_dir = os.path.dirname(os.path.realpath(__file__))
+ DpdkPacketGenerator._chdir(self.directory)
+ dpdk_vars = common.get_dpdk_pktgen_vars()
+ self._init_physical_nics(self.dpdk_interfaces, dpdk_vars)
+ common.run_command(self.command)
+ self._finalize_physical_nics(self.dpdk_interfaces, dpdk_vars)
+ DpdkPacketGenerator._chdir(current_dir)
+
+ def init_dpdk_pktgen(self,
+ dpdk_interfaces,
+ lua_script='generic_test.lua',
+ pcap_file_0='',
+ pcap_file_1='',
+ vlan_0='',
+ vlan_1=''):
+ """
+ Initializes internal parameters and configuration of the module.
+ Needs to be called before the send_traffic
+ :param dpdk_interfaces: Number of interfaces to be used (type: int)
+ :param lua_script: Full path of the Lua script to be used (type: str)
+ :param pcap_file_0: Full path of the Pcap file to be used for port 0
+ (type: str)
+ :param pcap_file_1: Full path of the Pcap file to be used for port 1
+ (type: str)
+ :param vlan_0: VLAN tag to be used for port 0 (type: str)
+ :param vlan_1: VLAN tag to be used for port 1 (type: str)
+ :return:
+ """
+ # Input Validation
+ if pcap_file_0 and not vlan_0:
+ message = 'In order to use NIC_0, the parameter vlan_0 is required'
+ raise ValueError(message)
+ if dpdk_interfaces > 1 and pcap_file_1 and not vlan_1:
+ message = 'in order to use NIC_1, the parameter vlan_1 is required'
+ raise ValueError(message)
+
+ self.dpdk_interfaces = dpdk_interfaces
+ vars = common.get_dpdk_pktgen_vars()
+
+ lua_directory = common.get_base_dir()
+ lua_directory += fp.EXPERIMENTAL_FRAMEWORK_DIR
+ lua_directory += fp.DPDK_PKTGEN_DIR
+
+ pcap_directory = common.get_base_dir()
+ pcap_directory += fp.EXPERIMENTAL_FRAMEWORK_DIR
+ pcap_directory += fp.PCAP_DIR
+
+ DpdkPacketGenerator._init_input_validation(pcap_file_0,
+ pcap_file_1,
+ lua_script,
+ pcap_directory,
+ lua_directory,
+ vars)
+
+ self.directory = vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY]
+ self.program_name = vars[conf_file.CFSP_DPDK_PROGRAM_NAME]
+
+ core_nics = DpdkPacketGenerator.\
+ _get_core_nics(dpdk_interfaces, vars[conf_file.CFSP_DPDK_COREMASK])
+ self.command_options = ['-c ' + vars[conf_file.CFSP_DPDK_COREMASK],
+ '-n ' + vars[conf_file.
+ CFSP_DPDK_MEMORY_CHANNEL],
+ '--proc-type auto',
+ '--file-prefix pg',
+ '-- -T',
+ '-P',
+ '-m "' + core_nics + '"',
+ '-f ' + lua_directory + lua_script,
+ '-s 0:' + pcap_directory + pcap_file_0]
+
+ if pcap_file_1:
+ self.command_options.append('-s 1:' + pcap_directory + pcap_file_1)
+
+ # Avoid to show the output of the packet generator
+ self.command_options.append('> /dev/null')
+ # Prepare the command to be invoked
+ self.command = self.directory + self.program_name
+ for opt in self.command_options:
+ self.command += (' ' + opt)
+ if pcap_file_0 and vlan_0:
+ DpdkPacketGenerator._change_vlan(pcap_directory, pcap_file_0,
+ vlan_0)
+ if pcap_file_1 and vlan_1:
+ DpdkPacketGenerator._change_vlan(pcap_directory, pcap_file_1,
+ vlan_1)
+
+ @staticmethod
+ def _get_core_nics(dpdk_interfaces, coremask):
+ """
+ Retruns the core_nics string to be used in the dpdk pktgen command
+ :param dpdk_interfaces: number of interfaces to be used in the pktgen
+ (type: int)
+ :param coremask: hexadecimal value representing the cores assigned to
+ the pktgen (type: str)
+ :return: Returns the core nics param for pktgen (type: str)
+ """
+ if dpdk_interfaces == 1:
+ return DpdkPacketGenerator._cores_configuration(coremask, 1, 2, 0)
+ elif dpdk_interfaces == 2:
+ return DpdkPacketGenerator._cores_configuration(coremask, 1, 2, 2)
+ raise ValueError("This framework only supports two ports to generate "
+ "traffic")
+
+ @staticmethod
+ def _change_vlan(pcap_directory, pcap_file, vlan):
+ common.LOG.info("Changing VLAN Tag on Packet: " + pcap_file +
+ ". New VLAN Tag is " + vlan)
+ command = pcap_directory + 'vlan_tag.sh '
+ command += pcap_directory + pcap_file + ' ' + vlan
+ common.run_command(command)
+
+ @staticmethod
+ def _init_input_validation(pcap_file_0, pcap_file_1, lua_script,
+ pcap_directory, lua_directory, variables):
+ """
+ Validates the input parameters values and raises an exception if
+ there is any non valid param
+ :param pcap_file_0: file name of the pcap file for NIC 0
+ (it does not includes the path) (type: str)
+ :param pcap_file_1: file name of the pcap file for NIC 1
+ (it does not includes the path) (type: str)
+ :param lua_script: file name of the lua script to be used
+ (it does not includes the path) (type: str)
+ :param pcap_directory: directory where the pcap files are located
+ (type: str)
+ :param lua_directory: directory where the lua scripts are located
+ (type: str)
+ :param variables: variables for the packet gen from configuration file
+ (type: dict)
+ :return: None
+ """
+ if not pcap_directory:
+ raise ValueError("pcap_directory not provided correctly")
+ if not pcap_file_0:
+ raise ValueError("pcap_file_0 not provided correctly")
+ if not pcap_file_1:
+ raise ValueError("pcap_file_1 not provided correctly")
+ if not lua_script:
+ raise ValueError("lua_script not provided correctly")
+ if not os.path.isfile(pcap_directory + pcap_file_0):
+ raise ValueError("The file " + pcap_file_0 + " does not exist")
+ if not os.path.isfile(pcap_directory + pcap_file_1):
+ raise ValueError("The file " + pcap_file_1 + " does not exist")
+ if not os.path.isfile(lua_directory + lua_script):
+ raise ValueError("The file " + lua_script + " does not exist")
+ for var in [conf_file.CFSP_DPDK_PKTGEN_DIRECTORY,
+ conf_file.CFSP_DPDK_PROGRAM_NAME,
+ conf_file.CFSP_DPDK_COREMASK,
+ conf_file.CFSP_DPDK_MEMORY_CHANNEL]:
+ if var not in variables.keys() or (var in variables.keys() and
+ variables[var] is ''):
+ raise ValueError("The variable " + var + " does not exist")
+
+ @staticmethod
+ def _chdir(directory):
+ """
+ Changes the current directory
+ :param directory: directory where to move (type: str)
+ :return: None
+ """
+ os.chdir(directory)
+
+ def _init_physical_nics(self, dpdk_interfaces, dpdk_vars):
+ """
+ Initializes the physical interfaces
+ :param dpdk_interfaces: Number of interfaces to be used (type: int)
+ :param dpdk_vars: variables from config file related to DPDK pktgen
+ (type: dict)
+ :return: None
+ """
+ if not dpdk_interfaces == 1 and not dpdk_interfaces == 2:
+ raise ValueError('The number of NICs can be 1 or 2')
+ # Initialize NIC 1
+ # bus_address_1 = dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1]
+ interface_1 = dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1]
+ common.run_command('ifconfig ' + interface_1 + ' down')
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --unbind ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --bind=igb_uio ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
+ if dpdk_interfaces == 2:
+ # Initialize NIC 2
+ # bus_address_2 = dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2]
+ interface_2 = dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2]
+ common.run_command('ifconfig ' + interface_2 + ' down')
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --unbind ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --bind=igb_uio ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
+
+ def _finalize_physical_nics(self, dpdk_interfaces, dpdk_vars):
+ """
+ Finalizes the physical interfaces
+ :param dpdk_interfaces: Number of interfaces to be used (type: int)
+ :param dpdk_vars: variables from config file related to DPDK pktgen
+ (type: dict)
+ :return: None
+ """
+ if not dpdk_interfaces == 1 and not dpdk_interfaces == 2:
+ raise ValueError('No interfaces have been indicated for packet '
+ 'generation usage. Please specify one or two '
+ 'NICs')
+ # Initialize NIC 1
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --unbind ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --bind=ixgbe ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
+ common.run_command('ifconfig ' +
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] +
+ ' up')
+ if dpdk_interfaces == 2:
+ # Initialize NIC 2
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --unbind ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
+ common.run_command(dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
+ 'tools/dpdk_nic_bind.py --bind=ixgbe ' +
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
+ common.run_command('ifconfig ' +
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] +
+ ' up')
+
+ @staticmethod
+ def _cores_configuration(coremask, pktgen_cores=1, nic_1_cores=2,
+ nic_2_cores=2):
+ """
+ Calculation of the core_nics parameter which is necessary for the
+ packet generator to run
+
+ :param coremask: Hexadecimal value indicating the cores to be assigned
+ to the whole dpdk pktgen software (included the
+ ones to receive and send packets from NICs)
+ (type: str)
+ :param pktgen_cores: number of cores to be assigned to main thread of
+ the pktgen directly
+ :param nic_1_cores: number of cores to be assigned to the first NIC
+ :param nic_2_nics: number of cores to be assigned to the second NIC
+ :return: returns the core_nics parameter (type: str)
+ """
+ required_cores = pktgen_cores + nic_1_cores + nic_2_cores
+ bin_coremask = bin(int(coremask, 16))[2:]
+ index = len(bin_coremask)
+ cores = []
+ while index >= 0:
+ index -= 1
+ if bin_coremask[index] == '1':
+ core = index
+ cores.append(core)
+ if len(cores) < required_cores:
+ raise ValueError('The provided coremask does not provide'
+ ' enough cores for the DPDK packet generator')
+ # ret_pktgen_cores = []
+ ret_nic_1_cores = []
+ ret_nic_2_cores = []
+ current_core = 0
+
+ if nic_2_cores > 0:
+ ret_nic_2_cores.append(cores[current_core])
+ current_core += 1
+ if nic_2_cores > 1:
+ ret_nic_2_cores.append(cores[current_core])
+ current_core += 1
+
+ if nic_1_cores > 0:
+ ret_nic_1_cores.append(cores[current_core])
+ current_core += 1
+ if nic_1_cores > 1:
+ ret_nic_1_cores.append(cores[current_core])
+ current_core += 1
+
+ # for n in range(0, pktgen_cores):
+ # ret_pktgen_cores.append(cores[n])
+ # for n in range(0, nic_1_cores):
+ # ret_nic_1_cores.append(cores[pktgen_cores + n])
+ # for n in range(0, nic_2_cores):
+ # ret_nic_2_cores.append(cores[pktgen_cores + nic_1_cores + n])
+
+ corenics = ''
+ if nic_1_cores > 0:
+ if nic_1_cores < 2:
+ corenics += str(ret_nic_1_cores[0]) + '.0'
+ if nic_1_cores == 2:
+ corenics += '[' + str(ret_nic_1_cores[0])
+ corenics += ':' + str(ret_nic_1_cores[1])
+ corenics += '].0'
+ if nic_2_cores > 0:
+ corenics += ','
+ if nic_2_cores < 2:
+ corenics += str(ret_nic_2_cores[0]) + '.1'
+ if nic_2_cores == 2:
+ corenics += '[' + str(ret_nic_2_cores[0])
+ corenics += ':' + str(ret_nic_2_cores[1])
+ corenics += '].1'
+ return corenics
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_pktgen/constant_traffic.lua b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_pktgen/constant_traffic.lua
new file mode 100644
index 000000000..3348b286b
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_pktgen/constant_traffic.lua
@@ -0,0 +1,74 @@
+-----------------------------------------------------------------------------
+-- Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+-----------------------------------------------------------------------------
+
+-----------------------------------
+----- Constant traffic sender -----
+-----------------------------------
+
+package.path = package.path ..";?.lua;test/?.lua;app/?.lua;../?.lua"
+require "Pktgen";
+
+----- Packet Gen Configuration
+local sendport = "0";
+pktgen.vlan(sendport, "on");
+pktgen.ping4("all");
+pktgen.icmp_echo("all", "on");
+pktgen.process("all", "on");
+
+
+----- Script Configuration
+local traffic_delay = 0;
+local traffic_rate = 0;
+local out_file = "";
+
+
+function start_traffic(rate)
+ local endStats, diff, prev, iteration, flag, found;
+ flag = false;
+ found = false;
+
+ -- Send traffic at the specified rate
+ print("Start Generation");
+ pktgen.set(sendport, "rate", rate);
+ sleep(1);
+ pktgen.start(sendport);
+ sleep(traffic_delay);
+ pktgen.stop(sendport);
+ print("Stop Generation");
+
+ -- Collect statistics about the experiment
+ endStats = pktgen.portStats("all", "port");
+ sent_packets = endStats[0].opackets
+ return sent_packets;
+end
+
+
+pktgen.clr();
+print("INSTANTIATION VALIDATION TEST")
+
+-- Write output on log file
+file = io.open(out_file, "w");
+
+-- Start experiment
+packets = start_traffic(traffic_rate);
+print("SENT PACKETS: " .. packets);
+file:write(packets);
+
+-- Close the log file
+file:close();
+
+-- Quit the environment
+os.exit(1);
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/igmp.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/igmp.pcap
new file mode 100644
index 000000000..1b8f24b29
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/igmp.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1024.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1024.pcap
new file mode 100644
index 000000000..445f05a26
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1024.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_128.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_128.pcap
new file mode 100644
index 000000000..df91f9bb9
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_128.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1280.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1280.pcap
new file mode 100644
index 000000000..58cb704f9
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1280.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1514.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1514.pcap
new file mode 100644
index 000000000..be23d4e96
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1514.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1518.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1518.pcap
new file mode 100644
index 000000000..a99c4480a
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_1518.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_256.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_256.pcap
new file mode 100644
index 000000000..21c34c2c2
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_256.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_512.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_512.pcap
new file mode 100644
index 000000000..8e52ecdd8
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_512.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_64.pcap b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_64.pcap
new file mode 100644
index 000000000..9438270bc
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/packet_64.pcap
Binary files differ
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/vlan_tag.sh b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/vlan_tag.sh
new file mode 100755
index 000000000..cd9740ad2
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/pcap_files/vlan_tag.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+INPUT_FILE=$1
+VLAN_TAG=$2
+
+tcprewrite --enet-vlan=add --enet-vlan-tag=$VLAN_TAG --enet-vlan-cfi=0 --enet-vlan-pri=0 --infile=$INPUT_FILE --outfile=$INPUT_FILE \ No newline at end of file
diff --git a/yardstick/vTC/apexlake/tests/base_packet_generator_test.py b/yardstick/vTC/apexlake/tests/base_packet_generator_test.py
new file mode 100644
index 000000000..b0e27d069
--- /dev/null
+++ b/yardstick/vTC/apexlake/tests/base_packet_generator_test.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+from experimental_framework.packet_generators import base_packet_generator
+
+
+class BasePacketGeneratorTest(unittest.TestCase):
+
+ def setUp(self):
+ self.mut = base_packet_generator.BasePacketGenerator()
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_send_traffic_for_failure(self):
+ self.assertRaises(NotImplementedError, self.mut.send_traffic)
diff --git a/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py
new file mode 100644
index 000000000..ad1cdcd2b
--- /dev/null
+++ b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py
@@ -0,0 +1,705 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import mock
+from experimental_framework.constants import conf_file_sections as conf_file
+
+
+from experimental_framework.packet_generators \
+ import dpdk_packet_generator as mut
+
+
+def dummy_get_dpdk_pktgen_vars():
+ vars = dict()
+ vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'pktgen_dir/'
+ vars[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program'
+ vars[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ vars[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memchannel'
+ return vars
+
+
+def dummy_get_base_dir():
+ return 'base_dir/'
+
+
+def dummy_dirname(dir):
+ if dir == 'pktgen_dir_test':
+ return 'pktgen_dir'
+ return 'test_directory'
+
+
+class MockChangeVlan():
+
+ ret_val = [False, False]
+
+ @staticmethod
+ def mock_change_vlan(pcap_dir=None, pcap_file=None, vlan=None):
+ if not pcap_file and not vlan:
+ return MockChangeVlan.ret_val
+
+ if pcap_dir == 'base_dir/experimental_framework/packet_generators/' \
+ 'pcap_files/' and \
+ pcap_file == 'pcap_file_1' and vlan == 'vlan0':
+ MockChangeVlan.ret_val[0] = True
+ if pcap_dir == 'base_dir/experimental_framework/packet_generators/' \
+ 'pcap_files/' and \
+ pcap_file == 'pcap_file_2' and vlan == 'vlan1':
+ MockChangeVlan.ret_val[1] = True
+ return False
+
+
+class TestDpdkPacketGenConstructor(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_constructor(self):
+ obj = mut.DpdkPacketGenerator()
+ self.assertEqual(obj.command, '')
+ self.assertEqual(obj.directory, '')
+ self.assertEqual(obj.dpdk_interfaces, -1)
+
+
+class TestDpdkPacketGenInitialization(unittest.TestCase):
+
+ def setUp(self):
+ self.mut = mut.DpdkPacketGenerator()
+ pass
+
+ def tearDown(self):
+ pass
+
+ @mock.patch('os.path')
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars',
+ side_effect=dummy_get_dpdk_pktgen_vars)
+ @mock.patch('experimental_framework.common.get_base_dir',
+ side_effect=dummy_get_base_dir)
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._get_core_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_init_input_validation')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._change_vlan')
+ def test_init_dpdk_pktgen_for_success(self, m_change_vlan,
+ mock_init_input_validation,
+ mock_get_core_nics,
+ common_get_base_dir,
+ common_get_dpdk_vars,
+ mock_path):
+ """
+ Tests the initialization of the packet generator
+ """
+ mock_init_input_validation.return_value = None
+ mock_get_core_nics.return_value = "{corenics}"
+ mock_path.isfile.return_value = True
+ expected = 'pktgen_dir/program -c coremask -n memchannel ' \
+ '--proc-type auto --file-prefix pg -- -T -P -m ' \
+ '"{corenics}" -f base_dir/experimental_framework/' \
+ 'packet_generators/dpdk_pktgen/lua_file ' \
+ '-s 0:base_dir/experimental_framework/packet_generators' \
+ '/pcap_files/pcap_file > /dev/null'
+ self.mut.init_dpdk_pktgen(dpdk_interfaces=1, lua_script='lua_file',
+ pcap_file_0='pcap_file', vlan_0='vlan0')
+ self.assertEqual(expected, self.mut.command)
+ m_change_vlan.assert_called_once_with('base_dir/'
+ 'experimental_framework/'
+ 'packet_generators/pcap_files/',
+ 'pcap_file', 'vlan0')
+
+ @mock.patch('os.path')
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars',
+ side_effect=dummy_get_dpdk_pktgen_vars)
+ @mock.patch('experimental_framework.common.get_base_dir',
+ side_effect=dummy_get_base_dir)
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._get_core_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_init_input_validation')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_change_vlan', side_effect=MockChangeVlan.mock_change_vlan)
+ def test_init_dpdk_pktgen_2_for_success(self, m_change_vlan,
+ mock_init_input_validation,
+ mock_get_core_nics,
+ common_get_base_dir,
+ common_get_dpdk_vars, mock_path):
+ """
+ Tests the initialization of the packet generator
+ :param common_get_base_dir: mock obj
+ :param common_get_dpdk_vars: mock obj
+ :param mock_path: mock obj
+ :return: None
+ """
+ mock_init_input_validation.return_value = None
+ mock_get_core_nics.return_value = "{corenics}"
+ mock_path.isfile.return_value = True
+ expected = 'pktgen_dir/program -c coremask -n memchannel ' \
+ '--proc-type auto --file-prefix pg -- -T -P -m ' \
+ '"{corenics}" -f base_dir/experimental_framework/' \
+ 'packet_generators/dpdk_pktgen/lua_file ' \
+ '-s 0:base_dir/experimental_framework/packet_generators/' \
+ 'pcap_files/pcap_file_1 ' \
+ '-s 1:base_dir/experimental_framework/packet_generators/' \
+ 'pcap_files/pcap_file_2 ' \
+ '> /dev/null'
+ self.mut.init_dpdk_pktgen(dpdk_interfaces=1, lua_script='lua_file',
+ pcap_file_0='pcap_file_1',
+ pcap_file_1='pcap_file_2', vlan_0='vlan0',
+ vlan_1='vlan1')
+ self.assertEqual(expected, self.mut.command)
+ self.assertEqual(MockChangeVlan.mock_change_vlan(), [True, True])
+
+ @mock.patch('os.path')
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars',
+ side_effect=dummy_get_dpdk_pktgen_vars)
+ @mock.patch('experimental_framework.common.get_base_dir',
+ side_effect=dummy_get_base_dir)
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._get_core_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_init_input_validation')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._change_vlan')
+ def test_init_dpdk_pktgen_for_failure(self, m_change_vlan,
+ mock_init_input_validation,
+ mock_get_core_nics,
+ common_get_base_dir,
+ common_get_dpdk_vars,
+ mock_path):
+ """
+ Tests the initialization of the packet generator
+ :param common_get_base_dir: mock obj
+ :param common_get_dpdk_vars: mock obj
+ :param mock_path: mock obj
+ :return: None
+ """
+ mock_init_input_validation.return_value = None
+ mock_get_core_nics.return_value = "{corenics}"
+ self.assertRaises(ValueError, self.mut.init_dpdk_pktgen, 1,
+ 'lua_file', 'pcap_file')
+
+ @mock.patch('os.path')
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars',
+ side_effect=dummy_get_dpdk_pktgen_vars)
+ @mock.patch('experimental_framework.common.get_base_dir',
+ side_effect=dummy_get_base_dir)
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_get_core_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_init_input_validation')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_change_vlan')
+ def test_init_dpdk_pktgen_for_failure_2(self, m_change_vlan,
+ mock_init_input_validation,
+ mock_get_core_nics,
+ common_get_base_dir,
+ common_get_dpdk_vars,
+ mock_path):
+ """
+ Tests the initialization of the packet generator
+ :param common_get_base_dir: mock obj
+ :param common_get_dpdk_vars: mock obj
+ :param mock_path: mock obj
+ :return: None
+ """
+ mock_init_input_validation.return_value = None
+ mock_get_core_nics.return_value = "{corenics}"
+ self.assertRaises(ValueError, self.mut.init_dpdk_pktgen, 2,
+ 'lua_file_1', 'pcap_file_1', 'pcap_file_2',
+ 'vlan_0')
+
+
+class DpdkPacketGeneratorDummy(mut.DpdkPacketGenerator):
+
+ def __init__(self):
+ self.directory = 'self_directory'
+ self.dpdk_interfaces = 1
+ self.command = 'command'
+ self._count = 0
+
+ chdir_test = [False, False]
+
+ @staticmethod
+ def _chdir(directory=None):
+ if not directory:
+ return DpdkPacketGeneratorDummy.chdir_test
+ if directory == 'current_directory':
+ DpdkPacketGeneratorDummy.chdir_test[0] = True
+ # self._count += 1
+ if directory == 'self_directory':
+ DpdkPacketGeneratorDummy.chdir_test[1] = True
+ # self._count += 1
+ return DpdkPacketGeneratorDummy.chdir_test
+
+
+class TestDpdkPacketGenSendTraffic(unittest.TestCase):
+
+ def setUp(self):
+ self.mut = DpdkPacketGeneratorDummy()
+
+ @mock.patch('os.system')
+ @mock.patch('os.path')
+ @mock.patch('os.path.dirname', side_effect=dummy_dirname)
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars',
+ side_effect=dummy_get_dpdk_pktgen_vars)
+ @mock.patch('experimental_framework.common.get_base_dir',
+ side_effect=dummy_get_base_dir)
+ @mock.patch('experimental_framework.common.run_command')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._get_core_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_init_physical_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_finalize_physical_nics')
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator._chdir',
+ side_effect=DpdkPacketGeneratorDummy._chdir)
+ def test_send_traffic_for_success(self, mock_ch_dir,
+ mock_finalize_physical_nics,
+ mock_init_physical_nics,
+ mock_get_core_nics,
+ common_run_command,
+ common_get_base_dir,
+ common_get_dpdk_vars,
+ mock_dir_name,
+ mock_os_path,
+ mock_os_system):
+ '''
+ Calls the packet generator and starts to send traffic
+ Blocking call
+ '''
+ mock_get_core_nics.return_value = "{corenics}"
+ mock_os_path.realpath.return_value = 'pktgen_dir_test'
+ mock_os_path.dirname.return_value = 'current_directory'
+ self.mut.send_traffic()
+
+ self.assertEqual(DpdkPacketGeneratorDummy._chdir(), [True, True])
+ mock_init_physical_nics.\
+ assert_called_once_with(1, {'coremask': 'coremask',
+ 'program_name': 'program',
+ 'memory_channels': 'memchannel',
+ 'pktgen_directory': 'pktgen_dir/'})
+ mock_finalize_physical_nics.\
+ assert_called_once_with(1, {'coremask': 'coremask',
+ 'program_name': 'program',
+ 'memory_channels': 'memchannel',
+ 'pktgen_directory': 'pktgen_dir/'})
+ common_run_command.assert_called_once_with('command')
+
+
+class MockRunCommand:
+
+ ret_val = [False, False, False, False, False, False]
+ ret_val_finalization = [False, False, False, False, False, False]
+
+ @staticmethod
+ def mock_run_command(command=None):
+ if command == 'ifconfig interface_1 down':
+ MockRunCommand.ret_val[0] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py --unbind 1:00.0':
+ MockRunCommand.ret_val[1] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py ' \
+ '--bind=igb_uio 1:00.0':
+ MockRunCommand.ret_val[2] = True
+ if command == 'ifconfig interface_2 down':
+ MockRunCommand.ret_val[3] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py ' \
+ '--unbind 1:00.1':
+ MockRunCommand.ret_val[4] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py ' \
+ '--bind=igb_uio 1:00.1':
+ MockRunCommand.ret_val[5] = True
+ else:
+ return MockRunCommand.ret_val
+
+ @staticmethod
+ def mock_run_command_finalization(command=None):
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py --unbind 1:00.0':
+ MockRunCommand.ret_val_finalization[0] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py ' \
+ '--bind=ixgbe 1:00.0':
+ MockRunCommand.ret_val_finalization[1] = True
+ if command == 'ifconfig interface_1 up':
+ MockRunCommand.ret_val_finalization[2] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py --unbind 1:00.1':
+ MockRunCommand.ret_val_finalization[3] = True
+ if command == 'dpdk_directory/tools/dpdk_nic_bind.py ' \
+ '--bind=ixgbe 1:00.1':
+ MockRunCommand.ret_val_finalization[4] = True
+ if command == 'ifconfig interface_2 up':
+ MockRunCommand.ret_val_finalization[5] = True
+ else:
+ return MockRunCommand.ret_val_finalization
+
+
+class TestDpdkPacketGenOthers(unittest.TestCase):
+
+ def setUp(self):
+ self.mut = mut.DpdkPacketGenerator()
+
+ def tearDown(self):
+ pass
+
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_cores_configuration')
+ def test__get_core_nics_for_failure(self, mock_cores_configuration):
+ mock_cores_configuration.return_value = None
+ self.assertRaises(ValueError, mut.DpdkPacketGenerator._get_core_nics,
+ '', '')
+
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_cores_configuration')
+ def test__get_core_nics_one_nic_for_success(self,
+ mock_cores_configuration):
+ mock_cores_configuration.return_value = 'ret_val'
+ expected = 'ret_val'
+ output = mut.DpdkPacketGenerator._get_core_nics(1, 'coremask')
+ self.assertEqual(expected, output)
+ mock_cores_configuration.assert_called_once_with('coremask', 1, 2, 0)
+
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator.'
+ '_cores_configuration')
+ def test__get_core_nics_two_nics_for_success(self,
+ mock_cores_configuration):
+ mock_cores_configuration.return_value = 'ret_val'
+ expected = 'ret_val'
+ output = mut.DpdkPacketGenerator._get_core_nics(2, 'coremask')
+ self.assertEqual(expected, output)
+ mock_cores_configuration.assert_called_once_with('coremask', 1, 2, 2)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_success(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ pcap_directory = 'pcap_directory'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertEqual(mut.DpdkPacketGenerator._init_input_validation(
+ pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory,
+ variables), None)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_failure(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ pcap_directory = 'pcap_directory'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ # variables[common.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_failure_2(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_directory = None
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_failure_3(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_directory = 'directory'
+ pcap_file_0 = None
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_failure_4(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_directory = 'directory'
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = None
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile')
+ def test__init_input_validation_for_failure_5(self, mock_is_file):
+ mock_is_file.return_value = True
+
+ pcap_directory = 'directory'
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = None
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile', side_effect=[False])
+ def test__init_input_validation_for_failure_6(self, mock_is_file):
+ # mock_is_file.return_value = False
+
+ pcap_directory = 'directory'
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile', side_effect=[True, False])
+ def test__init_input_validation_for_failure_7(self, mock_is_file):
+ pcap_directory = 'directory'
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.path.isfile', side_effect=[True, True, False])
+ def test__init_input_validation_for_failure_8(self, mock_is_file):
+ pcap_directory = 'directory'
+ pcap_file_0 = 'pcap_file_0'
+ pcap_file_1 = 'pcap_file_1'
+ lua_script = 'lua_script'
+ lua_directory = 'lua_directory'
+
+ variables = dict()
+ variables[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'directory'
+ variables[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ variables[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ variables[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator.
+ _init_input_validation, pcap_file_0, pcap_file_1,
+ lua_script, pcap_directory, lua_directory, variables)
+
+ @mock.patch('os.chdir')
+ def test__chdir_for_success(self, mock_os_chdir):
+ mut.DpdkPacketGenerator._chdir('directory')
+ mock_os_chdir.assert_called_once_with('directory')
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=MockRunCommand.mock_run_command)
+ def test__init_physical_nics_for_success(self, mock_run_command):
+ dpdk_interfaces = 1
+ dpdk_vars = dict()
+
+ dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'pktgen_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ dpdk_vars[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ dpdk_vars[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1] = '1:00.0'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2] = '1:00.1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] = 'interface_1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] = 'interface_2'
+ self.mut._init_physical_nics(dpdk_interfaces, dpdk_vars)
+ self.assertEqual(MockRunCommand.mock_run_command(),
+ [True, True, True, False, False, False])
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=MockRunCommand.mock_run_command)
+ def test__init_physical_nics_for_success_2(self, mock_run_command):
+ dpdk_interfaces = 2
+ dpdk_vars = dict()
+
+ dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'pktgen_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ dpdk_vars[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ dpdk_vars[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1] = '1:00.0'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2] = '1:00.1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] = 'interface_1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] = 'interface_2'
+ self.mut._init_physical_nics(dpdk_interfaces, dpdk_vars)
+ self.assertEqual(MockRunCommand.mock_run_command(),
+ [True, True, True, True, True, True])
+
+ @mock.patch('experimental_framework.common.run_command')
+ def test__init_physical_nics_for_failure(self, mock_run_command):
+ dpdk_interfaces = 3
+ dpdk_vars = dict()
+ self.assertRaises(ValueError, self.mut._init_physical_nics,
+ dpdk_interfaces, dpdk_vars)
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=MockRunCommand.mock_run_command_finalization)
+ def test__finalize_physical_nics_for_success(self, mock_run_command):
+ dpdk_interfaces = 1
+ dpdk_vars = dict()
+ dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'pktgen_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ dpdk_vars[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ dpdk_vars[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1] = '1:00.0'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2] = '1:00.1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] = 'interface_1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] = 'interface_2'
+ self.mut._finalize_physical_nics(dpdk_interfaces, dpdk_vars)
+ self.assertEqual(MockRunCommand.mock_run_command_finalization(),
+ [True, True, True, False, False, False])
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=MockRunCommand.mock_run_command_finalization)
+ def test__finalize_physical_nics_for_success_2(self, mock_run_command):
+ dpdk_interfaces = 2
+ dpdk_vars = dict()
+ dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] = 'dpdk_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PKTGEN_DIRECTORY] = 'pktgen_directory/'
+ dpdk_vars[conf_file.CFSP_DPDK_PROGRAM_NAME] = 'program_name'
+ dpdk_vars[conf_file.CFSP_DPDK_COREMASK] = 'coremask'
+ dpdk_vars[conf_file.CFSP_DPDK_MEMORY_CHANNEL] = 'memory_channels'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1] = '1:00.0'
+ dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2] = '1:00.1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] = 'interface_1'
+ dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] = 'interface_2'
+ self.mut._finalize_physical_nics(dpdk_interfaces, dpdk_vars)
+ self.assertEqual(MockRunCommand.mock_run_command_finalization(),
+ [True, True, True, True, True, True])
+
+ def test__finalize_physical_nics_for_failure(self):
+ dpdk_interfaces = 0
+ dpdk_vars = dict()
+ self.assertRaises(ValueError, self.mut._finalize_physical_nics,
+ dpdk_interfaces, dpdk_vars)
+
+ def test__cores_configuration_for_success(self):
+ coremask = '1f'
+ expected = '[2:1].0,[4:3].1'
+ output = mut.DpdkPacketGenerator._cores_configuration(coremask,
+ 1, 2, 2)
+ self.assertEqual(expected, output)
+
+ def test__cores_configuration_for_success_2(self):
+ coremask = '1f'
+ expected = '2.0,[4:3].1'
+ output = mut.DpdkPacketGenerator._cores_configuration(coremask,
+ 1, 1, 2)
+ self.assertEqual(expected, output)
+
+ def test__cores_configuration_for_success_3(self):
+ coremask = '1f'
+ expected = '[3:2].0,4.1'
+ output = mut.DpdkPacketGenerator._cores_configuration(coremask,
+ 1, 2, 1)
+ self.assertEqual(expected, output)
+
+ def test__cores_configuration_for_failure(self):
+ coremask = '1'
+ self.assertRaises(ValueError,
+ mut.DpdkPacketGenerator._cores_configuration,
+ coremask, 1, 2, 2)
+
+ @mock.patch('experimental_framework.common.LOG')
+ @mock.patch('experimental_framework.common.run_command')
+ def test__change_vlan_for_success(self, mock_run_command, mock_log):
+ mut.DpdkPacketGenerator._change_vlan('/directory/', 'pcap_file', '10')
+ expected_param = '/directory/vlan_tag.sh /directory/pcap_file 10'
+ mock_run_command.assert_called_once_with(expected_param)