rtr_two_iface.sh revision bf231ba7
1#!/usr/bin/env bash
2
3function rtr_two_iface_clean {
4  echo "Clearing all VPP instances.."
5  pkill vpp --signal 9
6
7  rm /dev/shm/*
8
9  echo "Cleaning RTR topology.."
10  ip netns exec vpp1-rtr-ns ifconfig vppbr1 down
11  ip netns exec vpp1-rtr-ns brctl delbr vppbr1
12  ip netns exec vpp2-rtr-ns ifconfig vppbr2 down
13  ip netns exec vpp2-rtr-ns brctl delbr vppbr2
14  ip link del dev vpp1 &> /dev/null
15  ip link del dev vpp2 &> /dev/null
16  ip link del dev vpp1_rtr &> /dev/null
17  ip link del dev rtr1_vpp1 &> /dev/null
18  ip link del dev vpp2_rtr &> /dev/null
19  ip link del dev rtr_vpp2 &> /dev/null
20  ip link del dev odl_vpp1 &> /dev/null
21  ip link del dev odl_vpp2 &> /dev/null
22
23  ip netns del vpp1-ns &> /dev/null
24  ip netns del vpp2-ns &> /dev/null
25  ip netns del vpp1-rtr-ns &> /dev/null
26  ip netns del vpp2-rtr-ns &> /dev/null
27
28  odl_clear_all
29}
30
31function rtr_two_iface_setup {
32  # create namespaces
33  ip netns add vpp1-ns
34  ip netns add vpp2-ns
35  ip netns add vpp1-rtr-ns
36  ip netns add vpp2-rtr-ns
37
38  # create pair interfaces between vpp[1|2], rtr and odl
39  ip link add veth_vpp1_rtr type veth peer name vpp1_rtr
40  ip link add veth_rtr_vpp1 type veth peer name rtr_vpp1
41  ip link add veth_vpp2_rtr type veth peer name vpp2_rtr
42  ip link add veth_rtr_vpp2 type veth peer name rtr_vpp2
43  ip link add veth_odl_vpp1 type veth peer name odl_vpp1
44  ip link add veth_odl_vpp2 type veth peer name odl_vpp2
45
46  # enable peer interfaces
47  ip link set dev vpp1_rtr up
48  ip link set dev rtr_vpp1 up
49  ip link set dev vpp2_rtr up
50  ip link set dev rtr_vpp2 up
51  ip link set dev odl_vpp1 up
52  ip link set dev odl_vpp2 up
53
54  # enable veth interfaces and set them in the appropriate ip ns
55  ip link set dev veth_vpp1_rtr up netns vpp1-rtr-ns
56  ip link set dev veth_rtr_vpp1 up netns vpp1-rtr-ns
57  ip link set dev veth_vpp2_rtr up netns vpp2-rtr-ns
58  ip link set dev veth_rtr_vpp2 up netns vpp2-rtr-ns
59  ip link set dev veth_odl_vpp1 up netns vpp1-rtr-ns
60  ip link set dev veth_odl_vpp2 up netns vpp2-rtr-ns
61
62  # vpp1, rtr and odl
63  ip netns exec vpp1-rtr-ns brctl addbr vppbr1
64  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_vpp1_rtr
65  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_rtr_vpp1
66  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_odl_vpp1
67  ip netns exec vpp1-rtr-ns ifconfig vppbr1 up
68
69  # vpp2, rtr and odl
70  ip netns exec vpp2-rtr-ns brctl addbr vppbr2
71  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_vpp2_rtr
72  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_rtr_vpp2
73  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_odl_vpp2
74  ip netns exec vpp2-rtr-ns ifconfig vppbr2 up
75
76  # vpp1 to client
77  ip link add veth_vpp1 type veth peer name vpp1
78  ip link set dev vpp1 up
79  ip link set dev veth_vpp1 up netns vpp1-ns
80
81  ip netns exec vpp1-ns \
82    bash -c "
83      ip link set dev lo up
84      ip addr add 6.0.2.2/24 dev veth_vpp1
85      ip addr add 6:0:2::2/64 dev veth_vpp1
86      ip route add 6.0.4.0/24 via 6.0.2.1
87      ip route add 6:0:4::0/64 via 6:0:2::1
88  "
89
90  # vpp2 to client
91  ip link add veth_vpp2 type veth peer name vpp2
92  ip link set dev vpp2 up
93  ip link set dev veth_vpp2 up netns vpp2-ns
94
95  ip netns exec vpp2-ns \
96    bash -c "
97      ip link set dev lo up
98      ip addr add 6.0.4.4/24 dev veth_vpp2
99      ip addr add 6:0:4::4/64 dev veth_vpp2
100      ip route add 6.0.2.0/24 via 6.0.4.1
101      ip route add 6:0:2::0/64 via 6:0:4::1
102  "
103
104  # vpp1 to odl
105  ip addr add 6.0.3.100/24 dev odl_vpp1
106  ip addr add 6:0:3::100/64 dev odl_vpp1
107  ethtool --offload  odl_vpp1 rx off tx off
108
109  # vpp2 to odl
110  ip addr add 6.0.5.100/24 dev odl_vpp2
111  ip addr add 6:0:5::100/64 dev odl_vpp2
112  ethtool --offload  odl_vpp2 rx off tx off
113
114  # generate config files
115  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
116
117  start_vpp 5002 vpp1
118  start_vpp 5003 vpp2
119  start_vpp 5004 vpp3
120
121  echo "* Selected configuration method: $CFG_METHOD"
122  if [ "$CFG_METHOD" == "cli" ] ; then
123    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
124    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
125    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
126  elif [ "$CFG_METHOD" == "vat" ] ; then
127    sleep 2
128    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
129    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
130    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
131  else
132    echo "=== WARNING:"
133    echo "=== Invalid configuration method selected!"
134    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
135    echo "==="
136  fi
137  post_curl "add-mapping" ${ODL_CONFIG_FILE1}
138  post_curl "add-mapping" ${ODL_CONFIG_FILE2}
139}
140