blob: 5ebca4df88b84207d05ada57111f2a3b7edaec8d [file] [log] [blame]
Dave Wallace543852a2017-08-03 02:11:34 -04001#! /bin/bash
2#
3# socket_test.sh -- script to run socket tests.
4#
5script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Yalei Wang904a8502018-09-20 16:46:29 +08006vpp_dir="$WS_ROOT/build-root/build-vpp-native/vpp/bin/"
7vpp_debug_dir="$WS_ROOT/build-root/build-vpp_debug-native/vpp/bin/"
Dave Wallace543852a2017-08-03 02:11:34 -04008vpp_shm_dir="/dev/shm/"
Dave Wallace3079a642017-09-06 01:59:43 -04009vpp_run_dir="/run/vpp"
Damjan Marion79dcbc72018-09-12 14:01:10 +020010lib_dir="$WS_ROOT/build-root/install-vpp-native/vpp/lib/"
11lib_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/lib/"
Dave Wallace6ccff022018-11-06 17:45:32 -050012dpdk_devbind="$WS_ROOT/extras/vpp_config/scripts/dpdk-devbind.py"
Dave Wallace543852a2017-08-03 02:11:34 -040013docker_vpp_dir="/vpp/"
Dave Wallace30fb4a22017-08-17 16:22:04 -040014docker_app_dir="/vpp/"
Damjan Marion79dcbc72018-09-12 14:01:10 +020015docker_lib_dir="/vpp-lib/"
Dave Wallace543852a2017-08-03 02:11:34 -040016docker_os="ubuntu"
Yalei Wang904a8502018-09-20 16:46:29 +080017vcl_ldpreload_lib="libvcl_ldpreload.so"
Dave Wallace3079a642017-09-06 01:59:43 -040018user_gid="$(id -g)"
Dave Wallace543852a2017-08-03 02:11:34 -040019vpp_app="vpp"
Florin Corasab2f6db2018-08-31 14:31:41 -070020sock_srvr_app="sock_test_server"
21sock_clnt_app="sock_test_client"
Dave Wallace543852a2017-08-03 02:11:34 -040022sock_srvr_addr="127.0.0.1"
23sock_srvr_port="22000"
Dave Wallace30fb4a22017-08-17 16:22:04 -040024iperf_srvr_app="iperf3 -V4d -s"
25iperf_clnt_app="iperf3 -V4d -c \$srvr_addr"
Dave Wallace543852a2017-08-03 02:11:34 -040026gdb_in_emacs="gdb_in_emacs"
Dave Wallace8af20542017-10-26 03:29:30 -040027vcl_config="vcl.conf"
28vcl_config_dir="$WS_ROOT/src/vcl/"
29docker_vcl_config_dir="/etc/vpp/"
Keith Burns (alagalah)9e482bb2017-08-30 14:06:52 -070030xterm_geom="100x60"
Dave Wallace543852a2017-08-03 02:11:34 -040031bash_header="#! /bin/bash"
32tmp_cmdfile_prefix="/tmp/socket_test_cmd"
33cmd1_file="${tmp_cmdfile_prefix}1.$$"
34cmd2_file="${tmp_cmdfile_prefix}2.$$"
35cmd3_file="${tmp_cmdfile_prefix}3.$$"
Dave Wallace3d674492017-09-25 15:37:56 -040036vpp_eth_name="enp0s8"
Dave Wallace3079a642017-09-06 01:59:43 -040037tmp_vpp_exec_file="/tmp/vpp_config.$$"
Dave Wallace543852a2017-08-03 02:11:34 -040038tmp_gdb_cmdfile_prefix="/tmp/gdb_cmdfile"
39def_gdb_cmdfile_prefix="$WS_ROOT/extras/gdb/gdb_cmdfile"
40tmp_gdb_cmdfile_vpp="${tmp_gdb_cmdfile_prefix}_vpp.$$"
41tmp_gdb_cmdfile_client="${tmp_gdb_cmdfile_prefix}_vcl_client.$$"
42tmp_gdb_cmdfile_server="${tmp_gdb_cmdfile_prefix}_vcl_server.$$"
43get_docker_server_ip4addr='srvr_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '\''{print $2}'\'' | sed -e '\''s,/16,,'\'' -e '\''s,",,g'\'' -e '\''s/,//'\'')'
44#' single quote to fix the confused emacs colorizer.
45trap_signals="SIGINT SIGTERM EXIT"
46
47# Set default values for imported environment variables if they don't exist.
48#
49VPP_GDB_CMDFILE="${VPP_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vpp}"
50VPPCOM_CLIENT_GDB_CMDFILE="${VPPCOM_CLIENT_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_client}"
51VPPCOM_SERVER_GDB_CMDFILE="${VPPCOM_SERVER_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_server}"
52
53usage() {
54 cat <<EOF
55Usage: socket_test.sh OPTIONS TEST
56TESTS:
57 nk, native-kernel Run server & client on host using kernel.
58 nv, native-vcl Run vpp, server & client on host using VppComLib.
59 np, native-preload Run vpp, server & client on host using LD_PRELOAD.
60 dk, docker-kernel Run server & client in docker using kernel stack.
61 dv, docker-vcl Run vpp on host, server & client in docker using VppComLib.
62 dp, docker-preload Run vpp on host, server & client in docker using LD_PRELOAD.
63
64OPTIONS:
65 -h Print this usage text.
66 -l Leave ${tmp_cmdfile_prefix}* files after test run.
67 -b Run bash after application exit.
68 -d Run the vpp_debug version of all apps.
Dave Wallace774169b2017-11-01 20:07:40 -040069 -c Set VCL_CONFIG to use the vcl_test.conf file.
Dave Wallace543852a2017-08-03 02:11:34 -040070 -i Run iperf3 for client/server app in native tests.
Dave Wallace3d674492017-09-25 15:37:56 -040071 -n Name of ethernet for VPP to use in multi-host cfg.
Dave Wallacefbbb07c2018-03-08 11:35:03 -050072 -f Full thru host stack vpp configuration.
Dave Wallace3079a642017-09-06 01:59:43 -040073 -m c[lient] Run client in multi-host cfg (server on remote host)
74 s[erver] Run server in multi-host cfg (client on remote host)
Dave Wallace543852a2017-08-03 02:11:34 -040075 -e a[ll] Run all in emacs+gdb.
76 c[lient] Run client in emacs+gdb.
77 s[erver] Run server in emacs+gdb.
78 v[pp] Run vpp in emacs+gdb.
79 -g a[ll] Run all in gdb.
80 c[lient] Run client in gdb.
81 s[erver] Run server in gdb.
82 v[pp] Run vpp in gdb.
83 -t Use tabs in one xterm if available (e.g. xfce4-terminal).
84
85OPTIONS passed to client/server:
Dave Wallacede910062018-03-20 09:22:13 -040086 -6 Use IPv6.
87 -D Use UDP as the transport.
Dave Wallace543852a2017-08-03 02:11:34 -040088 -S <ip address> Server IP address.
89 -P <server port> Server Port number.
90 -E <data> Run Echo test.
91 -N <num-writes> Test Cfg: number of writes.
92 -R <rxbuf-size> Test Cfg: rx buffer size.
93 -T <txbuf-size> Test Cfg: tx buffer size.
94 -U Run Uni-directional test.
95 -B Run Bi-directional test.
96 -I <num-tst-socks> Send data over multiple test sockets in parallel.
97 -V Test Cfg: Verbose mode.
98 -X Exit client/server after running test.
99
100Environment variables:
Dave Wallace8af20542017-10-26 03:29:30 -0400101 VCL_CONFIG Pathname of vppcom configuration file.
Dave Wallace543852a2017-08-03 02:11:34 -0400102 VPP_GDB_CMDFILE Pathname of gdb command file for vpp.
103 VPPCOM_CLIENT_GDB_CMDFILE Pathname of gdb command file for client.
104 VPPCOM_SERVER_GDB_CMDFILE Pathname of gdb command file for server.
105EOF
106 exit 1
107}
108
109declare -i emacs_vpp=0
110declare -i emacs_client=0
111declare -i emacs_server=0
112declare -i gdb_vpp=0
113declare -i gdb_client=0
114declare -i gdb_server=0
115declare -i perf_vpp=0
116declare -i perf_client=0
117declare -i perf_server=0
118declare -i leave_tmp_files=0
119declare -i bash_after_exit=0
120declare -i iperf3=0
Dave Wallace3d674492017-09-25 15:37:56 -0400121declare -i use_ipv6=0
Dave Wallacede910062018-03-20 09:22:13 -0400122declare -i transport_udp=0
Dave Wallace543852a2017-08-03 02:11:34 -0400123
Dave Wallacede910062018-03-20 09:22:13 -0400124while getopts ":hitlbcd6fn:m:e:g:p:E:I:N:P:R:S:T:UBVXD" opt; do
Dave Wallace543852a2017-08-03 02:11:34 -0400125 case $opt in
126 h) usage ;;
127 l) leave_tmp_files=1
128 ;;
129 b) bash_after_exit=1
130 ;;
131 i) iperf3=1
132 ;;
Dave Wallace3d674492017-09-25 15:37:56 -0400133 6) use_ipv6=1
Dave Wallacede910062018-03-20 09:22:13 -0400134 sock_srvr_addr="::1"
135 sock_clnt_options="$sock_clnt_options -$opt"
136 sock_srvr_options="$sock_srvr_options -$opt"
Dave Wallace3d674492017-09-25 15:37:56 -0400137 ;;
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500138 f) full_thru_host_stack_vpp_cfg=1
139 ;;
Dave Wallace543852a2017-08-03 02:11:34 -0400140 t) xterm_geom="180x40"
141 use_tabs="true"
142 ;;
Dave Wallace8af20542017-10-26 03:29:30 -0400143 c) VCL_CONFIG="${vcl_config_dir}vcl_test.conf"
Dave Wallace543852a2017-08-03 02:11:34 -0400144 ;;
145 d) title_dbg="-DEBUG"
146 vpp_dir=$vpp_debug_dir
Damjan Marion79dcbc72018-09-12 14:01:10 +0200147 lib_dir=$lib_debug_dir
Dave Wallace543852a2017-08-03 02:11:34 -0400148 ;;
149 e) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
150 emacs_client=1
151 emacs_server=1
152 emacs_vpp=1
153 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
154 emacs_client=1
155 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
156 emacs_server=1
157 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
158 emacs_vpp=1
159 else
160 echo "ERROR: Option -e unknown argument \'$OPTARG\'" >&2
161 usage
162 fi
163 title_dbg="-DEBUG"
164 vpp_dir=$vpp_debug_dir
Damjan Marion79dcbc72018-09-12 14:01:10 +0200165 lib_dir=$lib_debug_dir
Dave Wallace543852a2017-08-03 02:11:34 -0400166 ;;
Dave Wallace3d674492017-09-25 15:37:56 -0400167 n) vpp_eth_name="$OPTARG"
168 ;;
Dave Wallace3079a642017-09-06 01:59:43 -0400169 m) if [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
170 multi_host="client"
171 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
172 multi_host="server"
173 else
174 echo "ERROR: Option -e unknown argument \'$OPTARG\'" >&2
175 usage
176 fi
177 ;;
Dave Wallace543852a2017-08-03 02:11:34 -0400178 g) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
179 gdb_client=1
180 gdb_server=1
181 gdb_vpp=1
182 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
183 gdb_client=1
184 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
185 gdb_server=1
186 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
187 gdb_vpp=1
188 else
189 echo "ERROR: Option -g unknown argument \'$OPTARG\'" >&2
190 usage
191 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400192 ;;
193 p) if [ $OPTARG = "a" ] || [ $OPTARG = "all" ] ; then
194 perf_client=1
195 perf_server=1
196 perf_vpp=1
197 elif [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
198 perf_client=1
199 elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
200 perf_server=1
201 elif [ $OPTARG = "v" ] || [ $OPTARG = "vpp" ] ; then
202 perf_vpp=1
203 else
204 echo "ERROR: Option -p unknown argument \'$OPTARG\'" >&2
205 usage
206 fi
207 echo "WARNING: -p options TBD"
208 ;;
209 S) sock_srvr_addr="$OPTARG"
210 ;;
211 P) sock_srvr_port="$OPTARG"
212 ;;
Dave Wallacede910062018-03-20 09:22:13 -0400213 D) sock_clnt_options="$sock_clnt_options -$opt"
214 sock_srvr_options="$sock_srvr_options -$opt"
215 ;;
Dave Wallace543852a2017-08-03 02:11:34 -0400216E|I|N|R|T) sock_clnt_options="$sock_clnt_options -$opt \"$OPTARG\""
217 ;;
218 U|B|V|X) sock_clnt_options="$sock_clnt_options -$opt"
219 ;;
220 \?)
221 echo "ERROR: Invalid option: -$OPTARG" >&2
222 usage
223 ;;
224 :)
225 echo "ERROR: Option -$OPTARG requires an argument." >&2
226 usage
227 ;;
228 esac
229done
230
231shift $(( $OPTIND-1 ))
232while ! [[ $run_test ]] && (( $# > 0 )) ; do
233 case $1 in
234 "nk" | "native-kernel")
235 run_test="native_kernel" ;;
236 "np" | "native-preload")
237 run_test="native_preload" ;;
238 "nv" | "native-vcl")
Yalei Wang904a8502018-09-20 16:46:29 +0800239 sock_srvr_app="vcl_test_server"
240 sock_clnt_app="vcl_test_client"
Dave Wallace543852a2017-08-03 02:11:34 -0400241 run_test="native_vcl" ;;
242 "dk" | "docker-kernel")
243 run_test="docker_kernel" ;;
244 "dp" | "docker-preload")
245 run_test="docker_preload" ;;
246 "dv" | "docker-vcl")
Yalei Wang904a8502018-09-20 16:46:29 +0800247 sock_srvr_app="vcl_test_server"
248 sock_clnt_app="vcl_test_client"
Dave Wallace543852a2017-08-03 02:11:34 -0400249 run_test="docker_vcl" ;;
250 *)
251 echo "ERROR: Unknown option '$1'!" >&2
252 usage ;;
253 esac
254 shift
255done
256
Dave Wallaceee45d412017-11-24 21:44:06 -0500257if [ -z "$VCL_DEBUG" ] ; then
258 if [ "$title_dbg" = "-DEBUG" ] ; then
259 VCL_DEBUG=1
260 else
261 VCL_DEBUG=0
262 fi
263fi
264
Damjan Marion79dcbc72018-09-12 14:01:10 +0200265VCL_LDPRELOAD_LIB_DIR="${VCL_LDPRELOAD_LIB_DIR:-$lib_dir}"
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400266
Dave Wallace543852a2017-08-03 02:11:34 -0400267if [ -z "$WS_ROOT" ] ; then
268 echo "ERROR: WS_ROOT environment variable not set!" >&2
269 echo " Please set WS_ROOT to VPP workspace root directory." >&2
Dave Wallace3079a642017-09-06 01:59:43 -0400270 exit 1
Dave Wallace543852a2017-08-03 02:11:34 -0400271fi
272
Dave Wallace6ccff022018-11-06 17:45:32 -0500273if [ ! -d $vpp_dir ] ; then
274 if [ -z "$title_dbg" ] ; then
275 (cd $WS_ROOT; make build-release)
276 else
277 (cd $WS_ROOT; make build)
278 fi
Dave Wallace3d674492017-09-25 15:37:56 -0400279fi
280
Dave Wallace543852a2017-08-03 02:11:34 -0400281if [ ! -d $vpp_dir ] ; then
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400282 echo "ERROR: Missing VPP$title_dbg bin directory!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400283 echo " $vpp_dir" >&2
284 env_test_failed="true"
285fi
286
287if [[ $run_test =~ .*"_preload" ]] ; then
Damjan Marion79dcbc72018-09-12 14:01:10 +0200288 if [ ! -d $lib_dir ] ; then
289 echo "ERROR: Missing VPP$title_dbg lib directory!" >&2
290 echo " $lib_dir" >&2
Dave Wallaced69f4f42017-08-14 18:26:46 -0400291 elif [ ! -d $VCL_LDPRELOAD_LIB_DIR ] ; then
292 echo "ERROR: Missing VCL LD_PRELOAD Library directory!" >&2
293 echo " $VCL_LDPRELOAD_LIB_DIR" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400294 env_test_failed="true"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400295 elif [ ! -f $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib ] ; then
296 echo "ERROR: Missing VCL LD_PRELOAD library!" >&2
297 echo " $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400298 env_test_failed="true"
299 fi
300fi
301
302if [ ! -f $vpp_dir$vpp_app ] ; then
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400303 echo "ERROR: Missing VPP$title_dbg Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400304 echo " $vpp_dir$vpp_app" >&2
305 env_test_failed="true"
306fi
307
Dave Wallace30fb4a22017-08-17 16:22:04 -0400308if [ ! -f $vpp_dir$sock_srvr_app ] && [ ! $iperf3 -eq 1 ] ; then
Yalei Wang904a8502018-09-20 16:46:29 +0800309 echo "ERROR: Missing SERVER$title_dbg Socket Server Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400310 echo " $vpp_dir$sock_srvr_app" >&2
311 env_test_failed="true"
312fi
313
Dave Wallace30fb4a22017-08-17 16:22:04 -0400314if [ ! -f $vpp_dir$sock_clnt_app ] && [ ! $iperf3 -eq 1 ] ; then
Yalei Wang904a8502018-09-20 16:46:29 +0800315 echo "ERROR: Missing CLIENT$title_dbg Socket Client Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400316 echo " $vpp_dir$sock_clnt_app" >&2
317 env_test_failed="true"
318fi
319
320if [[ $run_test =~ "docker_".* ]] ; then
321 if [ $emacs_client -eq 1 ] || [ $emacs_server -eq 1 ] || [ $gdb_client -eq 1 ] || [ $gdb_server -eq 1 ] ; then
322
323 echo "WARNING: gdb is not currently supported in docker."
324 echo " Ignoring client/server gdb options."
325 emacs_client=0
326 emacs_server=0
327 gdb_client=0
328 gdb_server=0
329 fi
330fi
331
Dave Wallace30fb4a22017-08-17 16:22:04 -0400332if [[ $run_test =~ .*"_vcl" ]] && [ $iperf3 -eq 1 ] ; then
333 echo "ERROR: Invalid option 'i' for test $run_test!"
334 echo " iperf3 is not compiled with the VCL library."
335 env_test_failed="true"
336fi
337
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500338if [ -n "$multi_host"] && [ ! -f "$dpdk_devbind" ] ; then
Dave Wallace19481612017-09-15 18:47:44 -0400339 echo "ERROR: Can't find dpdk-devbind.py!"
Damjan Marion4a6cb832018-09-18 18:41:38 +0200340 echo " Run \"cd \$WS_ROOT; make install-ext-deps\" to install it."
Dave Wallace19481612017-09-15 18:47:44 -0400341 echo
342 env_test_failed="true"
343fi
344
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500345if [ -n "$full_thru_host_stack_vpp_cfg" ] && [ -n "$multi_host" ] ; then
346 echo "ERROR: Invalid options, cannot specify both \"-f\" and \"-m $multi_host\"!"
347 echo
348 env_test_failed="true"
349fi
350
Dave Wallace543852a2017-08-03 02:11:34 -0400351if [ -n "$env_test_failed" ] ; then
352 exit 1
353fi
354
Dave Wallace8af20542017-10-26 03:29:30 -0400355if [ -f "$VCL_CONFIG" ] ; then
356 vcl_config="$(basename $VCL_CONFIG)"
357 vcl_config_dir="$(dirname $VCL_CONFIG)/"
358 api_prefix="$(egrep -s '^\s*api-prefix \w+' $VCL_CONFIG | tail -1 | awk -e '{print $2}')"
Dave Wallace543852a2017-08-03 02:11:34 -0400359 if [ -n "$api_prefix" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400360 api_segment=" api-segment { gid $user_gid prefix $api_prefix }"
Dave Wallace543852a2017-08-03 02:11:34 -0400361 fi
362fi
Dave Wallace8af20542017-10-26 03:29:30 -0400363if [ -n "$VCL_APP_NAMESPACE_ID" ] && [ -n "$VCL_APP_NAMESPACE_SECRET" ] ; then
364 namespace_id="$VCL_APP_NAMESPACE_ID"
365 namespace_secret="$VCL_APP_NAMESPACE_SECRET"
366fi
367
Dave Wallace3079a642017-09-06 01:59:43 -0400368if [ -z "$api_segment" ] ; then
369 api_segment=" api-segment { gid $user_gid }"
370fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500371vpp_args="unix { interactive full-coredump coredump-size unlimited exec $tmp_vpp_exec_file}${api_segment}"
Dave Wallace543852a2017-08-03 02:11:34 -0400372
Dave Wallace30fb4a22017-08-17 16:22:04 -0400373if [ $iperf3 -eq 1 ] ; then
Dave Wallace543852a2017-08-03 02:11:34 -0400374 app_dir="$(dirname $(which iperf3))/"
375 srvr_app=$iperf_srvr_app
376 clnt_app=$iperf_clnt_app
Dave Wallace30fb4a22017-08-17 16:22:04 -0400377 if [[ $run_test =~ "docker_".* ]] ; then
378 unset -v app_dir
379 sock_srvr_port=5201
380 docker_app_dir="networkstatic/"
381 unset -v docker_os
382 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400383else
384 app_dir="$vpp_dir"
Dave Wallacede910062018-03-20 09:22:13 -0400385 srvr_app="$sock_srvr_app${sock_srvr_options} $sock_srvr_port"
Dave Wallace543852a2017-08-03 02:11:34 -0400386 clnt_app="$sock_clnt_app${sock_clnt_options} \$srvr_addr $sock_srvr_port"
387fi
388
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400389
Dave Wallace543852a2017-08-03 02:11:34 -0400390verify_no_vpp() {
Dave Wallace3d674492017-09-25 15:37:56 -0400391 local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
392
393 if [ -n "$api_prefix" ] ; then
394 grep_for_vpp="$grep_for_vpp|grep \"prefix $api_prefix\""
395 fi
396 local running_vpp="$(eval $grep_for_vpp)"
397 if [ -n "$running_vpp" ] ; then
398 echo "ERROR: Please kill the following vpp instance(s):"
Dave Wallace543852a2017-08-03 02:11:34 -0400399 echo
Dave Wallace3d674492017-09-25 15:37:56 -0400400 echo $running_vpp
Dave Wallace543852a2017-08-03 02:11:34 -0400401 echo
402 exit 1
403 fi
404 clean_devshm="$vpp_shm_dir*db $vpp_shm_dir*global_vm $vpp_shm_dir*vpe-api $vpp_shm_dir[0-9]*-[0-9]* $vpp_shm_dir*:segment[0-9]*"
Dave Wallace3d674492017-09-25 15:37:56 -0400405 sudo rm -f $clean_devshm
Dave Wallace543852a2017-08-03 02:11:34 -0400406 devshm_files="$(ls -l $clean_devshm 2>/dev/null | grep $(whoami))"
407 if [ "$devshm_files" != "" ] ; then
408 echo "ERROR: Please remove the following $vpp_shm_dir files:"
409 for file in "$devshm_files" ; do
410 echo " $file"
411 done
412 exit 1
413 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400414 if [ ! -d "$vpp_run_dir" ] ; then
415 sudo mkdir $vpp_run_dir
416 sudo chown root:$USER $vpp_run_dir
417 fi
Dave Wallacede910062018-03-20 09:22:13 -0400418 if [ $use_ipv6 -eq 0 ] && [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
419 sock_srvr_table=0
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500420 sock_srvr_addr=172.16.1.1
Dave Wallacede910062018-03-20 09:22:13 -0400421 sock_client_table=1
422 sock_client_addr=172.16.2.1
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500423 client_namespace_id="1"
424 client_namespace_secret="5678"
425 server_namespace_id="0"
426 server_namespace_secret="1234"
427 cat <<EOF >> $tmp_vpp_exec_file
428session enable
429create loop inter
430create loop inter
431set inter state loop0 up
Dave Wallacede910062018-03-20 09:22:13 -0400432set inter ip table loop0 $sock_srvr_table
433set inter ip address loop0 $sock_srvr_addr/24
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500434set inter state loop1 up
Dave Wallacede910062018-03-20 09:22:13 -0400435set inter ip table loop1 $sock_client_table
436set inter ip address loop1 $sock_client_addr/24
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500437app ns add id 0 secret 1234 sw_if_index 1
438app ns add id 1 secret 5678 sw_if_index 2
Dave Wallacede910062018-03-20 09:22:13 -0400439ip route add $sock_srvr_addr/32 table $sock_client_table via lookup in table $sock_srvr_table
440ip route add $sock_client_addr/32 table $sock_srvr_table via lookup in table $sock_client_table
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500441EOF
Dave Wallacede910062018-03-20 09:22:13 -0400442 elif [ $use_ipv6 -eq 1 ] && [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
443 sock_srvr_table=1
444 sock_srvr_addr=fd01:1::1
445 sock_client_table=2
446 sock_client_addr=fd01:2::1
447 client_namespace_id="1"
448 client_namespace_secret="5678"
449 server_namespace_id="0"
450 server_namespace_secret="1234"
451 cat <<EOF >> $tmp_vpp_exec_file
452session enable
453create loop inter
454create loop inter
455set inter state loop0 up
456set inter ip6 table loop0 $sock_srvr_table
457set inter ip address loop0 $sock_srvr_addr/64
458set inter state loop1 up
459set inter ip6 table loop1 $sock_client_table
460set inter ip address loop1 $sock_client_addr/64
461app ns add id 0 secret 1234 sw_if_index 1
462app ns add id 1 secret 5678 sw_if_index 2
463ip route add $sock_srvr_addr/128 table $sock_client_table via lookup in table $sock_srvr_table
464ip route add $sock_client_addr/128 table $sock_srvr_table via lookup in table $sock_client_table
465EOF
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500466 elif [ -n "$multi_host" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400467 vpp_eth_pci_id="$(ls -ld /sys/class/net/$vpp_eth_name/device | awk '{print $11}' | cut -d/ -f4)"
468 if [ -z "$vpp_eth_pci_id" ] ; then
469 echo "ERROR: Missing ethernet interface $vpp_eth_name!"
470 usage
471 fi
472 printf -v bus "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f2)"
473 printf -v slot "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f3 | cut -d. -f1)"
474 printf -v func "%x" "0x$(echo $vpp_eth_pci_id | cut -d. -f2)"
475
476 vpp_eth_kernel_driver="$(basename $(ls -l /sys/bus/pci/devices/$vpp_eth_pci_id/driver | awk '{print $11}'))"
477 if [ -z "$vpp_eth_kernel_driver" ] ; then
478 echo "ERROR: Missing kernel driver for $vpp_eth_name!"
479 usage
480 fi
481 case $vpp_eth_kernel_driver in
482 e1000)
483 vpp_eth_ifname="GigabitEthernet$bus/$slot/$func" ;;
484 ixgbe)
485 vpp_eth_ifname="TenGigabitEthernet$bus/$slot/$func" ;;
Dave Wallace3d674492017-09-25 15:37:56 -0400486 i40e)
487 vpp_eth_ifname="FortyGigabitEthernet$bus/$slot/$func" ;;
Dave Wallace3079a642017-09-06 01:59:43 -0400488 *)
489 echo "ERROR: Unknown ethernet kernel driver $vpp_eth_kernel_driver!"
490 usage ;;
491 esac
492
493 vpp_eth_ip4_addr="$(ip -4 -br addr show $vpp_eth_name | awk '{print $3}')"
494 if [ -z "$vpp_eth_ip4_addr" ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400495 if [ "$multi_host" = "server" ] ; then
496 vpp_eth_ip4_addr="10.10.10.10/24"
497 else
498 vpp_eth_ip4_addr="10.10.10.11/24"
499 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400500 fi
Dave Wallace3d674492017-09-25 15:37:56 -0400501 if [ $use_ipv6 -eq 1 ] && [ -z "$vpp_eth_ip6_addr" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400502 echo "ERROR: No inet6 address configured for $vpp_eth_name!"
503 usage
504 fi
Damjan Marion79dcbc72018-09-12 14:01:10 +0200505 vpp_args="$vpp_args plugins { path ${lib_dir}vpp_plugins } dpdk { dev $vpp_eth_pci_id }"
Dave Wallace3079a642017-09-06 01:59:43 -0400506
Dave Wallace3d674492017-09-25 15:37:56 -0400507 sudo ifconfig $vpp_eth_name down 2> /dev/null
Dave Wallace3079a642017-09-06 01:59:43 -0400508 echo "Configuring VPP to use $vpp_eth_name ($vpp_eth_pci_id), inet addr $vpp_eth_ip4_addr"
509
510 cat <<EOF >> $tmp_vpp_exec_file
511set int state $vpp_eth_ifname up
512set int ip addr $vpp_eth_ifname $vpp_eth_ip4_addr
513EOF
514
515 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400516
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500517 if [ -z "$full_thru_host_stack_vpp_cfg" ] && [ -n "$namespace_id" ] ; then
Dave Wallace8af20542017-10-26 03:29:30 -0400518 cat <<EOF >> $tmp_vpp_exec_file
519session enable
520app ns add id $namespace_id secret $namespace_secret sw_if_index 0
521EOF
522 fi
523
524 cat <<EOF >> $tmp_vpp_exec_file
Yalei Wang904a8502018-09-20 16:46:29 +0800525create tap id 0
526set int ip addr tap0 172.17.0.2/24
Dave Wallace8af20542017-10-26 03:29:30 -0400527show version
528show version verbose
529show cpu
530show int
531EOF
Dave Wallace543852a2017-08-03 02:11:34 -0400532}
533
534verify_no_docker_containers() {
535 if (( $(which docker | wc -l) < 1 )) ; then
536 echo "ERROR: docker is not installed!"
537 echo "See https://docs.docker.com/engine/installation/linux/ubuntu/"
538 echo " or https://docs.docker.com/engine/installation/linux/centos/"
539 exit 1
540 fi
541 if (( $(docker ps | wc -l) > 1 )) ; then
542 echo "ERROR: Run the following to kill all docker containers:"
543 echo "docker kill \$(docker ps -q)"
544 echo
545 docker ps
546 exit 1
547 fi
548}
549
550set_pre_cmd() {
551 # arguments
552 # $1 : emacs flag
553 # $2 : gdb flag
554 # $3 : optional LD_PRELOAD library pathname
555 local -i emacs=$1
556 local -i gdb=$2
557
558 if [ $emacs -eq 1 ] ; then
559 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
560 pre_cmd="$gdb_in_emacs "
561 elif [ $gdb -eq 1 ] ; then
562 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
Dave Wallace4878cbe2017-11-21 03:45:09 -0500563 pre_cmd="gdb -x $tmp_gdb_cmdfile --args "
Dave Wallace543852a2017-08-03 02:11:34 -0400564 elif [ -z $3 ] ; then
565 unset -v pre_cmd
566 else
567 docker_ld_preload="-e LD_PRELOAD=$3 "
568 pre_cmd="LD_PRELOAD=$3 "
569 fi
570}
571
572write_script_header() {
573 # arguments
574 # $1 : command script file
575 # $2 : gdb command file
576 # $3 : title
577 # $4 : optional command string (typically "sleep 2")
578 echo "$bash_header" > $1
579 echo -e "#\n# $1 generated on $(date)\n#" >> $1
580 if [ $leave_tmp_files -eq 0 ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400581 if [ -n "$multi_host" ] ; then
582 echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file; sudo $dpdk_devbind -b $vpp_eth_kernel_driver $vpp_eth_pci_id; sudo ifconfig $vpp_eth_name up\" $trap_signals" >> $1
Dave Wallace3079a642017-09-06 01:59:43 -0400583 else
584 echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file\" $trap_signals" >> $1
585 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400586 fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500587 if [ -n "$VCL_CONFIG" ] ; then
588 echo "export VCL_CONFIG=${vcl_config_dir}${vcl_config}" >> $1
589 fi
Dave Wallaceb5a86ee2018-02-16 18:26:11 -0500590 if [ -n "$VCL_API_PREFIX" ] ; then
591 echo "export VCL_API_PREFIX=$VCL_API_PREFIX" >> $1
592 fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500593 if [ -n "$VCL_DEBUG" ] ; then
594 echo "export VCL_DEBUG=$VCL_DEBUG" >> $1
595 fi
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500596 if [ -n "$LDP_DEBUG" ] ; then
597 echo "export LDP_DEBUG=$LDP_DEBUG" >> $1
Dave Wallace048b1d62018-01-03 22:24:41 -0500598 fi
599 if [ -n "$VCOM_APP_NAME" ] ; then
600 echo "export VCOM_APP_NAME=$VCOM_APP_NAME" >> $1
601 fi
602 if [ -n "$VCOM_SID_BIT" ] ; then
603 echo "export VCOM_SID_BIT=$VCOM_SID_BIT" >> $1
604 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400605 if [ -n "$namespace_id" ] ; then
606 echo "export VCL_APP_NAMESPACE_ID=\"$namespace_id\"" >> $1
607 echo "export VCL_APP_NAMESPACE_SECRET=\"$namespace_secret\"" >> $1
608 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500609 if [ -n "$VCL_APP_SCOPE_LOCAL" ] || [ -z "$multi_host" ] &&
610 [ -z "$full_thru_host_stack_vpp_cfg" ] ; then
Dave Wallace774169b2017-11-01 20:07:40 -0400611 echo "export VCL_APP_SCOPE_LOCAL=true" >> $1
Dave Wallace8af20542017-10-26 03:29:30 -0400612 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500613 if [ -n "$VCL_APP_SCOPE_GLOBAL" ] || [ -n "$multi_host" ] ||
614 [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
Dave Wallace774169b2017-11-01 20:07:40 -0400615 echo "export VCL_APP_SCOPE_GLOBAL=true" >> $1
616 fi
617 if [ -n "$VCL_APP_PROXY_TRANSPORT_TCP" ] ; then
618 echo "export VCL_APP_PROXY_TRANSPORT_TCP=true" >> $1
619 fi
620 if [ -n "$VCL_APP_PROXY_TRANSPORT_UDP" ] ; then
621 echo "export VCL_APP_PROXY_TRANSPORT_UDP=true" >> $1
Dave Wallace8af20542017-10-26 03:29:30 -0400622 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400623 if [ "$pre_cmd" = "$gdb_in_emacs " ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400624 if [ -n "$multi_host" ] && [[ $3 =~ "VPP".* ]] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400625 cat <<EOF >> $1
626$gdb_in_emacs() {
627 sudo emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
628}
629EOF
630 else
631 cat <<EOF >> $1
Dave Wallace543852a2017-08-03 02:11:34 -0400632$gdb_in_emacs() {
633 emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
634}
635EOF
Dave Wallace3079a642017-09-06 01:59:43 -0400636 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400637 fi
638 if [ -n "$4" ] ; then
639 echo "$4" >> $1
640 fi
641}
642
643write_script_footer() {
644 # arguments
645 # $1 : command script file
646 # $2 : perf flag indicating to run bash before exit
647 local -i perf=$2
648 if [ $bash_after_exit -eq 1 ] || [ $perf -eq 1 ] ; then
649 echo "bash" >> $1
650 fi
651}
652
653write_gdb_cmdfile() {
654 # arguments
655 # $1 : gdb command file
656 # $2 : User specified gdb cmdfile
657 # $3 : emacs flag
658 # $4 : optional LD_PRELOAD library pathname.
659 local -i emacs=$3
660
661 echo "# $1 generated on $(date)" > $1
662 echo "#" >> $1
663 echo "set confirm off" >> $1
664 if [ -n "$4" ] ; then
665 echo "set exec-wrapper env LD_PRELOAD=$4" >> $1
Dave Wallace59179392017-11-07 02:20:07 -0500666 # echo "start" >> $1
Dave Wallace543852a2017-08-03 02:11:34 -0400667 fi
668
669 if [ ! -f $2 ] ; then
670 echo -n "# " >> $1
671 fi
672 echo "source $2" >> $1
673 if [ $emacs -eq 0 ] ; then
674 echo "run" >> $1
675 fi
676}
677
678native_kernel() {
679 banner="Running NATIVE-KERNEL socket test"
Dave Wallace3079a642017-09-06 01:59:43 -0400680 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
681 title1="SERVER$title_dbg (Native-Kernel Socket Test)"
682 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
683 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
684 set_pre_cmd $emacs_server $gdb_server
685 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
686 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd1_file
687 write_script_footer $cmd1_file $perf_server
688 chmod +x $cmd1_file
689 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400690
Dave Wallace3079a642017-09-06 01:59:43 -0400691 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
692 title2="CLIENT$title_dbg (Native-Kernel Socket Test)"
693 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
694 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
695 set_pre_cmd $emacs_client $gdb_client
696 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
697 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd2_file
698 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd2_file
699 write_script_footer $cmd2_file $perf_client
700 chmod +x $cmd2_file
Dave Wallace543852a2017-08-03 02:11:34 -0400701
Dave Wallace3079a642017-09-06 01:59:43 -0400702 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400703}
704
705native_preload() {
706 verify_no_vpp
707 banner="Running NATIVE-PRELOAD socket test"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400708 ld_preload="$VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400709
710 title1="VPP$title_dbg (Native-Preload Socket Test)"
711 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
712 gdb_cmdfile=$VPP_GDB_CMDFILE
713 set_pre_cmd $emacs_vpp $gdb_vpp
714 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400715 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
716 echo -n "sudo " >> $cmd1_file
717 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400718 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
719 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400720 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400721
Dave Wallace3079a642017-09-06 01:59:43 -0400722 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
723 title2="SERVER$title_dbg (Native-Preload Socket Test)"
724 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
725 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
726 set_pre_cmd $emacs_server $gdb_server $ld_preload
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500727 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
728 namespace_id="$server_namespace_id"
729 namespace_secret="$server_namespace_secret"
730 fi
Dave Wallacede910062018-03-20 09:22:13 -0400731 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 3"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200732 echo "export LD_LIBRARY_PATH=\"$lib_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400733 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
734 write_script_footer $cmd2_file $perf_server
735 chmod +x $cmd2_file
736 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400737
Dave Wallace3079a642017-09-06 01:59:43 -0400738 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
739 title3="CLIENT$title_dbg (Native-Preload Socket Test)"
740 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
741 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
742 set_pre_cmd $emacs_client $gdb_client $ld_preload
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500743 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
744 namespace_id="$client_namespace_id"
745 namespace_secret="$client_namespace_secret"
746 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400747 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 4"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200748 echo "export LD_LIBRARY_PATH=\"$lib_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400749 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
750 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
751 write_script_footer $cmd3_file $perf_client
752 chmod +x $cmd3_file
753 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400754}
755
756native_vcl() {
757 verify_no_vpp
758 banner="Running NATIVE-VCL socket test"
759
760 title1="VPP$title_dbg (Native-VCL Socket Test)"
761 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
762 gdb_cmdfile=$VPP_GDB_CMDFILE
763 set_pre_cmd $emacs_vpp $gdb_vpp
764 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400765 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
766 echo -n "sudo " >> $cmd1_file
767 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400768 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
769 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400770 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400771
Dave Wallace3079a642017-09-06 01:59:43 -0400772 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
773 title2="SERVER$title_dbg (Native-VCL Socket Test)"
774 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
775 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
776 set_pre_cmd $emacs_server $gdb_server
Dave Wallace3d674492017-09-25 15:37:56 -0400777 if [ "$multi_host" = "server" ] ; then
778 delay="sleep 10"
779 else
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500780 delay="sleep 3"
781 fi
782 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
783 namespace_id="$server_namespace_id"
784 namespace_secret="$server_namespace_secret"
Dave Wallace3d674492017-09-25 15:37:56 -0400785 fi
786 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "$delay"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200787 echo "export LD_LIBRARY_PATH=\"$lib_dir:$LD_LIBRARY_PATH\"" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400788 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
789 write_script_footer $cmd2_file $perf_server
790 chmod +x $cmd2_file
791 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400792
Dave Wallace3079a642017-09-06 01:59:43 -0400793 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
794 title3="CLIENT$title_dbg (Native-VCL Socket Test)"
795 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
796 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
797 set_pre_cmd $emacs_client $gdb_client
Dave Wallace3d674492017-09-25 15:37:56 -0400798 if [ "$multi_host" = "client" ] ; then
799 delay="sleep 10"
800 else
Dave Wallace8af20542017-10-26 03:29:30 -0400801 delay="sleep 4"
Dave Wallace3d674492017-09-25 15:37:56 -0400802 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500803 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
804 namespace_id="$client_namespace_id"
805 namespace_secret="$client_namespace_secret"
806 fi
Dave Wallace3d674492017-09-25 15:37:56 -0400807 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "$delay"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200808 echo "export LD_LIBRARY_PATH=\"$lib_dir:$LD_LIBRARY_PATH\"" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400809 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
810 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
811 write_script_footer $cmd3_file $perf_client
812 chmod +x $cmd3_file
813 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400814}
815
816docker_kernel() {
817 verify_no_docker_containers
818 banner="Running DOCKER-KERNEL socket test"
819
Dave Wallace3079a642017-09-06 01:59:43 -0400820 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
821 title1="SERVER$title_dbg (Docker-Native Socket Test)"
822 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
823 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
824 set_pre_cmd $emacs_server $gdb_server
825 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
826 echo "docker run -it --cpuset-cpus='4-7' --cpuset-cpus='4-7' -v $vpp_dir:$docker_vpp_dir -p $sock_srvr_port:$sock_srvr_port $docker_os ${docker_app_dir}${srvr_app}" >> $cmd1_file
827 write_script_footer $cmd1_file $perf_server
828 chmod +x $cmd1_file
829 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400830
Dave Wallace3079a642017-09-06 01:59:43 -0400831 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
832 title2="CLIENT$title_dbg (Docker-Native Socket Test)"
833 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
834 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
835 set_pre_cmd $emacs_client $gdb_client
836 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
837 echo "$get_docker_server_ip4addr" >> $cmd2_file
838 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_dir:$docker_vpp_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd2_file
839 write_script_footer $cmd2_file $perf_client
840 chmod +x $cmd2_file
841 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400842}
843
844docker_preload() {
845 verify_no_vpp
846 verify_no_docker_containers
847 banner="Running DOCKER-PRELOAD socket test"
Dave Wallace30fb4a22017-08-17 16:22:04 -0400848 docker_ld_preload_dir="/vcl-ldpreload/"
849 ld_preload_dir="$VCL_LDPRELOAD_LIB_DIR"
850 ld_preload="$docker_ld_preload_dir$vcl_ldpreload_lib "
851 docker_ld_preload_lib="$docker_ld_preload_dir$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400852
853 title1="VPP$title_dbg (Docker-Preload Socket Test)"
854 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
855 gdb_cmdfile=$VPP_GDB_CMDFILE
856 set_pre_cmd $emacs_vpp $gdb_vpp
857 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400858 if [ -n "$multi_host" ] ; then
859 echo -n "sudo " >> $cmd1_file
860 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400861 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
862 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400863 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400864
Dave Wallace3079a642017-09-06 01:59:43 -0400865 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
866 title2="SERVER$title_dbg (Docker-Preload Socket Test)"
867 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
868 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
869 set_pre_cmd $emacs_server $gdb_server $docker_ld_preload_lib
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500870 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
871 namespace_id="$server_namespace_id"
872 namespace_secret="$server_namespace_secret"
873 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400874 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200875 echo "docker run -it -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib_dir:$docker_lib_dir -v $ld_preload_dir:$docker_ld_preload_dir -v $vcl_config_dir:$docker_vcl_config_dir -p $sock_srvr_port:$sock_srvr_port -e VCL_DEBUG=$VCL_DEBUG -e VCL_CONFIG=${docker_vcl_config_dir}$vcl_config -e LD_LIBRARY_PATH=$docker_lib_dir:$docker_ld_preload_dir ${docker_ld_preload}$docker_os ${docker_app_dir}${srvr_app}" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400876 write_script_footer $cmd2_file $perf_server
877 chmod +x $cmd2_file
878 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400879
Dave Wallace3079a642017-09-06 01:59:43 -0400880 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
881 title3="CLIENT$title_dbg (Docker-Preload Socket Test)"
882 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
883 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
884 set_pre_cmd $emacs_client $gdb_client $docker_ld_preload_lib
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500885 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
886 namespace_id="$client_namespace_id"
887 namespace_secret="$client_namespace_secret"
888 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400889 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 4"
Dave Wallace3079a642017-09-06 01:59:43 -0400890 echo "$get_docker_server_ip4addr" >> $cmd3_file
Damjan Marion79dcbc72018-09-12 14:01:10 +0200891 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib_dir:$docker_lib_dir -v $ld_preload_dir:$docker_ld_preload_dir -v $vcl_config_dir:$docker_vcl_config_dir -e VCL_DEBUG=$VCL_DEBUG -e VCL_CONFIG=${docker_vcl_config_dir}$vcl_config -e LD_LIBRARY_PATH=$docker_lib_dir ${docker_ld_preload}$docker_os ${docker_app_dir}${clnt_app}" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400892 write_script_footer $cmd3_file $perf_client
893 chmod +x $cmd3_file
894 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400895}
896
897docker_vcl() {
898 verify_no_vpp
899 verify_no_docker_containers
900 banner="Running DOCKER-VCL socket test"
901
902 title1="VPP$title_dbg (Docker-VCL Socket Test)"
903 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
904 gdb_cmdfile=$VPP_GDB_CMDFILE
905 set_pre_cmd $emacs_vpp $gdb_vpp
906 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400907 if [ -n "$multi_host" ] ; then
908 echo -n "sudo " >> $cmd1_file
909 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400910 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
911 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400912 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400913
Dave Wallace3079a642017-09-06 01:59:43 -0400914 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
915 title2="SERVER$title_dbg (Docker-VCL Socket Test)"
916 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
917 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
918 set_pre_cmd $emacs_server $gdb_server
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500919 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
920 namespace_id="$server_namespace_id"
921 namespace_secret="$server_namespace_secret"
922 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400923 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200924 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib_dir:$docker_lib_dir -v $vcl_config_dir:$docker_vcl_config_dir -p $sock_srvr_port:$sock_srvr_port -e VCL_CONFIG=${docker_vcl_config_dir}/$vcl_config -e LD_LIBRARY_PATH=$docker_lib_dir $docker_os ${docker_app_dir}${srvr_app}" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400925 write_script_footer $cmd2_file $perf_server
926 chmod +x $cmd2_file
927 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400928
Dave Wallace3079a642017-09-06 01:59:43 -0400929 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
930 title3="CLIENT$title_dbg (Docker-VCL Socket Test)"
931 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
932 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
933 set_pre_cmd $emacs_client $gdb_client
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500934 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
935 namespace_id="$client_namespace_id"
936 namespace_secret="$client_namespace_secret"
937 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400938 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
939 echo "$get_docker_server_ip4addr" >> $cmd3_file
Damjan Marion79dcbc72018-09-12 14:01:10 +0200940 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_shm_dir:$vpp_shm_dir -v $vpp_dir:$docker_vpp_dir -v $lib_dir:$docker_lib_dir -v $vcl_config_dir:$docker_vcl_config_dir -e VCL_CONFIG=${docker_vcl_config_dir}/$vcl_config -e LD_LIBRARY_PATH=$docker_lib_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400941 write_script_footer $cmd3_file $perf_client
942 chmod +x $cmd3_file
943 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400944}
945
946if [[ $run_test ]] ; then
947 eval $run_test
948else
949 echo "ERROR: Please specify a test to run!" >&2
950 usage;
951fi
952
953if (( $(which xfce4-terminal | wc -l) > 0 )) ; then
954 xterm_cmd="xfce4-terminal --geometry $xterm_geom"
955 if [[ $use_tabs ]] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400956 declare -a tab_cmd_files
957 declare -a tab_titles
958 declare -i i=0
959
960 if [ -x "$cmd1_file" ] ; then
961 tab_cmd_files[$i]="$cmd1_file"
962 tab_titles[$i]="$title1"
963 (( i++ ))
Dave Wallace543852a2017-08-03 02:11:34 -0400964 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400965 if [ -x "$cmd2_file" ] ; then
966 tab_cmd_files[$i]="$cmd2_file"
967 tab_titles[$i]="$title2"
968 (( i++ ))
969 fi
970 if [ -x "$cmd3_file" ] ; then
971 tab_cmd_files[$i]="$cmd3_file"
972 tab_titles[$i]="$title3"
973 fi
974
975 if [ -n "${tab_cmd_files[2]}" ] ; then
976 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}" --tab --title "${tab_titles[1]}" --command "${tab_cmd_files[1]}" --tab --title "${tab_titles[2]}" --command "${tab_cmd_files[2]}"
977 elif [ -n "${tab_cmd_files[1]}" ] ; then
978 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}" --tab --title "${tab_titles[1]}" --command "${tab_cmd_files[1]}"
979
980 else
981 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}"
982 fi
983
Dave Wallace543852a2017-08-03 02:11:34 -0400984 else
Dave Wallace3079a642017-09-06 01:59:43 -0400985 if [ -x "$cmd1_file" ] ; then
986 ($xterm_cmd --title "$title1" --command "$cmd1_file" &)
987 fi
988 if [ -x "$cmd2_file" ] ; then
989 ($xterm_cmd --title "$title2" --command "$cmd2_file" &)
990 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400991 if [ -x "$cmd3_file" ] ; then
992 ($xterm_cmd --title "$title3" --command "$cmd3_file" &)
993 fi
994 fi
995
996else
997 if [[ $use_tabs ]] ; then
998 echo "Sorry, plain ol' xterm doesn't support tabs."
999 fi
1000 xterm_cmd="xterm -fs 10 -geometry $xterm_geom"
Dave Wallace3079a642017-09-06 01:59:43 -04001001 if [ -x "$cmd1_file" ] ; then
1002 ($xterm_cmd -title "$title1" -e "$cmd1_file" &)
1003 fi
1004 if [ -x "$cmd2_file" ] ; then
1005 ($xterm_cmd -title "$title2" -e "$cmd2_file" &)
1006 fi
Dave Wallace543852a2017-08-03 02:11:34 -04001007 if [ -x "$cmd3_file" ] ; then
1008 ($xterm_cmd -title "$title3" -e "$cmd3_file" &)
1009 fi
1010fi
1011
1012sleep 1