blob: 9fdaf1faa1c6be174c5e37ab288b82e5e32035ab [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
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020021class 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:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020031 if (
32 bti.set_id == t.bt_tbl_id.bt_set
33 and bti.sub_domain_id == t.bt_tbl_id.bt_sub_domain
34 and bti.hdr_len_id == t.bt_tbl_id.bt_hdr_len_id
35 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070036 return True
37 return False
38
39
40def find_bier_route(test, bti, bp):
41 routes = test.vapi.bier_route_dump(bti)
42 for r in routes:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 if (
44 bti.set_id == r.br_route.br_tbl_id.bt_set
45 and bti.sub_domain_id == r.br_route.br_tbl_id.bt_sub_domain
46 and bti.hdr_len_id == r.br_route.br_tbl_id.bt_hdr_len_id
47 and bp == r.br_route.br_bp
48 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070049 return True
50 return False
51
52
53def find_bier_disp_table(test, bdti):
54 tables = test.vapi.bier_disp_table_dump()
55 for t in tables:
56 if bdti == t.bdt_tbl_id:
57 return True
58 return False
59
60
61def find_bier_disp_entry(test, bdti, bp):
62 entries = test.vapi.bier_disp_entry_dump(bdti)
63 for e in entries:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020064 if bp == e.bde_bp and bdti == e.bde_tbl_id:
Neale Rannsd792d9c2017-10-21 10:53:20 -070065 return True
66 return False
67
68
69def find_bier_imp(test, bti, bp):
70 imps = test.vapi.bier_imp_dump()
71 for i in imps:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 if (
73 bti.set_id == i.bi_tbl_id.bt_set
74 and bti.sub_domain_id == i.bi_tbl_id.bt_sub_domain
75 and bti.hdr_len_id == i.bi_tbl_id.bt_hdr_len_id
76 and bp == i.bi_src
77 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070078 return True
79 return False
80
81
82class VppBierTable(VppObject):
83 """
84 BIER Table
85 """
86
87 def __init__(self, test, id, mpls_label):
88 self._test = test
89 self.id = id
90 self.mpls_label = mpls_label
91
92 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020093 self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=1)
Neale Rannsd792d9c2017-10-21 10:53:20 -070094 self._test.registry.register(self, self._test.logger)
95
96 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020097 self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=0)
Neale Rannsd792d9c2017-10-21 10:53:20 -070098
Neale Rannsd792d9c2017-10-21 10:53:20 -070099 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200100 return "bier-table;[%d:%d:%d]" % (
101 self.id.set_id,
102 self.id.sub_domain_id,
103 self.id.hdr_len_id,
104 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700105
106 def query_vpp_config(self):
107 return find_bier_table(self._test, self.id)
108
109
110class VppBierRoute(VppObject):
111 """
112 BIER route
113 """
114
Neale Ranns91286372017-12-05 13:24:04 -0800115 def __init__(self, test, tbl_id, bp, paths):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700116 self._test = test
117 self.tbl_id = tbl_id
Neale Rannsd792d9c2017-10-21 10:53:20 -0700118 self.bp = bp
Neale Ranns91286372017-12-05 13:24:04 -0800119 self.paths = paths
Neale Ranns097fa662018-05-01 05:17:55 -0700120 self.encoded_paths = []
121 for path in self.paths:
122 self.encoded_paths.append(path.encode())
Neale Ranns31ed7442018-02-23 05:29:09 -0800123
Neale Rannsd792d9c2017-10-21 10:53:20 -0700124 def add_vpp_config(self):
125 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200126 self.tbl_id, self.bp, self.encoded_paths, is_add=1
127 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700128 self._test.registry.register(self, self._test.logger)
129
130 def remove_vpp_config(self):
131 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200132 self.tbl_id, self.bp, self.encoded_paths, is_add=0
133 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700134
Neale Rannsef90ed02018-09-13 08:45:12 -0700135 def update_paths(self, paths):
136 self.paths = paths
Neale Ranns097fa662018-05-01 05:17:55 -0700137 self.encoded_paths = []
138 for path in self.paths:
139 self.encoded_paths.append(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700140 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200141 self.tbl_id, self.bp, self.encoded_paths, is_replace=1
142 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700143
144 def add_path(self, path):
Neale Ranns097fa662018-05-01 05:17:55 -0700145 self.encoded_paths.append(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700146 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200147 self.tbl_id, self.bp, [path.encode()], is_add=1, is_replace=0
148 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700149 self.paths.append(path)
150 self._test.registry.register(self, self._test.logger)
151
152 def remove_path(self, path):
Neale Ranns097fa662018-05-01 05:17:55 -0700153 self.encoded_paths.remove(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700154 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200155 self.tbl_id, self.bp, [path.encode()], is_add=0, is_replace=0
156 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700157 self.paths.remove(path)
158
159 def remove_all_paths(self):
160 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200161 self.tbl_id, self.bp, [], is_add=0, is_replace=1
162 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700163 self.paths = []
164
Neale Rannsd792d9c2017-10-21 10:53:20 -0700165 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200166 return "bier-route;[%d:%d:%d:%d]" % (
167 self.tbl_id.set_id,
168 self.tbl_id.sub_domain_id,
169 self.tbl_id.hdr_len_id,
170 self.bp,
171 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700172
173 def query_vpp_config(self):
174 return find_bier_route(self._test, self.tbl_id, self.bp)
175
176
177class VppBierImp(VppObject):
178 """
179 BIER route
180 """
181
182 def __init__(self, test, tbl_id, src, ibytes):
183 self._test = test
184 self.tbl_id = tbl_id
185 self.ibytes = ibytes
186 self.src = src
187
188 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200189 res = self._test.vapi.bier_imp_add(self.tbl_id, self.src, self.ibytes)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700190 self.bi_index = res.bi_index
191 self._test.registry.register(self, self._test.logger)
192
193 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200194 self._test.vapi.bier_imp_del(self.bi_index)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700195
Neale Rannsd792d9c2017-10-21 10:53:20 -0700196 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200197 return "bier-imp;[%d:%d:%d:%d]" % (
198 self.tbl_id.set_id,
199 self.tbl_id.sub_domain_id,
200 self.tbl_id.hdr_len_id,
201 self.src,
202 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700203
204 def query_vpp_config(self):
205 return find_bier_imp(self._test, self.tbl_id, self.src)
206
207
208class VppBierDispTable(VppObject):
209 """
210 BIER Disposition Table
211 """
212
213 def __init__(self, test, id):
214 self._test = test
215 self.id = id
216
217 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200218 self._test.vapi.bier_disp_table_add_del(self.id, is_add=1)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700219 self._test.registry.register(self, self._test.logger)
220
221 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200222 self._test.vapi.bier_disp_table_add_del(self.id, is_add=0)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700223
Neale Rannsd792d9c2017-10-21 10:53:20 -0700224 def object_id(self):
225 return "bier-disp-table;[%d]" % (self.id)
226
227 def query_vpp_config(self):
228 return find_bier_disp_table(self._test, self.id)
229
230
231class VppBierDispEntry(VppObject):
232 """
233 BIER Disposition Entry
234 """
235
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200236 def __init__(
237 self, test, tbl_id, bp, payload_proto, nh_proto, nh, nh_tbl, rpf_id=~0
238 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700239 self._test = test
240 self.tbl_id = tbl_id
241 self.nh_tbl = nh_tbl
Neale Rannsf0510722018-01-31 11:35:41 -0800242 self.nh_proto = nh_proto
Neale Rannsd792d9c2017-10-21 10:53:20 -0700243 self.bp = bp
244 self.payload_proto = payload_proto
245 self.rpf_id = rpf_id
246 self.nh = socket.inet_pton(socket.AF_INET, nh)
247
248 def add_vpp_config(self):
249 self._test.vapi.bier_disp_entry_add_del(
250 self.tbl_id,
251 self.bp,
252 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800253 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700254 self.nh,
255 self.nh_tbl,
256 self.rpf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200257 is_add=1,
258 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700259 self._test.registry.register(self, self._test.logger)
260
261 def remove_vpp_config(self):
262 self._test.vapi.bier_disp_entry_add_del(
263 self.tbl_id,
264 self.bp,
265 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800266 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700267 self.nh,
268 self.nh_tbl,
269 self.rpf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200270 is_add=0,
271 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700272
Neale Rannsd792d9c2017-10-21 10:53:20 -0700273 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200274 return "bier-disp-entry;[%d:%d]" % (self.tbl_id, self.bp)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700275
276 def query_vpp_config(self):
277 return find_bier_disp_entry(self._test, self.tbl_id, self.bp)