def _change_vlan(pcap_directory, pcap_file, vlan):
     common.LOG.info("Changing VLAN Tag on Packet: " + pcap_file +
                     ". New VLAN Tag is " + vlan)
     command = "chmod +x {}{}".format(pcap_directory, 'vlan_tag.sh')
     common.run_command(command)
     command = pcap_directory + 'vlan_tag.sh '
     command += pcap_directory + pcap_file + ' ' + vlan
     common.run_command(command)
 def _change_vlan(pcap_directory, pcap_file, vlan):
     common.LOG.info("Changing VLAN Tag on Packet: " + pcap_file +
                     ". New VLAN Tag is " + vlan)
     command = "chmod +x {}{}".format(pcap_directory, 'vlan_tag.sh')
     common.run_command(command)
     command = pcap_directory + 'vlan_tag.sh '
     command += pcap_directory + pcap_file + ' ' + vlan
     common.run_command(command)
 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 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)
Exemple #5
0
    def _init_packet_checker(self):
        """
        Sets up the multicast and starts the packet checker
        :return:
        """
        # Kill any other process running from previous failed execution
        self.res_dir = os.getcwd()
        pids = self._get_pids()
        for pid in pids:
            os.kill(pid, signal.SIGTERM)

        # initialization of the VLAN interface
        command = "ip link add link "
        command += self.interface_name
        command += " name "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " type vlan id " + self.params[VLAN_RECEIVER]
        common.run_command(command)

        # set up the new
        command = 'ifconfig ' + self.interface_name + '.' + \
                  self.params[VLAN_RECEIVER]
        # An IP address is required for the interface to receive a multicast
        # flow. The specific address is not important
        command += ' 10.254.254.254 up'
        common.run_command(command)

        # configure smcroute
        command = "echo 'mgroup from "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " group "
        command += MULTICAST_GROUP
        command += "' > /etc/smcroute.conf"
        common.run_command(command)

        # run smcroute on the interface
        command = 'smcroute -d'
        common.run_command(command)

        # Start the packet checker
        command = self.pkt_checker_command
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += ' 128'
        command += ' &'
        common.run_command(command)
    def _init_packet_checker(self):
        """
        Sets up the multicast and starts the packet checker
        :return:
        """
        # Kill any other process running from previous failed execution
        self.res_dir = os.getcwd()
        pids = self._get_pids()
        for pid in pids:
            os.kill(pid, signal.SIGTERM)

        # initialization of the VLAN interface
        command = "ip link add link "
        command += self.interface_name
        command += " name "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " type vlan id " + self.params[VLAN_RECEIVER]
        common.run_command(command)

        # set up the new
        command = 'ifconfig ' + self.interface_name + '.' + \
                  self.params[VLAN_RECEIVER]
        # An IP address is required for the interface to receive a multicast
        # flow. The specific address is not important
        command += ' 10.254.254.254 up'
        common.run_command(command)

        # configure smcroute
        command = "echo 'mgroup from "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " group "
        command += MULTICAST_GROUP
        command += "' > /etc/smcroute.conf"
        common.run_command(command)

        # run smcroute on the interface
        command = 'smcroute -d'
        common.run_command(command)

        # Start the packet checker
        command = self.pkt_checker_command
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += ' 128'
        command += ' &'
        common.run_command(command)
