1bcae6baeSFilip Tehlar#!/usr/bin/env bash
2bcae6baeSFilip Tehlar
3bcae6baeSFilip Tehlarfunction two_customers_topo_clean {
4bcae6baeSFilip Tehlar  echo "Clearing all VPP instances.."
5bcae6baeSFilip Tehlar  pkill vpp --signal 9
6bcae6baeSFilip Tehlar  rm /dev/shm/*
7bcae6baeSFilip Tehlar
8bcae6baeSFilip Tehlar  echo "Cleaning topology.."
9bcae6baeSFilip Tehlar  ip netns exec intervpp-ns ifconfig vppbr1 down
10bcae6baeSFilip Tehlar  ip netns exec intervpp-ns brctl delbr vppbr1
11bcae6baeSFilip Tehlar  ip link del dev vpp1_cus1 &> /dev/null
12bcae6baeSFilip Tehlar  ip link del dev vpp2_cus1 &> /dev/null
13bcae6baeSFilip Tehlar  ip link del dev vpp1_cus2 &> /dev/null
14bcae6baeSFilip Tehlar  ip link del dev vpp2_cus2 &> /dev/null
15bcae6baeSFilip Tehlar  ip link del dev intervpp1 &> /dev/null
16bcae6baeSFilip Tehlar  ip link del dev intervpp2 &> /dev/null
17bcae6baeSFilip Tehlar  ip link del dev odl &> /dev/null
18bcae6baeSFilip Tehlar
19bcae6baeSFilip Tehlar  ip netns del vpp1-cus1-ns &> /dev/null
20bcae6baeSFilip Tehlar  ip netns del vpp1-cus2-ns &> /dev/null
21bcae6baeSFilip Tehlar  ip netns del vpp2-cus1-ns &> /dev/null
22bcae6baeSFilip Tehlar  ip netns del vpp2-cus2-ns &> /dev/null
23bcae6baeSFilip Tehlar  ip netns del intervpp-ns &> /dev/null
24bcae6baeSFilip Tehlar
25bcae6baeSFilip Tehlar  odl_clear_all
26bcae6baeSFilip Tehlar}
27bcae6baeSFilip Tehlar
28bcae6baeSFilip Tehlarfunction two_customers_topo_setup {
29bcae6baeSFilip Tehlar  echo "Configuring topology..."
30bcae6baeSFilip Tehlar  ip netns add vpp1-cus1-ns
31bcae6baeSFilip Tehlar  ip netns add vpp1-cus2-ns
32bcae6baeSFilip Tehlar  ip netns add vpp2-cus1-ns
33bcae6baeSFilip Tehlar  ip netns add vpp2-cus2-ns
34bcae6baeSFilip Tehlar  ip netns add intervpp-ns
35bcae6baeSFilip Tehlar
36bcae6baeSFilip Tehlar  ip link add veth_intervpp1 type veth peer name intervpp1
37bcae6baeSFilip Tehlar  ip link add veth_intervpp2 type veth peer name intervpp2
38bcae6baeSFilip Tehlar  ip link add veth_odl type veth peer name odl
39bcae6baeSFilip Tehlar  ip link set dev intervpp1 up
40bcae6baeSFilip Tehlar  ip link set dev intervpp2 up
41bcae6baeSFilip Tehlar  ip link set dev odl up
42bcae6baeSFilip Tehlar  ip link set dev veth_intervpp1 up netns intervpp-ns
43bcae6baeSFilip Tehlar  ip link set dev veth_intervpp2 up netns intervpp-ns
44bcae6baeSFilip Tehlar  ip link set dev veth_odl up netns intervpp-ns
45bcae6baeSFilip Tehlar
46bcae6baeSFilip Tehlar  ip netns exec intervpp-ns brctl addbr vppbr1
47bcae6baeSFilip Tehlar  ip netns exec intervpp-ns brctl addif vppbr1 veth_intervpp1
48bcae6baeSFilip Tehlar  ip netns exec intervpp-ns brctl addif vppbr1 veth_intervpp2
49bcae6baeSFilip Tehlar  ip netns exec intervpp-ns brctl addif vppbr1 veth_odl
50bcae6baeSFilip Tehlar  ip netns exec intervpp-ns ifconfig vppbr1 up
51bcae6baeSFilip Tehlar
52bcae6baeSFilip Tehlar  # customer1 configuration on vpp1
53bcae6baeSFilip Tehlar  ip link add veth_vpp1_cus1 type veth peer name vpp1_cus1
54bcae6baeSFilip Tehlar  ip link set dev vpp1_cus1 up
55bcae6baeSFilip Tehlar  ip link set dev veth_vpp1_cus1 up netns vpp1-cus1-ns
56bcae6baeSFilip Tehlar
57bcae6baeSFilip Tehlar  ip netns exec vpp1-cus1-ns \
58bcae6baeSFilip Tehlar    bash -c "
59bcae6baeSFilip Tehlar      ip link set dev lo up
60bcae6baeSFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp1_cus1
61bcae6baeSFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp1_cus1
62bcae6baeSFilip Tehlar      ip route add 6.0.4.0/24 via 6.0.2.1
63bcae6baeSFilip Tehlar      ip route add 6:0:4::0/64 via 6:0:2::1
64bcae6baeSFilip Tehlar  "
65bcae6baeSFilip Tehlar
66bcae6baeSFilip Tehlar  # customer2 configuration on vpp1
67bcae6baeSFilip Tehlar  ip link add veth_vpp1_cus2 type veth peer name vpp1_cus2
68bcae6baeSFilip Tehlar  ip link set dev vpp1_cus2 up
69bcae6baeSFilip Tehlar  ip link set dev veth_vpp1_cus2 up netns vpp1-cus2-ns
70bcae6baeSFilip Tehlar
71bcae6baeSFilip Tehlar  ip netns exec vpp1-cus2-ns \
72bcae6baeSFilip Tehlar    bash -c "
73bcae6baeSFilip Tehlar      ip link set dev lo up
74bcae6baeSFilip Tehlar      ip addr add 6.0.2.2/24 dev veth_vpp1_cus2
75bcae6baeSFilip Tehlar      ip addr add 6:0:2::2/64 dev veth_vpp1_cus2
76bcae6baeSFilip Tehlar      ip route add 6.0.4.0/24 via 6.0.2.1
77bcae6baeSFilip Tehlar      ip route add 6:0:4::0/64 via 6:0:2::1
78bcae6baeSFilip Tehlar  "
79bcae6baeSFilip Tehlar
80bcae6baeSFilip Tehlar  # customer1 configuration on vpp2
81bcae6baeSFilip Tehlar  ip link add veth_vpp2_cus1 type veth peer name vpp2_cus1
82bcae6baeSFilip Tehlar  ip link set dev vpp2_cus1 up
83bcae6baeSFilip Tehlar  ip link set dev veth_vpp2_cus1 up netns vpp2-cus1-ns
84bcae6baeSFilip Tehlar
85bcae6baeSFilip Tehlar  ip netns exec vpp2-cus1-ns \
86bcae6baeSFilip Tehlar    bash -c "
87bcae6baeSFilip Tehlar      ip link set dev lo up
88bcae6baeSFilip Tehlar      ip addr add 6.0.4.4/24 dev veth_vpp2_cus1
89bcae6baeSFilip Tehlar      ip addr add 6:0:4::4/64 dev veth_vpp2_cus1
90bcae6baeSFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.4.1
91bcae6baeSFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:4::1
92bcae6baeSFilip Tehlar  "
93bcae6baeSFilip Tehlar
94bcae6baeSFilip Tehlar  # customer2 configuration on vpp2
95bcae6baeSFilip Tehlar  ip link add veth_vpp2_cus2 type veth peer name vpp2_cus2
96bcae6baeSFilip Tehlar  ip link set dev vpp2_cus2 up
97bcae6baeSFilip Tehlar  ip link set dev veth_vpp2_cus2 up netns vpp2-cus2-ns
98bcae6baeSFilip Tehlar
99bcae6baeSFilip Tehlar  ip netns exec vpp2-cus2-ns \
100bcae6baeSFilip Tehlar    bash -c "
101bcae6baeSFilip Tehlar      ip link set dev lo up
102bcae6baeSFilip Tehlar      ip addr add 6.0.4.4/24 dev veth_vpp2_cus2
103bcae6baeSFilip Tehlar      ip addr add 6:0:4::4/64 dev veth_vpp2_cus2
104bcae6baeSFilip Tehlar      ip route add 6.0.2.0/24 via 6.0.4.1
105bcae6baeSFilip Tehlar      ip route add 6:0:2::0/64 via 6:0:4::1
106bcae6baeSFilip Tehlar  "
107bcae6baeSFilip Tehlar
108bcae6baeSFilip Tehlar  ip addr add 6.0.3.100/24 dev odl
109bcae6baeSFilip Tehlar  ip addr add 6:0:3::100/64 dev odl
110bcae6baeSFilip Tehlar  ethtool --offload  odl rx off tx off
111bcae6baeSFilip Tehlar
112bf231ba7SFilip Tehlar  # generate config files
113bf231ba7SFilip Tehlar  ./scripts/generate_config.py ${VPP_LITE_CONF} ${CFG_METHOD}
114bf231ba7SFilip Tehlar
115abc68849SFilip Tehlar  sleep 3
116bf231ba7SFilip Tehlar  start_vpp 5002 vpp1
117bf231ba7SFilip Tehlar  start_vpp 5003 vpp2
118bf231ba7SFilip Tehlar
119bf231ba7SFilip Tehlar  echo "* Selected configuration method: $CFG_METHOD"
120bf450b80SFilip Tehlar  sleep 2
121bf231ba7SFilip Tehlar  if [ "$CFG_METHOD" == "cli" ] ; then
122bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp1.cli" | nc 0 5002
123bf231ba7SFilip Tehlar    echo "exec ${VPP_LITE_CONF}/vpp2.cli" | nc 0 5003
124bf231ba7SFilip Tehlar  elif [ "$CFG_METHOD" == "vat" ] ; then
125bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp1 script in ${VPP_LITE_CONF}/vpp1.vat
126bf231ba7SFilip Tehlar    ${VPP_API_TEST} chroot prefix vpp2 script in ${VPP_LITE_CONF}/vpp2.vat
127bf231ba7SFilip Tehlar  else
128bf231ba7SFilip Tehlar    echo "=== WARNING:"
129bf231ba7SFilip Tehlar    echo "=== Invalid configuration method selected!"
130bf231ba7SFilip Tehlar    echo "=== To resolve this set env variable CFG_METHOD to vat or cli."
131bf231ba7SFilip Tehlar    echo "==="
132bf231ba7SFilip Tehlar  fi
1331df1d674SFilip Tehlar
134bcae6baeSFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE1}
135bcae6baeSFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE2}
136bcae6baeSFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE3}
137bcae6baeSFilip Tehlar  post_curl "add-mapping" ${ODL_CONFIG_FILE4}
138bcae6baeSFilip Tehlar}
139