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