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