1ODL_USER="admin"
2ODL_PASSWD="admin"
3ODL_IP="127.0.0.1"
4ODL_PORT="8181"
5
6# path to vpp executable
7VPP_LITE_DIR=/vpp/build-root/install-vpp_debug-native/vpp/bin
8VPP_LITE_BIN=${VPP_LITE_DIR}/vpp
9VPP_API_TEST=/vpp/build-root/install-vpp_debug-native/vpp-api-test/bin/vpp_api_test
10VPP_PLUGIN_DIR=${VPP_LITE_DIR}/../lib64/vpp_plugins
11ONE_ROOT=/vpp/one
12
13# read user config file if exists
14if [ -f "${HOME}/.onerc" ] ; then
15  source "${HOME}/.onerc"
16fi
17
18if [ ! -f "${VPP_LITE_BIN}" ] ; then
19  echo "Error: VPP binary not found. You can set VPP_LITE_BIN in config.sh"
20  echo "Current value:"
21  echo "VPP_LITE_BIN=${VPP_LITE_BIN}"
22  exit 1
23fi
24
25if [ ! -f "${VPP_API_TEST}" ] ; then
26  echo "Error: vpp_api_test not found. Either it's not built or environment \
27    variable VPP_API_TEST is not set. You can build vpp_api_test with:"
28  echo "$ make build-vat"
29  echo "VPP_API_TEST can be set in config.sh or in ~/.onerc."
30  echo "Current value:"
31  echo "VPP_API_TEST=${VPP_API_TEST}"
32  exit 1
33fi
34
35if [ "${CFG_METHOD}" == '' ] ; then
36  CFG_METHOD=vat
37  echo
38  echo "* INFO: configuration method not selected, defaulting to 'vat'"
39  echo "* To define the method run the test as follows:"
40  echo "* $ sudo CFG_METHOD=vat|cli ./tests/<tc>.sh"
41  echo
42fi
43
44function clean_all
45{
46  echo "Clearing all VPP instances.."
47  pkill vpp --signal 9
48  rm /dev/shm/* &> /dev/null
49
50  echo "Cleaning topology.."
51  ip netns exec intervppns ifconfig vppbr down &> /dev/null
52  ip netns exec intervppns brctl delbr vppbr &> /dev/null
53  ip netns exec intervppns1 ifconfig vppbr down &> /dev/null
54  ip netns exec intervppns1 brctl delbr vppbr &> /dev/null
55  ip netns exec intervppns2 ifconfig vppbr down &> /dev/null
56  ip netns exec intervppns2 brctl delbr vppbr &> /dev/null
57  ip netns exec intervpp-ns ifconfig vppbr1 down &> /dev/null
58  ip netns exec intervpp-ns brctl delbr vppbr1 &> /dev/null
59  ip netns exec xtr-rtr-ns ifconfig vppbr1 down &> /dev/null
60  ip netns exec xtr-rtr-ns brctl delbr vppbr1 &> /dev/null
61
62  ip link del dev veth_vpp1 &> /dev/null
63  ip link del dev veth_vpp2 &> /dev/null
64  ip link del dev vpp1_cus1 &> /dev/null
65  ip link del dev vpp2_cus1 &> /dev/null
66  ip link del dev vpp1_cus2 &> /dev/null
67  ip link del dev vpp2_cus2 &> /dev/null
68  ip link del dev vpp1 &> /dev/null
69  ip link del dev vpp2 &> /dev/null
70
71  ip link del dev veth_intervpp1 &> /dev/null
72  ip link del dev veth_intervpp2 &> /dev/null
73  ip link del dev veth_intervpp11 &> /dev/null
74  ip link del dev veth_intervpp12 &> /dev/null
75  ip link del dev veth_intervpp21 &> /dev/null
76  ip link del dev veth_intervpp22 &> /dev/null
77  ip link del dev intervpp1 &> /dev/null
78  ip link del dev intervpp2 &> /dev/null
79  ip link del dev xtr_rtr1 &> /dev/null
80  ip link del dev xtr_rtr2 &> /dev/null
81  ip link del dev xtr_rtr3 &> /dev/null
82
83  ip link del dev veth_odl &> /dev/null
84  ip link del dev odl &> /dev/null
85
86  ip netns del vppns1 &> /dev/null
87  ip netns del vppns2 &> /dev/null
88  ip netns del intervppns &> /dev/null
89  ip netns del intervppns1 &> /dev/null
90  ip netns del intervppns2 &> /dev/null
91  ip netns del vpp1-cus1-ns &> /dev/null
92  ip netns del vpp1-cus2-ns &> /dev/null
93  ip netns del vpp2-cus1-ns &> /dev/null
94  ip netns del vpp2-cus2-ns &> /dev/null
95  ip netns del intervpp-ns &> /dev/null
96  ip netns del vpp-ns1 &> /dev/null
97  ip netns del vpp-ns2 &> /dev/null
98  ip netns del xtr-rtr-ns &> /dev/null
99
100  if [ "$1" != "no_odl" ] ; then
101    odl_clear_all
102  fi
103}
104
105function maybe_pause
106{
107  if [ "$WAIT" == "1" ] ; then
108    read -p  "press any key to continue .." -n1
109  fi
110}
111
112
113function start_vpp
114{
115  # start_vpp port prefix
116
117  ${VPP_LITE_BIN} \
118    unix { log /tmp/$2.log           \
119           full-coredump             \
120           cli-listen localhost:$1 } \
121    api-trace { on } api-segment { prefix "$2" } \
122    plugins { plugin dpdk_plugin.so { disable } } \
123    plugin_path ${VPP_PLUGIN_DIR} 2> /dev/null
124}
125
126function print_status
127{
128  # show_status rc error_msg
129  if [ $1 -ne 0 ] ; then
130    echo "Test failed: $2"
131  else
132    echo "Test passed."
133    test_result=0
134  fi
135}
136
137function assert_rc_ok
138{
139  # assert_rc_ok rc cleanup_fcn error_msg
140  if [ $1 -ne 0 ] ; then
141    echo $3
142    maybe_pause
143    $2
144    exit $test_result
145  fi
146}
147
148function assert_rc_not_ok
149{
150  if [ $1 -eq 0 ] ; then
151    echo $3
152    maybe_pause
153    $2
154    exit $test_result
155  fi
156}
157
158function start_map_resolver
159{
160  echo "starting dummy map resolver on interface $1"
161  python scripts/dummy_mr.py "$1" 4342 &
162  mr_id=$!
163}
164
165function start_map_server
166{
167  echo "starting dummy map server on interface $1"
168  python scripts/dummy_map_server.py "$1" 4342 &
169  ms_id=$!
170}
171
172function check_counters
173{
174  python scripts/vat/check_counters.py ${VPP_API_TEST} ${VAT_TEMPLATES} "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8"
175}
176
177