3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
14 # Commandline arguments
15 DST_IP=$1 # destination IP address
16 NUM_PORTS=$2 # number of source ports
17 PKT_SIZE=$3 # packet size
18 DURATION=$4 # test duration (seconds)
19 TRXQUEUE=$5 # number of RX/TX queues to use
20 PPS=$6 # packets per second to send
23 UDP_SRC_MIN=1000 # UDP source port min
24 UDP_SRC_MAX=$(( UDP_SRC_MIN + NUM_PORTS - 1 )) # UDP source port max
25 UDP_DST_MIN=1000 # UDP destination port min
26 UDP_DST_MAX=$(( UDP_DST_MIN + NUM_PORTS )) # UDP destination port max
28 # helper function to send commands to pktgen
35 result=$(cat $PGDEV | fgrep "Result: OK:")
36 if [ "$result" = "" ]; then
37 cat $PGDEV | fgrep "Result:" >/dev/stderr
42 # remove all devices from thread
46 while [ ${COUNTER} -lt ${TRXQUEUE} ]; do
51 PGDEV=/proc/net/pktgen/kpktgend_${COUNTER}
53 # Remove all devices from this thread
54 pgset "rem_device_all"
59 # configure pktgen (see pktgen doc for details)
62 pps=$(( PPS / TRXQUEUE ))
64 while [ ${COUNTER} -lt ${TRXQUEUE} ]; do
69 PGDEV=/proc/net/pktgen/kpktgend_${COUNTER}
71 # Add device to thread
72 pgset "add_device $DEV@${COUNTER}"
78 PGDEV=/proc/net/pktgen/$DEV@${COUNTER}
80 # 0 means continious sends untill explicitly stopped
83 # set pps count to test with an explicit number. if 0 will try with bandwidth
91 # use different queue per thread
92 pgset "queue_map_min ${COUNTER}"
93 pgset "queue_map_max ${COUNTER}"
95 # packet size, NIC adds 4 bytes CRC
96 pgset "pkt_size $PKT_SIZE"
98 # random address within the min-max range
99 pgset "flag UDPDST_RND"
100 pgset "flag UDPSRC_RND"
101 pgset "flag IPDST_RND"
104 pgset "dst_min $DST_IP"
105 pgset "dst_max $DST_IP"
107 # destination MAC address
110 # source UDP port range
111 pgset "udp_src_min $UDP_SRC_MIN"
112 pgset "udp_src_max $UDP_SRC_MAX"
114 # destination UDP port range
115 pgset "udp_dst_min $UDP_DST_MIN"
116 pgset "udp_dst_max $UDP_DST_MAX"
118 let COUNTER=COUNTER+1
126 # Time to run, result can be viewed in /proc/net/pktgen/$DEV
127 PGDEV=/proc/net/pktgen/pgctrl
128 # Will hang, Ctrl-C or SIGINT to stop
132 while [ ${COUNTER} -lt ${TRXQUEUE} ]; do
133 taskset -c ${COUNTER} kpktgend_${COUNTER}
134 let COUNTER=COUNTER+1
138 # run pktgen for ${DURATION} seconds
151 # write the result to stdout in json format
157 PGDEV=/proc/net/pktgen/$DEV@
159 while [ ${COUNTER} -lt ${TRXQUEUE} ]; do
160 sent=$(($sent + $(awk '/^Result:/{print $5}' <$PGDEV${COUNTER})))
161 result_pps=$(($result_pps + $(awk 'match($0,/'\([0-9]+\)pps'/, a) {print a[1]}' <$PGDEV${COUNTER})))
162 errors=$(($errors + $(awk '/errors:/{print $5}' <$PGDEV${COUNTER})))
163 let COUNTER=COUNTER+1
166 flows=$(( NUM_PORTS * (NUM_PORTS + 1) ))
168 echo '{ "packets_sent"':${sent} , '"packets_per_second"':${result_pps}, '"flows"':${flows}, '"errors"':${errors} '}'
177 ping -c 3 $DST_IP >/dev/null
179 # destination MAC address
180 MAC=`arp -n | grep -w $DST_IP | awk '{print $3}'`
183 DEV=`arp -n | grep -w $DST_IP | awk '{print $5}'`
191 PGDEV=/proc/net/pktgen/$DEV@
195 while [ ${COUNTER} -lt ${TRXQUEUE} ]; do
196 result=$(cat $PGDEV${COUNTER} | fgrep "Result: OK:")
197 if [ "$result" = "" ]; then
198 cat $PGDEV${COUNTER} | fgrep Result: >/dev/stderr
201 let COUNTER=COUNTER+1