18719d315SFlorin Coras#!/usr/bin/env bash
28719d315SFlorin Coras
38719d315SFlorin Corasfunction basic_topo_clean
48719d315SFlorin Coras{
58719d315SFlorin Coras  echo "Clearing all VPP instances.."
68719d315SFlorin Coras  pkill vpp --signal 9
78719d315SFlorin Coras  rm /dev/shm/*
88719d315SFlorin Coras
98719d315SFlorin Coras  echo "Cleaning topology.."
108719d315SFlorin Coras  ip netns exec intervppns ifconfig vppbr down
118719d315SFlorin Coras  ip netns exec intervppns brctl delbr vppbr
128719d315SFlorin Coras  ip link del dev veth_vpp1 &> /dev/null
138719d315SFlorin Coras  ip link del dev veth_vpp2 &> /dev/null
148719d315SFlorin Coras  ip link del dev veth_intervpp1 &> /dev/null
158719d315SFlorin Coras  ip link del dev veth_intervpp2 &> /dev/null
168719d315SFlorin Coras  ip link del dev veth_odl &> /dev/null
178719d315SFlorin Coras  ip netns del vppns1 &> /dev/null
188719d315SFlorin Coras  ip netns del vppns2 &> /dev/null
198719d315SFlorin Coras  ip netns del intervppns &> /dev/null
208719d315SFlorin Coras
218719d315SFlorin Coras  if [ "$1" != "no_odl" ] ; then
228719d315SFlorin Coras    odl_clear_all
238719d315SFlorin Coras  fi
248719d315SFlorin Coras}
258719d315SFlorin Coras
268719d315SFlorin Corasfunction set_arp
278719d315SFlorin Coras{
288719d315SFlorin Coras  mac1=`ip netns exec vppns1 ip a show dev veth_vpp1  | grep "link/ether" | awk '{print $2}'`
298719d315SFlorin Coras  ip netns exec vppns2 arp -s 6.0.1.11 $mac1
308719d315SFlorin Coras
318719d315SFlorin Coras  mac2=`ip netns exec vppns2 ip a show dev veth_vpp2  | grep "link/ether" | awk '{print $2}'`
328719d315SFlorin Coras  ip netns exec vppns1 arp -s 6.0.1.12 $mac2
338719d315SFlorin Coras}
348719d315SFlorin Coras
358719d315SFlorin Corasfunction basic_topo_setup
368719d315SFlorin Coras{
378719d315SFlorin Coras
388719d315SFlorin Coras  # create vpp to clients and inter-vpp namespaces
398719d315SFlorin Coras  ip netns add vppns1
408719d315SFlorin Coras  ip netns add vppns2
418719d315SFlorin Coras  ip netns add intervppns
428719d315SFlorin Coras
438719d315SFlorin Coras  # create vpp and odl interfaces and set them in intervppns
448719d315SFlorin Coras  ip link add veth_intervpp1 type veth peer name intervpp1
458719d315SFlorin Coras  ip link add veth_intervpp2 type veth peer name intervpp2
468719d315SFlorin Coras  ip link add veth_odl type veth peer name odl
478719d315SFlorin Coras  ip link set dev intervpp1 up
488719d315SFlorin Coras  ip link set dev intervpp2 up
498719d315SFlorin Coras  ip link set dev odl up
508719d315SFlorin Coras  ip link set dev veth_intervpp1 up netns intervppns
518719d315SFlorin Coras  ip link set dev veth_intervpp2 up netns intervppns
528719d315SFlorin Coras  ip link set dev veth_odl up netns intervppns
538719d315SFlorin Coras
548719d315SFlorin Coras  # create bridge in intervppns and add vpp and odl interfaces
558719d315SFlorin Coras  ip netns exec intervppns brctl addbr vppbr
568719d315SFlorin Coras  ip netns exec intervppns brctl addif vppbr veth_intervpp1
578719d315SFlorin Coras  ip netns exec intervppns brctl addif vppbr veth_intervpp2
588719d315SFlorin Coras  ip netns exec intervppns brctl addif vppbr veth_odl
598719d315SFlorin Coras  ip netns exec intervppns ifconfig vppbr up
608719d315SFlorin Coras
618719d315SFlorin Coras  # create and configure 1st veth client to vpp pair
628719d315SFlorin Coras  ip link add veth_vpp1 type veth peer name vpp1
638719d315SFlorin Coras  ip link set dev vpp1 up
648719d315SFlorin Coras  ip link set dev veth_vpp1 address 08:11:11:11:11:11
658719d315SFlorin Coras  ip link set dev veth_vpp1 up netns vppns1
668719d315SFlorin Coras
678719d315SFlorin Coras  # create and configure 2nd veth client to vpp pair
688719d315SFlorin Coras  ip link add veth_vpp2 type veth peer name vpp2
698719d315SFlorin Coras  ip link set dev vpp2 up
708719d315SFlorin Coras  ip link set dev veth_vpp2 address 08:22:22:22:22:22
718719d315SFlorin Coras  ip link set dev veth_vpp2 up netns vppns2
728719d315SFlorin Coras
738719d315SFlorin Coras  ip netns exec vppns1 \
748719d315SFlorin Coras  bash -c "
758719d315SFlorin Coras    ip link set dev lo up
768719d315SFlorin Coras    ip addr add 6.0.1.11/24 dev veth_vpp1
778719d315SFlorin Coras    ip addr add 6:0:1::11/64 dev veth_vpp1
788719d315SFlorin Coras  "
798719d315SFlorin Coras
808719d315SFlorin Coras  ip netns exec vppns2 \
818719d315SFlorin Coras  bash -c "
828719d315SFlorin Coras    ip link set dev lo up
838719d315SFlorin Coras    ip addr add 6.0.1.12/24 dev veth_vpp2
848719d315SFlorin Coras    ip addr add 6:0:1::12/64 dev veth_vpp2
858719d315SFlorin Coras  "
868719d315SFlorin Coras
878719d315SFlorin Coras  # set odl iface ip and disable checksum offloading
888719d315SFlorin Coras  ip addr add 6.0.3.100/24 dev odl
898719d315SFlorin Coras  ip addr add 6:0:3::100/64 dev odl
908719d315SFlorin Coras  ethtool --offload  odl rx off tx off
918719d315SFlorin Coras
92bf231ba7SFilip Tehlar  # generate config files
93bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
94bf231ba7SFilip Tehlar
95bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
96bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
97bf231ba7SFilip Tehlar
985089c812SFilip Tehlar  maybe_pause
995089c812SFilip Tehlar
100bf450b80SFilip Tehlar  sleep 2
101bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
102bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
103bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
104bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
105bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
106bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
107bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
108bf231ba7SFilip Tehlar  else
109bf231ba7SFilip Tehlar    echo "=== WARNING:"
110bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
111bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
112bf231ba7SFilip Tehlar    echo "==="
113bf231ba7SFilip Tehlar  fi
1141df1d674SFilip Tehlar
1158719d315SFlorin Coras  if [ "$1" != "no_odl" ] ; then
1168719d315SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
1178719d315SFlorin Coras    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
1188719d315SFlorin Coras  fi
1198719d315SFlorin Coras
1208719d315SFlorin Coras  # avoid arp requests
1218719d315SFlorin Coras  set_arp
1228719d315SFlorin Coras}
1238719d315SFlorin Coras
124