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