Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1 | # NB NB NB NB NB NB NB NB NB NB NB |
| 2 | # |
| 3 | # NOTE: The API binary wrappers in this file are in the process of being |
| 4 | # deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using |
| 5 | # named arguments directly instead. |
| 6 | # |
| 7 | |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 8 | import os |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 9 | import time |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 10 | from collections import deque |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 11 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 12 | from six import moves, iteritems |
Paul Vinciguerra | 8467919 | 2019-01-13 11:33:52 -0800 | [diff] [blame] | 13 | from vpp_papi import VPP, mac_pton |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 14 | from hook import Hook |
Paul Vinciguerra | b5f15bd | 2019-03-17 08:42:58 -0700 | [diff] [blame] | 15 | from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 16 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 17 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 18 | class QOS_SOURCE: |
| 19 | EXT = 0 |
| 20 | VLAN = 1 |
| 21 | MPLS = 2 |
| 22 | IP = 3 |
| 23 | |
| 24 | |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 25 | class SYSLOG_SEVERITY: |
| 26 | EMERG = 0 |
| 27 | ALERT = 1 |
| 28 | CRIT = 2 |
| 29 | ERR = 3 |
| 30 | WARN = 4 |
| 31 | NOTICE = 5 |
| 32 | INFO = 6 |
| 33 | DBG = 7 |
| 34 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 35 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 36 | # |
| 37 | # Dictionary keyed on message name to override default values for |
| 38 | # named parameters |
| 39 | # |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 40 | defaultmapping = { |
| 41 | 'map_add_domain': {'mtu': 1280}, |
| 42 | 'syslog_set_sender': {'collector_port': 514, |
| 43 | 'max_msg_size': 480}, |
| 44 | 'acl_interface_add_del': {'is_add': 1, 'is_input': 1}, |
| 45 | 'acl_interface_list_dump': {'sw_if_index': 4294967295, }, |
| 46 | 'app_namespace_add_del': {'sw_if_index': 4294967295, }, |
| 47 | 'bd_ip_mac_add_del': {'is_add': 1, }, |
| 48 | 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1, |
| 49 | 'is_add': 1, }, |
| 50 | 'bier_disp_table_add_del': {'is_add': 1, }, |
| 51 | 'bier_imp_add': {'is_add': 1, }, |
| 52 | 'bier_route_add_del': {'is_add': 1, }, |
| 53 | 'bier_table_add_del': {'is_add': 1, }, |
| 54 | 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1, |
| 55 | 'learn': 1, 'is_add': 1, }, |
Paul Vinciguerra | 9a29f79 | 2019-04-30 20:44:25 -0700 | [diff] [blame^] | 56 | 'bvi_create': {'user_instance': 4294967295, }, |
| 57 | 'bvi_delete': {}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 58 | 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295, |
| 59 | 'nbuckets': 2, 'memory_size': 2097152, |
| 60 | 'next_table_index': 4294967295, |
| 61 | 'miss_next_index': 4294967295, }, |
| 62 | 'dhcp6_client_enable_disable': {'enable': 1, }, |
| 63 | 'dhcp6_clients_enable_disable': {'enable': 1, }, |
| 64 | 'dhcp6_pd_client_enable_disable': {'enable': 1, }, |
| 65 | 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, }, |
| 66 | 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, }, |
| 67 | 'dhcp_proxy_config': {'is_add': 1, }, |
| 68 | 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, }, |
| 69 | 'dslite_add_del_pool_addr_range': {'is_add': 1, }, |
| 70 | 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, }, |
| 71 | 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 72 | 'decap_next_index': 4294967295, }, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 73 | 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 74 | 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295, |
| 75 | 'decap_next_index': 4294967295, }, |
| 76 | 'input_acl_set_interface': {'ip4_table_index': 4294967295, |
| 77 | 'ip6_table_index': 4294967295, |
| 78 | 'l2_table_index': 4294967295, }, |
| 79 | 'ip6_add_del_address_using_prefix': {'is_add': 1, }, |
| 80 | 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, }, |
| 81 | 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295, |
| 82 | 'next_hop_weight': 1, 'next_hop_via_label': 1048576, |
| 83 | 'next_hop_id': 4294967295, |
| 84 | 'classify_table_index': 4294967295, 'is_add': 1, }, |
| 85 | 'ip_mroute_add_del': {'is_add': 1, }, |
| 86 | 'ip_neighbor_add_del': {'is_add': 1, }, |
| 87 | 'ip_punt_police': {'is_add': 1, }, |
| 88 | 'ip_punt_redirect': {'is_add': 1, }, |
| 89 | 'ip_table_add_del': {'is_add': 1, }, |
| 90 | 'ip_unnumbered_dump': {'sw_if_index': 4294967295, }, |
| 91 | 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, }, |
| 92 | 'ipsec_interface_add_del_spd': {'is_add': 1, }, |
| 93 | 'ipsec_sad_entry_add_del': {'is_add': 1, }, |
| 94 | 'ipsec_spd_add_del': {'is_add': 1, }, |
| 95 | 'ipsec_spd_dump': {'sa_id': 4294967295, }, |
| 96 | 'ipsec_spd_entry_add_del': {'local_port_stop': 65535, |
| 97 | 'remote_port_stop': 65535, 'priority': 100, |
| 98 | 'is_outbound': 1, |
| 99 | 'is_add': 1, }, |
| 100 | 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, }, |
| 101 | 'l2_emulation': {'enable': 1, }, |
| 102 | 'l2fib_add_del': {'is_add': 1, }, |
Paul Vinciguerra | f7f1334 | 2019-03-19 11:54:39 -0700 | [diff] [blame] | 103 | 'lb_conf': {'sticky_buckets_per_core': 4294967295, |
| 104 | 'flow_timeout': 4294967295}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 105 | 'lisp_add_del_adjacency': {'is_add': 1, }, |
| 106 | 'lisp_add_del_local_eid': {'is_add': 1, }, |
| 107 | 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, }, |
| 108 | 'lisp_add_del_locator_set': {'is_add': 1, }, |
| 109 | 'lisp_add_del_remote_mapping': {'is_add': 1, }, |
| 110 | 'macip_acl_add_replace': {'acl_index': 4294967295, }, |
| 111 | 'macip_acl_dump': {'acl_index': 4294967295, }, |
| 112 | 'macip_acl_interface_add_del': {'is_add': 1, }, |
| 113 | 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, }, |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 114 | 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295, |
| 115 | 'mr_next_hop_weight': 1, |
| 116 | 'mr_next_hop_via_label': 1048576, |
| 117 | 'mr_is_add': 1, |
| 118 | 'mr_classify_table_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 119 | 'mpls_table_add_del': {'is_add': 1, }, |
| 120 | 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295, |
| 121 | 'next_hop_weight': 1, |
| 122 | 'next_hop_via_label': 1048576, |
| 123 | 'is_add': 1, }, |
| 124 | 'mpls_tunnel_dump': {'sw_if_index': 4294967295, }, |
| 125 | 'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, }, |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 126 | 'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 127 | 'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 128 | 'nat44_add_del_interface_addr': {'is_add': 1, }, |
| 129 | 'nat44_add_del_lb_static_mapping': {'is_add': 1, }, |
| 130 | 'nat44_add_del_static_mapping': {'external_sw_if_index': 4294967295, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 131 | 'is_add': 1, }, |
| 132 | 'nat44_interface_add_del_feature': {'is_add': 1, }, |
| 133 | 'nat44_interface_add_del_output_feature': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 134 | 'nat44_lb_static_mapping_add_del_local': {'is_add': 1, }, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 135 | 'nat64_add_del_interface': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 136 | 'nat64_add_del_interface_addr': {'is_add': 1, }, |
| 137 | 'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, }, |
| 138 | 'nat64_add_del_prefix': {'is_add': 1, }, |
| 139 | 'nat64_add_del_static_bib': {'is_add': 1, }, |
| 140 | 'nat64_bib_dump': {'protocol': 255, }, |
| 141 | 'nat64_st_dump': {'protocol': 255, }, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 142 | 'nat66_add_del_interface': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 143 | 'nat66_add_del_static_mapping': {'is_add': 1, }, |
| 144 | 'nat_det_add_del_map': {'is_add': 1, }, |
| 145 | 'nat_ha_resync': {'want_resync_event': 1, }, |
| 146 | 'nat_ha_set_failover': {'refresh': 10, }, |
| 147 | 'nat_ha_set_listener': {'path_mtu': 512, }, |
| 148 | 'nat_ipfix_enable_disable': {'domain_id': 1, 'src_port': 4739, |
| 149 | 'enable': 1, }, |
| 150 | 'nat_set_mss_clamping': {'mss_value': 1500, }, |
| 151 | 'nat_set_reass': {'timeout': 2, 'max_reass': 1024, 'max_frag': 5, }, |
| 152 | 'nat_set_timeouts': {'udp': 300, 'tcp_established': 7440, |
| 153 | 'tcp_transitory': 240, 'icmp': 60, }, |
| 154 | 'output_acl_set_interface': {'ip4_table_index': 4294967295, |
| 155 | 'ip6_table_index': 4294967295, |
| 156 | 'l2_table_index': 4294967295, }, |
| 157 | 'pppoe_add_del_session': {'is_add': 1, }, |
| 158 | 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, }, |
| 159 | 'proxy_arp_add_del': {'is_add': 1, }, |
| 160 | 'proxy_arp_intfc_enable_disable': {'is_enable': 1, }, |
| 161 | 'punt_socket_register': {'protocol': 17, 'header_version': 1, |
| 162 | 'is_ip4': 1, }, |
| 163 | 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, }, |
| 164 | 'punt_socket_dump': {'is_ip6': 1, }, |
| 165 | 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1, |
| 166 | 'proto': 1, }, |
| 167 | 'set_ipfix_exporter': {'collector_port': 4739, }, |
| 168 | 'sr_localsid_add_del': {'sw_if_index': 4294967295, }, |
| 169 | 'sr_policy_add': {'weight': 1, 'is_encap': 1, }, |
| 170 | 'svs_enable_disable': {'is_enable': 1, }, |
| 171 | 'svs_route_add_del': {'is_add': 1, }, |
| 172 | 'svs_table_add_del': {'is_add': 1, }, |
| 173 | 'sw_interface_add_del_address': {'is_add': 1, }, |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 174 | 'sw_interface_dump': {'sw_if_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 175 | 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295, |
| 176 | 'pref_lifetime': 4294967295, }, |
| 177 | 'sw_interface_set_ip_directed_broadcast': {'enable': 1, }, |
| 178 | 'sw_interface_set_l2_bridge': {'enable': 1, }, |
| 179 | 'sw_interface_set_mpls_enable': {'enable': 1, }, |
| 180 | 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], }, |
| 181 | 'sw_interface_set_unnumbered': {'is_add': 1, }, |
| 182 | 'sw_interface_span_enable_disable': {'state': 1, }, |
| 183 | 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 184 | 'decap_next_index': 4294967295, |
| 185 | 'instance': 4294967295, }, |
| 186 | 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 187 | 'instance': 4294967295, }, |
| 188 | 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, }, |
| 189 | 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 190 | 'protocol': 3, }, |
| 191 | 'want_bfd_events': {'enable_disable': 1, }, |
| 192 | 'want_dhcp6_pd_reply_events': {'enable_disable': 1, }, |
| 193 | 'want_dhcp6_reply_events': {'enable_disable': 1, }, |
| 194 | 'want_igmp_events': {'enable': 1, }, |
| 195 | 'want_interface_events': {'enable_disable': 1, }, |
| 196 | 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', }, |
| 197 | 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', }, |
| 198 | 'want_ip6_ra_events': {'enable_disable': 1, }, |
| 199 | 'want_l2_macs_events': {'enable_disable': 1, }, |
| 200 | } |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 201 | |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 202 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 203 | class UnexpectedApiReturnValueError(Exception): |
| 204 | """ exception raised when the API return value is unexpected """ |
| 205 | pass |
| 206 | |
| 207 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 208 | class VppPapiProvider(object): |
| 209 | """VPP-api provider using vpp-papi |
| 210 | |
| 211 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | """ |
| 213 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 214 | _zero, _negative = range(2) |
| 215 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 216 | def __init__(self, name, shm_prefix, test_class, read_timeout): |
Paul Vinciguerra | 895e2f8 | 2019-01-08 20:37:40 -0800 | [diff] [blame] | 217 | self.hook = Hook(test_class) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 218 | self.name = name |
| 219 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 220 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 221 | self._expect_api_retval = self._zero |
| 222 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 223 | |
Klement Sekera | b8c72a4 | 2018-11-08 11:21:39 +0100 | [diff] [blame] | 224 | install_dir = os.getenv('VPP_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 225 | |
Paul Vinciguerra | 04575c5 | 2019-01-13 10:26:05 -0800 | [diff] [blame] | 226 | # Vapi requires 'VPP_API_DIR', not set when run from Makefile. |
| 227 | if 'VPP_API_DIR' not in os.environ: |
| 228 | os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH') |
| 229 | |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 230 | use_socket = False |
| 231 | try: |
| 232 | if os.environ['SOCKET'] == '1': |
| 233 | use_socket = True |
| 234 | except: |
| 235 | pass |
Paul Vinciguerra | 04575c5 | 2019-01-13 10:26:05 -0800 | [diff] [blame] | 236 | self.vpp = VPP(logger=test_class.logger, |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 237 | read_timeout=read_timeout, |
| 238 | use_socket=use_socket, |
| 239 | server_address=test_class.api_sock) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 240 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 241 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 242 | def __enter__(self): |
| 243 | return self |
| 244 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 245 | def assert_negative_api_retval(self): |
| 246 | """ Expect API failure - used with with, e.g.: |
| 247 | with self.vapi.assert_negative_api_retval(): |
| 248 | self.vapi.<api call expected to fail> |
| 249 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 250 | self._expect_stack.append(self._expect_api_retval) |
| 251 | self._expect_api_retval = self._negative |
| 252 | return self |
| 253 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 254 | def assert_zero_api_retval(self): |
| 255 | """ Expect API success - used with with, e.g.: |
| 256 | with self.vapi.assert_negative_api_retval(): |
| 257 | self.vapi.<api call expected to succeed> |
| 258 | |
| 259 | note: this is useful only inside another with block |
| 260 | as success is the default expected value |
| 261 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 262 | self._expect_stack.append(self._expect_api_retval) |
| 263 | self._expect_api_retval = self._zero |
| 264 | return self |
| 265 | |
| 266 | def __exit__(self, exc_type, exc_value, traceback): |
| 267 | self._expect_api_retval = self._expect_stack.pop() |
| 268 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 269 | def register_hook(self, hook): |
| 270 | """Replace hook registration with new hook |
| 271 | |
| 272 | :param hook: |
| 273 | |
| 274 | """ |
| 275 | self.hook = hook |
| 276 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 277 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 278 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 279 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 280 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 281 | return e |
| 282 | |
| 283 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 284 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 285 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 286 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 287 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 288 | else: |
| 289 | self.test_class.logger.debug("Expecting event within %ss", |
| 290 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 291 | if self._events: |
| 292 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 293 | limit = time.time() + timeout |
| 294 | while time.time() < limit: |
| 295 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 296 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 297 | if name and type(e).__name__ != name: |
| 298 | raise Exception( |
| 299 | "Unexpected event received: %s, expected: %s" % |
| 300 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 301 | self.test_class.logger.debug("Returning event %s:%s" % |
| 302 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 303 | return e |
Paul Vinciguerra | 0f6602c | 2019-03-10 09:10:54 -0700 | [diff] [blame] | 304 | self.test_class.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 305 | raise Exception("Event did not occur within timeout") |
| 306 | |
| 307 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 308 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 309 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 310 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 311 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 312 | self._events.append(event) |
| 313 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 314 | def factory(self, name, apifn): |
| 315 | def f(*a, **ka): |
| 316 | fields = apifn._func.msg.fields |
| 317 | |
| 318 | # add positional and kw arguments |
| 319 | d = ka |
| 320 | for i, o in enumerate(fields[3:]): |
| 321 | try: |
| 322 | d[o] = a[i] |
| 323 | except: |
| 324 | break |
| 325 | |
| 326 | # Default override |
| 327 | if name in defaultmapping: |
| 328 | for k, v in iteritems(defaultmapping[name]): |
| 329 | if k in d: |
| 330 | continue |
| 331 | d[k] = v |
| 332 | return self.api(apifn, d) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 333 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 334 | return f |
| 335 | |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 336 | def __getattribute__(self, name): |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 337 | try: |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 338 | method = super(VppPapiProvider, self).__getattribute__(name) |
| 339 | except AttributeError: |
| 340 | method = self.factory(name, getattr(self.papi, name)) |
| 341 | # lazily load the method so we don't need to call factory |
| 342 | # again for this name. |
| 343 | setattr(self, name, method) |
| 344 | return method |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 345 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 346 | def connect(self): |
| 347 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 348 | self.vpp.connect(self.name, self.shm_prefix) |
| 349 | self.papi = self.vpp.api |
| 350 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 351 | |
| 352 | def disconnect(self): |
| 353 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 354 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 355 | |
| 356 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 357 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 358 | Call the appropriate hooks before and after the API call |
| 359 | |
| 360 | :param api_fn: API function to call |
| 361 | :param api_args: tuple of API function arguments |
| 362 | :param expected_retval: Expected return value (Default value = 0) |
| 363 | :returns: reply from the API |
| 364 | |
| 365 | """ |
| 366 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 367 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 368 | if self._expect_api_retval == self._negative: |
| 369 | if hasattr(reply, 'retval') and reply.retval >= 0: |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 370 | msg = "API call passed unexpectedly: expected negative " \ |
| 371 | "return value instead of %d in %s" % \ |
| 372 | (reply.retval, moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 373 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 374 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 375 | elif self._expect_api_retval == self._zero: |
| 376 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 377 | msg = "API call failed, expected %d return value instead " \ |
| 378 | "of %d in %s" % (expected_retval, reply.retval, |
| 379 | moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 380 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 381 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 382 | else: |
| 383 | raise Exception("Internal error, unexpected value for " |
| 384 | "self._expect_api_retval %s" % |
| 385 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 386 | self.hook.after_api(api_fn.__name__, api_args) |
| 387 | return reply |
| 388 | |
| 389 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 390 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 391 | |
| 392 | :param cli: CLI to execute |
| 393 | :returns: CLI output |
| 394 | |
| 395 | """ |
| 396 | self.hook.before_cli(cli) |
| 397 | cli += '\n' |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 398 | r = self.papi.cli_inband(cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 399 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 400 | if hasattr(r, 'reply'): |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 401 | return r.reply |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 402 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 403 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 404 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 405 | |
| 406 | :param cli: CLI to execute |
| 407 | :returns: CLI output |
| 408 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 409 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 410 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 411 | def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"): |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 412 | return self.api(self.papi.want_ip4_arp_events, |
| 413 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 414 | 'ip': ip, |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 415 | 'pid': os.getpid(), }) |
| 416 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 417 | def want_ip6_nd_events(self, enable_disable=1, ip="::"): |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 418 | return self.api(self.papi.want_ip6_nd_events, |
| 419 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 420 | 'ip': ip, |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 421 | 'pid': os.getpid(), }) |
| 422 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 423 | def want_ip6_ra_events(self, enable_disable=1): |
| 424 | return self.api(self.papi.want_ip6_ra_events, |
| 425 | {'enable_disable': enable_disable, |
| 426 | 'pid': os.getpid(), }) |
| 427 | |
| 428 | def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120, |
| 429 | mrc=0, mrd=0): |
| 430 | return self.api(self.papi.ip6nd_send_router_solicitation, |
| 431 | {'irt': irt, |
| 432 | 'mrt': mrt, |
| 433 | 'mrc': mrc, |
| 434 | 'mrd': mrd, |
| 435 | 'sw_if_index': sw_if_index}) |
| 436 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 437 | def want_interface_events(self, enable_disable=1): |
| 438 | return self.api(self.papi.want_interface_events, |
| 439 | {'enable_disable': enable_disable, |
| 440 | 'pid': os.getpid(), }) |
| 441 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 442 | def want_l2_macs_events(self, enable_disable=1, scan_delay=0, |
| 443 | max_macs_in_event=0, learn_limit=0): |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 444 | return self.api(self.papi.want_l2_macs_events, |
| 445 | {'enable_disable': enable_disable, |
| 446 | 'scan_delay': scan_delay, |
| 447 | 'max_macs_in_event': max_macs_in_event, |
| 448 | 'learn_limit': learn_limit, |
| 449 | 'pid': os.getpid(), }) |
| 450 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 451 | def want_dhcp6_reply_events(self, enable_disable=1): |
| 452 | return self.api(self.papi.want_dhcp6_reply_events, |
| 453 | {'enable_disable': enable_disable, |
| 454 | 'pid': os.getpid()}) |
| 455 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 456 | def want_dhcp6_pd_reply_events(self, enable_disable=1): |
| 457 | return self.api(self.papi.want_dhcp6_pd_reply_events, |
| 458 | {'enable_disable': enable_disable, |
| 459 | 'pid': os.getpid()}) |
| 460 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 461 | def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 462 | prefixes, server_index=0xFFFFFFFF, |
| 463 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 464 | ): |
| 465 | return self.api(self.papi.dhcp6_pd_send_client_message, |
| 466 | {'sw_if_index': sw_if_index, |
| 467 | 'server_index': server_index, |
| 468 | 'irt': irt, |
| 469 | 'mrt': mrt, |
| 470 | 'mrc': mrc, |
| 471 | 'mrd': mrd, |
| 472 | 'stop': stop, |
| 473 | 'msg_type': msg_type, |
| 474 | 'T1': T1, |
| 475 | 'T2': T2, |
| 476 | 'n_prefixes': len(prefixes), |
| 477 | 'prefixes': prefixes}) |
| 478 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 479 | def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='', |
| 480 | enable=1): |
| 481 | return self.api(self.papi.dhcp6_client_enable_disable, |
| 482 | {'sw_if_index': sw_if_index, |
| 483 | 'enable': enable}) |
| 484 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 485 | def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='', |
| 486 | enable=1): |
| 487 | return self.api(self.papi.dhcp6_pd_client_enable_disable, |
| 488 | {'sw_if_index': sw_if_index, |
| 489 | 'prefix_group': prefix_group, |
| 490 | 'enable': enable}) |
| 491 | |
| 492 | def ip6_add_del_address_using_prefix(self, sw_if_index, address, |
| 493 | prefix_length, prefix_group, |
| 494 | is_add=1): |
| 495 | return self.api(self.papi.ip6_add_del_address_using_prefix, |
| 496 | {'sw_if_index': sw_if_index, |
| 497 | 'prefix_group': prefix_group, |
| 498 | 'address': address, |
| 499 | 'prefix_length': prefix_length, |
| 500 | 'is_add': is_add}) |
| 501 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 502 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 503 | return self.api(self.papi.sw_interface_set_mac_address, |
| 504 | {'sw_if_index': sw_if_index, |
| 505 | 'mac_address': mac}) |
| 506 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 507 | def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 508 | """Create p2p ethernet subinterface |
| 509 | |
| 510 | :param sw_if_index: main (parent) interface |
| 511 | :param remote_mac: client (remote) mac address |
| 512 | |
| 513 | """ |
| 514 | return self.api( |
| 515 | self.papi.p2p_ethernet_add, |
| 516 | {'parent_if_index': sw_if_index, |
| 517 | 'remote_mac': remote_mac, |
| 518 | 'subif_id': subif_id}) |
| 519 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 520 | def p2p_ethernet_del(self, sw_if_index, remote_mac): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 521 | """Delete p2p ethernet subinterface |
| 522 | |
| 523 | :param sw_if_index: main (parent) interface |
| 524 | :param remote_mac: client (remote) mac address |
| 525 | |
| 526 | """ |
| 527 | return self.api( |
| 528 | self.papi.p2p_ethernet_del, |
| 529 | {'parent_if_index': sw_if_index, |
| 530 | 'remote_mac': remote_mac}) |
| 531 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 532 | def create_vlan_subif(self, sw_if_index, vlan): |
| 533 | """ |
| 534 | |
| 535 | :param vlan: |
| 536 | :param sw_if_index: |
| 537 | |
| 538 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 539 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 540 | {'sw_if_index': sw_if_index, |
| 541 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 542 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 543 | def create_loopback(self, mac=''): |
| 544 | """ |
| 545 | |
| 546 | :param mac: (Optional) |
| 547 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 548 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 549 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 550 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 551 | def ip_neighbor_add_del(self, |
| 552 | sw_if_index, |
| 553 | mac_address, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 554 | ip_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 555 | is_add=1, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 556 | flags=0): |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 557 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 558 | |
| 559 | :param sw_if_index: |
| 560 | :param mac_address: |
| 561 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 562 | :param is_add: (Default value = 1) |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 563 | :param flags: (Default value = 0/NONE) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 564 | """ |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 565 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 566 | self.papi.ip_neighbor_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 567 | { |
| 568 | 'is_add': is_add, |
| 569 | 'neighbor': { |
| 570 | 'sw_if_index': sw_if_index, |
| 571 | 'flags': flags, |
| 572 | 'mac_address': mac_address, |
| 573 | 'ip_address': ip_address |
| 574 | } |
| 575 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 576 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 577 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 578 | def proxy_arp_add_del(self, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 579 | low, |
| 580 | hi, |
| 581 | table_id=0, |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 582 | is_add=1): |
| 583 | """ Config Proxy Arp Range. |
| 584 | |
| 585 | :param low_address: Start address in the rnage to Proxy for |
| 586 | :param hi_address: End address in the rnage to Proxy for |
| 587 | :param vrf_id: The VRF/table in which to proxy |
| 588 | """ |
| 589 | |
| 590 | return self.api( |
| 591 | self.papi.proxy_arp_add_del, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 592 | {'proxy': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 593 | { |
| 594 | 'table_id': table_id, |
| 595 | 'low': low, |
| 596 | 'hi': hi, |
| 597 | }, |
| 598 | 'is_add': is_add}) |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 599 | |
| 600 | def proxy_arp_intfc_enable_disable(self, |
| 601 | sw_if_index, |
| 602 | is_enable=1): |
| 603 | """ Enable/Disable an interface for proxy ARP requests |
| 604 | |
| 605 | :param sw_if_index: Interface |
| 606 | :param enable_disable: Enable/Disable |
| 607 | """ |
| 608 | |
| 609 | return self.api( |
| 610 | self.papi.proxy_arp_intfc_enable_disable, |
| 611 | {'sw_if_index': sw_if_index, |
| 612 | 'enable_disable': is_enable |
| 613 | } |
| 614 | ) |
| 615 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 616 | def gre_tunnel_add_del(self, |
| 617 | src, |
| 618 | dst, |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 619 | outer_fib_id=0, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 620 | tunnel_type=0, |
| 621 | instance=0xFFFFFFFF, |
| 622 | session_id=0, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 623 | is_add=1): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 624 | """ Add a GRE tunnel |
| 625 | |
| 626 | :param src_address: |
| 627 | :param dst_address: |
| 628 | :param outer_fib_id: (Default value = 0) |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 629 | :param tunnel_type: (Default value = 0) |
| 630 | :param instance: (Default value = 0xFFFFFFFF) |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 631 | :param session_id: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 632 | :param is_add: (Default value = 1) |
| 633 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 634 | """ |
| 635 | |
| 636 | return self.api( |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 637 | self.papi.gre_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 638 | {'is_add': is_add, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 639 | 'tunnel': |
| 640 | { |
| 641 | 'type': tunnel_type, |
| 642 | 'instance': instance, |
| 643 | 'src': src, |
| 644 | 'dst': dst, |
| 645 | 'outer_fib_id': outer_fib_id, |
| 646 | 'session_id': session_id} |
| 647 | } |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 648 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 649 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 650 | def udp_encap_add(self, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 651 | src_ip, |
| 652 | dst_ip, |
| 653 | src_port, |
| 654 | dst_port, |
| 655 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 656 | """ Add a GRE tunnel |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 657 | :param src_ip: |
| 658 | :param dst_ip: |
| 659 | :param src_port: |
| 660 | :param dst_port: |
| 661 | :param outer_fib_id: (Default value = 0) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 662 | """ |
| 663 | |
| 664 | return self.api( |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 665 | self.papi.udp_encap_add, |
| 666 | { |
| 667 | 'udp_encap': { |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 668 | 'src_ip': src_ip, |
| 669 | 'dst_ip': dst_ip, |
| 670 | 'src_port': src_port, |
| 671 | 'dst_port': dst_port, |
| 672 | 'table_id': table_id |
| 673 | } |
| 674 | }) |
| 675 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 676 | def mpls_table_add_del( |
| 677 | self, |
| 678 | table_id, |
| 679 | is_add=1): |
| 680 | """ |
| 681 | |
| 682 | :param table_id |
| 683 | :param is_add: (Default value = 1) |
| 684 | |
| 685 | """ |
| 686 | |
| 687 | return self.api( |
| 688 | self.papi.mpls_table_add_del, |
| 689 | {'mt_table_id': table_id, |
| 690 | 'mt_is_add': is_add}) |
| 691 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 692 | def mpls_ip_bind_unbind( |
| 693 | self, |
| 694 | label, |
| 695 | dst_address, |
| 696 | dst_address_length, |
| 697 | table_id=0, |
| 698 | ip_table_id=0, |
| 699 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 700 | is_bind=1): |
| 701 | """ |
| 702 | """ |
| 703 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 704 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 705 | {'mb_mpls_table_id': table_id, |
| 706 | 'mb_label': label, |
| 707 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 708 | 'mb_is_bind': is_bind, |
| 709 | 'mb_is_ip4': is_ip4, |
| 710 | 'mb_address_length': dst_address_length, |
| 711 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 712 | |
| 713 | def mpls_tunnel_add_del( |
| 714 | self, |
| 715 | tun_sw_if_index, |
| 716 | next_hop_proto_is_ip4, |
| 717 | next_hop_address, |
| 718 | next_hop_sw_if_index=0xFFFFFFFF, |
| 719 | next_hop_table_id=0, |
| 720 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 721 | next_hop_n_out_labels=0, |
| 722 | next_hop_out_label_stack=[], |
| 723 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 724 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 725 | l2_only=0, |
| 726 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 727 | """ |
| 728 | |
| 729 | :param dst_address_length: |
| 730 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 731 | :param dst_address: |
| 732 | :param next_hop_address: |
| 733 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 734 | :param vrf_id: (Default value = 0) |
| 735 | :param lookup_in_vrf: (Default value = 0) |
| 736 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 737 | :param is_add: (Default value = 1) |
| 738 | :param is_drop: (Default value = 0) |
| 739 | :param is_ipv6: (Default value = 0) |
| 740 | :param is_local: (Default value = 0) |
| 741 | :param is_classify: (Default value = 0) |
| 742 | :param is_multipath: (Default value = 0) |
| 743 | :param is_resolve_host: (Default value = 0) |
| 744 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 745 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 746 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 747 | |
| 748 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 749 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 750 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 751 | {'mt_sw_if_index': tun_sw_if_index, |
| 752 | 'mt_is_add': is_add, |
| 753 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 754 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 755 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 756 | 'mt_next_hop_weight': next_hop_weight, |
| 757 | 'mt_next_hop': next_hop_address, |
| 758 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 759 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 760 | 'mt_next_hop_table_id': next_hop_table_id, |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 761 | 'mt_next_hop_via_label': next_hop_via_label, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 762 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 763 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 764 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 765 | self, |
| 766 | sw_if_index, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 767 | is_add=1, |
| 768 | flags=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 769 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 770 | |
| 771 | :param sw_if_index: Software index of the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 772 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 773 | :param flags: NAT_IS_INSIDE if inside else outside |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 774 | """ |
| 775 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 776 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 777 | {'is_add': is_add, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 778 | 'flags': flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 779 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 780 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 781 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 782 | self, |
| 783 | sw_if_index, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 784 | is_add=1, |
| 785 | flags=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 786 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 787 | |
| 788 | :param sw_if_index: Software index of the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 789 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 790 | :param flags: NAT_IS_INSIDE if inside else outside |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 791 | """ |
| 792 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 793 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 794 | {'is_add': is_add, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 795 | 'flags': flags, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 796 | 'sw_if_index': sw_if_index}) |
| 797 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 798 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 799 | self, |
| 800 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 801 | external_ip=0, |
| 802 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 803 | local_port=0, |
| 804 | external_port=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 805 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 806 | protocol=0, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 807 | is_add=1, |
| 808 | flags=0, |
| 809 | tag=""): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 810 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 811 | |
| 812 | :param local_ip: Local IP address |
| 813 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 814 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 815 | :param local_port: Local port number (Default value = 0) |
| 816 | :param external_port: External port number (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 817 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 818 | :param protocol: IP protocol (Default value = 0) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 819 | :param flags: NAT configuration flags |
Ole Trøan | 89fec71 | 2019-04-23 12:38:35 +0000 | [diff] [blame] | 820 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 821 | :param tag: Opaque string tag |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 822 | """ |
| 823 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 824 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 825 | {'is_add': is_add, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 826 | 'flags': flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 827 | 'local_ip_address': local_ip, |
| 828 | 'external_ip_address': external_ip, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 829 | 'protocol': protocol, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 830 | 'local_port': local_port, |
| 831 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 832 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 833 | 'vrf_id': vrf_id, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 834 | 'tag': tag}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 835 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 836 | def nat44_add_del_identity_mapping( |
| 837 | self, |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 838 | ip=b'0', |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 839 | sw_if_index=0xFFFFFFFF, |
| 840 | port=0, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 841 | flags=0, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 842 | vrf_id=0, |
| 843 | protocol=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 844 | tag='', |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 845 | is_add=1): |
| 846 | """Add/delete NAT44 identity mapping |
| 847 | |
| 848 | :param ip: IP address (Default value = 0) |
| 849 | :param sw_if_index: Interface instead of IP address |
| 850 | :param port: Port number (Default value = 0) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 851 | :param flags: NAT configuration flags (NAT_IS_ADDR_ONLY) |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 852 | :param vrf_id: VRF ID |
| 853 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 854 | :param tag: Opaque string tag |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 855 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 856 | """ |
| 857 | return self.api( |
| 858 | self.papi.nat44_add_del_identity_mapping, |
| 859 | {'is_add': is_add, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 860 | 'flags': flags, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 861 | 'ip_address': ip, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 862 | 'protocol': protocol, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 863 | 'port': port, |
| 864 | 'sw_if_index': sw_if_index, |
| 865 | 'vrf_id': vrf_id, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 866 | 'tag': tag}) |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 867 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 868 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 869 | self, |
| 870 | first_ip_address, |
| 871 | last_ip_address, |
| 872 | is_add=1, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 873 | vrf_id=0xFFFFFFFF, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 874 | flags=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 875 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 876 | |
| 877 | :param first_ip_address: First IP address |
| 878 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 879 | :param vrf_id: VRF id for the address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 880 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 881 | :param flags: NAT configuration flags (NAT_IS_TWICE_NAT) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 882 | """ |
| 883 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 884 | self.papi.nat44_add_del_address_range, |
| 885 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 886 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 887 | 'vrf_id': vrf_id, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 888 | 'is_add': is_add, |
| 889 | 'flags': flags}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 890 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 891 | def nat44_add_del_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 892 | self, |
| 893 | sw_if_index, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 894 | flags=0, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 895 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 896 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 897 | |
| 898 | :param sw_if_index: Software index of the interface |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 899 | :param flags: NAT configuration flags (NAT_IS_TWICE_NAT) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 900 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 901 | """ |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 902 | return self.api( |
| 903 | self.papi.nat44_add_del_interface_addr, |
| 904 | {'is_add': is_add, |
| 905 | 'sw_if_index': sw_if_index, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 906 | 'flags': flags}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 907 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 908 | def nat44_add_del_lb_static_mapping( |
| 909 | self, |
| 910 | external_addr, |
| 911 | external_port, |
| 912 | protocol, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 913 | tag='', |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 914 | affinity=0, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 915 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 916 | locals=[], |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 917 | flags=0, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 918 | is_add=1): |
| 919 | """Add/delete NAT44 load balancing static mapping |
| 920 | |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 921 | :param tag: Opaque string tag |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 922 | :param affinity: if 0 disabled, otherwise client IP affinity timeout |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 923 | :param flags: NAT configuration flags (NAT_IS_TWICE_NAT) |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 924 | :param is_add - 1 if add, 0 if delete |
| 925 | """ |
| 926 | return self.api( |
| 927 | self.papi.nat44_add_del_lb_static_mapping, |
| 928 | {'is_add': is_add, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 929 | 'flags': flags, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 930 | 'external_addr': external_addr, |
| 931 | 'external_port': external_port, |
| 932 | 'protocol': protocol, |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 933 | 'affinity': affinity, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 934 | 'local_num': local_num, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 935 | 'locals': locals, |
| 936 | 'tag': tag}) |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 937 | |
Matus Fabian | b686508 | 2018-12-06 03:11:09 -0800 | [diff] [blame] | 938 | def nat44_lb_static_mapping_add_del_local( |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 939 | self, |
| 940 | external_addr, |
| 941 | external_port, |
| 942 | local_addr, |
| 943 | local_port, |
| 944 | protocol, |
| 945 | probability, |
| 946 | vrf_id=0, |
| 947 | is_add=1): |
Matus Fabian | b686508 | 2018-12-06 03:11:09 -0800 | [diff] [blame] | 948 | """Add/delete NAT44 load-balancing static mapping rule backend |
| 949 | |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 950 | :param external_addr: external IPv4 address of the service |
Matus Fabian | b686508 | 2018-12-06 03:11:09 -0800 | [diff] [blame] | 951 | :param external_port: external L4 port number of the service |
| 952 | :param local_addr: IPv4 address of the internal node |
| 953 | :param local_port: L4 port number of the internal node |
| 954 | :param protocol: IP protocol number |
| 955 | :param probability: probability of the internal node |
| 956 | :param vrf_id: VRF id of the internal node |
| 957 | :param is_add: 1 if add, 0 if delete |
| 958 | """ |
| 959 | return self.api( |
| 960 | self.papi.nat44_lb_static_mapping_add_del_local, |
| 961 | {'is_add': is_add, |
| 962 | 'external_addr': external_addr, |
| 963 | 'external_port': external_port, |
| 964 | 'local': { |
| 965 | 'addr': local_addr, |
| 966 | 'port': local_port, |
| 967 | 'probability': probability, |
| 968 | 'vrf_id': vrf_id}, |
| 969 | 'protocol': protocol}) |
| 970 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 971 | def nat44_del_session( |
| 972 | self, |
| 973 | addr, |
| 974 | port, |
| 975 | protocol, |
| 976 | vrf_id=0, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 977 | flags=0, |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 978 | ext_host_address=None, |
| 979 | ext_host_port=0): |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 980 | """Delete NAT44 session |
| 981 | |
| 982 | :param addr: IPv4 address |
| 983 | :param por: port number |
| 984 | :param protocol: IP protocol number |
| 985 | :param vrf_id: VRF ID |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 986 | :param flags: NAT configuration flags (NAT_IS_INSIDE) |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 987 | :param ext_host_address: external host IPv4 address |
| 988 | :param ext_host_port: external host port |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 989 | """ |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 990 | return self.api( |
| 991 | self.papi.nat44_del_session, |
| 992 | {'address': addr, |
| 993 | 'protocol': protocol, |
| 994 | 'port': port, |
| 995 | 'vrf_id': vrf_id, |
| 996 | 'flags': flags, |
| 997 | 'ext_host_address': ext_host_address, |
| 998 | 'ext_host_port': ext_host_port}) |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 999 | |
Juraj Sloboda | 7b92979 | 2017-11-23 13:20:48 +0100 | [diff] [blame] | 1000 | def nat44_forwarding_enable_disable( |
| 1001 | self, |
| 1002 | enable): |
| 1003 | """Enable/disable forwarding for NAT44 |
| 1004 | |
| 1005 | :param enable: 1 for enable, 0 for disable |
| 1006 | """ |
| 1007 | return self.api( |
| 1008 | self.papi.nat44_forwarding_enable_disable, |
| 1009 | {'enable': enable}) |
| 1010 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1011 | def nat_det_map_dump(self): |
| 1012 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1013 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1014 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1015 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1016 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1017 | |
Matus Fabian | bb4e022 | 2018-09-13 02:36:25 -0700 | [diff] [blame] | 1018 | def nat_set_mss_clamping(self, enable=0, mss_value=1500): |
| 1019 | """Set TCP MSS rewriting configuration |
| 1020 | |
| 1021 | :param enable: disable(0)/enable(1) MSS rewriting feature |
| 1022 | :param mss_value: MSS value to be used for MSS rewriting |
| 1023 | """ |
| 1024 | return self.api( |
| 1025 | self.papi.nat_set_mss_clamping, |
| 1026 | {'enable': enable, 'mss_value': mss_value}) |
| 1027 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1028 | def nat64_add_del_static_bib( |
| 1029 | self, |
| 1030 | in_ip, |
| 1031 | out_ip, |
| 1032 | in_port, |
| 1033 | out_port, |
| 1034 | protocol, |
| 1035 | vrf_id=0, |
| 1036 | is_add=1): |
| 1037 | """Add/delete S-NAT static BIB entry |
| 1038 | |
| 1039 | :param in_ip: Inside IPv6 address |
| 1040 | :param out_ip: Outside IPv4 address |
| 1041 | :param in_port: Inside port number |
| 1042 | :param out_port: Outside port number |
| 1043 | :param protocol: IP protocol |
| 1044 | :param vrf_id: VRF ID (Default value = 0) |
| 1045 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1046 | """ |
| 1047 | return self.api( |
| 1048 | self.papi.nat64_add_del_static_bib, |
| 1049 | {'i_addr': in_ip, |
| 1050 | 'o_addr': out_ip, |
| 1051 | 'i_port': in_port, |
| 1052 | 'o_port': out_port, |
| 1053 | 'vrf_id': vrf_id, |
| 1054 | 'proto': protocol, |
| 1055 | 'is_add': is_add}) |
| 1056 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1057 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1058 | """Dump NAT64 BIB |
| 1059 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1060 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1061 | :returns: Dictionary of NAT64 BIB entries |
| 1062 | """ |
| 1063 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1064 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1065 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1066 | """Dump NAT64 session table |
| 1067 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1068 | :param protocol: IP protocol (Default value = 255, all STs) |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1069 | :returns: Dictionary of NAT64 session table entries |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1070 | """ |
| 1071 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1072 | |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 1073 | def nat64_add_del_prefix(self, prefix, vrf_id=0, is_add=1): |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1074 | """Add/del NAT64 prefix |
| 1075 | |
| 1076 | :param prefix: NAT64 prefix |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1077 | :param vrf_id: VRF id of tenant (Default 0) |
| 1078 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1079 | """ |
| 1080 | return self.api( |
| 1081 | self.papi.nat64_add_del_prefix, |
| 1082 | {'prefix': prefix, |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1083 | 'vrf_id': vrf_id, |
| 1084 | 'is_add': is_add}) |
| 1085 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1086 | def nat64_add_del_interface_addr( |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 1087 | self, |
| 1088 | sw_if_index, |
| 1089 | is_add=1): |
| 1090 | """Add/del NAT64 address from interface |
| 1091 | |
| 1092 | :param sw_if_index: Software index of the interface |
| 1093 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1094 | """ |
| 1095 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 1096 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1097 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1098 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 1099 | """Set DS-Lite AFTR addresses |
| 1100 | |
| 1101 | :param ip4: IPv4 address |
| 1102 | :param ip6: IPv6 address |
| 1103 | """ |
| 1104 | return self.api( |
| 1105 | self.papi.dslite_set_aftr_addr, |
| 1106 | {'ip4_addr': ip4, |
| 1107 | 'ip6_addr': ip6}) |
| 1108 | |
Juraj Sloboda | c5c6a33 | 2018-01-09 16:08:32 +0100 | [diff] [blame] | 1109 | def dslite_set_b4_addr(self, ip6, ip4): |
| 1110 | """Set DS-Lite B4 IPv6 address |
| 1111 | |
| 1112 | :param ip4: IPv4 address |
| 1113 | :param ip6: IPv6 address |
| 1114 | """ |
| 1115 | return self.api( |
| 1116 | self.papi.dslite_set_b4_addr, |
| 1117 | {'ip4_addr': ip4, |
| 1118 | 'ip6_addr': ip6}) |
| 1119 | |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1120 | def nat66_add_del_interface( |
| 1121 | self, |
| 1122 | sw_if_index, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 1123 | flags=0, |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1124 | is_add=1): |
| 1125 | """Enable/disable NAT66 feature on the interface |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 1126 | |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1127 | :param sw_if_index: Index of the interface |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 1128 | :param flags: NAT configuration flags (NAT_IS_INSIDE) |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1129 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1130 | """ |
| 1131 | return self.api( |
| 1132 | self.papi.nat66_add_del_interface, |
Filip Varga | dd1e3e7 | 2019-04-15 18:52:43 +0200 | [diff] [blame] | 1133 | {'is_add': is_add, |
| 1134 | 'flags': flags, |
| 1135 | 'sw_if_index': sw_if_index}) |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1136 | |
| 1137 | def nat66_add_del_static_mapping( |
| 1138 | self, |
| 1139 | in_ip, |
| 1140 | out_ip, |
| 1141 | vrf_id=0, |
| 1142 | is_add=1): |
| 1143 | """Add/delete NAT66 static mapping |
| 1144 | |
| 1145 | :param in_ip: Inside IPv6 address |
| 1146 | :param out_ip: Outside IPv6 address |
| 1147 | :param vrf_id: VRF ID (Default value = 0) |
| 1148 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1149 | """ |
| 1150 | return self.api( |
| 1151 | self.papi.nat66_add_del_static_mapping, |
| 1152 | {'local_ip_address': in_ip, |
| 1153 | 'external_ip_address': out_ip, |
| 1154 | 'vrf_id': vrf_id, |
| 1155 | 'is_add': is_add}) |
| 1156 | |
Matus Fabian | 34931eb | 2019-02-26 09:05:23 -0800 | [diff] [blame] | 1157 | def nat_ha_set_listener(self, addr, port, path_mtu=512): |
| 1158 | """Set HA listener (local settings) |
| 1159 | |
| 1160 | :param addr: local IP4 address |
| 1161 | :param port: local UDP port number |
| 1162 | :param path_mtu: path MTU (Default value = 512) |
| 1163 | """ |
| 1164 | return self.api(self.papi.nat_ha_set_listener, |
| 1165 | {'ip_address': addr, |
| 1166 | 'port': port, |
| 1167 | 'path_mtu': path_mtu}) |
| 1168 | |
| 1169 | def nat_ha_get_listener(self): |
| 1170 | """Get HA listener/local configuration""" |
| 1171 | return self.api(self.papi.nat_ha_get_listener, {}) |
| 1172 | |
| 1173 | def nat_ha_set_failover(self, addr, port, refresh=10): |
| 1174 | """Set HA failover (remote settings) |
| 1175 | |
| 1176 | :param addr: failover IP4 address |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 1177 | :param port: failover UDP port number |
Matus Fabian | 34931eb | 2019-02-26 09:05:23 -0800 | [diff] [blame] | 1178 | :param refresh: number of seconds after which to send session refresh |
| 1179 | """ |
| 1180 | return self.api(self.papi.nat_ha_set_failover, |
| 1181 | {'ip_address': addr, |
| 1182 | 'port': port, |
| 1183 | 'session_refresh_interval': refresh}) |
| 1184 | |
Matus Fabian | 34931eb | 2019-02-26 09:05:23 -0800 | [diff] [blame] | 1185 | def nat_ha_resync(self, want_resync_event=1): |
| 1186 | """Resync HA (resend existing sessions to new failover) |
| 1187 | :param want_resync_event: if non-zero resync completed event sent |
| 1188 | """ |
| 1189 | return self.api(self.papi.nat_ha_resync, |
| 1190 | {'want_resync_event': want_resync_event, |
| 1191 | 'pid': os.getpid()}) |
| 1192 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1193 | def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1194 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1195 | bfd_key_id=None, conf_key_id=None): |
| 1196 | if bfd_key_id is None: |
| 1197 | return self.api(self.papi.bfd_udp_add, |
| 1198 | { |
| 1199 | 'sw_if_index': sw_if_index, |
| 1200 | 'desired_min_tx': desired_min_tx, |
| 1201 | 'required_min_rx': required_min_rx, |
| 1202 | 'local_addr': local_addr, |
| 1203 | 'peer_addr': peer_addr, |
| 1204 | 'is_ipv6': is_ipv6, |
| 1205 | 'detect_mult': detect_mult, |
| 1206 | }) |
| 1207 | else: |
| 1208 | return self.api(self.papi.bfd_udp_add, |
| 1209 | { |
| 1210 | 'sw_if_index': sw_if_index, |
| 1211 | 'desired_min_tx': desired_min_tx, |
| 1212 | 'required_min_rx': required_min_rx, |
| 1213 | 'local_addr': local_addr, |
| 1214 | 'peer_addr': peer_addr, |
| 1215 | 'is_ipv6': is_ipv6, |
| 1216 | 'detect_mult': detect_mult, |
| 1217 | 'is_authenticated': 1, |
| 1218 | 'bfd_key_id': bfd_key_id, |
| 1219 | 'conf_key_id': conf_key_id, |
| 1220 | }) |
| 1221 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1222 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1223 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1224 | return self.api(self.papi.bfd_udp_mod, |
| 1225 | { |
| 1226 | 'sw_if_index': sw_if_index, |
| 1227 | 'desired_min_tx': desired_min_tx, |
| 1228 | 'required_min_rx': required_min_rx, |
| 1229 | 'local_addr': local_addr, |
| 1230 | 'peer_addr': peer_addr, |
| 1231 | 'is_ipv6': is_ipv6, |
| 1232 | 'detect_mult': detect_mult, |
| 1233 | }) |
| 1234 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1235 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1236 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1237 | is_delayed=False): |
| 1238 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1239 | { |
| 1240 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1241 | 'local_addr': local_addr, |
| 1242 | 'peer_addr': peer_addr, |
| 1243 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1244 | 'is_delayed': 1 if is_delayed else 0, |
| 1245 | 'bfd_key_id': bfd_key_id, |
| 1246 | 'conf_key_id': conf_key_id, |
| 1247 | }) |
| 1248 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1249 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1250 | peer_addr, is_ipv6=0): |
| 1251 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1252 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1253 | 'sw_if_index': sw_if_index, |
| 1254 | 'local_addr': local_addr, |
| 1255 | 'peer_addr': peer_addr, |
| 1256 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1257 | }) |
| 1258 | |
| 1259 | def want_bfd_events(self, enable_disable=1): |
| 1260 | return self.api(self.papi.want_bfd_events, { |
| 1261 | 'enable_disable': enable_disable, |
| 1262 | 'pid': os.getpid(), |
| 1263 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1264 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1265 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1266 | return self.api(self.papi.bfd_auth_set_key, { |
| 1267 | 'conf_key_id': conf_key_id, |
| 1268 | 'auth_type': auth_type, |
| 1269 | 'key': key, |
| 1270 | 'key_len': len(key), |
| 1271 | }) |
| 1272 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1273 | def classify_add_del_table( |
| 1274 | self, |
| 1275 | is_add, |
| 1276 | mask, |
| 1277 | match_n_vectors=1, |
| 1278 | table_index=0xFFFFFFFF, |
| 1279 | nbuckets=2, |
| 1280 | memory_size=2097152, |
| 1281 | skip_n_vectors=0, |
| 1282 | next_table_index=0xFFFFFFFF, |
| 1283 | miss_next_index=0xFFFFFFFF, |
| 1284 | current_data_flag=0, |
| 1285 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1286 | """ |
| 1287 | :param is_add: |
| 1288 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1289 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1290 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1291 | :param nbuckets: (Default value = 2) |
| 1292 | :param memory_size: (Default value = 2097152) |
| 1293 | :param skip_n_vectors: (Default value = 0) |
| 1294 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1295 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1296 | :param current_data_flag: (Default value = 0) |
| 1297 | :param current_data_offset: (Default value = 0) |
| 1298 | """ |
| 1299 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 1300 | mask_len = ((len(mask) - 1) / 16 + 1) * 16 |
| 1301 | mask = mask + '\0' * (mask_len - len(mask)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1302 | return self.api( |
| 1303 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1304 | {'is_add': is_add, |
| 1305 | 'table_index': table_index, |
| 1306 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1307 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1308 | 'skip_n_vectors': skip_n_vectors, |
| 1309 | 'match_n_vectors': match_n_vectors, |
| 1310 | 'next_table_index': next_table_index, |
| 1311 | 'miss_next_index': miss_next_index, |
| 1312 | 'current_data_flag': current_data_flag, |
| 1313 | 'current_data_offset': current_data_offset, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 1314 | 'mask_len': mask_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1315 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1316 | |
| 1317 | def classify_add_del_session( |
| 1318 | self, |
| 1319 | is_add, |
| 1320 | table_index, |
| 1321 | match, |
| 1322 | opaque_index=0xFFFFFFFF, |
| 1323 | hit_next_index=0xFFFFFFFF, |
| 1324 | advance=0, |
| 1325 | action=0, |
| 1326 | metadata=0): |
| 1327 | """ |
| 1328 | :param is_add: |
| 1329 | :param table_index: |
| 1330 | :param match: |
| 1331 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1332 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1333 | :param advance: (Default value = 0) |
| 1334 | :param action: (Default value = 0) |
| 1335 | :param metadata: (Default value = 0) |
| 1336 | """ |
| 1337 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 1338 | match_len = ((len(match) - 1) / 16 + 1) * 16 |
| 1339 | match = match + '\0' * (match_len - len(match)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1340 | return self.api( |
| 1341 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1342 | {'is_add': is_add, |
| 1343 | 'table_index': table_index, |
| 1344 | 'hit_next_index': hit_next_index, |
| 1345 | 'opaque_index': opaque_index, |
| 1346 | 'advance': advance, |
| 1347 | 'action': action, |
| 1348 | 'metadata': metadata, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 1349 | 'match_len': match_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1350 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1351 | |
| 1352 | def input_acl_set_interface( |
| 1353 | self, |
| 1354 | is_add, |
| 1355 | sw_if_index, |
| 1356 | ip4_table_index=0xFFFFFFFF, |
| 1357 | ip6_table_index=0xFFFFFFFF, |
| 1358 | l2_table_index=0xFFFFFFFF): |
| 1359 | """ |
| 1360 | :param is_add: |
| 1361 | :param sw_if_index: |
| 1362 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1363 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1364 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1365 | """ |
| 1366 | |
| 1367 | return self.api( |
| 1368 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1369 | {'sw_if_index': sw_if_index, |
| 1370 | 'ip4_table_index': ip4_table_index, |
| 1371 | 'ip6_table_index': ip6_table_index, |
| 1372 | 'l2_table_index': l2_table_index, |
| 1373 | 'is_add': is_add}) |
| 1374 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 1375 | def output_acl_set_interface( |
| 1376 | self, |
| 1377 | is_add, |
| 1378 | sw_if_index, |
| 1379 | ip4_table_index=0xFFFFFFFF, |
| 1380 | ip6_table_index=0xFFFFFFFF, |
| 1381 | l2_table_index=0xFFFFFFFF): |
| 1382 | """ |
| 1383 | :param is_add: |
| 1384 | :param sw_if_index: |
| 1385 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1386 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1387 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1388 | """ |
| 1389 | |
| 1390 | return self.api( |
| 1391 | self.papi.output_acl_set_interface, |
| 1392 | {'sw_if_index': sw_if_index, |
| 1393 | 'ip4_table_index': ip4_table_index, |
| 1394 | 'ip6_table_index': ip6_table_index, |
| 1395 | 'l2_table_index': l2_table_index, |
| 1396 | 'is_add': is_add}) |
| 1397 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1398 | def set_ipfix_exporter( |
| 1399 | self, |
| 1400 | collector_address, |
| 1401 | src_address, |
| 1402 | path_mtu, |
| 1403 | template_interval, |
| 1404 | vrf_id=0, |
| 1405 | collector_port=4739, |
| 1406 | udp_checksum=0): |
| 1407 | return self.api( |
| 1408 | self.papi.set_ipfix_exporter, |
| 1409 | { |
| 1410 | 'collector_address': collector_address, |
| 1411 | 'collector_port': collector_port, |
| 1412 | 'src_address': src_address, |
| 1413 | 'vrf_id': vrf_id, |
| 1414 | 'path_mtu': path_mtu, |
| 1415 | 'template_interval': template_interval, |
| 1416 | 'udp_checksum': udp_checksum, |
| 1417 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1418 | |
| 1419 | def dhcp_proxy_config(self, |
| 1420 | dhcp_server, |
| 1421 | dhcp_src_address, |
| 1422 | rx_table_id=0, |
| 1423 | server_table_id=0, |
| 1424 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1425 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1426 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1427 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1428 | { |
| 1429 | 'rx_vrf_id': rx_table_id, |
| 1430 | 'server_vrf_id': server_table_id, |
| 1431 | 'is_ipv6': is_ipv6, |
| 1432 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1433 | 'dhcp_server': dhcp_server, |
| 1434 | 'dhcp_src_address': dhcp_src_address, |
| 1435 | }) |
| 1436 | |
| 1437 | def dhcp_proxy_set_vss(self, |
| 1438 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1439 | vss_type=255, |
| 1440 | vpn_ascii_id="", |
| 1441 | oui=0, |
| 1442 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1443 | is_add=1, |
| 1444 | is_ip6=0): |
| 1445 | return self.api( |
| 1446 | self.papi.dhcp_proxy_set_vss, |
| 1447 | { |
| 1448 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1449 | 'vss_type': vss_type, |
| 1450 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1451 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1452 | 'vpn_index': vpn_index, |
| 1453 | 'is_add': is_add, |
| 1454 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1455 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1456 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1457 | def dhcp_client_config(self, |
| 1458 | sw_if_index, |
| 1459 | hostname, |
| 1460 | client_id='', |
| 1461 | is_add=1, |
| 1462 | set_broadcast_flag=1, |
| 1463 | want_dhcp_events=0): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1464 | return self.api( |
| 1465 | self.papi.dhcp_client_config, |
| 1466 | { |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1467 | 'is_add': is_add, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1468 | 'client': { |
| 1469 | 'sw_if_index': sw_if_index, |
| 1470 | 'hostname': hostname, |
| 1471 | 'id': client_id, |
| 1472 | 'want_dhcp_event': want_dhcp_events, |
| 1473 | 'set_broadcast_flag': set_broadcast_flag, |
| 1474 | 'pid': os.getpid()} |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1475 | }) |
| 1476 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1477 | def ip_mroute_add_del(self, |
| 1478 | src_address, |
| 1479 | grp_address, |
| 1480 | grp_address_length, |
| 1481 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1482 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1483 | next_hop_sw_if_index, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1484 | next_hop_address, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1485 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1486 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1487 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1488 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1489 | is_add=1, |
| 1490 | is_ipv6=0, |
| 1491 | is_local=0): |
| 1492 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1493 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1494 | """ |
| 1495 | return self.api( |
| 1496 | self.papi.ip_mroute_add_del, |
| 1497 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1498 | 'entry_flags': e_flags, |
| 1499 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1500 | 'table_id': table_id, |
| 1501 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1502 | 'is_add': is_add, |
| 1503 | 'is_ipv6': is_ipv6, |
| 1504 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1505 | 'bier_imp': bier_imp, |
| 1506 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1507 | 'grp_address_length': grp_address_length, |
| 1508 | 'grp_address': grp_address, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1509 | 'src_address': src_address, |
| 1510 | 'nh_address': next_hop_address}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1511 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1512 | def lisp_enable_disable(self, is_enabled): |
| 1513 | return self.api( |
| 1514 | self.papi.lisp_enable_disable, |
| 1515 | { |
| 1516 | 'is_en': is_enabled, |
| 1517 | }) |
| 1518 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1519 | def lisp_add_del_locator_set(self, |
| 1520 | ls_name, |
| 1521 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1522 | return self.api( |
| 1523 | self.papi.lisp_add_del_locator_set, |
| 1524 | { |
| 1525 | 'is_add': is_add, |
| 1526 | 'locator_set_name': ls_name |
| 1527 | }) |
| 1528 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1529 | def lisp_add_del_locator(self, |
| 1530 | ls_name, |
| 1531 | sw_if_index, |
| 1532 | priority=1, |
| 1533 | weight=1, |
| 1534 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1535 | return self.api( |
| 1536 | self.papi.lisp_add_del_locator, |
| 1537 | { |
| 1538 | 'is_add': is_add, |
| 1539 | 'locator_set_name': ls_name, |
| 1540 | 'sw_if_index': sw_if_index, |
| 1541 | 'priority': priority, |
| 1542 | 'weight': weight |
| 1543 | }) |
| 1544 | |
| 1545 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1546 | return self.api( |
| 1547 | self.papi.lisp_locator_dump, |
| 1548 | { |
| 1549 | 'is_index_set': is_index_set, |
| 1550 | 'ls_name': ls_name, |
| 1551 | 'ls_index': ls_index, |
| 1552 | }) |
| 1553 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1554 | def lisp_add_del_local_eid(self, |
| 1555 | ls_name, |
| 1556 | eid_type, |
| 1557 | eid, |
| 1558 | prefix_len, |
| 1559 | vni=0, |
| 1560 | key_id=0, |
| 1561 | key="", |
| 1562 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1563 | return self.api( |
| 1564 | self.papi.lisp_add_del_local_eid, |
| 1565 | { |
| 1566 | 'locator_set_name': ls_name, |
| 1567 | 'is_add': is_add, |
| 1568 | 'eid_type': eid_type, |
| 1569 | 'eid': eid, |
| 1570 | 'prefix_len': prefix_len, |
| 1571 | 'vni': vni, |
| 1572 | 'key_id': key_id, |
| 1573 | 'key': key |
| 1574 | }) |
| 1575 | |
| 1576 | def lisp_eid_table_dump(self, |
| 1577 | eid_set=0, |
| 1578 | prefix_length=0, |
| 1579 | vni=0, |
| 1580 | eid_type=0, |
| 1581 | eid=None, |
| 1582 | filter_opt=0): |
| 1583 | return self.api( |
| 1584 | self.papi.lisp_eid_table_dump, |
| 1585 | { |
| 1586 | 'eid_set': eid_set, |
| 1587 | 'prefix_length': prefix_length, |
| 1588 | 'vni': vni, |
| 1589 | 'eid_type': eid_type, |
| 1590 | 'eid': eid, |
| 1591 | 'filter': filter_opt, |
| 1592 | }) |
| 1593 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1594 | def lisp_add_del_remote_mapping(self, |
| 1595 | eid_type, |
| 1596 | eid, |
| 1597 | eid_prefix_len=0, |
| 1598 | vni=0, |
| 1599 | rlocs=[], |
| 1600 | rlocs_num=0, |
| 1601 | is_src_dst=0, |
| 1602 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1603 | return self.api( |
| 1604 | self.papi.lisp_add_del_remote_mapping, |
| 1605 | { |
| 1606 | 'is_add': is_add, |
| 1607 | 'eid_type': eid_type, |
| 1608 | 'eid': eid, |
| 1609 | 'eid_len': eid_prefix_len, |
| 1610 | 'rloc_num': rlocs_num, |
| 1611 | 'rlocs': rlocs, |
| 1612 | 'vni': vni, |
| 1613 | 'is_src_dst': is_src_dst, |
| 1614 | }) |
| 1615 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1616 | def lisp_add_del_adjacency(self, |
| 1617 | leid, |
| 1618 | reid, |
| 1619 | leid_len, |
| 1620 | reid_len, |
| 1621 | eid_type, |
| 1622 | is_add=1, |
| 1623 | vni=0): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1624 | return self.api( |
| 1625 | self.papi.lisp_add_del_adjacency, |
| 1626 | { |
| 1627 | 'is_add': is_add, |
| 1628 | 'vni': vni, |
| 1629 | 'eid_type': eid_type, |
| 1630 | 'leid': leid, |
| 1631 | 'reid': reid, |
| 1632 | 'leid_len': leid_len, |
| 1633 | 'reid_len': reid_len, |
| 1634 | }) |
| 1635 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 1636 | def gtpu_add_del_tunnel( |
| 1637 | self, |
| 1638 | src_addr, |
| 1639 | dst_addr, |
| 1640 | is_add=1, |
| 1641 | is_ipv6=0, |
| 1642 | mcast_sw_if_index=0xFFFFFFFF, |
| 1643 | encap_vrf_id=0, |
| 1644 | decap_next_index=0xFFFFFFFF, |
| 1645 | teid=0): |
| 1646 | """ |
| 1647 | |
| 1648 | :param is_add: (Default value = 1) |
| 1649 | :param is_ipv6: (Default value = 0) |
| 1650 | :param src_addr: |
| 1651 | :param dst_addr: |
| 1652 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1653 | :param encap_vrf_id: (Default value = 0) |
| 1654 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 1655 | :param teid: (Default value = 0) |
| 1656 | |
| 1657 | """ |
| 1658 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 1659 | {'is_add': is_add, |
| 1660 | 'is_ipv6': is_ipv6, |
| 1661 | 'src_address': src_addr, |
| 1662 | 'dst_address': dst_addr, |
| 1663 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1664 | 'encap_vrf_id': encap_vrf_id, |
| 1665 | 'decap_next_index': decap_next_index, |
| 1666 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1667 | |
| 1668 | def vxlan_gpe_add_del_tunnel( |
| 1669 | self, |
| 1670 | src_addr, |
| 1671 | dst_addr, |
| 1672 | mcast_sw_if_index=0xFFFFFFFF, |
| 1673 | is_add=1, |
| 1674 | is_ipv6=0, |
| 1675 | encap_vrf_id=0, |
| 1676 | decap_vrf_id=0, |
| 1677 | protocol=3, |
| 1678 | vni=0): |
| 1679 | """ |
| 1680 | |
| 1681 | :param local: |
| 1682 | :param remote: |
| 1683 | :param is_add: (Default value = 1) |
| 1684 | :param is_ipv6: (Default value = 0) |
| 1685 | :param encap_vrf_id: (Default value = 0) |
| 1686 | :param decap_vrf_id: (Default value = 0) |
| 1687 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1688 | :param protocol: (Default value = 3) |
| 1689 | :param vni: (Default value = 0) |
| 1690 | |
| 1691 | """ |
| 1692 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 1693 | {'is_add': is_add, |
| 1694 | 'is_ipv6': is_ipv6, |
| 1695 | 'local': src_addr, |
| 1696 | 'remote': dst_addr, |
| 1697 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1698 | 'encap_vrf_id': encap_vrf_id, |
| 1699 | 'decap_vrf_id': decap_vrf_id, |
| 1700 | 'protocol': protocol, |
| 1701 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 1702 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1703 | def vxlan_gbp_tunnel_add_del( |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1704 | self, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1705 | src, |
| 1706 | dst, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1707 | mcast_sw_if_index=0xFFFFFFFF, |
| 1708 | is_add=1, |
| 1709 | is_ipv6=0, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1710 | encap_table_id=0, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1711 | vni=0, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1712 | mode=1, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1713 | instance=0xFFFFFFFF): |
| 1714 | """ |
| 1715 | |
| 1716 | :param dst_addr: |
| 1717 | :param src_addr: |
| 1718 | :param is_add: (Default value = 1) |
| 1719 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1720 | :param encap_table_id: (Default value = 0) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1721 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 1722 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1723 | :param vni: (Default value = 0) |
| 1724 | :param instance: (Default value = 0xFFFFFFFF) |
| 1725 | |
| 1726 | """ |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1727 | return self.api(self.papi.vxlan_gbp_tunnel_add_del, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1728 | {'is_add': is_add, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1729 | 'tunnel': { |
| 1730 | 'src': src, |
| 1731 | 'dst': dst, |
| 1732 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1733 | 'encap_table_id': encap_table_id, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1734 | 'vni': vni, |
Neale Ranns | 4dd4cf4 | 2019-03-27 05:06:47 -0700 | [diff] [blame] | 1735 | 'instance': instance, |
| 1736 | "mode": mode}}) |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1737 | |
| 1738 | def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): |
| 1739 | return self.api(self.papi.vxlan_gbp_tunnel_dump, |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1740 | {'sw_if_index': sw_if_index, |
| 1741 | '_no_type_conversion': True}) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1742 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 1743 | def pppoe_add_del_session( |
| 1744 | self, |
| 1745 | client_ip, |
| 1746 | client_mac, |
| 1747 | session_id=0, |
| 1748 | is_add=1, |
| 1749 | is_ipv6=0, |
| 1750 | decap_vrf_id=0): |
| 1751 | """ |
| 1752 | |
| 1753 | :param is_add: (Default value = 1) |
| 1754 | :param is_ipv6: (Default value = 0) |
| 1755 | :param client_ip: |
| 1756 | :param session_id: (Default value = 0) |
| 1757 | :param client_mac: |
| 1758 | :param decap_vrf_id: (Default value = 0) |
| 1759 | |
| 1760 | """ |
| 1761 | return self.api(self.papi.pppoe_add_del_session, |
| 1762 | {'is_add': is_add, |
| 1763 | 'is_ipv6': is_ipv6, |
| 1764 | 'session_id': session_id, |
| 1765 | 'client_ip': client_ip, |
| 1766 | 'decap_vrf_id': decap_vrf_id, |
| 1767 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1768 | |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 1769 | def sr_mpls_policy_add(self, bsid, weight, type, segments): |
| 1770 | return self.api(self.papi.sr_mpls_policy_add, |
| 1771 | {'bsid': bsid, |
| 1772 | 'weight': weight, |
| 1773 | 'type': type, |
| 1774 | 'n_segments': len(segments), |
| 1775 | 'segments': segments}) |
| 1776 | |
| 1777 | def sr_mpls_policy_del(self, bsid): |
| 1778 | return self.api(self.papi.sr_mpls_policy_del, |
| 1779 | {'bsid': bsid}) |
| 1780 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1781 | def sr_localsid_add_del(self, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1782 | localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1783 | behavior, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1784 | nh_addr4, |
| 1785 | nh_addr6, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1786 | is_del=0, |
| 1787 | end_psp=0, |
| 1788 | sw_if_index=0xFFFFFFFF, |
| 1789 | vlan_index=0, |
| 1790 | fib_table=0, |
| 1791 | ): |
| 1792 | """ Add/del IPv6 SR local-SID. |
| 1793 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1794 | :param localsid: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1795 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 1796 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1797 | :param nh_addr4: |
| 1798 | :param nh_addr6: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1799 | :param is_del: (Default value = 0) |
| 1800 | :param end_psp: (Default value = 0) |
| 1801 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 1802 | :param vlan_index: (Default value = 0) |
| 1803 | :param fib_table: (Default value = 0) |
| 1804 | """ |
| 1805 | return self.api( |
| 1806 | self.papi.sr_localsid_add_del, |
| 1807 | {'is_del': is_del, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1808 | 'localsid': localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1809 | 'end_psp': end_psp, |
| 1810 | 'behavior': behavior, |
| 1811 | 'sw_if_index': sw_if_index, |
| 1812 | 'vlan_index': vlan_index, |
| 1813 | 'fib_table': fib_table, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1814 | 'nh_addr4': nh_addr4, |
| 1815 | 'nh_addr6': nh_addr6 |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1816 | } |
| 1817 | ) |
| 1818 | |
| 1819 | def sr_policy_add( |
| 1820 | self, |
| 1821 | bsid_addr, |
| 1822 | weight=1, |
| 1823 | is_encap=1, |
| 1824 | type=0, |
| 1825 | fib_table=0, |
| 1826 | n_segments=0, |
| 1827 | segments=[]): |
| 1828 | """ |
| 1829 | :param bsid_addr: bindingSID of the SR Policy |
| 1830 | :param weight: weight of the sid list. optional. (default: 1) |
| 1831 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 1832 | (default: Encap) |
| 1833 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 1834 | (default: default) |
| 1835 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 1836 | (default: 0) |
| 1837 | :param n_segments: number of segments \ |
| 1838 | (default: 0) |
| 1839 | :param segments: a vector of IPv6 address composing the segment list \ |
| 1840 | (default: []) |
| 1841 | """ |
| 1842 | return self.api( |
| 1843 | self.papi.sr_policy_add, |
| 1844 | {'bsid_addr': bsid_addr, |
| 1845 | 'weight': weight, |
| 1846 | 'is_encap': is_encap, |
| 1847 | 'type': type, |
| 1848 | 'fib_table': fib_table, |
| 1849 | 'n_segments': n_segments, |
| 1850 | 'segments': segments |
| 1851 | } |
| 1852 | ) |
| 1853 | |
| 1854 | def sr_policy_del( |
| 1855 | self, |
| 1856 | bsid_addr, |
| 1857 | sr_policy_index=0): |
| 1858 | """ |
| 1859 | :param bsid: bindingSID of the SR Policy |
| 1860 | :param sr_policy_index: index of the sr policy (default: 0) |
| 1861 | """ |
| 1862 | return self.api( |
| 1863 | self.papi.sr_policy_del, |
| 1864 | {'bsid_addr': bsid_addr, |
| 1865 | 'sr_policy_index': sr_policy_index |
| 1866 | }) |
| 1867 | |
| 1868 | def sr_steering_add_del( |
| 1869 | self, |
| 1870 | is_del, |
| 1871 | bsid_addr, |
| 1872 | sr_policy_index, |
| 1873 | table_id, |
| 1874 | prefix_addr, |
| 1875 | mask_width, |
| 1876 | sw_if_index, |
| 1877 | traffic_type): |
| 1878 | """ |
| 1879 | Steer traffic L2 and L3 traffic through a given SR policy |
| 1880 | |
| 1881 | :param is_del: delete or add |
| 1882 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 1883 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 1884 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 1885 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 1886 | :param mask_width: is the mask for L3 traffic type |
| 1887 | :param sw_if_index: is the incoming interface for L2 traffic |
| 1888 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 1889 | """ |
| 1890 | return self.api( |
| 1891 | self.papi.sr_steering_add_del, |
| 1892 | {'is_del': is_del, |
| 1893 | 'bsid_addr': bsid_addr, |
| 1894 | 'sr_policy_index': sr_policy_index, |
| 1895 | 'table_id': table_id, |
| 1896 | 'prefix_addr': prefix_addr, |
| 1897 | 'mask_width': mask_width, |
| 1898 | 'sw_if_index': sw_if_index, |
| 1899 | 'traffic_type': traffic_type |
| 1900 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1901 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1902 | def acl_add_replace(self, acl_index, r, tag='', |
| 1903 | expected_retval=0): |
| 1904 | """Add/replace an ACL |
| 1905 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 1906 | :param acl_rule r: ACL rules array. |
| 1907 | :param str tag: symbolic tag (description) for this ACL. |
| 1908 | :param int count: number of rules. |
| 1909 | """ |
| 1910 | return self.api(self.papi.acl_add_replace, |
| 1911 | {'acl_index': acl_index, |
| 1912 | 'r': r, |
| 1913 | 'count': len(r), |
| 1914 | 'tag': tag}, |
| 1915 | expected_retval=expected_retval) |
| 1916 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 1917 | def acl_del(self, acl_index, expected_retval=0): |
| 1918 | """ |
| 1919 | |
| 1920 | :param acl_index: |
| 1921 | :return: |
| 1922 | """ |
| 1923 | return self.api(self.papi.acl_del, |
| 1924 | {'acl_index': acl_index}, |
| 1925 | expected_retval=expected_retval) |
| 1926 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1927 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 1928 | expected_retval=0): |
| 1929 | return self.api(self.papi.acl_interface_set_acl_list, |
| 1930 | {'sw_if_index': sw_if_index, |
| 1931 | 'count': len(acls), |
| 1932 | 'n_input': n_input, |
| 1933 | 'acls': acls}, |
| 1934 | expected_retval=expected_retval) |
| 1935 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 1936 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 1937 | n_input, whitelist, |
| 1938 | expected_retval=0): |
| 1939 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 1940 | {'sw_if_index': sw_if_index, |
| 1941 | 'count': len(whitelist), |
| 1942 | 'n_input': n_input, |
| 1943 | 'whitelist': whitelist}, |
| 1944 | expected_retval=expected_retval) |
| 1945 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 1946 | def acl_interface_add_del(self, |
| 1947 | sw_if_index, |
| 1948 | acl_index, |
| 1949 | is_add=1): |
| 1950 | """ Add/Delete ACL to/from interface |
| 1951 | |
| 1952 | :param sw_if_index: |
| 1953 | :param acl_index: |
| 1954 | :param is_add: (Default value = 1) |
| 1955 | """ |
| 1956 | |
| 1957 | return self.api(self.papi.acl_interface_add_del, |
| 1958 | {'is_add': is_add, |
| 1959 | 'is_input': 1, |
| 1960 | 'sw_if_index': sw_if_index, |
| 1961 | 'acl_index': acl_index}) |
| 1962 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1963 | def acl_dump(self, acl_index, expected_retval=0): |
| 1964 | return self.api(self.papi.acl_dump, |
| 1965 | {'acl_index': acl_index}, |
| 1966 | expected_retval=expected_retval) |
| 1967 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 1968 | def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF, |
| 1969 | expected_retval=0): |
| 1970 | return self.api(self.papi.acl_interface_list_dump, |
| 1971 | {'sw_if_index': sw_if_index}, |
| 1972 | expected_retval=expected_retval) |
| 1973 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1974 | def macip_acl_add(self, rules, tag=""): |
| 1975 | """ Add MACIP acl |
| 1976 | |
| 1977 | :param rules: list of rules for given acl |
| 1978 | :param tag: acl tag |
| 1979 | """ |
| 1980 | |
| 1981 | return self.api(self.papi.macip_acl_add, |
| 1982 | {'r': rules, |
| 1983 | 'count': len(rules), |
| 1984 | 'tag': tag}) |
| 1985 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1986 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 1987 | """ Add MACIP acl |
| 1988 | |
| 1989 | :param rules: list of rules for given acl |
| 1990 | :param tag: acl tag |
| 1991 | """ |
| 1992 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1993 | return self.api(self.papi.macip_acl_add_replace, |
| 1994 | {'acl_index': acl_index, |
| 1995 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1996 | 'count': len(rules), |
| 1997 | 'tag': tag}) |
| 1998 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1999 | def macip_acl_interface_add_del(self, |
| 2000 | sw_if_index, |
| 2001 | acl_index, |
| 2002 | is_add=1): |
| 2003 | """ Add MACIP acl to interface |
| 2004 | |
| 2005 | :param sw_if_index: |
| 2006 | :param acl_index: |
| 2007 | :param is_add: (Default value = 1) |
| 2008 | """ |
| 2009 | |
| 2010 | return self.api(self.papi.macip_acl_interface_add_del, |
| 2011 | {'is_add': is_add, |
| 2012 | 'sw_if_index': sw_if_index, |
| 2013 | 'acl_index': acl_index}) |
| 2014 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2015 | def macip_acl_dump(self, acl_index=4294967295): |
| 2016 | """ Return MACIP acl dump |
| 2017 | """ |
| 2018 | |
| 2019 | return self.api( |
| 2020 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2021 | |
| 2022 | def policer_add_del(self, |
| 2023 | name, |
| 2024 | cir, |
| 2025 | eir, |
| 2026 | cb, |
| 2027 | eb, |
| 2028 | is_add=1, |
| 2029 | rate_type=0, |
| 2030 | round_type=0, |
| 2031 | ptype=0, |
| 2032 | color_aware=0, |
| 2033 | conform_action_type=1, |
| 2034 | conform_dscp=0, |
| 2035 | exceed_action_type=0, |
| 2036 | exceed_dscp=0, |
| 2037 | violate_action_type=0, |
| 2038 | violate_dscp=0): |
| 2039 | return self.api(self.papi.policer_add_del, |
| 2040 | {'name': name, |
| 2041 | 'cir': cir, |
| 2042 | 'eir': eir, |
| 2043 | 'cb': cb, |
| 2044 | 'eb': eb, |
| 2045 | 'is_add': is_add, |
| 2046 | 'rate_type': rate_type, |
| 2047 | 'round_type': round_type, |
| 2048 | 'type': ptype, |
| 2049 | 'color_aware': color_aware, |
| 2050 | 'conform_action_type': conform_action_type, |
| 2051 | 'conform_dscp': conform_dscp, |
| 2052 | 'exceed_action_type': exceed_action_type, |
| 2053 | 'exceed_dscp': exceed_dscp, |
| 2054 | 'violate_action_type': violate_action_type, |
| 2055 | 'violate_dscp': violate_dscp}) |
| 2056 | |
| 2057 | def ip_punt_police(self, |
| 2058 | policer_index, |
| 2059 | is_ip6=0, |
| 2060 | is_add=1): |
| 2061 | return self.api(self.papi.ip_punt_police, |
| 2062 | {'policer_index': policer_index, |
| 2063 | 'is_add': is_add, |
| 2064 | 'is_ip6': is_ip6}) |
| 2065 | |
| 2066 | def ip_punt_redirect(self, |
| 2067 | rx_sw_if_index, |
| 2068 | tx_sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2069 | address, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2070 | is_add=1): |
| 2071 | return self.api(self.papi.ip_punt_redirect, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 2072 | {'punt': {'rx_sw_if_index': rx_sw_if_index, |
| 2073 | 'tx_sw_if_index': tx_sw_if_index, |
| 2074 | 'nh': address}, |
| 2075 | 'is_add': is_add}) |
| 2076 | |
| 2077 | def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0): |
| 2078 | return self.api(self.papi.ip_punt_redirect_dump, |
| 2079 | {'sw_if_index': sw_if_index, |
| 2080 | 'is_ipv6': is_ipv6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2081 | |
| 2082 | def bier_table_add_del(self, |
| 2083 | bti, |
| 2084 | mpls_label, |
| 2085 | is_add=1): |
| 2086 | """ BIER Table add/del """ |
| 2087 | return self.api( |
| 2088 | self.papi.bier_table_add_del, |
| 2089 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 2090 | "bt_sub_domain": bti.sub_domain_id, |
| 2091 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2092 | 'bt_label': mpls_label, |
| 2093 | 'bt_is_add': is_add}) |
| 2094 | |
| 2095 | def bier_table_dump(self): |
| 2096 | return self.api(self.papi.bier_table_dump, {}) |
| 2097 | |
| 2098 | def bier_route_add_del(self, |
| 2099 | bti, |
| 2100 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2101 | paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 2102 | is_add=1, |
| 2103 | is_replace=0): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2104 | """ BIER Route add/del """ |
| 2105 | return self.api( |
| 2106 | self.papi.bier_route_add_del, |
| 2107 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2108 | "bt_sub_domain": bti.sub_domain_id, |
| 2109 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2110 | 'br_bp': bp, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 2111 | 'br_n_paths': len(paths), |
| 2112 | 'br_paths': paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 2113 | 'br_is_add': is_add, |
| 2114 | 'br_is_replace': is_replace}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2115 | |
| 2116 | def bier_route_dump(self, bti): |
| 2117 | return self.api( |
| 2118 | self.papi.bier_route_dump, |
| 2119 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2120 | "bt_sub_domain": bti.sub_domain_id, |
| 2121 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 2122 | |
| 2123 | def bier_imp_add(self, |
| 2124 | bti, |
| 2125 | src, |
| 2126 | ibytes, |
| 2127 | is_add=1): |
| 2128 | """ BIER Imposition Add """ |
| 2129 | return self.api( |
| 2130 | self.papi.bier_imp_add, |
| 2131 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 2132 | "bt_sub_domain": bti.sub_domain_id, |
| 2133 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2134 | 'bi_src': src, |
| 2135 | 'bi_n_bytes': len(ibytes), |
| 2136 | 'bi_bytes': ibytes}) |
| 2137 | |
| 2138 | def bier_imp_del(self, bi_index): |
| 2139 | """ BIER Imposition del """ |
| 2140 | return self.api( |
| 2141 | self.papi.bier_imp_del, |
| 2142 | {'bi_index': bi_index}) |
| 2143 | |
| 2144 | def bier_imp_dump(self): |
| 2145 | return self.api(self.papi.bier_imp_dump, {}) |
| 2146 | |
| 2147 | def bier_disp_table_add_del(self, |
| 2148 | bdti, |
| 2149 | is_add=1): |
| 2150 | """ BIER Disposition Table add/del """ |
| 2151 | return self.api( |
| 2152 | self.papi.bier_disp_table_add_del, |
| 2153 | {'bdt_tbl_id': bdti, |
| 2154 | 'bdt_is_add': is_add}) |
| 2155 | |
| 2156 | def bier_disp_table_dump(self): |
| 2157 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 2158 | |
| 2159 | def bier_disp_entry_add_del(self, |
| 2160 | bdti, |
| 2161 | bp, |
| 2162 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 2163 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2164 | next_hop, |
| 2165 | next_hop_tbl_id=0, |
| 2166 | next_hop_rpf_id=~0, |
| 2167 | next_hop_is_ip4=1, |
| 2168 | is_add=1): |
| 2169 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 2170 | lstack = [] |
| 2171 | while (len(lstack) < 16): |
| 2172 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2173 | return self.api( |
| 2174 | self.papi.bier_disp_entry_add_del, |
| 2175 | {'bde_tbl_id': bdti, |
| 2176 | 'bde_bp': bp, |
| 2177 | 'bde_payload_proto': payload_proto, |
| 2178 | 'bde_n_paths': 1, |
| 2179 | 'bde_paths': [{'next_hop': next_hop, |
| 2180 | 'table_id': next_hop_tbl_id, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 2181 | 'afi': next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2182 | 'rpf_id': next_hop_rpf_id, |
| 2183 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 2184 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2185 | 'bde_is_add': is_add}) |
| 2186 | |
| 2187 | def bier_disp_entry_dump(self, bdti): |
| 2188 | return self.api( |
| 2189 | self.papi.bier_disp_entry_dump, |
| 2190 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 2191 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 2192 | def session_enable_disable(self, is_enabled): |
| 2193 | return self.api( |
| 2194 | self.papi.session_enable_disable, |
| 2195 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2196 | |
| 2197 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 2198 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 2199 | Sample CLI : 'ipsec spd add 1' |
| 2200 | |
| 2201 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 2202 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 2203 | optional |
| 2204 | :returns: reply from the API |
| 2205 | """ |
| 2206 | return self.api( |
| 2207 | self.papi.ipsec_spd_add_del, { |
| 2208 | 'spd_id': spd_id, 'is_add': is_add}) |
| 2209 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 2210 | def ipsec_spds_dump(self): |
| 2211 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 2212 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2213 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 2214 | """ IPSEC interface SPD add/del - \ |
| 2215 | Wrapper to associate/disassociate SPD to interface in VPP |
| 2216 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 2217 | |
| 2218 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 2219 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 2220 | association mandatory |
| 2221 | :param is_add - add(1) or del(0) association with interface \ |
| 2222 | (Default 1 - add) . optional |
| 2223 | :returns: reply from the API |
| 2224 | """ |
| 2225 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 2226 | self.papi.ipsec_interface_add_del_spd, |
| 2227 | {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2228 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 2229 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 2230 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 2231 | {'spd_index': spd_index if spd_index else 0, |
| 2232 | 'spd_index_valid': 1 if spd_index else 0}) |
| 2233 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2234 | def ipsec_sad_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2235 | sad_id, |
| 2236 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2237 | integrity_algorithm, |
| 2238 | integrity_key, |
| 2239 | crypto_algorithm, |
| 2240 | crypto_key, |
| 2241 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2242 | tunnel_src_address='', |
| 2243 | tunnel_dst_address='', |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2244 | flags=0, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 2245 | salt=0, |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2246 | is_add=1): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2247 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2248 | :param sad_id: security association ID |
| 2249 | :param spi: security param index of the SA in decimal |
| 2250 | :param integrity_algorithm: |
| 2251 | :param integrity_key: |
| 2252 | :param crypto_algorithm: |
| 2253 | :param crypto_key: |
| 2254 | :param protocol: AH(0) or ESP(1) protocol |
| 2255 | :param tunnel_src_address: tunnel mode outer src address |
| 2256 | :param tunnel_dst_address: tunnel mode outer dst address |
| 2257 | :param is_add: |
| 2258 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2259 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 2260 | crypto and ipsec algorithms |
| 2261 | """ |
| 2262 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2263 | self.papi.ipsec_sad_entry_add_del, |
| 2264 | { |
| 2265 | 'is_add': is_add, |
| 2266 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2267 | { |
| 2268 | 'sad_id': sad_id, |
| 2269 | 'spi': spi, |
| 2270 | 'tunnel_src': tunnel_src_address, |
| 2271 | 'tunnel_dst': tunnel_dst_address, |
| 2272 | 'protocol': protocol, |
| 2273 | 'integrity_algorithm': integrity_algorithm, |
| 2274 | 'integrity_key': { |
| 2275 | 'length': len(integrity_key), |
| 2276 | 'data': integrity_key, |
| 2277 | }, |
| 2278 | 'crypto_algorithm': crypto_algorithm, |
| 2279 | 'crypto_key': { |
| 2280 | 'length': len(crypto_key), |
| 2281 | 'data': crypto_key, |
| 2282 | }, |
| 2283 | 'flags': flags, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 2284 | 'salt': salt, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2285 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2286 | }) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2287 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 2288 | def ipsec_sa_dump(self, sa_id=None): |
| 2289 | return self.api(self.papi.ipsec_sa_dump, |
| 2290 | {'sa_id': sa_id if sa_id else 0xffffffff}) |
| 2291 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2292 | def ipsec_spd_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2293 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2294 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2295 | local_address_start, |
| 2296 | local_address_stop, |
| 2297 | remote_address_start, |
| 2298 | remote_address_stop, |
| 2299 | local_port_start=0, |
| 2300 | local_port_stop=65535, |
| 2301 | remote_port_start=0, |
| 2302 | remote_port_stop=65535, |
| 2303 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2304 | policy=0, |
| 2305 | priority=100, |
| 2306 | is_outbound=1, |
| 2307 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 2308 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2309 | is_ip_any=0): |
| 2310 | """ IPSEC policy SPD add/del - |
| 2311 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2312 | :param spd_id: SPD ID for the policy |
| 2313 | :param local_address_start: local-ip-range start address |
| 2314 | :param local_address_stop : local-ip-range stop address |
| 2315 | :param remote_address_start: remote-ip-range start address |
| 2316 | :param remote_address_stop : remote-ip-range stop address |
| 2317 | :param local_port_start: (Default value = 0) |
| 2318 | :param local_port_stop: (Default value = 65535) |
| 2319 | :param remote_port_start: (Default value = 0) |
| 2320 | :param remote_port_stop: (Default value = 65535) |
| 2321 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 2322 | :param sa_id: Security Association ID for mapping it to SPD |
| 2323 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 2324 | (Default value = 0) |
| 2325 | :param priority: value for the spd action (Default value = 100) |
| 2326 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 2327 | (Default value = 1) |
| 2328 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2329 | """ |
| 2330 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2331 | self.papi.ipsec_spd_entry_add_del, |
| 2332 | { |
| 2333 | 'is_add': is_add, |
| 2334 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2335 | { |
| 2336 | 'spd_id': spd_id, |
| 2337 | 'sa_id': sa_id, |
| 2338 | 'local_address_start': local_address_start, |
| 2339 | 'local_address_stop': local_address_stop, |
| 2340 | 'remote_address_start': remote_address_start, |
| 2341 | 'remote_address_stop': remote_address_stop, |
| 2342 | 'local_port_start': local_port_start, |
| 2343 | 'local_port_stop': local_port_stop, |
| 2344 | 'remote_port_start': remote_port_start, |
| 2345 | 'remote_port_stop': remote_port_stop, |
| 2346 | 'protocol': protocol, |
| 2347 | 'policy': policy, |
| 2348 | 'priority': priority, |
| 2349 | 'is_outbound': is_outbound, |
| 2350 | 'is_ip_any': is_ip_any |
| 2351 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 2352 | }) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 2353 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 2354 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 2355 | return self.api(self.papi.ipsec_spd_dump, |
| 2356 | {'spd_id': spd_id, |
| 2357 | 'sa_id': sa_id}) |
| 2358 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2359 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 2360 | remote_spi, crypto_alg, local_crypto_key, |
| 2361 | remote_crypto_key, integ_alg, local_integ_key, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 2362 | remote_integ_key, is_add=1, esn=0, salt=0, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2363 | anti_replay=1, renumber=0, show_instance=0): |
| 2364 | return self.api( |
| 2365 | self.papi.ipsec_tunnel_if_add_del, |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 2366 | { |
| 2367 | 'local_ip': local_ip, |
| 2368 | 'remote_ip': remote_ip, |
| 2369 | 'local_spi': local_spi, |
| 2370 | 'remote_spi': remote_spi, |
| 2371 | 'crypto_alg': crypto_alg, |
| 2372 | 'local_crypto_key_len': len(local_crypto_key), |
| 2373 | 'local_crypto_key': local_crypto_key, |
| 2374 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 2375 | 'remote_crypto_key': remote_crypto_key, |
| 2376 | 'integ_alg': integ_alg, |
| 2377 | 'local_integ_key_len': len(local_integ_key), |
| 2378 | 'local_integ_key': local_integ_key, |
| 2379 | 'remote_integ_key_len': len(remote_integ_key), |
| 2380 | 'remote_integ_key': remote_integ_key, |
| 2381 | 'is_add': is_add, |
| 2382 | 'esn': esn, |
| 2383 | 'anti_replay': anti_replay, |
| 2384 | 'renumber': renumber, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 2385 | 'show_instance': show_instance, |
| 2386 | 'salt': salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 2387 | }) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 2388 | |
Neale Ranns | f05e732 | 2019-03-29 20:23:58 +0000 | [diff] [blame] | 2389 | def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip, |
| 2390 | sa_out, sa_in, is_add=1): |
| 2391 | return self.api(self.papi.ipsec_gre_tunnel_add_del, |
| 2392 | { |
| 2393 | 'is_add': is_add, |
| 2394 | 'tunnel': { |
| 2395 | 'src': local_ip, |
| 2396 | 'dst': remote_ip, |
| 2397 | 'local_sa_id': sa_out, |
| 2398 | 'remote_sa_id': sa_in |
| 2399 | } |
| 2400 | }) |
| 2401 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 2402 | def ipsec_select_backend(self, protocol, index): |
| 2403 | return self.api(self.papi.ipsec_select_backend, |
| 2404 | {'protocol': protocol, 'index': index}) |
| 2405 | |
| 2406 | def ipsec_backend_dump(self): |
| 2407 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 2408 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 2409 | def app_namespace_add_del(self, |
| 2410 | namespace_id, |
| 2411 | ip4_fib_id=0, |
| 2412 | ip6_fib_id=0, |
| 2413 | sw_if_index=0xFFFFFFFF, |
| 2414 | secret=0): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 2415 | return self.api( |
| 2416 | self.papi.app_namespace_add_del, |
| 2417 | {'secret': secret, |
| 2418 | 'sw_if_index': sw_if_index, |
| 2419 | 'ip4_fib_id': ip4_fib_id, |
| 2420 | 'ip6_fib_id': ip6_fib_id, |
| 2421 | 'namespace_id': namespace_id, |
| 2422 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 2423 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 2424 | def punt_socket_register(self, port, pathname, protocol=0x11, |
| 2425 | header_version=1, is_ip4=1): |
| 2426 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 2427 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 2428 | {'header_version': header_version, |
| 2429 | 'punt': {'ipv': is_ip4, |
| 2430 | 'l4_protocol': protocol, |
| 2431 | 'l4_port': port}, |
| 2432 | 'pathname': pathname}) |
| 2433 | |
| 2434 | def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1): |
| 2435 | """ Unregister punt socket """ |
| 2436 | return self.api(self.papi.punt_socket_deregister, |
| 2437 | {'punt': {'ipv': is_ip4, |
| 2438 | 'l4_protocol': protocol, |
| 2439 | 'l4_port': port}}) |
| 2440 | |
| 2441 | def punt_socket_dump(self, is_ip6=1): |
| 2442 | """ Dump punt socket""" |
| 2443 | return self.api(self.papi.punt_socket_dump, |
| 2444 | {'is_ipv6': is_ip6}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 2445 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2446 | def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2447 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 2448 | """ GBP endpoint Add """ |
| 2449 | return self.api(self.papi.gbp_endpoint_add, |
| 2450 | {'endpoint': { |
| 2451 | 'sw_if_index': sw_if_index, |
| 2452 | 'ips': ips, |
| 2453 | 'n_ips': len(ips), |
| 2454 | 'mac': mac, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2455 | 'sclass': sclass, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2456 | 'flags': flags, |
| 2457 | 'tun': { |
| 2458 | 'src': tun_src, |
| 2459 | 'dst': tun_dst, |
| 2460 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 2461 | |
| 2462 | def gbp_endpoint_del(self, handle): |
| 2463 | """ GBP endpoint Del """ |
| 2464 | return self.api(self.papi.gbp_endpoint_del, |
| 2465 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2466 | |
| 2467 | def gbp_endpoint_dump(self): |
| 2468 | """ GBP endpoint Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2469 | return self.api(self.papi.gbp_endpoint_dump, |
| 2470 | {'_no_type_conversion': True}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2471 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2472 | def gbp_endpoint_group_add(self, vnid, sclass, bd, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 2473 | rd, uplink_sw_if_index, |
| 2474 | retention): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2475 | """ GBP endpoint group Add """ |
| 2476 | return self.api(self.papi.gbp_endpoint_group_add, |
| 2477 | {'epg': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2478 | { |
| 2479 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 2480 | 'bd_id': bd, |
| 2481 | 'rd_id': rd, |
| 2482 | 'vnid': vnid, |
| 2483 | 'sclass': sclass, |
| 2484 | 'retention': retention |
| 2485 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2486 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2487 | def gbp_endpoint_group_del(self, sclass): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2488 | """ GBP endpoint group Del """ |
| 2489 | return self.api(self.papi.gbp_endpoint_group_del, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2490 | {'sclass': sclass}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2491 | |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 2492 | def gbp_bridge_domain_add(self, bd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2493 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2494 | uu_fwd_sw_if_index, |
| 2495 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2496 | """ GBP bridge-domain Add """ |
| 2497 | return self.api(self.papi.gbp_bridge_domain_add, |
| 2498 | {'bd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2499 | { |
| 2500 | 'flags': flags, |
| 2501 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 2502 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
| 2503 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
| 2504 | 'bd_id': bd_id |
| 2505 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2506 | |
| 2507 | def gbp_bridge_domain_del(self, bd_id): |
| 2508 | """ GBP bridge-domain Del """ |
| 2509 | return self.api(self.papi.gbp_bridge_domain_del, |
| 2510 | {'bd_id': bd_id}) |
| 2511 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2512 | def gbp_route_domain_add(self, rd_id, |
| 2513 | ip4_table_id, |
| 2514 | ip6_table_id, |
| 2515 | ip4_uu_sw_if_index, |
| 2516 | ip6_uu_sw_if_index): |
| 2517 | """ GBP route-domain Add """ |
| 2518 | return self.api(self.papi.gbp_route_domain_add, |
| 2519 | {'rd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2520 | { |
| 2521 | 'ip4_table_id': ip4_table_id, |
| 2522 | 'ip6_table_id': ip6_table_id, |
| 2523 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 2524 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 2525 | 'rd_id': rd_id |
| 2526 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2527 | |
| 2528 | def gbp_route_domain_del(self, rd_id): |
| 2529 | """ GBP route-domain Del """ |
| 2530 | return self.api(self.papi.gbp_route_domain_del, |
| 2531 | {'rd_id': rd_id}) |
| 2532 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2533 | def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2534 | """ GBP recirc Add/Del """ |
| 2535 | return self.api(self.papi.gbp_recirc_add_del, |
| 2536 | {'is_add': is_add, |
| 2537 | 'recirc': { |
| 2538 | 'is_ext': is_ext, |
| 2539 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2540 | 'sclass': sclass}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2541 | |
| 2542 | def gbp_recirc_dump(self): |
| 2543 | """ GBP recirc Dump """ |
| 2544 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 2545 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2546 | def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id): |
| 2547 | """ GBP recirc Add/Del """ |
| 2548 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 2549 | {'is_add': is_add, |
| 2550 | 'ext_itf': { |
| 2551 | 'sw_if_index': sw_if_index, |
| 2552 | 'bd_id': bd_id, |
| 2553 | 'rd_id': rd_id}}) |
| 2554 | |
| 2555 | def gbp_ext_itf_dump(self): |
| 2556 | """ GBP recirc Dump """ |
| 2557 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 2558 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2559 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 2560 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2561 | sw_if_index=0xffffffff, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2562 | sclass=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2563 | """ GBP Subnet Add/Del """ |
| 2564 | return self.api(self.papi.gbp_subnet_add_del, |
| 2565 | {'is_add': is_add, |
| 2566 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2567 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2568 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2569 | 'sclass': sclass, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 2570 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2571 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2572 | |
| 2573 | def gbp_subnet_dump(self): |
| 2574 | """ GBP Subnet Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2575 | return self.api(self.papi.gbp_subnet_dump, |
| 2576 | {'_no_type_conversion': True}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2577 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2578 | def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index, |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 2579 | rules, allowed_ethertypes): |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2580 | """ GBP contract Add/Del """ |
| 2581 | return self.api(self.papi.gbp_contract_add_del, |
| 2582 | {'is_add': is_add, |
| 2583 | 'contract': { |
| 2584 | 'acl_index': acl_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2585 | 'sclass': sclass, |
| 2586 | 'dclass': dclass, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 2587 | 'n_rules': len(rules), |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 2588 | 'rules': rules, |
| 2589 | 'n_ether_types': len(allowed_ethertypes), |
| 2590 | 'allowed_ethertypes': allowed_ethertypes}}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2591 | |
| 2592 | def gbp_contract_dump(self): |
| 2593 | """ GBP contract Dump """ |
| 2594 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 2595 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2596 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2597 | """ GBP VXLAN tunnel add """ |
| 2598 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 2599 | { |
| 2600 | 'tunnel': { |
| 2601 | 'vni': vni, |
| 2602 | 'mode': mode, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2603 | 'bd_rd_id': bd_rd_id, |
| 2604 | 'src': src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2605 | } |
| 2606 | }) |
| 2607 | |
| 2608 | def gbp_vxlan_tunnel_del(self, vni): |
| 2609 | """ GBP VXLAN tunnel del """ |
| 2610 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 2611 | { |
| 2612 | 'vni': vni, |
| 2613 | }) |
| 2614 | |
| 2615 | def gbp_vxlan_tunnel_dump(self): |
| 2616 | """ GBP VXLAN tunnel add/del """ |
| 2617 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 2618 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 2619 | def qos_egress_map_update(self, id, outputs): |
| 2620 | """ QOS egress map update """ |
| 2621 | return self.api(self.papi.qos_egress_map_update, |
| 2622 | {'map_id': id, |
| 2623 | 'rows': outputs}) |
| 2624 | |
| 2625 | def qos_egress_map_delete(self, id): |
| 2626 | """ QOS egress map delete """ |
| 2627 | return self.api(self.papi.qos_egress_map_delete, |
| 2628 | {'map_id': id}) |
| 2629 | |
| 2630 | def qos_mark_enable_disable(self, sw_if_index, |
| 2631 | output_source, |
| 2632 | map_id, |
| 2633 | enable): |
| 2634 | """ QOS Mark Enable/Disable """ |
| 2635 | return self.api(self.papi.qos_mark_enable_disable, |
| 2636 | {'map_id': map_id, |
| 2637 | 'sw_if_index': sw_if_index, |
| 2638 | 'output_source': output_source, |
| 2639 | 'enable': enable}) |
| 2640 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2641 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 2642 | """ Enable/disable IGMP on a given interface """ |
| 2643 | return self.api(self.papi.igmp_enable_disable, |
| 2644 | {'enable': enable, |
| 2645 | 'mode': host, |
| 2646 | 'sw_if_index': sw_if_index}) |
| 2647 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 2648 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 2649 | """ Add/del IGMP proxy device """ |
| 2650 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 2651 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2652 | 'add': add}) |
| 2653 | |
| 2654 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 2655 | """ Add/del interface to/from IGMP proxy device """ |
| 2656 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 2657 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2658 | 'add': add}) |
| 2659 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2660 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2661 | """ Listen for new (S,G) on specified interface |
| 2662 | |
| 2663 | :param enable: add/del |
| 2664 | :param sw_if_index: interface sw index |
| 2665 | :param saddr: source ip4 addr |
| 2666 | :param gaddr: group ip4 addr |
| 2667 | """ |
| 2668 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2669 | { |
| 2670 | 'group': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2671 | { |
| 2672 | 'filter': filter, |
| 2673 | 'sw_if_index': sw_if_index, |
| 2674 | 'n_srcs': len(saddrs), |
| 2675 | 'saddrs': saddrs, |
| 2676 | 'gaddr': gaddr |
| 2677 | } |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2678 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2679 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2680 | def igmp_clear_interface(self, sw_if_index): |
| 2681 | """ Remove all (S,G)s from specified interface |
| 2682 | doesn't send IGMP report! |
| 2683 | """ |
| 2684 | return self.api( |
| 2685 | self.papi.igmp_clear_interface, { |
| 2686 | 'sw_if_index': sw_if_index}) |
| 2687 | |
| 2688 | def want_igmp_events(self, enable=1): |
| 2689 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 2690 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2691 | |
| 2692 | def bond_create( |
| 2693 | self, |
| 2694 | mode, |
| 2695 | lb, |
| 2696 | use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2697 | mac_address='', |
| 2698 | interface_id=0xFFFFFFFF): |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2699 | """ |
| 2700 | :param mode: mode |
| 2701 | :param lb: load balance |
| 2702 | :param use_custom_mac: use custom mac |
| 2703 | :param mac_address: mac address |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2704 | :param interface_id: custom interface ID |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2705 | """ |
| 2706 | return self.api( |
| 2707 | self.papi.bond_create, |
| 2708 | {'mode': mode, |
| 2709 | 'lb': lb, |
| 2710 | 'use_custom_mac': use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2711 | 'mac_address': mac_address, |
| 2712 | 'id': interface_id |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2713 | }) |
| 2714 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 2715 | def pipe_delete(self, parent_sw_if_index): |
| 2716 | return self.api(self.papi.pipe_delete, |
| 2717 | {'parent_sw_if_index': parent_sw_if_index}) |
| 2718 | |
Jakub Grajciar | b1be2a0 | 2018-09-19 13:36:16 +0200 | [diff] [blame] | 2719 | def memif_create( |
| 2720 | self, |
| 2721 | role, |
| 2722 | mode, |
| 2723 | rx_queues=None, |
| 2724 | tx_queues=None, |
| 2725 | _id=None, |
| 2726 | socket_id=None, |
| 2727 | secret=None, |
| 2728 | ring_size=None, |
| 2729 | buffer_size=None, |
| 2730 | hw_addr=None): |
| 2731 | return self.api(self.papi.memif_create, |
| 2732 | {'role': role, |
| 2733 | 'mode': mode, |
| 2734 | 'rx_queues': rx_queues, |
| 2735 | 'tx_queues': tx_queues, |
| 2736 | 'id': _id, |
| 2737 | 'socket_id': socket_id, |
| 2738 | 'secret': secret, |
| 2739 | 'ring_size': ring_size, |
| 2740 | 'buffer_size': buffer_size, |
| 2741 | 'hw_addr': hw_addr}) |
| 2742 | |
Neale Ranns | d1e68ab | 2018-10-01 01:42:13 -0700 | [diff] [blame] | 2743 | def svs_table_add_del(self, af, table_id, is_add=1): |
| 2744 | return self.api(self.papi.svs_table_add_del, |
| 2745 | { |
| 2746 | 'table_id': table_id, |
| 2747 | 'is_add': is_add, |
| 2748 | 'af': af, |
| 2749 | }) |
| 2750 | |
| 2751 | def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1): |
| 2752 | return self.api(self.papi.svs_route_add_del, |
| 2753 | { |
| 2754 | 'table_id': table_id, |
| 2755 | 'source_table_id': src_table_id, |
| 2756 | 'prefix': prefix, |
| 2757 | 'is_add': is_add, |
| 2758 | }) |
| 2759 | |
| 2760 | def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1): |
| 2761 | return self.api(self.papi.svs_enable_disable, |
| 2762 | { |
| 2763 | 'af': af, |
| 2764 | 'table_id': table_id, |
| 2765 | 'sw_if_index': sw_if_index, |
| 2766 | 'is_enable': is_enable, |
| 2767 | }) |