blob: 328d4f03eb5a65eadc8596032e224795c273351d [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 Ranns91286372017-12-05 13:24:04 -08007from vpp_ip_route import MPLS_LABEL_INVALID, VppRoutePath
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
123 def add_vpp_config(self):
124 self._test.vapi.bier_route_add_del(
125 self.tbl_id,
126 self.bp,
Neale Ranns91286372017-12-05 13:24:04 -0800127 self.paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700128 is_add=1)
129 self._test.registry.register(self, self._test.logger)
130
131 def remove_vpp_config(self):
132 self._test.vapi.bier_route_add_del(
133 self.tbl_id,
134 self.bp,
Neale Ranns91286372017-12-05 13:24:04 -0800135 self.paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700136 is_add=0)
137
138 def __str__(self):
139 return self.object_id()
140
141 def object_id(self):
142 return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
143 self.tbl_id.sub_domain_id,
144 self.tbl_id.hdr_len_id,
145 self.bp)
146
147 def query_vpp_config(self):
148 return find_bier_route(self._test, self.tbl_id, self.bp)
149
150
151class VppBierImp(VppObject):
152 """
153 BIER route
154 """
155
156 def __init__(self, test, tbl_id, src, ibytes):
157 self._test = test
158 self.tbl_id = tbl_id
159 self.ibytes = ibytes
160 self.src = src
161
162 def add_vpp_config(self):
163 res = self._test.vapi.bier_imp_add(
164 self.tbl_id,
165 self.src,
166 self.ibytes)
167 self.bi_index = res.bi_index
168 self._test.registry.register(self, self._test.logger)
169
170 def remove_vpp_config(self):
171 self._test.vapi.bier_imp_del(
172 self.bi_index)
173
174 def __str__(self):
175 return self.object_id()
176
177 def object_id(self):
178 return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
179 self.tbl_id.sub_domain_id,
180 self.tbl_id.hdr_len_id,
181 self.src)
182
183 def query_vpp_config(self):
184 return find_bier_imp(self._test, self.tbl_id, self.src)
185
186
187class VppBierDispTable(VppObject):
188 """
189 BIER Disposition Table
190 """
191
192 def __init__(self, test, id):
193 self._test = test
194 self.id = id
195
196 def add_vpp_config(self):
197 self._test.vapi.bier_disp_table_add_del(
198 self.id,
199 is_add=1)
200 self._test.registry.register(self, self._test.logger)
201
202 def remove_vpp_config(self):
203 self._test.vapi.bier_disp_table_add_del(
204 self.id,
205 is_add=0)
206
207 def __str__(self):
208 return self.object_id()
209
210 def object_id(self):
211 return "bier-disp-table;[%d]" % (self.id)
212
213 def query_vpp_config(self):
214 return find_bier_disp_table(self._test, self.id)
215
216
217class VppBierDispEntry(VppObject):
218 """
219 BIER Disposition Entry
220 """
221
222 def __init__(self, test, tbl_id, bp, payload_proto, nh, nh_tbl,
223 rpf_id=~0):
224 self._test = test
225 self.tbl_id = tbl_id
226 self.nh_tbl = nh_tbl
227 self.bp = bp
228 self.payload_proto = payload_proto
229 self.rpf_id = rpf_id
230 self.nh = socket.inet_pton(socket.AF_INET, nh)
231
232 def add_vpp_config(self):
233 self._test.vapi.bier_disp_entry_add_del(
234 self.tbl_id,
235 self.bp,
236 self.payload_proto,
237 self.nh,
238 self.nh_tbl,
239 self.rpf_id,
240 is_add=1)
241 self._test.registry.register(self, self._test.logger)
242
243 def remove_vpp_config(self):
244 self._test.vapi.bier_disp_entry_add_del(
245 self.tbl_id,
246 self.bp,
247 self.payload_proto,
248 self.nh,
249 self.nh_tbl,
250 self.rpf_id,
251 is_add=0)
252
253 def __str__(self):
254 return self.object_id()
255
256 def object_id(self):
257 return "bier-disp-entry;[%d:%d]" % (self.tbl_id,
258 self.bp)
259
260 def query_vpp_config(self):
261 return find_bier_disp_entry(self._test, self.tbl_id, self.bp)