blob: c46530af077824c7a1d65c7e0e1bfa45a1a19415 [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
7
8
9class BIER_HDR_PAYLOAD:
10 BIER_HDR_PROTO_MPLS_DOWN_STREAM = 1
11 BIER_HDR_PROTO_MPLS_UP_STREAM = 2
12 BIER_HDR_PROTO_ETHERNET = 3
13 BIER_HDR_PROTO_IPV4 = 4
14 BIER_HDR_PROTO_IPV6 = 5
15 BIER_HDR_PROTO_VXLAN = 6
16 BIER_HDR_PROTO_CTRL = 7
17 BIER_HDR_PROTO_OAM = 8
18
19
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020020class VppBierTableID:
Neale Ranns91286372017-12-05 13:24:04 -080021 def __init__(self, sub_domain_id, set_id, hdr_len_id):
Neale Rannsd792d9c2017-10-21 10:53:20 -070022 self.set_id = set_id
23 self.sub_domain_id = sub_domain_id
24 self.hdr_len_id = hdr_len_id
25
26
27def find_bier_table(test, bti):
28 tables = test.vapi.bier_table_dump()
29 for t in tables:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020030 if (
31 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 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070035 return True
36 return False
37
38
39def find_bier_route(test, bti, bp):
40 routes = test.vapi.bier_route_dump(bti)
41 for r in routes:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020042 if (
43 bti.set_id == r.br_route.br_tbl_id.bt_set
44 and bti.sub_domain_id == r.br_route.br_tbl_id.bt_sub_domain
45 and bti.hdr_len_id == r.br_route.br_tbl_id.bt_hdr_len_id
46 and bp == r.br_route.br_bp
47 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070048 return True
49 return False
50
51
52def find_bier_disp_table(test, bdti):
53 tables = test.vapi.bier_disp_table_dump()
54 for t in tables:
55 if bdti == t.bdt_tbl_id:
56 return True
57 return False
58
59
60def find_bier_disp_entry(test, bdti, bp):
61 entries = test.vapi.bier_disp_entry_dump(bdti)
62 for e in entries:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020063 if bp == e.bde_bp and bdti == e.bde_tbl_id:
Neale Rannsd792d9c2017-10-21 10:53:20 -070064 return True
65 return False
66
67
68def find_bier_imp(test, bti, bp):
69 imps = test.vapi.bier_imp_dump()
70 for i in imps:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020071 if (
72 bti.set_id == i.bi_tbl_id.bt_set
73 and bti.sub_domain_id == i.bi_tbl_id.bt_sub_domain
74 and bti.hdr_len_id == i.bi_tbl_id.bt_hdr_len_id
75 and bp == i.bi_src
76 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -070077 return True
78 return False
79
80
81class VppBierTable(VppObject):
82 """
83 BIER Table
84 """
85
86 def __init__(self, test, id, mpls_label):
87 self._test = test
88 self.id = id
89 self.mpls_label = mpls_label
90
91 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020092 self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=1)
Neale Rannsd792d9c2017-10-21 10:53:20 -070093 self._test.registry.register(self, self._test.logger)
94
95 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020096 self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=0)
Neale Rannsd792d9c2017-10-21 10:53:20 -070097
Neale Rannsd792d9c2017-10-21 10:53:20 -070098 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020099 return "bier-table;[%d:%d:%d]" % (
100 self.id.set_id,
101 self.id.sub_domain_id,
102 self.id.hdr_len_id,
103 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700104
105 def query_vpp_config(self):
106 return find_bier_table(self._test, self.id)
107
108
109class VppBierRoute(VppObject):
110 """
111 BIER route
112 """
113
Neale Ranns91286372017-12-05 13:24:04 -0800114 def __init__(self, test, tbl_id, bp, paths):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700115 self._test = test
116 self.tbl_id = tbl_id
Neale Rannsd792d9c2017-10-21 10:53:20 -0700117 self.bp = bp
Neale Ranns91286372017-12-05 13:24:04 -0800118 self.paths = paths
Neale Ranns097fa662018-05-01 05:17:55 -0700119 self.encoded_paths = []
120 for path in self.paths:
121 self.encoded_paths.append(path.encode())
Neale Ranns31ed7442018-02-23 05:29:09 -0800122
Neale Rannsd792d9c2017-10-21 10:53:20 -0700123 def add_vpp_config(self):
124 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200125 self.tbl_id, self.bp, self.encoded_paths, is_add=1
126 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700127 self._test.registry.register(self, self._test.logger)
128
129 def remove_vpp_config(self):
130 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200131 self.tbl_id, self.bp, self.encoded_paths, is_add=0
132 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700133
Neale Rannsef90ed02018-09-13 08:45:12 -0700134 def update_paths(self, paths):
135 self.paths = paths
Neale Ranns097fa662018-05-01 05:17:55 -0700136 self.encoded_paths = []
137 for path in self.paths:
138 self.encoded_paths.append(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700139 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200140 self.tbl_id, self.bp, self.encoded_paths, is_replace=1
141 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700142
143 def add_path(self, path):
Neale Ranns097fa662018-05-01 05:17:55 -0700144 self.encoded_paths.append(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700145 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200146 self.tbl_id, self.bp, [path.encode()], is_add=1, is_replace=0
147 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700148 self.paths.append(path)
149 self._test.registry.register(self, self._test.logger)
150
151 def remove_path(self, path):
Neale Ranns097fa662018-05-01 05:17:55 -0700152 self.encoded_paths.remove(path.encode())
Neale Rannsef90ed02018-09-13 08:45:12 -0700153 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200154 self.tbl_id, self.bp, [path.encode()], is_add=0, is_replace=0
155 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700156 self.paths.remove(path)
157
158 def remove_all_paths(self):
159 self._test.vapi.bier_route_add_del(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200160 self.tbl_id, self.bp, [], is_add=0, is_replace=1
161 )
Neale Rannsef90ed02018-09-13 08:45:12 -0700162 self.paths = []
163
Neale Rannsd792d9c2017-10-21 10:53:20 -0700164 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200165 return "bier-route;[%d:%d:%d:%d]" % (
166 self.tbl_id.set_id,
167 self.tbl_id.sub_domain_id,
168 self.tbl_id.hdr_len_id,
169 self.bp,
170 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700171
172 def query_vpp_config(self):
173 return find_bier_route(self._test, self.tbl_id, self.bp)
174
175
176class VppBierImp(VppObject):
177 """
178 BIER route
179 """
180
181 def __init__(self, test, tbl_id, src, ibytes):
182 self._test = test
183 self.tbl_id = tbl_id
184 self.ibytes = ibytes
185 self.src = src
186
187 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200188 res = self._test.vapi.bier_imp_add(self.tbl_id, self.src, self.ibytes)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700189 self.bi_index = res.bi_index
190 self._test.registry.register(self, self._test.logger)
191
192 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200193 self._test.vapi.bier_imp_del(self.bi_index)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700194
Neale Rannsd792d9c2017-10-21 10:53:20 -0700195 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200196 return "bier-imp;[%d:%d:%d:%d]" % (
197 self.tbl_id.set_id,
198 self.tbl_id.sub_domain_id,
199 self.tbl_id.hdr_len_id,
200 self.src,
201 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700202
203 def query_vpp_config(self):
204 return find_bier_imp(self._test, self.tbl_id, self.src)
205
206
207class VppBierDispTable(VppObject):
208 """
209 BIER Disposition Table
210 """
211
212 def __init__(self, test, id):
213 self._test = test
214 self.id = id
215
216 def add_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200217 self._test.vapi.bier_disp_table_add_del(self.id, is_add=1)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700218 self._test.registry.register(self, self._test.logger)
219
220 def remove_vpp_config(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200221 self._test.vapi.bier_disp_table_add_del(self.id, is_add=0)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700222
Neale Rannsd792d9c2017-10-21 10:53:20 -0700223 def object_id(self):
224 return "bier-disp-table;[%d]" % (self.id)
225
226 def query_vpp_config(self):
227 return find_bier_disp_table(self._test, self.id)
228
229
230class VppBierDispEntry(VppObject):
231 """
232 BIER Disposition Entry
233 """
234
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200235 def __init__(
236 self, test, tbl_id, bp, payload_proto, nh_proto, nh, nh_tbl, rpf_id=~0
237 ):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700238 self._test = test
239 self.tbl_id = tbl_id
240 self.nh_tbl = nh_tbl
Neale Rannsf0510722018-01-31 11:35:41 -0800241 self.nh_proto = nh_proto
Neale Rannsd792d9c2017-10-21 10:53:20 -0700242 self.bp = bp
243 self.payload_proto = payload_proto
244 self.rpf_id = rpf_id
245 self.nh = socket.inet_pton(socket.AF_INET, nh)
246
247 def add_vpp_config(self):
248 self._test.vapi.bier_disp_entry_add_del(
249 self.tbl_id,
250 self.bp,
251 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800252 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700253 self.nh,
254 self.nh_tbl,
255 self.rpf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200256 is_add=1,
257 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700258 self._test.registry.register(self, self._test.logger)
259
260 def remove_vpp_config(self):
261 self._test.vapi.bier_disp_entry_add_del(
262 self.tbl_id,
263 self.bp,
264 self.payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800265 self.nh_proto,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700266 self.nh,
267 self.nh_tbl,
268 self.rpf_id,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200269 is_add=0,
270 )
Neale Rannsd792d9c2017-10-21 10:53:20 -0700271
Neale Rannsd792d9c2017-10-21 10:53:20 -0700272 def object_id(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200273 return "bier-disp-entry;[%d:%d]" % (self.tbl_id, self.bp)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700274
275 def query_vpp_config(self):
276 return find_bier_disp_entry(self._test, self.tbl_id, self.bp)