#!/bin/sh export RTE_SDK=/opt/dpdk export RTE_TARGET=x86_64-default-linuxapp-gcc export RTE_ARCH=x86_64 RTE_SRC=/usr/src/dpdk HUGE_PAGES_MEM=2097152 #[1024 * 2048kB] DEVS=("I350" "82599") PCI_UTIL=${RTE_SRC}/tools/pci_unbind.py OVS_PREFIX=/opt/openvswitchdpdk IGB_UIO=$OVS_PREFIX/share/openvswitchdpdk/kmod/igb_uio.ko RTE_KNI=$OVS_PREFIX/share/openvswitchdpdk/kmod/rte_kni.ko #check hugetlbfs mount echo -n "Mounting hugepages..." mount | grep "nodev on /mnt/huge type hugetlbfs" if [ $? -ne 0 ]; then mkdir -p /mnt/huge mount -t hugetlbfs nodev /mnt/huge fi echo "OK!" #increase hugepages for all nodes echo -n "Allocating hugepages..." #get hugepages sizes hp_sz=`cat /proc/meminfo | grep Hugepagesize | sed -r "s/Hugepagesize:[^0-9]*([0-9]+) kB/\1/"` #calculate huge pages number to get the equivalent of 1024 pages of 2MB huge_pages_no=`expr ${HUGE_PAGES_MEM} / ${hp_sz}` #get hugepages no hp=0 #Find out if this is a NUMA machine ls /sys/devices/system/node/node* > /dev/null 2>&1 if [ $? -ne 0 ]; then hp=`cat /proc/sys/vm/nr_hugepages` hptest=`expr $hp + $huge_pages_no` echo $hptest > /proc/sys/vm/nr_hugepages else hparray=() nodes=`ls /sys/devices/system/node | grep node | wc -l` for (( i=0; $i<$nodes; i++ )) do hp=`cat /sys/devices/system/node/node${i}/hugepages/hugepages-${hp_sz}kB/nr_hugepages` hptest=`expr $hp + $huge_pages_no` echo $hptest > /sys/devices/system/node/node${i}/hugepages/hugepages-${hp_sz}kB/nr_hugepages hparray+=("$hp") done fi echo "OK!" echo "Allocated ${huge_pages_no} x ${hp_sz}kB" #Insert igb_uio and rte_kni modules echo "Inserting kernel modules" rmmod openvswitch 2>/dev/null rmmod -f rte_kni 2>/dev/null rmmod -f igb_uio 2>/dev/null rmmod -f uio 2>/dev/null modprobe uio insmod ${IGB_UIO} #insert igb_uio, needed by some dpdk tests if [ $? -ne 0 ]; then echo "FAIL: uio/igb_uio load" DEVS=() else echo "PASS: uio/igb_uio load" fi #insert rte_kni driver in loopback mode, needed by KNI tests #insmod ${RTE_KNI} lo_mode=lo_mode_fifo insmod ${RTE_KNI} if [ $? -ne 0 ]; then echo "FAIL: rte_kni load" DEVS=() else echo "PASS: rte_kni load" fi #bind devices to igb_uio, needed by dpdk-ovs tests search_str="" len=${#DEVS[@]} tmp=$len for dev in ${DEVS[@]} do tmp=$[$tmp-1] if [ $tmp -gt 0 ]; then search_str+="${dev}\|" else search_str+=${dev} fi done #Get devices with link and bind to igb_uio drvarray=() pciarray=() tmp=1 len=`${PCI_UTIL} --status|grep ${search_str}|grep -v -i 'active'|wc -l` while [[ $tmp -le $len ]] do DEV_INFO=`${PCI_UTIL} --status|grep ${search_str}|grep -v -i 'active'|sed -n ${tmp}p` tmp=$[$tmp+1] DEV_PCI_ADDR=`echo ${DEV_INFO}|sed -r "s/([^ ]*) .*/\1/"` DEV_ETH=`echo ${DEV_INFO}|grep if=|sed -r "s/.*if=([^ ]*).*/\1/"` if [ "${DEV_ETH}" == "" ]; then echo "Skipping device ${DEV_PCI_ADDR}" continue fi ifconfig ${DEV_ETH} up sleep 1 ifconfig ${DEV_ETH}|grep RUNNING>/dev/null if [ $? -ne 0 ]; then echo "Skipping device ${DEV_ETH}" continue fi DEV_NAME=`echo ${DEV_INFO}|sed -r "s/.*'(.*)'.*/\1/"` DEV_DRV=`echo ${DEV_INFO}|sed -r "s/.*drv=([^ ]*).*/\1/"` pciarray+=("${DEV_PCI_ADDR}") drvarray+=("${DEV_DRV}") echo -n "Binding device ${DEV_PCI_ADDR}..." ${PCI_UTIL} --bind=igb_uio ${DEV_PCI_ADDR} echo "OK!" done # Pre test cleanup rm -f $OVS_PREFIX/etc/openvswitch/conf.db mkdir -p $OVS_PREFIX/var/run/openvswitch 2>/dev/null mkdir -p $OVS_PREFIX/etc/openvswitch 2>/dev/null # Create OVS schema echo -n "Create OVS schema..." $OVS_PREFIX/bin/ovsdb-tool create $OVS_PREFIX/etc/openvswitch/conf.db $OVS_PREFIX/share/openvswitch/vswitch.ovsschema sleep 2 echo "OK!" #Start DB server echo -n "Start DB server..." $OVS_PREFIX/sbin/ovsdb-server --remote=punix:$OVS_PREFIX/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options > ovsdb-server.log 2>&1 & ovsdb_server_pid=$! sleep 2 echo "OK!" #init DB echo -n "Init DB..." $OVS_PREFIX/bin/ovs-vsctl --no-wait init sleep 2 echo "OK!" #Configure DB echo -n "Configure DB..." $OVS_PREFIX/bin/ovs-vsctl --no-wait del-br br0 $OVS_PREFIX/bin/ovs-vsctl --no-wait add-br br0 -- set Bridge br0 datapath_type=dpdk #Configure switch to use an OpenFlow controller and disable -n-band management $OVS_PREFIX/bin/ovs-vsctl --no-wait set-controller br0 tcp:127.0.0.1:6653 $OVS_PREFIX/bin/ovs-vsctl --no-wait set Bridge br0 other_config:disable-in-band=true #Add ports to switch $OVS_PREFIX/bin/ovs-vsctl --no-wait add-port br0 ovs_dpdk_64 -- set Interface ovs_dpdk_64 type=dpdkveth ofport_request=64 $OVS_PREFIX/bin/ovs-vsctl --no-wait add-port br0 ovs_dpdk_65 -- set Interface ovs_dpdk_65 type=dpdkveth ofport_request=65 $OVS_PREFIX/bin/ovs-vsctl --no-wait add-port br0 ovs_dpdk_66 -- set Interface ovs_dpdk_66 type=dpdkveth ofport_request=66 $OVS_PREFIX/bin/ovs-vsctl --no-wait add-port br0 ovs_dpdk_67 -- set Interface ovs_dpdk_67 type=dpdkveth ofport_request=67 sleep 2 echo "OK!" #Start DPDK OVS echo -n "Start DPDK OVS..." $OVS_PREFIX/bin/ovs_dpdk -c 0x0f -n 4 --proc-type=primary --socket-mem 1024,1024 -- -p 0x03 -n 2 -v 4 --stats=1 --client_switching_core=1 --config="(0,0,2),(1,0,3)" > ovs_dpdk.log 2>&1 & ovs_dpdk_pid=$! s=0 delta=5 tmo=120 while [[ $s -lt $tmo ]] do echo -n "." sleep $delta if grep --quiet "APP: Client switching core is" ovs_dpdk.log; then echo OK! break fi s=$[$s+$delta] done if [ $s -lt $tmo ]; then echo PASS: Starting DPDK vSwitch #Start DPDK OVS daemon echo -n "Start DPDK OVS daemon..." $OVS_PREFIX/sbin/ovs-vswitchd -c 0x10 --proc-type=secondary > ovs-vswitchd.log 2>&1 & ovs_vswitchd_pid=$! s=0 delta=5 tmo=120 while [[ $s -lt $tmo ]] do echo -n "." sleep $delta if grep --quiet "EAL: Master core" ovs-vswitchd.log; then echo OK! break fi s=$[$s+$delta] done if [ $s -lt $tmo ]; then echo PASS: Starting DPDK vSwitch daemon #Cleanup flows $OVS_PREFIX/bin/ovs-ofctl del-flows br0 sleep 40 #Configure all interfaces up and promiscuous ifconfig vEth0 up ifconfig vEth1 up ifconfig vEth2 up ifconfig vEth3 up ifconfig vEth0 promisc #ifconfig vEth1 promisc #ifconfig vEth2 promisc #ifconfig vEth3 promisc tcpdump -i vEth0 & #tcpdump -i vEth2 & #tcpdump -i vEth3 & #Start OFTest echo -n "Start OFTest..." cd /opt/oftest/ ./oft -i 64@vEth0 -i 65@vEth1 -i 66@vEth2 -i 67@vEth3 flow_matches 2>&1 | \ grep "\.\.\." | sed -r "s/(.*) ... (FAIL)/\2: \1/" | sed -r "s/(.*) ... (ok)/PASS: \1/" sleep 2 echo "Kill processes..." kill -9 $ovs_vswitchd_pid 2>&1 > /dev/null sleep 1 else echo NOK! echo FAIL: Starting DPDK vSwitch daemon cd /opt/oftest/ ./oft --list-test-names | sed -r "s/(.*)/SKIP: \1/" echo "Kill processes..." fi else echo NOK! echo FAIL: Starting DPDK vSwitch cd /opt/oftest/ ./oft --list-test-names | sed -r "s/(.*)/SKIP: \1/" echo "Kill processes..." fi kill -9 $ovs_dpdk_pid 2>&1 > /dev/null sleep 1 kill -9 $ovsdb_server_pid 2>&1 > /dev/null sleep 1 #bind devices to initial drivers for ((i=0;i<${#pciarray[@]};i++)); do echo -n "Restoring device ${pciarray[$i]} ..." ${PCI_UTIL} --bind=${drvarray[$i]} ${pciarray[$i]} echo "OK!" done rmmod rte_kni rmmod igb_uio echo -n "Freeing hugepages..." #Find out if this is a NUMA machine ls /sys/devices/system/node/node* > /dev/null 2>&1 if [ $? -ne 0 ]; then echo $hp > /proc/sys/vm/nr_hugepages else i=0 for hp in ${hparray[@]} do echo $hp > "/sys/devices/system/node/node${i}/hugepages/hugepages-${hp_sz}kB/nr_hugepages" ((i++)) done fi echo "OK!" rm -rf /mnt/huge/* echo "Test done!"