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 multihoming_topo_setup
3376ab0052SFlorin Coras{
3476ab0052SFlorin Coras
3576ab0052SFlorin Coras  # create vpp to clients and inter-vpp namespaces
3676ab0052SFlorin Coras  ip netns add vppns1
3776ab0052SFlorin Coras  ip netns add vppns2
3876ab0052SFlorin Coras  ip netns add intervppns1
3976ab0052SFlorin Coras  ip netns add intervppns2
4076ab0052SFlorin Coras
4176ab0052SFlorin Coras  # create vpp and odl interfaces and set them in intervppns1
4276ab0052SFlorin Coras  ip link add veth_intervpp11 type veth peer name intervpp11
4376ab0052SFlorin Coras  ip link add veth_intervpp12 type veth peer name intervpp12
4476ab0052SFlorin Coras  ip link add veth_odl type veth peer name odl
4576ab0052SFlorin Coras  ip link set dev intervpp11 up
4676ab0052SFlorin Coras  ip link set dev intervpp12 up
4776ab0052SFlorin Coras  ip link set dev odl up
4876ab0052SFlorin Coras  ip link set dev veth_intervpp11 up netns intervppns1
4976ab0052SFlorin Coras  ip link set dev veth_intervpp12 up netns intervppns1
5076ab0052SFlorin Coras  ip link set dev veth_odl up netns intervppns1
5176ab0052SFlorin Coras
5276ab0052SFlorin Coras  ip link add veth_intervpp21 type veth peer name intervpp21
5376ab0052SFlorin Coras  ip link add veth_intervpp22 type veth peer name intervpp22
5476ab0052SFlorin Coras  ip link set dev intervpp21 up
5576ab0052SFlorin Coras  ip link set dev intervpp22 up
5676ab0052SFlorin Coras  ip link set dev veth_intervpp21 up netns intervppns2
5776ab0052SFlorin Coras  ip link set dev veth_intervpp22 up netns intervppns2
5876ab0052SFlorin Coras
5976ab0052SFlorin Coras  # create bridge in intervppns1 and add vpp and odl interfaces
6076ab0052SFlorin Coras  ip netns exec intervppns1 brctl addbr vppbr
6176ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_intervpp11
6276ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_intervpp12
6376ab0052SFlorin Coras  ip netns exec intervppns1 brctl addif vppbr veth_odl
6476ab0052SFlorin Coras  ip netns exec intervppns1 ifconfig vppbr up
6576ab0052SFlorin Coras
6676ab0052SFlorin Coras  # create bridge in intervppns2 and add vpp and odl interfaces
6776ab0052SFlorin Coras  ip netns exec intervppns2 brctl addbr vppbr
6876ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_intervpp21
6976ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_intervpp22
7076ab0052SFlorin Coras  ip netns exec intervppns2 brctl addif vppbr veth_odl
7176ab0052SFlorin Coras  ip netns exec intervppns2 ifconfig vppbr up
7276ab0052SFlorin Coras
7376ab0052SFlorin Coras  # create and configure 1st veth client to vpp pair
7476ab0052SFlorin Coras  ip link add veth_vpp1 type veth peer name vpp1
7576ab0052SFlorin Coras  ip link set dev vpp1 up
7676ab0052SFlorin Coras  ip link set dev veth_vpp1 up netns vppns1
7776ab0052SFlorin Coras
7876ab0052SFlorin Coras  # create and configure 2nd veth client to vpp pair
7976ab0052SFlorin Coras  ip link add veth_vpp2 type veth peer name vpp2
8076ab0052SFlorin Coras  ip link set dev vpp2 up
8176ab0052SFlorin Coras  ip link set dev veth_vpp2 up netns vppns2
8276ab0052SFlorin Coras
8376ab0052SFlorin Coras  ip netns exec vppns1 \
8476ab0052SFlorin Coras  bash -c "
8576ab0052SFlorin Coras    ip link set dev lo up
8676ab0052SFlorin Coras    ip addr add 6.0.1.2/24 dev veth_vpp1
8776ab0052SFlorin Coras    ip route add 6.0.2.0/24 via 6.0.1.1
8876ab0052SFlorin Coras    ip addr add 6:0:1::2/64 dev veth_vpp1
8976ab0052SFlorin Coras    ip route add 6:0:2::0/64 via 6:0:1::1
9076ab0052SFlorin Coras  "
9176ab0052SFlorin Coras
9276ab0052SFlorin Coras  ip netns exec vppns2 \
9376ab0052SFlorin Coras  bash -c "
9476ab0052SFlorin Coras    ip link set dev lo up
9576ab0052SFlorin Coras    ip addr add 6.0.2.2/24 dev veth_vpp2
9676ab0052SFlorin Coras    ip route add 6.0.1.0/24 via 6.0.2.1
9776ab0052SFlorin Coras    ip addr add 6:0:2::2/64 dev veth_vpp2
9876ab0052SFlorin Coras    ip route add 6:0:1::0/64 via 6:0:2::1
9976ab0052SFlorin Coras  "
10076ab0052SFlorin Coras
10176ab0052SFlorin Coras  # set odl iface ip and disable checksum offloading
10276ab0052SFlorin Coras  ip addr add 6.0.3.100/24 dev odl
10376ab0052SFlorin Coras  ip addr add 6:0:3::100/64 dev odl
10476ab0052SFlorin Coras  ethtool --offload  odl rx off tx off
10576ab0052SFlorin Coras
106bf231ba7SFilip Tehlar  # generate config files
107bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
108bf231ba7SFilip Tehlar
109bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
110bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
111bf231ba7SFilip Tehlar
112bf450b80SFilip Tehlar  sleep 2
113bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
114bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
115bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
116bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
117bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
118bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
119bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
120bf231ba7SFilip Tehlar  else
121bf231ba7SFilip Tehlar    echo "=== WARNING:"
122bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
123bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
124bf231ba7SFilip Tehlar    echo "==="
125bf231ba7SFilip Tehlar  fi
1261df1d674SFilip Tehlar
12776ab0052SFlorin Coras  if [ "$1" != "no_odl" ] ; then
12876ab0052SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
12976ab0052SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
13076ab0052SFlorin Coras  fi
13176ab0052SFlorin Coras}
13276ab0052SFlorin Coras
133