Merge "Add enable/disable test"
[one.git] / tests / data_plane / csit_topo / lisp_test.sh
1 #!/usr/bin/env bash
2 #
3 #
4 #         +------+                   +-----+
5 #         |      | VPP1_INT  TG_INT1 |     |
6 #         | VPP1 +-------------------+ TG  |
7 #         |      |                   |     |
8 #         |      |                   |     |
9 #         +--+---+                   +--+--+
10 #            | VPP1_INT                 | TG_INT2
11 #   ODL_INT  |                          |
12 # ODL -------|                          |
13 #            | VPP2_INT                 |
14 #         +--+---+                      |
15 #         |      | VPP2_INT             |
16 #         | VPP2 +----------------------+
17 #         |      |
18 #         |      |
19 #         +------+
20
21 if [ "$1" == "-h" ] || [ "$1" == "-help" ] ; then
22   echo "lisp_test.sh [ip4] [ip6] [ip4_ip6] [4o6] [6o4] [remote] [remote6]"
23   echo "        ip4 - test ip4 topology"
24   echo "        ip6 - test ip6 topology"
25   echo "        ip4_ip6 - test ip4 and ip6 topology"
26   echo "        4o6 - test ip4 over ip6"
27   echo "        6o4 - test ip6 over ip4"
28   echo "        remote - test statick mapping, whit out ODL"
29   echo "        remote6 - test statick mapping for IPv6, whit out ODL"
30   exit 0
31 fi
32
33 set -x
34
35 USER="csit"
36 ODL_USER="admin"
37 ODL_PASSWD="admin"
38 VPP1_IP="192.168.255.101"
39 VPP2_IP="192.168.255.102"
40 TG_IP="192.168.255.100"
41 ODL_IP="192.168.255.10"
42 ODL_PORT="8181"
43 TMP_DIR="/tmp/vpp_${RANDOM}_lisp_test"
44 TG_INT1="eth2"
45 TG_INT2="eth3"
46 ODL_M_USER="user"
47 ODL_INT="eth2"
48 VPP_CONFIG_DIR="../configs/vpp_csit_config/"
49 VPP_CONFIG1="vpp1.conf"
50 VPP_CONFIG1_6="vpp1_6.conf"
51 VPP_CONFIG2="vpp2.conf"
52 VPP_CONFIG2_6="vpp2_6.conf"
53 VPP_RECONF2="vpp2_reconf.conf"
54 VPP_RECONF2_6="vpp2_reconf_6.conf"
55 ODL_CONFIG_DIR="../configs/odl/"
56 ODL_ADD_CONFIG1="add_ipv4_odl1.txt"
57 ODL_ADD_CONFIG1_6="add_ipv6_odl1.txt"
58 ODL_ADD_CONFIG2="add_ipv4_odl2.txt"
59 ODL_ADD_CONFIG2_6="add_ipv6_odl2.txt"
60 ODL_REPLACE_CONFIG2="replace_ipv4_odl2.txt"
61 ODL_REPLACE_CONFIG2_6="replace_ipv6_odl2.txt"
62
63 if [ "$1" == "remote" ] ; then
64   VPP_CONFIG1="vpp1_remote.conf"
65   VPP_CONFIG2="vpp2_remote.conf"
66   VPP_RECONF1="vpp1_reconf_remote.conf"
67   VPP_RECONF2="vpp2_reconf.conf"
68 fi
69
70 if [ "$1" == "remote6" ] ; then
71   VPP_CONFIG1="vpp1_6_remote.conf"
72   VPP_CONFIG2="vpp2_6_remote.conf"
73   VPP_RECONF1="vpp1_6_reconf_remote.conf"
74   VPP_RECONF2="vpp2_reconf_6.conf"
75 fi
76
77 if [ "$1" == "4o6" ] ; then
78   VPP_CONFIG1="vpp1_4o6.conf"
79   VPP_CONFIG2="vpp2_4o6.conf"
80   VPP_RECONF2="vpp2_reconf_4o6.conf"
81   ODL_ADD_CONFIG1="add_ipv4o6_odl1.txt"
82   ODL_ADD_CONFIG2="add_ipv4o6_odl2.txt"
83   ODL_REPLACE_CONFIG2="replace_ipv4o6_odl2.txt"
84 fi
85
86 if [ "$1" == "6o4" ] ; then
87   VPP_CONFIG1="vpp1_6o4.conf"
88   VPP_CONFIG2="vpp2_6o4.conf"
89   VPP_RECONF2="vpp2_reconf_6o4.conf"
90   ODL_ADD_CONFIG1="add_ipv6o4_odl1.txt"
91   ODL_ADD_CONFIG2="add_ipv6o4_odl2.txt"
92   ODL_REPLACE_CONFIG2="replace_ipv6o4_odl2.txt"
93 fi
94
95 function ssh_vpp1 {
96     ssh ${USER}@${VPP1_IP} ${@} || exit
97 }
98
99 function ssh_vpp2 {
100     ssh ${USER}@${VPP2_IP} ${@} || exit
101 }
102
103 function ssh_tg {
104     ssh ${USER}@${TG_IP} ${@} || exit
105 }
106
107 function ssh_odl {
108     ssh ${ODL_M_USER}@${ODL_IP} ${@} || exit
109 }
110
111 function post_curl {
112   curl -X POST http://${ODL_IP}:${ODL_PORT}/restconf/operations/odl-mappingservice:${1} \
113      -H "Content-Type: application/json" --data-binary "@${ODL_CONFIG_DIR}${2}" \
114      -u ${ODL_USER}:${ODL_PASSWD}
115 }
116
117 if [ "$1" != "remote" ] && [ "$1" != "remote6" ]  ; then
118   curl -X DELETE http://${ODL_IP}:${ODL_PORT}/restconf/config/odl-mappingservice:mapping-database/ \
119        -u ${ODL_USER}:${ODL_PASSWD}
120 fi
121
122 ssh_tg "sudo ip netns del net2 &> /dev/null || exit 0"
123 ssh_tg "sudo ip addr flush dev ${TG_INT1} &> /dev/null || exit 0"
124 ssh_tg "sudo ip route del 6.0.2.0/24 via 6.0.1.1 || exit 0"
125 ssh_tg "sudo ip route del 6:0:2::0/64 via 6:0:1::1 || exit 0"
126
127 ssh_odl "sudo ip addr flush dev ${ODL_INT} &> /dev/null || exit 0"
128 ssh_odl "sudo ip addr add 6.0.3.100/24 dev ${ODL_INT}"
129 ssh_odl "sudo ip addr add 6:0:3::100/64 dev ${ODL_INT}"
130
131 ssh_odl "sudo ethtool --offload  ${ODL_INT}  rx off tx off"
132
133 ssh_vpp1 "sudo stop vpp;  exit 0"
134 ssh_vpp2 "sudo stop vpp;  exit 0"
135
136 ssh_vpp1 "sudo start vpp;  exit 0"
137 ssh_vpp2 "sudo start vpp;  exit 0"
138
139 ssh_vpp1 "mkdir ${TMP_DIR}"
140 ssh_vpp2 "mkdir ${TMP_DIR}"
141
142 ssh_tg "sudo ip netns add net2"
143 ssh_tg "sudo ip link set dev ${TG_INT2} netns net2"
144
145 if [ "$#" == 0 ] || [ "$1" == "ip4" ] ; then
146   source lisp_ip4.sh
147 fi
148
149 if [ "$1" == "ip6" ] ; then
150   source lisp_ip6.sh
151 fi
152
153 if [ "$1" == "4o6" ] ; then
154   source lisp_ip4o6.sh
155 fi
156
157 if [ "$1" == "6o4" ] ; then
158   source lisp_ip6o4.sh
159 fi
160
161 if [ "$1" == "ip4_ip6" ] ; then
162   source lisp_ip4.sh
163   source lisp_ip6.sh
164
165   ping_lisp
166   ping_lisp6
167 fi
168
169 if [ "$1" == "remote" ] ; then
170   source lisp_remote.sh
171 fi
172
173 if [ "$1" == "remote6" ] ; then
174   source lisp_6_remote.sh
175 fi
176
177 #clean tmp file
178 ssh_vpp1 "sudo rm -r ${TMP_DIR}"
179 ssh_vpp2 "sudo rm -r ${TMP_DIR}"
180
181 echo "Success"