19b9b4ff5SFlorin Coras#!/usr/bin/env bash
29b9b4ff5SFlorin Coras
39325071dSFilip Tehlarfunction set_arp
49325071dSFilip Tehlar{
59325071dSFilip Tehlar  odl_mac1=`ip a show dev odl_vpp1 | grep "link/ether" | awk '{print $2}'`
69325071dSFilip Tehlar  echo "set ip arp host-vpp1_rtr 6.0.3.100 $odl_mac1" | nc 0 5002
79325071dSFilip Tehlar
89325071dSFilip Tehlar  odl_mac2=`ip a show dev odl_vpp2 | grep "link/ether" | awk '{print $2}'`
99325071dSFilip Tehlar  echo "set ip arp host-vpp2_rtr 6.0.3.100 $odl_mac1" | nc 0 5003
109325071dSFilip Tehlar
119325071dSFilip Tehlar  mac=`echo "sh hard host-rtr_vpp1" | nc 0 5004 | grep 'Ethernet address' | awk '{print $3}'`
129325071dSFilip Tehlar  echo "set ip arp host-vpp1_rtr 6.0.3.2 $mac" | nc 0 5002
139325071dSFilip Tehlar
149325071dSFilip Tehlar  mac=`echo "sh hard host-vpp2_rtr" | nc 0 5003 | grep 'Ethernet address' | awk '{print $3}'`
159325071dSFilip Tehlar  echo "set ip arp host-rtr_vpp2 6.0.5.1 $mac" | nc 0 5004
169325071dSFilip Tehlar}
179325071dSFilip Tehlar
189b9b4ff5SFlorin Corasfunction rtr_two_iface_clean {
199b9b4ff5SFlorin Coras  echo "Clearing all VPP instances.."
209b9b4ff5SFlorin Coras  pkill vpp --signal 9
219b9b4ff5SFlorin Coras
229b9b4ff5SFlorin Coras  rm /dev/shm/*
239b9b4ff5SFlorin Coras
249b9b4ff5SFlorin Coras  echo "Cleaning RTR topology.."
259b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns ifconfig vppbr1 down
269b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns brctl delbr vppbr1
279b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns ifconfig vppbr2 down
289b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns brctl delbr vppbr2
299b9b4ff5SFlorin Coras  ip link del dev vpp1 &> /dev/null
309b9b4ff5SFlorin Coras  ip link del dev vpp2 &> /dev/null
319b9b4ff5SFlorin Coras  ip link del dev vpp1_rtr &> /dev/null
329b9b4ff5SFlorin Coras  ip link del dev rtr1_vpp1 &> /dev/null
339b9b4ff5SFlorin Coras  ip link del dev vpp2_rtr &> /dev/null
349b9b4ff5SFlorin Coras  ip link del dev rtr_vpp2 &> /dev/null
359b9b4ff5SFlorin Coras  ip link del dev odl_vpp1 &> /dev/null
369b9b4ff5SFlorin Coras  ip link del dev odl_vpp2 &> /dev/null
379b9b4ff5SFlorin Coras
389b9b4ff5SFlorin Coras  ip netns del vpp1-ns &> /dev/null
399b9b4ff5SFlorin Coras  ip netns del vpp2-ns &> /dev/null
409b9b4ff5SFlorin Coras  ip netns del vpp1-rtr-ns &> /dev/null
419b9b4ff5SFlorin Coras  ip netns del vpp2-rtr-ns &> /dev/null
429b9b4ff5SFlorin Coras
439b9b4ff5SFlorin Coras  odl_clear_all
449b9b4ff5SFlorin Coras}
459b9b4ff5SFlorin Coras
469b9b4ff5SFlorin Corasfunction rtr_two_iface_setup {
479b9b4ff5SFlorin Coras  # create namespaces
489b9b4ff5SFlorin Coras  ip netns add vpp1-ns
499b9b4ff5SFlorin Coras  ip netns add vpp2-ns
509b9b4ff5SFlorin Coras  ip netns add vpp1-rtr-ns
519b9b4ff5SFlorin Coras  ip netns add vpp2-rtr-ns
529b9b4ff5SFlorin Coras
539b9b4ff5SFlorin Coras  # create pair interfaces between vpp[1|2], rtr and odl
549b9b4ff5SFlorin Coras  ip link add veth_vpp1_rtr type veth peer name vpp1_rtr
559b9b4ff5SFlorin Coras  ip link add veth_rtr_vpp1 type veth peer name rtr_vpp1
569b9b4ff5SFlorin Coras  ip link add veth_vpp2_rtr type veth peer name vpp2_rtr
579b9b4ff5SFlorin Coras  ip link add veth_rtr_vpp2 type veth peer name rtr_vpp2
589b9b4ff5SFlorin Coras  ip link add veth_odl_vpp1 type veth peer name odl_vpp1
599b9b4ff5SFlorin Coras  ip link add veth_odl_vpp2 type veth peer name odl_vpp2
609b9b4ff5SFlorin Coras
619b9b4ff5SFlorin Coras  # enable peer interfaces
629b9b4ff5SFlorin Coras  ip link set dev vpp1_rtr up
639b9b4ff5SFlorin Coras  ip link set dev rtr_vpp1 up
649b9b4ff5SFlorin Coras  ip link set dev vpp2_rtr up
659b9b4ff5SFlorin Coras  ip link set dev rtr_vpp2 up
669b9b4ff5SFlorin Coras  ip link set dev odl_vpp1 up
679b9b4ff5SFlorin Coras  ip link set dev odl_vpp2 up
689b9b4ff5SFlorin Coras
699b9b4ff5SFlorin Coras  # enable veth interfaces and set them in the appropriate ip ns
709b9b4ff5SFlorin Coras  ip link set dev veth_vpp1_rtr up netns vpp1-rtr-ns
719b9b4ff5SFlorin Coras  ip link set dev veth_rtr_vpp1 up netns vpp1-rtr-ns
729b9b4ff5SFlorin Coras  ip link set dev veth_vpp2_rtr up netns vpp2-rtr-ns
739b9b4ff5SFlorin Coras  ip link set dev veth_rtr_vpp2 up netns vpp2-rtr-ns
749b9b4ff5SFlorin Coras  ip link set dev veth_odl_vpp1 up netns vpp1-rtr-ns
759b9b4ff5SFlorin Coras  ip link set dev veth_odl_vpp2 up netns vpp2-rtr-ns
769b9b4ff5SFlorin Coras
779b9b4ff5SFlorin Coras  # vpp1, rtr and odl
789b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns brctl addbr vppbr1
799b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_vpp1_rtr
809b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_rtr_vpp1
819b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns brctl addif vppbr1 veth_odl_vpp1
829b9b4ff5SFlorin Coras  ip netns exec vpp1-rtr-ns ifconfig vppbr1 up
839b9b4ff5SFlorin Coras
849b9b4ff5SFlorin Coras  # vpp2, rtr and odl
859b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns brctl addbr vppbr2
869b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_vpp2_rtr
879b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_rtr_vpp2
889b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_odl_vpp2
899b9b4ff5SFlorin Coras  ip netns exec vpp2-rtr-ns ifconfig vppbr2 up
909b9b4ff5SFlorin Coras
919b9b4ff5SFlorin Coras  # vpp1 to client
929b9b4ff5SFlorin Coras  ip link add veth_vpp1 type veth peer name vpp1
939b9b4ff5SFlorin Coras  ip link set dev vpp1 up
949b9b4ff5SFlorin Coras  ip link set dev veth_vpp1 up netns vpp1-ns
959b9b4ff5SFlorin Coras
969b9b4ff5SFlorin Coras  ip netns exec vpp1-ns \
979b9b4ff5SFlorin Coras    bash -c "
989b9b4ff5SFlorin Coras      ip link set dev lo up
999b9b4ff5SFlorin Coras      ip addr add 6.0.2.2/24 dev veth_vpp1
1009b9b4ff5SFlorin Coras      ip addr add 6:0:2::2/64 dev veth_vpp1
1019b9b4ff5SFlorin Coras      ip route add 6.0.4.0/24 via 6.0.2.1
1029b9b4ff5SFlorin Coras      ip route add 6:0:4::0/64 via 6:0:2::1
1039b9b4ff5SFlorin Coras  "
1049b9b4ff5SFlorin Coras
1059b9b4ff5SFlorin Coras  # vpp2 to client
1069b9b4ff5SFlorin Coras  ip link add veth_vpp2 type veth peer name vpp2
1079b9b4ff5SFlorin Coras  ip link set dev vpp2 up
1089b9b4ff5SFlorin Coras  ip link set dev veth_vpp2 up netns vpp2-ns
1099b9b4ff5SFlorin Coras
1109b9b4ff5SFlorin Coras  ip netns exec vpp2-ns \
1119b9b4ff5SFlorin Coras    bash -c "
1129b9b4ff5SFlorin Coras      ip link set dev lo up
1139b9b4ff5SFlorin Coras      ip addr add 6.0.4.4/24 dev veth_vpp2
1149b9b4ff5SFlorin Coras      ip addr add 6:0:4::4/64 dev veth_vpp2
1159b9b4ff5SFlorin Coras      ip route add 6.0.2.0/24 via 6.0.4.1
1169b9b4ff5SFlorin Coras      ip route add 6:0:2::0/64 via 6:0:4::1
1179b9b4ff5SFlorin Coras  "
1189b9b4ff5SFlorin Coras
1199b9b4ff5SFlorin Coras  # vpp1 to odl
1209b9b4ff5SFlorin Coras  ip addr add 6.0.3.100/24 dev odl_vpp1
1219b9b4ff5SFlorin Coras  ip addr add 6:0:3::100/64 dev odl_vpp1
1229b9b4ff5SFlorin Coras  ethtool --offload  odl_vpp1 rx off tx off
1239b9b4ff5SFlorin Coras
1249b9b4ff5SFlorin Coras  # vpp2 to odl
1259b9b4ff5SFlorin Coras  ip addr add 6.0.5.100/24 dev odl_vpp2
1269b9b4ff5SFlorin Coras  ip addr add 6:0:5::100/64 dev odl_vpp2
1279b9b4ff5SFlorin Coras  ethtool --offload  odl_vpp2 rx off tx off
1289b9b4ff5SFlorin Coras
129bf231ba7SFilip Tehlar  # generate config files
130bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
131bf231ba7SFilip Tehlar
132bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
133bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
134bf231ba7SFilip Tehlar  start_vpp 5004 vpp3
135bf231ba7SFilip Tehlar
136bf450b80SFilip Tehlar  sleep 2
137bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
138bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
139bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
140bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
141bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp3.cli" | nc 0 5004
142bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
143bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
144bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
145bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp3 script in ${VPP_LITE_CONF}/vpp3.vat
146bf231ba7SFilip Tehlar  else
147bf231ba7SFilip Tehlar    echo "=== WARNING:"
148bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
149bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
150bf231ba7SFilip Tehlar    echo "==="
151bf231ba7SFilip Tehlar  fi
1529b9b4ff5SFlorin Coras  post_curl "add-mapping" ${ODL_CONFIG_FILE1}
1539b9b4ff5SFlorin Coras  post_curl "add-mapping" ${ODL_CONFIG_FILE2}
1549325071dSFilip Tehlar
1559325071dSFilip Tehlar  set_arp
1569b9b4ff5SFlorin Coras}
157