2 ##############################################################################
3 # Copyright (c) 2017 ZTE corporation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
14 # Commandline arguments
15 SRC_IP=$1 # source IP address of sender in VM A
16 DST_IP=$2 # destination IP address of receiver in VM A
17 FWD_REV_MAC=$3 # MAC address of forwarding receiver in VM B
18 FWD_SEND_MAC=$4 # MAC address of forwarding sender in VM B
19 RATE=$5 # packet rate in percentage
20 PKT_SIZE=$6 # packet size
24 DPDK_VERSION="dpdk-17.02"
25 PKTGEN_VERSION="pktgen-3.2.12"
30 if lsmod | grep "uio" &> /dev/null ; then
31 echo "uio module is loaded"
36 if lsmod | grep "igb_uio" &> /dev/null ; then
37 echo "igb_uio module is loaded"
39 insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
42 if lsmod | grep "rte_kni" &> /dev/null ; then
43 echo "rte_kni module is loaded"
45 insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
51 chmod 777 /sys/bus/pci/drivers/virtio-pci/*
52 chmod 777 /sys/bus/pci/drivers/igb_uio/*
55 add_interface_to_dpdk(){
56 ip link set $ETH1 down
57 ip link set $ETH2 down
58 interfaces=$(lspci |grep Eth |tail -n +2 |awk '{print $1}')
59 /opt/tempT/$DPDK_VERSION/usertools/dpdk-devbind.py --bind=igb_uio $interfaces
63 create_pktgen_config_lua()
65 touch /home/ubuntu/pktgen_latency.lua
66 lua_file="/home/ubuntu/pktgen_latency.lua"
70 cat << EOF > "/home/ubuntu/pktgen_latency.lua"
71 package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
74 function pktgen_config()
78 pktgen.set_ipaddr("0", "dst", "$DST_IP");
79 pktgen.set_ipaddr("0", "src", "$SRC_IP/24");
80 pktgen.set_mac("0", "$FWD_REV_MAC");
81 pktgen.set_ipaddr("1", "dst", "$SRC_IP");
82 pktgen.set_ipaddr("1", "src", "$DST_IP/24");
83 pktgen.set_mac("1", "$FWD_SEND_MAC");
84 pktgen.set(0, "rate", $RATE);
85 pktgen.set(0, "size", $PKT_SIZE);
86 pktgen.set_proto("all", "udp");
87 pktgen.latency("all","enable");
88 pktgen.latency("all","on");
100 touch /home/ubuntu/pktgen.exp
101 expect_file="/home/ubuntu/pktgen.exp"
102 chmod 777 $expect_file
105 cat << 'EOF' > "/home/ubuntu/pktgen.exp"
108 set blacklist [lindex $argv 0]
109 set log [lindex $argv 1]
112 spawn ./app/app/x86_64-native-linuxapp-gcc/pktgen -c 0x07 -n 4 -b $blacklist -- -P -m "1.0, 2.1" -f /home/ubuntu/pktgen_latency.lua
120 send "page latency\n"
122 set result "${result}$expect_out(0,string)"
124 set count [expr $count-1]
131 set file [ open $log w ]
139 blacklist=$(lspci |grep Eth |awk '{print $1}'|head -1)
140 cd /opt/tempT/$PKTGEN_VERSION
141 touch /home/ubuntu/result.log
142 result_log="/home/ubuntu/result.log"
143 sudo expect /home/ubuntu/pktgen.exp $blacklist $result_log
150 create_pktgen_config_lua
152 add_interface_to_dpdk