smr_rtr_disjoint.sh revision af093531
1#!/usr/bin/env bash
2
3function smr_rtr_disjoint_clean {
4  echo "Clearing all VPP instances.."
5  pkill vpp --signal 9
6
7  rm /dev/shm/*
8
9  echo "Cleaning RTR topology.."
10  ip netns exec wan4-ns ifconfig vppbr1 down
11  ip netns exec wan4-ns brctl delbr vppbr1
12  ip netns exec vpp2-rtr-ns ifconfig vppbr2 down
13  ip netns exec vpp2-rtr-ns brctl delbr vppbr2
14  ip link del dev vpp1 &> /dev/null
15  ip link del dev vpp2 &> /dev/null
16  ip link del dev vpp1_wan4 &> /dev/null
17  ip link del dev rtr1_vpp1 &> /dev/null
18  ip link del dev vpp2_rtr &> /dev/null
19  ip link del dev rtr_vpp2 &> /dev/null
20  ip link del dev odl_wan4 &> /dev/null
21  ip link del dev odl_vpp2 &> /dev/null
22
23  ip netns del vpp1-ns &> /dev/null
24  ip netns del vpp2-ns &> /dev/null
25  ip netns del wan4-ns &> /dev/null
26  ip netns del vpp2-rtr-ns &> /dev/null
27
28  odl_clear_all
29}
30
31function smr_rtr_disjoint_setup {
32  # create namespaces
33  ip netns add vpp1-ns
34  ip netns add vpp2-ns
35  ip netns add wan4-ns
36  ip netns add vpp2-rtr-ns
37
38  # create pair interfaces between vpp[1|2], rtr and odl
39  ip link add veth_vpp1_wan4 type veth peer name vpp1_wan4
40  ip link add veth_rtr_wan4 type veth peer name rtr_wan4
41  ip link add veth_vpp2_rtr type veth peer name vpp2_rtr
42  ip link add veth_vpp2_wan4 type veth peer name vpp2_wan4
43  ip link add veth_rtr_vpp2 type veth peer name rtr_vpp2
44  ip link add veth_odl_wan4 type veth peer name odl_wan4
45  ip link add veth_odl_vpp2 type veth peer name odl_vpp2
46
47  # enable peer interfaces
48  ip link set dev vpp1_wan4 up
49  ip link set dev rtr_wan4 up
50  ip link set dev vpp2_rtr up
51  ip link set dev vpp2_wan4 up
52  ip link set dev rtr_vpp2 up
53  ip link set dev odl_wan4 up
54  ip link set dev odl_vpp2 up
55
56  # enable veth interfaces and set them in the appropriate ip ns
57  ip link set dev veth_vpp1_wan4 up netns wan4-ns
58  ip link set dev veth_rtr_wan4 up netns wan4-ns
59  ip link set dev veth_vpp2_rtr up netns vpp2-rtr-ns
60  ip link set dev veth_vpp2_wan4 up netns wan4-ns
61  ip link set dev veth_rtr_vpp2 up netns vpp2-rtr-ns
62  ip link set dev veth_odl_wan4 up netns wan4-ns
63  ip link set dev veth_odl_vpp2 up netns vpp2-rtr-ns
64
65  # vpp1, rtr and odl
66  ip netns exec wan4-ns brctl addbr vppbr1
67  ip netns exec wan4-ns brctl addif vppbr1 veth_vpp1_wan4
68  ip netns exec wan4-ns brctl addif vppbr1 veth_rtr_wan4
69  ip netns exec wan4-ns brctl addif vppbr1 veth_vpp2_wan4
70  ip netns exec wan4-ns brctl addif vppbr1 veth_odl_wan4
71  ip netns exec wan4-ns ifconfig vppbr1 up
72
73  # vpp2, rtr and odl
74  ip netns exec vpp2-rtr-ns brctl addbr vppbr2
75  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_vpp2_rtr
76  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_rtr_vpp2
77  ip netns exec vpp2-rtr-ns brctl addif vppbr2 veth_odl_vpp2
78  ip netns exec vpp2-rtr-ns ifconfig vppbr2 up
79
80  # vpp1 to client
81  ip link add veth_vpp1 type veth peer name vpp1
82  ip link set dev vpp1 up
83  ip link set dev veth_vpp1 up netns vpp1-ns
84
85  ip netns exec vpp1-ns \
86    bash -c "
87      ip link set dev lo up
88      ip addr add 6.0.2.2/24 dev veth_vpp1
89      ip addr add 6:0:2::2/64 dev veth_vpp1
90      ip route add 6.0.4.0/24 via 6.0.2.1
91      ip route add 6:0:4::0/64 via 6:0:2::1
92  "
93
94  # vpp2 to client
95  ip link add veth_vpp2 type veth peer name vpp2
96  ip link set dev vpp2 up
97  ip link set dev veth_vpp2 up netns vpp2-ns
98
99  ip netns exec vpp2-ns \
100    bash -c "
101      ip link set dev lo up
102      ip addr add 6.0.4.4/24 dev veth_vpp2
103      ip addr add 6:0:4::4/64 dev veth_vpp2
104      ip route add 6.0.2.0/24 via 6.0.4.1
105      ip route add 6:0:2::0/64 via 6:0:4::1
106  "
107
108  # vpp1 to odl
109  ip addr add 6.0.3.100/24 dev odl_wan4
110  ip addr add 6:0:3::100/64 dev odl_wan4
111  ethtool --offload  odl_wan4 rx off tx off
112
113  # vpp2 to odl
114  ip addr add 6.0.5.100/24 dev odl_vpp2
115  ip addr add 6:0:5::100/64 dev odl_vpp2
116  ethtool --offload  odl_vpp2 rx off tx off
117
118  ${VPP_LITE_BIN} \
119    unix { log /tmp/vpp1.log cli-listen \
120           localhost:5002 full-coredump \
121           exec ${VPP_LITE_CONF}/vpp1.config } \
122    api-trace { on } api-segment {prefix xtr1}
123
124  ${VPP_LITE_BIN} \
125    unix { log /tmp/vpp2.log cli-listen \
126           localhost:5003 full-coredump \
127           exec ${VPP_LITE_CONF}/vpp2.config } \
128    api-trace { on } api-segment {prefix xtr2}
129
130   ${VPP_LITE_BIN} \
131    unix { log /tmp/rtr.log cli-listen \
132           localhost:5004 full-coredump \
133           exec ${VPP_LITE_CONF}/rtr.config } \
134    api-trace { on } api-segment {prefix rtr}
135
136  post_curl "add-mapping" ${ODL_CONFIG_FILE1}
137  post_curl "add-mapping" ${ODL_CONFIG_FILE2}
138}
139
140function smr_rtr_disjoint_reconfigure {
141  post_curl "add-mapping" ${ODL_CONFIG_FILE3}
142  post_curl "add-mapping" ${ODL_CONFIG_FILE4}
143}
144