6 from vpp_object import VppObject
7 from vpp_ip_route import MPLS_LABEL_INVALID, VppRoutePath, VppMplsLabel
10 class 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
21 class VppBierTableID():
22 def __init__(self, sub_domain_id, set_id, hdr_len_id):
24 self.sub_domain_id = sub_domain_id
25 self.hdr_len_id = hdr_len_id
28 def find_bier_table(test, bti):
29 tables = test.vapi.bier_table_dump()
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:
38 def find_bier_route(test, bti, bp):
39 routes = test.vapi.bier_route_dump(bti)
41 if bti.set_id == r.br_route.br_tbl_id.bt_set \
42 and bti.sub_domain_id == r.br_route.br_tbl_id.bt_sub_domain \
43 and bti.hdr_len_id == r.br_route.br_tbl_id.bt_hdr_len_id \
44 and bp == r.br_route.br_bp:
49 def find_bier_disp_table(test, bdti):
50 tables = test.vapi.bier_disp_table_dump()
52 if bdti == t.bdt_tbl_id:
57 def find_bier_disp_entry(test, bdti, bp):
58 entries = test.vapi.bier_disp_entry_dump(bdti)
61 and bdti == e.bde_tbl_id:
66 def find_bier_imp(test, bti, bp):
67 imps = test.vapi.bier_imp_dump()
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 \
77 class VppBierTable(VppObject):
82 def __init__(self, test, id, mpls_label):
85 self.mpls_label = mpls_label
87 def add_vpp_config(self):
88 self._test.vapi.bier_table_add_del(
92 self._test.registry.register(self, self._test.logger)
94 def remove_vpp_config(self):
95 self._test.vapi.bier_table_add_del(
101 return "bier-table;[%d:%d:%d]" % (self.id.set_id,
102 self.id.sub_domain_id,
105 def query_vpp_config(self):
106 return find_bier_table(self._test, self.id)
109 class VppBierRoute(VppObject):
114 def __init__(self, test, tbl_id, bp, paths):
119 self.encoded_paths = []
120 for path in self.paths:
121 self.encoded_paths.append(path.encode())
123 def add_vpp_config(self):
124 self._test.vapi.bier_route_add_del(
129 self._test.registry.register(self, self._test.logger)
131 def remove_vpp_config(self):
132 self._test.vapi.bier_route_add_del(
138 def update_paths(self, paths):
140 self.encoded_paths = []
141 for path in self.paths:
142 self.encoded_paths.append(path.encode())
143 self._test.vapi.bier_route_add_del(
149 def add_path(self, path):
150 self.encoded_paths.append(path.encode())
151 self._test.vapi.bier_route_add_del(
157 self.paths.append(path)
158 self._test.registry.register(self, self._test.logger)
160 def remove_path(self, path):
161 self.encoded_paths.remove(path.encode())
162 self._test.vapi.bier_route_add_del(
168 self.paths.remove(path)
170 def remove_all_paths(self):
171 self._test.vapi.bier_route_add_del(
180 return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
181 self.tbl_id.sub_domain_id,
182 self.tbl_id.hdr_len_id,
185 def query_vpp_config(self):
186 return find_bier_route(self._test, self.tbl_id, self.bp)
189 class VppBierImp(VppObject):
194 def __init__(self, test, tbl_id, src, ibytes):
200 def add_vpp_config(self):
201 res = self._test.vapi.bier_imp_add(
205 self.bi_index = res.bi_index
206 self._test.registry.register(self, self._test.logger)
208 def remove_vpp_config(self):
209 self._test.vapi.bier_imp_del(
213 return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
214 self.tbl_id.sub_domain_id,
215 self.tbl_id.hdr_len_id,
218 def query_vpp_config(self):
219 return find_bier_imp(self._test, self.tbl_id, self.src)
222 class VppBierDispTable(VppObject):
224 BIER Disposition Table
227 def __init__(self, test, id):
231 def add_vpp_config(self):
232 self._test.vapi.bier_disp_table_add_del(
235 self._test.registry.register(self, self._test.logger)
237 def remove_vpp_config(self):
238 self._test.vapi.bier_disp_table_add_del(
243 return "bier-disp-table;[%d]" % (self.id)
245 def query_vpp_config(self):
246 return find_bier_disp_table(self._test, self.id)
249 class VppBierDispEntry(VppObject):
251 BIER Disposition Entry
254 def __init__(self, test, tbl_id, bp, payload_proto, nh_proto,
255 nh, nh_tbl, rpf_id=~0):
259 self.nh_proto = nh_proto
261 self.payload_proto = payload_proto
263 self.nh = socket.inet_pton(socket.AF_INET, nh)
265 def add_vpp_config(self):
266 self._test.vapi.bier_disp_entry_add_del(
275 self._test.registry.register(self, self._test.logger)
277 def remove_vpp_config(self):
278 self._test.vapi.bier_disp_entry_add_del(
289 return "bier-disp-entry;[%d:%d]" % (self.tbl_id,
292 def query_vpp_config(self):
293 return find_bier_disp_entry(self._test, self.tbl_id, self.bp)