forked from perftool-incubator/bench-trafficgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trafficgen-client
executable file
·187 lines (175 loc) · 6.76 KB
/
trafficgen-client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
exec >trafficgen-client-stderrout.txt
exec 2>&1
. /usr/bin/trafficgen-base || (echo "/usr/bin/trafficgen-base not found"; exit 1)
dump_runtime
validate_label
# defaults
sample_dir=`/bin/pwd`
traffic_generator=trex-txrx # TODO: get trex-txrx-profile to be the default
devices=""
active_devices=""
device_pairs_opt="" # The device IDs to pass to binary-search. If empty, binary-search assumes 0 and 1
passthru_args=()
re='^(--[^=]+)=([^=]+)'
while [ $# -gt 0 ]; do
if [[ "$1" =~ $re ]]; then
arg="${BASH_REMATCH[1]}"
val="${BASH_REMATCH[2]}"
shift
else
arg="$1"
shift
val="$1"
shift
fi
case "$arg" in
# The following two are needed to determine DPDK device IDs (0,1,2...)
--trex-active-devices)
active_devices="$val"
;;
--trex-devices)
devices="$val"
;;
# Skip options not intended for binary-search
--trex-cpus|--trex-mem-limit|--trex-mbuf-factor|--trex-software-mode|--trex-mellanox-support)
;;
# All other options should be supported natively by binary-search
*)
passthru_args+=("$arg")
passthru_args+=("$val")
;;
esac
done
if [ -z "$active_devices" ]; then
active_devices="$devices"
fi
# Trafficgen-client might need MAC info from the server (testpmd)
echo "These files exist in ./msgs/rx:"
/bin/ls -l msgs/rx
file="msgs/rx/server-start-end:1"
echo
cat $file
echo
if [ -e "$file" ]; then
echo "Found $file"
dstmacs=`jq -r '.macs[]' $file | tr "\n" "," | sed -e s/,$//`
passthru_args+=(" --dst-macs=$dstmacs")
fi
# Map the PCI device locations to logical DPDK IDs
# If no devices are defined, it is assumed that
# trafficgen-infra has autodetected 2 devices, and they
# are the only 2 set up for DPDK, and will be device IDs
# 0 and 1.
if [ ! -z "$devices" ]; then
total_devices=$(echo $devices | sed -e "s/,/ /g" | wc -w)
#if [ $(echo "${total_devices} % 2" | bc) != 0 ]; then
if [ $(($total_devices % 2)) != 0 ]; then
exit_error "devices must be supplied in quantities of 2" 1 "$sample_dir"
else
#total_device_pairs=$(echo "${total_devices} / 2" | bc)
total_device_pairs=$(($total_devices / 2))
if [ $traffic_generator == "trex-txrx" -o $traffic_generator == "trex-txrx-profile" ]; then
device_pair_index=0
device_pairs_opt+=" --device-pairs="
for device in $(seq 1 2 ${total_devices}); do
device_a=$(( device - 1))
device_b=${device}
device_pairs_opt+="${device_a}:${device_b}"
(( device_pair_index++ ))
if [ ${device_pair_index} -lt ${total_device_pairs} ]; then
device_pairs_opt+=","
fi
done
else
if [ "${total_device_pairs}" -gt 1 ]; then
exit_error "only the trex-txrx* traffic generators support more than 1 pair of devices" 1 "$sample_dir"
fi
fi
fi
total_active_devices=$(echo ${active_devices} | sed -e "s/,/ /g" | wc -w)
if [ $(($total_active_devices % 2)) -ne 0 ]; then
exit_error "active devices must be supplied in quantities of 2" 1 "$sample_dir"
else
if [ $traffic_generator != "trex-txrx" -a \
$traffic_generator != "trex-txrx-profile" -a \
"${devices}" != "${active_devices}" ]; then
exit_error "only the trex-txrx* traffic generators support --client-devices != --active-client-devices" 1 "$sample_dir"
else
if [ $traffic_generator == "trex-txrx" -o $traffic_generator == "trex-txrx-profile" ]; then
active_device_pair_index=0
device_pairs_opt+=" --active-device-pairs="
active_device_state=0
active_devices_processed=0
for active_device in `echo $active_devices | sed -e s/,/" "/g`; do
device_index=0
active_device_index=-1
for device in `echo $devices | sed -e s/,/" "/g`; do
if [ "${device}" == "${active_device}" ]; then
active_device_index=${device_index}
fi
(( device_index++ ))
done
(( active_devices_processed++ ))
if [ ${active_device_index} -ne -1 ]; then
if [ ${active_device_state} -eq 0 ]; then
device_pairs_opt+="${active_device_index}:"
(( active_device_state++ ))
elif [ ${active_device_state} -eq 1 ]; then
device_pairs_opt+="${active_device_index}"
active_device_state=0
if [ ${active_devices_processed} -lt ${total_active_devices} ]; then
device_pairs_opt+=","
fi
fi
else
exit_error "Couldn't find an active device [${active_device}] in the list of devices [${devices}]" 1 "$sample_dir"
fi
done
fi
fi
fi
fi
if [ -z "$(command -v binary-search.py)" ]; then
exit_error "ERROR: binary-search.py is missing" 1 "$sample_dir"
fi
if [ ! -e /usr/bin/python3 ]; then
exit_error "can't find /usr/bin/python3, exiting" 1 "$sample_dir"
fi
cmd="binary-search.py ${passthru_args[@]} --output-dir $sample_dir $device_pairs_opt"
echo "About to run: $cmd"
$cmd 2>&1 | xz > $sample_dir/binary-search.txt.xz
bs_rc=${PIPESTATUS[0]}
# output the search summary
cmd="reporter.py --input ${sample_dir}/binary-search.json.xz --type search-summary"
echo "About to run: $cmd"
$cmd 2>&1 | xz > ${sample_dir}/binary-search.search-summary.txt.xz
if [ "$endpoint" == "k8s" -a "$osruntime" == "pod" ]; then
# Don't shutdown TRex, as we can't remove the hugepages in /dev/hugepages after
# when using a pod.
exit 0
fi
if [ -e $sample_dir/trex-server-running.txt ]; then
echo "Skipping TRex shutdown since I did not start it"
else
echo "Shutting down TRex"
pid_file="$sample_dir/trex-server-pid.txt"
if [ ! -e $pid_file ]; then
exit_error "[ERROR] could not find TRex pid file: $pid_file" 1 "$sample_dir"
exit 1
fi
pid=`cat $pid_file`
if [ ! -z "$pid" ]; then
kill -s SIGINT $pid || kill -s SIGTERM $pid
rc=$?
if [ $rc -gt 0 ]; then
exit_error "kill of TRex pid $pid failed" $rc "$sample_dir"
fi
else
exit_error "[ERROR] could not find TRex PID in $pid_file" 1 "$sample_dir"
fi
fi
if [ $bs_rc != 0 ]; then
error=`xzgrep -E "ERROR" $sample_dir/binary-search.txt.xz`
exit_error "binary-search.py failed:\n$error" 1 "$sample_dir"
fi