3_node_star.sh revision 3db341de
1#!/usr/bin/env bash
2
3#                                 +--------+
4#                                 |        |
5#               6.0.10.25         |   MR   |
6#            08:55:55:55:55:55    |        |
7#                    +            +--------+
8#                    |                 |6.0.3.100
9# 6:0:1::2           |vpp8             |6:0:3::100
10# 6.0.1.2     vpp1 +-+------+          |         +--------+
11#        +---------+        |xtr1      |    xtr2 |        |vpp2
12#                  |  VPP1  +----------+---------+  VPP2  +---------+
13#        +---------+        |          |         |        |      6.0.2.2
14# 6.0.5.5     vpp3 +-+------+          |         +-----+--+      6:0:2::2
15# 6:0:5::5           |vpp5             |xtr3           |vpp7
16#                    |             +--------+          |
17#                    +             |        |          + 6.0.10.22
18#                6.0.10.21         |  VPP3  |             08:22:22:22:22:22
19#            08:11:11:11:11:11     |        |
20#             6:0:10::21           +-+----+-+
21#                                vpp6|    |vpp4
22#                                    |    |
23#                                    |    +6.0.2.2
24#                                    +     6:0:2::2
25#                             6.0.10.22
26#                             6:0:10::22
27#                             08:22:22:22:22:22
28#
29
30
31function 3_node_star_topo_clean
32{
33  echo "Clearing all VPP instances.."
34  pkill vpp --signal 9
35
36  rm /dev/shm/*
37
38  echo "Cleaning 3 node star topology..."
39  ip netns exec xtr-ns ifconfig vppbr1 down
40  ip netns exec xtr-ns brctl delbr vppbr1
41  ip link del dev vpp1 &> /dev/null
42  ip link del dev vpp2 &> /dev/null
43  ip link del dev vpp3 &> /dev/null
44  ip link del dev vpp4 &> /dev/null
45  ip link del dev vpp5 &> /dev/null
46  ip link del dev vpp6 &> /dev/null
47  ip link del dev vpp7 &> /dev/null
48  ip link del dev vpp8 &> /dev/null
49  ip link del dev xtr1 &> /dev/null
50  ip link del dev xtr2 &> /dev/null
51  ip link del dev xtr3 &> /dev/null
52  ip link del dev odl &> /dev/null
53
54  ip netns del vpp-ns1 &> /dev/null
55  ip netns del vpp-ns2 &> /dev/null
56  ip netns del vpp-ns3 &> /dev/null
57  ip netns del vpp-ns4 &> /dev/null
58  ip netns del vpp-ns5 &> /dev/null
59  ip netns del vpp-ns6 &> /dev/null
60  ip netns del vpp-ns7 &> /dev/null
61  ip netns del vpp-ns8 &> /dev/null
62  ip netns del xtr-ns &> /dev/null
63
64  if [ "$1" != "no_odl" ] ; then
65    odl_clear_all
66  fi
67}
68
69function set_arp
70{
71  odl_mac=`ip a show dev odl | grep "link/ether" | awk '{print $2}'`
72  echo "set ip arp host-xtr1 6.0.3.100 $odl_mac" | nc 0 5002
73  echo "set ip arp host-xtr2 6.0.3.100 $odl_mac" | nc 0 5003
74  echo "set ip arp host-xtr3 6.0.3.100 $odl_mac" | nc 0 5004
75
76  mac1=`ip netns exec vpp-ns5 ip a show dev veth_vpp5  | grep "link/ether" | awk '{print $2}'`
77  ip netns exec vpp-ns6 arp -s 6.0.10.21 $mac1
78
79  mac2=`ip netns exec vpp-ns8 ip a show dev veth_vpp8  | grep "link/ether" | awk '{print $2}'`
80  ip netns exec vpp-ns7 arp -s 6.0.10.25 $mac2
81
82  mac3=`ip netns exec vpp-ns7 ip a show dev veth_vpp7  | grep "link/ether" | awk '{print $2}'`
83  ip netns exec vpp-ns5 arp -s 6.0.10.22 $mac3
84  ip netns exec vpp-ns8 arp -s 6.0.10.22 $mac3
85}
86
87function 3_node_star_topo_setup
88{
89  ip netns add vpp-ns1
90  ip netns add vpp-ns2
91  ip netns add vpp-ns3
92  ip netns add vpp-ns4
93  ip netns add vpp-ns5
94  ip netns add vpp-ns6
95  ip netns add vpp-ns7
96  ip netns add vpp-ns8
97  ip netns add xtr-ns
98
99  ip link add veth_xtr1 type veth peer name xtr1
100  ip link add veth_xtr2 type veth peer name xtr2
101  ip link add veth_xtr3 type veth peer name xtr3
102  ip link add veth_odl type veth peer name odl
103  ip link set dev xtr1 up
104  ip link set dev xtr2 up
105  ip link set dev xtr3 up
106  ip link set dev odl up
107
108  ip link set dev veth_xtr1 up netns xtr-ns
109  ip link set dev veth_xtr2 up netns xtr-ns
110  ip link set dev veth_xtr3 up netns xtr-ns
111  ip link set dev veth_odl up netns xtr-ns
112
113  ip netns exec xtr-ns brctl addbr vppbr1
114  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr1
115  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr2
116  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr3
117  ip netns exec xtr-ns brctl addif vppbr1 veth_odl
118  ip netns exec xtr-ns ifconfig vppbr1 up
119
120  ip link add veth_vpp1 type veth peer name vpp1
121  ip link set dev vpp1 up
122  ip link set dev veth_vpp1 up netns vpp-ns1
123
124  ip netns exec vpp-ns1 \
125    bash -c "
126      ip link set dev lo up
127      ip addr add 6.0.1.2/24 dev veth_vpp1
128      ip addr add 6:0:1::2/64 dev veth_vpp1
129      ip route add 6.0.2.0/24 via 6.0.1.1
130      ip route add 6:0:2::0/64 via 6:0:1::1
131  "
132
133  ip link add veth_vpp2 type veth peer name vpp2
134  ip link set dev vpp2 up
135  ip link set dev veth_vpp2 up netns vpp-ns2
136
137  ip netns exec vpp-ns2 \
138    bash -c "
139      ip link set dev lo up
140      ip addr add 6.0.2.2/24 dev veth_vpp2
141      ip addr add 6:0:2::2/64 dev veth_vpp2
142      ip route add 6.0.1.0/24 via 6.0.2.1
143      ip route add 6:0:1::0/64 via 6:0:2::1
144  "
145
146  ip link add veth_vpp3 type veth peer name vpp3
147  ip link set dev vpp3 up
148  ip link set dev veth_vpp3 up netns vpp-ns3
149
150  ip netns exec vpp-ns3 \
151    bash -c "
152      ip link set dev lo up
153      ip addr add 6.0.5.5/24 dev veth_vpp3
154      ip addr add 6:0:5::5/64 dev veth_vpp3
155      ip route add 6.0.2.0/24 via 6.0.5.1
156      ip route add 6:0:2::0/64 via 6:0:5::1
157  "
158
159  ip link add veth_vpp4 type veth peer name vpp4
160  ip link set dev vpp4 up
161  ip link set dev veth_vpp4 up netns vpp-ns4
162
163  ip netns exec vpp-ns4 \
164    bash -c "
165      ip link set dev lo up
166      ip addr add 6.0.2.2/24 dev veth_vpp4
167      ip addr add 6:0:2::2/64 dev veth_vpp4
168      ip route add 6.0.5.0/24 via 6.0.2.1
169      ip route add 6:0:5::0/64 via 6:0:2::1
170  "
171
172  ip link add veth_vpp5 type veth peer name vpp5
173  ip link set dev vpp5 up
174  ip link set dev veth_vpp5 address 08:11:11:11:11:11
175  ip link set dev veth_vpp5 up netns vpp-ns5
176
177  ip netns exec vpp-ns5 \
178    bash -c "
179      ip link set dev lo up
180      ip addr add 6.0.10.21/24 dev veth_vpp5
181      ip addr add 6:0:10::21/64 dev veth_vpp5
182  "
183
184  ip link add veth_vpp6 type veth peer name vpp6
185  ip link set dev vpp6 up
186  ip link set dev veth_vpp6 address 08:22:22:22:22:22
187  ip link set dev veth_vpp6 up netns vpp-ns6
188
189  ip netns exec vpp-ns6 \
190    bash -c "
191      ip link set dev lo up
192      ip addr add 6.0.10.22/24 dev veth_vpp6
193      ip addr add 6:0:10::22/64 dev veth_vpp6
194  "
195
196  ip link add veth_vpp7 type veth peer name vpp7
197  ip link set dev vpp7 up
198  ip link set dev veth_vpp7 address 08:22:22:22:22:22
199  ip link set dev veth_vpp7 up netns vpp-ns7
200
201  ip netns exec vpp-ns7 \
202    bash -c "
203      ip link set dev lo up
204      ip addr add 6.0.10.22/24 dev veth_vpp7
205  "
206
207  ip link add veth_vpp8 type veth peer name vpp8
208  ip link set dev vpp8 up
209  ip link set dev veth_vpp8 address 08:55:55:55:55:55
210  ip link set dev veth_vpp8 up netns vpp-ns8
211
212  ip netns exec vpp-ns8 \
213    bash -c "
214      ip link set dev lo up
215      ip addr add 6.0.10.25/24 dev veth_vpp8
216  "
217
218  ip addr add 6.0.3.100/24 dev odl
219  ip addr add 6:0:3::100/64 dev odl
220  ethtool --offload  odl rx off tx off
221maybe_pause
222  # generate config files
223  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
224
225  start_vpp 5002 vpp1
226  start_vpp 5003 vpp2
227  start_vpp 5004 vpp3
228
229  echo "* Selected configuration method: $CFG_METHOD"
230  if [ "$CFG_METHOD" == "cli" ] ; then
231    sleep 1
232    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
233    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
234    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
235  elif [ "$CFG_METHOD" == "vat" ] ; then
236    sleep 2
237    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
238    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
239    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
240  else
241    echo "=== WARNING:"
242    echo "=== Invalid configuration method selected!"
243    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
244    echo "==="
245  fi
246
247  if [ "$1" != "no_odl" ] ; then
248    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
249    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
250  fi
251
252  if [ "$2" != "no_arp" ] ; then
253    set_arp
254  fi
255}
256