Merge "Add pod.yaml files for Apex"
[yardstick.git] / yardstick / benchmark / scenarios / networking / pktgen_dpdk_latency_benchmark.bash
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 ZTE corporation and others.
4 #
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 ##############################################################################
10 #!/bin/sh
11
12 set -e
13
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
21 ETH1=$7
22 ETH2=$8
23
24 DPDK_VERSION="dpdk-17.02"
25 PKTGEN_VERSION="pktgen-3.2.12"
26
27
28 load_modules()
29 {
30     if lsmod | grep "uio" &> /dev/null ; then
31     echo "uio module is loaded"
32     else
33     modprobe uio
34     fi
35
36     if lsmod | grep "igb_uio" &> /dev/null ; then
37     echo "igb_uio module is loaded"
38     else
39     insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
40     fi
41
42     if lsmod | grep "rte_kni" &> /dev/null ; then
43     echo "rte_kni module is loaded"
44     else
45     insmod /opt/tempT/$DPDK_VERSION/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
46     fi
47 }
48
49 change_permissions()
50 {
51     chmod 777 /sys/bus/pci/drivers/virtio-pci/*
52     chmod 777 /sys/bus/pci/drivers/igb_uio/*
53 }
54
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
60
61 }
62
63 create_pktgen_config_lua()
64 {
65     touch /home/ubuntu/pktgen_latency.lua
66     lua_file="/home/ubuntu/pktgen_latency.lua"
67     chmod 777 $lua_file
68     echo $lua_file
69
70     cat << EOF > "/home/ubuntu/pktgen_latency.lua"
71 package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
72
73  -- require "Pktgen";
74 function pktgen_config()
75
76   pktgen.screen("off");
77
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");
89
90   pktgen.start(0);
91   end
92
93 pktgen_config()
94 EOF
95 }
96
97
98 create_expect_file()
99 {
100     touch /home/ubuntu/pktgen.exp
101     expect_file="/home/ubuntu/pktgen.exp"
102     chmod 777 $expect_file
103     echo $expect_file
104
105     cat << 'EOF' > "/home/ubuntu/pktgen.exp"
106 #!/usr/bin/expect
107
108 set blacklist  [lindex $argv 0]
109 set log [lindex $argv 1]
110 set result {}
111 set timeout 15
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
113 expect "Pktgen>"
114 send "\n"
115 expect "Pktgen>"
116 send "on\n"
117 expect "Pktgen>"
118 set count 10
119 while { $count } {
120     send "page latency\n"
121     expect -re "(..*)"
122     set result "${result}$expect_out(0,string)"
123     set timeout 1
124     set count [expr $count-1]
125 }
126 send "stop 0\n"
127 expect "Pktgen>"
128 send "quit\n"
129 expect "#"
130
131 set file [ open $log w ]
132 puts $file $result
133 EOF
134
135 }
136
137 run_pktgen()
138 {
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
144 }
145
146 main()
147 {
148     load_modules
149     change_permissions
150     create_pktgen_config_lua
151     create_expect_file
152     add_interface_to_dpdk
153     run_pktgen
154 }
155
156 main