112defda1SFilip Tehlar
2ae57efc8SFilip Tehlar#
3ae57efc8SFilip Tehlar#                                +--------+
4ae57efc8SFilip Tehlar#                                |        |
5ae57efc8SFilip Tehlar#                                |   MR   |
6ae57efc8SFilip Tehlar#                                |        |
7ae57efc8SFilip Tehlar#                                +--------+
8abc68849SFilip Tehlar#                                odl  |6.0.3.100
9ae57efc8SFilip Tehlar#6:0:1::2                             |6:0:3::100
10ae57efc8SFilip Tehlar#6.0.1.2     vpp1 +--------+          |         +--------+
11ae57efc8SFilip Tehlar#       +---------+        |intervpp1 |intervpp2|        |vpp2
12ae57efc8SFilip Tehlar#                 |  VPP1  +----------+---------+  VPP2  +---------+
13abc68849SFilip Tehlar#                 |        |          |         |        |      6.0.2.2
14abc68849SFilip Tehlar#                 +--------+          |         +--------+      6:0:2::2
15abc68849SFilip Tehlar#                                     +mr
16abc68849SFilip Tehlar#                                     6.0.3.200
17ae57efc8SFilip Tehlar#
18ae57efc8SFilip Tehlar
19ae57efc8SFilip Tehlarfunction set_arp
20ae57efc8SFilip Tehlar{
219325071dSFilip Tehlar  odl_mac=`ip a show dev odl | grep "link/ether" | awk '{print $2}'`
2225531ee0SFilip Tehlar  echo "set ip arp host-intervpp1 6.0.3.100 $odl_mac" | nc 0 5002
2325531ee0SFilip Tehlar  echo "set ip arp host-intervpp2 6.0.3.100 $odl_mac" | nc 0 5003
249325071dSFilip Tehlar
25ae57efc8SFilip Tehlar  mac=`ip netns exec vppns1 ip a show dev veth_vpp1  | grep "link/ether" | awk '{print $2}'`
26ae57efc8SFilip Tehlar  echo "set ip arp host-vpp1 6.0.1.2 $mac" | nc 0 5002
27ae57efc8SFilip Tehlar  echo "set ip6 neighbor host-vpp1 6:0:1::2 $mac" | nc 0 5002
28ae57efc8SFilip Tehlar
29ae57efc8SFilip Tehlar  mac=`ip netns exec vppns2 ip a show dev veth_vpp2  | grep "link/ether" | awk '{print $2}'`
30ae57efc8SFilip Tehlar  echo "set ip arp host-vpp2 6.0.2.2 $mac" | nc 0 5003
31ae57efc8SFilip Tehlar  echo "set ip6 neighbor host-vpp2 6:0:2::2 $mac" | nc 0 5003
32ae57efc8SFilip Tehlar
33ae57efc8SFilip Tehlar  mac=`echo "sh hard host-intervpp1" | nc 0 5002 | grep 'Ethernet address' | awk '{print $3}'`
34ae57efc8SFilip Tehlar  echo "set ip arp host-intervpp2 6.0.3.1 $mac" | nc 0 5003
3518b298a6SFilip Tehlar  echo "set ip6 neighbor host-intervpp2 6:0:3::1 $mac" | nc 0 5003
36ae57efc8SFilip Tehlar
37ae57efc8SFilip Tehlar  mac=`echo "sh hard host-intervpp2" | nc 0 5003 | grep 'Ethernet address' | awk '{print $3}'`
38ae57efc8SFilip Tehlar  echo "set ip arp host-intervpp1 6.0.3.2 $mac" | nc 0 5002
3918b298a6SFilip Tehlar  echo "set ip6 neighbor host-intervpp1 6:0:3::2 $mac" | nc 0 5002
40ae57efc8SFilip Tehlar}
41ae57efc8SFilip Tehlar
42ae57efc8SFilip Tehlarfunction 2_node_topo_clean
4312defda1SFilip Tehlar{
4412defda1SFilip Tehlar  echo "Clearing all VPP instances.."
4512defda1SFilip Tehlar  pkill vpp --signal 9
4612defda1SFilip Tehlar  rm /dev/shm/*
4712defda1SFilip Tehlar
4812defda1SFilip Tehlar  echo "Cleaning topology.."
4912defda1SFilip Tehlar  ip netns exec intervppns ifconfig vppbr down
5012defda1SFilip Tehlar  ip netns exec intervppns brctl delbr vppbr
5112defda1SFilip Tehlar  ip link del dev veth_vpp1 &> /dev/null
5212defda1SFilip Tehlar  ip link del dev veth_vpp2 &> /dev/null
5312defda1SFilip Tehlar  ip link del dev veth_intervpp1 &> /dev/null
5412defda1SFilip Tehlar  ip link del dev veth_intervpp2 &> /dev/null
5512defda1SFilip Tehlar  ip link del dev veth_odl &> /dev/null
56abc68849SFilip Tehlar  ip link del dev veth_mr &> /dev/null
5712defda1SFilip Tehlar  ip netns del vppns1 &> /dev/null
5812defda1SFilip Tehlar  ip netns del vppns2 &> /dev/null
5912defda1SFilip Tehlar  ip netns del intervppns &> /dev/null
6012defda1SFilip Tehlar
6112defda1SFilip Tehlar  if [ "$1" != "no_odl" ] ; then
6212defda1SFilip Tehlar    odl_clear_all
6312defda1SFilip Tehlar  fi
6412defda1SFilip Tehlar}
6512defda1SFilip Tehlar
66ae57efc8SFilip Tehlarfunction 2_node_topo_setup
6712defda1SFilip Tehlar{
6812defda1SFilip Tehlar
6912defda1SFilip Tehlar  # create vpp to clients and inter-vpp namespaces
7012defda1SFilip Tehlar  ip netns add vppns1
7112defda1SFilip Tehlar  ip netns add vppns2
7212defda1SFilip Tehlar  ip netns add intervppns
7312defda1SFilip Tehlar
7412defda1SFilip Tehlar  # create vpp and odl interfaces and set them in intervppns
7512defda1SFilip Tehlar  ip link add veth_intervpp1 type veth peer name intervpp1
7612defda1SFilip Tehlar  ip link add veth_intervpp2 type veth peer name intervpp2
7712defda1SFilip Tehlar  ip link add veth_odl type veth peer name odl
78abc68849SFilip Tehlar  ip link add veth_mr type veth peer name mr
7912defda1SFilip Tehlar  ip link set dev intervpp1 up
8012defda1SFilip Tehlar  ip link set dev intervpp2 up
8112defda1SFilip Tehlar  ip link set dev odl up
82abc68849SFilip Tehlar  ip link set dev mr up
8312defda1SFilip Tehlar  ip link set dev veth_intervpp1 up netns intervppns
8412defda1SFilip Tehlar  ip link set dev veth_intervpp2 up netns intervppns
8512defda1SFilip Tehlar  ip link set dev veth_odl up netns intervppns
86abc68849SFilip Tehlar  ip link set dev veth_mr up netns intervppns
8712defda1SFilip Tehlar
8812defda1SFilip Tehlar  # create bridge in intervppns and add vpp and odl interfaces
8912defda1SFilip Tehlar  ip netns exec intervppns brctl addbr vppbr
9012defda1SFilip Tehlar  ip netns exec intervppns brctl addif vppbr veth_intervpp1
9112defda1SFilip Tehlar  ip netns exec intervppns brctl addif vppbr veth_intervpp2
9212defda1SFilip Tehlar  ip netns exec intervppns brctl addif vppbr veth_odl
93abc68849SFilip Tehlar  ip netns exec intervppns brctl addif vppbr veth_mr
9412defda1SFilip Tehlar  ip netns exec intervppns ifconfig vppbr up
9512defda1SFilip Tehlar
9612defda1SFilip Tehlar  # create and configure 1st veth client to vpp pair
9712defda1SFilip Tehlar  ip link add veth_vpp1 type veth peer name vpp1
9812defda1SFilip Tehlar  ip link set dev vpp1 up
9912defda1SFilip Tehlar  ip link set dev veth_vpp1 up netns vppns1
10012defda1SFilip Tehlar
10112defda1SFilip Tehlar  # create and configure 2nd veth client to vpp pair
10212defda1SFilip Tehlar  ip link add veth_vpp2 type veth peer name vpp2
10312defda1SFilip Tehlar  ip link set dev vpp2 up
10412defda1SFilip Tehlar  ip link set dev veth_vpp2 up netns vppns2
10512defda1SFilip Tehlar
10612defda1SFilip Tehlar  ip netns exec vppns1 \
10712defda1SFilip Tehlar  bash -c "
10812defda1SFilip Tehlar    ip link set dev lo up
10912defda1SFilip Tehlar    ip addr add 6.0.1.2/24 dev veth_vpp1
11012defda1SFilip Tehlar    ip route add 6.0.2.0/24 via 6.0.1.1
11112defda1SFilip Tehlar    ip addr add 6:0:1::2/64 dev veth_vpp1
11212defda1SFilip Tehlar    ip route add 6:0:2::0/64 via 6:0:1::1
11312defda1SFilip Tehlar  "
11412defda1SFilip Tehlar
11512defda1SFilip Tehlar  ip netns exec vppns2 \
11612defda1SFilip Tehlar  bash -c "
11712defda1SFilip Tehlar    ip link set dev lo up
11812defda1SFilip Tehlar    ip addr add 6.0.2.2/24 dev veth_vpp2
11912defda1SFilip Tehlar    ip route add 6.0.1.0/24 via 6.0.2.1
12012defda1SFilip Tehlar    ip addr add 6:0:2::2/64 dev veth_vpp2
12112defda1SFilip Tehlar    ip route add 6:0:1::0/64 via 6:0:2::1
12212defda1SFilip Tehlar  "
12312defda1SFilip Tehlar
12412defda1SFilip Tehlar  # set odl iface ip and disable checksum offloading
12512defda1SFilip Tehlar  ip addr add 6.0.3.100/24 dev odl
12612defda1SFilip Tehlar  ip addr add 6:0:3::100/64 dev odl
12712defda1SFilip Tehlar  ethtool --offload  odl rx off tx off
12812defda1SFilip Tehlar
129abc68849SFilip Tehlar  ip addr add 6.0.3.200/24 dev mr
130abc68849SFilip Tehlar  ethtool --offload mr rx off tx off
131abc68849SFilip Tehlar
132bf231ba7SFilip Tehlar  # generate config files
133bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
134bf231ba7SFilip Tehlar
135bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
136bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
137bf231ba7SFilip Tehlar
13818b298a6SFilip Tehlar  sleep 2
139bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
140bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
141bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
142bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
143bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
144bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
145bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.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
1521df1d674SFilip Tehlar
15312defda1SFilip Tehlar  if [ "$1" != "no_odl" ] ; then
15412defda1SFilip Tehlar    post_curl "add-mapping" ${ODL_CONFIG_FILE1}
15512defda1SFilip Tehlar    post_curl "add-mapping" ${ODL_CONFIG_FILE2}
15612defda1SFilip Tehlar  fi
157ae57efc8SFilip Tehlar
158ae57efc8SFilip Tehlar  set_arp
15912defda1SFilip Tehlar}
160