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