Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1 | """ |
| 2 | BIER Tables and Routes |
| 3 | """ |
| 4 | |
| 5 | import socket |
| 6 | from vpp_object import VppObject |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 7 | from vpp_ip_route import MPLS_LABEL_INVALID, VppRoutePath, VppMplsLabel |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 8 | |
| 9 | |
| 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 |
| 19 | |
| 20 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 21 | class VppBierTableID: |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 22 | def __init__(self, sub_domain_id, set_id, hdr_len_id): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 23 | self.set_id = set_id |
| 24 | self.sub_domain_id = sub_domain_id |
| 25 | self.hdr_len_id = hdr_len_id |
| 26 | |
| 27 | |
| 28 | def find_bier_table(test, bti): |
| 29 | tables = test.vapi.bier_table_dump() |
| 30 | for t in tables: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 31 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 36 | return True |
| 37 | return False |
| 38 | |
| 39 | |
| 40 | def find_bier_route(test, bti, bp): |
| 41 | routes = test.vapi.bier_route_dump(bti) |
| 42 | for r in routes: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 43 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 49 | return True |
| 50 | return False |
| 51 | |
| 52 | |
| 53 | def 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 | |
| 61 | def find_bier_disp_entry(test, bdti, bp): |
| 62 | entries = test.vapi.bier_disp_entry_dump(bdti) |
| 63 | for e in entries: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 64 | if bp == e.bde_bp and bdti == e.bde_tbl_id: |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 65 | return True |
| 66 | return False |
| 67 | |
| 68 | |
| 69 | def find_bier_imp(test, bti, bp): |
| 70 | imps = test.vapi.bier_imp_dump() |
| 71 | for i in imps: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 78 | return True |
| 79 | return False |
| 80 | |
| 81 | |
| 82 | class 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 93 | self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=1) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 94 | self._test.registry.register(self, self._test.logger) |
| 95 | |
| 96 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 97 | self._test.vapi.bier_table_add_del(self.id, self.mpls_label, is_add=0) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 98 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 99 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 100 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 105 | |
| 106 | def query_vpp_config(self): |
| 107 | return find_bier_table(self._test, self.id) |
| 108 | |
| 109 | |
| 110 | class VppBierRoute(VppObject): |
| 111 | """ |
| 112 | BIER route |
| 113 | """ |
| 114 | |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 115 | def __init__(self, test, tbl_id, bp, paths): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 116 | self._test = test |
| 117 | self.tbl_id = tbl_id |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 118 | self.bp = bp |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 119 | self.paths = paths |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 120 | self.encoded_paths = [] |
| 121 | for path in self.paths: |
| 122 | self.encoded_paths.append(path.encode()) |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 123 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 124 | def add_vpp_config(self): |
| 125 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 126 | self.tbl_id, self.bp, self.encoded_paths, is_add=1 |
| 127 | ) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 128 | self._test.registry.register(self, self._test.logger) |
| 129 | |
| 130 | def remove_vpp_config(self): |
| 131 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 132 | self.tbl_id, self.bp, self.encoded_paths, is_add=0 |
| 133 | ) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 134 | |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 135 | def update_paths(self, paths): |
| 136 | self.paths = paths |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 137 | self.encoded_paths = [] |
| 138 | for path in self.paths: |
| 139 | self.encoded_paths.append(path.encode()) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 140 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 141 | self.tbl_id, self.bp, self.encoded_paths, is_replace=1 |
| 142 | ) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 143 | |
| 144 | def add_path(self, path): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 145 | self.encoded_paths.append(path.encode()) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 146 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 147 | self.tbl_id, self.bp, [path.encode()], is_add=1, is_replace=0 |
| 148 | ) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 149 | self.paths.append(path) |
| 150 | self._test.registry.register(self, self._test.logger) |
| 151 | |
| 152 | def remove_path(self, path): |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 153 | self.encoded_paths.remove(path.encode()) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 154 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 155 | self.tbl_id, self.bp, [path.encode()], is_add=0, is_replace=0 |
| 156 | ) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 157 | self.paths.remove(path) |
| 158 | |
| 159 | def remove_all_paths(self): |
| 160 | self._test.vapi.bier_route_add_del( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 161 | self.tbl_id, self.bp, [], is_add=0, is_replace=1 |
| 162 | ) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 163 | self.paths = [] |
| 164 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 165 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 166 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 172 | |
| 173 | def query_vpp_config(self): |
| 174 | return find_bier_route(self._test, self.tbl_id, self.bp) |
| 175 | |
| 176 | |
| 177 | class 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 189 | res = self._test.vapi.bier_imp_add(self.tbl_id, self.src, self.ibytes) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 190 | self.bi_index = res.bi_index |
| 191 | self._test.registry.register(self, self._test.logger) |
| 192 | |
| 193 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 194 | self._test.vapi.bier_imp_del(self.bi_index) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 195 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 196 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 197 | 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 Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 203 | |
| 204 | def query_vpp_config(self): |
| 205 | return find_bier_imp(self._test, self.tbl_id, self.src) |
| 206 | |
| 207 | |
| 208 | class 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 Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 218 | self._test.vapi.bier_disp_table_add_del(self.id, is_add=1) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 219 | self._test.registry.register(self, self._test.logger) |
| 220 | |
| 221 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 222 | self._test.vapi.bier_disp_table_add_del(self.id, is_add=0) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 223 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 224 | 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 | |
| 231 | class VppBierDispEntry(VppObject): |
| 232 | """ |
| 233 | BIER Disposition Entry |
| 234 | """ |
| 235 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 236 | def __init__( |
| 237 | self, test, tbl_id, bp, payload_proto, nh_proto, nh, nh_tbl, rpf_id=~0 |
| 238 | ): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 239 | self._test = test |
| 240 | self.tbl_id = tbl_id |
| 241 | self.nh_tbl = nh_tbl |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 242 | self.nh_proto = nh_proto |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 243 | 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 Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 253 | self.nh_proto, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 254 | self.nh, |
| 255 | self.nh_tbl, |
| 256 | self.rpf_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 257 | is_add=1, |
| 258 | ) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 259 | 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 Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 266 | self.nh_proto, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 267 | self.nh, |
| 268 | self.nh_tbl, |
| 269 | self.rpf_id, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 270 | is_add=0, |
| 271 | ) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 272 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 273 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 274 | return "bier-disp-entry;[%d:%d]" % (self.tbl_id, self.bp) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 275 | |
| 276 | def query_vpp_config(self): |
| 277 | return find_bier_disp_entry(self._test, self.tbl_id, self.bp) |