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)
21 UDP_SRC_MIN=1000 # UDP source port min
22 UDP_SRC_MAX=$(( UDP_SRC_MIN + NUM_PORTS - 1 )) # UDP source port max
23 UDP_DST_MIN=1000 # UDP destination port min
24 UDP_DST_MAX=$(( UDP_DST_MIN + NUM_PORTS )) # UDP destination port max
26 # helper function to send commands to pktgen
33 result=$(cat $PGDEV | fgrep "Result: OK:")
34 if [ "$result" = "" ]; then
35 cat $PGDEV | fgrep "Result:" >/dev/stderr
40 # configure pktgen (see pktgen doc for details)
47 PGDEV=/proc/net/pktgen/kpktgend_0
49 # Remove all devices from this thread
50 pgset "rem_device_all"
52 # Add device to thread
53 pgset "add_device $DEV"
59 PGDEV=/proc/net/pktgen/$DEV
61 # 0 means continious sends untill explicitly stopped
64 # use single SKB for all transmits
67 # packet size, NIC adds 4 bytes CRC
68 pgset "pkt_size $PKT_SIZE"
70 # random address within the min-max range
71 pgset "flag IPDST_RND UDPSRC_RND UDPDST_RND"
74 pgset "dst_min $DST_IP"
75 pgset "dst_max $DST_IP"
77 # destination MAC address
80 # source UDP port range
81 pgset "udp_src_min $UDP_SRC_MIN"
82 pgset "udp_src_max $UDP_SRC_MAX"
84 # destination UDP port range
85 pgset "udp_dst_min $UDP_DST_MIN"
86 pgset "udp_dst_max $UDP_DST_MAX"
92 # Time to run, result can be vieved in /proc/net/pktgen/$DEV
93 PGDEV=/proc/net/pktgen/pgctrl
94 # Will hang, Ctrl-C or SIGINT to stop
98 # run pktgen for ${DURATION} seconds
111 # write the result to stdout in json format
114 sent=$(awk '/^Result:/{print $5}' <$PGDEV)
115 pps=$(awk 'match($0,/'\([0-9]+\)pps'/, a) {print a[1]}' <$PGDEV)
116 errors=$(awk '/errors:/{print $5}' <$PGDEV)
118 flows=$(( NUM_PORTS * (NUM_PORTS + 1) ))
120 echo { '"packets_sent"':$sent , '"packets_per_second"':$pps, '"flows"':$flows, '"errors"':$errors }
128 ping -c 3 $DST_IP >/dev/null
130 # destination MAC address
131 MAC=`arp -n | grep -w $DST_IP | awk '{print $3}'`
134 DEV=`arp -n | grep -w $DST_IP | awk '{print $5}'`
142 PGDEV=/proc/net/pktgen/$DEV
145 result=$(cat $PGDEV | fgrep "Result: OK:")
146 if [ "$result" = "" ]; then
147 cat $PGDEV | fgrep Result: >/dev/stderr