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