+
+ def _modify_dpdk_makefile(self):
+ """
+ Modifies DPDK makefile in Guest before compilation if needed
+ """
+ pass
+
+ def _configure_copy_sources(self, dirname):
+ """
+ Mount shared directory and copy DPDK and l2fwd sources
+ """
+ # mount shared directory
+ self.execute_and_wait('umount /dev/sdb1')
+ self.execute_and_wait('rm -rf ' + S.getValue('GUEST_OVS_DPDK_DIR'))
+ self.execute_and_wait('mkdir -p ' + S.getValue('OVS_DPDK_SHARE'))
+ self.execute_and_wait('mount -o ro,iocharset=utf8 /dev/sdb1 ' +
+ S.getValue('OVS_DPDK_SHARE'))
+ self.execute_and_wait('mkdir -p ' + S.getValue('GUEST_OVS_DPDK_DIR'))
+ self.execute_and_wait('cp -r ' + os.path.join(S.getValue('OVS_DPDK_SHARE'), dirname) +
+ ' ' + S.getValue('GUEST_OVS_DPDK_DIR'))
+ self.execute_and_wait('umount /dev/sdb1')
+
+ def _configure_disable_firewall(self):
+ """
+ Disable firewall in VM
+ """
+ for iptables in ['iptables', 'ip6tables']:
+ # filter table
+ for chain in ['INPUT', 'FORWARD', 'OUTPUT']:
+ self.execute_and_wait("{} -t filter -P {} ACCEPT".format(iptables, chain))
+ # mangle table
+ for chain in ['PREROUTING', 'INPUT', 'FORWARD', 'OUTPUT', 'POSTROUTING']:
+ self.execute_and_wait("{} -t mangle -P {} ACCEPT".format(iptables, chain))
+ # nat table
+ for chain in ['PREROUTING', 'INPUT', 'OUTPUT', 'POSTROUTING']:
+ self.execute_and_wait("{} -t nat -P {} ACCEPT".format(iptables, chain))
+
+ # flush rules and delete chains created by user
+ for table in ['filter', 'mangle', 'nat']:
+ self.execute_and_wait("{} -t {} -F".format(iptables, table))
+ self.execute_and_wait("{} -t {} -X".format(iptables, table))
+
+
+ def _configure_testpmd(self):
+ """
+ Configure VM to perform L2 forwarding between NICs by DPDK's testpmd
+ """
+ self._configure_copy_sources('DPDK')
+ self._configure_disable_firewall()
+
+ # Guest images _should_ have 1024 hugepages by default,
+ # but just in case:'''
+ self.execute_and_wait('sysctl vm.nr_hugepages=1024')
+
+ # Mount hugepages
+ self.execute_and_wait('mkdir -p /dev/hugepages')
+ self.execute_and_wait(
+ 'mount -t hugetlbfs hugetlbfs /dev/hugepages')
+
+ # build and configure system for dpdk
+ self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
+ '/DPDK')
+ self.execute_and_wait('export CC=gcc')
+ self.execute_and_wait('export RTE_SDK=' +
+ S.getValue('GUEST_OVS_DPDK_DIR') + '/DPDK')
+ self.execute_and_wait('export RTE_TARGET=%s' % S.getValue('RTE_TARGET'))
+
+ # modify makefile if needed
+ self._modify_dpdk_makefile()
+
+ # disable network interfaces, so DPDK can take care of them
+ self.execute_and_wait('ifdown ' + self._net1)
+ self.execute_and_wait('ifdown ' + self._net2)
+
+ # build and insert igb_uio and rebind interfaces to it
+ self.execute_and_wait('make RTE_OUTPUT=$RTE_SDK/$RTE_TARGET -C '
+ '$RTE_SDK/lib/librte_eal/linuxapp/igb_uio')
+ self.execute_and_wait('modprobe uio')
+ self.execute_and_wait('insmod %s/kmod/igb_uio.ko' %
+ S.getValue('RTE_TARGET'))
+ self.execute_and_wait('./tools/dpdk*bind.py --status')
+ self.execute_and_wait(
+ './tools/dpdk*bind.py -u' ' ' +
+ S.getValue('GUEST_NET1_PCI_ADDRESS')[self._number] + ' ' +
+ S.getValue('GUEST_NET2_PCI_ADDRESS')[self._number])
+ self.execute_and_wait(
+ './tools/dpdk*bind.py -b igb_uio' ' ' +
+ S.getValue('GUEST_NET1_PCI_ADDRESS')[self._number] + ' ' +
+ S.getValue('GUEST_NET2_PCI_ADDRESS')[self._number])
+ self.execute_and_wait('./tools/dpdk*bind.py --status')
+
+ # build and run 'test-pmd'
+ self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
+ '/DPDK/app/test-pmd')
+ self.execute_and_wait('make clean')
+ self.execute_and_wait('make')
+ if int(S.getValue('GUEST_NIC_QUEUES')):
+ self.execute_and_wait(
+ './testpmd {} -n4 --socket-mem 512 --'.format(
+ S.getValue('GUEST_TESTPMD_CPU_MASK')) +
+ ' --burst=64 -i --txqflags=0xf00 ' +
+ '--nb-cores={} --rxq={} --txq={} '.format(
+ S.getValue('GUEST_TESTPMD_NB_CORES'),
+ S.getValue('GUEST_TESTPMD_TXQ'),
+ S.getValue('GUEST_TESTPMD_RXQ')) +
+ '--disable-hw-vlan', 60, "Done")
+ else:
+ self.execute_and_wait(
+ './testpmd {} -n 4 --socket-mem 512 --'.format(
+ S.getValue('GUEST_TESTPMD_CPU_MASK')) +
+ ' --burst=64 -i --txqflags=0xf00 ' +
+ '--disable-hw-vlan', 60, "Done")
+ self.execute('set fwd ' + self._testpmd_fwd_mode, 1)
+ self.execute_and_wait('start', 20,
+ 'TX RS bit threshold=.+ - TXQ flags=0xf00')
+
+ def _configure_l2fwd(self):
+ """
+ Configure VM to perform L2 forwarding between NICs by l2fwd module
+ """
+ self._configure_copy_sources('l2fwd')
+ self._configure_disable_firewall()
+
+ # build and configure system for l2fwd
+ self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
+ '/l2fwd')
+ self.execute_and_wait('export CC=gcc')
+
+ self.execute_and_wait('make')
+ self.execute_and_wait('insmod ' + S.getValue('GUEST_OVS_DPDK_DIR') +
+ '/l2fwd' + '/l2fwd.ko net1=' + self._net1 +
+ ' net2=' + self._net2)
+
+ def _configure_linux_bridge(self):
+ """
+ Configure VM to perform L2 forwarding between NICs by linux bridge
+ """
+ self._configure_disable_firewall()
+
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_NIC1_IP_CIDR')[self._number] +
+ ' dev ' + self._net1)
+ self.execute('ip link set dev ' + self._net1 + ' up')
+
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_NIC2_IP_CIDR')[self._number] +
+ ' dev ' + self._net2)
+ self.execute('ip link set dev ' + self._net2 + ' up')
+
+ # configure linux bridge
+ self.execute('brctl addbr br0')
+ self.execute('brctl addif br0 ' + self._net1 + ' ' + self._net2)
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_BRIDGE_IP')[self._number] +
+ ' dev br0')
+ self.execute('ip link set dev br0 up')
+
+ # Add the arp entries for the IXIA ports and the bridge you are using.
+ # Use command line values if provided.
+ trafficgen_mac = get_test_param('vanilla_tgen_port1_mac',
+ S.getValue('VANILLA_TGEN_PORT1_MAC'))
+ trafficgen_ip = get_test_param('vanilla_tgen_port1_ip',
+ S.getValue('VANILLA_TGEN_PORT1_IP'))
+
+ self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
+
+ trafficgen_mac = get_test_param('vanilla_tgen_port2_mac',
+ S.getValue('VANILLA_TGEN_PORT2_MAC'))
+ trafficgen_ip = get_test_param('vanilla_tgen_port2_ip',
+ S.getValue('VANILLA_TGEN_PORT2_IP'))
+
+ self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
+
+ # Enable forwarding
+ self.execute('sysctl -w net.ipv4.ip_forward=1')
+
+ # Controls source route verification
+ # 0 means no source validation
+ self.execute('sysctl -w net.ipv4.conf.all.rp_filter=0')
+ self.execute('sysctl -w net.ipv4.conf.' + self._net1 + '.rp_filter=0')
+ self.execute('sysctl -w net.ipv4.conf.' + self._net2 + '.rp_filter=0')