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