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