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