blob: f408ad44d8270876863b0c1ad4c1c0813741617a [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 Wallace19481612017-09-15 18:47:44 -040012dpdk_devbind="/usr/share/dpdk/usertools/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 Wallace4f6c3a92017-10-24 15:39:44 -0400273if [[ "$(grep bin_PROGRAMS $WS_ROOT/src/vcl.am)" = "" ]] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400274 $WS_ROOT/extras/vagrant/vcl_test.sh $WS_ROOT $USER
275 (cd $WS_ROOT; make build)
276fi
277
Dave Wallace543852a2017-08-03 02:11:34 -0400278if [ ! -d $vpp_dir ] ; then
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400279 echo "ERROR: Missing VPP$title_dbg bin directory!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400280 echo " $vpp_dir" >&2
281 env_test_failed="true"
282fi
283
284if [[ $run_test =~ .*"_preload" ]] ; then
Damjan Marion79dcbc72018-09-12 14:01:10 +0200285 if [ ! -d $lib_dir ] ; then
286 echo "ERROR: Missing VPP$title_dbg lib directory!" >&2
287 echo " $lib_dir" >&2
Dave Wallaced69f4f42017-08-14 18:26:46 -0400288 elif [ ! -d $VCL_LDPRELOAD_LIB_DIR ] ; then
289 echo "ERROR: Missing VCL LD_PRELOAD Library directory!" >&2
290 echo " $VCL_LDPRELOAD_LIB_DIR" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400291 env_test_failed="true"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400292 elif [ ! -f $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib ] ; then
293 echo "ERROR: Missing VCL LD_PRELOAD library!" >&2
294 echo " $VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400295 env_test_failed="true"
296 fi
297fi
298
299if [ ! -f $vpp_dir$vpp_app ] ; then
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400300 echo "ERROR: Missing VPP$title_dbg Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400301 echo " $vpp_dir$vpp_app" >&2
302 env_test_failed="true"
303fi
304
Dave Wallace30fb4a22017-08-17 16:22:04 -0400305if [ ! -f $vpp_dir$sock_srvr_app ] && [ ! $iperf3 -eq 1 ] ; then
Yalei Wang904a8502018-09-20 16:46:29 +0800306 echo "ERROR: Missing SERVER$title_dbg Socket Server Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400307 echo " $vpp_dir$sock_srvr_app" >&2
308 env_test_failed="true"
309fi
310
Dave Wallace30fb4a22017-08-17 16:22:04 -0400311if [ ! -f $vpp_dir$sock_clnt_app ] && [ ! $iperf3 -eq 1 ] ; then
Yalei Wang904a8502018-09-20 16:46:29 +0800312 echo "ERROR: Missing CLIENT$title_dbg Socket Client Application!" >&2
Dave Wallace543852a2017-08-03 02:11:34 -0400313 echo " $vpp_dir$sock_clnt_app" >&2
314 env_test_failed="true"
315fi
316
317if [[ $run_test =~ "docker_".* ]] ; then
318 if [ $emacs_client -eq 1 ] || [ $emacs_server -eq 1 ] || [ $gdb_client -eq 1 ] || [ $gdb_server -eq 1 ] ; then
319
320 echo "WARNING: gdb is not currently supported in docker."
321 echo " Ignoring client/server gdb options."
322 emacs_client=0
323 emacs_server=0
324 gdb_client=0
325 gdb_server=0
326 fi
327fi
328
Dave Wallace30fb4a22017-08-17 16:22:04 -0400329if [[ $run_test =~ .*"_vcl" ]] && [ $iperf3 -eq 1 ] ; then
330 echo "ERROR: Invalid option 'i' for test $run_test!"
331 echo " iperf3 is not compiled with the VCL library."
332 env_test_failed="true"
333fi
334
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500335if [ -n "$multi_host"] && [ ! -f "$dpdk_devbind" ] ; then
Dave Wallace19481612017-09-15 18:47:44 -0400336 echo "ERROR: Can't find dpdk-devbind.py!"
Damjan Marion4a6cb832018-09-18 18:41:38 +0200337 echo " Run \"cd \$WS_ROOT; make install-ext-deps\" to install it."
Dave Wallace19481612017-09-15 18:47:44 -0400338 echo
339 env_test_failed="true"
340fi
341
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500342if [ -n "$full_thru_host_stack_vpp_cfg" ] && [ -n "$multi_host" ] ; then
343 echo "ERROR: Invalid options, cannot specify both \"-f\" and \"-m $multi_host\"!"
344 echo
345 env_test_failed="true"
346fi
347
Dave Wallace543852a2017-08-03 02:11:34 -0400348if [ -n "$env_test_failed" ] ; then
349 exit 1
350fi
351
Dave Wallace8af20542017-10-26 03:29:30 -0400352if [ -f "$VCL_CONFIG" ] ; then
353 vcl_config="$(basename $VCL_CONFIG)"
354 vcl_config_dir="$(dirname $VCL_CONFIG)/"
355 api_prefix="$(egrep -s '^\s*api-prefix \w+' $VCL_CONFIG | tail -1 | awk -e '{print $2}')"
Dave Wallace543852a2017-08-03 02:11:34 -0400356 if [ -n "$api_prefix" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400357 api_segment=" api-segment { gid $user_gid prefix $api_prefix }"
Dave Wallace543852a2017-08-03 02:11:34 -0400358 fi
359fi
Dave Wallace8af20542017-10-26 03:29:30 -0400360if [ -n "$VCL_APP_NAMESPACE_ID" ] && [ -n "$VCL_APP_NAMESPACE_SECRET" ] ; then
361 namespace_id="$VCL_APP_NAMESPACE_ID"
362 namespace_secret="$VCL_APP_NAMESPACE_SECRET"
363fi
364
Dave Wallace3079a642017-09-06 01:59:43 -0400365if [ -z "$api_segment" ] ; then
366 api_segment=" api-segment { gid $user_gid }"
367fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500368vpp_args="unix { interactive full-coredump coredump-size unlimited exec $tmp_vpp_exec_file}${api_segment}"
Dave Wallace543852a2017-08-03 02:11:34 -0400369
Dave Wallace30fb4a22017-08-17 16:22:04 -0400370if [ $iperf3 -eq 1 ] ; then
Dave Wallace543852a2017-08-03 02:11:34 -0400371 app_dir="$(dirname $(which iperf3))/"
372 srvr_app=$iperf_srvr_app
373 clnt_app=$iperf_clnt_app
Dave Wallace30fb4a22017-08-17 16:22:04 -0400374 if [[ $run_test =~ "docker_".* ]] ; then
375 unset -v app_dir
376 sock_srvr_port=5201
377 docker_app_dir="networkstatic/"
378 unset -v docker_os
379 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400380else
381 app_dir="$vpp_dir"
Dave Wallacede910062018-03-20 09:22:13 -0400382 srvr_app="$sock_srvr_app${sock_srvr_options} $sock_srvr_port"
Dave Wallace543852a2017-08-03 02:11:34 -0400383 clnt_app="$sock_clnt_app${sock_clnt_options} \$srvr_addr $sock_srvr_port"
384fi
385
Dave Wallace5c7cf1c2017-10-24 04:12:18 -0400386
Dave Wallace543852a2017-08-03 02:11:34 -0400387verify_no_vpp() {
Dave Wallace3d674492017-09-25 15:37:56 -0400388 local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
389
390 if [ -n "$api_prefix" ] ; then
391 grep_for_vpp="$grep_for_vpp|grep \"prefix $api_prefix\""
392 fi
393 local running_vpp="$(eval $grep_for_vpp)"
394 if [ -n "$running_vpp" ] ; then
395 echo "ERROR: Please kill the following vpp instance(s):"
Dave Wallace543852a2017-08-03 02:11:34 -0400396 echo
Dave Wallace3d674492017-09-25 15:37:56 -0400397 echo $running_vpp
Dave Wallace543852a2017-08-03 02:11:34 -0400398 echo
399 exit 1
400 fi
401 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 -0400402 sudo rm -f $clean_devshm
Dave Wallace543852a2017-08-03 02:11:34 -0400403 devshm_files="$(ls -l $clean_devshm 2>/dev/null | grep $(whoami))"
404 if [ "$devshm_files" != "" ] ; then
405 echo "ERROR: Please remove the following $vpp_shm_dir files:"
406 for file in "$devshm_files" ; do
407 echo " $file"
408 done
409 exit 1
410 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400411 if [ ! -d "$vpp_run_dir" ] ; then
412 sudo mkdir $vpp_run_dir
413 sudo chown root:$USER $vpp_run_dir
414 fi
Dave Wallacede910062018-03-20 09:22:13 -0400415 if [ $use_ipv6 -eq 0 ] && [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
416 sock_srvr_table=0
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500417 sock_srvr_addr=172.16.1.1
Dave Wallacede910062018-03-20 09:22:13 -0400418 sock_client_table=1
419 sock_client_addr=172.16.2.1
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500420 client_namespace_id="1"
421 client_namespace_secret="5678"
422 server_namespace_id="0"
423 server_namespace_secret="1234"
424 cat <<EOF >> $tmp_vpp_exec_file
425session enable
426create loop inter
427create loop inter
428set inter state loop0 up
Dave Wallacede910062018-03-20 09:22:13 -0400429set inter ip table loop0 $sock_srvr_table
430set inter ip address loop0 $sock_srvr_addr/24
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500431set inter state loop1 up
Dave Wallacede910062018-03-20 09:22:13 -0400432set inter ip table loop1 $sock_client_table
433set inter ip address loop1 $sock_client_addr/24
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500434app ns add id 0 secret 1234 sw_if_index 1
435app ns add id 1 secret 5678 sw_if_index 2
Dave Wallacede910062018-03-20 09:22:13 -0400436ip route add $sock_srvr_addr/32 table $sock_client_table via lookup in table $sock_srvr_table
437ip route add $sock_client_addr/32 table $sock_srvr_table via lookup in table $sock_client_table
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500438EOF
Dave Wallacede910062018-03-20 09:22:13 -0400439 elif [ $use_ipv6 -eq 1 ] && [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
440 sock_srvr_table=1
441 sock_srvr_addr=fd01:1::1
442 sock_client_table=2
443 sock_client_addr=fd01:2::1
444 client_namespace_id="1"
445 client_namespace_secret="5678"
446 server_namespace_id="0"
447 server_namespace_secret="1234"
448 cat <<EOF >> $tmp_vpp_exec_file
449session enable
450create loop inter
451create loop inter
452set inter state loop0 up
453set inter ip6 table loop0 $sock_srvr_table
454set inter ip address loop0 $sock_srvr_addr/64
455set inter state loop1 up
456set inter ip6 table loop1 $sock_client_table
457set inter ip address loop1 $sock_client_addr/64
458app ns add id 0 secret 1234 sw_if_index 1
459app ns add id 1 secret 5678 sw_if_index 2
460ip route add $sock_srvr_addr/128 table $sock_client_table via lookup in table $sock_srvr_table
461ip route add $sock_client_addr/128 table $sock_srvr_table via lookup in table $sock_client_table
462EOF
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500463 elif [ -n "$multi_host" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400464 vpp_eth_pci_id="$(ls -ld /sys/class/net/$vpp_eth_name/device | awk '{print $11}' | cut -d/ -f4)"
465 if [ -z "$vpp_eth_pci_id" ] ; then
466 echo "ERROR: Missing ethernet interface $vpp_eth_name!"
467 usage
468 fi
469 printf -v bus "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f2)"
470 printf -v slot "%x" "0x$(echo $vpp_eth_pci_id | cut -d: -f3 | cut -d. -f1)"
471 printf -v func "%x" "0x$(echo $vpp_eth_pci_id | cut -d. -f2)"
472
473 vpp_eth_kernel_driver="$(basename $(ls -l /sys/bus/pci/devices/$vpp_eth_pci_id/driver | awk '{print $11}'))"
474 if [ -z "$vpp_eth_kernel_driver" ] ; then
475 echo "ERROR: Missing kernel driver for $vpp_eth_name!"
476 usage
477 fi
478 case $vpp_eth_kernel_driver in
479 e1000)
480 vpp_eth_ifname="GigabitEthernet$bus/$slot/$func" ;;
481 ixgbe)
482 vpp_eth_ifname="TenGigabitEthernet$bus/$slot/$func" ;;
Dave Wallace3d674492017-09-25 15:37:56 -0400483 i40e)
484 vpp_eth_ifname="FortyGigabitEthernet$bus/$slot/$func" ;;
Dave Wallace3079a642017-09-06 01:59:43 -0400485 *)
486 echo "ERROR: Unknown ethernet kernel driver $vpp_eth_kernel_driver!"
487 usage ;;
488 esac
489
490 vpp_eth_ip4_addr="$(ip -4 -br addr show $vpp_eth_name | awk '{print $3}')"
491 if [ -z "$vpp_eth_ip4_addr" ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400492 if [ "$multi_host" = "server" ] ; then
493 vpp_eth_ip4_addr="10.10.10.10/24"
494 else
495 vpp_eth_ip4_addr="10.10.10.11/24"
496 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400497 fi
Dave Wallace3d674492017-09-25 15:37:56 -0400498 if [ $use_ipv6 -eq 1 ] && [ -z "$vpp_eth_ip6_addr" ] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400499 echo "ERROR: No inet6 address configured for $vpp_eth_name!"
500 usage
501 fi
Damjan Marion79dcbc72018-09-12 14:01:10 +0200502 vpp_args="$vpp_args plugins { path ${lib_dir}vpp_plugins } dpdk { dev $vpp_eth_pci_id }"
Dave Wallace3079a642017-09-06 01:59:43 -0400503
Dave Wallace3d674492017-09-25 15:37:56 -0400504 sudo ifconfig $vpp_eth_name down 2> /dev/null
Dave Wallace3079a642017-09-06 01:59:43 -0400505 echo "Configuring VPP to use $vpp_eth_name ($vpp_eth_pci_id), inet addr $vpp_eth_ip4_addr"
506
507 cat <<EOF >> $tmp_vpp_exec_file
508set int state $vpp_eth_ifname up
509set int ip addr $vpp_eth_ifname $vpp_eth_ip4_addr
510EOF
511
512 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400513
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500514 if [ -z "$full_thru_host_stack_vpp_cfg" ] && [ -n "$namespace_id" ] ; then
Dave Wallace8af20542017-10-26 03:29:30 -0400515 cat <<EOF >> $tmp_vpp_exec_file
516session enable
517app ns add id $namespace_id secret $namespace_secret sw_if_index 0
518EOF
519 fi
520
521 cat <<EOF >> $tmp_vpp_exec_file
Yalei Wang904a8502018-09-20 16:46:29 +0800522create tap id 0
523set int ip addr tap0 172.17.0.2/24
Dave Wallace8af20542017-10-26 03:29:30 -0400524show version
525show version verbose
526show cpu
527show int
528EOF
Dave Wallace543852a2017-08-03 02:11:34 -0400529}
530
531verify_no_docker_containers() {
532 if (( $(which docker | wc -l) < 1 )) ; then
533 echo "ERROR: docker is not installed!"
534 echo "See https://docs.docker.com/engine/installation/linux/ubuntu/"
535 echo " or https://docs.docker.com/engine/installation/linux/centos/"
536 exit 1
537 fi
538 if (( $(docker ps | wc -l) > 1 )) ; then
539 echo "ERROR: Run the following to kill all docker containers:"
540 echo "docker kill \$(docker ps -q)"
541 echo
542 docker ps
543 exit 1
544 fi
545}
546
547set_pre_cmd() {
548 # arguments
549 # $1 : emacs flag
550 # $2 : gdb flag
551 # $3 : optional LD_PRELOAD library pathname
552 local -i emacs=$1
553 local -i gdb=$2
554
555 if [ $emacs -eq 1 ] ; then
556 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
557 pre_cmd="$gdb_in_emacs "
558 elif [ $gdb -eq 1 ] ; then
559 write_gdb_cmdfile $tmp_gdb_cmdfile $gdb_cmdfile $emacs $3
Dave Wallace4878cbe2017-11-21 03:45:09 -0500560 pre_cmd="gdb -x $tmp_gdb_cmdfile --args "
Dave Wallace543852a2017-08-03 02:11:34 -0400561 elif [ -z $3 ] ; then
562 unset -v pre_cmd
563 else
564 docker_ld_preload="-e LD_PRELOAD=$3 "
565 pre_cmd="LD_PRELOAD=$3 "
566 fi
567}
568
569write_script_header() {
570 # arguments
571 # $1 : command script file
572 # $2 : gdb command file
573 # $3 : title
574 # $4 : optional command string (typically "sleep 2")
575 echo "$bash_header" > $1
576 echo -e "#\n# $1 generated on $(date)\n#" >> $1
577 if [ $leave_tmp_files -eq 0 ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400578 if [ -n "$multi_host" ] ; then
579 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 -0400580 else
581 echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file\" $trap_signals" >> $1
582 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400583 fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500584 if [ -n "$VCL_CONFIG" ] ; then
585 echo "export VCL_CONFIG=${vcl_config_dir}${vcl_config}" >> $1
586 fi
Dave Wallaceb5a86ee2018-02-16 18:26:11 -0500587 if [ -n "$VCL_API_PREFIX" ] ; then
588 echo "export VCL_API_PREFIX=$VCL_API_PREFIX" >> $1
589 fi
Dave Wallace498b3a52017-11-09 13:00:34 -0500590 if [ -n "$VCL_DEBUG" ] ; then
591 echo "export VCL_DEBUG=$VCL_DEBUG" >> $1
592 fi
Dave Wallace3ee1fe12018-02-23 01:09:11 -0500593 if [ -n "$LDP_DEBUG" ] ; then
594 echo "export LDP_DEBUG=$LDP_DEBUG" >> $1
Dave Wallace048b1d62018-01-03 22:24:41 -0500595 fi
596 if [ -n "$VCOM_APP_NAME" ] ; then
597 echo "export VCOM_APP_NAME=$VCOM_APP_NAME" >> $1
598 fi
599 if [ -n "$VCOM_SID_BIT" ] ; then
600 echo "export VCOM_SID_BIT=$VCOM_SID_BIT" >> $1
601 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400602 if [ -n "$namespace_id" ] ; then
603 echo "export VCL_APP_NAMESPACE_ID=\"$namespace_id\"" >> $1
604 echo "export VCL_APP_NAMESPACE_SECRET=\"$namespace_secret\"" >> $1
605 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500606 if [ -n "$VCL_APP_SCOPE_LOCAL" ] || [ -z "$multi_host" ] &&
607 [ -z "$full_thru_host_stack_vpp_cfg" ] ; then
Dave Wallace774169b2017-11-01 20:07:40 -0400608 echo "export VCL_APP_SCOPE_LOCAL=true" >> $1
Dave Wallace8af20542017-10-26 03:29:30 -0400609 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500610 if [ -n "$VCL_APP_SCOPE_GLOBAL" ] || [ -n "$multi_host" ] ||
611 [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
Dave Wallace774169b2017-11-01 20:07:40 -0400612 echo "export VCL_APP_SCOPE_GLOBAL=true" >> $1
613 fi
614 if [ -n "$VCL_APP_PROXY_TRANSPORT_TCP" ] ; then
615 echo "export VCL_APP_PROXY_TRANSPORT_TCP=true" >> $1
616 fi
617 if [ -n "$VCL_APP_PROXY_TRANSPORT_UDP" ] ; then
618 echo "export VCL_APP_PROXY_TRANSPORT_UDP=true" >> $1
Dave Wallace8af20542017-10-26 03:29:30 -0400619 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400620 if [ "$pre_cmd" = "$gdb_in_emacs " ] ; then
Dave Wallace3d674492017-09-25 15:37:56 -0400621 if [ -n "$multi_host" ] && [[ $3 =~ "VPP".* ]] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400622 cat <<EOF >> $1
623$gdb_in_emacs() {
624 sudo emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
625}
626EOF
627 else
628 cat <<EOF >> $1
Dave Wallace543852a2017-08-03 02:11:34 -0400629$gdb_in_emacs() {
630 emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
631}
632EOF
Dave Wallace3079a642017-09-06 01:59:43 -0400633 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400634 fi
635 if [ -n "$4" ] ; then
636 echo "$4" >> $1
637 fi
638}
639
640write_script_footer() {
641 # arguments
642 # $1 : command script file
643 # $2 : perf flag indicating to run bash before exit
644 local -i perf=$2
645 if [ $bash_after_exit -eq 1 ] || [ $perf -eq 1 ] ; then
646 echo "bash" >> $1
647 fi
648}
649
650write_gdb_cmdfile() {
651 # arguments
652 # $1 : gdb command file
653 # $2 : User specified gdb cmdfile
654 # $3 : emacs flag
655 # $4 : optional LD_PRELOAD library pathname.
656 local -i emacs=$3
657
658 echo "# $1 generated on $(date)" > $1
659 echo "#" >> $1
660 echo "set confirm off" >> $1
661 if [ -n "$4" ] ; then
662 echo "set exec-wrapper env LD_PRELOAD=$4" >> $1
Dave Wallace59179392017-11-07 02:20:07 -0500663 # echo "start" >> $1
Dave Wallace543852a2017-08-03 02:11:34 -0400664 fi
665
666 if [ ! -f $2 ] ; then
667 echo -n "# " >> $1
668 fi
669 echo "source $2" >> $1
670 if [ $emacs -eq 0 ] ; then
671 echo "run" >> $1
672 fi
673}
674
675native_kernel() {
676 banner="Running NATIVE-KERNEL socket test"
Dave Wallace3079a642017-09-06 01:59:43 -0400677 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
678 title1="SERVER$title_dbg (Native-Kernel Socket Test)"
679 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
680 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
681 set_pre_cmd $emacs_server $gdb_server
682 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
683 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd1_file
684 write_script_footer $cmd1_file $perf_server
685 chmod +x $cmd1_file
686 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400687
Dave Wallace3079a642017-09-06 01:59:43 -0400688 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
689 title2="CLIENT$title_dbg (Native-Kernel Socket Test)"
690 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
691 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
692 set_pre_cmd $emacs_client $gdb_client
693 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
694 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd2_file
695 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd2_file
696 write_script_footer $cmd2_file $perf_client
697 chmod +x $cmd2_file
Dave Wallace543852a2017-08-03 02:11:34 -0400698
Dave Wallace3079a642017-09-06 01:59:43 -0400699 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400700}
701
702native_preload() {
703 verify_no_vpp
704 banner="Running NATIVE-PRELOAD socket test"
Dave Wallaced69f4f42017-08-14 18:26:46 -0400705 ld_preload="$VCL_LDPRELOAD_LIB_DIR/$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400706
707 title1="VPP$title_dbg (Native-Preload Socket Test)"
708 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
709 gdb_cmdfile=$VPP_GDB_CMDFILE
710 set_pre_cmd $emacs_vpp $gdb_vpp
711 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400712 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
713 echo -n "sudo " >> $cmd1_file
714 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400715 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
716 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400717 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400718
Dave Wallace3079a642017-09-06 01:59:43 -0400719 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
720 title2="SERVER$title_dbg (Native-Preload Socket Test)"
721 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
722 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
723 set_pre_cmd $emacs_server $gdb_server $ld_preload
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500724 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
725 namespace_id="$server_namespace_id"
726 namespace_secret="$server_namespace_secret"
727 fi
Dave Wallacede910062018-03-20 09:22:13 -0400728 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 3"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200729 echo "export LD_LIBRARY_PATH=\"$lib_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400730 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
731 write_script_footer $cmd2_file $perf_server
732 chmod +x $cmd2_file
733 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400734
Dave Wallace3079a642017-09-06 01:59:43 -0400735 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
736 title3="CLIENT$title_dbg (Native-Preload Socket Test)"
737 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
738 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
739 set_pre_cmd $emacs_client $gdb_client $ld_preload
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500740 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
741 namespace_id="$client_namespace_id"
742 namespace_secret="$client_namespace_secret"
743 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400744 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 4"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200745 echo "export LD_LIBRARY_PATH=\"$lib_dir:$VCL_LDPRELOAD_LIB_DIR:$LD_LIBRARY_PATH\"" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400746 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
747 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
748 write_script_footer $cmd3_file $perf_client
749 chmod +x $cmd3_file
750 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400751}
752
753native_vcl() {
754 verify_no_vpp
755 banner="Running NATIVE-VCL socket test"
756
757 title1="VPP$title_dbg (Native-VCL Socket Test)"
758 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
759 gdb_cmdfile=$VPP_GDB_CMDFILE
760 set_pre_cmd $emacs_vpp $gdb_vpp
761 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400762 if [ -n "$multi_host" ] && [ $emacs_vpp -eq 0 ] ; then
763 echo -n "sudo " >> $cmd1_file
764 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400765 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args " >> $cmd1_file
766 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400767 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400768
Dave Wallace3079a642017-09-06 01:59:43 -0400769 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
770 title2="SERVER$title_dbg (Native-VCL Socket Test)"
771 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
772 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
773 set_pre_cmd $emacs_server $gdb_server
Dave Wallace3d674492017-09-25 15:37:56 -0400774 if [ "$multi_host" = "server" ] ; then
775 delay="sleep 10"
776 else
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500777 delay="sleep 3"
778 fi
779 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
780 namespace_id="$server_namespace_id"
781 namespace_secret="$server_namespace_secret"
Dave Wallace3d674492017-09-25 15:37:56 -0400782 fi
783 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "$delay"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200784 echo "export LD_LIBRARY_PATH=\"$lib_dir:$LD_LIBRARY_PATH\"" >> $cmd2_file
Dave Wallace3079a642017-09-06 01:59:43 -0400785 echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
786 write_script_footer $cmd2_file $perf_server
787 chmod +x $cmd2_file
788 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400789
Dave Wallace3079a642017-09-06 01:59:43 -0400790 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
791 title3="CLIENT$title_dbg (Native-VCL Socket Test)"
792 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
793 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
794 set_pre_cmd $emacs_client $gdb_client
Dave Wallace3d674492017-09-25 15:37:56 -0400795 if [ "$multi_host" = "client" ] ; then
796 delay="sleep 10"
797 else
Dave Wallace8af20542017-10-26 03:29:30 -0400798 delay="sleep 4"
Dave Wallace3d674492017-09-25 15:37:56 -0400799 fi
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500800 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
801 namespace_id="$client_namespace_id"
802 namespace_secret="$client_namespace_secret"
803 fi
Dave Wallace3d674492017-09-25 15:37:56 -0400804 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "$delay"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200805 echo "export LD_LIBRARY_PATH=\"$lib_dir:$LD_LIBRARY_PATH\"" >> $cmd3_file
Dave Wallace3079a642017-09-06 01:59:43 -0400806 echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
807 echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file
808 write_script_footer $cmd3_file $perf_client
809 chmod +x $cmd3_file
810 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400811}
812
813docker_kernel() {
814 verify_no_docker_containers
815 banner="Running DOCKER-KERNEL socket test"
816
Dave Wallace3079a642017-09-06 01:59:43 -0400817 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
818 title1="SERVER$title_dbg (Docker-Native Socket Test)"
819 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
820 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
821 set_pre_cmd $emacs_server $gdb_server
822 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
823 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
824 write_script_footer $cmd1_file $perf_server
825 chmod +x $cmd1_file
826 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400827
Dave Wallace3079a642017-09-06 01:59:43 -0400828 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
829 title2="CLIENT$title_dbg (Docker-Native Socket Test)"
830 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
831 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
832 set_pre_cmd $emacs_client $gdb_client
833 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
834 echo "$get_docker_server_ip4addr" >> $cmd2_file
835 echo "docker run -it --cpuset-cpus='4-7' -v $vpp_dir:$docker_vpp_dir $docker_os ${docker_app_dir}${clnt_app}" >> $cmd2_file
836 write_script_footer $cmd2_file $perf_client
837 chmod +x $cmd2_file
838 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400839}
840
841docker_preload() {
842 verify_no_vpp
843 verify_no_docker_containers
844 banner="Running DOCKER-PRELOAD socket test"
Dave Wallace30fb4a22017-08-17 16:22:04 -0400845 docker_ld_preload_dir="/vcl-ldpreload/"
846 ld_preload_dir="$VCL_LDPRELOAD_LIB_DIR"
847 ld_preload="$docker_ld_preload_dir$vcl_ldpreload_lib "
848 docker_ld_preload_lib="$docker_ld_preload_dir$vcl_ldpreload_lib "
Dave Wallace543852a2017-08-03 02:11:34 -0400849
850 title1="VPP$title_dbg (Docker-Preload Socket Test)"
851 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
852 gdb_cmdfile=$VPP_GDB_CMDFILE
853 set_pre_cmd $emacs_vpp $gdb_vpp
854 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400855 if [ -n "$multi_host" ] ; then
856 echo -n "sudo " >> $cmd1_file
857 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400858 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
859 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400860 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400861
Dave Wallace3079a642017-09-06 01:59:43 -0400862 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
863 title2="SERVER$title_dbg (Docker-Preload Socket Test)"
864 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
865 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
866 set_pre_cmd $emacs_server $gdb_server $docker_ld_preload_lib
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500867 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
868 namespace_id="$server_namespace_id"
869 namespace_secret="$server_namespace_secret"
870 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400871 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200872 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 -0400873 write_script_footer $cmd2_file $perf_server
874 chmod +x $cmd2_file
875 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400876
Dave Wallace3079a642017-09-06 01:59:43 -0400877 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
878 title3="CLIENT$title_dbg (Docker-Preload Socket Test)"
879 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
880 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
881 set_pre_cmd $emacs_client $gdb_client $docker_ld_preload_lib
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500882 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
883 namespace_id="$client_namespace_id"
884 namespace_secret="$client_namespace_secret"
885 fi
Dave Wallace8af20542017-10-26 03:29:30 -0400886 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 4"
Dave Wallace3079a642017-09-06 01:59:43 -0400887 echo "$get_docker_server_ip4addr" >> $cmd3_file
Damjan Marion79dcbc72018-09-12 14:01:10 +0200888 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 -0400889 write_script_footer $cmd3_file $perf_client
890 chmod +x $cmd3_file
891 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400892}
893
894docker_vcl() {
895 verify_no_vpp
896 verify_no_docker_containers
897 banner="Running DOCKER-VCL socket test"
898
899 title1="VPP$title_dbg (Docker-VCL Socket Test)"
900 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_vpp
901 gdb_cmdfile=$VPP_GDB_CMDFILE
902 set_pre_cmd $emacs_vpp $gdb_vpp
903 write_script_header $cmd1_file $tmp_gdb_cmdfile "$title1"
Dave Wallace3079a642017-09-06 01:59:43 -0400904 if [ -n "$multi_host" ] ; then
905 echo -n "sudo " >> $cmd1_file
906 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400907 echo "${pre_cmd}$vpp_dir$vpp_app $vpp_args" >> $cmd1_file
908 write_script_footer $cmd1_file $perf_vpp
Dave Wallace3079a642017-09-06 01:59:43 -0400909 chmod +x $cmd1_file
Dave Wallace543852a2017-08-03 02:11:34 -0400910
Dave Wallace3079a642017-09-06 01:59:43 -0400911 if [ -z "$multi_host" ] || [ "$multi_host" = "server" ] ; then
912 title2="SERVER$title_dbg (Docker-VCL Socket Test)"
913 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
914 gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
915 set_pre_cmd $emacs_server $gdb_server
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500916 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
917 namespace_id="$server_namespace_id"
918 namespace_secret="$server_namespace_secret"
919 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400920 write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
Damjan Marion79dcbc72018-09-12 14:01:10 +0200921 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 -0400922 write_script_footer $cmd2_file $perf_server
923 chmod +x $cmd2_file
924 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400925
Dave Wallace3079a642017-09-06 01:59:43 -0400926 if [ -z "$multi_host" ] || [ "$multi_host" = "client" ] ; then
927 title3="CLIENT$title_dbg (Docker-VCL Socket Test)"
928 tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
929 gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
930 set_pre_cmd $emacs_client $gdb_client
Dave Wallacefbbb07c2018-03-08 11:35:03 -0500931 if [ -n "$full_thru_host_stack_vpp_cfg" ] ; then
932 namespace_id="$client_namespace_id"
933 namespace_secret="$client_namespace_secret"
934 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400935 write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
936 echo "$get_docker_server_ip4addr" >> $cmd3_file
Damjan Marion79dcbc72018-09-12 14:01:10 +0200937 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 -0400938 write_script_footer $cmd3_file $perf_client
939 chmod +x $cmd3_file
940 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400941}
942
943if [[ $run_test ]] ; then
944 eval $run_test
945else
946 echo "ERROR: Please specify a test to run!" >&2
947 usage;
948fi
949
950if (( $(which xfce4-terminal | wc -l) > 0 )) ; then
951 xterm_cmd="xfce4-terminal --geometry $xterm_geom"
952 if [[ $use_tabs ]] ; then
Dave Wallace3079a642017-09-06 01:59:43 -0400953 declare -a tab_cmd_files
954 declare -a tab_titles
955 declare -i i=0
956
957 if [ -x "$cmd1_file" ] ; then
958 tab_cmd_files[$i]="$cmd1_file"
959 tab_titles[$i]="$title1"
960 (( i++ ))
Dave Wallace543852a2017-08-03 02:11:34 -0400961 fi
Dave Wallace3079a642017-09-06 01:59:43 -0400962 if [ -x "$cmd2_file" ] ; then
963 tab_cmd_files[$i]="$cmd2_file"
964 tab_titles[$i]="$title2"
965 (( i++ ))
966 fi
967 if [ -x "$cmd3_file" ] ; then
968 tab_cmd_files[$i]="$cmd3_file"
969 tab_titles[$i]="$title3"
970 fi
971
972 if [ -n "${tab_cmd_files[2]}" ] ; then
973 $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]}"
974 elif [ -n "${tab_cmd_files[1]}" ] ; then
975 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}" --tab --title "${tab_titles[1]}" --command "${tab_cmd_files[1]}"
976
977 else
978 $xterm_cmd --title "${tab_titles[0]}" --command "${tab_cmd_files[0]}"
979 fi
980
Dave Wallace543852a2017-08-03 02:11:34 -0400981 else
Dave Wallace3079a642017-09-06 01:59:43 -0400982 if [ -x "$cmd1_file" ] ; then
983 ($xterm_cmd --title "$title1" --command "$cmd1_file" &)
984 fi
985 if [ -x "$cmd2_file" ] ; then
986 ($xterm_cmd --title "$title2" --command "$cmd2_file" &)
987 fi
Dave Wallace543852a2017-08-03 02:11:34 -0400988 if [ -x "$cmd3_file" ] ; then
989 ($xterm_cmd --title "$title3" --command "$cmd3_file" &)
990 fi
991 fi
992
993else
994 if [[ $use_tabs ]] ; then
995 echo "Sorry, plain ol' xterm doesn't support tabs."
996 fi
997 xterm_cmd="xterm -fs 10 -geometry $xterm_geom"
Dave Wallace3079a642017-09-06 01:59:43 -0400998 if [ -x "$cmd1_file" ] ; then
999 ($xterm_cmd -title "$title1" -e "$cmd1_file" &)
1000 fi
1001 if [ -x "$cmd2_file" ] ; then
1002 ($xterm_cmd -title "$title2" -e "$cmd2_file" &)
1003 fi
Dave Wallace543852a2017-08-03 02:11:34 -04001004 if [ -x "$cmd3_file" ] ; then
1005 ($xterm_cmd -title "$title3" -e "$cmd3_file" &)
1006 fi
1007fi
1008
1009sleep 1