366bcbcde67b848f4afffeb40dd59c478671b4a3
[one.git] / tests / data_plane / vpp_lite_topo / topologies / 3_node_snake_topo.sh
1
2 function 3_node_snake_topo_clean
3 {
4   echo "Clearing all VPP instances.."
5   pkill vpp --signal 9
6   rm /dev/shm/*
7
8   echo "Cleaning topology.."
9   ip netns exec xtr-ns12 ifconfig br12 down
10   ip netns exec xtr-ns23 ifconfig br23 down
11
12   ip netns exec xtr-ns12 brctl delbr br12
13   ip netns exec xtr-ns23 brctl delbr br23
14
15   ip link del dev veth_vpp1 &> /dev/null
16   ip link del dev veth_vpp2 &> /dev/null
17   ip link del dev veth_xtr1_xtr2 &> /dev/null
18   ip link del dev veth_xtr2_xtr1 &> /dev/null
19   ip link del dev veth_xtr2_xtr3 &> /dev/null
20   ip link del dev veth_xtr3_xtr2 &> /dev/null
21
22   ip netns del vppns1 &> /dev/null
23   ip netns del vppns2 &> /dev/null
24   ip netns del xtr-ns12 &> /dev/null
25   ip netns del xtr-ns23 &> /dev/null
26 }
27
28 function 3_node_snake_topo_setup
29 {
30   ip netns add vppns1
31   ip netns add vppns2
32   ip netns add xtr-ns12
33   ip netns add xtr-ns23
34
35   ip link add veth_xtr1_xtr2 type veth peer name xtr1_xtr2
36   ip link add veth_xtr2_xtr1 type veth peer name xtr2_xtr1
37   ip link add veth_xtr2_xtr3 type veth peer name xtr2_xtr3
38   ip link add veth_xtr3_xtr2 type veth peer name xtr3_xtr2
39
40   # enable peer interfaces
41   ip link set dev xtr1_xtr2 up
42   ip link set dev xtr2_xtr1 up
43   ip link set dev xtr2_xtr3 up
44   ip link set dev xtr3_xtr2 up
45
46   ip link set dev veth_xtr1_xtr2 up netns xtr-ns12
47   ip link set dev veth_xtr2_xtr1 up netns xtr-ns12
48   ip link set dev veth_xtr2_xtr3 up netns xtr-ns23
49   ip link set dev veth_xtr3_xtr2 up netns xtr-ns23
50
51   ip netns exec xtr-ns12 brctl addbr br12
52   ip netns exec xtr-ns23 brctl addbr br23
53
54   ip netns exec xtr-ns12 brctl addif br12 veth_xtr1_xtr2
55   ip netns exec xtr-ns12 brctl addif br12 veth_xtr2_xtr1
56   ip netns exec xtr-ns12 ifconfig br12 up
57   ip netns exec xtr-ns23 brctl addif br23 veth_xtr2_xtr3
58   ip netns exec xtr-ns23 brctl addif br23 veth_xtr3_xtr2
59   ip netns exec xtr-ns23 ifconfig br23 up
60
61   # create and configure 1st veth client to vpp pair
62   ip link add veth_vpp1 type veth peer name vpp1
63   ip link set dev vpp1 up
64   ip link set dev veth_vpp1 up netns vppns1
65
66   # create and configure 2nd veth client to vpp pair
67   ip link add veth_vpp2 type veth peer name vpp2
68   ip link set dev vpp2 up
69   ip link set dev veth_vpp2 up netns vppns2
70
71   ip netns exec vppns1 \
72   bash -c "
73     ip link set dev lo up
74     ip addr add 6.0.1.2/24 dev veth_vpp1
75     ip route add 6.0.2.0/24 via 6.0.1.1
76     ip addr add 6:0:1::2/64 dev veth_vpp1
77     ip route add 6:0:2::0/64 via 6:0:1::1
78   "
79
80   ip netns exec vppns2 \
81   bash -c "
82     ip link set dev lo up
83     ip addr add 6.0.2.2/24 dev veth_vpp2
84     ip route add 6.0.1.0/24 via 6.0.2.1
85     ip addr add 6:0:2::2/64 dev veth_vpp2
86     ip route add 6:0:1::0/64 via 6:0:2::1
87   "
88
89   # generate config files
90   ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
91
92   start_vpp 5002 vpp1
93   start_vpp 5003 vpp2
94   start_vpp 5004 vpp3
95
96   sleep 2
97   echo "* Selected configuration method: $CFG_METHOD"
98   if [ "$CFG_METHOD" == "cli" ] ; then
99     echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
100     echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
101     echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
102   elif [ "$CFG_METHOD" == "vat" ] ; then
103     ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
104     ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
105     ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
106   else
107     echo "=== WARNING:"
108     echo "=== Invalid configuration method selected!"
109     echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
110     echo "==="
111   fi
112 }