14bf6318cSFilip TehlarODL_USER="admin"
24bf6318cSFilip TehlarODL_PASSWD="admin"
34bf6318cSFilip TehlarODL_IP="127.0.0.1"
44bf6318cSFilip TehlarODL_PORT="8181"
54bf6318cSFilip Tehlar
64bf6318cSFilip Tehlar# path to vpp executable
7348f41abSFilip TehlarVPP_LITE_DIR=/vpp/build-root/install-vpp_debug-native/vpp/bin
8aea14fd0SFilip TehlarVPP_LITE_BIN=${VPP_LITE_DIR}/vpp
9348f41abSFilip TehlarVPP_API_TEST=/vpp/build-root/install-vpp_debug-native/vpp-api-test/bin/vpp_api_test
10013d3a56SFilip TehlarVPP_PLUGIN_DIR=${VPP_LITE_DIR}/../lib64/vpp_plugins
11a6ba15e2SFilip TehlarONE_ROOT=/vpp/one
124bf6318cSFilip Tehlar
1312defda1SFilip Tehlar# read user config file if exists
1412defda1SFilip Tehlarif [ -f "${HOME}/.onerc" ] ; then
1512defda1SFilip Tehlar  source "${HOME}/.onerc"
1612defda1SFilip Tehlarfi
1712defda1SFilip Tehlar
184bf6318cSFilip Tehlarif [ ! -f "${VPP_LITE_BIN}" ] ; then
194bf6318cSFilip Tehlar  echo "Error: VPP binary not found. You can set VPP_LITE_BIN in config.sh"
204bf6318cSFilip Tehlar  echo "Current value:"
214bf6318cSFilip Tehlar  echo "VPP_LITE_BIN=${VPP_LITE_BIN}"
224bf6318cSFilip Tehlar  exit 1
234bf6318cSFilip Tehlarfi
244543d282SFlorin Coras
251df1d674SFilip Tehlarif [ ! -f "${VPP_API_TEST}" ] ; then
261df1d674SFilip Tehlar  echo "Error: vpp_api_test not found. Either it's not built or environment \
271df1d674SFilip Tehlar    variable VPP_API_TEST is not set. You can build vpp_api_test with:"
281df1d674SFilip Tehlar  echo "$ make build-vat"
291df1d674SFilip Tehlar  echo "VPP_API_TEST can be set in config.sh or in ~/.onerc."
301df1d674SFilip Tehlar  echo "Current value:"
31048ed618SFilip Tehlar  echo "VPP_API_TEST=${VPP_API_TEST}"
321df1d674SFilip Tehlar  exit 1
331df1d674SFilip Tehlarfi
341df1d674SFilip Tehlar
35bf231ba7SFilip Tehlarif [ "${CFG_METHOD}" == '' ] ; then
36bf231ba7SFilip Tehlar  CFG_METHOD=vat
37bf231ba7SFilip Tehlar  echo
38bf231ba7SFilip Tehlar  echo "* INFO: configuration method not selected, defaulting to 'vat'"
39bf231ba7SFilip Tehlar  echo "* To define the method run the test as follows:"
40bf231ba7SFilip Tehlar  echo "* $ sudo CFG_METHOD=vat|cli ./tests/<tc>.sh"
41bf231ba7SFilip Tehlar  echo
42bf231ba7SFilip Tehlarfi
43bf231ba7SFilip Tehlar
444543d282SFlorin Corasfunction clean_all
454543d282SFlorin Coras{
464543d282SFlorin Coras  echo "Clearing all VPP instances.."
474543d282SFlorin Coras  pkill vpp --signal 9
484543d282SFlorin Coras  rm /dev/shm/* &> /dev/null
494543d282SFlorin Coras
504543d282SFlorin Coras  echo "Cleaning topology.."
514543d282SFlorin Coras  ip netns exec intervppns ifconfig vppbr down &> /dev/null
524543d282SFlorin Coras  ip netns exec intervppns brctl delbr vppbr &> /dev/null
534543d282SFlorin Coras  ip netns exec intervppns1 ifconfig vppbr down &> /dev/null
544543d282SFlorin Coras  ip netns exec intervppns1 brctl delbr vppbr &> /dev/null
554543d282SFlorin Coras  ip netns exec intervppns2 ifconfig vppbr down &> /dev/null
564543d282SFlorin Coras  ip netns exec intervppns2 brctl delbr vppbr &> /dev/null
574543d282SFlorin Coras  ip netns exec intervpp-ns ifconfig vppbr1 down &> /dev/null
584543d282SFlorin Coras  ip netns exec intervpp-ns brctl delbr vppbr1 &> /dev/null
594543d282SFlorin Coras  ip netns exec xtr-rtr-ns ifconfig vppbr1 down &> /dev/null
604543d282SFlorin Coras  ip netns exec xtr-rtr-ns brctl delbr vppbr1 &> /dev/null
614543d282SFlorin Coras
624543d282SFlorin Coras  ip link del dev veth_vpp1 &> /dev/null
634543d282SFlorin Coras  ip link del dev veth_vpp2 &> /dev/null
644543d282SFlorin Coras  ip link del dev vpp1_cus1 &> /dev/null
654543d282SFlorin Coras  ip link del dev vpp2_cus1 &> /dev/null
664543d282SFlorin Coras  ip link del dev vpp1_cus2 &> /dev/null
674543d282SFlorin Coras  ip link del dev vpp2_cus2 &> /dev/null
684543d282SFlorin Coras  ip link del dev vpp1 &> /dev/null
694543d282SFlorin Coras  ip link del dev vpp2 &> /dev/null
704543d282SFlorin Coras
714543d282SFlorin Coras  ip link del dev veth_intervpp1 &> /dev/null
724543d282SFlorin Coras  ip link del dev veth_intervpp2 &> /dev/null
734543d282SFlorin Coras  ip link del dev veth_intervpp11 &> /dev/null
744543d282SFlorin Coras  ip link del dev veth_intervpp12 &> /dev/null
754543d282SFlorin Coras  ip link del dev veth_intervpp21 &> /dev/null
764543d282SFlorin Coras  ip link del dev veth_intervpp22 &> /dev/null
774543d282SFlorin Coras  ip link del dev intervpp1 &> /dev/null
784543d282SFlorin Coras  ip link del dev intervpp2 &> /dev/null
794543d282SFlorin Coras  ip link del dev xtr_rtr1 &> /dev/null
804543d282SFlorin Coras  ip link del dev xtr_rtr2 &> /dev/null
814543d282SFlorin Coras  ip link del dev xtr_rtr3 &> /dev/null
824543d282SFlorin Coras
834543d282SFlorin Coras  ip link del dev veth_odl &> /dev/null
844543d282SFlorin Coras  ip link del dev odl &> /dev/null
854543d282SFlorin Coras
864543d282SFlorin Coras  ip netns del vppns1 &> /dev/null
874543d282SFlorin Coras  ip netns del vppns2 &> /dev/null
884543d282SFlorin Coras  ip netns del intervppns &> /dev/null
894543d282SFlorin Coras  ip netns del intervppns1 &> /dev/null
904543d282SFlorin Coras  ip netns del intervppns2 &> /dev/null
914543d282SFlorin Coras  ip netns del vpp1-cus1-ns &> /dev/null
924543d282SFlorin Coras  ip netns del vpp1-cus2-ns &> /dev/null
934543d282SFlorin Coras  ip netns del vpp2-cus1-ns &> /dev/null
944543d282SFlorin Coras  ip netns del vpp2-cus2-ns &> /dev/null
954543d282SFlorin Coras  ip netns del intervpp-ns &> /dev/null
964543d282SFlorin Coras  ip netns del vpp-ns1 &> /dev/null
974543d282SFlorin Coras  ip netns del vpp-ns2 &> /dev/null
984543d282SFlorin Coras  ip netns del xtr-rtr-ns &> /dev/null
994543d282SFlorin Coras
1004543d282SFlorin Coras  if [ "$1" != "no_odl" ] ; then
1014543d282SFlorin Coras    odl_clear_all
1024543d282SFlorin Coras  fi
103bf231ba7SFilip Tehlar}
1044543d282SFlorin Coras
105bf231ba7SFilip Tehlarfunction maybe_pause
106bf231ba7SFilip Tehlar{
107bf231ba7SFilip Tehlar  if [ "$WAIT" == "1" ] ; then
108bf231ba7SFilip Tehlar    read -p  "press any key to continue .." -n1
109bf231ba7SFilip Tehlar  fi
110bf231ba7SFilip Tehlar}
111bf231ba7SFilip Tehlar
112bf231ba7SFilip Tehlar
113bf231ba7SFilip Tehlarfunction start_vpp
114bf231ba7SFilip Tehlar{
115bf231ba7SFilip Tehlar  # start_vpp port prefix
1164543d282SFlorin Coras
117bf231ba7SFilip Tehlar  ${VPP_LITE_BIN} \
118bf231ba7SFilip Tehlar    unix { log /tmp/$2.log           \
119bf231ba7SFilip Tehlar           full-coredump             \
120bf231ba7SFilip Tehlar           cli-listen localhost:$1 } \
121f20e6999SFilip Tehlar    api-trace { on } api-segment { prefix "$2" } \
122013d3a56SFilip Tehlar    plugins { plugin dpdk_plugin.so { disable } } \
1237000eb00SFilip Tehlar    plugin_path ${VPP_PLUGIN_DIR} 2> /dev/null
124bf231ba7SFilip Tehlar}
125bf231ba7SFilip Tehlar
126bf231ba7SFilip Tehlarfunction print_status
127bf231ba7SFilip Tehlar{
128bf231ba7SFilip Tehlar  # show_status rc error_msg
129bf231ba7SFilip Tehlar  if [ $1 -ne 0 ] ; then
130bf231ba7SFilip Tehlar    echo "Test failed: $2"
131bf231ba7SFilip Tehlar  else
132bf231ba7SFilip Tehlar    echo "Test passed."
133bf231ba7SFilip Tehlar    test_result=0
134bf231ba7SFilip Tehlar  fi
135bf231ba7SFilip Tehlar}
136bf231ba7SFilip Tehlar
137bf231ba7SFilip Tehlarfunction assert_rc_ok
138bf231ba7SFilip Tehlar{
139bf231ba7SFilip Tehlar  # assert_rc_ok rc cleanup_fcn error_msg
140bf231ba7SFilip Tehlar  if [ $1 -ne 0 ] ; then
141bf231ba7SFilip Tehlar    echo $3
1425089c812SFilip Tehlar    maybe_pause
1435089c812SFilip Tehlar    $2
1445089c812SFilip Tehlar    exit $test_result
1455089c812SFilip Tehlar  fi
1465089c812SFilip Tehlar}
1475089c812SFilip Tehlar
1485089c812SFilip Tehlarfunction assert_rc_not_ok
1495089c812SFilip Tehlar{
1505089c812SFilip Tehlar  if [ $1 -eq 0 ] ; then
1515089c812SFilip Tehlar    echo $3
1525089c812SFilip Tehlar    maybe_pause
153bf231ba7SFilip Tehlar    $2
154bf231ba7SFilip Tehlar    exit $test_result
155bf231ba7SFilip Tehlar  fi
1564543d282SFlorin Coras}
157abc68849SFilip Tehlar
158abc68849SFilip Tehlarfunction start_map_resolver
159abc68849SFilip Tehlar{
160abc68849SFilip Tehlar  echo "starting dummy map resolver on interface $1"
161abc68849SFilip Tehlar  python scripts/dummy_mr.py "$1" 4342 &
162abc68849SFilip Tehlar  mr_id=$!
163abc68849SFilip Tehlar}
1642e74e404SFilip Tehlar
165ebfd5b56SFilip Tehlarfunction start_map_server
166ebfd5b56SFilip Tehlar{
167ebfd5b56SFilip Tehlar  echo "starting dummy map server on interface $1"
168ebfd5b56SFilip Tehlar  python scripts/dummy_map_server.py "$1" 4342 &
169ebfd5b56SFilip Tehlar  ms_id=$!
170ebfd5b56SFilip Tehlar}
171ebfd5b56SFilip Tehlar
1722e74e404SFilip Tehlarfunction check_counters
1732e74e404SFilip Tehlar{
1742e74e404SFilip Tehlar  python scripts/vat/check_counters.py ${VPP_API_TEST} ${VAT_TEMPLATES} "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
1752e74e404SFilip Tehlar}
1762e74e404SFilip Tehlar
177