VCL-LDPRELOAD: statically link vppcom into libvcl-ldpreload.so
[vpp.git] / test / scripts / socket_test.sh
index 8c3f20a..35e9c0b 100755 (executable)
@@ -9,7 +9,7 @@ vpp_shm_dir="/dev/shm/"
 vpp_run_dir="/run/vpp"
 lib64_dir="$WS_ROOT/build-root/install-vpp-native/vpp/lib64/"
 lib64_debug_dir="$WS_ROOT/build-root/install-vpp_debug-native/vpp/lib64/"
-dpdk_devbind="$WS_ROOT/build-root/install-vpp-native/dpdk/share/dpdk/usertools/dpdk-devbind.py"
+dpdk_devbind="/usr/share/dpdk/usertools/dpdk-devbind.py"
 docker_vpp_dir="/vpp/"
 docker_app_dir="/vpp/"
 docker_lib64_dir="/vpp-lib64/"
@@ -33,6 +33,7 @@ tmp_cmdfile_prefix="/tmp/socket_test_cmd"
 cmd1_file="${tmp_cmdfile_prefix}1.$$"
 cmd2_file="${tmp_cmdfile_prefix}2.$$"
 cmd3_file="${tmp_cmdfile_prefix}3.$$"
+vpp_eth_name="enp0s8"
 tmp_vpp_exec_file="/tmp/vpp_config.$$"
 tmp_gdb_cmdfile_prefix="/tmp/gdb_cmdfile"
 def_gdb_cmdfile_prefix="$WS_ROOT/extras/gdb/gdb_cmdfile"
@@ -48,7 +49,6 @@ trap_signals="SIGINT SIGTERM EXIT"
 VPP_GDB_CMDFILE="${VPP_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vpp}"
 VPPCOM_CLIENT_GDB_CMDFILE="${VPPCOM_CLIENT_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_client}"
 VPPCOM_SERVER_GDB_CMDFILE="${VPPCOM_SERVER_GDB_CMDFILE:-${def_gdb_cmdfile_prefix}.vppcom_server}"
-VCL_LDPRELOAD_LIB_DIR="${VCL_LDPRELOAD_LIB_DIR:-/usr/local/lib}"
 
 usage() {
     cat <<EOF
@@ -68,6 +68,8 @@ OPTIONS:
   -d                  Run the vpp_debug version of all apps.
   -c                  Set VPPCOM_CONF to use the vppcom_test.conf file.
   -i                  Run iperf3 for client/server app in native tests.
+  -n                  Name of ethernet for VPP to use in multi-host cfg.
+  -6                  Use ipv6 addressing.
   -m c[lient]         Run client in multi-host cfg (server on remote host)
      s[erver]         Run server in multi-host cfg (client on remote host)
   -e a[ll]            Run all in emacs+gdb.
@@ -114,8 +116,9 @@ declare -i perf_server=0
 declare -i leave_tmp_files=0
 declare -i bash_after_exit=0
 declare -i iperf3=0
+declare -i use_ipv6=0
 
-while getopts ":hitlbcdm:e:g:p:E:I:N:P:R:S:T:UBVX" opt; do
+while getopts ":hitlbcd6n:m:e:g:p:E:I:N:P:R:S:T:UBVX" opt; do
     case $opt in
         h) usage ;;
         l) leave_tmp_files=1
@@ -124,6 +127,8 @@ while getopts ":hitlbcdm:e:g:p:E:I:N:P:R:S:T:UBVX" opt; do
            ;;
         i) iperf3=1
            ;;
+        6) use_ipv6=1
+           ;;
         t) xterm_geom="180x40"
            use_tabs="true"
            ;;
@@ -151,6 +156,8 @@ while getopts ":hitlbcdm:e:g:p:E:I:N:P:R:S:T:UBVX" opt; do
            vpp_dir=$vpp_debug_dir
            lib64_dir=$lib64_debug_dir
            ;;
+        n) vpp_eth_name="$OPTARG"
+           ;;
         m) if [ $OPTARG = "c" ] || [ $OPTARG = "client" ] ; then
                multi_host="client"
            elif [ $OPTARG = "s" ] || [ $OPTARG = "server" ] ; then
