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, |
| 1035 | want_dhcp_events=0): |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1036 | return self.api( |
| 1037 | self.papi.dhcp_client_config, |
| 1038 | { |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1039 | 'is_add': is_add, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 1040 | 'client': { |
| 1041 | 'sw_if_index': sw_if_index, |
| 1042 | 'hostname': hostname, |
| 1043 | 'id': client_id, |
| 1044 | 'want_dhcp_event': want_dhcp_events, |
| 1045 | 'set_broadcast_flag': set_broadcast_flag, |
| 1046 | 'pid': os.getpid()} |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1047 | }) |
| 1048 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1049 | def ip_mroute_add_del(self, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1050 | table_id, |
| 1051 | prefix, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1052 | e_flags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1053 | rpf_id, |
| 1054 | paths, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1055 | is_add=1, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1056 | is_multipath=1): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1057 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1058 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1059 | """ |
| 1060 | return self.api( |
| 1061 | self.papi.ip_mroute_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1062 | { |
| 1063 | 'is_add': is_add, |
| 1064 | 'is_multipath': is_multipath, |
| 1065 | 'route': { |
| 1066 | 'table_id': table_id, |
| 1067 | 'entry_flags': e_flags, |
| 1068 | 'rpf_id': rpf_id, |
| 1069 | 'prefix': prefix, |
| 1070 | 'n_paths': len(paths), |
| 1071 | 'paths': paths, |
| 1072 | } |
| 1073 | }) |
| 1074 | |
| 1075 | def mfib_signal_dump(self): |
| 1076 | return self.api(self.papi.mfib_signal_dump, {}) |
| 1077 | |
| 1078 | def ip_mroute_dump(self, table_id, is_ip6=False): |
| 1079 | return self.api(self.papi.ip_mroute_dump, |
| 1080 | {'table': { |
| 1081 | 'table_id': table_id, |
| 1082 | 'is_ip6': is_ip6 |
| 1083 | }}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1084 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1085 | def lisp_enable_disable(self, is_enabled): |
| 1086 | return self.api( |
| 1087 | self.papi.lisp_enable_disable, |
| 1088 | { |
| 1089 | 'is_en': is_enabled, |
| 1090 | }) |
| 1091 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1092 | def lisp_add_del_locator_set(self, |
| 1093 | ls_name, |
| 1094 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1095 | return self.api( |
| 1096 | self.papi.lisp_add_del_locator_set, |
| 1097 | { |
| 1098 | 'is_add': is_add, |
| 1099 | 'locator_set_name': ls_name |
| 1100 | }) |
| 1101 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1102 | def lisp_add_del_locator(self, |
| 1103 | ls_name, |
| 1104 | sw_if_index, |
| 1105 | priority=1, |
| 1106 | weight=1, |
| 1107 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1108 | return self.api( |
| 1109 | self.papi.lisp_add_del_locator, |
| 1110 | { |
| 1111 | 'is_add': is_add, |
| 1112 | 'locator_set_name': ls_name, |
| 1113 | 'sw_if_index': sw_if_index, |
| 1114 | 'priority': priority, |
| 1115 | 'weight': weight |
| 1116 | }) |
| 1117 | |
| 1118 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1119 | return self.api( |
| 1120 | self.papi.lisp_locator_dump, |
| 1121 | { |
| 1122 | 'is_index_set': is_index_set, |
| 1123 | 'ls_name': ls_name, |
| 1124 | 'ls_index': ls_index, |
| 1125 | }) |
| 1126 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1127 | def lisp_add_del_local_eid(self, |
| 1128 | ls_name, |
| 1129 | eid_type, |
| 1130 | eid, |
| 1131 | prefix_len, |
| 1132 | vni=0, |
| 1133 | key_id=0, |
| 1134 | key="", |
| 1135 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1136 | return self.api( |
| 1137 | self.papi.lisp_add_del_local_eid, |
| 1138 | { |
| 1139 | 'locator_set_name': ls_name, |
| 1140 | 'is_add': is_add, |
| 1141 | 'eid_type': eid_type, |
| 1142 | 'eid': eid, |
| 1143 | 'prefix_len': prefix_len, |
| 1144 | 'vni': vni, |
| 1145 | 'key_id': key_id, |
| 1146 | 'key': key |
| 1147 | }) |
| 1148 | |
| 1149 | def lisp_eid_table_dump(self, |
| 1150 | eid_set=0, |
| 1151 | prefix_length=0, |
| 1152 | vni=0, |
| 1153 | eid_type=0, |
| 1154 | eid=None, |
| 1155 | filter_opt=0): |
| 1156 | return self.api( |
| 1157 | self.papi.lisp_eid_table_dump, |
| 1158 | { |
| 1159 | 'eid_set': eid_set, |
| 1160 | 'prefix_length': prefix_length, |
| 1161 | 'vni': vni, |
| 1162 | 'eid_type': eid_type, |
| 1163 | 'eid': eid, |
| 1164 | 'filter': filter_opt, |
| 1165 | }) |
| 1166 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1167 | def lisp_add_del_remote_mapping(self, |
| 1168 | eid_type, |
| 1169 | eid, |
| 1170 | eid_prefix_len=0, |
| 1171 | vni=0, |
| 1172 | rlocs=[], |
| 1173 | rlocs_num=0, |
| 1174 | is_src_dst=0, |
| 1175 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1176 | return self.api( |
| 1177 | self.papi.lisp_add_del_remote_mapping, |
| 1178 | { |
| 1179 | 'is_add': is_add, |
| 1180 | 'eid_type': eid_type, |
| 1181 | 'eid': eid, |
| 1182 | 'eid_len': eid_prefix_len, |
| 1183 | 'rloc_num': rlocs_num, |
| 1184 | 'rlocs': rlocs, |
| 1185 | 'vni': vni, |
| 1186 | 'is_src_dst': is_src_dst, |
| 1187 | }) |
| 1188 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1189 | def lisp_add_del_adjacency(self, |
| 1190 | leid, |
| 1191 | reid, |
| 1192 | leid_len, |
| 1193 | reid_len, |
| 1194 | eid_type, |
| 1195 | is_add=1, |
| 1196 | vni=0): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1197 | return self.api( |
| 1198 | self.papi.lisp_add_del_adjacency, |
| 1199 | { |
| 1200 | 'is_add': is_add, |
| 1201 | 'vni': vni, |
| 1202 | 'eid_type': eid_type, |
| 1203 | 'leid': leid, |
| 1204 | 'reid': reid, |
| 1205 | 'leid_len': leid_len, |
| 1206 | 'reid_len': reid_len, |
| 1207 | }) |
| 1208 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 1209 | def gtpu_add_del_tunnel( |
| 1210 | self, |
| 1211 | src_addr, |
| 1212 | dst_addr, |
| 1213 | is_add=1, |
| 1214 | is_ipv6=0, |
| 1215 | mcast_sw_if_index=0xFFFFFFFF, |
| 1216 | encap_vrf_id=0, |
| 1217 | decap_next_index=0xFFFFFFFF, |
| 1218 | teid=0): |
| 1219 | """ |
| 1220 | |
| 1221 | :param is_add: (Default value = 1) |
| 1222 | :param is_ipv6: (Default value = 0) |
| 1223 | :param src_addr: |
| 1224 | :param dst_addr: |
| 1225 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1226 | :param encap_vrf_id: (Default value = 0) |
| 1227 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 1228 | :param teid: (Default value = 0) |
| 1229 | |
| 1230 | """ |
| 1231 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 1232 | {'is_add': is_add, |
| 1233 | 'is_ipv6': is_ipv6, |
| 1234 | 'src_address': src_addr, |
| 1235 | 'dst_address': dst_addr, |
| 1236 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1237 | 'encap_vrf_id': encap_vrf_id, |
| 1238 | 'decap_next_index': decap_next_index, |
| 1239 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1240 | |
| 1241 | def vxlan_gpe_add_del_tunnel( |
| 1242 | self, |
| 1243 | src_addr, |
| 1244 | dst_addr, |
| 1245 | mcast_sw_if_index=0xFFFFFFFF, |
| 1246 | is_add=1, |
| 1247 | is_ipv6=0, |
| 1248 | encap_vrf_id=0, |
| 1249 | decap_vrf_id=0, |
| 1250 | protocol=3, |
| 1251 | vni=0): |
| 1252 | """ |
| 1253 | |
| 1254 | :param local: |
| 1255 | :param remote: |
| 1256 | :param is_add: (Default value = 1) |
| 1257 | :param is_ipv6: (Default value = 0) |
| 1258 | :param encap_vrf_id: (Default value = 0) |
| 1259 | :param decap_vrf_id: (Default value = 0) |
| 1260 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1261 | :param protocol: (Default value = 3) |
| 1262 | :param vni: (Default value = 0) |
| 1263 | |
| 1264 | """ |
| 1265 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 1266 | {'is_add': is_add, |
| 1267 | 'is_ipv6': is_ipv6, |
| 1268 | 'local': src_addr, |
| 1269 | 'remote': dst_addr, |
| 1270 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 1271 | 'encap_vrf_id': encap_vrf_id, |
| 1272 | 'decap_vrf_id': decap_vrf_id, |
| 1273 | 'protocol': protocol, |
| 1274 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 1275 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 1276 | def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): |
| 1277 | return self.api(self.papi.vxlan_gbp_tunnel_dump, |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1278 | {'sw_if_index': sw_if_index, |
| 1279 | '_no_type_conversion': True}) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1280 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 1281 | def pppoe_add_del_session( |
| 1282 | self, |
| 1283 | client_ip, |
| 1284 | client_mac, |
| 1285 | session_id=0, |
| 1286 | is_add=1, |
| 1287 | is_ipv6=0, |
| 1288 | decap_vrf_id=0): |
| 1289 | """ |
| 1290 | |
| 1291 | :param is_add: (Default value = 1) |
| 1292 | :param is_ipv6: (Default value = 0) |
| 1293 | :param client_ip: |
| 1294 | :param session_id: (Default value = 0) |
| 1295 | :param client_mac: |
| 1296 | :param decap_vrf_id: (Default value = 0) |
| 1297 | |
| 1298 | """ |
| 1299 | return self.api(self.papi.pppoe_add_del_session, |
| 1300 | {'is_add': is_add, |
| 1301 | 'is_ipv6': is_ipv6, |
| 1302 | 'session_id': session_id, |
| 1303 | 'client_ip': client_ip, |
| 1304 | 'decap_vrf_id': decap_vrf_id, |
| 1305 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1306 | |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 1307 | def sr_mpls_policy_add(self, bsid, weight, type, segments): |
| 1308 | return self.api(self.papi.sr_mpls_policy_add, |
| 1309 | {'bsid': bsid, |
| 1310 | 'weight': weight, |
| 1311 | 'type': type, |
| 1312 | 'n_segments': len(segments), |
| 1313 | 'segments': segments}) |
| 1314 | |
| 1315 | def sr_mpls_policy_del(self, bsid): |
| 1316 | return self.api(self.papi.sr_mpls_policy_del, |
| 1317 | {'bsid': bsid}) |
| 1318 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1319 | def sr_localsid_add_del(self, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1320 | localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1321 | behavior, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1322 | nh_addr4, |
| 1323 | nh_addr6, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1324 | is_del=0, |
| 1325 | end_psp=0, |
| 1326 | sw_if_index=0xFFFFFFFF, |
| 1327 | vlan_index=0, |
| 1328 | fib_table=0, |
| 1329 | ): |
| 1330 | """ Add/del IPv6 SR local-SID. |
| 1331 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1332 | :param localsid: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1333 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 1334 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1335 | :param nh_addr4: |
| 1336 | :param nh_addr6: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1337 | :param is_del: (Default value = 0) |
| 1338 | :param end_psp: (Default value = 0) |
| 1339 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 1340 | :param vlan_index: (Default value = 0) |
| 1341 | :param fib_table: (Default value = 0) |
| 1342 | """ |
| 1343 | return self.api( |
| 1344 | self.papi.sr_localsid_add_del, |
| 1345 | {'is_del': is_del, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1346 | 'localsid': localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1347 | 'end_psp': end_psp, |
| 1348 | 'behavior': behavior, |
| 1349 | 'sw_if_index': sw_if_index, |
| 1350 | 'vlan_index': vlan_index, |
| 1351 | 'fib_table': fib_table, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 1352 | 'nh_addr4': nh_addr4, |
| 1353 | 'nh_addr6': nh_addr6 |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 1354 | } |
| 1355 | ) |
| 1356 | |
| 1357 | def sr_policy_add( |
| 1358 | self, |
| 1359 | bsid_addr, |
| 1360 | weight=1, |
| 1361 | is_encap=1, |
| 1362 | type=0, |
| 1363 | fib_table=0, |
| 1364 | n_segments=0, |
| 1365 | segments=[]): |
| 1366 | """ |
| 1367 | :param bsid_addr: bindingSID of the SR Policy |
| 1368 | :param weight: weight of the sid list. optional. (default: 1) |
| 1369 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 1370 | (default: Encap) |
| 1371 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 1372 | (default: default) |
| 1373 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 1374 | (default: 0) |
| 1375 | :param n_segments: number of segments \ |
| 1376 | (default: 0) |
| 1377 | :param segments: a vector of IPv6 address composing the segment list \ |
| 1378 | (default: []) |
| 1379 | """ |
| 1380 | return self.api( |
| 1381 | self.papi.sr_policy_add, |
| 1382 | {'bsid_addr': bsid_addr, |
| 1383 | 'weight': weight, |
| 1384 | 'is_encap': is_encap, |
| 1385 | 'type': type, |
| 1386 | 'fib_table': fib_table, |
| 1387 | 'n_segments': n_segments, |
| 1388 | 'segments': segments |
| 1389 | } |
| 1390 | ) |
| 1391 | |
| 1392 | def sr_policy_del( |
| 1393 | self, |
| 1394 | bsid_addr, |
| 1395 | sr_policy_index=0): |
| 1396 | """ |
| 1397 | :param bsid: bindingSID of the SR Policy |
| 1398 | :param sr_policy_index: index of the sr policy (default: 0) |
| 1399 | """ |
| 1400 | return self.api( |
| 1401 | self.papi.sr_policy_del, |
| 1402 | {'bsid_addr': bsid_addr, |
| 1403 | 'sr_policy_index': sr_policy_index |
| 1404 | }) |
| 1405 | |
| 1406 | def sr_steering_add_del( |
| 1407 | self, |
| 1408 | is_del, |
| 1409 | bsid_addr, |
| 1410 | sr_policy_index, |
| 1411 | table_id, |
| 1412 | prefix_addr, |
| 1413 | mask_width, |
| 1414 | sw_if_index, |
| 1415 | traffic_type): |
| 1416 | """ |
| 1417 | Steer traffic L2 and L3 traffic through a given SR policy |
| 1418 | |
| 1419 | :param is_del: delete or add |
| 1420 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 1421 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 1422 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 1423 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 1424 | :param mask_width: is the mask for L3 traffic type |
| 1425 | :param sw_if_index: is the incoming interface for L2 traffic |
| 1426 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 1427 | """ |
| 1428 | return self.api( |
| 1429 | self.papi.sr_steering_add_del, |
| 1430 | {'is_del': is_del, |
| 1431 | 'bsid_addr': bsid_addr, |
| 1432 | 'sr_policy_index': sr_policy_index, |
| 1433 | 'table_id': table_id, |
| 1434 | 'prefix_addr': prefix_addr, |
| 1435 | 'mask_width': mask_width, |
| 1436 | 'sw_if_index': sw_if_index, |
| 1437 | 'traffic_type': traffic_type |
| 1438 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1439 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1440 | def acl_add_replace(self, acl_index, r, tag='', |
| 1441 | expected_retval=0): |
| 1442 | """Add/replace an ACL |
| 1443 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 1444 | :param acl_rule r: ACL rules array. |
| 1445 | :param str tag: symbolic tag (description) for this ACL. |
| 1446 | :param int count: number of rules. |
| 1447 | """ |
| 1448 | return self.api(self.papi.acl_add_replace, |
| 1449 | {'acl_index': acl_index, |
| 1450 | 'r': r, |
| 1451 | 'count': len(r), |
| 1452 | 'tag': tag}, |
| 1453 | expected_retval=expected_retval) |
| 1454 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 1455 | def acl_del(self, acl_index, expected_retval=0): |
| 1456 | """ |
| 1457 | |
| 1458 | :param acl_index: |
| 1459 | :return: |
| 1460 | """ |
| 1461 | return self.api(self.papi.acl_del, |
| 1462 | {'acl_index': acl_index}, |
| 1463 | expected_retval=expected_retval) |
| 1464 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1465 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 1466 | expected_retval=0): |
| 1467 | return self.api(self.papi.acl_interface_set_acl_list, |
| 1468 | {'sw_if_index': sw_if_index, |
| 1469 | 'count': len(acls), |
| 1470 | 'n_input': n_input, |
| 1471 | 'acls': acls}, |
| 1472 | expected_retval=expected_retval) |
| 1473 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 1474 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 1475 | n_input, whitelist, |
| 1476 | expected_retval=0): |
| 1477 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 1478 | {'sw_if_index': sw_if_index, |
| 1479 | 'count': len(whitelist), |
| 1480 | 'n_input': n_input, |
| 1481 | 'whitelist': whitelist}, |
| 1482 | expected_retval=expected_retval) |
| 1483 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 1484 | def acl_interface_add_del(self, |
| 1485 | sw_if_index, |
| 1486 | acl_index, |
| 1487 | is_add=1): |
| 1488 | """ Add/Delete ACL to/from interface |
| 1489 | |
| 1490 | :param sw_if_index: |
| 1491 | :param acl_index: |
| 1492 | :param is_add: (Default value = 1) |
| 1493 | """ |
| 1494 | |
| 1495 | return self.api(self.papi.acl_interface_add_del, |
| 1496 | {'is_add': is_add, |
| 1497 | 'is_input': 1, |
| 1498 | 'sw_if_index': sw_if_index, |
| 1499 | 'acl_index': acl_index}) |
| 1500 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1501 | def acl_dump(self, acl_index, expected_retval=0): |
| 1502 | return self.api(self.papi.acl_dump, |
| 1503 | {'acl_index': acl_index}, |
| 1504 | expected_retval=expected_retval) |
| 1505 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 1506 | def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF, |
| 1507 | expected_retval=0): |
| 1508 | return self.api(self.papi.acl_interface_list_dump, |
| 1509 | {'sw_if_index': sw_if_index}, |
| 1510 | expected_retval=expected_retval) |
| 1511 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1512 | def macip_acl_add(self, rules, tag=""): |
| 1513 | """ Add MACIP acl |
| 1514 | |
| 1515 | :param rules: list of rules for given acl |
| 1516 | :param tag: acl tag |
| 1517 | """ |
| 1518 | |
| 1519 | return self.api(self.papi.macip_acl_add, |
| 1520 | {'r': rules, |
| 1521 | 'count': len(rules), |
| 1522 | 'tag': tag}) |
| 1523 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1524 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 1525 | """ Add MACIP acl |
| 1526 | |
| 1527 | :param rules: list of rules for given acl |
| 1528 | :param tag: acl tag |
| 1529 | """ |
| 1530 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1531 | return self.api(self.papi.macip_acl_add_replace, |
| 1532 | {'acl_index': acl_index, |
| 1533 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1534 | 'count': len(rules), |
| 1535 | 'tag': tag}) |
| 1536 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1537 | def macip_acl_interface_add_del(self, |
| 1538 | sw_if_index, |
| 1539 | acl_index, |
| 1540 | is_add=1): |
| 1541 | """ Add MACIP acl to interface |
| 1542 | |
| 1543 | :param sw_if_index: |
| 1544 | :param acl_index: |
| 1545 | :param is_add: (Default value = 1) |
| 1546 | """ |
| 1547 | |
| 1548 | return self.api(self.papi.macip_acl_interface_add_del, |
| 1549 | {'is_add': is_add, |
| 1550 | 'sw_if_index': sw_if_index, |
| 1551 | 'acl_index': acl_index}) |
| 1552 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1553 | def macip_acl_dump(self, acl_index=4294967295): |
| 1554 | """ Return MACIP acl dump |
| 1555 | """ |
| 1556 | |
| 1557 | return self.api( |
| 1558 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1559 | |
| 1560 | def policer_add_del(self, |
| 1561 | name, |
| 1562 | cir, |
| 1563 | eir, |
| 1564 | cb, |
| 1565 | eb, |
| 1566 | is_add=1, |
| 1567 | rate_type=0, |
| 1568 | round_type=0, |
| 1569 | ptype=0, |
| 1570 | color_aware=0, |
| 1571 | conform_action_type=1, |
| 1572 | conform_dscp=0, |
| 1573 | exceed_action_type=0, |
| 1574 | exceed_dscp=0, |
| 1575 | violate_action_type=0, |
| 1576 | violate_dscp=0): |
| 1577 | return self.api(self.papi.policer_add_del, |
| 1578 | {'name': name, |
| 1579 | 'cir': cir, |
| 1580 | 'eir': eir, |
| 1581 | 'cb': cb, |
| 1582 | 'eb': eb, |
| 1583 | 'is_add': is_add, |
| 1584 | 'rate_type': rate_type, |
| 1585 | 'round_type': round_type, |
| 1586 | 'type': ptype, |
| 1587 | 'color_aware': color_aware, |
| 1588 | 'conform_action_type': conform_action_type, |
| 1589 | 'conform_dscp': conform_dscp, |
| 1590 | 'exceed_action_type': exceed_action_type, |
| 1591 | 'exceed_dscp': exceed_dscp, |
| 1592 | 'violate_action_type': violate_action_type, |
| 1593 | 'violate_dscp': violate_dscp}) |
| 1594 | |
| 1595 | def ip_punt_police(self, |
| 1596 | policer_index, |
| 1597 | is_ip6=0, |
| 1598 | is_add=1): |
| 1599 | return self.api(self.papi.ip_punt_police, |
| 1600 | {'policer_index': policer_index, |
| 1601 | 'is_add': is_add, |
| 1602 | 'is_ip6': is_ip6}) |
| 1603 | |
| 1604 | def ip_punt_redirect(self, |
| 1605 | rx_sw_if_index, |
| 1606 | tx_sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1607 | address, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1608 | is_add=1): |
| 1609 | return self.api(self.papi.ip_punt_redirect, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1610 | {'punt': {'rx_sw_if_index': rx_sw_if_index, |
| 1611 | 'tx_sw_if_index': tx_sw_if_index, |
| 1612 | 'nh': address}, |
| 1613 | 'is_add': is_add}) |
| 1614 | |
| 1615 | def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0): |
| 1616 | return self.api(self.papi.ip_punt_redirect_dump, |
| 1617 | {'sw_if_index': sw_if_index, |
| 1618 | 'is_ipv6': is_ipv6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1619 | |
| 1620 | def bier_table_add_del(self, |
| 1621 | bti, |
| 1622 | mpls_label, |
| 1623 | is_add=1): |
| 1624 | """ BIER Table add/del """ |
| 1625 | return self.api( |
| 1626 | self.papi.bier_table_add_del, |
| 1627 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 1628 | "bt_sub_domain": bti.sub_domain_id, |
| 1629 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1630 | 'bt_label': mpls_label, |
| 1631 | 'bt_is_add': is_add}) |
| 1632 | |
| 1633 | def bier_table_dump(self): |
| 1634 | return self.api(self.papi.bier_table_dump, {}) |
| 1635 | |
| 1636 | def bier_route_add_del(self, |
| 1637 | bti, |
| 1638 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 1639 | paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 1640 | is_add=1, |
| 1641 | is_replace=0): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1642 | """ BIER Route add/del """ |
| 1643 | return self.api( |
| 1644 | self.papi.bier_route_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1645 | { |
| 1646 | 'br_route': { |
| 1647 | 'br_tbl_id': {"bt_set": bti.set_id, |
| 1648 | "bt_sub_domain": bti.sub_domain_id, |
| 1649 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1650 | 'br_bp': bp, |
| 1651 | 'br_n_paths': len(paths), |
| 1652 | 'br_paths': paths, |
| 1653 | }, |
| 1654 | 'br_is_add': is_add, |
| 1655 | 'br_is_replace': is_replace |
| 1656 | }) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1657 | |
| 1658 | def bier_route_dump(self, bti): |
| 1659 | return self.api( |
| 1660 | self.papi.bier_route_dump, |
| 1661 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 1662 | "bt_sub_domain": bti.sub_domain_id, |
| 1663 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 1664 | |
| 1665 | def bier_imp_add(self, |
| 1666 | bti, |
| 1667 | src, |
| 1668 | ibytes, |
| 1669 | is_add=1): |
| 1670 | """ BIER Imposition Add """ |
| 1671 | return self.api( |
| 1672 | self.papi.bier_imp_add, |
| 1673 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 1674 | "bt_sub_domain": bti.sub_domain_id, |
| 1675 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1676 | 'bi_src': src, |
| 1677 | 'bi_n_bytes': len(ibytes), |
| 1678 | 'bi_bytes': ibytes}) |
| 1679 | |
| 1680 | def bier_imp_del(self, bi_index): |
| 1681 | """ BIER Imposition del """ |
| 1682 | return self.api( |
| 1683 | self.papi.bier_imp_del, |
| 1684 | {'bi_index': bi_index}) |
| 1685 | |
| 1686 | def bier_imp_dump(self): |
| 1687 | return self.api(self.papi.bier_imp_dump, {}) |
| 1688 | |
| 1689 | def bier_disp_table_add_del(self, |
| 1690 | bdti, |
| 1691 | is_add=1): |
| 1692 | """ BIER Disposition Table add/del """ |
| 1693 | return self.api( |
| 1694 | self.papi.bier_disp_table_add_del, |
| 1695 | {'bdt_tbl_id': bdti, |
| 1696 | 'bdt_is_add': is_add}) |
| 1697 | |
| 1698 | def bier_disp_table_dump(self): |
| 1699 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 1700 | |
| 1701 | def bier_disp_entry_add_del(self, |
| 1702 | bdti, |
| 1703 | bp, |
| 1704 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 1705 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1706 | next_hop, |
| 1707 | next_hop_tbl_id=0, |
| 1708 | next_hop_rpf_id=~0, |
| 1709 | next_hop_is_ip4=1, |
| 1710 | is_add=1): |
| 1711 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1712 | lstack = [] |
| 1713 | while (len(lstack) < 16): |
| 1714 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1715 | return self.api( |
| 1716 | self.papi.bier_disp_entry_add_del, |
| 1717 | {'bde_tbl_id': bdti, |
| 1718 | 'bde_bp': bp, |
| 1719 | 'bde_payload_proto': payload_proto, |
| 1720 | 'bde_n_paths': 1, |
Paul Vinciguerra | 79a32a4 | 2019-07-11 19:09:30 -0400 | [diff] [blame] | 1721 | 'bde_paths': [{'table_id': next_hop_tbl_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1722 | 'rpf_id': next_hop_rpf_id, |
| 1723 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1724 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1725 | 'bde_is_add': is_add}) |
| 1726 | |
| 1727 | def bier_disp_entry_dump(self, bdti): |
| 1728 | return self.api( |
| 1729 | self.papi.bier_disp_entry_dump, |
| 1730 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 1731 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 1732 | def session_enable_disable(self, is_enabled): |
| 1733 | return self.api( |
| 1734 | self.papi.session_enable_disable, |
| 1735 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1736 | |
| 1737 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 1738 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 1739 | Sample CLI : 'ipsec spd add 1' |
| 1740 | |
| 1741 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 1742 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 1743 | optional |
| 1744 | :returns: reply from the API |
| 1745 | """ |
| 1746 | return self.api( |
| 1747 | self.papi.ipsec_spd_add_del, { |
| 1748 | 'spd_id': spd_id, 'is_add': is_add}) |
| 1749 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1750 | def ipsec_spds_dump(self): |
| 1751 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 1752 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1753 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 1754 | """ IPSEC interface SPD add/del - \ |
| 1755 | Wrapper to associate/disassociate SPD to interface in VPP |
| 1756 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 1757 | |
| 1758 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 1759 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 1760 | association mandatory |
| 1761 | :param is_add - add(1) or del(0) association with interface \ |
| 1762 | (Default 1 - add) . optional |
| 1763 | :returns: reply from the API |
| 1764 | """ |
| 1765 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 1766 | self.papi.ipsec_interface_add_del_spd, |
| 1767 | {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1768 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1769 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 1770 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 1771 | {'spd_index': spd_index if spd_index else 0, |
| 1772 | 'spd_index_valid': 1 if spd_index else 0}) |
| 1773 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1774 | def ipsec_sad_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1775 | sad_id, |
| 1776 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1777 | integrity_algorithm, |
| 1778 | integrity_key, |
| 1779 | crypto_algorithm, |
| 1780 | crypto_key, |
| 1781 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1782 | tunnel_src_address='', |
| 1783 | tunnel_dst_address='', |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1784 | flags=0, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1785 | salt=0, |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1786 | is_add=1): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1787 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1788 | :param sad_id: security association ID |
| 1789 | :param spi: security param index of the SA in decimal |
| 1790 | :param integrity_algorithm: |
| 1791 | :param integrity_key: |
| 1792 | :param crypto_algorithm: |
| 1793 | :param crypto_key: |
| 1794 | :param protocol: AH(0) or ESP(1) protocol |
| 1795 | :param tunnel_src_address: tunnel mode outer src address |
| 1796 | :param tunnel_dst_address: tunnel mode outer dst address |
| 1797 | :param is_add: |
| 1798 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1799 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 1800 | crypto and ipsec algorithms |
| 1801 | """ |
| 1802 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1803 | self.papi.ipsec_sad_entry_add_del, |
| 1804 | { |
| 1805 | 'is_add': is_add, |
| 1806 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1807 | { |
| 1808 | 'sad_id': sad_id, |
| 1809 | 'spi': spi, |
| 1810 | 'tunnel_src': tunnel_src_address, |
| 1811 | 'tunnel_dst': tunnel_dst_address, |
| 1812 | 'protocol': protocol, |
| 1813 | 'integrity_algorithm': integrity_algorithm, |
| 1814 | 'integrity_key': { |
| 1815 | 'length': len(integrity_key), |
| 1816 | 'data': integrity_key, |
| 1817 | }, |
| 1818 | 'crypto_algorithm': crypto_algorithm, |
| 1819 | 'crypto_key': { |
| 1820 | 'length': len(crypto_key), |
| 1821 | 'data': crypto_key, |
| 1822 | }, |
| 1823 | 'flags': flags, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1824 | 'salt': salt, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1825 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1826 | }) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1827 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1828 | def ipsec_sa_dump(self, sa_id=None): |
| 1829 | return self.api(self.papi.ipsec_sa_dump, |
| 1830 | {'sa_id': sa_id if sa_id else 0xffffffff}) |
| 1831 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1832 | def ipsec_spd_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1833 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1834 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1835 | local_address_start, |
| 1836 | local_address_stop, |
| 1837 | remote_address_start, |
| 1838 | remote_address_stop, |
| 1839 | local_port_start=0, |
| 1840 | local_port_stop=65535, |
| 1841 | remote_port_start=0, |
| 1842 | remote_port_stop=65535, |
| 1843 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1844 | policy=0, |
| 1845 | priority=100, |
| 1846 | is_outbound=1, |
| 1847 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 1848 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1849 | is_ip_any=0): |
| 1850 | """ IPSEC policy SPD add/del - |
| 1851 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1852 | :param spd_id: SPD ID for the policy |
| 1853 | :param local_address_start: local-ip-range start address |
| 1854 | :param local_address_stop : local-ip-range stop address |
| 1855 | :param remote_address_start: remote-ip-range start address |
| 1856 | :param remote_address_stop : remote-ip-range stop address |
| 1857 | :param local_port_start: (Default value = 0) |
| 1858 | :param local_port_stop: (Default value = 65535) |
| 1859 | :param remote_port_start: (Default value = 0) |
| 1860 | :param remote_port_stop: (Default value = 65535) |
| 1861 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 1862 | :param sa_id: Security Association ID for mapping it to SPD |
| 1863 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 1864 | (Default value = 0) |
| 1865 | :param priority: value for the spd action (Default value = 100) |
| 1866 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 1867 | (Default value = 1) |
| 1868 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1869 | """ |
| 1870 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1871 | self.papi.ipsec_spd_entry_add_del, |
| 1872 | { |
| 1873 | 'is_add': is_add, |
| 1874 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1875 | { |
| 1876 | 'spd_id': spd_id, |
| 1877 | 'sa_id': sa_id, |
| 1878 | 'local_address_start': local_address_start, |
| 1879 | 'local_address_stop': local_address_stop, |
| 1880 | 'remote_address_start': remote_address_start, |
| 1881 | 'remote_address_stop': remote_address_stop, |
| 1882 | 'local_port_start': local_port_start, |
| 1883 | 'local_port_stop': local_port_stop, |
| 1884 | 'remote_port_start': remote_port_start, |
| 1885 | 'remote_port_stop': remote_port_stop, |
| 1886 | 'protocol': protocol, |
| 1887 | 'policy': policy, |
| 1888 | 'priority': priority, |
| 1889 | 'is_outbound': is_outbound, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1890 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1891 | }) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1892 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1893 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 1894 | return self.api(self.papi.ipsec_spd_dump, |
| 1895 | {'spd_id': spd_id, |
| 1896 | 'sa_id': sa_id}) |
| 1897 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1898 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 1899 | remote_spi, crypto_alg, local_crypto_key, |
| 1900 | remote_crypto_key, integ_alg, local_integ_key, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1901 | remote_integ_key, is_add=1, esn=0, salt=0, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1902 | anti_replay=1, renumber=0, |
| 1903 | udp_encap=0, show_instance=0): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1904 | return self.api( |
| 1905 | self.papi.ipsec_tunnel_if_add_del, |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1906 | { |
| 1907 | 'local_ip': local_ip, |
| 1908 | 'remote_ip': remote_ip, |
| 1909 | 'local_spi': local_spi, |
| 1910 | 'remote_spi': remote_spi, |
| 1911 | 'crypto_alg': crypto_alg, |
| 1912 | 'local_crypto_key_len': len(local_crypto_key), |
| 1913 | 'local_crypto_key': local_crypto_key, |
| 1914 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 1915 | 'remote_crypto_key': remote_crypto_key, |
| 1916 | 'integ_alg': integ_alg, |
| 1917 | 'local_integ_key_len': len(local_integ_key), |
| 1918 | 'local_integ_key': local_integ_key, |
| 1919 | 'remote_integ_key_len': len(remote_integ_key), |
| 1920 | 'remote_integ_key': remote_integ_key, |
| 1921 | 'is_add': is_add, |
| 1922 | 'esn': esn, |
| 1923 | 'anti_replay': anti_replay, |
| 1924 | 'renumber': renumber, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1925 | 'show_instance': show_instance, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1926 | 'udp_encap': udp_encap, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1927 | 'salt': salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1928 | }) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1929 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1930 | def ipsec_select_backend(self, protocol, index): |
| 1931 | return self.api(self.papi.ipsec_select_backend, |
| 1932 | {'protocol': protocol, 'index': index}) |
| 1933 | |
| 1934 | def ipsec_backend_dump(self): |
| 1935 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 1936 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1937 | def app_namespace_add_del(self, |
| 1938 | namespace_id, |
| 1939 | ip4_fib_id=0, |
| 1940 | ip6_fib_id=0, |
| 1941 | sw_if_index=0xFFFFFFFF, |
| 1942 | secret=0): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1943 | return self.api( |
| 1944 | self.papi.app_namespace_add_del, |
| 1945 | {'secret': secret, |
| 1946 | 'sw_if_index': sw_if_index, |
| 1947 | 'ip4_fib_id': ip4_fib_id, |
| 1948 | 'ip6_fib_id': ip6_fib_id, |
| 1949 | 'namespace_id': namespace_id, |
| 1950 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1951 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1952 | def punt_socket_register(self, reg, pathname, |
| 1953 | header_version=1): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1954 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1955 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1956 | {'header_version': header_version, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1957 | 'punt': reg, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1958 | 'pathname': pathname}) |
| 1959 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1960 | def punt_socket_deregister(self, reg): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1961 | """ Unregister punt socket """ |
| 1962 | return self.api(self.papi.punt_socket_deregister, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1963 | {'punt': reg}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1964 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1965 | def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1966 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1967 | """ GBP endpoint Add """ |
| 1968 | return self.api(self.papi.gbp_endpoint_add, |
| 1969 | {'endpoint': { |
| 1970 | 'sw_if_index': sw_if_index, |
| 1971 | 'ips': ips, |
| 1972 | 'n_ips': len(ips), |
| 1973 | 'mac': mac, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1974 | 'sclass': sclass, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1975 | 'flags': flags, |
| 1976 | 'tun': { |
| 1977 | 'src': tun_src, |
| 1978 | 'dst': tun_dst, |
| 1979 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1980 | |
| 1981 | def gbp_endpoint_del(self, handle): |
| 1982 | """ GBP endpoint Del """ |
| 1983 | return self.api(self.papi.gbp_endpoint_del, |
| 1984 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1985 | |
| 1986 | def gbp_endpoint_dump(self): |
| 1987 | """ GBP endpoint Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 1988 | return self.api(self.papi.gbp_endpoint_dump, |
| 1989 | {'_no_type_conversion': True}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1990 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1991 | def gbp_endpoint_group_add(self, vnid, sclass, bd, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1992 | rd, uplink_sw_if_index, |
| 1993 | retention): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1994 | """ GBP endpoint group Add """ |
| 1995 | return self.api(self.papi.gbp_endpoint_group_add, |
| 1996 | {'epg': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1997 | { |
| 1998 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 1999 | 'bd_id': bd, |
| 2000 | 'rd_id': rd, |
| 2001 | 'vnid': vnid, |
| 2002 | 'sclass': sclass, |
| 2003 | 'retention': retention |
| 2004 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2005 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2006 | def gbp_endpoint_group_del(self, sclass): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2007 | """ GBP endpoint group Del """ |
| 2008 | return self.api(self.papi.gbp_endpoint_group_del, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2009 | {'sclass': sclass}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2010 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2011 | def gbp_bridge_domain_add(self, bd_id, rd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2012 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 2013 | uu_fwd_sw_if_index, |
| 2014 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2015 | """ GBP bridge-domain Add """ |
| 2016 | return self.api(self.papi.gbp_bridge_domain_add, |
| 2017 | {'bd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2018 | { |
| 2019 | 'flags': flags, |
| 2020 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 2021 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
| 2022 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2023 | 'bd_id': bd_id, |
| 2024 | 'rd_id': rd_id |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2025 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2026 | |
| 2027 | def gbp_bridge_domain_del(self, bd_id): |
| 2028 | """ GBP bridge-domain Del """ |
| 2029 | return self.api(self.papi.gbp_bridge_domain_del, |
| 2030 | {'bd_id': bd_id}) |
| 2031 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2032 | def gbp_route_domain_add(self, rd_id, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2033 | scope, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2034 | ip4_table_id, |
| 2035 | ip6_table_id, |
| 2036 | ip4_uu_sw_if_index, |
| 2037 | ip6_uu_sw_if_index): |
| 2038 | """ GBP route-domain Add """ |
| 2039 | return self.api(self.papi.gbp_route_domain_add, |
| 2040 | {'rd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2041 | { |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 2042 | 'scope': scope, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2043 | 'ip4_table_id': ip4_table_id, |
| 2044 | 'ip6_table_id': ip6_table_id, |
| 2045 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 2046 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 2047 | 'rd_id': rd_id |
| 2048 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2049 | |
| 2050 | def gbp_route_domain_del(self, rd_id): |
| 2051 | """ GBP route-domain Del """ |
| 2052 | return self.api(self.papi.gbp_route_domain_del, |
| 2053 | {'rd_id': rd_id}) |
| 2054 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2055 | 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] | 2056 | """ GBP recirc Add/Del """ |
| 2057 | return self.api(self.papi.gbp_recirc_add_del, |
| 2058 | {'is_add': is_add, |
| 2059 | 'recirc': { |
| 2060 | 'is_ext': is_ext, |
| 2061 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2062 | 'sclass': sclass}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2063 | |
| 2064 | def gbp_recirc_dump(self): |
| 2065 | """ GBP recirc Dump """ |
| 2066 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 2067 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 2068 | 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] | 2069 | """ GBP recirc Add/Del """ |
| 2070 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 2071 | {'is_add': is_add, |
| 2072 | 'ext_itf': { |
| 2073 | 'sw_if_index': sw_if_index, |
| 2074 | 'bd_id': bd_id, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 2075 | 'rd_id': rd_id, |
| 2076 | 'flags': flags}}) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 2077 | |
| 2078 | def gbp_ext_itf_dump(self): |
| 2079 | """ GBP recirc Dump """ |
| 2080 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 2081 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2082 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 2083 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2084 | sw_if_index=0xffffffff, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2085 | sclass=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2086 | """ GBP Subnet Add/Del """ |
| 2087 | return self.api(self.papi.gbp_subnet_add_del, |
| 2088 | {'is_add': is_add, |
| 2089 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2090 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2091 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 2092 | 'sclass': sclass, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 2093 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2094 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2095 | |
| 2096 | def gbp_subnet_dump(self): |
| 2097 | """ GBP Subnet Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2098 | return self.api(self.papi.gbp_subnet_dump, |
| 2099 | {'_no_type_conversion': True}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 2100 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 2101 | def gbp_contract_dump(self): |
| 2102 | """ GBP contract Dump """ |
| 2103 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 2104 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2105 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2106 | """ GBP VXLAN tunnel add """ |
| 2107 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 2108 | { |
| 2109 | 'tunnel': { |
| 2110 | 'vni': vni, |
| 2111 | 'mode': mode, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 2112 | 'bd_rd_id': bd_rd_id, |
| 2113 | 'src': src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 2114 | } |
| 2115 | }) |
| 2116 | |
| 2117 | def gbp_vxlan_tunnel_del(self, vni): |
| 2118 | """ GBP VXLAN tunnel del """ |
| 2119 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 2120 | { |
| 2121 | 'vni': vni, |
| 2122 | }) |
| 2123 | |
| 2124 | def gbp_vxlan_tunnel_dump(self): |
| 2125 | """ GBP VXLAN tunnel add/del """ |
| 2126 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 2127 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 2128 | def qos_egress_map_update(self, id, outputs): |
| 2129 | """ QOS egress map update """ |
| 2130 | return self.api(self.papi.qos_egress_map_update, |
| 2131 | {'map_id': id, |
| 2132 | 'rows': outputs}) |
| 2133 | |
| 2134 | def qos_egress_map_delete(self, id): |
| 2135 | """ QOS egress map delete """ |
| 2136 | return self.api(self.papi.qos_egress_map_delete, |
| 2137 | {'map_id': id}) |
| 2138 | |
| 2139 | def qos_mark_enable_disable(self, sw_if_index, |
| 2140 | output_source, |
| 2141 | map_id, |
| 2142 | enable): |
| 2143 | """ QOS Mark Enable/Disable """ |
| 2144 | return self.api(self.papi.qos_mark_enable_disable, |
| 2145 | {'map_id': map_id, |
| 2146 | 'sw_if_index': sw_if_index, |
| 2147 | 'output_source': output_source, |
| 2148 | 'enable': enable}) |
| 2149 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2150 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 2151 | """ Enable/disable IGMP on a given interface """ |
| 2152 | return self.api(self.papi.igmp_enable_disable, |
| 2153 | {'enable': enable, |
| 2154 | 'mode': host, |
| 2155 | 'sw_if_index': sw_if_index}) |
| 2156 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 2157 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 2158 | """ Add/del IGMP proxy device """ |
| 2159 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 2160 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2161 | 'add': add}) |
| 2162 | |
| 2163 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 2164 | """ Add/del interface to/from IGMP proxy device """ |
| 2165 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 2166 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 2167 | 'add': add}) |
| 2168 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2169 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2170 | """ Listen for new (S,G) on specified interface |
| 2171 | |
| 2172 | :param enable: add/del |
| 2173 | :param sw_if_index: interface sw index |
| 2174 | :param saddr: source ip4 addr |
| 2175 | :param gaddr: group ip4 addr |
| 2176 | """ |
| 2177 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2178 | { |
| 2179 | 'group': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 2180 | { |
| 2181 | 'filter': filter, |
| 2182 | 'sw_if_index': sw_if_index, |
| 2183 | 'n_srcs': len(saddrs), |
| 2184 | 'saddrs': saddrs, |
| 2185 | 'gaddr': gaddr |
| 2186 | } |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 2187 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2188 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 2189 | def igmp_clear_interface(self, sw_if_index): |
| 2190 | """ Remove all (S,G)s from specified interface |
| 2191 | doesn't send IGMP report! |
| 2192 | """ |
| 2193 | return self.api( |
| 2194 | self.papi.igmp_clear_interface, { |
| 2195 | 'sw_if_index': sw_if_index}) |
| 2196 | |
| 2197 | def want_igmp_events(self, enable=1): |
| 2198 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 2199 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2200 | |
| 2201 | def bond_create( |
| 2202 | self, |
| 2203 | mode, |
| 2204 | lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2205 | numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2206 | use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2207 | mac_address='', |
| 2208 | interface_id=0xFFFFFFFF): |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2209 | """ |
| 2210 | :param mode: mode |
| 2211 | :param lb: load balance |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2212 | :param numa_only: tx on local numa node for lacp mode |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2213 | :param use_custom_mac: use custom mac |
| 2214 | :param mac_address: mac address |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2215 | :param interface_id: custom interface ID |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2216 | """ |
| 2217 | return self.api( |
| 2218 | self.papi.bond_create, |
| 2219 | {'mode': mode, |
| 2220 | 'lb': lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 2221 | 'numa_only': numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2222 | 'use_custom_mac': use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 2223 | 'mac_address': mac_address, |
| 2224 | 'id': interface_id |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 2225 | }) |
| 2226 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 2227 | def pipe_delete(self, parent_sw_if_index): |
| 2228 | return self.api(self.papi.pipe_delete, |
| 2229 | {'parent_sw_if_index': parent_sw_if_index}) |
| 2230 | |
Neale Ranns | d1e68ab | 2018-10-01 01:42:13 -0700 | [diff] [blame] | 2231 | def svs_table_add_del(self, af, table_id, is_add=1): |
| 2232 | return self.api(self.papi.svs_table_add_del, |
| 2233 | { |
| 2234 | 'table_id': table_id, |
| 2235 | 'is_add': is_add, |
| 2236 | 'af': af, |
| 2237 | }) |
| 2238 | |
| 2239 | def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1): |
| 2240 | return self.api(self.papi.svs_route_add_del, |
| 2241 | { |
| 2242 | 'table_id': table_id, |
| 2243 | 'source_table_id': src_table_id, |
| 2244 | 'prefix': prefix, |
| 2245 | 'is_add': is_add, |
| 2246 | }) |
| 2247 | |
| 2248 | def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1): |
| 2249 | return self.api(self.papi.svs_enable_disable, |
| 2250 | { |
| 2251 | 'af': af, |
| 2252 | 'table_id': table_id, |
| 2253 | 'sw_if_index': sw_if_index, |
| 2254 | 'is_enable': is_enable, |
| 2255 | }) |