551f74d410fe8f085eb996dd3e3fa7034a81db1b
[one.git] / tests / data_plane / vpp_lite_topo / topologies / basic_topo_l2.sh
1 #!/usr/bin/env bash
2
3 function basic_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 intervppns ifconfig vppbr down
11   ip netns exec intervppns 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_intervpp1 &> /dev/null
15   ip link del dev veth_intervpp2 &> /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 intervppns &> /dev/null
20
21   if [ "$1" != "no_odl" ] ; then
22     odl_clear_all
23   fi
24 }
25
26 function set_arp
27 {
28   mac1=`ip netns exec vppns1 ip a show dev veth_vpp1  | grep "link/ether" | awk '{print $2}'`
29   ip netns exec vppns2 arp -s 6.0.1.11 $mac1
30
31   mac2=`ip netns exec vppns2 ip a show dev veth_vpp2  | grep "link/ether" | awk '{print $2}'`
32   ip netns exec vppns1 arp -s 6.0.1.12 $mac2
33 }
34
35 function basic_topo_setup
36 {
37
38   # create vpp to clients and inter-vpp namespaces
39   ip netns add vppns1
40   ip netns add vppns2
41   ip netns add intervppns
42
43   # create vpp and odl interfaces and set them in intervppns
44   ip link add veth_intervpp1 type veth peer name intervpp1
45   ip link add veth_intervpp2 type veth peer name intervpp2
46   ip link add veth_odl type veth peer name odl
47   ip link set dev intervpp1 up
48   ip link set dev intervpp2 up
49   ip link set dev odl up
50   ip link set dev veth_intervpp1 up netns intervppns
51   ip link set dev veth_intervpp2 up netns intervppns
52   ip link set dev veth_odl up netns intervppns
53
54   # create bridge in intervppns and add vpp and odl interfaces
55   ip netns exec intervppns brctl addbr vppbr
56   ip netns exec intervppns brctl addif vppbr veth_intervpp1
57   ip netns exec intervppns brctl addif vppbr veth_intervpp2
58   ip netns exec intervppns brctl addif vppbr veth_odl
59   ip netns exec intervppns ifconfig vppbr 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 address 08:11:11:11:11:11
65   ip link set dev veth_vpp1 up netns vppns1
66
67   # create and configure 2nd veth client to vpp pair
68   ip link add veth_vpp2 type veth peer name vpp2
69   ip link set dev vpp2 up
70   ip link set dev veth_vpp2 address 08:22:22:22:22:22
71   ip link set dev veth_vpp2 up netns vppns2
72
73   ip netns exec vppns1 \
74   bash -c "
75     ip link set dev lo up
76     ip addr add 6.0.1.11/24 dev veth_vpp1
77     ip addr add 6:0:1::11/64 dev veth_vpp1
78   "
79
80   ip netns exec vppns2 \
81   bash -c "
82     ip link set dev lo up
83     ip addr add 6.0.1.12/24 dev veth_vpp2
84     ip addr add 6:0:1::12/64 dev veth_vpp2
85   "
86
87   # set odl iface ip and disable checksum offloading
88   ip addr add 6.0.3.100/24 dev odl
89   ip addr add 6:0:3::100/64 dev odl
90   ethtool --offload  odl rx off tx off
91
92   # generate config files
93   ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
94
95   start_vpp 5002 vpp1
96   start_vpp 5003 vpp2
97
98   maybe_pause
99
100   sleep 2
101   echo "* Selected configuration method: $CFG_METHOD"
102   if [ "$CFG_METHOD" == "cli" ] ; then
103     echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
104     echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
105   elif [ "$CFG_METHOD" == "vat" ] ; then
106     ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
107     ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
108   else
109     echo "=== WARNING:"
110     echo "=== Invalid configuration method selected!"
111     echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
112     echo "==="
113   fi
114
115   if [ "$1" != "no_odl" ] ; then
116     post_curl "add-mapping" ${ODL_CONFIG_FILE1}
117     post_curl "add-mapping" ${ODL_CONFIG_FILE2}
118   fi
119
120   # avoid arp requests
121   set_arp
122 }
123