@@ -239,21 +246,28 @@ while ! [[ $run_test ]] && (( $# > 0 )) ; do
     shift
 done
 
+VCL_LDPRELOAD_LIB_DIR="${VCL_LDPRELOAD_LIB_DIR:-$lib64_dir}"
+
 if [ -z "$WS_ROOT" ] ; then
     echo "ERROR: WS_ROOT environment variable not set!" >&2
     echo "       Please set WS_ROOT to VPP workspace root directory." >&2
     exit 1
 fi
 
+if [[ "$(grep bin_PROGRAMS $WS_ROOT/src/uri.am)" = "" ]] ; then
+    $WS_ROOT/extras/vagrant/vcl_test.sh $WS_ROOT $USER
+    (cd $WS_ROOT; make build)
+fi
+
 if [ ! -d $vpp_dir ] ; then
-    echo "ERROR: Missing VPP$DEBUG bin directory!" >&2
+    echo "ERROR: Missing VPP$title_dbg bin directory!" >&2
     echo "       $vpp_dir" >&2
     env_test_failed="true"
 fi
 
 if [[ $run_test =~ .*"_preload" ]] ; then
    if [ ! -d $lib64_dir ] ; then
-       echo "ERROR: Missing VPP$DEBUG lib64 directory!" >&2
+       echo "ERROR: Missing VPP$title_dbg lib64 directory!" >&2
        echo "       $lib64_dir" >&2
    elif [ ! -d $VCL_LDPRELOAD_LIB_DIR ] ; then
        echo "ERROR: Missing VCL LD_PRELOAD Library directory!" >&2
@@ -267,19 +281,19 @@ if [[ $run_test =~ .*"_preload" ]] ; then
 fi
 
 if [ ! -f $vpp_dir$vpp_app ] ; then
-    echo "ERROR: Missing VPP$DEBUG Application!" >&2
+    echo "ERROR: Missing VPP$title_dbg Application!" >&2
     echo "       $vpp_dir$vpp_app" >&2
     env_test_failed="true"
 fi
 
 if [ ! -f $vpp_dir$sock_srvr_app ] && [ ! $iperf3 -eq 1 ] ; then
-    echo "ERROR: Missing$DEBUG Socket Server Application!" >&2
+    echo "ERROR: Missing$title_dbg Socket Server Application!" >&2
     echo "       $vpp_dir$sock_srvr_app" >&2
     env_test_failed="true"
 fi
 
 if [ ! -f $vpp_dir$sock_clnt_app ] && [ ! $iperf3 -eq 1 ] ; then
-    echo "ERROR: Missing$DEBUG Socket Client Application!" >&2
+    echo "ERROR: Missing$title_dbg Socket Client Application!" >&2
     echo "       $vpp_dir$sock_clnt_app" >&2
     env_test_failed="true"
 fi
@@ -302,6 +316,13 @@ if [[ $run_test =~ .*"_vcl" ]] && [ $iperf3 -eq 1 ] ; then
     env_test_failed="true"
 fi
 
+if [ -n "$mult_host"] && [ ! -f "$dpdk_devbind" ] ; then
+    echo "ERROR: Can't find dpdk-devbind.py!"
+    echo "       Run \"cd \$WS_ROOT; make dpdk-install-dev\" to install it."
+    echo
+    env_test_failed="true"
+fi
+
 if [ -n "$env_test_failed" ] ; then
     exit 1
 fi
@@ -318,6 +339,7 @@ if [ -z "$api_segment" ] ; then
     api_segment=" api-segment { gid $user_gid }"
 fi
 if [ -n "$multi_host" ] ; then
+    sudo modprobe uio_pci_generic
     vpp_args="unix { interactive exec $tmp_vpp_exec_file}${api_segment}"
 else
     vpp_args="unix { interactive }${api_segment}"
@@ -339,17 +361,23 @@ else
     clnt_app="$sock_clnt_app${sock_clnt_options} \$srvr_addr $sock_srvr_port"
 fi
 
+
 verify_no_vpp() {
-    local running_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
-    if [ "$(eval $running_vpp)" != "" ] ; then
-        echo "ERROR: Please kill all running vpp instances:"
+    local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\""
+    
+    if [ -n "$api_prefix" ] ; then
+        grep_for_vpp="$grep_for_vpp|grep \"prefix $api_prefix\""
+    fi
+    local running_vpp="$(eval $grep_for_vpp)"
+    if [ -n "$running_vpp" ] ; then
+        echo "ERROR: Please kill the following vpp instance(s):"
         echo
-        eval $running_vpp
+        echo $running_vpp
         echo
         exit 1
     fi
     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]*"
-    rm -f $clean_devshm
+    sudo rm -f $clean_devshm
     devshm_files="$(ls -l $clean_devshm 2>/dev/null | grep $(whoami))"
     if [ "$devshm_files" != "" ] ; then
         echo "ERROR: Please remove the following $vpp_shm_dir files:"
@@ -363,7 +391,6 @@ verify_no_vpp() {
         sudo chown root:$USER $vpp_run_dir
     fi
     if [ -n "$multi_host" ] ; then
-        vpp_eth_name="enp0s8"
         vpp_eth_pci_id="$(ls -ld /sys/class/net/$vpp_eth_name/device | awk '{print $11}' | cut -d/ -f4)"
         if [ -z "$vpp_eth_pci_id" ] ; then
             echo "ERROR: Missing ethernet interface $vpp_eth_name!"
@@ -383,6 +410,8 @@ verify_no_vpp() {
                 vpp_eth_ifname="GigabitEthernet$bus/$slot/$func" ;;
             ixgbe)
                 vpp_eth_ifname="TenGigabitEthernet$bus/$slot/$func" ;;
+            i40e)
+                vpp_eth_ifname="FortyGigabitEthernet$bus/$slot/$func" ;;
             *)
                 echo "ERROR: Unknown ethernet kernel driver $vpp_eth_kernel_driver!"
                 usage ;;
@@ -390,17 +419,19 @@ verify_no_vpp() {
         
         vpp_eth_ip4_addr="$(ip -4 -br addr show $vpp_eth_name | awk '{print $3}')"
         if [ -z "$vpp_eth_ip4_addr" ] ; then
-            echo "ERROR: No inet address configured for $vpp_eth_name!"
-            usage
+            if [ "$multi_host" = "server" ] ; then
+                vpp_eth_ip4_addr="10.10.10.10/24"
+            else
+                vpp_eth_ip4_addr="10.10.10.11/24"
+            fi
         fi
-        vpp_eth_ip6_addr="$(ip -6 -br addr show $vpp_eth_name | awk '{print $3}')"
-        if [ -z "$vpp_eth_ip6_addr" ] ; then
+        if [ $use_ipv6 -eq 1 ] && [ -z "$vpp_eth_ip6_addr" ] ; then
             echo "ERROR: No inet6 address configured for $vpp_eth_name!"
             usage
         fi
-        vpp_args="$vpp_args plugins { path $lib64_dir/vpp_plugins } dpdk { dev $vpp_eth_pci_id }"
+        vpp_args="$vpp_args plugins { path ${lib64_dir}vpp_plugins } dpdk { dev $vpp_eth_pci_id }"
                 
-        sudo ifdown $vpp_eth_name 2> /dev/null
+        sudo ifconfig $vpp_eth_name down 2> /dev/null
         echo "Configuring VPP to use $vpp_eth_name ($vpp_eth_pci_id), inet addr $vpp_eth_ip4_addr"
 
         cat <<EOF >> $tmp_vpp_exec_file
@@ -459,14 +490,14 @@ write_script_header() {
     echo -e "#\n# $1 generated on $(date)\n#" >> $1
     if [ $leave_tmp_files -eq 0 ] ; then
         if [ -n "$multi_host" ] ; then
-            echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file; sudo $dpdk_devbind -e $vpp_eth_kernel_driver $vpp_eth_pci_id; sudo ifup $vpp_eth_name\" $trap_signals" >> $1
+            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
         else
             echo "trap \"rm -f $1 $2 $tmp_vpp_exec_file\" $trap_signals" >> $1
         fi
     fi
     echo "export VPPCOM_CONF=${vppcom_conf_dir}${vppcom_conf}" >> $1
     if [ "$pre_cmd" = "$gdb_in_emacs " ] ; then
-        if [ -n "$multi_host" ] ; then
+        if [ -n "$multi_host" ] && [[ $3 =~ "VPP".* ]] ; then
             cat <<EOF >> $1
 $gdb_in_emacs() {
     sudo emacs --eval "(gdb \"gdb -x $2 -i=mi --args \$*\")" --eval "(setq frame-title-format \"$3\")"
@@ -611,7 +642,12 @@ native_vcl() {
         tmp_gdb_cmdfile=$tmp_gdb_cmdfile_server
         gdb_cmdfile=$VPPCOM_SERVER_GDB_CMDFILE
         set_pre_cmd $emacs_server $gdb_server
-        write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "sleep 2"
+        if [ "$multi_host" = "server" ] ; then
+            delay="sleep 10"
+        else
+            delay="sleep 2"
+        fi
+        write_script_header $cmd2_file $tmp_gdb_cmdfile "$title2" "$delay"
         echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd2_file
         echo "${pre_cmd}${app_dir}${srvr_app}" >> $cmd2_file
         write_script_footer $cmd2_file $perf_server
@@ -623,7 +659,12 @@ native_vcl() {
         tmp_gdb_cmdfile=$tmp_gdb_cmdfile_client
         gdb_cmdfile=$VPPCOM_CLIENT_GDB_CMDFILE
         set_pre_cmd $emacs_client $gdb_client
-        write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "sleep 3"
+        if [ "$multi_host" = "client" ] ; then
+            delay="sleep 10"
+        else
+            delay="sleep 2"
+        fi
+        write_script_header $cmd3_file $tmp_gdb_cmdfile "$title3" "$delay"
         echo "export LD_LIBRARY_PATH=\"$lib64_dir:$LD_LIBRARY_PATH\"" >> $cmd3_file
         echo "srvr_addr=\"$sock_srvr_addr\"" >> $cmd3_file
         echo "${pre_cmd}${app_dir}${clnt_app}" >> $cmd3_file