1572c17d6SFilip Tehlar
2572c17d6SFilip Tehlar#!/usr/bin/env bash
3572c17d6SFilip Tehlar
4572c17d6SFilip Tehlarfunction rtr_two_iface_two_customers_clean {
5572c17d6SFilip Tehlar  echo "Clearing all VPP instances.."
6572c17d6SFilip Tehlar  pkill vpp --signal 9
7572c17d6SFilip Tehlar
8572c17d6SFilip Tehlar  rm /dev/shm/*
9572c17d6SFilip Tehlar
10572c17d6SFilip Tehlar  echo "Cleaning RTR topology.."
11572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns ifconfig vppbr1 down
12572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns brctl delbr vppbr1
13572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns ifconfig vppbr2 down
14572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns brctl delbr vppbr2
15572c17d6SFilip Tehlar  ip link del dev vpp1 &> /dev/null
16572c17d6SFilip Tehlar  ip link del dev vpp2 &> /dev/null
17572c17d6SFilip Tehlar  ip link del dev vpp1_rtr &> /dev/null
18572c17d6SFilip Tehlar  ip link del dev rtr1_vpp1 &> /dev/null
19572c17d6SFilip Tehlar  ip link del dev vpp2_rtr &> /dev/null
20572c17d6SFilip Tehlar  ip link del dev rtr_vpp2 &> /dev/null
21572c17d6SFilip Tehlar  ip link del dev odl_vpp1 &> /dev/null
22572c17d6SFilip Tehlar  ip link del dev odl_vpp2 &> /dev/null
23572c17d6SFilip Tehlar
24572c17d6SFilip Tehlar  ip netns del vpp1-cus1-ns &> /dev/null
25572c17d6SFilip Tehlar  ip netns del vpp2-cus1-ns &> /dev/null
26572c17d6SFilip Tehlar  ip netns del vpp1-cus2-ns &> /dev/null
27572c17d6SFilip Tehlar  ip netns del vpp2-cus2-ns &> /dev/null
28572c17d6SFilip Tehlar  ip netns del vpp1-rtr-ns &> /dev/null
29572c17d6SFilip Tehlar  ip netns del vpp2-rtr-ns &> /dev/null
30572c17d6SFilip Tehlar
31572c17d6SFilip Tehlar  odl_clear_all
32572c17d6SFilip Tehlar}
33572c17d6SFilip Tehlar
34572c17d6SFilip Tehlarfunction rtr_two_iface_two_customers_setup {
35572c17d6SFilip Tehlar  # create namespaces
36572c17d6SFilip Tehlar  ip netns add vpp1-cus1-ns
37572c17d6SFilip Tehlar  ip netns add vpp1-cus2-ns
38572c17d6SFilip Tehlar  ip netns add vpp2-cus1-ns
39572c17d6SFilip Tehlar  ip netns add vpp2-cus2-ns
40572c17d6SFilip Tehlar  ip netns add vpp1-rtr-ns
41572c17d6SFilip Tehlar  ip netns add vpp2-rtr-ns
42572c17d6SFilip Tehlar
43572c17d6SFilip Tehlar  # create pair interfaces between vpp[1|2], rtr and odl
44572c17d6SFilip Tehlar  ip link add veth_vpp1_rtr type veth peer name vpp1_rtr
45572c17d6SFilip Tehlar  ip link add veth_rtr_vpp1 type veth peer name rtr_vpp1
46572c17d6SFilip Tehlar  ip link add veth_vpp2_rtr type veth peer name vpp2_rtr
47572c17d6SFilip Tehlar  ip link add veth_rtr_vpp2 type veth peer name rtr_vpp2
48572c17d6SFilip Tehlar  ip link add veth_odl_vpp1 type veth peer name odl_vpp1
49572c17d6SFilip Tehlar  ip link add veth_odl_vpp2 type veth peer name odl_vpp2
50572c17d6SFilip Tehlar
51572c17d6SFilip Tehlar  # enable peer interfaces
52572c17d6SFilip Tehlar  ip link set dev vpp1_rtr up
53572c17d6SFilip Tehlar  ip link set dev rtr_vpp1 up
54572c17d6SFilip Tehlar  ip link set dev vpp2_rtr up
55572c17d6SFilip Tehlar  ip link set dev rtr_vpp2 up
56572c17d6SFilip Tehlar  ip link set dev odl_vpp1 up
57572c17d6SFilip Tehlar  ip link set dev odl_vpp2 up
58572c17d6SFilip Tehlar
59572c17d6SFilip Tehlar  # enable veth interfaces and set them in the appropriate ip ns
60572c17d6SFilip Tehlar  ip link set dev veth_vpp1_rtr up netns vpp1-rtr-ns
61572c17d6SFilip Tehlar  ip link set dev veth_rtr_vpp1 up netns vpp1-rtr-ns
62572c17d6SFilip Tehlar  ip link set dev veth_vpp2_rtr up netns vpp2-rtr-ns
63572c17d6SFilip Tehlar  ip link set dev veth_rtr_vpp2 up netns vpp2-rtr-ns
64572c17d6SFilip Tehlar  ip link set dev veth_odl_vpp1 up netns vpp1-rtr-ns
65572c17d6SFilip Tehlar  ip link set dev veth_odl_vpp2 up netns vpp2-rtr-ns
66572c17d6SFilip Tehlar
67572c17d6SFilip Tehlar  # vpp1, rtr and odl
68572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns brctl addbr vppbr1
69572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_vpp1_rtr
70572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_rtr_vpp1
71572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_odl_vpp1
72572c17d6SFilip Tehlar  ip netns exec vpp1-rtr-ns ifconfig vppbr1 up
73572c17d6SFilip Tehlar
74572c17d6SFilip Tehlar  # vpp2, rtr and odl
75572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns brctl addbr vppbr2
76572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_vpp2_rtr
77572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_rtr_vpp2
78572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_odl_vpp2
79572c17d6SFilip Tehlar  ip netns exec vpp2-rtr-ns ifconfig vppbr2 up
80572c17d6SFilip Tehlar
81572c17d6SFilip Tehlar  # vpp1 to client1
82572c17d6SFilip Tehlar  ip link add veth_vpp1_cus1 type veth peer name vpp1_cus1
83572c17d6SFilip Tehlar  ip link set dev vpp1_cus1 up
84572c17d6SFilip Tehlar  ip link set dev veth_vpp1_cus1 up netns vpp1-cus1-ns
85572c17d6SFilip Tehlar
86572c17d6SFilip Tehlar  ip netns exec vpp1-cus1-ns \
87572c17d6SFilip Tehlar    bash -c "
88572c17d6SFilip Tehlar      ip link set dev lo up
89572c17d6SFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp1_cus1
90572c17d6SFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp1_cus1
91572c17d6SFilip Tehlar      ip route add 6.0.4.0/24 via 6.0.2.1
92572c17d6SFilip Tehlar      ip route add 6:0:4::0/64 via 6:0:2::1
93572c17d6SFilip Tehlar  "
94572c17d6SFilip Tehlar  # vpp1 to client2
95572c17d6SFilip Tehlar  ip link add veth_vpp1_cus2 type veth peer name vpp1_cus2
96572c17d6SFilip Tehlar  ip link set dev vpp1_cus2 up
97572c17d6SFilip Tehlar  ip link set dev veth_vpp1_cus2 up netns vpp1-cus2-ns
98572c17d6SFilip Tehlar
99572c17d6SFilip Tehlar  ip netns exec vpp1-cus2-ns \
100572c17d6SFilip Tehlar    bash -c "
101572c17d6SFilip Tehlar      ip link set dev lo up
102572c17d6SFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp1_cus2
103572c17d6SFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp1_cus2
104572c17d6SFilip Tehlar      ip route add 6.0.4.0/24 via 6.0.2.1
105572c17d6SFilip Tehlar      ip route add 6:0:4::0/64 via 6:0:2::1
106572c17d6SFilip Tehlar  "
107572c17d6SFilip Tehlar
108572c17d6SFilip Tehlar  # vpp2 to client1
109572c17d6SFilip Tehlar  ip link add veth_vpp2_cus1 type veth peer name vpp2_cus1
110572c17d6SFilip Tehlar  ip link set dev vpp2_cus1 up
111572c17d6SFilip Tehlar  ip link set dev veth_vpp2_cus1 up netns vpp2-cus1-ns
112572c17d6SFilip Tehlar
113572c17d6SFilip Tehlar  ip netns exec vpp2-cus1-ns \
114572c17d6SFilip Tehlar    bash -c "
115572c17d6SFilip Tehlar      ip link set dev lo up
116572c17d6SFilip Tehlar      ip addr add 6.0.4.4/24 dev veth_vpp2_cus1
117572c17d6SFilip Tehlar      ip addr add 6:0:4::4/64 dev veth_vpp2_cus1
118572c17d6SFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.4.1
119572c17d6SFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:4::1
120572c17d6SFilip Tehlar  "
121572c17d6SFilip Tehlar  # vpp2 to client2
122572c17d6SFilip Tehlar  ip link add veth_vpp2_cus2 type veth peer name vpp2_cus2
123572c17d6SFilip Tehlar  ip link set dev vpp2_cus2 up
124572c17d6SFilip Tehlar  ip link set dev veth_vpp2_cus2 up netns vpp2-cus2-ns
125572c17d6SFilip Tehlar
126572c17d6SFilip Tehlar  ip netns exec vpp2-cus2-ns \
127572c17d6SFilip Tehlar    bash -c "
128572c17d6SFilip Tehlar      ip link set dev lo up
129572c17d6SFilip Tehlar      ip addr add 6.0.4.4/24 dev veth_vpp2_cus2
130572c17d6SFilip Tehlar      ip addr add 6:0:4::4/64 dev veth_vpp2_cus2
131572c17d6SFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.4.1
132572c17d6SFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:4::1
133572c17d6SFilip Tehlar  "
134572c17d6SFilip Tehlar
135572c17d6SFilip Tehlar  # vpp1 to odl
136572c17d6SFilip Tehlar  ip addr add 6.0.3.100/24 dev odl_vpp1
137572c17d6SFilip Tehlar  ip addr add 6:0:3::100/64 dev odl_vpp1
138572c17d6SFilip Tehlar  ethtool --offload  odl_vpp1 rx off tx off
139572c17d6SFilip Tehlar
140572c17d6SFilip Tehlar  # vpp2 to odl
141572c17d6SFilip Tehlar  ip addr add 6.0.5.100/24 dev odl_vpp2
142572c17d6SFilip Tehlar  ip addr add 6:0:5::100/64 dev odl_vpp2
143572c17d6SFilip Tehlar  ethtool --offload  odl_vpp2 rx off tx off
144572c17d6SFilip Tehlar
145bf231ba7SFilip Tehlar  # generate config files
146bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
147bf231ba7SFilip Tehlar
148bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
149bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
150bf231ba7SFilip Tehlar  start_vpp 5004 vpp3
151bf231ba7SFilip Tehlar
152bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
153bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
154bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
155bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
156bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
157bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
158bf231ba7SFilip Tehlar    sleep 2
159bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
160bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
161bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
162bf231ba7SFilip Tehlar  else
163bf231ba7SFilip Tehlar    echo "=== WARNING:"
164bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
165bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
166bf231ba7SFilip Tehlar    echo "==="
167bf231ba7SFilip Tehlar  fi
168572c17d6SFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE1}
169572c17d6SFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE2}
170572c17d6SFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE3}
171572c17d6SFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE4}
172572c17d6SFilip Tehlar}
173