blob: 7566b1f95ab162f9545576e44c1aa1cb654fa967 [file] [log] [blame]
Neale Rannsd792d9c2017-10-21 10:53:20 -07001"""
2 BIER Tables and Routes
3"""
4
5import socket
6from vpp_object import VppObject
Neale Ranns31ed7442018-02-23 05:29:09 -08007from vpp_ip_route import MPLS_LABEL_INVALID, VppRoutePath, VppMplsLabel
Neale Rannsd792d9c2017-10-21 10:53:20 -07008
9
10class BIER_HDR_PAYLOAD:
11 BIER_HDR_PROTO_MPLS_DOWN_STREAM = 1
12 BIER_HDR_PROTO_MPLS_UP_STREAM = 2
13 BIER_HDR_PROTO_ETHERNET = 3
14 BIER_HDR_PROTO_IPV4 = 4
15 BIER_HDR_PROTO_IPV6 = 5
16 BIER_HDR_PROTO_VXLAN = 6
17 BIER_HDR_PROTO_CTRL = 7
18 BIER_HDR_PROTO_OAM = 8
19
20
21class VppBierTableID():
Neale Ranns91286372017-12-05 13:24:04 -080022 def __init__(self, sub_domain_id, set_id, hdr_len_id):
Neale Rannsd792d9c2017-10-21 10:53:20 -070023 self.set_id = set_id
24 self.sub_domain_id = sub_domain_id
25 self.hdr_len_id = hdr_len_id
26
27
28def find_bier_table(test, bti):
29 tables = test.vapi.bier_table_dump()
30 for t in tables:
31 if bti.set_id == t.bt_tbl_id.bt_set \
32 and bti.sub_domain_id == t.bt_tbl_id.bt_sub_domain \
33 and bti.hdr_len_id == t.bt_tbl_id.bt_hdr_len_id:
34 return True
35 return False
36
37
38def find_bier_route(test, bti, bp):
39 routes = test.vapi.bier_route_dump(bti)
40 for r in routes:
41 if bti.set_id == r.br_tbl_id.bt_set \
42 and bti.sub_domain_id == r.br_tbl_id.bt_sub_domain \
43 and bti.hdr_len_id == r.br_tbl_id.bt_hdr_len_id \
44 and bp == r.br_bp:
45 return True
46 return False
47
48
49def find_bier_disp_table(test, bdti):
50 tables = test.vapi.bier_disp_table_dump()
51 for t in tables:
52 if bdti == t.bdt_tbl_id:
53 return True
54 return False
55
56
57def find_bier_disp_entry(test, bdti, bp):
58 entries = test.vapi.bier_disp_entry_dump(bdti)
59 for e in entries:
60 if bp == e.bde_bp \
61 and bdti == e.bde_tbl_id:
62 return True
63 return False
64
65
66def find_bier_imp(test, bti, bp):
67 imps = test.vapi.bier_imp_dump()
68 for i in imps:
69 if bti.set_id == i.bi_tbl_id.bt_set \
70 and bti.sub_domain_id == i.bi_tbl_id.bt_sub_domain \
71 and bti.hdr_len_id == i.bi_tbl_id.bt_hdr_len_id \
72 and bp == i.bi_src:
73 return True
74 return False
75
76
77class VppBierTable(VppObject):
78 """
79 BIER Table
80 """
81
82 def __init__(self, test, id, mpls_label):
83 self._test = test
84 self.id = id
85 self.mpls_label = mpls_label
86
87 def add_vpp_config(self):
88 self._test.vapi.bier_table_add_del(
89 self.id,
90 self.mpls_label,
91 is_add=1)
92 self._test.registry.register(self, self._test.logger)
93
94 def remove_vpp_config(self):
95 self._test.vapi.bier_table_add_del(
96 self.id,
97 self.mpls_label,
98 is_add=0)
99
100 def __str__(self):
101 return self.object_id()
102
103 def object_id(self):
104 return "bier-table;[%d:%d:%d]" % (self.id.set_id,
105 self.id.sub_domain_id,
106 self.id.hdr_len_id)
107
108 def query_vpp_config(self):
109 return find_bier_table(self._test, self.id)
110
111
112class VppBierRoute(VppObject):
113 """
114 BIER route
115 """
116
Neale Ranns91286372017-12-05 13:24:04 -0800117 def __init__(self, test, tbl_id, bp, paths):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700118 self._test = test
119 self.tbl_id = tbl_id
Neale Rannsd792d9c2017-10-21 10:53:20 -0700120 self.bp = bp
Neale Ranns91286372017-12-05 13:24:04 -0800121 self.paths = paths
Neale Rannsd792d9c2017-10-21 10:53:20 -0700122
Neale Ranns31ed7442018-02-23 05:29:09 -0800123 def encode_paths(self):
124 br_paths = []
125 for p in self.paths:
126 lstack = []
127 for l in p.nh_labels:
128 if type(l) == VppMplsLabel:
129 lstack.append(l.encode())
130 else:
131 lstack.append({'label': l, 'ttl': 255})
132 n_labels = len(lstack)
133 while (len(lstack) < 16):
134 lstack.append({})
135 br_paths.append({'next_hop': p.nh_addr,
136 'weight': 1,
137 'afi': 0,
138 'preference': 0,
139 'table_id': p.nh_table_id,
140 'next_hop_id': p.next_hop_id,
141 'is_udp_encap': p.is_udp_encap,
142 'n_labels': n_labels,
143 'label_stack': lstack})
144 return br_paths
145
Neale Rannsd792d9c2017-10-21 10:53:20 -0700146 def add_vpp_config(self):
147 self._test.vapi.bier_route_add_del(
148 self.tbl_id,
149 self.bp,
Neale Ranns31ed7442018-02-23 05:29:09 -0800150 self.encode_paths(),
Neale Rannsd792d9c2017-10-21 10:53:20 -0700151 is_add=1)
152 self._test.registry.register(self, self._test.logger)
153
154 def remove_vpp_config(self):
155 self._test.vapi.bier_route_add_del(
156 self.tbl_id,
157 self.bp,
Neale Ranns31ed7442018-02-23 05:29:09 -0800158 self.encode_paths(),
Neale Rannsd792d9c2017-10-21 10:53:20 -0700159 is_add=0)
160
161 def __str__(self):
162 return self.object_id()
163
164 def object_id(self):
165 return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
166 self.tbl_id.sub_domain_id,
167 self.tbl_id.hdr_len_id,
168 self.bp)
169
170 def query_vpp_config(self):
171 return find_bier_route(self._test, self.tbl_id, self.bp)
172
173
174class VppBierImp(VppObject):
175 """
176 BIER route
177 """
178
179 def __init__(self, test, tbl_id, src, ibytes):
180 self._test = test
181 self.tbl_id = tbl_id
182 self.ibytes = ibytes
183 self.src = src
184
185 def add_vpp_config(self):
186 res = self._test.vapi.bier_imp_add(
187 self.tbl_id,
188 self.src,
189 self.ibytes)
190 self.bi_index = res.bi_index
191 self._test.registry.register(self, self._test.logger)
192
193 def remove_vpp_config(self):
194 self._test.vapi.bier_imp_del(
195 self.bi_index)
196
197 def __str__(self):
198 return self.object_id()
199
200 def object_id(self):
201 return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
202 self.tbl_id.sub_domain_id,
203 self.tbl_id.hdr_len_id,
204 self.src)
205
206 def query_vpp_config(self):
207 return find_bier_imp(self._test, self.tbl_id, self.src)
208
209
210class VppBierDispTable(VppObject):
211 """
212 BIER Disposition Table
213 """
214
215 def __init__(self, test, id):
216 self._test = test
217 self.id = id
218
219 def add_vpp_config(self):
220 self._test.vapi.bier_disp_table_add_del(
221 self.id,
222 is_add=1)
223 self._test.registry.register(self, self._test.logger)
224
225 def remove_vpp_config(self):
226 self._test.vapi.bier_disp_table_add_del(
227 self.id,
228 is_add=0)
229
230 def __str__(self):
231 return self.object_id()
232
233 def object_id(self):
234 return "bier-disp-table;[%d]" % (self.id)
235
236 def query_vpp_config(self):
237 return find_bier_disp_table(self._test, self.id)
238
239
240class VppBierDispEntry(VppObject):
241 """
242 BIER Disposition Entry
243 """
244
Neale Rannsf0510722018-01-31 11:35:41 -0800245 def __init__(self, test, tbl_id, bp, payload_proto, nh_proto,
246 nh, nh_tbl, rpf_id=~0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700247 self._test = test
248 self.tbl_id = tbl_id
249 self.nh_tbl = nh_tbl
Neale Rannsf0510722018-01-31 11:35:41 -0800250 self.nh_proto = nh_proto
Neale Rannsd792d9c2017-10-21 10:53:20 -0700251 self.bp = bp
252 self.payload_proto = payload_proto
253 self.rpf_id = rpf_id
254 self.nh = socket.inet_pton(socket.AF_INET, nh)
255
256 def add_vpp_config(self):
257 self._test.vapi.bier_disp_entry_add_del(
258 self.tbl_id,
259 self.bp,
260 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800261 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700262 self.nh,
263 self.nh_tbl,
264 self.rpf_id,
265 is_add=1)
266 self._test.registry.register(self, self._test.logger)
267
268 def remove_vpp_config(self):
269 self._test.vapi.bier_disp_entry_add_del(
270 self.tbl_id,
271 self.bp,
272 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800273 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700274 self.nh,
275 self.nh_tbl,
276 self.rpf_id,
277 is_add=0)
278
279 def __str__(self):
280 return self.object_id()
281
282 def object_id(self):
283 return "bier-disp-entry;[%d:%d]" % (self.tbl_id,
284 self.bp)
285
286 def query_vpp_config(self):
287 return find_bier_disp_entry(self._test, self.tbl_id, self.bp)