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 |
| 7 | |
| 8 | |
| 9 | class 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 | |
| 20 | class VppBierTableID(): |
| 21 | def __init__(self, set_id, sub_domain_id, hdr_len_id): |
| 22 | self.set_id = set_id |
| 23 | self.sub_domain_id = sub_domain_id |
| 24 | self.hdr_len_id = hdr_len_id |
| 25 | |
| 26 | |
| 27 | def find_bier_table(test, bti): |
| 28 | tables = test.vapi.bier_table_dump() |
| 29 | for t in tables: |
| 30 | if bti.set_id == t.bt_tbl_id.bt_set \ |
| 31 | and bti.sub_domain_id == t.bt_tbl_id.bt_sub_domain \ |
| 32 | and bti.hdr_len_id == t.bt_tbl_id.bt_hdr_len_id: |
| 33 | return True |
| 34 | return False |
| 35 | |
| 36 | |
| 37 | def find_bier_route(test, bti, bp): |
| 38 | routes = test.vapi.bier_route_dump(bti) |
| 39 | for r in routes: |
| 40 | if bti.set_id == r.br_tbl_id.bt_set \ |
| 41 | and bti.sub_domain_id == r.br_tbl_id.bt_sub_domain \ |
| 42 | and bti.hdr_len_id == r.br_tbl_id.bt_hdr_len_id \ |
| 43 | and bp == r.br_bp: |
| 44 | return True |
| 45 | return False |
| 46 | |
| 47 | |
| 48 | def find_bier_disp_table(test, bdti): |
| 49 | tables = test.vapi.bier_disp_table_dump() |
| 50 | for t in tables: |
| 51 | if bdti == t.bdt_tbl_id: |
| 52 | return True |
| 53 | return False |
| 54 | |
| 55 | |
| 56 | def find_bier_disp_entry(test, bdti, bp): |
| 57 | entries = test.vapi.bier_disp_entry_dump(bdti) |
| 58 | for e in entries: |
| 59 | if bp == e.bde_bp \ |
| 60 | and bdti == e.bde_tbl_id: |
| 61 | return True |
| 62 | return False |
| 63 | |
| 64 | |
| 65 | def find_bier_imp(test, bti, bp): |
| 66 | imps = test.vapi.bier_imp_dump() |
| 67 | for i in imps: |
| 68 | if bti.set_id == i.bi_tbl_id.bt_set \ |
| 69 | and bti.sub_domain_id == i.bi_tbl_id.bt_sub_domain \ |
| 70 | and bti.hdr_len_id == i.bi_tbl_id.bt_hdr_len_id \ |
| 71 | and bp == i.bi_src: |
| 72 | return True |
| 73 | return False |
| 74 | |
| 75 | |
| 76 | class VppBierTable(VppObject): |
| 77 | """ |
| 78 | BIER Table |
| 79 | """ |
| 80 | |
| 81 | def __init__(self, test, id, mpls_label): |
| 82 | self._test = test |
| 83 | self.id = id |
| 84 | self.mpls_label = mpls_label |
| 85 | |
| 86 | def add_vpp_config(self): |
| 87 | self._test.vapi.bier_table_add_del( |
| 88 | self.id, |
| 89 | self.mpls_label, |
| 90 | is_add=1) |
| 91 | self._test.registry.register(self, self._test.logger) |
| 92 | |
| 93 | def remove_vpp_config(self): |
| 94 | self._test.vapi.bier_table_add_del( |
| 95 | self.id, |
| 96 | self.mpls_label, |
| 97 | is_add=0) |
| 98 | |
| 99 | def __str__(self): |
| 100 | return self.object_id() |
| 101 | |
| 102 | def object_id(self): |
| 103 | return "bier-table;[%d:%d:%d]" % (self.id.set_id, |
| 104 | self.id.sub_domain_id, |
| 105 | self.id.hdr_len_id) |
| 106 | |
| 107 | def query_vpp_config(self): |
| 108 | return find_bier_table(self._test, self.id) |
| 109 | |
| 110 | |
| 111 | class VppBierRoute(VppObject): |
| 112 | """ |
| 113 | BIER route |
| 114 | """ |
| 115 | |
| 116 | def __init__(self, test, tbl_id, bp, nh, out_label, |
| 117 | disp_table=0): |
| 118 | self._test = test |
| 119 | self.tbl_id = tbl_id |
| 120 | self.out_label = out_label |
| 121 | self.bp = bp |
| 122 | self.disp_table = disp_table |
| 123 | self.nh = socket.inet_pton(socket.AF_INET, nh) |
| 124 | |
| 125 | def add_vpp_config(self): |
| 126 | self._test.vapi.bier_route_add_del( |
| 127 | self.tbl_id, |
| 128 | self.bp, |
| 129 | self.nh, |
| 130 | self.out_label, |
| 131 | self.disp_table, |
| 132 | is_add=1) |
| 133 | self._test.registry.register(self, self._test.logger) |
| 134 | |
| 135 | def remove_vpp_config(self): |
| 136 | self._test.vapi.bier_route_add_del( |
| 137 | self.tbl_id, |
| 138 | self.bp, |
| 139 | self.nh, |
| 140 | self.out_label, |
| 141 | self.disp_table, |
| 142 | is_add=0) |
| 143 | |
| 144 | def __str__(self): |
| 145 | return self.object_id() |
| 146 | |
| 147 | def object_id(self): |
| 148 | return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id, |
| 149 | self.tbl_id.sub_domain_id, |
| 150 | self.tbl_id.hdr_len_id, |
| 151 | self.bp) |
| 152 | |
| 153 | def query_vpp_config(self): |
| 154 | return find_bier_route(self._test, self.tbl_id, self.bp) |
| 155 | |
| 156 | |
| 157 | class VppBierImp(VppObject): |
| 158 | """ |
| 159 | BIER route |
| 160 | """ |
| 161 | |
| 162 | def __init__(self, test, tbl_id, src, ibytes): |
| 163 | self._test = test |
| 164 | self.tbl_id = tbl_id |
| 165 | self.ibytes = ibytes |
| 166 | self.src = src |
| 167 | |
| 168 | def add_vpp_config(self): |
| 169 | res = self._test.vapi.bier_imp_add( |
| 170 | self.tbl_id, |
| 171 | self.src, |
| 172 | self.ibytes) |
| 173 | self.bi_index = res.bi_index |
| 174 | self._test.registry.register(self, self._test.logger) |
| 175 | |
| 176 | def remove_vpp_config(self): |
| 177 | self._test.vapi.bier_imp_del( |
| 178 | self.bi_index) |
| 179 | |
| 180 | def __str__(self): |
| 181 | return self.object_id() |
| 182 | |
| 183 | def object_id(self): |
| 184 | return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id, |
| 185 | self.tbl_id.sub_domain_id, |
| 186 | self.tbl_id.hdr_len_id, |
| 187 | self.src) |
| 188 | |
| 189 | def query_vpp_config(self): |
| 190 | return find_bier_imp(self._test, self.tbl_id, self.src) |
| 191 | |
| 192 | |
| 193 | class VppBierDispTable(VppObject): |
| 194 | """ |
| 195 | BIER Disposition Table |
| 196 | """ |
| 197 | |
| 198 | def __init__(self, test, id): |
| 199 | self._test = test |
| 200 | self.id = id |
| 201 | |
| 202 | def add_vpp_config(self): |
| 203 | self._test.vapi.bier_disp_table_add_del( |
| 204 | self.id, |
| 205 | is_add=1) |
| 206 | self._test.registry.register(self, self._test.logger) |
| 207 | |
| 208 | def remove_vpp_config(self): |
| 209 | self._test.vapi.bier_disp_table_add_del( |
| 210 | self.id, |
| 211 | is_add=0) |
| 212 | |
| 213 | def __str__(self): |
| 214 | return self.object_id() |
| 215 | |
| 216 | def object_id(self): |
| 217 | return "bier-disp-table;[%d]" % (self.id) |
| 218 | |
| 219 | def query_vpp_config(self): |
| 220 | return find_bier_disp_table(self._test, self.id) |
| 221 | |
| 222 | |
| 223 | class VppBierDispEntry(VppObject): |
| 224 | """ |
| 225 | BIER Disposition Entry |
| 226 | """ |
| 227 | |
| 228 | def __init__(self, test, tbl_id, bp, payload_proto, nh, nh_tbl, |
| 229 | rpf_id=~0): |
| 230 | self._test = test |
| 231 | self.tbl_id = tbl_id |
| 232 | self.nh_tbl = nh_tbl |
| 233 | self.bp = bp |
| 234 | self.payload_proto = payload_proto |
| 235 | self.rpf_id = rpf_id |
| 236 | self.nh = socket.inet_pton(socket.AF_INET, nh) |
| 237 | |
| 238 | def add_vpp_config(self): |
| 239 | self._test.vapi.bier_disp_entry_add_del( |
| 240 | self.tbl_id, |
| 241 | self.bp, |
| 242 | self.payload_proto, |
| 243 | self.nh, |
| 244 | self.nh_tbl, |
| 245 | self.rpf_id, |
| 246 | is_add=1) |
| 247 | self._test.registry.register(self, self._test.logger) |
| 248 | |
| 249 | def remove_vpp_config(self): |
| 250 | self._test.vapi.bier_disp_entry_add_del( |
| 251 | self.tbl_id, |
| 252 | self.bp, |
| 253 | self.payload_proto, |
| 254 | self.nh, |
| 255 | self.nh_tbl, |
| 256 | self.rpf_id, |
| 257 | is_add=0) |
| 258 | |
| 259 | def __str__(self): |
| 260 | return self.object_id() |
| 261 | |
| 262 | def object_id(self): |
| 263 | return "bier-disp-entry;[%d:%d]" % (self.tbl_id, |
| 264 | self.bp) |
| 265 | |
| 266 | def query_vpp_config(self): |
| 267 | return find_bier_disp_entry(self._test, self.tbl_id, self.bp) |