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