Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1 | """ |
| 2 | IP Routes |
| 3 | |
| 4 | object abstractions for representing IP routes in VPP |
| 5 | """ |
| 6 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 7 | from vpp_object import * |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 8 | from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 9 | from vpp_ip import * |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 10 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 11 | # from vnet/vnet/mpls/mpls_types.h |
| 12 | MPLS_IETF_MAX_LABEL = 0xfffff |
| 13 | MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 14 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 15 | |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 16 | class MRouteItfFlags: |
| 17 | MFIB_ITF_FLAG_NONE = 0 |
| 18 | MFIB_ITF_FLAG_NEGATE_SIGNAL = 1 |
| 19 | MFIB_ITF_FLAG_ACCEPT = 2 |
| 20 | MFIB_ITF_FLAG_FORWARD = 4 |
| 21 | MFIB_ITF_FLAG_SIGNAL_PRESENT = 8 |
| 22 | MFIB_ITF_FLAG_INTERNAL_COPY = 16 |
| 23 | |
| 24 | |
| 25 | class MRouteEntryFlags: |
| 26 | MFIB_ENTRY_FLAG_NONE = 0 |
| 27 | MFIB_ENTRY_FLAG_SIGNAL = 1 |
| 28 | MFIB_ENTRY_FLAG_DROP = 2 |
| 29 | MFIB_ENTRY_FLAG_CONNECTED = 4 |
| 30 | MFIB_ENTRY_FLAG_INHERIT_ACCEPT = 8 |
| 31 | |
| 32 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 33 | class MplsLspMode: |
| 34 | PIPE = 0 |
| 35 | UNIFORM = 1 |
| 36 | |
| 37 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 38 | def ip_to_dpo_proto(addr): |
| 39 | if addr.version is 6: |
| 40 | return DpoProto.DPO_PROTO_IP6 |
| 41 | else: |
| 42 | return DpoProto.DPO_PROTO_IP4 |
| 43 | |
| 44 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 45 | def find_route(test, ip_addr, len, table_id=0, inet=AF_INET): |
| 46 | if inet == AF_INET: |
| 47 | s = 4 |
| 48 | routes = test.vapi.ip_fib_dump() |
| 49 | else: |
| 50 | s = 16 |
| 51 | routes = test.vapi.ip6_fib_dump() |
| 52 | |
| 53 | route_addr = inet_pton(inet, ip_addr) |
| 54 | for e in routes: |
| 55 | if route_addr == e.address[:s] \ |
| 56 | and len == e.address_length \ |
| 57 | and table_id == e.table_id: |
| 58 | return True |
| 59 | return False |
| 60 | |
| 61 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 62 | def find_mroute(test, grp_addr, src_addr, grp_addr_len, |
| 63 | table_id=0, inet=AF_INET): |
| 64 | if inet == AF_INET: |
| 65 | s = 4 |
| 66 | routes = test.vapi.ip_mfib_dump() |
| 67 | else: |
| 68 | s = 16 |
| 69 | routes = test.vapi.ip6_mfib_dump() |
| 70 | gaddr = inet_pton(inet, grp_addr) |
| 71 | saddr = inet_pton(inet, src_addr) |
| 72 | for e in routes: |
| 73 | if gaddr == e.grp_address[:s] \ |
| 74 | and grp_addr_len == e.address_length \ |
| 75 | and saddr == e.src_address[:s] \ |
| 76 | and table_id == e.table_id: |
| 77 | return True |
| 78 | return False |
| 79 | |
| 80 | |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 81 | def find_mpls_route(test, table_id, label, eos_bit, paths=None): |
| 82 | dump = test.vapi.mpls_fib_dump() |
| 83 | for e in dump: |
| 84 | if label == e.label \ |
| 85 | and eos_bit == e.eos_bit \ |
| 86 | and table_id == e.table_id: |
| 87 | if not paths: |
| 88 | return True |
| 89 | else: |
| 90 | if (len(paths) != len(e.path)): |
| 91 | return False |
| 92 | for i in range(len(paths)): |
| 93 | if (paths[i] != e.path[i]): |
| 94 | return False |
| 95 | return True |
| 96 | return False |
| 97 | |
| 98 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 99 | def fib_interface_ip_prefix(test, address, length, sw_if_index): |
| 100 | vp = VppIpPrefix(address, length) |
| 101 | addrs = test.vapi.ip_address_dump(sw_if_index, is_ipv6=vp.is_ip6) |
| 102 | |
| 103 | if vp.is_ip6: |
| 104 | n = 16 |
| 105 | else: |
| 106 | n = 4 |
| 107 | |
| 108 | for a in addrs: |
| 109 | if a.prefix_length == length and \ |
| 110 | a.sw_if_index == sw_if_index and \ |
| 111 | a.ip[:n] == vp.bytes: |
| 112 | return True |
| 113 | return False |
| 114 | |
| 115 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 116 | class VppIpTable(VppObject): |
| 117 | |
| 118 | def __init__(self, |
| 119 | test, |
| 120 | table_id, |
| 121 | is_ip6=0): |
| 122 | self._test = test |
| 123 | self.table_id = table_id |
| 124 | self.is_ip6 = is_ip6 |
| 125 | |
| 126 | def add_vpp_config(self): |
| 127 | self._test.vapi.ip_table_add_del( |
| 128 | self.table_id, |
| 129 | is_ipv6=self.is_ip6, |
| 130 | is_add=1) |
| 131 | self._test.registry.register(self, self._test.logger) |
| 132 | |
| 133 | def remove_vpp_config(self): |
| 134 | self._test.vapi.ip_table_add_del( |
| 135 | self.table_id, |
| 136 | is_ipv6=self.is_ip6, |
| 137 | is_add=0) |
| 138 | |
| 139 | def query_vpp_config(self): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 140 | if self.table_id == 0: |
| 141 | # the default table always exists |
| 142 | return False |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 143 | # find the default route |
| 144 | return find_route(self._test, |
| 145 | "::" if self.is_ip6 else "0.0.0.0", |
| 146 | 0, |
| 147 | self.table_id, |
| 148 | inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) |
| 149 | |
| 150 | def __str__(self): |
| 151 | return self.object_id() |
| 152 | |
| 153 | def object_id(self): |
| 154 | return ("table-%s-%d" % |
| 155 | ("v6" if self.is_ip6 == 1 else "v4", |
| 156 | self.table_id)) |
| 157 | |
| 158 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 159 | class VppIpInterfaceAddress(VppObject): |
| 160 | |
| 161 | def __init__(self, test, intf, addr, len): |
| 162 | self._test = test |
| 163 | self.intf = intf |
| 164 | self.prefix = VppIpPrefix(addr, len) |
| 165 | |
| 166 | def add_vpp_config(self): |
| 167 | self._test.vapi.sw_interface_add_del_address( |
| 168 | self.intf.sw_if_index, |
| 169 | self.prefix.bytes, |
| 170 | self.prefix.length, |
| 171 | is_add=1, |
| 172 | is_ipv6=self.prefix.is_ip6) |
| 173 | self._test.registry.register(self, self._test.logger) |
| 174 | |
| 175 | def remove_vpp_config(self): |
| 176 | self._test.vapi.sw_interface_add_del_address( |
| 177 | self.intf.sw_if_index, |
| 178 | self.prefix.bytes, |
| 179 | self.prefix.length, |
| 180 | is_add=0, |
| 181 | is_ipv6=self.prefix.is_ip6) |
| 182 | |
| 183 | def query_vpp_config(self): |
| 184 | return fib_interface_ip_prefix(self._test, |
| 185 | self.prefix.address, |
| 186 | self.prefix.length, |
| 187 | self.intf.sw_if_index) |
| 188 | |
| 189 | def __str__(self): |
| 190 | return self.object_id() |
| 191 | |
| 192 | def object_id(self): |
| 193 | return "interface-ip-%s-%s" % (self.intf, self.prefix) |
| 194 | |
| 195 | |
| 196 | class VppIpInterfaceBind(VppObject): |
| 197 | |
| 198 | def __init__(self, test, intf, table): |
| 199 | self._test = test |
| 200 | self.intf = intf |
| 201 | self.table = table |
| 202 | |
| 203 | def add_vpp_config(self): |
| 204 | if self.table.is_ip6: |
| 205 | self.intf.set_table_ip6(self.table.table_id) |
| 206 | else: |
| 207 | self.intf.set_table_ip4(self.table.table_id) |
| 208 | self._test.registry.register(self, self._test.logger) |
| 209 | |
| 210 | def remove_vpp_config(self): |
| 211 | if 0 == self.table.table_id: |
| 212 | return |
| 213 | if self.table.is_ip6: |
| 214 | self.intf.set_table_ip6(0) |
| 215 | else: |
| 216 | self.intf.set_table_ip4(0) |
| 217 | |
| 218 | def query_vpp_config(self): |
| 219 | if 0 == self.table.table_id: |
| 220 | return False |
| 221 | return self._test.vapi.sw_interface_get_table( |
| 222 | self.intf.sw_if_index, |
| 223 | self.table.is_ip6).vrf_id == self.table.table_id |
| 224 | |
| 225 | def __str__(self): |
| 226 | return self.object_id() |
| 227 | |
| 228 | def object_id(self): |
| 229 | return "interface-bind-%s-%s" % (self.intf, self.table) |
| 230 | |
| 231 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 232 | class VppMplsLabel(object): |
| 233 | def __init__(self, value, mode=MplsLspMode.PIPE, ttl=64, exp=0): |
| 234 | self.value = value |
| 235 | self.mode = mode |
| 236 | self.ttl = ttl |
| 237 | self.exp = exp |
| 238 | |
| 239 | def encode(self): |
| 240 | is_uniform = 0 if self.mode is MplsLspMode.PIPE else 1 |
| 241 | return {'label': self.value, |
| 242 | 'ttl': self.ttl, |
| 243 | 'exp': self.exp, |
| 244 | 'is_uniform': is_uniform} |
| 245 | |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 246 | def __eq__(self, other): |
| 247 | if isinstance(other, self.__class__): |
| 248 | return (self.value == other.value and |
| 249 | self.ttl == other.ttl and |
| 250 | self.exp == other.exp and |
| 251 | self.mode == other.mode) |
| 252 | elif hasattr(other, 'label'): |
| 253 | return (self.value == other.label and |
| 254 | self.ttl == other.ttl and |
| 255 | self.exp == other.exp and |
| 256 | (self.mode == MplsLspMode.UNIFORM) == other.is_uniform) |
| 257 | else: |
| 258 | return False |
| 259 | |
| 260 | def __ne__(self, other): |
| 261 | return not (self == other) |
| 262 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 263 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 264 | class VppRoutePath(object): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 265 | |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 266 | def __init__( |
| 267 | self, |
| 268 | nh_addr, |
| 269 | nh_sw_if_index, |
| 270 | nh_table_id=0, |
| 271 | labels=[], |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 272 | nh_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 273 | rpf_id=0, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 274 | is_interface_rx=0, |
| 275 | is_resolve_host=0, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 276 | is_resolve_attached=0, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 277 | is_source_lookup=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 278 | is_udp_encap=0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 279 | is_dvr=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 280 | next_hop_id=0xffffffff, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 281 | proto=DpoProto.DPO_PROTO_IP4): |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 282 | self.proto = proto |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 283 | self.nh_itf = nh_sw_if_index |
| 284 | self.nh_table_id = nh_table_id |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 285 | self.nh_via_label = nh_via_label |
| 286 | self.nh_labels = labels |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 287 | self.weight = 1 |
| 288 | self.rpf_id = rpf_id |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 289 | if self.proto is DpoProto.DPO_PROTO_IP6: |
| 290 | self.nh_addr = inet_pton(AF_INET6, nh_addr) |
| 291 | elif self.proto is DpoProto.DPO_PROTO_IP4: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 292 | self.nh_addr = inet_pton(AF_INET, nh_addr) |
Neale Ranns | 31426c6 | 2017-05-24 10:32:58 -0700 | [diff] [blame] | 293 | else: |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 294 | self.nh_addr = inet_pton(AF_INET6, "::") |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 295 | self.is_resolve_host = is_resolve_host |
| 296 | self.is_resolve_attached = is_resolve_attached |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 297 | self.is_interface_rx = is_interface_rx |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 298 | self.is_source_lookup = is_source_lookup |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 299 | self.is_rpf_id = 0 |
| 300 | if rpf_id != 0: |
| 301 | self.is_rpf_id = 1 |
| 302 | self.nh_itf = rpf_id |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 303 | self.is_udp_encap = is_udp_encap |
| 304 | self.next_hop_id = next_hop_id |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 305 | self.is_dvr = is_dvr |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 306 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 307 | def encode_labels(self): |
| 308 | lstack = [] |
| 309 | for l in self.nh_labels: |
| 310 | if type(l) == VppMplsLabel: |
| 311 | lstack.append(l.encode()) |
| 312 | else: |
| 313 | lstack.append({'label': l, |
| 314 | 'ttl': 255}) |
| 315 | return lstack |
| 316 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 317 | def encode(self): |
| 318 | return {'next_hop': self.nh_addr, |
| 319 | 'weight': 1, |
| 320 | 'afi': 0, |
| 321 | 'preference': 0, |
| 322 | 'table_id': self.nh_table_id, |
| 323 | 'next_hop_id': self.next_hop_id, |
| 324 | 'sw_if_index': self.nh_itf, |
| 325 | 'afi': self.proto, |
| 326 | 'is_udp_encap': self.is_udp_encap, |
| 327 | 'n_labels': len(self.nh_labels), |
| 328 | 'label_stack': self.encode_labels()} |
| 329 | |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 330 | def __eq__(self, other): |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 331 | if isinstance(other, self.__class__): |
| 332 | return self.nh_addr == other.nh_addr |
| 333 | elif hasattr(other, 'sw_if_index'): |
| 334 | # vl_api_fib_path_t |
| 335 | if (len(self.nh_labels) != other.n_labels): |
| 336 | return False |
| 337 | for i in range(len(self.nh_labels)): |
| 338 | if (self.nh_labels[i] != other.label_stack[i]): |
| 339 | return False |
| 340 | return self.nh_itf == other.sw_if_index |
| 341 | else: |
| 342 | return False |
| 343 | |
| 344 | def __ne__(self, other): |
| 345 | return not (self == other) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 346 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 347 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 348 | class VppMRoutePath(VppRoutePath): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 349 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 350 | def __init__(self, nh_sw_if_index, flags, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 351 | nh=None, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 352 | proto=DpoProto.DPO_PROTO_IP4, |
| 353 | bier_imp=0): |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 354 | if not nh: |
| 355 | nh = "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0" |
| 356 | super(VppMRoutePath, self).__init__(nh, |
| 357 | nh_sw_if_index, |
| 358 | proto=proto) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 359 | self.nh_i_flags = flags |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 360 | self.bier_imp = bier_imp |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 361 | |
| 362 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 363 | class VppIpRoute(VppObject): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 364 | """ |
| 365 | IP Route |
| 366 | """ |
| 367 | |
| 368 | def __init__(self, test, dest_addr, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 369 | dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0, |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 370 | is_unreach=0, is_prohibit=0, is_drop=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 371 | self._test = test |
| 372 | self.paths = paths |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 373 | self.dest_addr_len = dest_addr_len |
| 374 | self.table_id = table_id |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 375 | self.is_ip6 = is_ip6 |
| 376 | self.is_local = is_local |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 377 | self.is_unreach = is_unreach |
| 378 | self.is_prohibit = is_prohibit |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 379 | self.is_drop = is_drop |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 380 | self.dest_addr_p = dest_addr |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 381 | if is_ip6: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 382 | self.dest_addr = inet_pton(AF_INET6, dest_addr) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 383 | else: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 384 | self.dest_addr = inet_pton(AF_INET, dest_addr) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 385 | |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 386 | def modify(self, paths, is_local=0, |
| 387 | is_unreach=0, is_prohibit=0): |
| 388 | self.paths = paths |
| 389 | self.is_local = is_local |
| 390 | self.is_unreach = is_unreach |
| 391 | self.is_prohibit = is_prohibit |
| 392 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 393 | def add_vpp_config(self): |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 394 | if self.is_unreach or self.is_prohibit or self.is_drop: |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 395 | r = self._test.vapi.ip_add_del_route( |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 396 | self.dest_addr, |
| 397 | self.dest_addr_len, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 398 | inet_pton(AF_INET6, "::"), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 399 | 0xffffffff, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 400 | is_local=self.is_local, |
| 401 | is_unreach=self.is_unreach, |
| 402 | is_prohibit=self.is_prohibit, |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 403 | is_drop=self.is_drop, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 404 | table_id=self.table_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 405 | is_ipv6=self.is_ip6) |
| 406 | else: |
| 407 | for path in self.paths: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 408 | lstack = path.encode_labels() |
| 409 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 410 | r = self._test.vapi.ip_add_del_route( |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 411 | self.dest_addr, |
| 412 | self.dest_addr_len, |
| 413 | path.nh_addr, |
| 414 | path.nh_itf, |
| 415 | table_id=self.table_id, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 416 | next_hop_out_label_stack=lstack, |
| 417 | next_hop_n_out_labels=len(lstack), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 418 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 419 | next_hop_table_id=path.nh_table_id, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 420 | next_hop_id=path.next_hop_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 421 | is_ipv6=self.is_ip6, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 422 | is_dvr=path.is_dvr, |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 423 | is_local=self.is_local, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 424 | is_resolve_host=path.is_resolve_host, |
| 425 | is_resolve_attached=path.is_resolve_attached, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 426 | is_source_lookup=path.is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 427 | is_udp_encap=path.is_udp_encap, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 428 | is_multipath=1 if len(self.paths) > 1 else 0) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 429 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 430 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 431 | |
| 432 | def remove_vpp_config(self): |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 433 | if self.is_unreach or self.is_prohibit or self.is_drop: |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 434 | self._test.vapi.ip_add_del_route( |
| 435 | self.dest_addr, |
| 436 | self.dest_addr_len, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 437 | inet_pton(AF_INET6, "::"), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 438 | 0xffffffff, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 439 | is_local=self.is_local, |
| 440 | is_unreach=self.is_unreach, |
| 441 | is_prohibit=self.is_prohibit, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 442 | is_add=0, |
| 443 | table_id=self.table_id, |
| 444 | is_ipv6=self.is_ip6) |
| 445 | else: |
| 446 | for path in self.paths: |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 447 | self._test.vapi.ip_add_del_route( |
| 448 | self.dest_addr, |
| 449 | self.dest_addr_len, |
| 450 | path.nh_addr, |
| 451 | path.nh_itf, |
| 452 | table_id=self.table_id, |
| 453 | next_hop_table_id=path.nh_table_id, |
| 454 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 455 | next_hop_id=path.next_hop_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 456 | is_add=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 457 | is_udp_encap=path.is_udp_encap, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 458 | is_ipv6=self.is_ip6, |
| 459 | is_dvr=path.is_dvr) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 460 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 461 | def query_vpp_config(self): |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 462 | return find_route(self._test, |
| 463 | self.dest_addr_p, |
| 464 | self.dest_addr_len, |
| 465 | self.table_id, |
| 466 | inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 467 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 468 | def __str__(self): |
| 469 | return self.object_id() |
| 470 | |
| 471 | def object_id(self): |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 472 | return ("%d:%s/%d" |
| 473 | % (self.table_id, |
| 474 | self.dest_addr_p, |
| 475 | self.dest_addr_len)) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 476 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 477 | def get_stats_to(self): |
| 478 | c = self._test.statistics.get_counter("/net/route/to") |
| 479 | return c[0][self.stats_index] |
| 480 | |
| 481 | def get_stats_via(self): |
| 482 | c = self._test.statistics.get_counter("/net/route/via") |
| 483 | return c[0][self.stats_index] |
| 484 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 485 | |
| 486 | class VppIpMRoute(VppObject): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 487 | """ |
| 488 | IP Multicast Route |
| 489 | """ |
| 490 | |
| 491 | def __init__(self, test, src_addr, grp_addr, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 492 | grp_addr_len, e_flags, paths, table_id=0, |
| 493 | rpf_id=0, is_ip6=0): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 494 | self._test = test |
| 495 | self.paths = paths |
| 496 | self.grp_addr_len = grp_addr_len |
| 497 | self.table_id = table_id |
| 498 | self.e_flags = e_flags |
| 499 | self.is_ip6 = is_ip6 |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 500 | self.rpf_id = rpf_id |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 501 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 502 | self.grp_addr_p = grp_addr |
| 503 | self.src_addr_p = src_addr |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 504 | if is_ip6: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 505 | self.grp_addr = inet_pton(AF_INET6, grp_addr) |
| 506 | self.src_addr = inet_pton(AF_INET6, src_addr) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 507 | else: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 508 | self.grp_addr = inet_pton(AF_INET, grp_addr) |
| 509 | self.src_addr = inet_pton(AF_INET, src_addr) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 510 | |
| 511 | def add_vpp_config(self): |
| 512 | for path in self.paths: |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 513 | r = self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 514 | self.grp_addr, |
| 515 | self.grp_addr_len, |
| 516 | self.e_flags, |
| 517 | path.proto, |
| 518 | path.nh_itf, |
| 519 | path.nh_addr, |
| 520 | path.nh_i_flags, |
| 521 | bier_imp=path.bier_imp, |
| 522 | rpf_id=self.rpf_id, |
| 523 | table_id=self.table_id, |
| 524 | is_ipv6=self.is_ip6) |
| 525 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 526 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 527 | |
| 528 | def remove_vpp_config(self): |
| 529 | for path in self.paths: |
| 530 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 531 | self.grp_addr, |
| 532 | self.grp_addr_len, |
| 533 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 534 | path.proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 535 | path.nh_itf, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 536 | path.nh_addr, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 537 | path.nh_i_flags, |
| 538 | table_id=self.table_id, |
Neale Ranns | eea537a | 2018-01-09 04:11:28 -0800 | [diff] [blame] | 539 | bier_imp=path.bier_imp, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 540 | is_add=0, |
| 541 | is_ipv6=self.is_ip6) |
| 542 | |
| 543 | def update_entry_flags(self, flags): |
| 544 | self.e_flags = flags |
| 545 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 546 | self.grp_addr, |
| 547 | self.grp_addr_len, |
| 548 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 549 | 0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 550 | 0xffffffff, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 551 | "", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 552 | 0, |
| 553 | table_id=self.table_id, |
| 554 | is_ipv6=self.is_ip6) |
| 555 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 556 | def update_rpf_id(self, rpf_id): |
| 557 | self.rpf_id = rpf_id |
| 558 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 559 | self.grp_addr, |
| 560 | self.grp_addr_len, |
| 561 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 562 | 0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 563 | 0xffffffff, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 564 | "", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 565 | 0, |
| 566 | rpf_id=self.rpf_id, |
| 567 | table_id=self.table_id, |
| 568 | is_ipv6=self.is_ip6) |
| 569 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 570 | def update_path_flags(self, itf, flags): |
| 571 | for path in self.paths: |
| 572 | if path.nh_itf == itf: |
| 573 | path.nh_i_flags = flags |
| 574 | break |
| 575 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 576 | self.grp_addr, |
| 577 | self.grp_addr_len, |
| 578 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 579 | path.proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 580 | path.nh_itf, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 581 | path.nh_addr, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 582 | path.nh_i_flags, |
| 583 | table_id=self.table_id, |
| 584 | is_ipv6=self.is_ip6) |
| 585 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 586 | def query_vpp_config(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 587 | return find_mroute(self._test, |
| 588 | self.grp_addr_p, |
| 589 | self.src_addr_p, |
| 590 | self.grp_addr_len, |
| 591 | self.table_id, |
| 592 | inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 593 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 594 | def __str__(self): |
| 595 | return self.object_id() |
| 596 | |
| 597 | def object_id(self): |
| 598 | if self.is_ip6: |
| 599 | return ("%d:(%s,%s/%d)" |
| 600 | % (self.table_id, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 601 | inet_ntop(AF_INET6, self.src_addr), |
| 602 | inet_ntop(AF_INET6, self.grp_addr), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 603 | self.grp_addr_len)) |
| 604 | else: |
| 605 | return ("%d:(%s,%s/%d)" |
| 606 | % (self.table_id, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 607 | inet_ntop(AF_INET, self.src_addr), |
| 608 | inet_ntop(AF_INET, self.grp_addr), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 609 | self.grp_addr_len)) |
| 610 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 611 | def get_stats(self): |
| 612 | c = self._test.statistics.get_counter("/net/mroute") |
| 613 | return c[0][self.stats_index] |
| 614 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 615 | |
| 616 | class VppMFibSignal(object): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 617 | def __init__(self, test, route, interface, packet): |
| 618 | self.route = route |
| 619 | self.interface = interface |
| 620 | self.packet = packet |
| 621 | self.test = test |
| 622 | |
| 623 | def compare(self, signal): |
| 624 | self.test.assertEqual(self.interface, signal.sw_if_index) |
| 625 | self.test.assertEqual(self.route.table_id, signal.table_id) |
| 626 | self.test.assertEqual(self.route.grp_addr_len, |
| 627 | signal.grp_address_len) |
| 628 | for i in range(self.route.grp_addr_len / 8): |
| 629 | self.test.assertEqual(self.route.grp_addr[i], |
| 630 | signal.grp_address[i]) |
| 631 | if (self.route.grp_addr_len > 32): |
| 632 | for i in range(4): |
| 633 | self.test.assertEqual(self.route.src_addr[i], |
| 634 | signal.src_address[i]) |
| 635 | |
| 636 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 637 | class VppMplsIpBind(VppObject): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 638 | """ |
| 639 | MPLS to IP Binding |
| 640 | """ |
| 641 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 642 | def __init__(self, test, local_label, dest_addr, dest_addr_len, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 643 | table_id=0, ip_table_id=0, is_ip6=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 644 | self._test = test |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 645 | self.dest_addr_len = dest_addr_len |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 646 | self.dest_addr = dest_addr |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 647 | self.local_label = local_label |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 648 | self.table_id = table_id |
| 649 | self.ip_table_id = ip_table_id |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 650 | self.is_ip6 = is_ip6 |
| 651 | if is_ip6: |
| 652 | self.dest_addrn = inet_pton(AF_INET6, dest_addr) |
| 653 | else: |
| 654 | self.dest_addrn = inet_pton(AF_INET, dest_addr) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 655 | |
| 656 | def add_vpp_config(self): |
| 657 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 658 | self.dest_addrn, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 659 | self.dest_addr_len, |
| 660 | table_id=self.table_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 661 | ip_table_id=self.ip_table_id, |
| 662 | is_ip4=(self.is_ip6 == 0)) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 663 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 664 | |
| 665 | def remove_vpp_config(self): |
| 666 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 667 | self.dest_addrn, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 668 | self.dest_addr_len, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 669 | table_id=self.table_id, |
| 670 | ip_table_id=self.ip_table_id, |
| 671 | is_bind=0, |
| 672 | is_ip4=(self.is_ip6 == 0)) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 673 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 674 | def query_vpp_config(self): |
| 675 | dump = self._test.vapi.mpls_fib_dump() |
| 676 | for e in dump: |
| 677 | if self.local_label == e.label \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 678 | and self.table_id == e.table_id: |
| 679 | return True |
| 680 | return False |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 681 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 682 | def __str__(self): |
| 683 | return self.object_id() |
| 684 | |
| 685 | def object_id(self): |
| 686 | return ("%d:%s binds %d:%s/%d" |
| 687 | % (self.table_id, |
| 688 | self.local_label, |
| 689 | self.ip_table_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 690 | self.dest_addr, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 691 | self.dest_addr_len)) |
| 692 | |
| 693 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 694 | class VppMplsTable(VppObject): |
| 695 | |
| 696 | def __init__(self, |
| 697 | test, |
| 698 | table_id): |
| 699 | self._test = test |
| 700 | self.table_id = table_id |
| 701 | |
| 702 | def add_vpp_config(self): |
| 703 | self._test.vapi.mpls_table_add_del( |
| 704 | self.table_id, |
| 705 | is_add=1) |
| 706 | self._test.registry.register(self, self._test.logger) |
| 707 | |
| 708 | def remove_vpp_config(self): |
| 709 | self._test.vapi.mpls_table_add_del( |
| 710 | self.table_id, |
| 711 | is_add=0) |
| 712 | |
| 713 | def query_vpp_config(self): |
| 714 | # find the default route |
| 715 | dump = self._test.vapi.mpls_fib_dump() |
| 716 | if len(dump): |
| 717 | return True |
| 718 | return False |
| 719 | |
| 720 | def __str__(self): |
| 721 | return self.object_id() |
| 722 | |
| 723 | def object_id(self): |
| 724 | return ("table-mpls-%d" % (self.table_id)) |
| 725 | |
| 726 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 727 | class VppMplsRoute(VppObject): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 728 | """ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 729 | MPLS Route/LSP |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 730 | """ |
| 731 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 732 | def __init__(self, test, local_label, eos_bit, paths, table_id=0, |
| 733 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 734 | self._test = test |
| 735 | self.paths = paths |
| 736 | self.local_label = local_label |
| 737 | self.eos_bit = eos_bit |
| 738 | self.table_id = table_id |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 739 | self.is_multicast = is_multicast |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 740 | |
| 741 | def add_vpp_config(self): |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 742 | is_multipath = len(self.paths) > 1 |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 743 | for path in self.paths: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 744 | lstack = path.encode_labels() |
| 745 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 746 | r = self._test.vapi.mpls_route_add_del( |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 747 | self.local_label, |
| 748 | self.eos_bit, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 749 | path.proto, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 750 | path.nh_addr, |
| 751 | path.nh_itf, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 752 | is_multicast=self.is_multicast, |
| 753 | is_multipath=is_multipath, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 754 | table_id=self.table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 755 | is_interface_rx=path.is_interface_rx, |
| 756 | is_rpf_id=path.is_rpf_id, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 757 | next_hop_out_label_stack=lstack, |
| 758 | next_hop_n_out_labels=len(lstack), |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 759 | next_hop_via_label=path.nh_via_label, |
| 760 | next_hop_table_id=path.nh_table_id) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 761 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 762 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 763 | |
| 764 | def remove_vpp_config(self): |
| 765 | for path in self.paths: |
| 766 | self._test.vapi.mpls_route_add_del(self.local_label, |
| 767 | self.eos_bit, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 768 | path.proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 769 | path.nh_addr, |
| 770 | path.nh_itf, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 771 | is_rpf_id=path.is_rpf_id, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 772 | table_id=self.table_id, |
| 773 | is_add=0) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 774 | |
| 775 | def query_vpp_config(self): |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 776 | return find_mpls_route(self._test, self.table_id, |
| 777 | self.local_label, self.eos_bit) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 778 | |
| 779 | def __str__(self): |
| 780 | return self.object_id() |
| 781 | |
| 782 | def object_id(self): |
| 783 | return ("%d:%s/%d" |
| 784 | % (self.table_id, |
| 785 | self.local_label, |
| 786 | 20+self.eos_bit)) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 787 | |
| 788 | def get_stats_to(self): |
| 789 | c = self._test.statistics.get_counter("/net/route/to") |
| 790 | return c[0][self.stats_index] |
| 791 | |
| 792 | def get_stats_via(self): |
| 793 | c = self._test.statistics.get_counter("/net/route/via") |
| 794 | return c[0][self.stats_index] |