15089c812SFilip Tehlar#!/usr/bin/env bash
25089c812SFilip Tehlar
35089c812SFilip Tehlar#                                 +--------+
45089c812SFilip Tehlar#                                 |        |
55089c812SFilip Tehlar#               6.0.10.25         |   MR   |
65089c812SFilip Tehlar#            08:55:55:55:55:55    |        |
75089c812SFilip Tehlar#                    +            +--------+
85089c812SFilip Tehlar#                    |                 |6.0.3.100
95089c812SFilip Tehlar# 6:0:1::2           |vpp8             |6:0:3::100
105089c812SFilip Tehlar# 6.0.1.2     vpp1 +-+------+          |         +--------+
115089c812SFilip Tehlar#        +---------+        |xtr1      |    xtr2 |        |vpp2
125089c812SFilip Tehlar#                  |  VPP1  +----------+---------+  VPP2  +---------+
135089c812SFilip Tehlar#        +---------+        |          |         |        |      6.0.2.2
145089c812SFilip Tehlar# 6.0.5.5     vpp3 +-+------+          |         +-----+--+      6:0:2::2
155089c812SFilip Tehlar# 6:0:5::5           |vpp5             |xtr3           |vpp7
165089c812SFilip Tehlar#                    |             +--------+          |
175089c812SFilip Tehlar#                    +             |        |          + 6.0.10.22
185089c812SFilip Tehlar#                6.0.10.21         |  VPP3  |             08:22:22:22:22:22
195089c812SFilip Tehlar#            08:11:11:11:11:11     |        |
203db341deSFilip Tehlar#             6:0:10::21           +-+----+-+
215089c812SFilip Tehlar#                                vpp6|    |vpp4
225089c812SFilip Tehlar#                                    |    |
235089c812SFilip Tehlar#                                    |    +6.0.2.2
245089c812SFilip Tehlar#                                    +     6:0:2::2
255089c812SFilip Tehlar#                             6.0.10.22
263db341deSFilip Tehlar#                             6:0:10::22
275089c812SFilip Tehlar#                             08:22:22:22:22:22
285089c812SFilip Tehlar#
295089c812SFilip Tehlar
305089c812SFilip Tehlar
315089c812SFilip Tehlarfunction 3_node_star_topo_clean
325089c812SFilip Tehlar{
335089c812SFilip Tehlar  echo "Clearing all VPP instances.."
345089c812SFilip Tehlar  pkill vpp --signal 9
355089c812SFilip Tehlar
365089c812SFilip Tehlar  rm /dev/shm/*
375089c812SFilip Tehlar
385089c812SFilip Tehlar  echo "Cleaning 3 node star topology..."
395089c812SFilip Tehlar  ip netns exec xtr-ns ifconfig vppbr1 down
405089c812SFilip Tehlar  ip netns exec xtr-ns brctl delbr vppbr1
415089c812SFilip Tehlar  ip link del dev vpp1 &> /dev/null
425089c812SFilip Tehlar  ip link del dev vpp2 &> /dev/null
435089c812SFilip Tehlar  ip link del dev vpp3 &> /dev/null
445089c812SFilip Tehlar  ip link del dev vpp4 &> /dev/null
455089c812SFilip Tehlar  ip link del dev vpp5 &> /dev/null
465089c812SFilip Tehlar  ip link del dev vpp6 &> /dev/null
475089c812SFilip Tehlar  ip link del dev vpp7 &> /dev/null
485089c812SFilip Tehlar  ip link del dev vpp8 &> /dev/null
495089c812SFilip Tehlar  ip link del dev xtr1 &> /dev/null
505089c812SFilip Tehlar  ip link del dev xtr2 &> /dev/null
515089c812SFilip Tehlar  ip link del dev xtr3 &> /dev/null
525089c812SFilip Tehlar  ip link del dev odl &> /dev/null
535089c812SFilip Tehlar
545089c812SFilip Tehlar  ip netns del vpp-ns1 &> /dev/null
555089c812SFilip Tehlar  ip netns del vpp-ns2 &> /dev/null
565089c812SFilip Tehlar  ip netns del vpp-ns3 &> /dev/null
575089c812SFilip Tehlar  ip netns del vpp-ns4 &> /dev/null
585089c812SFilip Tehlar  ip netns del vpp-ns5 &> /dev/null
595089c812SFilip Tehlar  ip netns del vpp-ns6 &> /dev/null
605089c812SFilip Tehlar  ip netns del vpp-ns7 &> /dev/null
615089c812SFilip Tehlar  ip netns del vpp-ns8 &> /dev/null
625089c812SFilip Tehlar  ip netns del xtr-ns &> /dev/null
635089c812SFilip Tehlar
64f20e6999SFilip Tehlar  if [ "$1" != "no_odl" ] ; then
65f20e6999SFilip Tehlar    odl_clear_all
66f20e6999SFilip Tehlar  fi
675089c812SFilip Tehlar}
685089c812SFilip Tehlar
695089c812SFilip Tehlarfunction set_arp
705089c812SFilip Tehlar{
719325071dSFilip Tehlar  odl_mac=`ip a show dev odl | grep "link/ether" | awk '{print $2}'`
729325071dSFilip Tehlar  echo "set ip arp host-xtr1 6.0.3.100 $odl_mac" | nc 0 5002
739325071dSFilip Tehlar  echo "set ip arp host-xtr2 6.0.3.100 $odl_mac" | nc 0 5003
749325071dSFilip Tehlar  echo "set ip arp host-xtr3 6.0.3.100 $odl_mac" | nc 0 5004
759325071dSFilip Tehlar
765089c812SFilip Tehlar  mac1=`ip netns exec vpp-ns5 ip a show dev veth_vpp5  | grep "link/ether" | awk '{print $2}'`
775089c812SFilip Tehlar  ip netns exec vpp-ns6 arp -s 6.0.10.21 $mac1
785089c812SFilip Tehlar
795089c812SFilip Tehlar  mac2=`ip netns exec vpp-ns8 ip a show dev veth_vpp8  | grep "link/ether" | awk '{print $2}'`
805089c812SFilip Tehlar  ip netns exec vpp-ns7 arp -s 6.0.10.25 $mac2
815089c812SFilip Tehlar
825089c812SFilip Tehlar  mac3=`ip netns exec vpp-ns7 ip a show dev veth_vpp7  | grep "link/ether" | awk '{print $2}'`
835089c812SFilip Tehlar  ip netns exec vpp-ns5 arp -s 6.0.10.22 $mac3
845089c812SFilip Tehlar  ip netns exec vpp-ns8 arp -s 6.0.10.22 $mac3
855089c812SFilip Tehlar}
865089c812SFilip Tehlar
875089c812SFilip Tehlarfunction 3_node_star_topo_setup
885089c812SFilip Tehlar{
895089c812SFilip Tehlar  ip netns add vpp-ns1
905089c812SFilip Tehlar  ip netns add vpp-ns2
915089c812SFilip Tehlar  ip netns add vpp-ns3
925089c812SFilip Tehlar  ip netns add vpp-ns4
935089c812SFilip Tehlar  ip netns add vpp-ns5
945089c812SFilip Tehlar  ip netns add vpp-ns6
955089c812SFilip Tehlar  ip netns add vpp-ns7
965089c812SFilip Tehlar  ip netns add vpp-ns8
975089c812SFilip Tehlar  ip netns add xtr-ns
985089c812SFilip Tehlar
995089c812SFilip Tehlar  ip link add veth_xtr1 type veth peer name xtr1
1005089c812SFilip Tehlar  ip link add veth_xtr2 type veth peer name xtr2
1015089c812SFilip Tehlar  ip link add veth_xtr3 type veth peer name xtr3
1025089c812SFilip Tehlar  ip link add veth_odl type veth peer name odl
1035089c812SFilip Tehlar  ip link set dev xtr1 up
1045089c812SFilip Tehlar  ip link set dev xtr2 up
1055089c812SFilip Tehlar  ip link set dev xtr3 up
1065089c812SFilip Tehlar  ip link set dev odl up
1075089c812SFilip Tehlar
1085089c812SFilip Tehlar  ip link set dev veth_xtr1 up netns xtr-ns
1095089c812SFilip Tehlar  ip link set dev veth_xtr2 up netns xtr-ns
1105089c812SFilip Tehlar  ip link set dev veth_xtr3 up netns xtr-ns
1115089c812SFilip Tehlar  ip link set dev veth_odl up netns xtr-ns
1125089c812SFilip Tehlar
1135089c812SFilip Tehlar  ip netns exec xtr-ns brctl addbr vppbr1
1145089c812SFilip Tehlar  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr1
1155089c812SFilip Tehlar  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr2
1165089c812SFilip Tehlar  ip netns exec xtr-ns brctl addif vppbr1 veth_xtr3
1175089c812SFilip Tehlar  ip netns exec xtr-ns brctl addif vppbr1 veth_odl
1185089c812SFilip Tehlar  ip netns exec xtr-ns ifconfig vppbr1 up
1195089c812SFilip Tehlar
1205089c812SFilip Tehlar  ip link add veth_vpp1 type veth peer name vpp1
1215089c812SFilip Tehlar  ip link set dev vpp1 up
1225089c812SFilip Tehlar  ip link set dev veth_vpp1 up netns vpp-ns1
1235089c812SFilip Tehlar
1245089c812SFilip Tehlar  ip netns exec vpp-ns1 \
1255089c812SFilip Tehlar    bash -c "
1265089c812SFilip Tehlar      ip link set dev lo up
1275089c812SFilip Tehlar      ip addr add 6.0.1.2/24 dev veth_vpp1
1285089c812SFilip Tehlar      ip addr add 6:0:1::2/64 dev veth_vpp1
1295089c812SFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.1.1
1305089c812SFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:1::1
1315089c812SFilip Tehlar  "
1325089c812SFilip Tehlar
1335089c812SFilip Tehlar  ip link add veth_vpp2 type veth peer name vpp2
1345089c812SFilip Tehlar  ip link set dev vpp2 up
1355089c812SFilip Tehlar  ip link set dev veth_vpp2 up netns vpp-ns2
1365089c812SFilip Tehlar
1375089c812SFilip Tehlar  ip netns exec vpp-ns2 \
1385089c812SFilip Tehlar    bash -c "
1395089c812SFilip Tehlar      ip link set dev lo up
1405089c812SFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp2
1415089c812SFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp2
1425089c812SFilip Tehlar      ip route add 6.0.1.0/24 via 6.0.2.1
1435089c812SFilip Tehlar      ip route add 6:0:1::0/64 via 6:0:2::1
1445089c812SFilip Tehlar  "
1455089c812SFilip Tehlar
1465089c812SFilip Tehlar  ip link add veth_vpp3 type veth peer name vpp3
1475089c812SFilip Tehlar  ip link set dev vpp3 up
1485089c812SFilip Tehlar  ip link set dev veth_vpp3 up netns vpp-ns3
1495089c812SFilip Tehlar
1505089c812SFilip Tehlar  ip netns exec vpp-ns3 \
1515089c812SFilip Tehlar    bash -c "
1525089c812SFilip Tehlar      ip link set dev lo up
1535089c812SFilip Tehlar      ip addr add 6.0.5.5/24 dev veth_vpp3
1545089c812SFilip Tehlar      ip addr add 6:0:5::5/64 dev veth_vpp3
1555089c812SFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.5.1
1565089c812SFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:5::1
1575089c812SFilip Tehlar  "
1585089c812SFilip Tehlar
1595089c812SFilip Tehlar  ip link add veth_vpp4 type veth peer name vpp4
1605089c812SFilip Tehlar  ip link set dev vpp4 up
1615089c812SFilip Tehlar  ip link set dev veth_vpp4 up netns vpp-ns4
1625089c812SFilip Tehlar
1635089c812SFilip Tehlar  ip netns exec vpp-ns4 \
1645089c812SFilip Tehlar    bash -c "
1655089c812SFilip Tehlar      ip link set dev lo up
1665089c812SFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp4
1675089c812SFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp4
1685089c812SFilip Tehlar      ip route add 6.0.5.0/24 via 6.0.2.1
1695089c812SFilip Tehlar      ip route add 6:0:5::0/64 via 6:0:2::1
1705089c812SFilip Tehlar  "
1715089c812SFilip Tehlar
1725089c812SFilip Tehlar  ip link add veth_vpp5 type veth peer name vpp5
1735089c812SFilip Tehlar  ip link set dev vpp5 up
1745089c812SFilip Tehlar  ip link set dev veth_vpp5 address 08:11:11:11:11:11
1755089c812SFilip Tehlar  ip link set dev veth_vpp5 up netns vpp-ns5
1765089c812SFilip Tehlar
1775089c812SFilip Tehlar  ip netns exec vpp-ns5 \
1785089c812SFilip Tehlar    bash -c "
1795089c812SFilip Tehlar      ip link set dev lo up
1805089c812SFilip Tehlar      ip addr add 6.0.10.21/24 dev veth_vpp5
1813db341deSFilip Tehlar      ip addr add 6:0:10::21/64 dev veth_vpp5
1825089c812SFilip Tehlar  "
1835089c812SFilip Tehlar
1845089c812SFilip Tehlar  ip link add veth_vpp6 type veth peer name vpp6
1855089c812SFilip Tehlar  ip link set dev vpp6 up
1865089c812SFilip Tehlar  ip link set dev veth_vpp6 address 08:22:22:22:22:22
1875089c812SFilip Tehlar  ip link set dev veth_vpp6 up netns vpp-ns6
1885089c812SFilip Tehlar
1895089c812SFilip Tehlar  ip netns exec vpp-ns6 \
1905089c812SFilip Tehlar    bash -c "
1915089c812SFilip Tehlar      ip link set dev lo up
1925089c812SFilip Tehlar      ip addr add 6.0.10.22/24 dev veth_vpp6
1933db341deSFilip Tehlar      ip addr add 6:0:10::22/64 dev veth_vpp6
1945089c812SFilip Tehlar  "
1955089c812SFilip Tehlar
1965089c812SFilip Tehlar  ip link add veth_vpp7 type veth peer name vpp7
1975089c812SFilip Tehlar  ip link set dev vpp7 up
1985089c812SFilip Tehlar  ip link set dev veth_vpp7 address 08:22:22:22:22:22
1995089c812SFilip Tehlar  ip link set dev veth_vpp7 up netns vpp-ns7
2005089c812SFilip Tehlar
2015089c812SFilip Tehlar  ip netns exec vpp-ns7 \
2025089c812SFilip Tehlar    bash -c "
2035089c812SFilip Tehlar      ip link set dev lo up
2045089c812SFilip Tehlar      ip addr add 6.0.10.22/24 dev veth_vpp7
2055089c812SFilip Tehlar  "
2065089c812SFilip Tehlar
2075089c812SFilip Tehlar  ip link add veth_vpp8 type veth peer name vpp8
2085089c812SFilip Tehlar  ip link set dev vpp8 up
2095089c812SFilip Tehlar  ip link set dev veth_vpp8 address 08:55:55:55:55:55
2105089c812SFilip Tehlar  ip link set dev veth_vpp8 up netns vpp-ns8
2115089c812SFilip Tehlar
2125089c812SFilip Tehlar  ip netns exec vpp-ns8 \
2135089c812SFilip Tehlar    bash -c "
2145089c812SFilip Tehlar      ip link set dev lo up
2155089c812SFilip Tehlar      ip addr add 6.0.10.25/24 dev veth_vpp8
2165089c812SFilip Tehlar  "
2175089c812SFilip Tehlar
2185089c812SFilip Tehlar  ip addr add 6.0.3.100/24 dev odl
2195089c812SFilip Tehlar  ip addr add 6:0:3::100/64 dev odl
2205089c812SFilip Tehlar  ethtool --offload  odl rx off tx off
2215089c812SFilip Tehlarmaybe_pause
2225089c812SFilip Tehlar  # generate config files
2235089c812SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
2245089c812SFilip Tehlar
2255089c812SFilip Tehlar  start_vpp 5002 vpp1
2265089c812SFilip Tehlar  start_vpp 5003 vpp2
2275089c812SFilip Tehlar  start_vpp 5004 vpp3
2285089c812SFilip Tehlar
2295089c812SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
2305089c812SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
2313db341deSFilip Tehlar    sleep 1
2325089c812SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
2335089c812SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
2345089c812SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
2355089c812SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
2365089c812SFilip Tehlar    sleep 2
2375089c812SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
2385089c812SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
2395089c812SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
2405089c812SFilip Tehlar  else
2415089c812SFilip Tehlar    echo "=== WARNING:"
2425089c812SFilip Tehlar    echo "=== Invalid configuration method selected!"
2435089c812SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
2445089c812SFilip Tehlar    echo "==="
2455089c812SFilip Tehlar  fi
2465089c812SFilip Tehlar
247f20e6999SFilip Tehlar  if [ "$1" != "no_odl" ] ; then
248f20e6999SFilip Tehlar    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
249f20e6999SFilip Tehlar    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
250f20e6999SFilip Tehlar  fi
2515089c812SFilip Tehlar
252f20e6999SFilip Tehlar  if [ "$2" != "no_arp" ] ; then
253f20e6999SFilip Tehlar    set_arp
254f20e6999SFilip Tehlar  fi
2555089c812SFilip Tehlar}
256