07a85b35c181b12f09e3a95e00a23bb1b557abd7
[one.git] / tests / data_plane / vpp_lite_topo / topologies / multihoming_topo_l2.sh
1 #!/usr/bin/env bash
2
3 function multihoming_topo_clean
4 {
5   echo "Clearing all VPP instances.."
6   pkill vpp --signal 9
7   rm /dev/shm/*
8
9   echo "Cleaning topology.."
10   ip netns exec intervppns1 ifconfig vppbr down
11   ip netns exec intervppns1 brctl delbr vppbr
12   ip link del dev veth_vpp1 &> /dev/null
13   ip link del dev veth_vpp2 &> /dev/null
14   ip link del dev veth_intervpp11 &> /dev/null
15   ip link del dev veth_intervpp12 &> /dev/null
16   ip link del dev veth_odl &> /dev/null
17   ip netns del vppns1 &> /dev/null
18   ip netns del vppns2 &> /dev/null
19   ip netns del intervppns1 &> /dev/null
20
21   ip netns exec intervppns2 ifconfig vppbr down
22   ip netns exec intervppns2 brctl delbr vppbr
23   ip link del dev veth_intervpp21 &> /dev/null
24   ip link del dev veth_intervpp22 &> /dev/null
25   ip netns del intervppns2 &> /dev/null
26
27   if [ "$1" != "no_odl" ] ; then
28     odl_clear_all
29   fi
30 }
31
32 function set_arp
33 {
34   mac1=`ip netns exec vppns1 ip a show dev veth_vpp1  | grep "link/ether" | awk '{print $2}'`
35   ip netns exec vppns2 arp -s 6.0.1.11 $mac1
36
37   mac2=`ip netns exec vppns2 ip a show dev veth_vpp2  | grep "link/ether" | awk '{print $2}'`
38   ip netns exec vppns1 arp -s 6.0.1.12 $mac2
39 }
40
41 function multihoming_topo_setup
42 {
43
44   # create vpp to clients and inter-vpp namespaces
45   ip netns add vppns1
46   ip netns add vppns2
47   ip netns add intervppns1
48   ip netns add intervppns2
49
50   # create vpp and odl interfaces and set them in intervppns1
51   ip link add veth_intervpp11 type veth peer name intervpp11
52   ip link add veth_intervpp12 type veth peer name intervpp12
53   ip link add veth_odl type veth peer name odl
54   ip link set dev intervpp11 up
55   ip link set dev intervpp12 up
56   ip link set dev odl up
57   ip link set dev veth_intervpp11 up netns intervppns1
58   ip link set dev veth_intervpp12 up netns intervppns1
59   ip link set dev veth_odl up netns intervppns1
60
61   ip link add veth_intervpp21 type veth peer name intervpp21
62   ip link add veth_intervpp22 type veth peer name intervpp22
63   ip link set dev intervpp21 up
64   ip link set dev intervpp22 up
65   ip link set dev veth_intervpp21 up netns intervppns2
66   ip link set dev veth_intervpp22 up netns intervppns2
67
68   # create bridge in intervppns1 and add vpp and odl interfaces
69   ip netns exec intervppns1 brctl addbr vppbr
70   ip netns exec intervppns1 brctl addif vppbr veth_intervpp11
71   ip netns exec intervppns1 brctl addif vppbr veth_intervpp12
72   ip netns exec intervppns1 brctl addif vppbr veth_odl
73   ip netns exec intervppns1 ifconfig vppbr up
74
75   # create bridge in intervppns2 and add vpp and odl interfaces
76   ip netns exec intervppns2 brctl addbr vppbr
77   ip netns exec intervppns2 brctl addif vppbr veth_intervpp21
78   ip netns exec intervppns2 brctl addif vppbr veth_intervpp22
79   ip netns exec intervppns2 brctl addif vppbr veth_odl
80   ip netns exec intervppns2 ifconfig vppbr up
81
82   # create and configure 1st veth client to vpp pair
83   ip link add veth_vpp1 type veth peer name vpp1
84   ip link set dev vpp1 up
85   ip link set dev veth_vpp1 address 08:11:11:11:11:11
86   ip link set dev veth_vpp1 up netns vppns1
87
88   # create and configure 2nd veth client to vpp pair
89   ip link add veth_vpp2 type veth peer name vpp2
90   ip link set dev vpp2 up
91   ip link set dev veth_vpp2 address 08:22:22:22:22:22
92   ip link set dev veth_vpp2 up netns vppns2
93
94   ip netns exec vppns1 \
95   bash -c "
96     ip link set dev lo up
97     ip addr add 6.0.1.11/24 dev veth_vpp1
98     ip addr add 6:0:1::11/64 dev veth_vpp1
99   "
100
101   ip netns exec vppns2 \
102   bash -c "
103     ip link set dev lo up
104     ip addr add 6.0.1.12/24 dev veth_vpp2
105     ip addr add 6:0:1::12/64 dev veth_vpp2
106   "
107
108   # set odl iface ip and disable checksum offloading
109   ip addr add 6.0.3.100/24 dev odl
110   ip addr add 6:0:3::100/64 dev odl
111   ethtool --offload  odl rx off tx off
112
113   # generate config files
114   ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
115
116   start_vpp 5002 vpp1
117   start_vpp 5003 vpp2
118
119   echo "* Selected configuration method: $CFG_METHOD"
120   sleep 2
121   if [ "$CFG_METHOD" == "cli" ] ; then
122     echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
123     echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
124   elif [ "$CFG_METHOD" == "vat" ] ; then
125     ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
126     ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
127   else
128     echo "=== WARNING:"
129     echo "=== Invalid configuration method selected!"
130     echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
131     echo "==="
132   fi
133
134   if [ "$1" != "no_odl" ] ; then
135     post_curl "add-mapping" ${ODL_CONFIG_FILE1}
136     post_curl "add-mapping" ${ODL_CONFIG_FILE2}
137   fi
138
139   set_arp
140 }
141