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