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