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 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 18 | # |
| 19 | # Dictionary keyed on message name to override default values for |
| 20 | # named parameters |
| 21 | # |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 22 | defaultmapping = { |
| 23 | 'map_add_domain': {'mtu': 1280}, |
| 24 | 'syslog_set_sender': {'collector_port': 514, |
| 25 | 'max_msg_size': 480}, |
| 26 | 'acl_interface_add_del': {'is_add': 1, 'is_input': 1}, |
| 27 | 'acl_interface_list_dump': {'sw_if_index': 4294967295, }, |
| 28 | 'app_namespace_add_del': {'sw_if_index': 4294967295, }, |
| 29 | 'bd_ip_mac_add_del': {'is_add': 1, }, |
| 30 | 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1, |
| 31 | 'is_add': 1, }, |
| 32 | 'bier_disp_table_add_del': {'is_add': 1, }, |
| 33 | 'bier_imp_add': {'is_add': 1, }, |
| 34 | 'bier_route_add_del': {'is_add': 1, }, |
| 35 | 'bier_table_add_del': {'is_add': 1, }, |
| 36 | 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1, |
| 37 | 'learn': 1, 'is_add': 1, }, |
Paul Vinciguerra | 9a29f79 | 2019-04-30 20:44:25 -0700 | [diff] [blame] | 38 | 'bvi_create': {'user_instance': 4294967295, }, |
| 39 | 'bvi_delete': {}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 40 | 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295, |
| 41 | 'nbuckets': 2, 'memory_size': 2097152, |
| 42 | 'next_table_index': 4294967295, |
| 43 | 'miss_next_index': 4294967295, }, |
| 44 | 'dhcp6_client_enable_disable': {'enable': 1, }, |
| 45 | 'dhcp6_clients_enable_disable': {'enable': 1, }, |
| 46 | 'dhcp6_pd_client_enable_disable': {'enable': 1, }, |
| 47 | 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, }, |
| 48 | 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, }, |
| 49 | 'dhcp_proxy_config': {'is_add': 1, }, |
| 50 | 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 51 | 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, }, |
| 52 | 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 53 | 'decap_next_index': 4294967295, }, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 54 | 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 55 | 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295, |
| 56 | 'decap_next_index': 4294967295, }, |
| 57 | 'input_acl_set_interface': {'ip4_table_index': 4294967295, |
| 58 | 'ip6_table_index': 4294967295, |
| 59 | 'l2_table_index': 4294967295, }, |
| 60 | 'ip6_add_del_address_using_prefix': {'is_add': 1, }, |
| 61 | 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, }, |
| 62 | 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295, |
| 63 | 'next_hop_weight': 1, 'next_hop_via_label': 1048576, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 64 | 'classify_table_index': 4294967295, 'is_add': 1, }, |
| 65 | 'ip_mroute_add_del': {'is_add': 1, }, |
| 66 | 'ip_neighbor_add_del': {'is_add': 1, }, |
| 67 | 'ip_punt_police': {'is_add': 1, }, |
| 68 | 'ip_punt_redirect': {'is_add': 1, }, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 69 | 'ip_route_add_del': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 70 | 'ip_table_add_del': {'is_add': 1, }, |
| 71 | 'ip_unnumbered_dump': {'sw_if_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 72 | 'ipsec_interface_add_del_spd': {'is_add': 1, }, |
| 73 | 'ipsec_sad_entry_add_del': {'is_add': 1, }, |
| 74 | 'ipsec_spd_add_del': {'is_add': 1, }, |
| 75 | 'ipsec_spd_dump': {'sa_id': 4294967295, }, |
| 76 | 'ipsec_spd_entry_add_del': {'local_port_stop': 65535, |
| 77 | 'remote_port_stop': 65535, 'priority': 100, |
| 78 | 'is_outbound': 1, |
| 79 | 'is_add': 1, }, |
| 80 | 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, }, |
| 81 | 'l2_emulation': {'enable': 1, }, |
| 82 | 'l2fib_add_del': {'is_add': 1, }, |
Paul Vinciguerra | f7f1334 | 2019-03-19 11:54:39 -0700 | [diff] [blame] | 83 | 'lb_conf': {'sticky_buckets_per_core': 4294967295, |
| 84 | 'flow_timeout': 4294967295}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 85 | 'lisp_add_del_adjacency': {'is_add': 1, }, |
| 86 | 'lisp_add_del_local_eid': {'is_add': 1, }, |
| 87 | 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, }, |
| 88 | 'lisp_add_del_locator_set': {'is_add': 1, }, |
| 89 | 'lisp_add_del_remote_mapping': {'is_add': 1, }, |
| 90 | 'macip_acl_add_replace': {'acl_index': 4294967295, }, |
| 91 | 'macip_acl_dump': {'acl_index': 4294967295, }, |
| 92 | 'macip_acl_interface_add_del': {'is_add': 1, }, |
| 93 | 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, }, |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 94 | 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295, |
| 95 | 'mr_next_hop_weight': 1, |
| 96 | 'mr_next_hop_via_label': 1048576, |
| 97 | 'mr_is_add': 1, |
| 98 | 'mr_classify_table_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 99 | 'mpls_table_add_del': {'is_add': 1, }, |
| 100 | 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295, |
| 101 | 'next_hop_weight': 1, |
| 102 | 'next_hop_via_label': 1048576, |
| 103 | 'is_add': 1, }, |
| 104 | 'mpls_tunnel_dump': {'sw_if_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 105 | 'output_acl_set_interface': {'ip4_table_index': 4294967295, |
| 106 | 'ip6_table_index': 4294967295, |
| 107 | 'l2_table_index': 4294967295, }, |
| 108 | 'pppoe_add_del_session': {'is_add': 1, }, |
| 109 | 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, }, |
| 110 | 'proxy_arp_add_del': {'is_add': 1, }, |
| 111 | 'proxy_arp_intfc_enable_disable': {'is_enable': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 112 | 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1, |
| 113 | 'proto': 1, }, |
| 114 | 'set_ipfix_exporter': {'collector_port': 4739, }, |
| 115 | 'sr_localsid_add_del': {'sw_if_index': 4294967295, }, |
| 116 | 'sr_policy_add': {'weight': 1, 'is_encap': 1, }, |
| 117 | 'svs_enable_disable': {'is_enable': 1, }, |
| 118 | 'svs_route_add_del': {'is_add': 1, }, |
| 119 | 'svs_table_add_del': {'is_add': 1, }, |
| 120 | 'sw_interface_add_del_address': {'is_add': 1, }, |
Paul Vinciguerra | 6407ba5 | 2019-04-04 13:22:20 -0700 | [diff] [blame] | 121 | 'sw_interface_dump': {'sw_if_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 122 | 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295, |
| 123 | 'pref_lifetime': 4294967295, }, |
| 124 | 'sw_interface_set_ip_directed_broadcast': {'enable': 1, }, |
| 125 | 'sw_interface_set_l2_bridge': {'enable': 1, }, |
| 126 | 'sw_interface_set_mpls_enable': {'enable': 1, }, |
| 127 | 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], }, |
| 128 | 'sw_interface_set_unnumbered': {'is_add': 1, }, |
| 129 | 'sw_interface_span_enable_disable': {'state': 1, }, |
| 130 | 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 131 | 'decap_next_index': 4294967295, |
| 132 | 'instance': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 133 | 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, }, |
| 134 | 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 135 | 'protocol': 3, }, |
| 136 | 'want_bfd_events': {'enable_disable': 1, }, |
| 137 | 'want_dhcp6_pd_reply_events': {'enable_disable': 1, }, |
| 138 | 'want_dhcp6_reply_events': {'enable_disable': 1, }, |
| 139 | 'want_igmp_events': {'enable': 1, }, |
| 140 | 'want_interface_events': {'enable_disable': 1, }, |
| 141 | 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', }, |
| 142 | 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', }, |
| 143 | 'want_ip6_ra_events': {'enable_disable': 1, }, |
| 144 | 'want_l2_macs_events': {'enable_disable': 1, }, |
| 145 | } |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 146 | |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 147 | |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 148 | class CliFailedCommandError(Exception): |
| 149 | """ cli command failed.""" |
| 150 | |
| 151 | |
| 152 | class CliSyntaxError(Exception): |
| 153 | """ cli command had a syntax error.""" |
| 154 | |
| 155 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 156 | class UnexpectedApiReturnValueError(Exception): |
| 157 | """ exception raised when the API return value is unexpected """ |
| 158 | pass |
| 159 | |
| 160 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 161 | class VppPapiProvider(object): |
| 162 | """VPP-api provider using vpp-papi |
| 163 | |
| 164 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 165 | """ |
| 166 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 167 | _zero, _negative = range(2) |
| 168 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 169 | def __init__(self, name, shm_prefix, test_class, read_timeout): |
Paul Vinciguerra | 895e2f8 | 2019-01-08 20:37:40 -0800 | [diff] [blame] | 170 | self.hook = Hook(test_class) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 171 | self.name = name |
| 172 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 173 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 174 | self._expect_api_retval = self._zero |
| 175 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 176 | |
Paul Vinciguerra | 1954229 | 2019-03-17 17:34:46 -0700 | [diff] [blame] | 177 | # install_dir is a class attribute. We need to set it before |
| 178 | # calling the constructor. |
| 179 | VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH') |
Paul Vinciguerra | 04575c5 | 2019-01-13 10:26:05 -0800 | [diff] [blame] | 180 | |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 181 | use_socket = False |
| 182 | try: |
| 183 | if os.environ['SOCKET'] == '1': |
| 184 | use_socket = True |
Paul Vinciguerra | bff9f2f | 2019-05-09 16:12:35 -0400 | [diff] [blame] | 185 | except KeyError: |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 186 | pass |
Paul Vinciguerra | 1954229 | 2019-03-17 17:34:46 -0700 | [diff] [blame] | 187 | |
| 188 | self.vpp = VPPApiClient(logger=test_class.logger, |
| 189 | read_timeout=read_timeout, |
| 190 | use_socket=use_socket, |
| 191 | server_address=test_class.api_sock) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 192 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 193 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 194 | def __enter__(self): |
| 195 | return self |
| 196 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 197 | def assert_negative_api_retval(self): |
| 198 | """ Expect API failure - used with with, e.g.: |
| 199 | with self.vapi.assert_negative_api_retval(): |
| 200 | self.vapi.<api call expected to fail> |
| 201 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 202 | self._expect_stack.append(self._expect_api_retval) |
| 203 | self._expect_api_retval = self._negative |
| 204 | return self |
| 205 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 206 | def assert_zero_api_retval(self): |
| 207 | """ Expect API success - used with with, e.g.: |
| 208 | with self.vapi.assert_negative_api_retval(): |
| 209 | self.vapi.<api call expected to succeed> |
| 210 | |
| 211 | note: this is useful only inside another with block |
| 212 | as success is the default expected value |
| 213 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 214 | self._expect_stack.append(self._expect_api_retval) |
| 215 | self._expect_api_retval = self._zero |
| 216 | return self |
| 217 | |
| 218 | def __exit__(self, exc_type, exc_value, traceback): |
| 219 | self._expect_api_retval = self._expect_stack.pop() |
| 220 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 221 | def register_hook(self, hook): |
| 222 | """Replace hook registration with new hook |
| 223 | |
| 224 | :param hook: |
| 225 | |
| 226 | """ |
| 227 | self.hook = hook |
| 228 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 229 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 230 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 231 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 232 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 233 | return e |
| 234 | |
| 235 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 236 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 237 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 238 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 239 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 240 | else: |
| 241 | self.test_class.logger.debug("Expecting event within %ss", |
| 242 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 243 | if self._events: |
| 244 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 245 | limit = time.time() + timeout |
| 246 | while time.time() < limit: |
| 247 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 248 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 249 | if name and type(e).__name__ != name: |
| 250 | raise Exception( |
| 251 | "Unexpected event received: %s, expected: %s" % |
| 252 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 253 | self.test_class.logger.debug("Returning event %s:%s" % |
| 254 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 255 | return e |
Paul Vinciguerra | 0f6602c | 2019-03-10 09:10:54 -0700 | [diff] [blame] | 256 | self.test_class.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 257 | raise Exception("Event did not occur within timeout") |
| 258 | |
| 259 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 260 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 261 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 262 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 263 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 264 | self._events.append(event) |
| 265 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 266 | def factory(self, name, apifn): |
| 267 | def f(*a, **ka): |
| 268 | fields = apifn._func.msg.fields |
| 269 | |
| 270 | # add positional and kw arguments |
| 271 | d = ka |
| 272 | for i, o in enumerate(fields[3:]): |
| 273 | try: |
| 274 | d[o] = a[i] |
| 275 | except: |
| 276 | break |
| 277 | |
| 278 | # Default override |
| 279 | if name in defaultmapping: |
| 280 | for k, v in iteritems(defaultmapping[name]): |
| 281 | if k in d: |
| 282 | continue |
| 283 | d[k] = v |
| 284 | return self.api(apifn, d) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 285 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 286 | return f |
| 287 | |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 288 | def __getattribute__(self, name): |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 289 | try: |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 290 | method = super(VppPapiProvider, self).__getattribute__(name) |
| 291 | except AttributeError: |
| 292 | method = self.factory(name, getattr(self.papi, name)) |
| 293 | # lazily load the method so we don't need to call factory |
| 294 | # again for this name. |
| 295 | setattr(self, name, method) |
| 296 | return method |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 297 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 298 | def connect(self): |
| 299 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 300 | self.vpp.connect(self.name, self.shm_prefix) |
| 301 | self.papi = self.vpp.api |
| 302 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 303 | |
| 304 | def disconnect(self): |
| 305 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 306 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 307 | |
| 308 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 309 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 310 | Call the appropriate hooks before and after the API call |
| 311 | |
| 312 | :param api_fn: API function to call |
| 313 | :param api_args: tuple of API function arguments |
| 314 | :param expected_retval: Expected return value (Default value = 0) |
| 315 | :returns: reply from the API |
| 316 | |
| 317 | """ |
| 318 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 319 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 320 | if self._expect_api_retval == self._negative: |
| 321 | if hasattr(reply, 'retval') and reply.retval >= 0: |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 322 | msg = "API call passed unexpectedly: expected negative " \ |
| 323 | "return value instead of %d in %s" % \ |
| 324 | (reply.retval, moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 325 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 326 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 327 | elif self._expect_api_retval == self._zero: |
| 328 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 329 | msg = "API call failed, expected %d return value instead " \ |
| 330 | "of %d in %s" % (expected_retval, reply.retval, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 331 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 332 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 333 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 334 | else: |
| 335 | raise Exception("Internal error, unexpected value for " |
| 336 | "self._expect_api_retval %s" % |
| 337 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 338 | self.hook.after_api(api_fn.__name__, api_args) |
| 339 | return reply |
| 340 | |
| 341 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 342 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 343 | |
| 344 | :param cli: CLI to execute |
| 345 | :returns: CLI output |
| 346 | |
| 347 | """ |
| 348 | self.hook.before_cli(cli) |
| 349 | cli += '\n' |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 350 | r = self.papi.cli_inband(cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 351 | self.hook.after_cli(cli) |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 352 | if r.retval == -156: |
| 353 | raise CliSyntaxError(r.reply) |
| 354 | if r.retval != 0: |
| 355 | raise CliFailedCommandError(r.reply) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 356 | if hasattr(r, 'reply'): |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 357 | return r.reply |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 358 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 359 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 360 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 361 | |
| 362 | :param cli: CLI to execute |
| 363 | :returns: CLI output |
| 364 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 365 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 366 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 367 | 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] | 368 | return self.api(self.papi.want_ip4_arp_events, |
| 369 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 370 | 'ip': ip, |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 371 | 'pid': os.getpid(), }) |
| 372 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 373 | def want_ip6_nd_events(self, enable_disable=1, ip="::"): |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 374 | return self.api(self.papi.want_ip6_nd_events, |
| 375 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 376 | 'ip': ip, |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 377 | 'pid': os.getpid(), }) |
| 378 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 379 | def want_ip6_ra_events(self, enable_disable=1): |
| 380 | return self.api(self.papi.want_ip6_ra_events, |
| 381 | {'enable_disable': enable_disable, |
| 382 | 'pid': os.getpid(), }) |
| 383 | |
| 384 | def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120, |
| 385 | mrc=0, mrd=0): |
| 386 | return self.api(self.papi.ip6nd_send_router_solicitation, |
| 387 | {'irt': irt, |
| 388 | 'mrt': mrt, |
| 389 | 'mrc': mrc, |
| 390 | 'mrd': mrd, |
| 391 | 'sw_if_index': sw_if_index}) |
| 392 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 393 | def want_interface_events(self, enable_disable=1): |
| 394 | return self.api(self.papi.want_interface_events, |
| 395 | {'enable_disable': enable_disable, |
| 396 | 'pid': os.getpid(), }) |
| 397 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 398 | def want_l2_macs_events(self, enable_disable=1, scan_delay=0, |
| 399 | max_macs_in_event=0, learn_limit=0): |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 400 | return self.api(self.papi.want_l2_macs_events, |
| 401 | {'enable_disable': enable_disable, |
| 402 | 'scan_delay': scan_delay, |
| 403 | 'max_macs_in_event': max_macs_in_event, |
| 404 | 'learn_limit': learn_limit, |
| 405 | 'pid': os.getpid(), }) |
| 406 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 407 | def want_dhcp6_reply_events(self, enable_disable=1): |
| 408 | return self.api(self.papi.want_dhcp6_reply_events, |
| 409 | {'enable_disable': enable_disable, |
| 410 | 'pid': os.getpid()}) |
| 411 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 412 | def want_dhcp6_pd_reply_events(self, enable_disable=1): |
| 413 | return self.api(self.papi.want_dhcp6_pd_reply_events, |
| 414 | {'enable_disable': enable_disable, |
| 415 | 'pid': os.getpid()}) |
| 416 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 417 | def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 418 | prefixes, server_index=0xFFFFFFFF, |
| 419 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 420 | ): |
| 421 | return self.api(self.papi.dhcp6_pd_send_client_message, |
| 422 | {'sw_if_index': sw_if_index, |
| 423 | 'server_index': server_index, |
| 424 | 'irt': irt, |
| 425 | 'mrt': mrt, |
| 426 | 'mrc': mrc, |
| 427 | 'mrd': mrd, |
| 428 | 'stop': stop, |
| 429 | 'msg_type': msg_type, |
| 430 | 'T1': T1, |
| 431 | 'T2': T2, |
| 432 | 'n_prefixes': len(prefixes), |
| 433 | 'prefixes': prefixes}) |
| 434 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 435 | def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='', |
| 436 | enable=1): |
| 437 | return self.api(self.papi.dhcp6_client_enable_disable, |
| 438 | {'sw_if_index': sw_if_index, |
| 439 | 'enable': enable}) |
| 440 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 441 | def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='', |
| 442 | enable=1): |
| 443 | return self.api(self.papi.dhcp6_pd_client_enable_disable, |
| 444 | {'sw_if_index': sw_if_index, |
| 445 | 'prefix_group': prefix_group, |
| 446 | 'enable': enable}) |
| 447 | |
| 448 | def ip6_add_del_address_using_prefix(self, sw_if_index, address, |
| 449 | prefix_length, prefix_group, |
| 450 | is_add=1): |
| 451 | return self.api(self.papi.ip6_add_del_address_using_prefix, |
| 452 | {'sw_if_index': sw_if_index, |
| 453 | 'prefix_group': prefix_group, |
| 454 | 'address': address, |
| 455 | 'prefix_length': prefix_length, |
| 456 | 'is_add': is_add}) |
| 457 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 458 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 459 | return self.api(self.papi.sw_interface_set_mac_address, |
| 460 | {'sw_if_index': sw_if_index, |
| 461 | 'mac_address': mac}) |
| 462 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 463 | def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 464 | """Create p2p ethernet subinterface |
| 465 | |
| 466 | :param sw_if_index: main (parent) interface |
| 467 | :param remote_mac: client (remote) mac address |
| 468 | |
| 469 | """ |
| 470 | return self.api( |
| 471 | self.papi.p2p_ethernet_add, |
| 472 | {'parent_if_index': sw_if_index, |
| 473 | 'remote_mac': remote_mac, |
| 474 | 'subif_id': subif_id}) |
| 475 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 476 | def p2p_ethernet_del(self, sw_if_index, remote_mac): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 477 | """Delete 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_del, |
| 485 | {'parent_if_index': sw_if_index, |
| 486 | 'remote_mac': remote_mac}) |
| 487 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 488 | def create_vlan_subif(self, sw_if_index, vlan): |
| 489 | """ |
| 490 | |
| 491 | :param vlan: |
| 492 | :param sw_if_index: |
| 493 | |
| 494 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 495 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 496 | {'sw_if_index': sw_if_index, |
| 497 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 498 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 499 | def create_loopback(self, mac=''): |
| 500 | """ |
| 501 | |
| 502 | :param mac: (Optional) |
| 503 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 504 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 505 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 506 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 507 | def ip_table_add_del(self, |
| 508 | table_id, |
| 509 | is_add=1, |
| 510 | is_ipv6=0): |
| 511 | """ |
| 512 | |
| 513 | :param table_id |
| 514 | :param is_add: (Default value = 1) |
| 515 | :param is_ipv6: (Default value = 0) |
| 516 | |
| 517 | """ |
| 518 | |
| 519 | return self.api( |
| 520 | self.papi.ip_table_add_del, |
| 521 | {'table': |
| 522 | { |
| 523 | 'table_id': table_id, |
| 524 | 'is_ip6': is_ipv6 |
| 525 | }, |
| 526 | 'is_add': is_add}) |
| 527 | |
| 528 | def ip_table_dump(self): |
| 529 | return self.api(self.papi.ip_table_dump, {}) |
| 530 | |
| 531 | def ip_route_dump(self, table_id, is_ip6=False): |
| 532 | return self.api(self.papi.ip_route_dump, |
| 533 | {'table': { |
| 534 | 'table_id': table_id, |
| 535 | 'is_ip6': is_ip6 |
| 536 | }}) |
| 537 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 538 | def ip_neighbor_add_del(self, |
| 539 | sw_if_index, |
| 540 | mac_address, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 541 | ip_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 542 | is_add=1, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 543 | flags=0): |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 544 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 545 | |
| 546 | :param sw_if_index: |
| 547 | :param mac_address: |
| 548 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 549 | :param is_add: (Default value = 1) |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 550 | :param flags: (Default value = 0/NONE) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 551 | """ |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 552 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 553 | self.papi.ip_neighbor_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 554 | { |
| 555 | 'is_add': is_add, |
| 556 | 'neighbor': { |
| 557 | 'sw_if_index': sw_if_index, |
| 558 | 'flags': flags, |
| 559 | 'mac_address': mac_address, |
| 560 | 'ip_address': ip_address |
| 561 | } |
| 562 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 563 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 564 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 565 | def proxy_arp_add_del(self, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 566 | low, |
| 567 | hi, |
| 568 | table_id=0, |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 569 | is_add=1): |
| 570 | """ Config Proxy Arp Range. |
| 571 | |
| 572 | :param low_address: Start address in the rnage to Proxy for |
| 573 | :param hi_address: End address in the rnage to Proxy for |
| 574 | :param vrf_id: The VRF/table in which to proxy |
| 575 | """ |
| 576 | |
| 577 | return self.api( |
| 578 | self.papi.proxy_arp_add_del, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 579 | {'proxy': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 580 | { |
| 581 | 'table_id': table_id, |
| 582 | 'low': low, |
| 583 | 'hi': hi, |
| 584 | }, |
| 585 | 'is_add': is_add}) |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 586 | |
| 587 | def proxy_arp_intfc_enable_disable(self, |
| 588 | sw_if_index, |
| 589 | is_enable=1): |
| 590 | """ Enable/Disable an interface for proxy ARP requests |
| 591 | |
| 592 | :param sw_if_index: Interface |
| 593 | :param enable_disable: Enable/Disable |
| 594 | """ |
| 595 | |
| 596 | return self.api( |
| 597 | self.papi.proxy_arp_intfc_enable_disable, |
| 598 | {'sw_if_index': sw_if_index, |
| 599 | 'enable_disable': is_enable |
| 600 | } |
| 601 | ) |
| 602 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 603 | def gre_tunnel_add_del(self, |
| 604 | src, |
| 605 | dst, |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 606 | outer_fib_id=0, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 607 | tunnel_type=0, |
| 608 | instance=0xFFFFFFFF, |
| 609 | session_id=0, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 610 | is_add=1): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 611 | """ Add a GRE tunnel |
| 612 | |
| 613 | :param src_address: |
| 614 | :param dst_address: |
| 615 | :param outer_fib_id: (Default value = 0) |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 616 | :param tunnel_type: (Default value = 0) |
| 617 | :param instance: (Default value = 0xFFFFFFFF) |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 618 | :param session_id: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 619 | :param is_add: (Default value = 1) |
| 620 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 621 | """ |
| 622 | |
| 623 | return self.api( |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 624 | self.papi.gre_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 625 | {'is_add': is_add, |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 626 | 'tunnel': |
| 627 | { |
| 628 | 'type': tunnel_type, |
| 629 | 'instance': instance, |
| 630 | 'src': src, |
| 631 | 'dst': dst, |
| 632 | 'outer_fib_id': outer_fib_id, |
| 633 | 'session_id': session_id} |
| 634 | } |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 635 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 636 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 637 | def udp_encap_add(self, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 638 | src_ip, |
| 639 | dst_ip, |
| 640 | src_port, |
| 641 | dst_port, |
| 642 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 643 | """ Add a GRE tunnel |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 644 | :param src_ip: |
| 645 | :param dst_ip: |
| 646 | :param src_port: |
| 647 | :param dst_port: |
| 648 | :param outer_fib_id: (Default value = 0) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 649 | """ |
| 650 | |
| 651 | return self.api( |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 652 | self.papi.udp_encap_add, |
| 653 | { |
| 654 | 'udp_encap': { |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 655 | 'src_ip': src_ip, |
| 656 | 'dst_ip': dst_ip, |
| 657 | 'src_port': src_port, |
| 658 | 'dst_port': dst_port, |
| 659 | 'table_id': table_id |
| 660 | } |
| 661 | }) |
| 662 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 663 | def udp_encap_del(self, id): |
| 664 | return self.api(self.papi.udp_encap_del, {'id': id}) |
| 665 | |
| 666 | def udp_encap_dump(self): |
| 667 | return self.api(self.papi.udp_encap_dump, {}) |
| 668 | |
| 669 | def want_udp_encap_stats(self, enable=1): |
| 670 | return self.api(self.papi.want_udp_encap_stats, |
| 671 | {'enable': enable, |
| 672 | 'pid': os.getpid()}) |
| 673 | |
| 674 | def mpls_route_dump(self, table_id): |
| 675 | return self.api(self.papi.mpls_route_dump, |
| 676 | {'table': { |
| 677 | 'mt_table_id': table_id |
| 678 | }}) |
| 679 | |
| 680 | def mpls_table_dump(self): |
| 681 | return self.api(self.papi.mpls_table_dump, {}) |
| 682 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 683 | def mpls_table_add_del( |
| 684 | self, |
| 685 | table_id, |
| 686 | is_add=1): |
| 687 | """ |
| 688 | |
| 689 | :param table_id |
| 690 | :param is_add: (Default value = 1) |
| 691 | |
| 692 | """ |
| 693 | |
| 694 | return self.api( |
| 695 | self.papi.mpls_table_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 696 | {'mt_table': |
| 697 | { |
| 698 | 'mt_table_id': table_id, |
| 699 | }, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 700 | 'mt_is_add': is_add}) |
| 701 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 702 | def mpls_route_add_del(self, |
| 703 | table_id, |
| 704 | label, |
| 705 | eos, |
| 706 | eos_proto, |
| 707 | is_multicast, |
| 708 | paths, |
| 709 | is_add, |
| 710 | is_multipath): |
| 711 | """ MPLS Route add/del """ |
| 712 | return self.api( |
| 713 | self.papi.mpls_route_add_del, |
| 714 | {'mr_route': |
| 715 | { |
| 716 | 'mr_table_id': table_id, |
| 717 | 'mr_label': label, |
| 718 | 'mr_eos': eos, |
| 719 | 'mr_eos_proto': eos_proto, |
| 720 | 'mr_is_multicast': is_multicast, |
| 721 | 'mr_n_paths': len(paths), |
| 722 | 'mr_paths': paths, |
| 723 | }, |
| 724 | 'mr_is_add': is_add, |
| 725 | 'mr_is_multipath': is_multipath}) |
| 726 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 727 | def mpls_ip_bind_unbind( |
| 728 | self, |
| 729 | label, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 730 | prefix, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 731 | table_id=0, |
| 732 | ip_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 733 | is_bind=1): |
| 734 | """ |
| 735 | """ |
| 736 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 737 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 738 | {'mb_mpls_table_id': table_id, |
| 739 | 'mb_label': label, |
| 740 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 741 | 'mb_is_bind': is_bind, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 742 | 'mb_prefix': prefix}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 743 | |
| 744 | def mpls_tunnel_add_del( |
| 745 | self, |
| 746 | tun_sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 747 | paths, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 748 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 749 | l2_only=0, |
| 750 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 751 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 752 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 753 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 754 | self.papi.mpls_tunnel_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 755 | {'mt_is_add': is_add, |
| 756 | 'mt_tunnel': |
| 757 | { |
| 758 | 'mt_sw_if_index': tun_sw_if_index, |
| 759 | 'mt_l2_only': l2_only, |
| 760 | 'mt_is_multicast': is_multicast, |
| 761 | 'mt_n_paths': len(paths), |
| 762 | 'mt_paths': paths, |
| 763 | }}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 764 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 765 | 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] | 766 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 767 | bfd_key_id=None, conf_key_id=None): |
| 768 | if bfd_key_id is None: |
| 769 | return self.api(self.papi.bfd_udp_add, |
| 770 | { |
| 771 | 'sw_if_index': sw_if_index, |
| 772 | 'desired_min_tx': desired_min_tx, |
| 773 | 'required_min_rx': required_min_rx, |
| 774 | 'local_addr': local_addr, |
| 775 | 'peer_addr': peer_addr, |
| 776 | 'is_ipv6': is_ipv6, |
| 777 | 'detect_mult': detect_mult, |
| 778 | }) |
| 779 | else: |
| 780 | return self.api(self.papi.bfd_udp_add, |
| 781 | { |
| 782 | 'sw_if_index': sw_if_index, |
| 783 | 'desired_min_tx': desired_min_tx, |
| 784 | 'required_min_rx': required_min_rx, |
| 785 | 'local_addr': local_addr, |
| 786 | 'peer_addr': peer_addr, |
| 787 | 'is_ipv6': is_ipv6, |
| 788 | 'detect_mult': detect_mult, |
| 789 | 'is_authenticated': 1, |
| 790 | 'bfd_key_id': bfd_key_id, |
| 791 | 'conf_key_id': conf_key_id, |
| 792 | }) |
| 793 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 794 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 795 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 796 | return self.api(self.papi.bfd_udp_mod, |
| 797 | { |
| 798 | 'sw_if_index': sw_if_index, |
| 799 | 'desired_min_tx': desired_min_tx, |
| 800 | 'required_min_rx': required_min_rx, |
| 801 | 'local_addr': local_addr, |
| 802 | 'peer_addr': peer_addr, |
| 803 | 'is_ipv6': is_ipv6, |
| 804 | 'detect_mult': detect_mult, |
| 805 | }) |
| 806 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 807 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 808 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 809 | is_delayed=False): |
| 810 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 811 | { |
| 812 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 813 | 'local_addr': local_addr, |
| 814 | 'peer_addr': peer_addr, |
| 815 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 816 | 'is_delayed': 1 if is_delayed else 0, |
| 817 | 'bfd_key_id': bfd_key_id, |
| 818 | 'conf_key_id': conf_key_id, |
| 819 | }) |
| 820 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 821 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 822 | peer_addr, is_ipv6=0): |
| 823 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 824 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 825 | 'sw_if_index': sw_if_index, |
| 826 | 'local_addr': local_addr, |
| 827 | 'peer_addr': peer_addr, |
| 828 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 829 | }) |
| 830 | |
| 831 | def want_bfd_events(self, enable_disable=1): |
| 832 | return self.api(self.papi.want_bfd_events, { |
| 833 | 'enable_disable': enable_disable, |
| 834 | 'pid': os.getpid(), |
| 835 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 836 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 837 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 838 | return self.api(self.papi.bfd_auth_set_key, { |
| 839 | 'conf_key_id': conf_key_id, |
| 840 | 'auth_type': auth_type, |
| 841 | 'key': key, |
| 842 | 'key_len': len(key), |
| 843 | }) |
| 844 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 845 | def classify_add_del_table( |
| 846 | self, |
| 847 | is_add, |
| 848 | mask, |
| 849 | match_n_vectors=1, |
| 850 | table_index=0xFFFFFFFF, |
| 851 | nbuckets=2, |
| 852 | memory_size=2097152, |
| 853 | skip_n_vectors=0, |
| 854 | next_table_index=0xFFFFFFFF, |
| 855 | miss_next_index=0xFFFFFFFF, |
| 856 | current_data_flag=0, |
| 857 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 858 | """ |
| 859 | :param is_add: |
| 860 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 861 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 862 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 863 | :param nbuckets: (Default value = 2) |
| 864 | :param memory_size: (Default value = 2097152) |
| 865 | :param skip_n_vectors: (Default value = 0) |
| 866 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 867 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 868 | :param current_data_flag: (Default value = 0) |
| 869 | :param current_data_offset: (Default value = 0) |
| 870 | """ |
| 871 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 872 | mask_len = ((len(mask) - 1) / 16 + 1) * 16 |
| 873 | mask = mask + '\0' * (mask_len - len(mask)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 874 | return self.api( |
| 875 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 876 | {'is_add': is_add, |
| 877 | 'table_index': table_index, |
| 878 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 879 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 880 | 'skip_n_vectors': skip_n_vectors, |
| 881 | 'match_n_vectors': match_n_vectors, |
| 882 | 'next_table_index': next_table_index, |
| 883 | 'miss_next_index': miss_next_index, |
| 884 | 'current_data_flag': current_data_flag, |
| 885 | 'current_data_offset': current_data_offset, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 886 | 'mask_len': mask_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 887 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 888 | |
| 889 | def classify_add_del_session( |
| 890 | self, |
| 891 | is_add, |
| 892 | table_index, |
| 893 | match, |
| 894 | opaque_index=0xFFFFFFFF, |
| 895 | hit_next_index=0xFFFFFFFF, |
| 896 | advance=0, |
| 897 | action=0, |
| 898 | metadata=0): |
| 899 | """ |
| 900 | :param is_add: |
| 901 | :param table_index: |
| 902 | :param match: |
| 903 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 904 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 905 | :param advance: (Default value = 0) |
| 906 | :param action: (Default value = 0) |
| 907 | :param metadata: (Default value = 0) |
| 908 | """ |
| 909 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 910 | match_len = ((len(match) - 1) / 16 + 1) * 16 |
| 911 | match = match + '\0' * (match_len - len(match)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 912 | return self.api( |
| 913 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 914 | {'is_add': is_add, |
| 915 | 'table_index': table_index, |
| 916 | 'hit_next_index': hit_next_index, |
| 917 | 'opaque_index': opaque_index, |
| 918 | 'advance': advance, |
| 919 | 'action': action, |
| 920 | 'metadata': metadata, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 921 | 'match_len': match_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 922 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 923 | |
| 924 | def input_acl_set_interface( |
| 925 | self, |
| 926 | is_add, |
| 927 | sw_if_index, |
| 928 | ip4_table_index=0xFFFFFFFF, |
| 929 | ip6_table_index=0xFFFFFFFF, |
| 930 | l2_table_index=0xFFFFFFFF): |
| 931 | """ |
| 932 | :param is_add: |
| 933 | :param sw_if_index: |
| 934 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 935 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 936 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 937 | """ |
| 938 | |
| 939 | return self.api( |
| 940 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 941 | {'sw_if_index': sw_if_index, |
| 942 | 'ip4_table_index': ip4_table_index, |
| 943 | 'ip6_table_index': ip6_table_index, |
| 944 | 'l2_table_index': l2_table_index, |
| 945 | 'is_add': is_add}) |
| 946 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 947 | def output_acl_set_interface( |
| 948 | self, |
| 949 | is_add, |
| 950 | sw_if_index, |
| 951 | ip4_table_index=0xFFFFFFFF, |
| 952 | ip6_table_index=0xFFFFFFFF, |
| 953 | l2_table_index=0xFFFFFFFF): |
| 954 | """ |
| 955 | :param is_add: |
| 956 | :param sw_if_index: |
| 957 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 958 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 959 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 960 | """ |
| 961 | |
| 962 | return self.api( |
| 963 | self.papi.output_acl_set_interface, |
| 964 | {'sw_if_index': sw_if_index, |
| 965 | 'ip4_table_index': ip4_table_index, |
| 966 | 'ip6_table_index': ip6_table_index, |
| 967 | 'l2_table_index': l2_table_index, |
| 968 | 'is_add': is_add}) |
| 969 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 970 | def set_ipfix_exporter( |
| 971 | self, |
| 972 | collector_address, |
| 973 | src_address, |
| 974 | path_mtu, |
| 975 | template_interval, |
| 976 | vrf_id=0, |
| 977 | collector_port=4739, |
| 978 | udp_checksum=0): |
| 979 | return self.api( |
| 980 | self.papi.set_ipfix_exporter, |
| 981 | { |
| 982 | 'collector_address': collector_address, |
| 983 | 'collector_port': collector_port, |
| 984 | 'src_address': src_address, |
| 985 | 'vrf_id': vrf_id, |
| 986 | 'path_mtu': path_mtu, |
| 987 | 'template_interval': template_interval, |
| 988 | 'udp_checksum': udp_checksum, |
| 989 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 990 | |
| 991 | def dhcp_proxy_config(self, |
| 992 | dhcp_server, |
| 993 | dhcp_src_address, |
| 994 | rx_table_id=0, |
| 995 | server_table_id=0, |
| 996 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 997 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 998 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 999 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1000 | { |
| 1001 | 'rx_vrf_id': rx_table_id, |
| 1002 | 'server_vrf_id': server_table_id, |
| 1003 | 'is_ipv6': is_ipv6, |
| 1004 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1005 | 'dhcp_server': dhcp_server, |
| 1006 | 'dhcp_src_address': dhcp_src_address, |
| 1007 | }) |
| 1008 | |
| 1009 | def dhcp_proxy_set_vss(self, |
| 1010 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1011 | vss_type=255, |
| 1012 | vpn_ascii_id="", |
| 1013 | oui=0, |
| 1014 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1015 | is_add=1, |
| 1016 | is_ip6=0): |
| 1017 | return self.api( |
| 1018 | self.papi.dhcp_proxy_set_vss, |
| 1019 | { |
| 1020 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1021 | 'vss_type': vss_type, |
| 1022 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1023 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 1024 | 'vpn_index': vpn_index, |
| 1025 | 'is_add': is_add, |
| 1026 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1027 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1028 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1029 | def dhcp_client_config(self, |
| 1030 | sw_if_index, |
| 1031 | hostname, |
| 1032 | client_id='', |
| 1033 | is_add=1, |
| 1034 | set_broadcast_flag=1, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1035 | want_dhcp_events=0, |
| 1036 | dscp=0): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1037 | return self.api( |
| 1038 | self.papi.dhcp_client_config, |
| 1039 | { |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1040 | 'is_add': is_add, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1041 | 'client': { |
| 1042 | 'sw_if_index': sw_if_index, |
| 1043 | 'hostname': hostname, |
| 1044 | 'id': client_id, |
| 1045 | 'want_dhcp_event': want_dhcp_events, |
| 1046 | 'set_broadcast_flag': set_broadcast_flag, |
Neale Ranns | 038e1df | 2019-07-19 14:01:02 +0000 | [diff] [blame] | 1047 | 'dscp': dscp, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1048 | 'pid': os.getpid()} |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1049 | }) |
| 1050 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1051 | def ip_mroute_add_del(self, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1052 | table_id, |
| 1053 | prefix, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1054 | e_flags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1055 | rpf_id, |
| 1056 | paths, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1057 | is_add=1, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1058 | is_multipath=1): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1059 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1060 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1061 | """ |
| 1062 | return self.api( |
| 1063 | self.papi.ip_mroute_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1064 | { |
| 1065 | 'is_add': is_add, |
| 1066 | 'is_multipath': is_multipath, |
| 1067 | 'route': { |
| 1068 | 'table_id': table_id, |
| 1069 | 'entry_flags': e_flags, |
| 1070 | 'rpf_id': rpf_id, |
| 1071 | 'prefix': prefix, |
| 1072 | 'n_paths': len(paths), |
| 1073 | 'paths': paths, |
| 1074 | } |
| 1075 | }) |
| 1076 | |
| 1077 | def mfib_signal_dump(self): |
| 1078 | return self.api(self.papi.mfib_signal_dump, {}) |
| 1079 | |
| 1080 | def ip_mroute_dump(self, table_id, is_ip6=False): |
| 1081 | return self.api(self.papi.ip_mroute_dump, |
| 1082 | {'table': { |
| 1083 | 'table_id': table_id, |
| 1084 | 'is_ip6': is_ip6 |
| 1085 | }}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1086 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1087 | def lisp_enable_disable(self, is_enabled): |
| 1088 | return self.api( |
| 1089 | self.papi.lisp_enable_disable, |
| 1090 | { |
| 1091 | 'is_en': is_enabled, |
| 1092 | }) |
| 1093 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1094 | def lisp_add_del_locator_set(self, |
| 1095 | ls_name, |
| 1096 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1097 | return self.api( |
| 1098 | self.papi.lisp_add_del_locator_set, |
| 1099 | { |
| 1100 | 'is_add': is_add, |
| 1101 | 'locator_set_name': ls_name |
| 1102 | }) |
| 1103 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1104 | def lisp_add_del_locator(self, |
| 1105 | ls_name, |
| 1106 | sw_if_index, |
| 1107 | priority=1, |
| 1108 | weight=1, |
| 1109 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1110 | return self.api( |
| 1111 | self.papi.lisp_add_del_locator, |
| 1112 | { |
| 1113 | 'is_add': is_add, |
| 1114 | 'locator_set_name': ls_name, |
| 1115 | 'sw_if_index': sw_if_index, |
| 1116 | 'priority': priority, |
| 1117 | 'weight': weight |
| 1118 | }) |
| 1119 | |
| 1120 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1121 | return self.api( |
| 1122 | self.papi.lisp_locator_dump, |
| 1123 | { |
| 1124 | 'is_index_set': is_index_set, |
| 1125 | 'ls_name': ls_name, |
| 1126 | 'ls_index': ls_index, |
| 1127 | }) |
| 1128 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1129 | def lisp_add_del_local_eid(self, |
| 1130 | ls_name, |
| 1131 | eid_type, |
| 1132 | eid, |
| 1133 | prefix_len, |
| 1134 | vni=0, |
| 1135 | key_id=0, |
| 1136 | key="", |
| 1137 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1138 | return self.api( |
| 1139 | self.papi.lisp_add_del_local_eid, |
| 1140 | { |
| 1141 | 'locator_set_name': ls_name, |
| 1142 | 'is_add': is_add, |
| 1143 | 'eid_type': eid_type, |
| 1144 | 'eid': eid, |
| 1145 | 'prefix_len': prefix_len, |
| 1146 | 'vni': vni, |
| 1147 | 'key_id': key_id, |
| 1148 | 'key': key |
| 1149 | }) |
| 1150 | |
| 1151 | def lisp_eid_table_dump(self, |
| 1152 | eid_set=0, |
| 1153 | prefix_length=0, |
| 1154 | vni=0, |
| 1155 | eid_type=0, |
| 1156 | eid=None, |
| 1157 | filter_opt=0): |
| 1158 | return self.api( |
| 1159 | self.papi.lisp_eid_table_dump, |
| 1160 | { |
| 1161 | 'eid_set': eid_set, |
| 1162 | 'prefix_length': prefix_length, |
| 1163 | 'vni': vni, |
| 1164 | 'eid_type': eid_type, |
| 1165 | 'eid': eid, |
| 1166 | 'filter': filter_opt, |
| 1167 | }) |
| 1168 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1169 | def lisp_add_del_remote_mapping(self, |
| 1170 | eid_type, |
| 1171 | eid, |
| 1172 | eid_prefix_len=0, |
| 1173 | vni=0, |
| 1174 | rlocs=[], |
| 1175 | rlocs_num=0, |
| 1176 | is_src_dst=0, |
| 1177 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1178 | return self.api( |
| 1179 | self.papi.lisp_add_del_remote_mapping, |
| 1180 | { |
| 1181 | 'is_add': is_add, |
| 1182 | 'eid_type': eid_type, |
| 1183 | 'eid': eid, |
| 1184 | 'eid_len': eid_prefix_len, |
| 1185 | 'rloc_num': rlocs_num, |
| 1186 | 'rlocs': rlocs, |
| 1187 | 'vni': vni, |
| 1188 | 'is_src_dst': is_src_dst, |
| 1189 | }) |
| 1190 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1191 | def lisp_add_del_adjacency(self, |
| 1192 | leid, |
| 1193 | reid, |
| 1194 | leid_len, |
| 1195 | reid_len, |
| 1196 | eid_type, |
| 1197 | is_add=1, |
| 1198 | vni=0): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1199 | return self.api( |
| 1200 | self.papi.lisp_add_del_adjacency, |
| 1201 | { |
| 1202 | 'is_add': is_add, |
| 1203 | 'vni': vni, |
| 1204 | 'eid_type': eid_type, |
| 1205 | 'leid': leid, |
| 1206 | 'reid': reid, |
| 1207 | 'leid_len': leid_len, |
| 1208 | 'reid_len': reid_len, |
| 1209 | }) |
| 1210 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 1211 | def gtpu_add_del_tunnel( |
| 1212 | self, |
| 1213 | src_addr, |
| 1214 | dst_addr, |
| 1215 | is_add=1, |
| 1216 | is_ipv6=0, |
| 1217 | mcast_sw_if_index=0xFFFFFFFF, |
| 1218 | encap_vrf_id=0, |
| 1219 | decap_next_index=0xFFFFFFFF, |
| 1220 | teid=0): |
| 1221 | """ |
| 1222 | |
| 1223 | :param is_add: (Default value = 1) |
| 1224 | :param is_ipv6: (Default value = 0) |
| 1225 | :param src_addr: |
| 1226 | :param dst_addr: |
| 1227 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1228 | :param encap_vrf_id: (Default value = 0) |
| 1229 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 1230 | :param teid: (Default value = 0) |
| 1231 | |
| 1232 | """ |
| 1233 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 1234 | {'is_add': is_add, |
| 1235 | 'is_ipv6': is_ipv6, |
| 1236 | 'src_address': src_addr, |
| 1237 | 'dst_address': dst_addr, |
| 1238 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1239 | 'encap_vrf_id': encap_vrf_id, |
| 1240 | 'decap_next_index': decap_next_index, |
| 1241 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1242 | |
| 1243 | def vxlan_gpe_add_del_tunnel( |
| 1244 | self, |
| 1245 | src_addr, |
| 1246 | dst_addr, |
| 1247 | mcast_sw_if_index=0xFFFFFFFF, |
| 1248 | is_add=1, |
| 1249 | is_ipv6=0, |
| 1250 | encap_vrf_id=0, |
| 1251 | decap_vrf_id=0, |
| 1252 | protocol=3, |
| 1253 | vni=0): |
| 1254 | """ |
| 1255 | |
| 1256 | :param local: |
| 1257 | :param remote: |
| 1258 | :param is_add: (Default value = 1) |
| 1259 | :param is_ipv6: (Default value = 0) |
| 1260 | :param encap_vrf_id: (Default value = 0) |
| 1261 | :param decap_vrf_id: (Default value = 0) |
| 1262 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1263 | :param protocol: (Default value = 3) |
| 1264 | :param vni: (Default value = 0) |
| 1265 | |
| 1266 | """ |
| 1267 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 1268 | {'is_add': is_add, |
| 1269 | 'is_ipv6': is_ipv6, |
| 1270 | 'local': src_addr, |
| 1271 | 'remote': dst_addr, |
| 1272 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1273 | 'encap_vrf_id': encap_vrf_id, |
| 1274 | 'decap_vrf_id': decap_vrf_id, |
| 1275 | 'protocol': protocol, |
| 1276 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 1277 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 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, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1647 | { |
| 1648 | 'br_route': { |
| 1649 | 'br_tbl_id': {"bt_set": bti.set_id, |
| 1650 | "bt_sub_domain": bti.sub_domain_id, |
| 1651 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1652 | 'br_bp': bp, |
| 1653 | 'br_n_paths': len(paths), |
| 1654 | 'br_paths': paths, |
| 1655 | }, |
| 1656 | 'br_is_add': is_add, |
| 1657 | 'br_is_replace': is_replace |
| 1658 | }) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1659 | |
| 1660 | def bier_route_dump(self, bti): |
| 1661 | return self.api( |
| 1662 | self.papi.bier_route_dump, |
| 1663 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 1664 | "bt_sub_domain": bti.sub_domain_id, |
| 1665 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 1666 | |
| 1667 | def bier_imp_add(self, |
| 1668 | bti, |
| 1669 | src, |
| 1670 | ibytes, |
| 1671 | is_add=1): |
| 1672 | """ BIER Imposition Add """ |
| 1673 | return self.api( |
| 1674 | self.papi.bier_imp_add, |
| 1675 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 1676 | "bt_sub_domain": bti.sub_domain_id, |
| 1677 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1678 | 'bi_src': src, |
| 1679 | 'bi_n_bytes': len(ibytes), |
| 1680 | 'bi_bytes': ibytes}) |
| 1681 | |
| 1682 | def bier_imp_del(self, bi_index): |
| 1683 | """ BIER Imposition del """ |
| 1684 | return self.api( |
| 1685 | self.papi.bier_imp_del, |
| 1686 | {'bi_index': bi_index}) |
| 1687 | |
| 1688 | def bier_imp_dump(self): |
| 1689 | return self.api(self.papi.bier_imp_dump, {}) |
| 1690 | |
| 1691 | def bier_disp_table_add_del(self, |
| 1692 | bdti, |
| 1693 | is_add=1): |
| 1694 | """ BIER Disposition Table add/del """ |
| 1695 | return self.api( |
| 1696 | self.papi.bier_disp_table_add_del, |
| 1697 | {'bdt_tbl_id': bdti, |
| 1698 | 'bdt_is_add': is_add}) |
| 1699 | |
| 1700 | def bier_disp_table_dump(self): |
| 1701 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 1702 | |
| 1703 | def bier_disp_entry_add_del(self, |
| 1704 | bdti, |
| 1705 | bp, |
| 1706 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 1707 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1708 | next_hop, |
| 1709 | next_hop_tbl_id=0, |
| 1710 | next_hop_rpf_id=~0, |
| 1711 | next_hop_is_ip4=1, |
| 1712 | is_add=1): |
| 1713 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1714 | lstack = [] |
| 1715 | while (len(lstack) < 16): |
| 1716 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1717 | return self.api( |
| 1718 | self.papi.bier_disp_entry_add_del, |
| 1719 | {'bde_tbl_id': bdti, |
| 1720 | 'bde_bp': bp, |
| 1721 | 'bde_payload_proto': payload_proto, |
| 1722 | 'bde_n_paths': 1, |
Paul Vinciguerra | 79a32a4 | 2019-07-11 19:09:30 -0400 | [diff] [blame] | 1723 | 'bde_paths': [{'table_id': next_hop_tbl_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1724 | 'rpf_id': next_hop_rpf_id, |
| 1725 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1726 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1727 | 'bde_is_add': is_add}) |
| 1728 | |
| 1729 | def bier_disp_entry_dump(self, bdti): |
| 1730 | return self.api( |
| 1731 | self.papi.bier_disp_entry_dump, |
| 1732 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 1733 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 1734 | def session_enable_disable(self, is_enabled): |
| 1735 | return self.api( |
| 1736 | self.papi.session_enable_disable, |
| 1737 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1738 | |
| 1739 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 1740 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 1741 | Sample CLI : 'ipsec spd add 1' |
| 1742 | |
| 1743 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 1744 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 1745 | optional |
| 1746 | :returns: reply from the API |
| 1747 | """ |
| 1748 | return self.api( |
| 1749 | self.papi.ipsec_spd_add_del, { |
| 1750 | 'spd_id': spd_id, 'is_add': is_add}) |
| 1751 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1752 | def ipsec_spds_dump(self): |
| 1753 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 1754 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1755 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 1756 | """ IPSEC interface SPD add/del - \ |
| 1757 | Wrapper to associate/disassociate SPD to interface in VPP |
| 1758 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 1759 | |
| 1760 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 1761 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 1762 | association mandatory |
| 1763 | :param is_add - add(1) or del(0) association with interface \ |
| 1764 | (Default 1 - add) . optional |
| 1765 | :returns: reply from the API |
| 1766 | """ |
| 1767 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 1768 | self.papi.ipsec_interface_add_del_spd, |
| 1769 | {'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] | 1770 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1771 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 1772 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 1773 | {'spd_index': spd_index if spd_index else 0, |
| 1774 | 'spd_index_valid': 1 if spd_index else 0}) |
| 1775 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1776 | def ipsec_sad_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1777 | sad_id, |
| 1778 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1779 | integrity_algorithm, |
| 1780 | integrity_key, |
| 1781 | crypto_algorithm, |
| 1782 | crypto_key, |
| 1783 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1784 | tunnel_src_address='', |
| 1785 | tunnel_dst_address='', |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1786 | flags=0, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1787 | salt=0, |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1788 | is_add=1): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1789 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1790 | :param sad_id: security association ID |
| 1791 | :param spi: security param index of the SA in decimal |
| 1792 | :param integrity_algorithm: |
| 1793 | :param integrity_key: |
| 1794 | :param crypto_algorithm: |
| 1795 | :param crypto_key: |
| 1796 | :param protocol: AH(0) or ESP(1) protocol |
| 1797 | :param tunnel_src_address: tunnel mode outer src address |
| 1798 | :param tunnel_dst_address: tunnel mode outer dst address |
| 1799 | :param is_add: |
| 1800 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1801 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 1802 | crypto and ipsec algorithms |
| 1803 | """ |
| 1804 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1805 | self.papi.ipsec_sad_entry_add_del, |
| 1806 | { |
| 1807 | 'is_add': is_add, |
| 1808 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1809 | { |
| 1810 | 'sad_id': sad_id, |
| 1811 | 'spi': spi, |
| 1812 | 'tunnel_src': tunnel_src_address, |
| 1813 | 'tunnel_dst': tunnel_dst_address, |
| 1814 | 'protocol': protocol, |
| 1815 | 'integrity_algorithm': integrity_algorithm, |
| 1816 | 'integrity_key': { |
| 1817 | 'length': len(integrity_key), |
| 1818 | 'data': integrity_key, |
| 1819 | }, |
| 1820 | 'crypto_algorithm': crypto_algorithm, |
| 1821 | 'crypto_key': { |
| 1822 | 'length': len(crypto_key), |
| 1823 | 'data': crypto_key, |
| 1824 | }, |
| 1825 | 'flags': flags, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1826 | 'salt': salt, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1827 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1828 | }) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1829 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1830 | def ipsec_sa_dump(self, sa_id=None): |
| 1831 | return self.api(self.papi.ipsec_sa_dump, |
| 1832 | {'sa_id': sa_id if sa_id else 0xffffffff}) |
| 1833 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1834 | def ipsec_spd_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1835 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1836 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1837 | local_address_start, |
| 1838 | local_address_stop, |
| 1839 | remote_address_start, |
| 1840 | remote_address_stop, |
| 1841 | local_port_start=0, |
| 1842 | local_port_stop=65535, |
| 1843 | remote_port_start=0, |
| 1844 | remote_port_stop=65535, |
| 1845 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1846 | policy=0, |
| 1847 | priority=100, |
| 1848 | is_outbound=1, |
| 1849 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 1850 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1851 | is_ip_any=0): |
| 1852 | """ IPSEC policy SPD add/del - |
| 1853 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1854 | :param spd_id: SPD ID for the policy |
| 1855 | :param local_address_start: local-ip-range start address |
| 1856 | :param local_address_stop : local-ip-range stop address |
| 1857 | :param remote_address_start: remote-ip-range start address |
| 1858 | :param remote_address_stop : remote-ip-range stop address |
| 1859 | :param local_port_start: (Default value = 0) |
| 1860 | :param local_port_stop: (Default value = 65535) |
| 1861 | :param remote_port_start: (Default value = 0) |
| 1862 | :param remote_port_stop: (Default value = 65535) |
| 1863 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 1864 | :param sa_id: Security Association ID for mapping it to SPD |
| 1865 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 1866 | (Default value = 0) |
| 1867 | :param priority: value for the spd action (Default value = 100) |
| 1868 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 1869 | (Default value = 1) |
| 1870 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1871 | """ |
| 1872 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1873 | self.papi.ipsec_spd_entry_add_del, |
| 1874 | { |
| 1875 | 'is_add': is_add, |
| 1876 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1877 | { |
| 1878 | 'spd_id': spd_id, |
| 1879 | 'sa_id': sa_id, |
| 1880 | 'local_address_start': local_address_start, |
| 1881 | 'local_address_stop': local_address_stop, |
| 1882 | 'remote_address_start': remote_address_start, |
| 1883 | 'remote_address_stop': remote_address_stop, |
| 1884 | 'local_port_start': local_port_start, |
| 1885 | 'local_port_stop': local_port_stop, |
| 1886 | 'remote_port_start': remote_port_start, |
| 1887 | 'remote_port_stop': remote_port_stop, |
| 1888 | 'protocol': protocol, |
| 1889 | 'policy': policy, |
| 1890 | 'priority': priority, |
| 1891 | 'is_outbound': is_outbound, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1892 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1893 | }) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1894 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1895 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 1896 | return self.api(self.papi.ipsec_spd_dump, |
| 1897 | {'spd_id': spd_id, |
| 1898 | 'sa_id': sa_id}) |
| 1899 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1900 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 1901 | remote_spi, crypto_alg, local_crypto_key, |
| 1902 | remote_crypto_key, integ_alg, local_integ_key, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1903 | remote_integ_key, is_add=1, esn=0, salt=0, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1904 | anti_replay=1, renumber=0, |
| 1905 | udp_encap=0, show_instance=0): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1906 | return self.api( |
| 1907 | self.papi.ipsec_tunnel_if_add_del, |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1908 | { |
| 1909 | 'local_ip': local_ip, |
| 1910 | 'remote_ip': remote_ip, |
| 1911 | 'local_spi': local_spi, |
| 1912 | 'remote_spi': remote_spi, |
| 1913 | 'crypto_alg': crypto_alg, |
| 1914 | 'local_crypto_key_len': len(local_crypto_key), |
| 1915 | 'local_crypto_key': local_crypto_key, |
| 1916 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 1917 | 'remote_crypto_key': remote_crypto_key, |
| 1918 | 'integ_alg': integ_alg, |
| 1919 | 'local_integ_key_len': len(local_integ_key), |
| 1920 | 'local_integ_key': local_integ_key, |
| 1921 | 'remote_integ_key_len': len(remote_integ_key), |
| 1922 | 'remote_integ_key': remote_integ_key, |
| 1923 | 'is_add': is_add, |
| 1924 | 'esn': esn, |
| 1925 | 'anti_replay': anti_replay, |
| 1926 | 'renumber': renumber, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1927 | 'show_instance': show_instance, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1928 | 'udp_encap': udp_encap, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1929 | 'salt': salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1930 | }) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1931 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1932 | def ipsec_select_backend(self, protocol, index): |
| 1933 | return self.api(self.papi.ipsec_select_backend, |
| 1934 | {'protocol': protocol, 'index': index}) |
| 1935 | |
| 1936 | def ipsec_backend_dump(self): |
| 1937 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 1938 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1939 | def app_namespace_add_del(self, |
| 1940 | namespace_id, |
| 1941 | ip4_fib_id=0, |
| 1942 | ip6_fib_id=0, |
| 1943 | sw_if_index=0xFFFFFFFF, |
| 1944 | secret=0): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1945 | return self.api( |
| 1946 | self.papi.app_namespace_add_del, |
| 1947 | {'secret': secret, |
| 1948 | 'sw_if_index': sw_if_index, |
| 1949 | 'ip4_fib_id': ip4_fib_id, |
| 1950 | 'ip6_fib_id': ip6_fib_id, |
| 1951 | 'namespace_id': namespace_id, |
| 1952 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1953 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1954 | def punt_socket_register(self, reg, pathname, |
| 1955 | header_version=1): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1956 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1957 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1958 | {'header_version': header_version, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1959 | 'punt': reg, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1960 | 'pathname': pathname}) |
| 1961 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1962 | def punt_socket_deregister(self, reg): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1963 | """ Unregister punt socket """ |
| 1964 | return self.api(self.papi.punt_socket_deregister, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1965 | {'punt': reg}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1966 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1967 | def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1968 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1969 | """ GBP endpoint Add """ |
| 1970 | return self.api(self.papi.gbp_endpoint_add, |
| 1971 | {'endpoint': { |
| 1972 | 'sw_if_index': sw_if_index, |
| 1973 | 'ips': ips, |
| 1974 | 'n_ips': len(ips), |
| 1975 | 'mac': mac, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1976 | 'sclass': sclass, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1977 | 'flags': flags, |
| 1978 | 'tun': { |
| 1979 | 'src': tun_src, |
| 1980 | 'dst': tun_dst, |
| 1981 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1982 | |
| 1983 | def gbp_endpoint_del(self, handle): |
| 1984 | """ GBP endpoint Del """ |
| 1985 | return self.api(self.papi.gbp_endpoint_del, |
| 1986 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1987 | |
| 1988 | def gbp_endpoint_dump(self): |
| 1989 | """ GBP endpoint Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1990 | return self.api(self.papi.gbp_endpoint_dump, |
| 1991 | {'_no_type_conversion': True}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1992 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1993 | def gbp_endpoint_group_add(self, vnid, sclass, bd, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1994 | rd, uplink_sw_if_index, |
| 1995 | retention): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1996 | """ GBP endpoint group Add """ |
| 1997 | return self.api(self.papi.gbp_endpoint_group_add, |
| 1998 | {'epg': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1999 | { |
| 2000 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 2001 | 'bd_id': bd, |
| 2002 | 'rd_id': rd, |
| 2003 | 'vnid': vnid, |
| 2004 | 'sclass': sclass, |
| 2005 | 'retention': retention |
| 2006 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2007 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2008 | def gbp_endpoint_group_del(self, sclass): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2009 | """ GBP endpoint group Del """ |
| 2010 | return self.api(self.papi.gbp_endpoint_group_del, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2011 | {'sclass': sclass}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2012 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2013 | def gbp_bridge_domain_add(self, bd_id, rd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2014 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2015 | uu_fwd_sw_if_index, |
| 2016 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2017 | """ GBP bridge-domain Add """ |
| 2018 | return self.api(self.papi.gbp_bridge_domain_add, |
| 2019 | {'bd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2020 | { |
| 2021 | 'flags': flags, |
| 2022 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 2023 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
| 2024 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2025 | 'bd_id': bd_id, |
| 2026 | 'rd_id': rd_id |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2027 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2028 | |
| 2029 | def gbp_bridge_domain_del(self, bd_id): |
| 2030 | """ GBP bridge-domain Del """ |
| 2031 | return self.api(self.papi.gbp_bridge_domain_del, |
| 2032 | {'bd_id': bd_id}) |
| 2033 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2034 | def gbp_route_domain_add(self, rd_id, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2035 | scope, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2036 | ip4_table_id, |
| 2037 | ip6_table_id, |
| 2038 | ip4_uu_sw_if_index, |
| 2039 | ip6_uu_sw_if_index): |
| 2040 | """ GBP route-domain Add """ |
| 2041 | return self.api(self.papi.gbp_route_domain_add, |
| 2042 | {'rd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2043 | { |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2044 | 'scope': scope, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2045 | 'ip4_table_id': ip4_table_id, |
| 2046 | 'ip6_table_id': ip6_table_id, |
| 2047 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 2048 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 2049 | 'rd_id': rd_id |
| 2050 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2051 | |
| 2052 | def gbp_route_domain_del(self, rd_id): |
| 2053 | """ GBP route-domain Del """ |
| 2054 | return self.api(self.papi.gbp_route_domain_del, |
| 2055 | {'rd_id': rd_id}) |
| 2056 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2057 | 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] | 2058 | """ GBP recirc Add/Del """ |
| 2059 | return self.api(self.papi.gbp_recirc_add_del, |
| 2060 | {'is_add': is_add, |
| 2061 | 'recirc': { |
| 2062 | 'is_ext': is_ext, |
| 2063 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2064 | 'sclass': sclass}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2065 | |
| 2066 | def gbp_recirc_dump(self): |
| 2067 | """ GBP recirc Dump """ |
| 2068 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 2069 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 2070 | def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags): |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2071 | """ GBP recirc Add/Del """ |
| 2072 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 2073 | {'is_add': is_add, |
| 2074 | 'ext_itf': { |
| 2075 | 'sw_if_index': sw_if_index, |
| 2076 | 'bd_id': bd_id, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 2077 | 'rd_id': rd_id, |
| 2078 | 'flags': flags}}) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2079 | |
| 2080 | def gbp_ext_itf_dump(self): |
| 2081 | """ GBP recirc Dump """ |
| 2082 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 2083 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2084 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 2085 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2086 | sw_if_index=0xffffffff, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2087 | sclass=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2088 | """ GBP Subnet Add/Del """ |
| 2089 | return self.api(self.papi.gbp_subnet_add_del, |
| 2090 | {'is_add': is_add, |
| 2091 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2092 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2093 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2094 | 'sclass': sclass, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 2095 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2096 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2097 | |
| 2098 | def gbp_subnet_dump(self): |
| 2099 | """ GBP Subnet Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2100 | return self.api(self.papi.gbp_subnet_dump, |
| 2101 | {'_no_type_conversion': True}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2102 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2103 | def gbp_contract_dump(self): |
| 2104 | """ GBP contract Dump """ |
| 2105 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 2106 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2107 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2108 | """ GBP VXLAN tunnel add """ |
| 2109 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 2110 | { |
| 2111 | 'tunnel': { |
| 2112 | 'vni': vni, |
| 2113 | 'mode': mode, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2114 | 'bd_rd_id': bd_rd_id, |
| 2115 | 'src': src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2116 | } |
| 2117 | }) |
| 2118 | |
| 2119 | def gbp_vxlan_tunnel_del(self, vni): |
| 2120 | """ GBP VXLAN tunnel del """ |
| 2121 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 2122 | { |
| 2123 | 'vni': vni, |
| 2124 | }) |
| 2125 | |
| 2126 | def gbp_vxlan_tunnel_dump(self): |
| 2127 | """ GBP VXLAN tunnel add/del """ |
| 2128 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 2129 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2130 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 2131 | """ Enable/disable IGMP on a given interface """ |
| 2132 | return self.api(self.papi.igmp_enable_disable, |
| 2133 | {'enable': enable, |
| 2134 | 'mode': host, |
| 2135 | 'sw_if_index': sw_if_index}) |
| 2136 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 2137 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 2138 | """ Add/del IGMP proxy device """ |
| 2139 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 2140 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2141 | 'add': add}) |
| 2142 | |
| 2143 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 2144 | """ Add/del interface to/from IGMP proxy device """ |
| 2145 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 2146 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2147 | 'add': add}) |
| 2148 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2149 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2150 | """ Listen for new (S,G) on specified interface |
| 2151 | |
| 2152 | :param enable: add/del |
| 2153 | :param sw_if_index: interface sw index |
| 2154 | :param saddr: source ip4 addr |
| 2155 | :param gaddr: group ip4 addr |
| 2156 | """ |
| 2157 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2158 | { |
| 2159 | 'group': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2160 | { |
| 2161 | 'filter': filter, |
| 2162 | 'sw_if_index': sw_if_index, |
| 2163 | 'n_srcs': len(saddrs), |
| 2164 | 'saddrs': saddrs, |
| 2165 | 'gaddr': gaddr |
| 2166 | } |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2167 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2168 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2169 | def igmp_clear_interface(self, sw_if_index): |
| 2170 | """ Remove all (S,G)s from specified interface |
| 2171 | doesn't send IGMP report! |
| 2172 | """ |
| 2173 | return self.api( |
| 2174 | self.papi.igmp_clear_interface, { |
| 2175 | 'sw_if_index': sw_if_index}) |
| 2176 | |
| 2177 | def want_igmp_events(self, enable=1): |
| 2178 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 2179 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2180 | |
| 2181 | def bond_create( |
| 2182 | self, |
| 2183 | mode, |
| 2184 | lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2185 | numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2186 | use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2187 | mac_address='', |
| 2188 | interface_id=0xFFFFFFFF): |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2189 | """ |
| 2190 | :param mode: mode |
| 2191 | :param lb: load balance |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2192 | :param numa_only: tx on local numa node for lacp mode |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2193 | :param use_custom_mac: use custom mac |
| 2194 | :param mac_address: mac address |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2195 | :param interface_id: custom interface ID |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2196 | """ |
| 2197 | return self.api( |
| 2198 | self.papi.bond_create, |
| 2199 | {'mode': mode, |
| 2200 | 'lb': lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2201 | 'numa_only': numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2202 | 'use_custom_mac': use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2203 | 'mac_address': mac_address, |
| 2204 | 'id': interface_id |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2205 | }) |
| 2206 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 2207 | def pipe_delete(self, parent_sw_if_index): |
| 2208 | return self.api(self.papi.pipe_delete, |
| 2209 | {'parent_sw_if_index': parent_sw_if_index}) |
| 2210 | |
Neale Ranns | d1e68ab | 2018-10-01 01:42:13 -0700 | [diff] [blame] | 2211 | def svs_table_add_del(self, af, table_id, is_add=1): |
| 2212 | return self.api(self.papi.svs_table_add_del, |
| 2213 | { |
| 2214 | 'table_id': table_id, |
| 2215 | 'is_add': is_add, |
| 2216 | 'af': af, |
| 2217 | }) |
| 2218 | |
| 2219 | def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1): |
| 2220 | return self.api(self.papi.svs_route_add_del, |
| 2221 | { |
| 2222 | 'table_id': table_id, |
| 2223 | 'source_table_id': src_table_id, |
| 2224 | 'prefix': prefix, |
| 2225 | 'is_add': is_add, |
| 2226 | }) |
| 2227 | |
| 2228 | def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1): |
| 2229 | return self.api(self.papi.svs_enable_disable, |
| 2230 | { |
| 2231 | 'af': af, |
| 2232 | 'table_id': table_id, |
| 2233 | 'sw_if_index': sw_if_index, |
| 2234 | 'is_enable': is_enable, |
| 2235 | }) |