#!/bin/bash # set -x CURRENT_PATH=`dirname $0` TP_SVR=192.168.100.5 TP_PORT=10000 function get_netdev_by_pci() { DEV_LIST=`ifconfig -a |grep flags |awk -F: '{print $1}'` for i in ${DEV_LIST} do ethtool -i ${i} |grep bus-info |grep "$1" > /dev/null 2>&1 if [ $? -eq 0 ];then TARGET=${i} break fi done echo ${TARGET} } function pf_setup() { echo 1 > /proc/sys/net/ipv6/conf/eth_pf/disable_ipv6 ifconfig eth_pf up modprobe 8021q vconfig add eth_pf 100 vconfig set_flag eth_pf.100 1 1 ifconfig eth_pf.100 192.168.100.1 netmask 255.255.255.0 up sleep 1 } function vf_setup() { echo 8 > /sys/class/net/eth_pf/device/sriov_numvfs sleep 5 ifconfig eth_ctl up ifconfig eth_ctl mtu 2000 ip link set eth_pf vf 2 vlan 200 ifconfig eth_ctl 192.168.200.1 netmask 255.255.255.0 ifconfig eth_dign_s up ifconfig eth_rsv up ifconfig eth_ctl up ifconfig eth_raw up ifconfig eth_mcn1 up ifconfig eth_mcn2 up ifconfig eth_mcn3 up ifconfig eth_dign_c up sleep 5 } function bring_down_pfvf() { echo 0 > /sys/class/net/eth_pf/device/sriov_numvfs ifconfig eth_pf down sleep 3 } # Main loop while : do FAIL_FLAG=0 # Make sure PF is valid ping ${TP_SVR} -c 1 if [ $? -ne 0 ];then echo "Please make sure switch board is up." bring_down_pfvf pf_setup continue fi # Make sure TestPoint is up. echo "show version" | nc ${TP_SVR} ${TP_PORT} if [ $? -ne 0 ];then echo "Cannot reach TestPoint!" echo "Please make sure TestPoint is up and in remote-listen mode." sleep 5 continue fi # Create VFs and get MAC addresses vf_setup PF=`get_netdev_by_pci 01:00.0` VF1=`get_netdev_by_pci 01:00.1` VF2=`get_netdev_by_pci 01:00.2` VF3=`get_netdev_by_pci 01:00.3` VF4=`get_netdev_by_pci 01:00.4` VF5=`get_netdev_by_pci 01:00.5` VF6=`get_netdev_by_pci 01:00.6` VF7=`get_netdev_by_pci 01:00.7` VF8=`get_netdev_by_pci 01:01.0` MAC1=`ifconfig ${VF1} |grep ether |awk -F' ' '{print $2}'` MAC2=`ifconfig ${VF2} |grep ether |awk -F' ' '{print $2}'` MAC3=`ifconfig ${VF3} |grep ether |awk -F' ' '{print $2}'` MAC4=`ifconfig ${VF4} |grep ether |awk -F' ' '{print $2}'` MAC5=`ifconfig ${VF5} |grep ether |awk -F' ' '{print $2}'` MAC6=`ifconfig ${VF6} |grep ether |awk -F' ' '{print $2}'` MAC7=`ifconfig ${VF7} |grep ether |awk -F' ' '{print $2}'` MAC8=`ifconfig ${VF8} |grep ether |awk -F' ' '{print $2}'` MAC9=`ifconfig ${PF} |grep ether |awk -F' ' '{print $2}'` # Make sure VFs are valid MAC_TABLE=$(echo "show mac table all" | nc ${TP_SVR} ${TP_PORT}) for i in ${MAC1} ${MAC2} ${MAC3} ${MAC4} ${MAC5} ${MAC6} ${MAC7} ${MAC8} ${MAC9} do echo ${MAC_TABLE} |grep ${i} > /dev/null 2>&1 if [ $? -ne 0 ];then echo "MAC ${i} is not in table!" FAIL_FLAG=1 break fi done if [ ${FAIL_FLAG} -eq 1 ];then bring_down_pfvf continue fi echo "PF/VF setup successful." exit 0 done