176ab0052SFlorin Coras#!/usr/bin/env bash
276ab0052SFlorin Coras
376ab0052SFlorin Corasfunction multihoming_topo_clean
476ab0052SFlorin Coras{
576ab0052SFlorin Coras  echo "Clearing all VPP instances.."
676ab0052SFlorin Coras  pkill vpp --signal 9
776ab0052SFlorin Coras  rm /dev/shm/*
876ab0052SFlorin Coras
976ab0052SFlorin Coras  echo "Cleaning topology.."
1076ab0052SFlorin Coras  ip netns exec intervppns1 ifconfig vppbr down
1176ab0052SFlorin Coras  ip netns exec intervppns1 brctl delbr vppbr
1276ab0052SFlorin Coras  ip link del dev veth_vpp1 &> /dev/null
1376ab0052SFlorin Coras  ip link del dev veth_vpp2 &> /dev/null
1476ab0052SFlorin Coras  ip link del dev veth_intervpp11 &> /dev/null
1576ab0052SFlorin Coras  ip link del dev veth_intervpp12 &> /dev/null
1676ab0052SFlorin Coras  ip link del dev veth_odl &> /dev/null
1776ab0052SFlorin Coras  ip netns del vppns1 &> /dev/null
1876ab0052SFlorin Coras  ip netns del vppns2 &> /dev/null
1976ab0052SFlorin Coras  ip netns del intervppns1 &> /dev/null
2076ab0052SFlorin Coras
2176ab0052SFlorin Coras  ip netns exec intervppns2 ifconfig vppbr down
2276ab0052SFlorin Coras  ip netns exec intervppns2 brctl delbr vppbr
2376ab0052SFlorin Coras  ip link del dev veth_intervpp21 &> /dev/null
2476ab0052SFlorin Coras  ip link del dev veth_intervpp22 &> /dev/null
2576ab0052SFlorin Coras  ip netns del intervppns2 &> /dev/null
2676ab0052SFlorin Coras
2776ab0052SFlorin Coras  if [ "$1" != "no_odl" ] ; then
2876ab0052SFlorin Coras    odl_clear_all
2976ab0052SFlorin Coras  fi
3076ab0052SFlorin Coras}
3176ab0052SFlorin Coras
3276ab0052SFlorin Corasfunction set_arp
3376ab0052SFlorin Coras{
3476ab0052SFlorin Coras  mac1=`ip netns exec vppns1 ip a show dev veth_vpp1  | grep "link/ether" | awk '{print $2}'`
3576ab0052SFlorin Coras  ip netns exec vppns2 arp -s 6.0.1.11 $mac1
3676ab0052SFlorin Coras
3776ab0052SFlorin Coras  mac2=`ip netns exec vppns2 ip a show dev veth_vpp2  | grep "link/ether" | awk '{print $2}'`
3876ab0052SFlorin Coras  ip netns exec vppns1 arp -s 6.0.1.12 $mac2
3976ab0052SFlorin Coras}
4076ab0052SFlorin Coras
4176ab0052SFlorin Corasfunction multihoming_topo_setup
4276ab0052SFlorin Coras{
4376ab0052SFlorin Coras
4476ab0052SFlorin Coras  # create vpp to clients and inter-vpp namespaces
4576ab0052SFlorin Coras  ip netns add vppns1
4676ab0052SFlorin Coras  ip netns add vppns2
4776ab0052SFlorin Coras  ip netns add intervppns1
4876ab0052SFlorin Coras  ip netns add intervppns2
4976ab0052SFlorin Coras
5076ab0052SFlorin Coras  # create vpp and odl interfaces and set them in intervppns1
5176ab0052SFlorin Coras  ip link add veth_intervpp11 type veth peer name intervpp11
5276ab0052SFlorin Coras  ip link add veth_intervpp12 type veth peer name intervpp12
5376ab0052SFlorin Coras  ip link add veth_odl type veth peer name odl
5476ab0052SFlorin Coras  ip link set dev intervpp11 up
5576ab0052SFlorin Coras  ip link set dev intervpp12 up
5676ab0052SFlorin Coras  ip link set dev odl up
5776ab0052SFlorin Coras  ip link set dev veth_intervpp11 up netns intervppns1
5876ab0052SFlorin Coras  ip link set dev veth_intervpp12 up netns intervppns1
5976ab0052SFlorin Coras  ip link set dev veth_odl up netns intervppns1
6076ab0052SFlorin Coras
6176ab0052SFlorin Coras  ip link add veth_intervpp21 type veth peer name intervpp21
6276ab0052SFlorin Coras  ip link add veth_intervpp22 type veth peer name intervpp22
6376ab0052SFlorin Coras  ip link set dev intervpp21 up
6476ab0052SFlorin Coras  ip link set dev intervpp22 up
6576ab0052SFlorin Coras  ip link set dev veth_intervpp21 up netns intervppns2
6676ab0052SFlorin Coras  ip link set dev veth_intervpp22 up netns intervppns2
6776ab0052SFlorin Coras
6876ab0052SFlorin Coras  # create bridge in intervppns1 and add vpp and odl interfaces
6976ab0052SFlorin Coras  ip netns exec intervppns1 brctl addbr vppbr
7076ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_intervpp11
7176ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_intervpp12
7276ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_odl
7376ab0052SFlorin Coras  ip netns exec intervppns1 ifconfig vppbr up
7476ab0052SFlorin Coras
7576ab0052SFlorin Coras  # create bridge in intervppns2 and add vpp and odl interfaces
7676ab0052SFlorin Coras  ip netns exec intervppns2 brctl addbr vppbr
7776ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_intervpp21
7876ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_intervpp22
7976ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_odl
8076ab0052SFlorin Coras  ip netns exec intervppns2 ifconfig vppbr up
8176ab0052SFlorin Coras
8276ab0052SFlorin Coras  # create and configure 1st veth client to vpp pair
8376ab0052SFlorin Coras  ip link add veth_vpp1 type veth peer name vpp1
8476ab0052SFlorin Coras  ip link set dev vpp1 up
8576ab0052SFlorin Coras  ip link set dev veth_vpp1 address 08:11:11:11:11:11
8676ab0052SFlorin Coras  ip link set dev veth_vpp1 up netns vppns1
8776ab0052SFlorin Coras
8876ab0052SFlorin Coras  # create and configure 2nd veth client to vpp pair
8976ab0052SFlorin Coras  ip link add veth_vpp2 type veth peer name vpp2
9076ab0052SFlorin Coras  ip link set dev vpp2 up
9176ab0052SFlorin Coras  ip link set dev veth_vpp2 address 08:22:22:22:22:22
9276ab0052SFlorin Coras  ip link set dev veth_vpp2 up netns vppns2
9376ab0052SFlorin Coras
9476ab0052SFlorin Coras  ip netns exec vppns1 \
9576ab0052SFlorin Coras  bash -c "
9676ab0052SFlorin Coras    ip link set dev lo up
9776ab0052SFlorin Coras    ip addr add 6.0.1.11/24 dev veth_vpp1
9876ab0052SFlorin Coras    ip addr add 6:0:1::11/64 dev veth_vpp1
9976ab0052SFlorin Coras  "
10076ab0052SFlorin Coras
10176ab0052SFlorin Coras  ip netns exec vppns2 \
10276ab0052SFlorin Coras  bash -c "
10376ab0052SFlorin Coras    ip link set dev lo up
10476ab0052SFlorin Coras    ip addr add 6.0.1.12/24 dev veth_vpp2
10576ab0052SFlorin Coras    ip addr add 6:0:1::12/64 dev veth_vpp2
10676ab0052SFlorin Coras  "
10776ab0052SFlorin Coras
10876ab0052SFlorin Coras  # set odl iface ip and disable checksum offloading
10976ab0052SFlorin Coras  ip addr add 6.0.3.100/24 dev odl
11076ab0052SFlorin Coras  ip addr add 6:0:3::100/64 dev odl
11176ab0052SFlorin Coras  ethtool --offload  odl rx off tx off
11276ab0052SFlorin Coras
113bf231ba7SFilip Tehlar  # generate config files
114bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
115bf231ba7SFilip Tehlar
116bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
117bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
118bf231ba7SFilip Tehlar
119bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
120bf450b80SFilip Tehlar  sleep 2
121bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
122bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
123bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
124bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
125bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
126bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
127bf231ba7SFilip Tehlar  else
128bf231ba7SFilip Tehlar    echo "=== WARNING:"
129bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
130bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
131bf231ba7SFilip Tehlar    echo "==="
132bf231ba7SFilip Tehlar  fi
1331df1d674SFilip Tehlar
13476ab0052SFlorin Coras  if [ "$1" != "no_odl" ] ; then
13576ab0052SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
13676ab0052SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
13776ab0052SFlorin Coras  fi
13876ab0052SFlorin Coras
13976ab0052SFlorin Coras  set_arp
14076ab0052SFlorin Coras}
14176ab0052SFlorin Coras
142