Debian Codegraph @

samples/bagpipe-bgp/chain-redirect-lb

raw symbols SCIP
1 #!/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 # destination |-------|
11 # port 80 |-| SVM20 |
12 # -------------> |------| | |-------| ------------->
13 # VM1-------net1 | SVM1 |--| net2-----VM2
14 # .1 11.0.0 <------------- |------| | |-------| <------------- 12.0.0 .1
15 # |-| SVM21 | source
16 # |-------| port 80
17 #
18 # Route targets....
19 #
20 # net1: :1
21 # net2: :2
22 #
23 # - chain for traffic from net1 to net2:
24 # hop12_0: first hop: net1 to SVM1
25 # hop12_1: second hop: SVM1 to SVM2
26
27 as=64512
28
29 hop12_0=$as:120
30 hop12_1=$as:121
31
32 ##
33 ## - chain for traffic from net2 to net1:
34 ## hop21_0: first hop: net2 to SVM2
35 ## hop21_1: second hop: SVM2 to SVM1
36
37 hop21_0=$as:210
38 hop21_1=$as:211
39
40 ##
41 ## - traffic from net1 to net2 redirection to chain based on a classifier:
42 ## hop_redirect: redirect hop
43
44 redirect_hop12_0=$as:300
45 redirect_hop21_0=$as:400
46
47
48 source $(dirname $0)/generic-functions
49
50 clean_start
51
52 clean_netns_all net1vm1 svm1 svm2 net2vm2
53
54
55 ##
56 ## VM1: sur A
57 ##
58 ## [netns:net1vm1][tovpn]---[to-vm1][vrf:net1vm1]
59 ##
60 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
61
62
63
64 ## SVM1: sur B
65 ##
66 ## [vrf:x1][if:to-svm1-x1]---[x1][netns:svm1][h0]---[to-svm1-h0][vrf:h01]
67 ##
68 ##
69 ## x1:100.0.0.0/24
70 ## h01:30.0.0.0/24
71 ## h02:40.0.0.0/24
72 ## x2:200.0.0.0/24
73
74 ## attach x1 and configure vrf:x1 to attract traffic destined for TCP port 80:
75 ##
76 ## [vrf:net1vm1]--->[vrf:redirect_hop12_0]
77
78 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 \
79 --import $as:1 \
80 --readv-from-rt $as:2 --readv-to-rt $redirect_hop12_0 \
81 --redirect-rt $hop12_0 --destination-port 80
82
83 ## attach h0:
84
85 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 \
86 --import-rt $hop12_1 \
87
88 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
89
90 r_b ./setup-cross-routing svm1 x1 100.0.0.254 h0 30.0.0.254
91
92
93
94 ## SVM20: sur A
95 #
96 # [vrf:h02][to-svm20-h0]---[h0][netns:svm20][x2]---[if:to-svm20-x2][vrf:x2]
97
98 ## attach h0:
99
100 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 \
101 --import-rt $hop21_1
102
103 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 \
104 --export-rt $hop12_1 --import-rt $hop21_1 \
105 --lb-consistent-hash-order 0
106
107 ## attach x2:
108 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 \
109 --import $as:2 \
110 --readv-from-rt $as:1 --readv-to-rt $redirect_hop21_0 \
111 --redirect-rt $hop21_0 --source-port 80 \
112 --lb-consistent-hash-order 0
113
114 r_a ./setup-cross-routing svm20 x2 200.0.0.254 h0 40.0.0.254
115
116
117
118 ## SVM21: sur B
119 #
120 # [vrf:h02][to-svm21-h0]---[h0][netns:svm21][x2]---[if:to-svm21-x2][vrf:x2]
121
122 ## attach h0:
123
124 r_b 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 \
125 --import-rt $hop21_1
126
127 r_b 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 \
128 --export-rt $hop12_1 --import-rt $hop21_1 \
129 --lb-consistent-hash-order 1
130
131 ## attach x2:
132 r_b 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 \
133 --import $as:2 \
134 --readv-from-rt $as:1 --readv-to-rt $redirect_hop21_0 \
135 --redirect-rt $hop21_0 --source-port 80 \
136 --lb-consistent-hash-order 1
137
138 r_b ./setup-cross-routing svm21 x2 200.0.0.253 h0 40.0.0.253
139
140
141
142 ## VM2: sur B
143 ##
144
145 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
146
147 #
148 # Test
149 #
150
151 wait_ready
152
153 ## Attended result: 100% packet loss
154 r_a ip netns exec net1vm1 ping 12.0.0.1 -c 5 -W 1
155
156 ## Attended result: Connection to 12.0.0.1 80 port [tcp/http] succeeded!
157 r_b ip netns exec net2vm2 screen -m -d "sh -c \"echo -n '\\n\\n---- SUCCESS !!! ----\\n\\n' | nc -l -p 80 -q 1\""
158 r_a ip netns exec net1vm1 nc -nv 12.0.0.1 80
159
160 sleep 5
161
162 r_b ip netns exec net2vm2 screen -m -d "sh -c \"echo -n '\\n\\n---- SUCCESS !!! ----\\n\\n' | nc -l -p 80 -q 1\""
163 r_a ip netns exec net1vm1 nc -nv 12.0.0.1 80
164
165 r_a bagpipe-looking-glass vpns instances net1vm1 dataplane flows
166 r_a bagpipe-looking-glass vpns instances redirect-to-ipvpn-64512_300 dataplane flows
167 r_b bagpipe-looking-glass vpns instances x1 dataplane flows
168 r_b bagpipe-looking-glass vpns instances h01 dataplane flows
169 r_a bagpipe-looking-glass vpns instances h02 dataplane flows
170 r_a bagpipe-looking-glass vpns instances x2 dataplane flows
171 r_b bagpipe-looking-glass vpns instances h02 dataplane flows
172 r_b bagpipe-looking-glass vpns instances x2 dataplane flows
173 r_b bagpipe-looking-glass vpns instances redirect-to-ipvpn-64512_400 dataplane flows
174 r_b bagpipe-looking-glass vpns instances net2vm2 dataplane flows
175
176
177 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
178 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
179 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
180
181 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 \
182 --lb-consistent-hash-order 0
183 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
184 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
185
186 r_b 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 \
187 --lb-consistent-hash-order 1
188 r_b 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
189 r_b 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
190
191 r_both bagpipe-looking-glass logs
192
193 clean_stop
194