10b237f3cSFilip Tehlar
20b237f3cSFilip Tehlarfunction 3_node_snake_topo_clean
30b237f3cSFilip Tehlar{
40b237f3cSFilip Tehlar  echo "Clearing all VPP instances.."
50b237f3cSFilip Tehlar  pkill vpp --signal 9
60b237f3cSFilip Tehlar  rm /dev/shm/*
70b237f3cSFilip Tehlar
80b237f3cSFilip Tehlar  echo "Cleaning topology.."
90b237f3cSFilip Tehlar  ip netns exec xtr-ns12 ifconfig br12 down
100b237f3cSFilip Tehlar  ip netns exec xtr-ns23 ifconfig br23 down
110b237f3cSFilip Tehlar
120b237f3cSFilip Tehlar  ip netns exec xtr-ns12 brctl delbr br12
130b237f3cSFilip Tehlar  ip netns exec xtr-ns23 brctl delbr br23
140b237f3cSFilip Tehlar
150b237f3cSFilip Tehlar  ip link del dev veth_vpp1 &> /dev/null
160b237f3cSFilip Tehlar  ip link del dev veth_vpp2 &> /dev/null
170b237f3cSFilip Tehlar  ip link del dev veth_xtr1_xtr2 &> /dev/null
180b237f3cSFilip Tehlar  ip link del dev veth_xtr2_xtr1 &> /dev/null
190b237f3cSFilip Tehlar  ip link del dev veth_xtr2_xtr3 &> /dev/null
200b237f3cSFilip Tehlar  ip link del dev veth_xtr3_xtr2 &> /dev/null
210b237f3cSFilip Tehlar
220b237f3cSFilip Tehlar  ip netns del vppns1 &> /dev/null
230b237f3cSFilip Tehlar  ip netns del vppns2 &> /dev/null
240b237f3cSFilip Tehlar  ip netns del xtr-ns12 &> /dev/null
250b237f3cSFilip Tehlar  ip netns del xtr-ns23 &> /dev/null
260b237f3cSFilip Tehlar}
270b237f3cSFilip Tehlar
280b237f3cSFilip Tehlarfunction 3_node_snake_topo_setup
290b237f3cSFilip Tehlar{
300b237f3cSFilip Tehlar  ip netns add vppns1
310b237f3cSFilip Tehlar  ip netns add vppns2
320b237f3cSFilip Tehlar  ip netns add xtr-ns12
330b237f3cSFilip Tehlar  ip netns add xtr-ns23
340b237f3cSFilip Tehlar
350b237f3cSFilip Tehlar  ip link add veth_xtr1_xtr2 type veth peer name xtr1_xtr2
360b237f3cSFilip Tehlar  ip link add veth_xtr2_xtr1 type veth peer name xtr2_xtr1
370b237f3cSFilip Tehlar  ip link add veth_xtr2_xtr3 type veth peer name xtr2_xtr3
380b237f3cSFilip Tehlar  ip link add veth_xtr3_xtr2 type veth peer name xtr3_xtr2
390b237f3cSFilip Tehlar
400b237f3cSFilip Tehlar  # enable peer interfaces
410b237f3cSFilip Tehlar  ip link set dev xtr1_xtr2 up
420b237f3cSFilip Tehlar  ip link set dev xtr2_xtr1 up
430b237f3cSFilip Tehlar  ip link set dev xtr2_xtr3 up
440b237f3cSFilip Tehlar  ip link set dev xtr3_xtr2 up
450b237f3cSFilip Tehlar
460b237f3cSFilip Tehlar  ip link set dev veth_xtr1_xtr2 up netns xtr-ns12
470b237f3cSFilip Tehlar  ip link set dev veth_xtr2_xtr1 up netns xtr-ns12
480b237f3cSFilip Tehlar  ip link set dev veth_xtr2_xtr3 up netns xtr-ns23
490b237f3cSFilip Tehlar  ip link set dev veth_xtr3_xtr2 up netns xtr-ns23
500b237f3cSFilip Tehlar
510b237f3cSFilip Tehlar  ip netns exec xtr-ns12 brctl addbr br12
520b237f3cSFilip Tehlar  ip netns exec xtr-ns23 brctl addbr br23
530b237f3cSFilip Tehlar
540b237f3cSFilip Tehlar  ip netns exec xtr-ns12 brctl addif br12 veth_xtr1_xtr2
550b237f3cSFilip Tehlar  ip netns exec xtr-ns12 brctl addif br12 veth_xtr2_xtr1
560b237f3cSFilip Tehlar  ip netns exec xtr-ns12 ifconfig br12 up
570b237f3cSFilip Tehlar  ip netns exec xtr-ns23 brctl addif br23 veth_xtr2_xtr3
580b237f3cSFilip Tehlar  ip netns exec xtr-ns23 brctl addif br23 veth_xtr3_xtr2
590b237f3cSFilip Tehlar  ip netns exec xtr-ns23 ifconfig br23 up
600b237f3cSFilip Tehlar
610b237f3cSFilip Tehlar  # create and configure 1st veth client to vpp pair
620b237f3cSFilip Tehlar  ip link add veth_vpp1 type veth peer name vpp1
630b237f3cSFilip Tehlar  ip link set dev vpp1 up
640b237f3cSFilip Tehlar  ip link set dev veth_vpp1 up netns vppns1
650b237f3cSFilip Tehlar
660b237f3cSFilip Tehlar  # create and configure 2nd veth client to vpp pair
670b237f3cSFilip Tehlar  ip link add veth_vpp2 type veth peer name vpp2
680b237f3cSFilip Tehlar  ip link set dev vpp2 up
690b237f3cSFilip Tehlar  ip link set dev veth_vpp2 up netns vppns2
700b237f3cSFilip Tehlar
710b237f3cSFilip Tehlar  ip netns exec vppns1 \
720b237f3cSFilip Tehlar  bash -c "
730b237f3cSFilip Tehlar    ip link set dev lo up
740b237f3cSFilip Tehlar    ip addr add 6.0.1.2/24 dev veth_vpp1
750b237f3cSFilip Tehlar    ip route add 6.0.2.0/24 via 6.0.1.1
760b237f3cSFilip Tehlar    ip addr add 6:0:1::2/64 dev veth_vpp1
770b237f3cSFilip Tehlar    ip route add 6:0:2::0/64 via 6:0:1::1
780b237f3cSFilip Tehlar  "
790b237f3cSFilip Tehlar
800b237f3cSFilip Tehlar  ip netns exec vppns2 \
810b237f3cSFilip Tehlar  bash -c "
820b237f3cSFilip Tehlar    ip link set dev lo up
830b237f3cSFilip Tehlar    ip addr add 6.0.2.2/24 dev veth_vpp2
840b237f3cSFilip Tehlar    ip route add 6.0.1.0/24 via 6.0.2.1
850b237f3cSFilip Tehlar    ip addr add 6:0:2::2/64 dev veth_vpp2
860b237f3cSFilip Tehlar    ip route add 6:0:1::0/64 via 6:0:2::1
870b237f3cSFilip Tehlar  "
880b237f3cSFilip Tehlar
890b237f3cSFilip Tehlar  # generate config files
900b237f3cSFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
910b237f3cSFilip Tehlar
920b237f3cSFilip Tehlar  start_vpp 5002 vpp1
930b237f3cSFilip Tehlar  start_vpp 5003 vpp2
940b237f3cSFilip Tehlar  start_vpp 5004 vpp3
950b237f3cSFilip Tehlar
960b237f3cSFilip Tehlar  sleep 2
970b237f3cSFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
980b237f3cSFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
990b237f3cSFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
1000b237f3cSFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
1010b237f3cSFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
1020b237f3cSFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
1030b237f3cSFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
1040b237f3cSFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
1050b237f3cSFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
1060b237f3cSFilip Tehlar  else
1070b237f3cSFilip Tehlar    echo "=== WARNING:"
1080b237f3cSFilip Tehlar    echo "=== Invalid configuration method selected!"
1090b237f3cSFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
1100b237f3cSFilip Tehlar    echo "==="
1110b237f3cSFilip Tehlar  fi
1120b237f3cSFilip Tehlar}
113