- WAN switching for static public IP
cat wanSwitching-static.sh
#!/bin/bash
#
# example values in case of d4's eth0
KERNEL_PORT_NAME="eth0"
DPDK_PORT_NAME="dpdk0"
PORT_PCI_ADDR="0000:02:00.0"
KERNEL_DRIVER="igb"
DPDK_DRIVER="uio_pci_generic"
LOCAL_GW="192.168.254.1"
PUBLIC_GW="xxx.xxx.xxx.xxx"
echo "# first of all, disable onebox-agent since it conflicts to this test #"
if [ $# != 1 ]; then
echo "Usage: nohup $0 [v2h | h2v] > /dev/null"
echo " - v2h: VM to Host Switching"
echo " - h2v: Host to VM Switching"
exit 1
fi
if [ $1 = "v2h" ]; then
echo "starting WAN switching from VM to Host..."
ovs-vsctl del-port br-wan ${DPDK_PORT_NAME}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR}
ifconfig br-internet up
route del default
route add default gw ${PUBLIC_GW}
echo "Done!"
elif [ $1 = "h2v" ]; then
echo "starting WAN switching from Host to VM..."
ifconfig ${KERNEL_PORT_NAME} down
brctl delif br-internet ${KERNEL_PORT_NAME}
ifconfig br-internet down
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR}
ovs-vsctl add-port br-wan ${DPDK_PORT_NAME} \
-- set interface ${DPDK_PORT_NAME} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR}
route add default gw ${LOCAL_GW}
ssh ${LOCAL_GW} "route add default gw ${PUBLIC_GW}"
echo "Done!"
else
echo "error: invalid parameter"
exit 1
fi
- two WAN switching for static public IPs
cat wanSwitching-static-2ports.sh
#!/bin/bash
#
# example values in case of d8's eth0
KERNEL_PORT_NAME0="eth0"
KERNEL_PORT_NAME1="eth1"
DPDK_PORT_NAME0="eth0"
DPDK_PORT_NAME1="eth1"
PORT_PCI_ADDR0="0000:06:00.0"
PORT_PCI_ADDR1="0000:06:00.1"
KERNEL_DRIVER="ixgbe"
DPDK_DRIVER="uio_pci_generic"
LOCAL_GW="192.168.254.1"
PUBLIC_GW="xxx.xxx.xxx.xxx"
echo "# first of all, disable onebox-agent since it conflicts to this test #"
if [ $# != 1 ]; then
echo "Usage: nohup $0 [v2h | h2v] > /dev/null"
echo " - v2h: VM to Host Switching"
echo " - h2v: Host to VM Switching"
exit 1
fi
if [ $1 = "v2h" ]; then
echo "starting WAN switching from VM to Host..."
ovs-vsctl del-port br-wan ${DPDK_PORT_NAME0}
ovs-vsctl del-port br-wan1 ${DPDK_PORT_NAME1}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR1}
ifconfig br-internet up
ifconfig br-internet1 up
route del default
route add default gw ${PUBLIC_GW}
echo "Done!"
elif [ $1 = "h2v" ]; then
echo "starting WAN switching from Host to VM..."
ifconfig ${KERNEL_PORT_NAME0} down
ifconfig ${KERNEL_PORT_NAME1} down
brctl delif br-internet ${KERNEL_PORT_NAME0}
brctl delif br-internet1 ${KERNEL_PORT_NAME1}
ifconfig br-internet down
ifconfig br-internet1 down
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR1}
ovs-vsctl add-port br-wan ${DPDK_PORT_NAME0} \
-- set interface ${DPDK_PORT_NAME0} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR0}
ovs-vsctl add-port br-wan1 ${DPDK_PORT_NAME1} \
-- set interface ${DPDK_PORT_NAME1} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR1}
route add default gw ${LOCAL_GW}
ssh ${LOCAL_GW} "route add default gw ${PUBLIC_GW} dev eth1"
echo "Done!"
else
echo "error: invalid parameter"
exit 1
fi
- WAN switching for dhcp public IP
cat wanSwitching-dhcp.sh
#!/bin/bash
#
# example values in case of d4's eth0
KERNEL_PORT_NAME="eth0"
DPDK_PORT_NAME="eth0"
PORT_PCI_ADDR="0000:02:00.0"
KERNEL_DRIVER="igb"
DPDK_DRIVER="uio_pci_generic"
LOCAL_GW="192.168.254.1"
PUBLIC_GW="xxx.xxx.xxx.xxx"
VM_IP_RELEASE_CMD='/sbin/dhclient -r -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1; /sbin/dhclient -x -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1; ip addr flush dev eth1'
VM_IP_ACQUIRE_CMD='/sbin/dhclient -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1'
HOST_IP_RELEASE_CMD='dhclient -r -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet; dhclient -x -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet; ip addr flush dev br-internet'
HOST_IP_ACQUIRE_CMD='dhclient -1 -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet'
echo "# first of all, disable onebox-agent since it conflicts to this test #"
if [ $# != 1 ]; then
echo "Usage: nohup $0 [v2h | h2v] > /dev/null"
echo " - v2h: VM to Host Switching"
echo " - h2v: Host to VM Switching"
exit 1
fi
if [ $1 = "v2h" ]; then
echo "starting WAN switching from VM to Host..."
ssh ${LOCAL_GW} ${VM_IP_RELEASE_CMD}
ovs-vsctl del-port br-wan ${DPDK_PORT_NAME}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR}
ifconfig br-internet up
${HOST_IP_ACQUIRE_CMD}
route del default
route add default gw ${PUBLIC_GW}
echo "Done!"
elif [ $1 = "h2v" ]; then
echo "starting WAN switching from Host to VM..."
${HOST_IP_RELEASE_CMD}
ifconfig ${KERNEL_PORT_NAME} down
brctl delif br-internet ${KERNEL_PORT_NAME}
ifconfig br-internet 0.0.0.0
ifconfig br-internet down
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR}
ovs-vsctl add-port br-wan ${DPDK_PORT_NAME} \
-- set interface ${DPDK_PORT_NAME} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR}
route add default gw ${LOCAL_GW}
ssh ${LOCAL_GW} ${VM_IP_ACQUIRE_CMD}
echo "Done!"
else
echo "error: invalid parameter"
exit 1
fi
- two WAN switching for dhcp public IPs
cat wanSwitching-dhcp-2ports.sh
#!/bin/bash
#
# example values in case of d4's eth0
KERNEL_PORT_NAME0="eth0"
KERNEL_PORT_NAME1="eth1"
DPDK_PORT_NAME0="eth0"
DPDK_PORT_NAME1="eth1"
PORT_PCI_ADDR0="0000:02:00.0"
PORT_PCI_ADDR1="0000:02:00.1"
KERNEL_DRIVER="igb"
DPDK_DRIVER="uio_pci_generic"
LOCAL_GW="192.168.254.1"
PUBLIC_GW="xxx.xxx.xxx.xxx"
VM_IP_RELEASE_CMD0='/sbin/dhclient -r -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1; /sbin/dhclient -x -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1; ip addr flush dev eth1'
VM_IP_RELEASE_CMD1='/sbin/dhclient -r -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5; /sbin/dhclient -x -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5; ip addr flush dev eth5'
VM_IP_ACQUIRE_CMD0='/sbin/dhclient -q -cf /work/etc/dhclient/dhclient_eth1.conf -lf /var/state/dhcp/dhclient_eth1.lease -pf /var/run/dhclient_eth1.conf.pid eth1'
VM_IP_ACQUIRE_CMD1='/sbin/dhclient -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5'
HOST_IP_RELEASE_CMD0='dhclient -r -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet; dhclient -x -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet; ip addr flush dev br-internet'
HOST_IP_RELEASE_CMD1='dhclient -r -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1; dhclient -x -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1; ip addr flush dev br-internet1'
HOST_IP_ACQUIRE_CMD0='dhclient -1 -pf /run/dhclient.br-internet.pid -lf /var/lib/dhcp/dhclient.br-internet.leases br-internet'
HOST_IP_ACQUIRE_CMD1='dhclient -1 -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1'
echo "# first of all, disable onebox-agent since it conflicts to this test #"
if [ $# != 1 ]; then
echo "Usage: nohup $0 [v2h | h2v] > /dev/null"
echo " - v2h: VM to Host Switching"
echo " - h2v: Host to VM Switching"
exit 1
fi
if [ $1 = "v2h" ]; then
echo "starting WAN switching from VM to Host..."
ssh ${LOCAL_GW} ${VM_IP_RELEASE_CMD0}
ssh ${LOCAL_GW} ${VM_IP_RELEASE_CMD1}
ovs-vsctl del-port br-wan ${DPDK_PORT_NAME0}
ovs-vsctl del-port br-wan1 ${DPDK_PORT_NAME1}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR1}
ifconfig br-internet up
ifconfig br-internet1 up
${HOST_IP_ACQUIRE_CMD0}
${HOST_IP_ACQUIRE_CMD1}
route del default
route add default gw ${PUBLIC_GW}
echo "Done!"
elif [ $1 = "h2v" ]; then
echo "starting WAN switching from Host to VM..."
${HOST_IP_RELEASE_CMD0}
${HOST_IP_RELEASE_CMD1}
ifconfig ${KERNEL_PORT_NAME0} down
ifconfig ${KERNEL_PORT_NAME1} down
brctl delif br-internet ${KERNEL_PORT_NAME0}
brctl delif br-internet1 ${KERNEL_PORT_NAME1}
ifconfig br-internet down
ifconfig br-internet1 down
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR1}
ovs-vsctl add-port br-wan ${DPDK_PORT_NAME0} \
-- set interface ${DPDK_PORT_NAME0} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR0}
ovs-vsctl add-port br-wan1 ${DPDK_PORT_NAME1} \
-- set interface ${DPDK_PORT_NAME1} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR1}
route add default gw ${LOCAL_GW}
ssh ${LOCAL_GW} ${VM_IP_ACQUIRE_CMD0}
ssh ${LOCAL_GW} ${VM_IP_ACQUIRE_CMD1}
echo "Done!"
else
echo "error: invalid parameter"
exit 1
fi
- two WAN switching for a static public IP and a dhcp public IP
cat wanSwitching-mixed-2ports.sh
#!/bin/bash
#
# example values in case of d4's eth0
KERNEL_PORT_NAME0="eth0"
KERNEL_PORT_NAME1="eth1"
DPDK_PORT_NAME0="eth0"
DPDK_PORT_NAME1="eth1"
PORT_PCI_ADDR0="0000:02:00.0"
PORT_PCI_ADDR1="0000:03:00.0"
KERNEL_DRIVER="igb"
DPDK_DRIVER="uio_pci_generic"
LOCAL_GW="192.168.254.1"
PUBLIC_GW="xxx.xxx.xxx.xxx"
VM_IP_RELEASE_CMD1='/sbin/dhclient -r -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5; /sbin/dhclient -x -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5; ip addr flush dev eth5'
VM_IP_ACQUIRE_CMD1='/sbin/dhclient -q -cf /work/etc/dhclient/dhclient_eth5.conf -lf /var/state/dhcp/dhclient_eth5.lease -pf /var/run/dhclient_eth5.conf.pid eth5'
HOST_IP_RELEASE_CMD1='dhclient -r -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1; dhclient -x -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1; ip addr flush dev br-internet1'
HOST_IP_ACQUIRE_CMD1='dhclient -1 -pf /run/dhclient.br-internet1.pid -lf /var/lib/dhcp/dhclient.br-internet1.leases br-internet1'
echo "# first of all, disable onebox-agent since it conflicts to this test #"
if [ $# != 1 ]; then
echo "Usage: nohup $0 [v2h | h2v] > /dev/null"
echo " - v2h: VM to Host Switching"
echo " - h2v: Host to VM Switching"
exit 1
fi
if [ $1 = "v2h" ]; then
echo "starting WAN switching from VM to Host..."
ssh ${LOCAL_GW} ${VM_IP_RELEASE_CMD1}
ovs-vsctl del-port br-wan ${DPDK_PORT_NAME0}
ovs-vsctl del-port br-wan1 ${DPDK_PORT_NAME1}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${KERNEL_DRIVER} ${PORT_PCI_ADDR1}
ifconfig br-internet up
ifconfig br-internet1 up
${HOST_IP_ACQUIRE_CMD1}
route del default
route add default gw ${PUBLIC_GW}
echo "Done!"
elif [ $1 = "h2v" ]; then
echo "starting WAN switching from Host to VM..."
${HOST_IP_RELEASE_CMD1}
ifconfig ${KERNEL_PORT_NAME0} down
ifconfig ${KERNEL_PORT_NAME1} down
brctl delif br-internet ${KERNEL_PORT_NAME0}
brctl delif br-internet1 ${KERNEL_PORT_NAME1}
ifconfig br-internet down
ifconfig br-internet1 down
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR0}
dpdk-devbind --force -b ${DPDK_DRIVER} ${PORT_PCI_ADDR1}
ovs-vsctl add-port br-wan ${DPDK_PORT_NAME0} \
-- set interface ${DPDK_PORT_NAME0} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR0}
ovs-vsctl add-port br-wan1 ${DPDK_PORT_NAME1} \
-- set interface ${DPDK_PORT_NAME1} type=dpdk \
options:dpdk-devargs=${PORT_PCI_ADDR1}
route add default gw ${LOCAL_GW}
ssh ${LOCAL_GW} ${VM_IP_ACQUIRE_CMD1}
ssh ${LOCAL_GW} "route add default gw ${PUBLIC_GW} dev eth1"
echo "Done!"
else
echo "error: invalid parameter"
exit 1
fi
cat repeatSwitching.sh
#!/bin/bash
#
if [ $# != 2 ]; then
echo "Usage: $0 number initial-direction"
echo " - initial-direction: v2h | h2v"
echo "Example: $0 10 v2h"
exit 1
fi
number=$1
direction=$2
reg4int='^[0-9]+$'
if ! [[ ${number} =~ ${reg4int} ]]; then
echo "error: 1st parameter is not a number"
echo "exiting..."
exit 1
fi
if [ ${direction} != "h2v" ] && [ ${direction} != "v2h" ]; then
echo "error: 2nd parameter is invalid"
echo "exiting..."
exit 1
fi
for ((i=1; i<=number; i++))
do
if [ -z "$(ps -ef | grep ovs-vswitchd | grep unix)" ]; then
echo "error: ovs-vswitchd might be crashed"
echo "exiting..."
exit 1
fi
# uncomment a line below according to your test type
#./wanSwitching-static.sh ${direction}
#./wanSwitching-dhcp.sh ${direction}
#./wanSwitching-mixed-2ports.sh ${direction}
#./wanSwitching-static-2ports.sh ${direction}
#./wanSwitching-dhcp-2ports.sh ${direction}
echo "---------- DONE ${i}th SWITCHING ----------"
if [ ${direction} = "v2h" ]; then
direction="h2v"
else
direction="v2h"
fi
sleep 5
done