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, }, |
| 99 | 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, }, |
| 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, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 129 | 'want_l2_macs_events': {'enable_disable': 1, }, |
| 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 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 377 | def want_l2_macs_events(self, enable_disable=1, scan_delay=0, |
| 378 | max_macs_in_event=0, learn_limit=0): |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 379 | return self.api(self.papi.want_l2_macs_events, |
| 380 | {'enable_disable': enable_disable, |
| 381 | 'scan_delay': scan_delay, |
| 382 | 'max_macs_in_event': max_macs_in_event, |
| 383 | 'learn_limit': learn_limit, |
| 384 | 'pid': os.getpid(), }) |
| 385 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 386 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 387 | return self.api(self.papi.sw_interface_set_mac_address, |
| 388 | {'sw_if_index': sw_if_index, |
| 389 | 'mac_address': mac}) |
| 390 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 391 | def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 392 | """Create p2p ethernet subinterface |
| 393 | |
| 394 | :param sw_if_index: main (parent) interface |
| 395 | :param remote_mac: client (remote) mac address |
| 396 | |
| 397 | """ |
| 398 | return self.api( |
| 399 | self.papi.p2p_ethernet_add, |
| 400 | {'parent_if_index': sw_if_index, |
| 401 | 'remote_mac': remote_mac, |
| 402 | 'subif_id': subif_id}) |
| 403 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 404 | def p2p_ethernet_del(self, sw_if_index, remote_mac): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 405 | """Delete p2p ethernet subinterface |
| 406 | |
| 407 | :param sw_if_index: main (parent) interface |
| 408 | :param remote_mac: client (remote) mac address |
| 409 | |
| 410 | """ |
| 411 | return self.api( |
| 412 | self.papi.p2p_ethernet_del, |
| 413 | {'parent_if_index': sw_if_index, |
| 414 | 'remote_mac': remote_mac}) |
| 415 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 416 | def create_vlan_subif(self, sw_if_index, vlan): |
| 417 | """ |
| 418 | |
| 419 | :param vlan: |
| 420 | :param sw_if_index: |
| 421 | |
| 422 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 423 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 424 | {'sw_if_index': sw_if_index, |
| 425 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 426 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 427 | def create_loopback(self, mac=''): |
| 428 | """ |
| 429 | |
| 430 | :param mac: (Optional) |
| 431 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 432 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 433 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 434 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 435 | def ip_route_dump(self, table_id, is_ip6=False): |
| 436 | return self.api(self.papi.ip_route_dump, |
| 437 | {'table': { |
| 438 | 'table_id': table_id, |
| 439 | 'is_ip6': is_ip6 |
| 440 | }}) |
| 441 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 442 | def ip_neighbor_add_del(self, |
| 443 | sw_if_index, |
| 444 | mac_address, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 445 | ip_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 446 | is_add=1, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 447 | flags=0): |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 448 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 449 | |
| 450 | :param sw_if_index: |
| 451 | :param mac_address: |
| 452 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 453 | :param is_add: (Default value = 1) |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 454 | :param flags: (Default value = 0/NONE) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 455 | """ |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 456 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 457 | self.papi.ip_neighbor_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 458 | { |
| 459 | 'is_add': is_add, |
| 460 | 'neighbor': { |
| 461 | 'sw_if_index': sw_if_index, |
| 462 | 'flags': flags, |
| 463 | 'mac_address': mac_address, |
| 464 | 'ip_address': ip_address |
| 465 | } |
| 466 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 467 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 468 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 469 | def proxy_arp_add_del(self, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 470 | low, |
| 471 | hi, |
| 472 | table_id=0, |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 473 | is_add=1): |
| 474 | """ Config Proxy Arp Range. |
| 475 | |
| 476 | :param low_address: Start address in the rnage to Proxy for |
| 477 | :param hi_address: End address in the rnage to Proxy for |
| 478 | :param vrf_id: The VRF/table in which to proxy |
| 479 | """ |
| 480 | |
| 481 | return self.api( |
| 482 | self.papi.proxy_arp_add_del, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 483 | {'proxy': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 484 | { |
| 485 | 'table_id': table_id, |
| 486 | 'low': low, |
| 487 | 'hi': hi, |
| 488 | }, |
| 489 | 'is_add': is_add}) |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 490 | |
| 491 | def proxy_arp_intfc_enable_disable(self, |
| 492 | sw_if_index, |
| 493 | is_enable=1): |
| 494 | """ Enable/Disable an interface for proxy ARP requests |
| 495 | |
| 496 | :param sw_if_index: Interface |
| 497 | :param enable_disable: Enable/Disable |
| 498 | """ |
| 499 | |
| 500 | return self.api( |
| 501 | self.papi.proxy_arp_intfc_enable_disable, |
| 502 | {'sw_if_index': sw_if_index, |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 503 | 'enable': is_enable |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 504 | } |
| 505 | ) |
| 506 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 507 | def udp_encap_add(self, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 508 | src_ip, |
| 509 | dst_ip, |
| 510 | src_port, |
| 511 | dst_port, |
| 512 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 513 | """ Add a GRE tunnel |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 514 | :param src_ip: |
| 515 | :param dst_ip: |
| 516 | :param src_port: |
| 517 | :param dst_port: |
| 518 | :param outer_fib_id: (Default value = 0) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 519 | """ |
| 520 | |
| 521 | return self.api( |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 522 | self.papi.udp_encap_add, |
| 523 | { |
| 524 | 'udp_encap': { |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 525 | 'src_ip': src_ip, |
| 526 | 'dst_ip': dst_ip, |
| 527 | 'src_port': src_port, |
| 528 | 'dst_port': dst_port, |
| 529 | 'table_id': table_id |
| 530 | } |
| 531 | }) |
| 532 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 533 | def udp_encap_del(self, id): |
| 534 | return self.api(self.papi.udp_encap_del, {'id': id}) |
| 535 | |
| 536 | def udp_encap_dump(self): |
| 537 | return self.api(self.papi.udp_encap_dump, {}) |
| 538 | |
| 539 | def want_udp_encap_stats(self, enable=1): |
| 540 | return self.api(self.papi.want_udp_encap_stats, |
| 541 | {'enable': enable, |
| 542 | 'pid': os.getpid()}) |
| 543 | |
| 544 | def mpls_route_dump(self, table_id): |
| 545 | return self.api(self.papi.mpls_route_dump, |
| 546 | {'table': { |
| 547 | 'mt_table_id': table_id |
| 548 | }}) |
| 549 | |
| 550 | def mpls_table_dump(self): |
| 551 | return self.api(self.papi.mpls_table_dump, {}) |
| 552 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 553 | def mpls_table_add_del( |
| 554 | self, |
| 555 | table_id, |
| 556 | is_add=1): |
| 557 | """ |
| 558 | |
| 559 | :param table_id |
| 560 | :param is_add: (Default value = 1) |
| 561 | |
| 562 | """ |
| 563 | |
| 564 | return self.api( |
| 565 | self.papi.mpls_table_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 566 | {'mt_table': |
| 567 | { |
| 568 | 'mt_table_id': table_id, |
| 569 | }, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 570 | 'mt_is_add': is_add}) |
| 571 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 572 | def mpls_route_add_del(self, |
| 573 | table_id, |
| 574 | label, |
| 575 | eos, |
| 576 | eos_proto, |
| 577 | is_multicast, |
| 578 | paths, |
| 579 | is_add, |
| 580 | is_multipath): |
| 581 | """ MPLS Route add/del """ |
| 582 | return self.api( |
| 583 | self.papi.mpls_route_add_del, |
| 584 | {'mr_route': |
| 585 | { |
| 586 | 'mr_table_id': table_id, |
| 587 | 'mr_label': label, |
| 588 | 'mr_eos': eos, |
| 589 | 'mr_eos_proto': eos_proto, |
| 590 | 'mr_is_multicast': is_multicast, |
| 591 | 'mr_n_paths': len(paths), |
| 592 | 'mr_paths': paths, |
| 593 | }, |
| 594 | 'mr_is_add': is_add, |
| 595 | 'mr_is_multipath': is_multipath}) |
| 596 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 597 | def mpls_ip_bind_unbind( |
| 598 | self, |
| 599 | label, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 600 | prefix, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 601 | table_id=0, |
| 602 | ip_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 603 | is_bind=1): |
| 604 | """ |
| 605 | """ |
| 606 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 607 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 608 | {'mb_mpls_table_id': table_id, |
| 609 | 'mb_label': label, |
| 610 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 611 | 'mb_is_bind': is_bind, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 612 | 'mb_prefix': prefix}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 613 | |
| 614 | def mpls_tunnel_add_del( |
| 615 | self, |
| 616 | tun_sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 617 | paths, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 618 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 619 | l2_only=0, |
| 620 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 621 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 622 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 623 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 624 | self.papi.mpls_tunnel_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 625 | {'mt_is_add': is_add, |
| 626 | 'mt_tunnel': |
| 627 | { |
| 628 | 'mt_sw_if_index': tun_sw_if_index, |
| 629 | 'mt_l2_only': l2_only, |
| 630 | 'mt_is_multicast': is_multicast, |
| 631 | 'mt_n_paths': len(paths), |
| 632 | 'mt_paths': paths, |
| 633 | }}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 634 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 635 | def input_acl_set_interface( |
| 636 | self, |
| 637 | is_add, |
| 638 | sw_if_index, |
| 639 | ip4_table_index=0xFFFFFFFF, |
| 640 | ip6_table_index=0xFFFFFFFF, |
| 641 | l2_table_index=0xFFFFFFFF): |
| 642 | """ |
| 643 | :param is_add: |
| 644 | :param sw_if_index: |
| 645 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 646 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 647 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 648 | """ |
| 649 | |
| 650 | return self.api( |
| 651 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 652 | {'sw_if_index': sw_if_index, |
| 653 | 'ip4_table_index': ip4_table_index, |
| 654 | 'ip6_table_index': ip6_table_index, |
| 655 | 'l2_table_index': l2_table_index, |
| 656 | 'is_add': is_add}) |
| 657 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 658 | def output_acl_set_interface( |
| 659 | self, |
| 660 | is_add, |
| 661 | sw_if_index, |
| 662 | ip4_table_index=0xFFFFFFFF, |
| 663 | ip6_table_index=0xFFFFFFFF, |
| 664 | l2_table_index=0xFFFFFFFF): |
| 665 | """ |
| 666 | :param is_add: |
| 667 | :param sw_if_index: |
| 668 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 669 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 670 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 671 | """ |
| 672 | |
| 673 | return self.api( |
| 674 | self.papi.output_acl_set_interface, |
| 675 | {'sw_if_index': sw_if_index, |
| 676 | 'ip4_table_index': ip4_table_index, |
| 677 | 'ip6_table_index': ip6_table_index, |
| 678 | 'l2_table_index': l2_table_index, |
| 679 | 'is_add': is_add}) |
| 680 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 681 | def set_ipfix_exporter( |
| 682 | self, |
| 683 | collector_address, |
| 684 | src_address, |
| 685 | path_mtu, |
| 686 | template_interval, |
| 687 | vrf_id=0, |
| 688 | collector_port=4739, |
| 689 | udp_checksum=0): |
| 690 | return self.api( |
| 691 | self.papi.set_ipfix_exporter, |
| 692 | { |
| 693 | 'collector_address': collector_address, |
| 694 | 'collector_port': collector_port, |
| 695 | 'src_address': src_address, |
| 696 | 'vrf_id': vrf_id, |
| 697 | 'path_mtu': path_mtu, |
| 698 | 'template_interval': template_interval, |
| 699 | 'udp_checksum': udp_checksum, |
| 700 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 701 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 702 | def ip_mroute_add_del(self, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 703 | table_id, |
| 704 | prefix, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 705 | e_flags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 706 | rpf_id, |
| 707 | paths, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 708 | is_add=1, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 709 | is_multipath=1): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 710 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 711 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 712 | """ |
| 713 | return self.api( |
| 714 | self.papi.ip_mroute_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 715 | { |
| 716 | 'is_add': is_add, |
| 717 | 'is_multipath': is_multipath, |
| 718 | 'route': { |
| 719 | 'table_id': table_id, |
| 720 | 'entry_flags': e_flags, |
| 721 | 'rpf_id': rpf_id, |
| 722 | 'prefix': prefix, |
| 723 | 'n_paths': len(paths), |
| 724 | 'paths': paths, |
| 725 | } |
| 726 | }) |
| 727 | |
| 728 | def mfib_signal_dump(self): |
| 729 | return self.api(self.papi.mfib_signal_dump, {}) |
| 730 | |
| 731 | def ip_mroute_dump(self, table_id, is_ip6=False): |
| 732 | return self.api(self.papi.ip_mroute_dump, |
| 733 | {'table': { |
| 734 | 'table_id': table_id, |
| 735 | 'is_ip6': is_ip6 |
| 736 | }}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 737 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 738 | def lisp_enable_disable(self, is_enabled): |
| 739 | return self.api( |
| 740 | self.papi.lisp_enable_disable, |
| 741 | { |
| 742 | 'is_en': is_enabled, |
| 743 | }) |
| 744 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 745 | def lisp_add_del_locator_set(self, |
| 746 | ls_name, |
| 747 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 748 | return self.api( |
| 749 | self.papi.lisp_add_del_locator_set, |
| 750 | { |
| 751 | 'is_add': is_add, |
| 752 | 'locator_set_name': ls_name |
| 753 | }) |
| 754 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 755 | def lisp_add_del_locator(self, |
| 756 | ls_name, |
| 757 | sw_if_index, |
| 758 | priority=1, |
| 759 | weight=1, |
| 760 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 761 | return self.api( |
| 762 | self.papi.lisp_add_del_locator, |
| 763 | { |
| 764 | 'is_add': is_add, |
| 765 | 'locator_set_name': ls_name, |
| 766 | 'sw_if_index': sw_if_index, |
| 767 | 'priority': priority, |
| 768 | 'weight': weight |
| 769 | }) |
| 770 | |
| 771 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 772 | return self.api( |
| 773 | self.papi.lisp_locator_dump, |
| 774 | { |
| 775 | 'is_index_set': is_index_set, |
| 776 | 'ls_name': ls_name, |
| 777 | 'ls_index': ls_index, |
| 778 | }) |
| 779 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 780 | def lisp_add_del_local_eid(self, |
| 781 | ls_name, |
| 782 | eid_type, |
| 783 | eid, |
| 784 | prefix_len, |
| 785 | vni=0, |
| 786 | key_id=0, |
| 787 | key="", |
| 788 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 789 | return self.api( |
| 790 | self.papi.lisp_add_del_local_eid, |
| 791 | { |
| 792 | 'locator_set_name': ls_name, |
| 793 | 'is_add': is_add, |
| 794 | 'eid_type': eid_type, |
| 795 | 'eid': eid, |
| 796 | 'prefix_len': prefix_len, |
| 797 | 'vni': vni, |
| 798 | 'key_id': key_id, |
| 799 | 'key': key |
| 800 | }) |
| 801 | |
| 802 | def lisp_eid_table_dump(self, |
| 803 | eid_set=0, |
| 804 | prefix_length=0, |
| 805 | vni=0, |
| 806 | eid_type=0, |
| 807 | eid=None, |
| 808 | filter_opt=0): |
| 809 | return self.api( |
| 810 | self.papi.lisp_eid_table_dump, |
| 811 | { |
| 812 | 'eid_set': eid_set, |
| 813 | 'prefix_length': prefix_length, |
| 814 | 'vni': vni, |
| 815 | 'eid_type': eid_type, |
| 816 | 'eid': eid, |
| 817 | 'filter': filter_opt, |
| 818 | }) |
| 819 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 820 | def lisp_add_del_remote_mapping(self, |
| 821 | eid_type, |
| 822 | eid, |
| 823 | eid_prefix_len=0, |
| 824 | vni=0, |
| 825 | rlocs=[], |
| 826 | rlocs_num=0, |
| 827 | is_src_dst=0, |
| 828 | is_add=1): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 829 | return self.api( |
| 830 | self.papi.lisp_add_del_remote_mapping, |
| 831 | { |
| 832 | 'is_add': is_add, |
| 833 | 'eid_type': eid_type, |
| 834 | 'eid': eid, |
| 835 | 'eid_len': eid_prefix_len, |
| 836 | 'rloc_num': rlocs_num, |
| 837 | 'rlocs': rlocs, |
| 838 | 'vni': vni, |
| 839 | 'is_src_dst': is_src_dst, |
| 840 | }) |
| 841 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 842 | def lisp_add_del_adjacency(self, |
| 843 | leid, |
| 844 | reid, |
| 845 | leid_len, |
| 846 | reid_len, |
| 847 | eid_type, |
| 848 | is_add=1, |
| 849 | vni=0): |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 850 | return self.api( |
| 851 | self.papi.lisp_add_del_adjacency, |
| 852 | { |
| 853 | 'is_add': is_add, |
| 854 | 'vni': vni, |
| 855 | 'eid_type': eid_type, |
| 856 | 'leid': leid, |
| 857 | 'reid': reid, |
| 858 | 'leid_len': leid_len, |
| 859 | 'reid_len': reid_len, |
| 860 | }) |
| 861 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 862 | def vxlan_gpe_add_del_tunnel( |
| 863 | self, |
| 864 | src_addr, |
| 865 | dst_addr, |
| 866 | mcast_sw_if_index=0xFFFFFFFF, |
| 867 | is_add=1, |
| 868 | is_ipv6=0, |
| 869 | encap_vrf_id=0, |
| 870 | decap_vrf_id=0, |
| 871 | protocol=3, |
| 872 | vni=0): |
| 873 | """ |
| 874 | |
| 875 | :param local: |
| 876 | :param remote: |
| 877 | :param is_add: (Default value = 1) |
| 878 | :param is_ipv6: (Default value = 0) |
| 879 | :param encap_vrf_id: (Default value = 0) |
| 880 | :param decap_vrf_id: (Default value = 0) |
| 881 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 882 | :param protocol: (Default value = 3) |
| 883 | :param vni: (Default value = 0) |
| 884 | |
| 885 | """ |
| 886 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 887 | {'is_add': is_add, |
| 888 | 'is_ipv6': is_ipv6, |
| 889 | 'local': src_addr, |
| 890 | 'remote': dst_addr, |
| 891 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 892 | 'encap_vrf_id': encap_vrf_id, |
| 893 | 'decap_vrf_id': decap_vrf_id, |
| 894 | 'protocol': protocol, |
| 895 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 896 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 897 | def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): |
| 898 | return self.api(self.papi.vxlan_gbp_tunnel_dump, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 899 | {'sw_if_index': sw_if_index}) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 900 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 901 | def pppoe_add_del_session( |
| 902 | self, |
| 903 | client_ip, |
| 904 | client_mac, |
| 905 | session_id=0, |
| 906 | is_add=1, |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 907 | decap_vrf_id=0): |
| 908 | """ |
| 909 | |
| 910 | :param is_add: (Default value = 1) |
| 911 | :param is_ipv6: (Default value = 0) |
| 912 | :param client_ip: |
| 913 | :param session_id: (Default value = 0) |
| 914 | :param client_mac: |
| 915 | :param decap_vrf_id: (Default value = 0) |
| 916 | |
| 917 | """ |
| 918 | return self.api(self.papi.pppoe_add_del_session, |
| 919 | {'is_add': is_add, |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 920 | 'session_id': session_id, |
| 921 | 'client_ip': client_ip, |
| 922 | 'decap_vrf_id': decap_vrf_id, |
| 923 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 924 | |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 925 | def sr_mpls_policy_add(self, bsid, weight, type, segments): |
| 926 | return self.api(self.papi.sr_mpls_policy_add, |
| 927 | {'bsid': bsid, |
| 928 | 'weight': weight, |
| 929 | 'type': type, |
| 930 | 'n_segments': len(segments), |
| 931 | 'segments': segments}) |
| 932 | |
| 933 | def sr_mpls_policy_del(self, bsid): |
| 934 | return self.api(self.papi.sr_mpls_policy_del, |
| 935 | {'bsid': bsid}) |
| 936 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 937 | def sr_localsid_add_del(self, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 938 | localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 939 | behavior, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 940 | nh_addr4, |
| 941 | nh_addr6, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 942 | is_del=0, |
| 943 | end_psp=0, |
| 944 | sw_if_index=0xFFFFFFFF, |
| 945 | vlan_index=0, |
| 946 | fib_table=0, |
| 947 | ): |
| 948 | """ Add/del IPv6 SR local-SID. |
| 949 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 950 | :param localsid: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 951 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 952 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 953 | :param nh_addr4: |
| 954 | :param nh_addr6: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 955 | :param is_del: (Default value = 0) |
| 956 | :param end_psp: (Default value = 0) |
| 957 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 958 | :param vlan_index: (Default value = 0) |
| 959 | :param fib_table: (Default value = 0) |
| 960 | """ |
| 961 | return self.api( |
| 962 | self.papi.sr_localsid_add_del, |
| 963 | {'is_del': is_del, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 964 | 'localsid': localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 965 | 'end_psp': end_psp, |
| 966 | 'behavior': behavior, |
| 967 | 'sw_if_index': sw_if_index, |
| 968 | 'vlan_index': vlan_index, |
| 969 | 'fib_table': fib_table, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 970 | 'nh_addr4': nh_addr4, |
| 971 | 'nh_addr6': nh_addr6 |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 972 | } |
| 973 | ) |
| 974 | |
| 975 | def sr_policy_add( |
| 976 | self, |
| 977 | bsid_addr, |
| 978 | weight=1, |
| 979 | is_encap=1, |
| 980 | type=0, |
| 981 | fib_table=0, |
| 982 | n_segments=0, |
| 983 | segments=[]): |
| 984 | """ |
| 985 | :param bsid_addr: bindingSID of the SR Policy |
| 986 | :param weight: weight of the sid list. optional. (default: 1) |
| 987 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 988 | (default: Encap) |
| 989 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 990 | (default: default) |
| 991 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 992 | (default: 0) |
| 993 | :param n_segments: number of segments \ |
| 994 | (default: 0) |
| 995 | :param segments: a vector of IPv6 address composing the segment list \ |
| 996 | (default: []) |
| 997 | """ |
| 998 | return self.api( |
| 999 | self.papi.sr_policy_add, |
| 1000 | {'bsid_addr': bsid_addr, |
| 1001 | 'weight': weight, |
| 1002 | 'is_encap': is_encap, |
| 1003 | 'type': type, |
| 1004 | 'fib_table': fib_table, |
| 1005 | 'n_segments': n_segments, |
| 1006 | 'segments': segments |
| 1007 | } |
| 1008 | ) |
| 1009 | |
| 1010 | def sr_policy_del( |
| 1011 | self, |
| 1012 | bsid_addr, |
| 1013 | sr_policy_index=0): |
| 1014 | """ |
| 1015 | :param bsid: bindingSID of the SR Policy |
| 1016 | :param sr_policy_index: index of the sr policy (default: 0) |
| 1017 | """ |
| 1018 | return self.api( |
| 1019 | self.papi.sr_policy_del, |
| 1020 | {'bsid_addr': bsid_addr, |
| 1021 | 'sr_policy_index': sr_policy_index |
| 1022 | }) |
| 1023 | |
| 1024 | def sr_steering_add_del( |
| 1025 | self, |
| 1026 | is_del, |
| 1027 | bsid_addr, |
| 1028 | sr_policy_index, |
| 1029 | table_id, |
| 1030 | prefix_addr, |
| 1031 | mask_width, |
| 1032 | sw_if_index, |
| 1033 | traffic_type): |
| 1034 | """ |
| 1035 | Steer traffic L2 and L3 traffic through a given SR policy |
| 1036 | |
| 1037 | :param is_del: delete or add |
| 1038 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 1039 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 1040 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 1041 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 1042 | :param mask_width: is the mask for L3 traffic type |
| 1043 | :param sw_if_index: is the incoming interface for L2 traffic |
| 1044 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 1045 | """ |
| 1046 | return self.api( |
| 1047 | self.papi.sr_steering_add_del, |
| 1048 | {'is_del': is_del, |
| 1049 | 'bsid_addr': bsid_addr, |
| 1050 | 'sr_policy_index': sr_policy_index, |
| 1051 | 'table_id': table_id, |
| 1052 | 'prefix_addr': prefix_addr, |
| 1053 | 'mask_width': mask_width, |
| 1054 | 'sw_if_index': sw_if_index, |
| 1055 | 'traffic_type': traffic_type |
| 1056 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1057 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1058 | def acl_add_replace(self, acl_index, r, tag='', |
| 1059 | expected_retval=0): |
| 1060 | """Add/replace an ACL |
| 1061 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 1062 | :param acl_rule r: ACL rules array. |
| 1063 | :param str tag: symbolic tag (description) for this ACL. |
| 1064 | :param int count: number of rules. |
| 1065 | """ |
| 1066 | return self.api(self.papi.acl_add_replace, |
| 1067 | {'acl_index': acl_index, |
| 1068 | 'r': r, |
| 1069 | 'count': len(r), |
| 1070 | 'tag': tag}, |
| 1071 | expected_retval=expected_retval) |
| 1072 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 1073 | def acl_del(self, acl_index, expected_retval=0): |
| 1074 | """ |
| 1075 | |
| 1076 | :param acl_index: |
| 1077 | :return: |
| 1078 | """ |
| 1079 | return self.api(self.papi.acl_del, |
| 1080 | {'acl_index': acl_index}, |
| 1081 | expected_retval=expected_retval) |
| 1082 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1083 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 1084 | expected_retval=0): |
| 1085 | return self.api(self.papi.acl_interface_set_acl_list, |
| 1086 | {'sw_if_index': sw_if_index, |
| 1087 | 'count': len(acls), |
| 1088 | 'n_input': n_input, |
| 1089 | 'acls': acls}, |
| 1090 | expected_retval=expected_retval) |
| 1091 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 1092 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 1093 | n_input, whitelist, |
| 1094 | expected_retval=0): |
| 1095 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 1096 | {'sw_if_index': sw_if_index, |
| 1097 | 'count': len(whitelist), |
| 1098 | 'n_input': n_input, |
| 1099 | 'whitelist': whitelist}, |
| 1100 | expected_retval=expected_retval) |
| 1101 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 1102 | def acl_interface_add_del(self, |
| 1103 | sw_if_index, |
| 1104 | acl_index, |
| 1105 | is_add=1): |
| 1106 | """ Add/Delete ACL to/from interface |
| 1107 | |
| 1108 | :param sw_if_index: |
| 1109 | :param acl_index: |
| 1110 | :param is_add: (Default value = 1) |
| 1111 | """ |
| 1112 | |
| 1113 | return self.api(self.papi.acl_interface_add_del, |
| 1114 | {'is_add': is_add, |
| 1115 | 'is_input': 1, |
| 1116 | 'sw_if_index': sw_if_index, |
| 1117 | 'acl_index': acl_index}) |
| 1118 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 1119 | def acl_dump(self, acl_index, expected_retval=0): |
| 1120 | return self.api(self.papi.acl_dump, |
| 1121 | {'acl_index': acl_index}, |
| 1122 | expected_retval=expected_retval) |
| 1123 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 1124 | def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF, |
| 1125 | expected_retval=0): |
| 1126 | return self.api(self.papi.acl_interface_list_dump, |
| 1127 | {'sw_if_index': sw_if_index}, |
| 1128 | expected_retval=expected_retval) |
| 1129 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1130 | def macip_acl_add(self, rules, tag=""): |
| 1131 | """ Add MACIP acl |
| 1132 | |
| 1133 | :param rules: list of rules for given acl |
| 1134 | :param tag: acl tag |
| 1135 | """ |
| 1136 | |
| 1137 | return self.api(self.papi.macip_acl_add, |
| 1138 | {'r': rules, |
| 1139 | 'count': len(rules), |
| 1140 | 'tag': tag}) |
| 1141 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1142 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 1143 | """ Add MACIP acl |
| 1144 | |
| 1145 | :param rules: list of rules for given acl |
| 1146 | :param tag: acl tag |
| 1147 | """ |
| 1148 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 1149 | return self.api(self.papi.macip_acl_add_replace, |
| 1150 | {'acl_index': acl_index, |
| 1151 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1152 | 'count': len(rules), |
| 1153 | 'tag': tag}) |
| 1154 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1155 | def macip_acl_interface_add_del(self, |
| 1156 | sw_if_index, |
| 1157 | acl_index, |
| 1158 | is_add=1): |
| 1159 | """ Add MACIP acl to interface |
| 1160 | |
| 1161 | :param sw_if_index: |
| 1162 | :param acl_index: |
| 1163 | :param is_add: (Default value = 1) |
| 1164 | """ |
| 1165 | |
| 1166 | return self.api(self.papi.macip_acl_interface_add_del, |
| 1167 | {'is_add': is_add, |
| 1168 | 'sw_if_index': sw_if_index, |
| 1169 | 'acl_index': acl_index}) |
| 1170 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 1171 | def macip_acl_dump(self, acl_index=4294967295): |
| 1172 | """ Return MACIP acl dump |
| 1173 | """ |
| 1174 | |
| 1175 | return self.api( |
| 1176 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1177 | |
| 1178 | def policer_add_del(self, |
| 1179 | name, |
| 1180 | cir, |
| 1181 | eir, |
| 1182 | cb, |
| 1183 | eb, |
| 1184 | is_add=1, |
| 1185 | rate_type=0, |
| 1186 | round_type=0, |
| 1187 | ptype=0, |
| 1188 | color_aware=0, |
| 1189 | conform_action_type=1, |
| 1190 | conform_dscp=0, |
| 1191 | exceed_action_type=0, |
| 1192 | exceed_dscp=0, |
| 1193 | violate_action_type=0, |
| 1194 | violate_dscp=0): |
| 1195 | return self.api(self.papi.policer_add_del, |
| 1196 | {'name': name, |
| 1197 | 'cir': cir, |
| 1198 | 'eir': eir, |
| 1199 | 'cb': cb, |
| 1200 | 'eb': eb, |
| 1201 | 'is_add': is_add, |
| 1202 | 'rate_type': rate_type, |
| 1203 | 'round_type': round_type, |
| 1204 | 'type': ptype, |
| 1205 | 'color_aware': color_aware, |
| 1206 | 'conform_action_type': conform_action_type, |
| 1207 | 'conform_dscp': conform_dscp, |
| 1208 | 'exceed_action_type': exceed_action_type, |
| 1209 | 'exceed_dscp': exceed_dscp, |
| 1210 | 'violate_action_type': violate_action_type, |
| 1211 | 'violate_dscp': violate_dscp}) |
| 1212 | |
| 1213 | def ip_punt_police(self, |
| 1214 | policer_index, |
| 1215 | is_ip6=0, |
| 1216 | is_add=1): |
| 1217 | return self.api(self.papi.ip_punt_police, |
| 1218 | {'policer_index': policer_index, |
| 1219 | 'is_add': is_add, |
| 1220 | 'is_ip6': is_ip6}) |
| 1221 | |
| 1222 | def ip_punt_redirect(self, |
| 1223 | rx_sw_if_index, |
| 1224 | tx_sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1225 | address, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 1226 | is_add=1): |
| 1227 | return self.api(self.papi.ip_punt_redirect, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 1228 | {'punt': {'rx_sw_if_index': rx_sw_if_index, |
| 1229 | 'tx_sw_if_index': tx_sw_if_index, |
| 1230 | 'nh': address}, |
| 1231 | 'is_add': is_add}) |
| 1232 | |
| 1233 | def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0): |
| 1234 | return self.api(self.papi.ip_punt_redirect_dump, |
| 1235 | {'sw_if_index': sw_if_index, |
| 1236 | 'is_ipv6': is_ipv6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1237 | |
| 1238 | def bier_table_add_del(self, |
| 1239 | bti, |
| 1240 | mpls_label, |
| 1241 | is_add=1): |
| 1242 | """ BIER Table add/del """ |
| 1243 | return self.api( |
| 1244 | self.papi.bier_table_add_del, |
| 1245 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 1246 | "bt_sub_domain": bti.sub_domain_id, |
| 1247 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1248 | 'bt_label': mpls_label, |
| 1249 | 'bt_is_add': is_add}) |
| 1250 | |
| 1251 | def bier_table_dump(self): |
| 1252 | return self.api(self.papi.bier_table_dump, {}) |
| 1253 | |
| 1254 | def bier_route_add_del(self, |
| 1255 | bti, |
| 1256 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 1257 | paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 1258 | is_add=1, |
| 1259 | is_replace=0): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1260 | """ BIER Route add/del """ |
| 1261 | return self.api( |
| 1262 | self.papi.bier_route_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1263 | { |
| 1264 | 'br_route': { |
| 1265 | 'br_tbl_id': {"bt_set": bti.set_id, |
| 1266 | "bt_sub_domain": bti.sub_domain_id, |
| 1267 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1268 | 'br_bp': bp, |
| 1269 | 'br_n_paths': len(paths), |
| 1270 | 'br_paths': paths, |
| 1271 | }, |
| 1272 | 'br_is_add': is_add, |
| 1273 | 'br_is_replace': is_replace |
| 1274 | }) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1275 | |
| 1276 | def bier_route_dump(self, bti): |
| 1277 | return self.api( |
| 1278 | self.papi.bier_route_dump, |
| 1279 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 1280 | "bt_sub_domain": bti.sub_domain_id, |
| 1281 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 1282 | |
| 1283 | def bier_imp_add(self, |
| 1284 | bti, |
| 1285 | src, |
| 1286 | ibytes, |
| 1287 | is_add=1): |
| 1288 | """ BIER Imposition Add """ |
| 1289 | return self.api( |
| 1290 | self.papi.bier_imp_add, |
| 1291 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 1292 | "bt_sub_domain": bti.sub_domain_id, |
| 1293 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 1294 | 'bi_src': src, |
| 1295 | 'bi_n_bytes': len(ibytes), |
| 1296 | 'bi_bytes': ibytes}) |
| 1297 | |
| 1298 | def bier_imp_del(self, bi_index): |
| 1299 | """ BIER Imposition del """ |
| 1300 | return self.api( |
| 1301 | self.papi.bier_imp_del, |
| 1302 | {'bi_index': bi_index}) |
| 1303 | |
| 1304 | def bier_imp_dump(self): |
| 1305 | return self.api(self.papi.bier_imp_dump, {}) |
| 1306 | |
| 1307 | def bier_disp_table_add_del(self, |
| 1308 | bdti, |
| 1309 | is_add=1): |
| 1310 | """ BIER Disposition Table add/del """ |
| 1311 | return self.api( |
| 1312 | self.papi.bier_disp_table_add_del, |
| 1313 | {'bdt_tbl_id': bdti, |
| 1314 | 'bdt_is_add': is_add}) |
| 1315 | |
| 1316 | def bier_disp_table_dump(self): |
| 1317 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 1318 | |
| 1319 | def bier_disp_entry_add_del(self, |
| 1320 | bdti, |
| 1321 | bp, |
| 1322 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 1323 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1324 | next_hop, |
| 1325 | next_hop_tbl_id=0, |
| 1326 | next_hop_rpf_id=~0, |
| 1327 | next_hop_is_ip4=1, |
| 1328 | is_add=1): |
| 1329 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1330 | lstack = [] |
| 1331 | while (len(lstack) < 16): |
| 1332 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1333 | return self.api( |
| 1334 | self.papi.bier_disp_entry_add_del, |
| 1335 | {'bde_tbl_id': bdti, |
| 1336 | 'bde_bp': bp, |
| 1337 | 'bde_payload_proto': payload_proto, |
| 1338 | 'bde_n_paths': 1, |
Paul Vinciguerra | 79a32a4 | 2019-07-11 19:09:30 -0400 | [diff] [blame] | 1339 | 'bde_paths': [{'table_id': next_hop_tbl_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1340 | 'rpf_id': next_hop_rpf_id, |
| 1341 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1342 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1343 | 'bde_is_add': is_add}) |
| 1344 | |
| 1345 | def bier_disp_entry_dump(self, bdti): |
| 1346 | return self.api( |
| 1347 | self.papi.bier_disp_entry_dump, |
| 1348 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 1349 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 1350 | def session_enable_disable(self, is_enabled): |
| 1351 | return self.api( |
| 1352 | self.papi.session_enable_disable, |
| 1353 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1354 | |
| 1355 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 1356 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 1357 | Sample CLI : 'ipsec spd add 1' |
| 1358 | |
| 1359 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 1360 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 1361 | optional |
| 1362 | :returns: reply from the API |
| 1363 | """ |
| 1364 | return self.api( |
| 1365 | self.papi.ipsec_spd_add_del, { |
| 1366 | 'spd_id': spd_id, 'is_add': is_add}) |
| 1367 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1368 | def ipsec_spds_dump(self): |
| 1369 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 1370 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1371 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 1372 | """ IPSEC interface SPD add/del - \ |
| 1373 | Wrapper to associate/disassociate SPD to interface in VPP |
| 1374 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 1375 | |
| 1376 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 1377 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 1378 | association mandatory |
| 1379 | :param is_add - add(1) or del(0) association with interface \ |
| 1380 | (Default 1 - add) . optional |
| 1381 | :returns: reply from the API |
| 1382 | """ |
| 1383 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 1384 | self.papi.ipsec_interface_add_del_spd, |
| 1385 | {'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] | 1386 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1387 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 1388 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 1389 | {'spd_index': spd_index if spd_index else 0, |
| 1390 | 'spd_index_valid': 1 if spd_index else 0}) |
| 1391 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1392 | def ipsec_sad_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1393 | sad_id, |
| 1394 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1395 | integrity_algorithm, |
| 1396 | integrity_key, |
| 1397 | crypto_algorithm, |
| 1398 | crypto_key, |
| 1399 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1400 | tunnel_src_address='', |
| 1401 | tunnel_dst_address='', |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1402 | flags=0, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1403 | salt=0, |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1404 | is_add=1): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1405 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1406 | :param sad_id: security association ID |
| 1407 | :param spi: security param index of the SA in decimal |
| 1408 | :param integrity_algorithm: |
| 1409 | :param integrity_key: |
| 1410 | :param crypto_algorithm: |
| 1411 | :param crypto_key: |
| 1412 | :param protocol: AH(0) or ESP(1) protocol |
| 1413 | :param tunnel_src_address: tunnel mode outer src address |
| 1414 | :param tunnel_dst_address: tunnel mode outer dst address |
| 1415 | :param is_add: |
| 1416 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1417 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 1418 | crypto and ipsec algorithms |
| 1419 | """ |
| 1420 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1421 | self.papi.ipsec_sad_entry_add_del, |
| 1422 | { |
| 1423 | 'is_add': is_add, |
| 1424 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1425 | { |
| 1426 | 'sad_id': sad_id, |
| 1427 | 'spi': spi, |
| 1428 | 'tunnel_src': tunnel_src_address, |
| 1429 | 'tunnel_dst': tunnel_dst_address, |
| 1430 | 'protocol': protocol, |
| 1431 | 'integrity_algorithm': integrity_algorithm, |
| 1432 | 'integrity_key': { |
| 1433 | 'length': len(integrity_key), |
| 1434 | 'data': integrity_key, |
| 1435 | }, |
| 1436 | 'crypto_algorithm': crypto_algorithm, |
| 1437 | 'crypto_key': { |
| 1438 | 'length': len(crypto_key), |
| 1439 | 'data': crypto_key, |
| 1440 | }, |
| 1441 | 'flags': flags, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1442 | 'salt': salt, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1443 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1444 | }) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1445 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1446 | def ipsec_sa_dump(self, sa_id=None): |
| 1447 | return self.api(self.papi.ipsec_sa_dump, |
| 1448 | {'sa_id': sa_id if sa_id else 0xffffffff}) |
| 1449 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1450 | def ipsec_spd_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1451 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1452 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1453 | local_address_start, |
| 1454 | local_address_stop, |
| 1455 | remote_address_start, |
| 1456 | remote_address_stop, |
| 1457 | local_port_start=0, |
| 1458 | local_port_stop=65535, |
| 1459 | remote_port_start=0, |
| 1460 | remote_port_stop=65535, |
| 1461 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1462 | policy=0, |
| 1463 | priority=100, |
| 1464 | is_outbound=1, |
| 1465 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 1466 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1467 | is_ip_any=0): |
| 1468 | """ IPSEC policy SPD add/del - |
| 1469 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1470 | :param spd_id: SPD ID for the policy |
| 1471 | :param local_address_start: local-ip-range start address |
| 1472 | :param local_address_stop : local-ip-range stop address |
| 1473 | :param remote_address_start: remote-ip-range start address |
| 1474 | :param remote_address_stop : remote-ip-range stop address |
| 1475 | :param local_port_start: (Default value = 0) |
| 1476 | :param local_port_stop: (Default value = 65535) |
| 1477 | :param remote_port_start: (Default value = 0) |
| 1478 | :param remote_port_stop: (Default value = 65535) |
| 1479 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 1480 | :param sa_id: Security Association ID for mapping it to SPD |
| 1481 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 1482 | (Default value = 0) |
| 1483 | :param priority: value for the spd action (Default value = 100) |
| 1484 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 1485 | (Default value = 1) |
| 1486 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1487 | """ |
| 1488 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1489 | self.papi.ipsec_spd_entry_add_del, |
| 1490 | { |
| 1491 | 'is_add': is_add, |
| 1492 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1493 | { |
| 1494 | 'spd_id': spd_id, |
| 1495 | 'sa_id': sa_id, |
| 1496 | 'local_address_start': local_address_start, |
| 1497 | 'local_address_stop': local_address_stop, |
| 1498 | 'remote_address_start': remote_address_start, |
| 1499 | 'remote_address_stop': remote_address_stop, |
| 1500 | 'local_port_start': local_port_start, |
| 1501 | 'local_port_stop': local_port_stop, |
| 1502 | 'remote_port_start': remote_port_start, |
| 1503 | 'remote_port_stop': remote_port_stop, |
| 1504 | 'protocol': protocol, |
| 1505 | 'policy': policy, |
| 1506 | 'priority': priority, |
| 1507 | 'is_outbound': is_outbound, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1508 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 1509 | }) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1510 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 1511 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 1512 | return self.api(self.papi.ipsec_spd_dump, |
| 1513 | {'spd_id': spd_id, |
| 1514 | 'sa_id': sa_id}) |
| 1515 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1516 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 1517 | remote_spi, crypto_alg, local_crypto_key, |
| 1518 | remote_crypto_key, integ_alg, local_integ_key, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1519 | remote_integ_key, is_add=1, esn=0, salt=0, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1520 | anti_replay=1, renumber=0, |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 1521 | udp_encap=0, show_instance=0xffffffff): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1522 | return self.api( |
| 1523 | self.papi.ipsec_tunnel_if_add_del, |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1524 | { |
| 1525 | 'local_ip': local_ip, |
| 1526 | 'remote_ip': remote_ip, |
| 1527 | 'local_spi': local_spi, |
| 1528 | 'remote_spi': remote_spi, |
| 1529 | 'crypto_alg': crypto_alg, |
| 1530 | 'local_crypto_key_len': len(local_crypto_key), |
| 1531 | 'local_crypto_key': local_crypto_key, |
| 1532 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 1533 | 'remote_crypto_key': remote_crypto_key, |
| 1534 | 'integ_alg': integ_alg, |
| 1535 | 'local_integ_key_len': len(local_integ_key), |
| 1536 | 'local_integ_key': local_integ_key, |
| 1537 | 'remote_integ_key_len': len(remote_integ_key), |
| 1538 | 'remote_integ_key': remote_integ_key, |
| 1539 | 'is_add': is_add, |
| 1540 | 'esn': esn, |
| 1541 | 'anti_replay': anti_replay, |
| 1542 | 'renumber': renumber, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1543 | 'show_instance': show_instance, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 1544 | 'udp_encap': udp_encap, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 1545 | 'salt': salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 1546 | }) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 1547 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 1548 | def ipsec_select_backend(self, protocol, index): |
| 1549 | return self.api(self.papi.ipsec_select_backend, |
| 1550 | {'protocol': protocol, 'index': index}) |
| 1551 | |
| 1552 | def ipsec_backend_dump(self): |
| 1553 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 1554 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 1555 | def app_namespace_add_del(self, |
| 1556 | namespace_id, |
| 1557 | ip4_fib_id=0, |
| 1558 | ip6_fib_id=0, |
| 1559 | sw_if_index=0xFFFFFFFF, |
| 1560 | secret=0): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 1561 | return self.api( |
| 1562 | self.papi.app_namespace_add_del, |
| 1563 | {'secret': secret, |
| 1564 | 'sw_if_index': sw_if_index, |
| 1565 | 'ip4_fib_id': ip4_fib_id, |
| 1566 | 'ip6_fib_id': ip6_fib_id, |
| 1567 | 'namespace_id': namespace_id, |
| 1568 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1569 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1570 | def punt_socket_register(self, reg, pathname, |
| 1571 | header_version=1): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1572 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1573 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1574 | {'header_version': header_version, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1575 | 'punt': reg, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1576 | 'pathname': pathname}) |
| 1577 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1578 | def punt_socket_deregister(self, reg): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 1579 | """ Unregister punt socket """ |
| 1580 | return self.api(self.papi.punt_socket_deregister, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 1581 | {'punt': reg}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 1582 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1583 | def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1584 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1585 | """ GBP endpoint Add """ |
| 1586 | return self.api(self.papi.gbp_endpoint_add, |
| 1587 | {'endpoint': { |
| 1588 | 'sw_if_index': sw_if_index, |
| 1589 | 'ips': ips, |
| 1590 | 'n_ips': len(ips), |
| 1591 | 'mac': mac, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1592 | 'sclass': sclass, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1593 | 'flags': flags, |
| 1594 | 'tun': { |
| 1595 | 'src': tun_src, |
| 1596 | 'dst': tun_dst, |
| 1597 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1598 | |
| 1599 | def gbp_endpoint_del(self, handle): |
| 1600 | """ GBP endpoint Del """ |
| 1601 | return self.api(self.papi.gbp_endpoint_del, |
| 1602 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1603 | |
| 1604 | def gbp_endpoint_dump(self): |
| 1605 | """ GBP endpoint Dump """ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1606 | return self.api(self.papi.gbp_endpoint_dump, {}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1607 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1608 | def gbp_endpoint_group_add(self, vnid, sclass, bd, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1609 | rd, uplink_sw_if_index, |
| 1610 | retention): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1611 | """ GBP endpoint group Add """ |
| 1612 | return self.api(self.papi.gbp_endpoint_group_add, |
| 1613 | {'epg': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1614 | { |
| 1615 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 1616 | 'bd_id': bd, |
| 1617 | 'rd_id': rd, |
| 1618 | 'vnid': vnid, |
| 1619 | 'sclass': sclass, |
| 1620 | 'retention': retention |
| 1621 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1622 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1623 | def gbp_endpoint_group_del(self, sclass): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1624 | """ GBP endpoint group Del """ |
| 1625 | return self.api(self.papi.gbp_endpoint_group_del, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1626 | {'sclass': sclass}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1627 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1628 | def gbp_bridge_domain_add(self, bd_id, rd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1629 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1630 | uu_fwd_sw_if_index, |
| 1631 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1632 | """ GBP bridge-domain Add """ |
| 1633 | return self.api(self.papi.gbp_bridge_domain_add, |
| 1634 | {'bd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1635 | { |
| 1636 | 'flags': flags, |
| 1637 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 1638 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
| 1639 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1640 | 'bd_id': bd_id, |
| 1641 | 'rd_id': rd_id |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1642 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1643 | |
| 1644 | def gbp_bridge_domain_del(self, bd_id): |
| 1645 | """ GBP bridge-domain Del """ |
| 1646 | return self.api(self.papi.gbp_bridge_domain_del, |
| 1647 | {'bd_id': bd_id}) |
| 1648 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1649 | def gbp_route_domain_add(self, rd_id, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1650 | scope, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1651 | ip4_table_id, |
| 1652 | ip6_table_id, |
| 1653 | ip4_uu_sw_if_index, |
| 1654 | ip6_uu_sw_if_index): |
| 1655 | """ GBP route-domain Add """ |
| 1656 | return self.api(self.papi.gbp_route_domain_add, |
| 1657 | {'rd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1658 | { |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1659 | 'scope': scope, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1660 | 'ip4_table_id': ip4_table_id, |
| 1661 | 'ip6_table_id': ip6_table_id, |
| 1662 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 1663 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 1664 | 'rd_id': rd_id |
| 1665 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1666 | |
| 1667 | def gbp_route_domain_del(self, rd_id): |
| 1668 | """ GBP route-domain Del """ |
| 1669 | return self.api(self.papi.gbp_route_domain_del, |
| 1670 | {'rd_id': rd_id}) |
| 1671 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1672 | 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] | 1673 | """ GBP recirc Add/Del """ |
| 1674 | return self.api(self.papi.gbp_recirc_add_del, |
| 1675 | {'is_add': is_add, |
| 1676 | 'recirc': { |
| 1677 | 'is_ext': is_ext, |
| 1678 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1679 | 'sclass': sclass}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1680 | |
| 1681 | def gbp_recirc_dump(self): |
| 1682 | """ GBP recirc Dump """ |
| 1683 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 1684 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 1685 | 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] | 1686 | """ GBP recirc Add/Del """ |
| 1687 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 1688 | {'is_add': is_add, |
| 1689 | 'ext_itf': { |
| 1690 | 'sw_if_index': sw_if_index, |
| 1691 | 'bd_id': bd_id, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 1692 | 'rd_id': rd_id, |
| 1693 | 'flags': flags}}) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 1694 | |
| 1695 | def gbp_ext_itf_dump(self): |
| 1696 | """ GBP recirc Dump """ |
| 1697 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 1698 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1699 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 1700 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1701 | sw_if_index=0xffffffff, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1702 | sclass=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1703 | """ GBP Subnet Add/Del """ |
| 1704 | return self.api(self.papi.gbp_subnet_add_del, |
| 1705 | {'is_add': is_add, |
| 1706 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1707 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1708 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1709 | 'sclass': sclass, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1710 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1711 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1712 | |
| 1713 | def gbp_subnet_dump(self): |
| 1714 | """ GBP Subnet Dump """ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1715 | return self.api(self.papi.gbp_subnet_dump, {}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1716 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1717 | def gbp_contract_dump(self): |
| 1718 | """ GBP contract Dump """ |
| 1719 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 1720 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1721 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1722 | """ GBP VXLAN tunnel add """ |
| 1723 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 1724 | { |
| 1725 | 'tunnel': { |
| 1726 | 'vni': vni, |
| 1727 | 'mode': mode, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1728 | 'bd_rd_id': bd_rd_id, |
| 1729 | 'src': src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1730 | } |
| 1731 | }) |
| 1732 | |
| 1733 | def gbp_vxlan_tunnel_del(self, vni): |
| 1734 | """ GBP VXLAN tunnel del """ |
| 1735 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 1736 | { |
| 1737 | 'vni': vni, |
| 1738 | }) |
| 1739 | |
| 1740 | def gbp_vxlan_tunnel_dump(self): |
| 1741 | """ GBP VXLAN tunnel add/del """ |
| 1742 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 1743 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1744 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 1745 | """ Enable/disable IGMP on a given interface """ |
| 1746 | return self.api(self.papi.igmp_enable_disable, |
| 1747 | {'enable': enable, |
| 1748 | 'mode': host, |
| 1749 | 'sw_if_index': sw_if_index}) |
| 1750 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 1751 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 1752 | """ Add/del IGMP proxy device """ |
| 1753 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 1754 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 1755 | 'add': add}) |
| 1756 | |
| 1757 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 1758 | """ Add/del interface to/from IGMP proxy device """ |
| 1759 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 1760 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 1761 | 'add': add}) |
| 1762 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1763 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1764 | """ Listen for new (S,G) on specified interface |
| 1765 | |
| 1766 | :param enable: add/del |
| 1767 | :param sw_if_index: interface sw index |
| 1768 | :param saddr: source ip4 addr |
| 1769 | :param gaddr: group ip4 addr |
| 1770 | """ |
| 1771 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1772 | { |
| 1773 | 'group': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1774 | { |
| 1775 | 'filter': filter, |
| 1776 | 'sw_if_index': sw_if_index, |
| 1777 | 'n_srcs': len(saddrs), |
| 1778 | 'saddrs': saddrs, |
| 1779 | 'gaddr': gaddr |
| 1780 | } |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1781 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1782 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1783 | def igmp_clear_interface(self, sw_if_index): |
| 1784 | """ Remove all (S,G)s from specified interface |
| 1785 | doesn't send IGMP report! |
| 1786 | """ |
| 1787 | return self.api( |
| 1788 | self.papi.igmp_clear_interface, { |
| 1789 | 'sw_if_index': sw_if_index}) |
| 1790 | |
| 1791 | def want_igmp_events(self, enable=1): |
| 1792 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 1793 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1794 | |
| 1795 | def bond_create( |
| 1796 | self, |
| 1797 | mode, |
| 1798 | lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 1799 | numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1800 | use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 1801 | mac_address='', |
| 1802 | interface_id=0xFFFFFFFF): |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1803 | """ |
| 1804 | :param mode: mode |
| 1805 | :param lb: load balance |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 1806 | :param numa_only: tx on local numa node for lacp mode |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1807 | :param use_custom_mac: use custom mac |
| 1808 | :param mac_address: mac address |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 1809 | :param interface_id: custom interface ID |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1810 | """ |
| 1811 | return self.api( |
| 1812 | self.papi.bond_create, |
| 1813 | {'mode': mode, |
| 1814 | 'lb': lb, |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 1815 | 'numa_only': numa_only, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1816 | 'use_custom_mac': use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 1817 | 'mac_address': mac_address, |
| 1818 | 'id': interface_id |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1819 | }) |
| 1820 | |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 1821 | def pipe_delete(self, parent_sw_if_index): |
| 1822 | return self.api(self.papi.pipe_delete, |
| 1823 | {'parent_sw_if_index': parent_sw_if_index}) |
| 1824 | |
Neale Ranns | d1e68ab | 2018-10-01 01:42:13 -0700 | [diff] [blame] | 1825 | def svs_table_add_del(self, af, table_id, is_add=1): |
| 1826 | return self.api(self.papi.svs_table_add_del, |
| 1827 | { |
| 1828 | 'table_id': table_id, |
| 1829 | 'is_add': is_add, |
| 1830 | 'af': af, |
| 1831 | }) |
| 1832 | |
| 1833 | def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1): |
| 1834 | return self.api(self.papi.svs_route_add_del, |
| 1835 | { |
| 1836 | 'table_id': table_id, |
| 1837 | 'source_table_id': src_table_id, |
| 1838 | 'prefix': prefix, |
| 1839 | 'is_add': is_add, |
| 1840 | }) |
| 1841 | |
| 1842 | def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1): |
| 1843 | return self.api(self.papi.svs_enable_disable, |
| 1844 | { |
| 1845 | 'af': af, |
| 1846 | 'table_id': table_id, |
| 1847 | 'sw_if_index': sw_if_index, |
| 1848 | 'is_enable': is_enable, |
| 1849 | }) |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 1850 | |
| 1851 | def feature_gso_enable_disable(self, sw_if_index, enable_disable=1): |
| 1852 | return self.api(self.papi.feature_gso_enable_disable, |
| 1853 | { |
| 1854 | 'sw_if_index': sw_if_index, |
| 1855 | 'enable_disable': enable_disable, |
| 1856 | }) |