Debian Codegraph @

samples/bagpipe-bgp/chain-redirect-lb2

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 #
3 # 5-tuple classified chain setup with two-directions traffic combined and default routes announced at
4 # intermediate hops (Ingress VRF between hops configured to statically announce a 0.0.0.0/0)
5 #
6 # This script will setup network namespaces SVM1 ("service VM1") and SVM2 so that
7 # traffic between net1 (to which VM1 is attached) and net2 (to which VM2 is attached)
8 # goes through SMV1 and SVM2 based on a 5-tuple classification:
9 #
10 # |-------|
11 # |-| SVM20 | \
12 # destination | |-------| |
13 # port 80 | |
14 # -------------> |------| | |-------| | ------------->
15 # VM1-------net1 | SVM1 |--|-| SVM21 | > net2-----VM2
16 # .1 11.0.0 <------------- |------| | |-------| | <------------- 12.0.0 .1
17 # | | source
18 # | |-------| | port 80
19 # |-| SVM22 | /
20 # |-------|
21 #
22 # Route targets....
23 #
24 # net1: :1
25 # net2: :2
26 #
27 # - chain for traffic from net1 to net2:
28 # hop12_0: first hop: net1 to SVM1
29 # hop12_1: second hop: SVM1 to SVM2
30
31 as=64512
32
33 hop12_0=$as:120
34 hop12_1=$as:121
35
36 ##
37 ## - chain for traffic from net2 to net1:
38 ## hop21_0: first hop: net2 to SVM2
39 ## hop21_1: second hop: SVM2 to SVM1
40
41 hop21_0=$as:210
42 hop21_1=$as:211
43
44 ##
45 ## - traffic from net1 to net2 redirection to chain based on a classifier:
46 ## hop_redirect: redirect hop
47
48 redirect_hop12_0=$as:300
49 redirect_hop21_0=$as:400
50
51
52 source $(dirnamescip-shell system . . dirname. $0)/generic-functions
53
54 clean_start
55
56 clean_netns_all net1vm1 svm1 svm2 net2vm2
57
58
59 ##
60 ## VM1: sur A
61 ##
62 ## [netns:net1vm1][tovpn]---[to-vm1][vrf:net1vm1]
63 ##
64 r_a bagpipe-rest-attach --attach --port netns:to-vm1 --network-type ipvpn --vpn-instance-id net1vm1 --ip 11.0.0.1 --rt $as:1 --import-rt $hop12_0
65
66
67
68 ## SVM1: sur B
69 ##
70 ## [vrf:x1][if:to-svm1-x1]---[x1][netns:svm1][h0]---[to-svm1-h0][vrf:h01]
71 ##
72 ##
73 ## x1:100.0.0.0/24
74 ## h01:30.0.0.0/24
75 ## h02:40.0.0.0/24
76 ## x2:200.0.0.0/24
77
78 ## attach x1 and configure vrf:x1 to attract traffic destined for TCP port 80:
79 ##
80 ## [vrf:net1vm1]--->[vrf:redirect_hop12_0]
81
82 r_b bagpipe-rest-attach --attach --port netns:to-svm1-x1 --network-type ipvpn --vpn-instance-id x1 --ip 100.0.0.1/24 --netns svm1 --if2vpn x1 \
83 --import $as:1 \
84 --readv-from-rt $as:2 --readv-to-rt $redirect_hop12_0 \
85 --redirect-rt $hop12_0 --destination-port 80
86
87 ## attach h0:
88
89 r_b bagpipe-rest-attach --attach --port netns:to-svm1-h0 --mac 52:54:00:99:99:99 --network-type ipvpn --vpn-instance-id h01 --ip 30.0.0.1/24 --netns svm1 --if2vpn h0 \
90 --import-rt $hop12_1 \
91
92 r_b bagpipe-rest-attach --attach --port to-svm1-h0 --mac 52:54:00:99:99:99 --network-type ipvpn --vpn-instance-id h01 --ip 0.0.0.0/0 --advertise-subnet --export-rt $hop21_1 --import-rt $hop12_1
93
94 r_b ./setup-cross-routing svm1 x1 100.0.0.254 h0 30.0.0.254
95
96
97
98 ## SVM2x: sur A
99 #
100
101 ## SVM22
102 # [vrf:h02][to-svm22-h0]---[h0][netns:svm22][x2]---[if:to-svm22-x2][vrf:x2]
103
104 ## attach h0:
105
106 r_a bagpipe-rest-attach --attach --port netns:to-svm22-h0 --mac 52:54:22:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.3/24 --netns svm22 --if2vpn h0 \
107 --import-rt $hop21_1
108
109 r_a bagpipe-rest-attach --attach --port to-svm22-h0 --mac 52:54:22:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
110 --export-rt $hop12_1 --import-rt $hop21_1 \
111 --lb-consistent-hash-order 2
112
113 ## attach x2:
114 r_a bagpipe-rest-attach --attach --port netns:to-svm22-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.3/24 --netns svm22 --if2vpn x2 \
115 --import $as:2 \
116 --readv-from-rt $as:1 --readv-to-rt $redirect_hop21_0 \
117 --redirect-rt $hop21_0 --source-port 80 \
118 --lb-consistent-hash-order 2
119
120 r_a ./setup-cross-routing svm22 x2 200.0.0.254 h0 40.0.0.254
121
122 ## SVM21
123 # [vrf:h02][to-svm21-h0]---[h0][netns:svm21][x2]---[if:to-svm21-x2][vrf:x2]
124
125 ## attach h0:
126
127 r_a bagpipe-rest-attach --attach --port netns:to-svm21-h0 --mac 52:54:21:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.2/24 --netns svm21 --if2vpn h0 \
128 --import-rt $hop21_1
129
130 r_a bagpipe-rest-attach --attach --port to-svm21-h0 --mac 52:54:21:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
131 --export-rt $hop12_1 --import-rt $hop21_1 \
132 --lb-consistent-hash-order 1
133
134 ## attach x2:
135 r_a bagpipe-rest-attach --attach --port netns:to-svm21-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.2/24 --netns svm21 --if2vpn x2 \
136 --import $as:2 \
137 --readv-from-rt $as:1 --readv-to-rt $redirect_hop21_0 \
138 --redirect-rt $hop21_0 --source-port 80 \
139 --lb-consistent-hash-order 1
140
141 r_a ./setup-cross-routing svm21 x2 200.0.0.254 h0 40.0.0.254
142
143 ## SVM20
144 # [vrf:h02][to-svm20-h0]---[h0][netns:svm20][x2]---[if:to-svm20-x2][vrf:x2]
145
146 ## attach h0:
147
148 r_a bagpipe-rest-attach --attach --port netns:to-svm20-h0 --mac 52:54:20:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.1/24 --netns svm20 --if2vpn h0 \
149 --import-rt $hop21_1
150
151 r_a bagpipe-rest-attach --attach --port to-svm20-h0 --mac 52:54:20:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
152 --export-rt $hop12_1 --import-rt $hop21_1 \
153 --lb-consistent-hash-order 0
154
155 ## attach x2:
156 r_a bagpipe-rest-attach --attach --port netns:to-svm20-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.1/24 --netns svm20 --if2vpn x2 \
157 --import $as:2 \
158 --readv-from-rt $as:1 --readv-to-rt $redirect_hop21_0 \
159 --redirect-rt $hop21_0 --source-port 80 \
160 --lb-consistent-hash-order 0
161
162 r_a ./setup-cross-routing svm20 x2 200.0.0.254 h0 40.0.0.254
163
164
165
166 ## VM2: sur B
167 ##
168
169 r_b bagpipe-rest-attach --attach --port netns:to-vm2 --network-type ipvpn --vpn-instance-id net2vm2 --ip 12.0.0.1 --rt $as:2 --import-rt $hop21_0
170
171 #
172 # Test
173 #
174
175 wait_ready
176
177 ## Attended result: 100% packet loss
178 r_a ip netns exec net1vm1 ping 12.0.0.1 -c 5 -W 1
179
180 ## Attended result: Connection to 12.0.0.1 80 port [tcp/http] succeeded!
181 r_b ip netns exec net2vm2 screen -m -d "sh -c \"echo -n '\\n\\n---- SUCCESS !!! ----\\n\\n' | nc -l -p 80 -q 1\""
182 r_a ip netns exec net1vm1 nc -nv 12.0.0.1 80
183
184 sleepscip-shell system . . sleep. 5
185
186 r_b ip netns exec net2vm2 screen -m -d "sh -c \"echo -n '\\n\\n---- SUCCESS !!! ----\\n\\n' | nc -l -p 80 -q 1\""
187 r_a ip netns exec net1vm1 nc -nv 12.0.0.1 80
188
189 sleepscip-shell system . . sleep. 5
190
191 r_b ip netns exec net2vm2 screen -m -d "sh -c \"echo -n '\\n\\n---- SUCCESS !!! ----\\n\\n' | nc -l -p 80 -q 1\""
192 r_a ip netns exec net1vm1 nc -nv 12.0.0.1 80
193
194 r_a bagpipe-looking-glass vpns instances net1vm1 dataplane flows
195 r_a bagpipe-looking-glass vpns instances redirect-to-ipvpn-64512_300 dataplane flows
196 r_b bagpipe-looking-glass vpns instances x1 dataplane flows
197 r_b bagpipe-looking-glass vpns instances h01 dataplane flows
198 r_a bagpipe-looking-glass vpns instances h02 dataplane flows
199 r_a bagpipe-looking-glass vpns instances x2 dataplane flows
200 r_b bagpipe-looking-glass vpns instances redirect-to-ipvpn-64512_400 dataplane flows
201 r_b bagpipe-looking-glass vpns instances net2vm2 dataplane flows
202
203
204 r_b bagpipe-rest-attach --detach --port netns:to-svm1-x1 --network-type ipvpn --vpn-instance-id x1 --ip 100.0.0.1/24 --netns svm1 --if2vpn x1
205 r_b bagpipe-rest-attach --detach --port to-svm1-h0 --mac 52:54:00:99:99:99 --network-type ipvpn --vpn-instance-id h01 --ip 0.0.0.0/0 --advertise-subnet
206 r_b bagpipe-rest-attach --detach --port netns:to-svm1-h0 --mac 52:54:00:99:99:99 --network-type ipvpn --vpn-instance-id h01 --ip 30.0.0.1/24 --netns svm1 --if2vpn h0
207
208 r_a bagpipe-rest-attach --detach --port to-svm20-h0 --mac 52:54:20:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
209 --lb-consistent-hash-order 0
210 r_a bagpipe-rest-attach --detach --port netns:to-svm20-h0 --mac 52:54:20:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.1/24 --netns svm20 --if2vpn h0
211 r_a bagpipe-rest-attach --detach --port netns:to-svm20-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.1/24 --netns svm20 --if2vpn x2 \
212 --lb-consistent-hash-order 0
213
214 r_a bagpipe-rest-attach --detach --port to-svm22-h0 --mac 52:54:22:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
215 --lb-consistent-hash-order 2
216 r_a bagpipe-rest-attach --detach --port netns:to-svm22-h0 --mac 52:54:22:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.3/24 --netns svm20 --if2vpn h0
217 r_a bagpipe-rest-attach --detach --port netns:to-svm22-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.3/24 --netns svm22 --if2vpn x2 \
218 --lb-consistent-hash-order 2
219
220 r_a bagpipe-rest-attach --detach --port to-svm21-h0 --mac 52:54:21:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 0.0.0.0/0 --advertise-subnet \
221 --lb-consistent-hash-order 1
222 r_a bagpipe-rest-attach --detach --port netns:to-svm21-h0 --mac 52:54:21:99:99:99 --network-type ipvpn --vpn-instance-id h02 --ip 40.0.0.2/24 --netns svm21 --if2vpn h0
223 r_a bagpipe-rest-attach --detach --port netns:to-svm21-x2 --network-type ipvpn --vpn-instance-id x2 --ip 200.0.0.2/24 --netns svm21 --if2vpn x2 \
224 --lb-consistent-hash-order 1
225
226 r_a bagpipe-looking-glass vpns instances
227 r_b bagpipe-looking-glass vpns instances
228
229 r_both bagpipe-looking-glass logs
230
231 clean_stop
232