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