diff options
Diffstat (limited to 'extras/scripts/host-stack/vcl-ldpreload/test/common')
3 files changed, 122 insertions, 0 deletions
diff --git a/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_test.sh b/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_test.sh new file mode 100755 index 00000000000..73f2911b57c --- /dev/null +++ b/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_test.sh @@ -0,0 +1,94 @@ +#! /bin/bash +# +# nginx_test.sh +# +# Run specified app using LD_PRELOAD to fetch a page from +# nginx running in vpp1 net-namespace. +# +# Specify the following environment variables: +# +# STRACE_ONLY - Run app with strace instead of LD_PRELOAD. +# TEST_APP - App to run (default: curl) +# + +# Configuration variables. +# +vpp_dk_name="NGINX" +# Comment out the next line to run the VPP release version +debug="_debug" +vpp_app="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/bin/vpp" + +check_for_vpp() { + local grep_for_vpp="ps -eaf|grep -v grep|grep \"bin/vpp\"" + running_vpp="$(eval $grep_for_vpp)" +} + +# Verify Environment. +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 [ -z "$VCL_LDPRELOAD_LIB_DIR" ] ; then + echo "ERROR: VCL_LDPRELOAD_LIB_DIR environment variable not set!" >&2 + echo " Please set VCL_LDPRELOAD_LIB_DIR to " >&2 + echo " $WS_ROOT/build-root/install-vpp[_debug]-native/vpp/lib." >&2 + exit 1 +fi + +TEST_APP="${TEST_APP:-curl}" +LDP_DIR="${WS_ROOT}/extras/vcl-ldpreload" +LDP_TEST_DIR="${LDP_TEST_DIR:-${LDP_DIR}/test}" +LDP_LIB="${LDP_LIB:-${VCL_LDPRELOAD_LIB_DIR}/libvcl_ldpreload.so.0.0.0}" + +if [ ! -f "$LDP_LIB" ] ; then + echo "ERROR: Missing VCL-LDPRELOAD Library: $LDP_LIB" + echo " Run 'cd $WS_ROOT; make build[-release] ' !" + exit 1 +fi + +if [ -n "$STRACE_ONLY" ] ; then + echo "Running strace -tt $TEST_APP http://$nginx_addr" + strace -tt $TEST_APP http://$nginx_addr +else + check_for_vpp + if [ -z "$running_vpp" ] ; then + echo -e "\nConfiguring network interfaces" + sudo ip link del dev vpp_dk + sudo ip link add name vpp_dk type veth peer name vpp1 + sudo ip link set dev vpp_dk up + sudo ethtool --offload vpp_dk rx off tx off + sudo ip link set dev vpp1 up + sudo ethtool --offload vpp1 rx off tx off + sudo ip link set dev lo up + sudo brctl addif docker0 vpp_dk + + echo "Starting VPP " + sudo rm -f /dev/shm/* + sudo xfce4-terminal --title VPP --command "$vpp_app unix { interactive exec $LDP_TEST_DIR/common/vpp_docker.conf full-coredump coredump-size unlimited } api-segment { gid $(id -g) }" & +# sudo $vpp_app unix { cli-listen localhost:5002 exec $LDP_TEST_DIR/common/vpp_docker.conf } api-segment { gid $(id -g) } + sleep 4 + fi + + if [ -z "$(docker ps -qf name=$vpp_dk_name)" ] ; then + echo -e "\nStarting NGINX in docker container ($vpp_dk_name)" + echo "docker run --rm --name $vpp_dk_name -v $LDP_TEST_DIR/common/nginx_welcome.html:/usr/share/nginx/html/index.html:ro -d nginx" + docker run --rm --name $vpp_dk_name -v $LDP_TEST_DIR/common/nginx_welcome.html:/usr/share/nginx/html/index.html:ro -d nginx + + export LD_LIBRARY_PATH="$WS_ROOT/build-root/install-vpp${debug}-native/vpp/lib/:$LDP_DIR/src/.libs:" + + # Extract nginx IPv4 address from docker bridge + # + nginx_addr=$(docker network inspect bridge | grep IPv4Address | awk -e '{print $2}' | sed -e 's,/16,,' -e 's,",,g' -e 's/,//') + + if [ -z "$nginx_addr" ] ; then + echo "ERROR: Unable to determine docker container address!" + exit 1 + fi + fi + + echo -e "\nRunning wget" + echo -e "LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr\n" + LD_PRELOAD=$LDP_LIB $TEST_APP http://$nginx_addr +fi diff --git a/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_welcome.html b/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_welcome.html new file mode 100644 index 00000000000..c3850904482 --- /dev/null +++ b/extras/scripts/host-stack/vcl-ldpreload/test/common/nginx_welcome.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html lang="en" xml:lang="en"> +<head> +<title>Welcome to nginx!</title> +<style> + body { + width: 35em; + margin: 0 auto; + font-family: Tahoma, Verdana, Arial, sans-serif; + } +</style> +</head> +<body> +<h1>Welcome to nginx!</h1> +<p>If you see this page, the nginx web server is successfully installed and +working. Further configuration is required.</p> + +<p>For online documentation and support please refer to +<a href="http://nginx.org/">nginx.org</a>.<br/> +Commercial support is available at +<a href="http://nginx.com/">nginx.com</a>.</p> + +<p><em>Thank you for using nginx.</em></p> +</body> +</html> diff --git a/extras/scripts/host-stack/vcl-ldpreload/test/common/vpp_docker.conf b/extras/scripts/host-stack/vcl-ldpreload/test/common/vpp_docker.conf new file mode 100644 index 00000000000..4d18bb2d208 --- /dev/null +++ b/extras/scripts/host-stack/vcl-ldpreload/test/common/vpp_docker.conf @@ -0,0 +1,3 @@ +create host-interface name vpp1 +set int state host-vpp1 up +set int ip address host-vpp1 172.17.0.123/24 |