Exemple #7
0
    def _finalize_packet_checker(self):
        """
        Obtains the PID of the packet checker and sends an alarm to
        terminate it
        :return: None
        """
        pids = self._get_pids()
        for pid in pids:
            os.kill(pid, signal.SIGTERM)

        # stop smcroute on the interface
        command = 'smcroute -k'
        common.run_command(command)

        # finalization of the VLAN interface
        command = "ip link delete "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        common.run_command(command)
    def _finalize_packet_checker(self):
        """
        Obtains the PID of the packet checker and sends an alarm to
        terminate it
        :return: None
        """
        pids = self._get_pids()
        for pid in pids:
            os.kill(pid, signal.SIGTERM)

        # stop smcroute on the interface
        command = 'smcroute -k'
        common.run_command(command)

        # finalization of the VLAN interface
        command = "ip link delete "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        common.run_command(command)
 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('sudo ' +
                        dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
                        'tools/dpdk_nic_bind.py --unbind ' +
                        dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
     time.sleep(5)
     common.run_command('sudo ' +
                        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('sudo ifconfig ' +
                        dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] +
                        ' up')
     if dpdk_interfaces == 2:
         # Initialize NIC 2
         common.run_command('sudo ' +
                            dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
                            'tools/dpdk_nic_bind.py --unbind ' +
                            dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
         time.sleep(5)
         common.run_command('sudo ' +
                            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('sudo ifconfig ' +
                            dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] +
                            ' up')
 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('sudo ifconfig ' + interface_1 + ' down')
     common.run_command('sudo ' +
                        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('sudo ' +
                        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('sudo ifconfig ' + interface_2 + ' down')
         common.run_command('sudo ' +
                            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('sudo ' +
                            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])
Exemple #11
0
    def _init_packet_checker(self):
        """
        Sets up the multicast and starts the packet checker
        :return:
        """
        # Kill any other process running from previous failed execution
        self.res_dir = common.get_result_dir()
        pids = self._get_pids()
        for pid in pids:
            # os.kill(pid, signal.SIGTERM)
            command = 'sudo kill ' + str(pid)
            common.run_command(command)

        # initialization of the VLAN interface
        command = "sudo ip link add link "
        command += self.interface_name
        command += " name "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " type vlan id " + self.params[VLAN_RECEIVER]
        common.run_command(command)

        # set up the new
        command = 'sudo ifconfig ' + self.interface_name + '.' + \
                  self.params[VLAN_RECEIVER]
        # An IP address is required for the interface to receive a multicast
        # flow. The specific address is not important
        command += ' 10.254.254.254 up netmask 255.255.255.248'
        common.run_command(command)

        command = "sudo ifconfig "
        command += self.interface_name + "." + self.params[VLAN_RECEIVER]
        command += " promisc"
        common.run_command(command)

        # configure smcroute
        command = "sudo echo 'mgroup from "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " group "
        command += MULTICAST_GROUP
        command += "' > /etc/smcroute.conf"
        common.run_command(command)

        # run smcroute on the interface
        command = 'sudo smcroute -d'
        common.run_command(command)
        time.sleep(3)

        # Start the packet checker
        current_dir = os.path.dirname(os.path.realpath(__file__))
        dir_list = self.pkt_checker_command.split('/')
        directory = '/'.join(dir_list[0:len(dir_list) - 1])
        os.chdir(directory)
        command = "make"
        common.run_command(command)
        os.chdir(current_dir)

        command = "sudo chmod +x {}".format(self.pkt_checker_command)
        common.run_command(command)

        command = 'sudo ' + self.pkt_checker_command
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += ' 128'
        command += ' &'
        common.run_command(command)
Exemple #12
0
 def test_run_command_for_success(self, mock_log, mock_os_system):
     command = 'command to be run'
     common.run_command(command)
     mock_os_system.assert_called_once_with(command)
Exemple #13
0
 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('sudo ' +
                        dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
                        'tools/dpdk_nic_bind.py --unbind ' +
                        dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_1])
     time.sleep(5)
     common.run_command('sudo ' +
                        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('sudo ifconfig ' +
                        dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_1] + ' up')
     if dpdk_interfaces == 2:
         # Initialize NIC 2
         common.run_command('sudo ' +
                            dpdk_vars[conf_file.CFSP_DPDK_DPDK_DIRECTORY] +
                            'tools/dpdk_nic_bind.py --unbind ' +
                            dpdk_vars[conf_file.CFSP_DPDK_BUS_SLOT_NIC_2])
         time.sleep(5)
         common.run_command('sudo ' +
                            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('sudo ifconfig ' +
                            dpdk_vars[conf_file.CFSP_DPDK_NAME_IF_2] +
                            ' up')
Exemple #14
0
 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('sudo ifconfig ' + interface_1 + ' down')
     common.run_command('sudo ' +
                        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('sudo ' +
                        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('sudo ifconfig ' + interface_2 + ' down')
         common.run_command('sudo ' +
                            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('sudo ' +
                            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 _init_packet_checker(self):
        """
        Sets up the multicast and starts the packet checker
        :return:
        """
        # Kill any other process running from previous failed execution
        self.res_dir = common.get_result_dir()
        pids = self._get_pids()
        for pid in pids:
            # os.kill(pid, signal.SIGTERM)
            command = 'sudo kill ' + str(pid)
            common.run_command(command)

        # initialization of the VLAN interface
        command = "sudo ip link add link "
        command += self.interface_name
        command += " name "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " type vlan id " + self.params[VLAN_RECEIVER]
        common.run_command(command)

        # set up the new
        command = 'sudo ifconfig ' + self.interface_name + '.' + \
                  self.params[VLAN_RECEIVER]
        # An IP address is required for the interface to receive a multicast
        # flow. The specific address is not important
        command += ' 10.254.254.254 up netmask 255.255.255.248'
        common.run_command(command)

        command = "sudo ifconfig "
        command += self.interface_name + "." + self.params[VLAN_RECEIVER]
        command += " promisc"
        common.run_command(command)

        # configure smcroute
        command = "sudo echo 'mgroup from "
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += " group "
        command += MULTICAST_GROUP
        command += "' > /etc/smcroute.conf"
        common.run_command(command)

        # run smcroute on the interface
        command = 'sudo smcroute -d'
        common.run_command(command)
        time.sleep(3)

        # Start the packet checker
        current_dir = os.path.dirname(os.path.realpath(__file__))
        dir_list = self.pkt_checker_command.split('/')
        directory = '/'.join(dir_list[0:len(dir_list)-1])
        os.chdir(directory)
        command = "make"
        common.run_command(command)
        os.chdir(current_dir)

        command = "sudo chmod +x {}".format(self.pkt_checker_command)
        common.run_command(command)

        command = 'sudo ' + self.pkt_checker_command
        command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
        command += ' 128'
        command += ' &'
        common.run_command(command)
 def test_run_command_for_success(self, mock_log, mock_os_system):
     command = 'command to be run'
     common.run_command(command)
     mock_os_system.assert_called_once_with(command)