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