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 | |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 7 | from vpp_object import VppObject |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 8 | from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 |
Paul Vinciguerra | a279d9c | 2019-02-28 09:00:09 -0800 | [diff] [blame] | 9 | from vpp_ip import DpoProto, VppIpPrefix |
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, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 320 | 'preference': 0, |
| 321 | 'table_id': self.nh_table_id, |
| 322 | 'next_hop_id': self.next_hop_id, |
| 323 | 'sw_if_index': self.nh_itf, |
| 324 | 'afi': self.proto, |
| 325 | 'is_udp_encap': self.is_udp_encap, |
| 326 | 'n_labels': len(self.nh_labels), |
| 327 | 'label_stack': self.encode_labels()} |
| 328 | |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 329 | def __eq__(self, other): |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 330 | if isinstance(other, self.__class__): |
| 331 | return self.nh_addr == other.nh_addr |
| 332 | elif hasattr(other, 'sw_if_index'): |
| 333 | # vl_api_fib_path_t |
| 334 | if (len(self.nh_labels) != other.n_labels): |
| 335 | return False |
| 336 | for i in range(len(self.nh_labels)): |
| 337 | if (self.nh_labels[i] != other.label_stack[i]): |
| 338 | return False |
| 339 | return self.nh_itf == other.sw_if_index |
| 340 | else: |
| 341 | return False |
| 342 | |
| 343 | def __ne__(self, other): |
| 344 | return not (self == other) |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 345 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 346 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 347 | class VppMRoutePath(VppRoutePath): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 348 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 349 | def __init__(self, nh_sw_if_index, flags, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 350 | nh=None, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 351 | proto=DpoProto.DPO_PROTO_IP4, |
| 352 | bier_imp=0): |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 353 | if not nh: |
| 354 | nh = "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0" |
| 355 | super(VppMRoutePath, self).__init__(nh, |
| 356 | nh_sw_if_index, |
| 357 | proto=proto) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 358 | self.nh_i_flags = flags |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 359 | self.bier_imp = bier_imp |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 360 | |
| 361 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 362 | class VppIpRoute(VppObject): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 363 | """ |
| 364 | IP Route |
| 365 | """ |
| 366 | |
| 367 | def __init__(self, test, dest_addr, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 368 | 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] | 369 | is_unreach=0, is_prohibit=0, is_drop=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 370 | self._test = test |
| 371 | self.paths = paths |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 372 | self.dest_addr_len = dest_addr_len |
| 373 | self.table_id = table_id |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 374 | self.is_ip6 = is_ip6 |
| 375 | self.is_local = is_local |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 376 | self.is_unreach = is_unreach |
| 377 | self.is_prohibit = is_prohibit |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 378 | self.is_drop = is_drop |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 379 | self.dest_addr_p = dest_addr |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 380 | if is_ip6: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 381 | self.dest_addr = inet_pton(AF_INET6, dest_addr) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 382 | else: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 383 | self.dest_addr = inet_pton(AF_INET, dest_addr) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 384 | |
Neale Ranns | 69b7aa4 | 2017-03-10 03:04:12 -0800 | [diff] [blame] | 385 | def modify(self, paths, is_local=0, |
| 386 | is_unreach=0, is_prohibit=0): |
| 387 | self.paths = paths |
| 388 | self.is_local = is_local |
| 389 | self.is_unreach = is_unreach |
| 390 | self.is_prohibit = is_prohibit |
| 391 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 392 | def add_vpp_config(self): |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 393 | if self.is_unreach or self.is_prohibit or self.is_drop: |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 394 | r = self._test.vapi.ip_add_del_route( |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 395 | self.dest_addr, |
| 396 | self.dest_addr_len, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 397 | inet_pton(AF_INET6, "::"), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 398 | 0xffffffff, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 399 | is_local=self.is_local, |
| 400 | is_unreach=self.is_unreach, |
| 401 | is_prohibit=self.is_prohibit, |
Neale Ranns | 3b93be5 | 2018-09-07 01:48:54 -0700 | [diff] [blame] | 402 | is_drop=self.is_drop, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 403 | table_id=self.table_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 404 | is_ipv6=self.is_ip6) |
| 405 | else: |
| 406 | for path in self.paths: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 407 | lstack = path.encode_labels() |
| 408 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 409 | r = self._test.vapi.ip_add_del_route( |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 410 | self.dest_addr, |
| 411 | self.dest_addr_len, |
| 412 | path.nh_addr, |
| 413 | path.nh_itf, |
| 414 | table_id=self.table_id, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 415 | next_hop_out_label_stack=lstack, |
| 416 | next_hop_n_out_labels=len(lstack), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 417 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 418 | next_hop_table_id=path.nh_table_id, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 419 | next_hop_id=path.next_hop_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 420 | is_ipv6=self.is_ip6, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 421 | is_dvr=path.is_dvr, |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 422 | is_local=self.is_local, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 423 | is_resolve_host=path.is_resolve_host, |
| 424 | is_resolve_attached=path.is_resolve_attached, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 425 | is_source_lookup=path.is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 426 | is_udp_encap=path.is_udp_encap, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 427 | is_multipath=1 if len(self.paths) > 1 else 0) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 428 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 429 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 430 | |
| 431 | def remove_vpp_config(self): |
Neale Ranns | 7425f92 | 2019-01-23 00:36:16 -0800 | [diff] [blame] | 432 | if self.is_unreach or self.is_prohibit or self.is_drop: |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 433 | self._test.vapi.ip_add_del_route( |
| 434 | self.dest_addr, |
| 435 | self.dest_addr_len, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 436 | inet_pton(AF_INET6, "::"), |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 437 | 0xffffffff, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 438 | is_local=self.is_local, |
| 439 | is_unreach=self.is_unreach, |
| 440 | is_prohibit=self.is_prohibit, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 441 | is_add=0, |
| 442 | table_id=self.table_id, |
| 443 | is_ipv6=self.is_ip6) |
| 444 | else: |
| 445 | for path in self.paths: |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 446 | self._test.vapi.ip_add_del_route( |
| 447 | self.dest_addr, |
| 448 | self.dest_addr_len, |
| 449 | path.nh_addr, |
| 450 | path.nh_itf, |
| 451 | table_id=self.table_id, |
| 452 | next_hop_table_id=path.nh_table_id, |
| 453 | next_hop_via_label=path.nh_via_label, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 454 | next_hop_id=path.next_hop_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 455 | is_add=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 456 | is_udp_encap=path.is_udp_encap, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 457 | is_ipv6=self.is_ip6, |
| 458 | is_dvr=path.is_dvr) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 459 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 460 | def query_vpp_config(self): |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 461 | return find_route(self._test, |
| 462 | self.dest_addr_p, |
| 463 | self.dest_addr_len, |
| 464 | self.table_id, |
| 465 | inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 466 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 467 | def __str__(self): |
| 468 | return self.object_id() |
| 469 | |
| 470 | def object_id(self): |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 471 | return ("%d:%s/%d" |
| 472 | % (self.table_id, |
| 473 | self.dest_addr_p, |
| 474 | self.dest_addr_len)) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 475 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 476 | def get_stats_to(self): |
| 477 | c = self._test.statistics.get_counter("/net/route/to") |
| 478 | return c[0][self.stats_index] |
| 479 | |
| 480 | def get_stats_via(self): |
| 481 | c = self._test.statistics.get_counter("/net/route/via") |
| 482 | return c[0][self.stats_index] |
| 483 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 484 | |
| 485 | class VppIpMRoute(VppObject): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 486 | """ |
| 487 | IP Multicast Route |
| 488 | """ |
| 489 | |
| 490 | def __init__(self, test, src_addr, grp_addr, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 491 | grp_addr_len, e_flags, paths, table_id=0, |
| 492 | rpf_id=0, is_ip6=0): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 493 | self._test = test |
| 494 | self.paths = paths |
| 495 | self.grp_addr_len = grp_addr_len |
| 496 | self.table_id = table_id |
| 497 | self.e_flags = e_flags |
| 498 | self.is_ip6 = is_ip6 |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 499 | self.rpf_id = rpf_id |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 500 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 501 | self.grp_addr_p = grp_addr |
| 502 | self.src_addr_p = src_addr |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 503 | if is_ip6: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 504 | self.grp_addr = inet_pton(AF_INET6, grp_addr) |
| 505 | self.src_addr = inet_pton(AF_INET6, src_addr) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 506 | else: |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 507 | self.grp_addr = inet_pton(AF_INET, grp_addr) |
| 508 | self.src_addr = inet_pton(AF_INET, src_addr) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 509 | |
| 510 | def add_vpp_config(self): |
| 511 | for path in self.paths: |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 512 | r = self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 513 | self.grp_addr, |
| 514 | self.grp_addr_len, |
| 515 | self.e_flags, |
| 516 | path.proto, |
| 517 | path.nh_itf, |
| 518 | path.nh_addr, |
| 519 | path.nh_i_flags, |
| 520 | bier_imp=path.bier_imp, |
| 521 | rpf_id=self.rpf_id, |
| 522 | table_id=self.table_id, |
| 523 | is_ipv6=self.is_ip6) |
| 524 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 525 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 526 | |
| 527 | def remove_vpp_config(self): |
| 528 | for path in self.paths: |
| 529 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 530 | self.grp_addr, |
| 531 | self.grp_addr_len, |
| 532 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 533 | path.proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 534 | path.nh_itf, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 535 | path.nh_addr, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 536 | path.nh_i_flags, |
| 537 | table_id=self.table_id, |
Neale Ranns | eea537a | 2018-01-09 04:11:28 -0800 | [diff] [blame] | 538 | bier_imp=path.bier_imp, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 539 | is_add=0, |
| 540 | is_ipv6=self.is_ip6) |
| 541 | |
| 542 | def update_entry_flags(self, flags): |
| 543 | self.e_flags = flags |
| 544 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 545 | self.grp_addr, |
| 546 | self.grp_addr_len, |
| 547 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 548 | 0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 549 | 0xffffffff, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 550 | "", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 551 | 0, |
| 552 | table_id=self.table_id, |
| 553 | is_ipv6=self.is_ip6) |
| 554 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 555 | def update_rpf_id(self, rpf_id): |
| 556 | self.rpf_id = rpf_id |
| 557 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 558 | self.grp_addr, |
| 559 | self.grp_addr_len, |
| 560 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 561 | 0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 562 | 0xffffffff, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 563 | "", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 564 | 0, |
| 565 | rpf_id=self.rpf_id, |
| 566 | table_id=self.table_id, |
| 567 | is_ipv6=self.is_ip6) |
| 568 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 569 | def update_path_flags(self, itf, flags): |
| 570 | for path in self.paths: |
| 571 | if path.nh_itf == itf: |
| 572 | path.nh_i_flags = flags |
| 573 | break |
| 574 | self._test.vapi.ip_mroute_add_del(self.src_addr, |
| 575 | self.grp_addr, |
| 576 | self.grp_addr_len, |
| 577 | self.e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 578 | path.proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 579 | path.nh_itf, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 580 | path.nh_addr, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 581 | path.nh_i_flags, |
| 582 | table_id=self.table_id, |
| 583 | is_ipv6=self.is_ip6) |
| 584 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 585 | def query_vpp_config(self): |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 586 | return find_mroute(self._test, |
| 587 | self.grp_addr_p, |
| 588 | self.src_addr_p, |
| 589 | self.grp_addr_len, |
| 590 | self.table_id, |
| 591 | inet=AF_INET6 if self.is_ip6 == 1 else AF_INET) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 592 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 593 | def __str__(self): |
| 594 | return self.object_id() |
| 595 | |
| 596 | def object_id(self): |
| 597 | if self.is_ip6: |
| 598 | return ("%d:(%s,%s/%d)" |
| 599 | % (self.table_id, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 600 | inet_ntop(AF_INET6, self.src_addr), |
| 601 | inet_ntop(AF_INET6, self.grp_addr), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 602 | self.grp_addr_len)) |
| 603 | else: |
| 604 | return ("%d:(%s,%s/%d)" |
| 605 | % (self.table_id, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 606 | inet_ntop(AF_INET, self.src_addr), |
| 607 | inet_ntop(AF_INET, self.grp_addr), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 608 | self.grp_addr_len)) |
| 609 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 610 | def get_stats(self): |
| 611 | c = self._test.statistics.get_counter("/net/mroute") |
| 612 | return c[0][self.stats_index] |
| 613 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 614 | |
| 615 | class VppMFibSignal(object): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 616 | def __init__(self, test, route, interface, packet): |
| 617 | self.route = route |
| 618 | self.interface = interface |
| 619 | self.packet = packet |
| 620 | self.test = test |
| 621 | |
| 622 | def compare(self, signal): |
| 623 | self.test.assertEqual(self.interface, signal.sw_if_index) |
| 624 | self.test.assertEqual(self.route.table_id, signal.table_id) |
| 625 | self.test.assertEqual(self.route.grp_addr_len, |
| 626 | signal.grp_address_len) |
| 627 | for i in range(self.route.grp_addr_len / 8): |
| 628 | self.test.assertEqual(self.route.grp_addr[i], |
| 629 | signal.grp_address[i]) |
| 630 | if (self.route.grp_addr_len > 32): |
| 631 | for i in range(4): |
| 632 | self.test.assertEqual(self.route.src_addr[i], |
| 633 | signal.src_address[i]) |
| 634 | |
| 635 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 636 | class VppMplsIpBind(VppObject): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 637 | """ |
| 638 | MPLS to IP Binding |
| 639 | """ |
| 640 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 641 | def __init__(self, test, local_label, dest_addr, dest_addr_len, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 642 | table_id=0, ip_table_id=0, is_ip6=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 643 | self._test = test |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 644 | self.dest_addr_len = dest_addr_len |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 645 | self.dest_addr = dest_addr |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 646 | self.local_label = local_label |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 647 | self.table_id = table_id |
| 648 | self.ip_table_id = ip_table_id |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 649 | self.is_ip6 = is_ip6 |
| 650 | if is_ip6: |
| 651 | self.dest_addrn = inet_pton(AF_INET6, dest_addr) |
| 652 | else: |
| 653 | self.dest_addrn = inet_pton(AF_INET, dest_addr) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 654 | |
| 655 | def add_vpp_config(self): |
| 656 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 657 | self.dest_addrn, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 658 | self.dest_addr_len, |
| 659 | table_id=self.table_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 660 | ip_table_id=self.ip_table_id, |
| 661 | is_ip4=(self.is_ip6 == 0)) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 662 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 663 | |
| 664 | def remove_vpp_config(self): |
| 665 | self._test.vapi.mpls_ip_bind_unbind(self.local_label, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 666 | self.dest_addrn, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 667 | self.dest_addr_len, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 668 | table_id=self.table_id, |
| 669 | ip_table_id=self.ip_table_id, |
| 670 | is_bind=0, |
| 671 | is_ip4=(self.is_ip6 == 0)) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 672 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 673 | def query_vpp_config(self): |
| 674 | dump = self._test.vapi.mpls_fib_dump() |
| 675 | for e in dump: |
| 676 | if self.local_label == e.label \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 677 | and self.table_id == e.table_id: |
| 678 | return True |
| 679 | return False |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 680 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 681 | def __str__(self): |
| 682 | return self.object_id() |
| 683 | |
| 684 | def object_id(self): |
| 685 | return ("%d:%s binds %d:%s/%d" |
| 686 | % (self.table_id, |
| 687 | self.local_label, |
| 688 | self.ip_table_id, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 689 | self.dest_addr, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 690 | self.dest_addr_len)) |
| 691 | |
| 692 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 693 | class VppMplsTable(VppObject): |
| 694 | |
| 695 | def __init__(self, |
| 696 | test, |
| 697 | table_id): |
| 698 | self._test = test |
| 699 | self.table_id = table_id |
| 700 | |
| 701 | def add_vpp_config(self): |
| 702 | self._test.vapi.mpls_table_add_del( |
| 703 | self.table_id, |
| 704 | is_add=1) |
| 705 | self._test.registry.register(self, self._test.logger) |
| 706 | |
| 707 | def remove_vpp_config(self): |
| 708 | self._test.vapi.mpls_table_add_del( |
| 709 | self.table_id, |
| 710 | is_add=0) |
| 711 | |
| 712 | def query_vpp_config(self): |
| 713 | # find the default route |
| 714 | dump = self._test.vapi.mpls_fib_dump() |
| 715 | if len(dump): |
| 716 | return True |
| 717 | return False |
| 718 | |
| 719 | def __str__(self): |
| 720 | return self.object_id() |
| 721 | |
| 722 | def object_id(self): |
| 723 | return ("table-mpls-%d" % (self.table_id)) |
| 724 | |
| 725 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 726 | class VppMplsRoute(VppObject): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 727 | """ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 728 | MPLS Route/LSP |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 729 | """ |
| 730 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 731 | def __init__(self, test, local_label, eos_bit, paths, table_id=0, |
| 732 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 733 | self._test = test |
| 734 | self.paths = paths |
| 735 | self.local_label = local_label |
| 736 | self.eos_bit = eos_bit |
| 737 | self.table_id = table_id |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 738 | self.is_multicast = is_multicast |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 739 | |
| 740 | def add_vpp_config(self): |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 741 | is_multipath = len(self.paths) > 1 |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 742 | for path in self.paths: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 743 | lstack = path.encode_labels() |
| 744 | |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 745 | r = self._test.vapi.mpls_route_add_del( |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 746 | self.local_label, |
| 747 | self.eos_bit, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 748 | path.proto, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 749 | path.nh_addr, |
| 750 | path.nh_itf, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 751 | is_multicast=self.is_multicast, |
| 752 | is_multipath=is_multipath, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 753 | table_id=self.table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 754 | is_interface_rx=path.is_interface_rx, |
| 755 | is_rpf_id=path.is_rpf_id, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 756 | next_hop_out_label_stack=lstack, |
| 757 | next_hop_n_out_labels=len(lstack), |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 758 | next_hop_via_label=path.nh_via_label, |
| 759 | next_hop_table_id=path.nh_table_id) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 760 | self.stats_index = r.stats_index |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 761 | self._test.registry.register(self, self._test.logger) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 762 | |
| 763 | def remove_vpp_config(self): |
| 764 | for path in self.paths: |
| 765 | self._test.vapi.mpls_route_add_del(self.local_label, |
| 766 | self.eos_bit, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 767 | path.proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 768 | path.nh_addr, |
| 769 | path.nh_itf, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 770 | is_rpf_id=path.is_rpf_id, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 771 | table_id=self.table_id, |
| 772 | is_add=0) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 773 | |
| 774 | def query_vpp_config(self): |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 775 | return find_mpls_route(self._test, self.table_id, |
| 776 | self.local_label, self.eos_bit) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 777 | |
| 778 | def __str__(self): |
| 779 | return self.object_id() |
| 780 | |
| 781 | def object_id(self): |
| 782 | return ("%d:%s/%d" |
| 783 | % (self.table_id, |
| 784 | self.local_label, |
| 785 | 20+self.eos_bit)) |
Neale Ranns | 008dbe1 | 2018-09-07 09:32:36 -0700 | [diff] [blame] | 786 | |
| 787 | def get_stats_to(self): |
| 788 | c = self._test.statistics.get_counter("/net/route/to") |
| 789 | return c[0][self.stats_index] |
| 790 | |
| 791 | def get_stats_via(self): |
| 792 | c = self._test.statistics.get_counter("/net/route/via") |
| 793 | return c[0][self.stats_index] |