Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1 | # NB NB NB NB NB NB NB NB NB NB NB |
| 2 | # |
| 3 | # NOTE: The API binary wrappers in this file are in the process of being |
| 4 | # deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using |
| 5 | # named arguments directly instead. |
| 6 | # |
| 7 | |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 8 | import os |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 9 | import time |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 10 | from collections import deque |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 11 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 12 | from six import moves, iteritems |
Paul Vinciguerra | 1954229 | 2019-03-17 17:34:46 -0700 | [diff] [blame] | 13 | from vpp_papi import VPPApiClient, mac_pton |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 14 | from hook import Hook |
Paul Vinciguerra | b5f15bd | 2019-03-17 08:42:58 -0700 | [diff] [blame] | 15 | from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 16 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 17 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 18 | # |
| 19 | # Dictionary keyed on message name to override default values for |
| 20 | # named parameters |
| 21 | # |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 22 | defaultmapping = { |
Paul Vinciguerra | c0e9441 | 2020-04-28 01:12:04 -0400 | [diff] [blame] | 23 | |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 24 | 'acl_interface_add_del': {'is_add': 1, 'is_input': 1}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 25 | 'bd_ip_mac_add_del': {'is_add': 1, }, |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 26 | 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None, |
| 27 | 'conf_key_id': None}, |
| 28 | 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None, |
| 29 | 'is_delayed': False}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 30 | 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1, |
| 31 | 'is_add': 1, }, |
| 32 | 'bier_disp_table_add_del': {'is_add': 1, }, |
| 33 | 'bier_imp_add': {'is_add': 1, }, |
| 34 | 'bier_route_add_del': {'is_add': 1, }, |
| 35 | 'bier_table_add_del': {'is_add': 1, }, |
| 36 | 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1, |
| 37 | 'learn': 1, 'is_add': 1, }, |
Paul Vinciguerra | 9a29f79 | 2019-04-30 20:44:25 -0700 | [diff] [blame] | 38 | 'bvi_delete': {}, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 39 | 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, }, |
| 40 | 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 41 | 'decap_next_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 42 | 'input_acl_set_interface': {'ip4_table_index': 4294967295, |
| 43 | 'ip6_table_index': 4294967295, |
| 44 | 'l2_table_index': 4294967295, }, |
| 45 | 'ip6_add_del_address_using_prefix': {'is_add': 1, }, |
| 46 | 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, }, |
| 47 | 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295, |
| 48 | 'next_hop_weight': 1, 'next_hop_via_label': 1048576, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 49 | 'classify_table_index': 4294967295, 'is_add': 1, }, |
| 50 | 'ip_mroute_add_del': {'is_add': 1, }, |
| 51 | 'ip_neighbor_add_del': {'is_add': 1, }, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 52 | 'ip_route_add_del': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 53 | 'ipsec_interface_add_del_spd': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 54 | 'ipsec_spd_add_del': {'is_add': 1, }, |
| 55 | 'ipsec_spd_dump': {'sa_id': 4294967295, }, |
| 56 | 'ipsec_spd_entry_add_del': {'local_port_stop': 65535, |
| 57 | 'remote_port_stop': 65535, 'priority': 100, |
| 58 | 'is_outbound': 1, |
| 59 | 'is_add': 1, }, |
| 60 | 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, }, |
| 61 | 'l2_emulation': {'enable': 1, }, |
| 62 | 'l2fib_add_del': {'is_add': 1, }, |
| 63 | 'lisp_add_del_adjacency': {'is_add': 1, }, |
| 64 | 'lisp_add_del_local_eid': {'is_add': 1, }, |
| 65 | 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, }, |
| 66 | 'lisp_add_del_locator_set': {'is_add': 1, }, |
| 67 | 'lisp_add_del_remote_mapping': {'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 68 | 'macip_acl_interface_add_del': {'is_add': 1, }, |
| 69 | 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, }, |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 70 | 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295, |
| 71 | 'mr_next_hop_weight': 1, |
| 72 | 'mr_next_hop_via_label': 1048576, |
| 73 | 'mr_is_add': 1, |
| 74 | 'mr_classify_table_index': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 75 | 'mpls_table_add_del': {'is_add': 1, }, |
| 76 | 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295, |
| 77 | 'next_hop_weight': 1, |
| 78 | 'next_hop_via_label': 1048576, |
| 79 | 'is_add': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 80 | 'output_acl_set_interface': {'ip4_table_index': 4294967295, |
| 81 | 'ip6_table_index': 4294967295, |
| 82 | 'l2_table_index': 4294967295, }, |
| 83 | 'pppoe_add_del_session': {'is_add': 1, }, |
Jakub Grajciar | cd01fb4 | 2020-03-02 13:16:53 +0100 | [diff] [blame] | 84 | 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 85 | 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1, |
| 86 | 'proto': 1, }, |
| 87 | 'set_ipfix_exporter': {'collector_port': 4739, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 88 | 'sr_policy_add': {'weight': 1, 'is_encap': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 89 | 'sw_interface_add_del_address': {'is_add': 1, }, |
| 90 | 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295, |
| 91 | 'pref_lifetime': 4294967295, }, |
| 92 | 'sw_interface_set_ip_directed_broadcast': {'enable': 1, }, |
| 93 | 'sw_interface_set_l2_bridge': {'enable': 1, }, |
| 94 | 'sw_interface_set_mpls_enable': {'enable': 1, }, |
| 95 | 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], }, |
| 96 | 'sw_interface_set_unnumbered': {'is_add': 1, }, |
| 97 | 'sw_interface_span_enable_disable': {'state': 1, }, |
| 98 | 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 99 | 'decap_next_index': 4294967295, |
| 100 | 'instance': 4294967295, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 101 | 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1, |
| 102 | 'protocol': 3, }, |
| 103 | 'want_bfd_events': {'enable_disable': 1, }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 104 | 'want_igmp_events': {'enable': 1, }, |
| 105 | 'want_interface_events': {'enable_disable': 1, }, |
Jakub Grajciar | 145e330 | 2019-10-24 13:52:42 +0200 | [diff] [blame] | 106 | 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), }, |
Jerome Tollet | 0f8d100 | 2021-01-07 12:44:17 +0100 | [diff] [blame] | 107 | 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), }, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 108 | } |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 109 | |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 110 | |
Paul Vinciguerra | 0b0a84c | 2020-05-02 10:40:33 -0400 | [diff] [blame] | 111 | def as_fn_signature(d): |
| 112 | return ", ".join(f"{k}={v}" for k, v in d.items()) |
| 113 | |
| 114 | |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 115 | class CliFailedCommandError(Exception): |
| 116 | """ cli command failed.""" |
| 117 | |
| 118 | |
| 119 | class CliSyntaxError(Exception): |
| 120 | """ cli command had a syntax error.""" |
| 121 | |
| 122 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 123 | class UnexpectedApiReturnValueError(Exception): |
| 124 | """ exception raised when the API return value is unexpected """ |
| 125 | pass |
| 126 | |
| 127 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 128 | class VppPapiProvider(object): |
| 129 | """VPP-api provider using vpp-papi |
| 130 | |
| 131 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 132 | """ |
| 133 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 134 | _zero, _negative = range(2) |
| 135 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 136 | def __init__(self, name, shm_prefix, test_class, read_timeout): |
Paul Vinciguerra | 895e2f8 | 2019-01-08 20:37:40 -0800 | [diff] [blame] | 137 | self.hook = Hook(test_class) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 138 | self.name = name |
| 139 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 140 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 141 | self._expect_api_retval = self._zero |
| 142 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 143 | |
Paul Vinciguerra | 1954229 | 2019-03-17 17:34:46 -0700 | [diff] [blame] | 144 | # install_dir is a class attribute. We need to set it before |
| 145 | # calling the constructor. |
| 146 | VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH') |
Paul Vinciguerra | 04575c5 | 2019-01-13 10:26:05 -0800 | [diff] [blame] | 147 | |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 148 | use_socket = False |
| 149 | try: |
| 150 | if os.environ['SOCKET'] == '1': |
| 151 | use_socket = True |
Paul Vinciguerra | bff9f2f | 2019-05-09 16:12:35 -0400 | [diff] [blame] | 152 | except KeyError: |
Ole Troan | 4ff09ae | 2019-04-15 11:27:22 +0200 | [diff] [blame] | 153 | pass |
Paul Vinciguerra | 1954229 | 2019-03-17 17:34:46 -0700 | [diff] [blame] | 154 | |
| 155 | self.vpp = VPPApiClient(logger=test_class.logger, |
| 156 | read_timeout=read_timeout, |
| 157 | use_socket=use_socket, |
| 158 | server_address=test_class.api_sock) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 159 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 160 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 161 | def __enter__(self): |
| 162 | return self |
| 163 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 164 | def assert_negative_api_retval(self): |
| 165 | """ Expect API failure - used with with, e.g.: |
| 166 | with self.vapi.assert_negative_api_retval(): |
| 167 | self.vapi.<api call expected to fail> |
| 168 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 169 | self._expect_stack.append(self._expect_api_retval) |
| 170 | self._expect_api_retval = self._negative |
| 171 | return self |
| 172 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 173 | def assert_zero_api_retval(self): |
| 174 | """ Expect API success - used with with, e.g.: |
| 175 | with self.vapi.assert_negative_api_retval(): |
| 176 | self.vapi.<api call expected to succeed> |
| 177 | |
| 178 | note: this is useful only inside another with block |
| 179 | as success is the default expected value |
| 180 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 181 | self._expect_stack.append(self._expect_api_retval) |
| 182 | self._expect_api_retval = self._zero |
| 183 | return self |
| 184 | |
| 185 | def __exit__(self, exc_type, exc_value, traceback): |
| 186 | self._expect_api_retval = self._expect_stack.pop() |
| 187 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 188 | def register_hook(self, hook): |
| 189 | """Replace hook registration with new hook |
| 190 | |
| 191 | :param hook: |
| 192 | |
| 193 | """ |
| 194 | self.hook = hook |
| 195 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 196 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 197 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 198 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 199 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 200 | return e |
| 201 | |
| 202 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 203 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 204 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 205 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 206 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 207 | else: |
| 208 | self.test_class.logger.debug("Expecting event within %ss", |
| 209 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 210 | if self._events: |
| 211 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 212 | limit = time.time() + timeout |
| 213 | while time.time() < limit: |
| 214 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 215 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 216 | if name and type(e).__name__ != name: |
| 217 | raise Exception( |
| 218 | "Unexpected event received: %s, expected: %s" % |
| 219 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 220 | self.test_class.logger.debug("Returning event %s:%s" % |
| 221 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 222 | return e |
Paul Vinciguerra | 0f6602c | 2019-03-10 09:10:54 -0700 | [diff] [blame] | 223 | self.test_class.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 224 | raise Exception("Event did not occur within timeout") |
| 225 | |
| 226 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 227 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 228 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 229 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 230 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 231 | self._events.append(event) |
| 232 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 233 | def factory(self, name, apifn): |
| 234 | def f(*a, **ka): |
| 235 | fields = apifn._func.msg.fields |
| 236 | |
| 237 | # add positional and kw arguments |
| 238 | d = ka |
| 239 | for i, o in enumerate(fields[3:]): |
| 240 | try: |
| 241 | d[o] = a[i] |
Jakub Grajciar | 4682feb | 2019-09-02 13:28:52 +0200 | [diff] [blame] | 242 | except BaseException: |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 243 | break |
| 244 | |
| 245 | # Default override |
| 246 | if name in defaultmapping: |
| 247 | for k, v in iteritems(defaultmapping[name]): |
| 248 | if k in d: |
| 249 | continue |
| 250 | d[k] = v |
| 251 | return self.api(apifn, d) |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 252 | |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 253 | return f |
| 254 | |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 255 | def __getattribute__(self, name): |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 256 | try: |
Paul Vinciguerra | 7ab9970 | 2019-03-05 04:30:04 -0800 | [diff] [blame] | 257 | method = super(VppPapiProvider, self).__getattribute__(name) |
| 258 | except AttributeError: |
| 259 | method = self.factory(name, getattr(self.papi, name)) |
| 260 | # lazily load the method so we don't need to call factory |
| 261 | # again for this name. |
| 262 | setattr(self, name, method) |
| 263 | return method |
Ole Troan | f159f58 | 2019-02-28 20:20:47 +0100 | [diff] [blame] | 264 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 265 | def connect(self): |
| 266 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 267 | self.vpp.connect(self.name, self.shm_prefix) |
| 268 | self.papi = self.vpp.api |
| 269 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 270 | |
| 271 | def disconnect(self): |
| 272 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 273 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 274 | |
| 275 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 276 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 277 | Call the appropriate hooks before and after the API call |
| 278 | |
| 279 | :param api_fn: API function to call |
| 280 | :param api_args: tuple of API function arguments |
| 281 | :param expected_retval: Expected return value (Default value = 0) |
| 282 | :returns: reply from the API |
| 283 | |
| 284 | """ |
| 285 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 286 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 287 | if self._expect_api_retval == self._negative: |
| 288 | if hasattr(reply, 'retval') and reply.retval >= 0: |
Paul Vinciguerra | 0b0a84c | 2020-05-02 10:40:33 -0400 | [diff] [blame] | 289 | msg = "%s(%s) passed unexpectedly: expected negative " \ |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 290 | "return value instead of %d in %s" % \ |
Paul Vinciguerra | 0b0a84c | 2020-05-02 10:40:33 -0400 | [diff] [blame] | 291 | (api_fn.__name__, as_fn_signature(api_args), |
| 292 | reply.retval, |
| 293 | moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 294 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 295 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 296 | elif self._expect_api_retval == self._zero: |
| 297 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Paul Vinciguerra | 0b0a84c | 2020-05-02 10:40:33 -0400 | [diff] [blame] | 298 | msg = "%s(%s) failed, expected %d return value instead " \ |
| 299 | "of %d in %s" % (api_fn.__name__, |
| 300 | as_fn_signature(api_args), |
| 301 | expected_retval, reply.retval, |
Paul Vinciguerra | 1b534f5 | 2019-06-15 20:31:31 -0400 | [diff] [blame] | 302 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 303 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 304 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 305 | else: |
| 306 | raise Exception("Internal error, unexpected value for " |
| 307 | "self._expect_api_retval %s" % |
| 308 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 309 | self.hook.after_api(api_fn.__name__, api_args) |
| 310 | return reply |
| 311 | |
Dave Barach | 5932ce1 | 2019-10-09 17:28:04 -0400 | [diff] [blame] | 312 | def cli_return_response(self, cli): |
| 313 | """ Execute a CLI, calling the before/after hooks appropriately. |
| 314 | Return the reply without examining it |
| 315 | |
| 316 | :param cli: CLI to execute |
| 317 | :returns: response object |
| 318 | |
| 319 | """ |
| 320 | self.hook.before_cli(cli) |
| 321 | cli += '\n' |
| 322 | r = self.papi.cli_inband(cmd=cli) |
| 323 | self.hook.after_cli(cli) |
| 324 | return r |
| 325 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 326 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 327 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 328 | |
| 329 | :param cli: CLI to execute |
| 330 | :returns: CLI output |
| 331 | |
| 332 | """ |
Dave Barach | 5932ce1 | 2019-10-09 17:28:04 -0400 | [diff] [blame] | 333 | r = self.cli_return_response(cli) |
Paul Vinciguerra | 9673e3e | 2019-05-10 20:41:08 -0400 | [diff] [blame] | 334 | if r.retval == -156: |
| 335 | raise CliSyntaxError(r.reply) |
| 336 | if r.retval != 0: |
| 337 | raise CliFailedCommandError(r.reply) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 338 | if hasattr(r, 'reply'): |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 339 | return r.reply |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 340 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 341 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 342 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 343 | |
| 344 | :param cli: CLI to execute |
| 345 | :returns: CLI output |
| 346 | """ |
Ole Troan | 6ed154f | 2019-10-15 19:31:55 +0200 | [diff] [blame] | 347 | return cli + "\n" + self.cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 348 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 349 | def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120, |
| 350 | mrc=0, mrd=0): |
| 351 | return self.api(self.papi.ip6nd_send_router_solicitation, |
| 352 | {'irt': irt, |
| 353 | 'mrt': mrt, |
| 354 | 'mrc': mrc, |
| 355 | 'mrd': mrd, |
| 356 | 'sw_if_index': sw_if_index}) |
| 357 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 358 | def want_interface_events(self, enable_disable=1): |
| 359 | return self.api(self.papi.want_interface_events, |
| 360 | {'enable_disable': enable_disable, |
| 361 | 'pid': os.getpid(), }) |
| 362 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 363 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 364 | return self.api(self.papi.sw_interface_set_mac_address, |
| 365 | {'sw_if_index': sw_if_index, |
| 366 | 'mac_address': mac}) |
| 367 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 368 | def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 369 | """Create p2p ethernet subinterface |
| 370 | |
| 371 | :param sw_if_index: main (parent) interface |
| 372 | :param remote_mac: client (remote) mac address |
| 373 | |
| 374 | """ |
| 375 | return self.api( |
| 376 | self.papi.p2p_ethernet_add, |
| 377 | {'parent_if_index': sw_if_index, |
| 378 | 'remote_mac': remote_mac, |
| 379 | 'subif_id': subif_id}) |
| 380 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 381 | def p2p_ethernet_del(self, sw_if_index, remote_mac): |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 382 | """Delete p2p ethernet subinterface |
| 383 | |
| 384 | :param sw_if_index: main (parent) interface |
| 385 | :param remote_mac: client (remote) mac address |
| 386 | |
| 387 | """ |
| 388 | return self.api( |
| 389 | self.papi.p2p_ethernet_del, |
| 390 | {'parent_if_index': sw_if_index, |
| 391 | 'remote_mac': remote_mac}) |
| 392 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 393 | def create_vlan_subif(self, sw_if_index, vlan): |
| 394 | """ |
| 395 | |
| 396 | :param vlan: |
| 397 | :param sw_if_index: |
| 398 | |
| 399 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 400 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 401 | {'sw_if_index': sw_if_index, |
| 402 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 403 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 404 | def create_loopback(self, mac=''): |
| 405 | """ |
| 406 | |
| 407 | :param mac: (Optional) |
| 408 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 409 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 410 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 411 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 412 | def ip_route_dump(self, table_id, is_ip6=False): |
| 413 | return self.api(self.papi.ip_route_dump, |
| 414 | {'table': { |
| 415 | 'table_id': table_id, |
| 416 | 'is_ip6': is_ip6 |
| 417 | }}) |
| 418 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 419 | def ip_neighbor_add_del(self, |
| 420 | sw_if_index, |
| 421 | mac_address, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 422 | ip_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 423 | is_add=1, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 424 | flags=0): |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 425 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 426 | |
| 427 | :param sw_if_index: |
| 428 | :param mac_address: |
| 429 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 430 | :param is_add: (Default value = 1) |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 431 | :param flags: (Default value = 0/NONE) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 432 | """ |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 433 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 434 | self.papi.ip_neighbor_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 435 | { |
| 436 | 'is_add': is_add, |
| 437 | 'neighbor': { |
| 438 | 'sw_if_index': sw_if_index, |
| 439 | 'flags': flags, |
| 440 | 'mac_address': mac_address, |
| 441 | 'ip_address': ip_address |
| 442 | } |
| 443 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 444 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 445 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 446 | def udp_encap_add(self, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 447 | src_ip, |
| 448 | dst_ip, |
| 449 | src_port, |
| 450 | dst_port, |
| 451 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 452 | """ Add a GRE tunnel |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 453 | :param src_ip: |
| 454 | :param dst_ip: |
| 455 | :param src_port: |
| 456 | :param dst_port: |
| 457 | :param outer_fib_id: (Default value = 0) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 458 | """ |
| 459 | |
| 460 | return self.api( |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 461 | self.papi.udp_encap_add, |
| 462 | { |
| 463 | 'udp_encap': { |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 464 | 'src_ip': src_ip, |
| 465 | 'dst_ip': dst_ip, |
| 466 | 'src_port': src_port, |
| 467 | 'dst_port': dst_port, |
| 468 | 'table_id': table_id |
| 469 | } |
| 470 | }) |
| 471 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 472 | def udp_encap_del(self, id): |
| 473 | return self.api(self.papi.udp_encap_del, {'id': id}) |
| 474 | |
| 475 | def udp_encap_dump(self): |
| 476 | return self.api(self.papi.udp_encap_dump, {}) |
| 477 | |
| 478 | def want_udp_encap_stats(self, enable=1): |
| 479 | return self.api(self.papi.want_udp_encap_stats, |
| 480 | {'enable': enable, |
| 481 | 'pid': os.getpid()}) |
| 482 | |
| 483 | def mpls_route_dump(self, table_id): |
| 484 | return self.api(self.papi.mpls_route_dump, |
| 485 | {'table': { |
| 486 | 'mt_table_id': table_id |
| 487 | }}) |
| 488 | |
| 489 | def mpls_table_dump(self): |
| 490 | return self.api(self.papi.mpls_table_dump, {}) |
| 491 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 492 | def mpls_table_add_del( |
| 493 | self, |
| 494 | table_id, |
| 495 | is_add=1): |
| 496 | """ |
| 497 | |
| 498 | :param table_id |
| 499 | :param is_add: (Default value = 1) |
| 500 | |
| 501 | """ |
| 502 | |
| 503 | return self.api( |
| 504 | self.papi.mpls_table_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 505 | {'mt_table': |
| 506 | { |
| 507 | 'mt_table_id': table_id, |
| 508 | }, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 509 | 'mt_is_add': is_add}) |
| 510 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 511 | def mpls_route_add_del(self, |
| 512 | table_id, |
| 513 | label, |
| 514 | eos, |
| 515 | eos_proto, |
| 516 | is_multicast, |
| 517 | paths, |
| 518 | is_add, |
| 519 | is_multipath): |
| 520 | """ MPLS Route add/del """ |
| 521 | return self.api( |
| 522 | self.papi.mpls_route_add_del, |
| 523 | {'mr_route': |
| 524 | { |
| 525 | 'mr_table_id': table_id, |
| 526 | 'mr_label': label, |
| 527 | 'mr_eos': eos, |
| 528 | 'mr_eos_proto': eos_proto, |
| 529 | 'mr_is_multicast': is_multicast, |
| 530 | 'mr_n_paths': len(paths), |
| 531 | 'mr_paths': paths, |
| 532 | }, |
| 533 | 'mr_is_add': is_add, |
| 534 | 'mr_is_multipath': is_multipath}) |
| 535 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 536 | def mpls_ip_bind_unbind( |
| 537 | self, |
| 538 | label, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 539 | prefix, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 540 | table_id=0, |
| 541 | ip_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 542 | is_bind=1): |
| 543 | """ |
| 544 | """ |
| 545 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 546 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 547 | {'mb_mpls_table_id': table_id, |
| 548 | 'mb_label': label, |
| 549 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 550 | 'mb_is_bind': is_bind, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 551 | 'mb_prefix': prefix}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 552 | |
| 553 | def mpls_tunnel_add_del( |
| 554 | self, |
| 555 | tun_sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 556 | paths, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 557 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 558 | l2_only=0, |
| 559 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 560 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 561 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 562 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 563 | self.papi.mpls_tunnel_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 564 | {'mt_is_add': is_add, |
| 565 | 'mt_tunnel': |
| 566 | { |
| 567 | 'mt_sw_if_index': tun_sw_if_index, |
| 568 | 'mt_l2_only': l2_only, |
| 569 | 'mt_is_multicast': is_multicast, |
| 570 | 'mt_n_paths': len(paths), |
| 571 | 'mt_paths': paths, |
| 572 | }}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 573 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 574 | def input_acl_set_interface( |
| 575 | self, |
| 576 | is_add, |
| 577 | sw_if_index, |
| 578 | ip4_table_index=0xFFFFFFFF, |
| 579 | ip6_table_index=0xFFFFFFFF, |
| 580 | l2_table_index=0xFFFFFFFF): |
| 581 | """ |
| 582 | :param is_add: |
| 583 | :param sw_if_index: |
| 584 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 585 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 586 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 587 | """ |
| 588 | |
| 589 | return self.api( |
| 590 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 591 | {'sw_if_index': sw_if_index, |
| 592 | 'ip4_table_index': ip4_table_index, |
| 593 | 'ip6_table_index': ip6_table_index, |
| 594 | 'l2_table_index': l2_table_index, |
| 595 | 'is_add': is_add}) |
| 596 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 597 | def output_acl_set_interface( |
| 598 | self, |
| 599 | is_add, |
| 600 | sw_if_index, |
| 601 | ip4_table_index=0xFFFFFFFF, |
| 602 | ip6_table_index=0xFFFFFFFF, |
| 603 | l2_table_index=0xFFFFFFFF): |
| 604 | """ |
| 605 | :param is_add: |
| 606 | :param sw_if_index: |
| 607 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 608 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 609 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 610 | """ |
| 611 | |
| 612 | return self.api( |
| 613 | self.papi.output_acl_set_interface, |
| 614 | {'sw_if_index': sw_if_index, |
| 615 | 'ip4_table_index': ip4_table_index, |
| 616 | 'ip6_table_index': ip6_table_index, |
| 617 | 'l2_table_index': l2_table_index, |
| 618 | 'is_add': is_add}) |
| 619 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 620 | def set_ipfix_exporter( |
| 621 | self, |
| 622 | collector_address, |
| 623 | src_address, |
| 624 | path_mtu, |
| 625 | template_interval, |
| 626 | vrf_id=0, |
| 627 | collector_port=4739, |
| 628 | udp_checksum=0): |
| 629 | return self.api( |
| 630 | self.papi.set_ipfix_exporter, |
| 631 | { |
| 632 | 'collector_address': collector_address, |
| 633 | 'collector_port': collector_port, |
| 634 | 'src_address': src_address, |
| 635 | 'vrf_id': vrf_id, |
| 636 | 'path_mtu': path_mtu, |
| 637 | 'template_interval': template_interval, |
| 638 | 'udp_checksum': udp_checksum, |
| 639 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 640 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 641 | def mfib_signal_dump(self): |
| 642 | return self.api(self.papi.mfib_signal_dump, {}) |
| 643 | |
| 644 | def ip_mroute_dump(self, table_id, is_ip6=False): |
| 645 | return self.api(self.papi.ip_mroute_dump, |
| 646 | {'table': { |
| 647 | 'table_id': table_id, |
| 648 | 'is_ip6': is_ip6 |
| 649 | }}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 650 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 651 | def vxlan_gpe_add_del_tunnel( |
| 652 | self, |
| 653 | src_addr, |
| 654 | dst_addr, |
| 655 | mcast_sw_if_index=0xFFFFFFFF, |
| 656 | is_add=1, |
| 657 | is_ipv6=0, |
| 658 | encap_vrf_id=0, |
| 659 | decap_vrf_id=0, |
| 660 | protocol=3, |
| 661 | vni=0): |
| 662 | """ |
| 663 | |
| 664 | :param local: |
| 665 | :param remote: |
| 666 | :param is_add: (Default value = 1) |
| 667 | :param is_ipv6: (Default value = 0) |
| 668 | :param encap_vrf_id: (Default value = 0) |
| 669 | :param decap_vrf_id: (Default value = 0) |
| 670 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 671 | :param protocol: (Default value = 3) |
| 672 | :param vni: (Default value = 0) |
| 673 | |
| 674 | """ |
| 675 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 676 | {'is_add': is_add, |
| 677 | 'is_ipv6': is_ipv6, |
| 678 | 'local': src_addr, |
| 679 | 'remote': dst_addr, |
| 680 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 681 | 'encap_vrf_id': encap_vrf_id, |
| 682 | 'decap_vrf_id': decap_vrf_id, |
| 683 | 'protocol': protocol, |
| 684 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 685 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 686 | def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): |
| 687 | return self.api(self.papi.vxlan_gbp_tunnel_dump, |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 688 | {'sw_if_index': sw_if_index}) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 689 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 690 | def pppoe_add_del_session( |
| 691 | self, |
| 692 | client_ip, |
| 693 | client_mac, |
| 694 | session_id=0, |
| 695 | is_add=1, |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 696 | decap_vrf_id=0): |
| 697 | """ |
| 698 | |
| 699 | :param is_add: (Default value = 1) |
| 700 | :param is_ipv6: (Default value = 0) |
| 701 | :param client_ip: |
| 702 | :param session_id: (Default value = 0) |
| 703 | :param client_mac: |
| 704 | :param decap_vrf_id: (Default value = 0) |
| 705 | |
| 706 | """ |
| 707 | return self.api(self.papi.pppoe_add_del_session, |
| 708 | {'is_add': is_add, |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 709 | 'session_id': session_id, |
| 710 | 'client_ip': client_ip, |
| 711 | 'decap_vrf_id': decap_vrf_id, |
| 712 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 713 | |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 714 | def sr_mpls_policy_add(self, bsid, weight, type, segments): |
| 715 | return self.api(self.papi.sr_mpls_policy_add, |
| 716 | {'bsid': bsid, |
| 717 | 'weight': weight, |
Jakub Grajciar | 00ec401 | 2020-01-31 10:17:29 +0100 | [diff] [blame] | 718 | 'is_spray': type, |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 719 | 'n_segments': len(segments), |
| 720 | 'segments': segments}) |
| 721 | |
| 722 | def sr_mpls_policy_del(self, bsid): |
| 723 | return self.api(self.papi.sr_mpls_policy_del, |
| 724 | {'bsid': bsid}) |
| 725 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 726 | def bier_table_add_del(self, |
| 727 | bti, |
| 728 | mpls_label, |
| 729 | is_add=1): |
| 730 | """ BIER Table add/del """ |
| 731 | return self.api( |
| 732 | self.papi.bier_table_add_del, |
| 733 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 734 | "bt_sub_domain": bti.sub_domain_id, |
| 735 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 736 | 'bt_label': mpls_label, |
| 737 | 'bt_is_add': is_add}) |
| 738 | |
| 739 | def bier_table_dump(self): |
| 740 | return self.api(self.papi.bier_table_dump, {}) |
| 741 | |
| 742 | def bier_route_add_del(self, |
| 743 | bti, |
| 744 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 745 | paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 746 | is_add=1, |
| 747 | is_replace=0): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 748 | """ BIER Route add/del """ |
| 749 | return self.api( |
| 750 | self.papi.bier_route_add_del, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 751 | { |
| 752 | 'br_route': { |
| 753 | 'br_tbl_id': {"bt_set": bti.set_id, |
| 754 | "bt_sub_domain": bti.sub_domain_id, |
| 755 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 756 | 'br_bp': bp, |
| 757 | 'br_n_paths': len(paths), |
| 758 | 'br_paths': paths, |
| 759 | }, |
| 760 | 'br_is_add': is_add, |
| 761 | 'br_is_replace': is_replace |
| 762 | }) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 763 | |
| 764 | def bier_route_dump(self, bti): |
| 765 | return self.api( |
| 766 | self.papi.bier_route_dump, |
| 767 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 768 | "bt_sub_domain": bti.sub_domain_id, |
| 769 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 770 | |
| 771 | def bier_imp_add(self, |
| 772 | bti, |
| 773 | src, |
| 774 | ibytes, |
| 775 | is_add=1): |
| 776 | """ BIER Imposition Add """ |
| 777 | return self.api( |
| 778 | self.papi.bier_imp_add, |
| 779 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 780 | "bt_sub_domain": bti.sub_domain_id, |
| 781 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 782 | 'bi_src': src, |
| 783 | 'bi_n_bytes': len(ibytes), |
| 784 | 'bi_bytes': ibytes}) |
| 785 | |
| 786 | def bier_imp_del(self, bi_index): |
| 787 | """ BIER Imposition del """ |
| 788 | return self.api( |
| 789 | self.papi.bier_imp_del, |
| 790 | {'bi_index': bi_index}) |
| 791 | |
| 792 | def bier_imp_dump(self): |
| 793 | return self.api(self.papi.bier_imp_dump, {}) |
| 794 | |
| 795 | def bier_disp_table_add_del(self, |
| 796 | bdti, |
| 797 | is_add=1): |
| 798 | """ BIER Disposition Table add/del """ |
| 799 | return self.api( |
| 800 | self.papi.bier_disp_table_add_del, |
| 801 | {'bdt_tbl_id': bdti, |
| 802 | 'bdt_is_add': is_add}) |
| 803 | |
| 804 | def bier_disp_table_dump(self): |
| 805 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 806 | |
| 807 | def bier_disp_entry_add_del(self, |
| 808 | bdti, |
| 809 | bp, |
| 810 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 811 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 812 | next_hop, |
| 813 | next_hop_tbl_id=0, |
| 814 | next_hop_rpf_id=~0, |
| 815 | next_hop_is_ip4=1, |
| 816 | is_add=1): |
| 817 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 818 | lstack = [] |
| 819 | while (len(lstack) < 16): |
| 820 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 821 | return self.api( |
| 822 | self.papi.bier_disp_entry_add_del, |
| 823 | {'bde_tbl_id': bdti, |
| 824 | 'bde_bp': bp, |
| 825 | 'bde_payload_proto': payload_proto, |
| 826 | 'bde_n_paths': 1, |
Paul Vinciguerra | 79a32a4 | 2019-07-11 19:09:30 -0400 | [diff] [blame] | 827 | 'bde_paths': [{'table_id': next_hop_tbl_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 828 | 'rpf_id': next_hop_rpf_id, |
| 829 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 830 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 831 | 'bde_is_add': is_add}) |
| 832 | |
| 833 | def bier_disp_entry_dump(self, bdti): |
| 834 | return self.api( |
| 835 | self.papi.bier_disp_entry_dump, |
| 836 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 837 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 838 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 839 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 840 | Sample CLI : 'ipsec spd add 1' |
| 841 | |
| 842 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 843 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 844 | optional |
| 845 | :returns: reply from the API |
| 846 | """ |
| 847 | return self.api( |
| 848 | self.papi.ipsec_spd_add_del, { |
| 849 | 'spd_id': spd_id, 'is_add': is_add}) |
| 850 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 851 | def ipsec_spds_dump(self): |
| 852 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 853 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 854 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 855 | """ IPSEC interface SPD add/del - \ |
| 856 | Wrapper to associate/disassociate SPD to interface in VPP |
| 857 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 858 | |
| 859 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 860 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 861 | association mandatory |
| 862 | :param is_add - add(1) or del(0) association with interface \ |
| 863 | (Default 1 - add) . optional |
| 864 | :returns: reply from the API |
| 865 | """ |
| 866 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 867 | self.papi.ipsec_interface_add_del_spd, |
| 868 | {'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] | 869 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 870 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 871 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 872 | {'spd_index': spd_index if spd_index else 0, |
| 873 | 'spd_index_valid': 1 if spd_index else 0}) |
| 874 | |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 875 | def ipsec_spd_entry_add_del(self, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 876 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 877 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 878 | local_address_start, |
| 879 | local_address_stop, |
| 880 | remote_address_start, |
| 881 | remote_address_stop, |
| 882 | local_port_start=0, |
| 883 | local_port_stop=65535, |
| 884 | remote_port_start=0, |
| 885 | remote_port_stop=65535, |
| 886 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 887 | policy=0, |
| 888 | priority=100, |
| 889 | is_outbound=1, |
| 890 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 891 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 892 | is_ip_any=0): |
| 893 | """ IPSEC policy SPD add/del - |
| 894 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 895 | :param spd_id: SPD ID for the policy |
| 896 | :param local_address_start: local-ip-range start address |
| 897 | :param local_address_stop : local-ip-range stop address |
| 898 | :param remote_address_start: remote-ip-range start address |
| 899 | :param remote_address_stop : remote-ip-range stop address |
| 900 | :param local_port_start: (Default value = 0) |
| 901 | :param local_port_stop: (Default value = 65535) |
| 902 | :param remote_port_start: (Default value = 0) |
| 903 | :param remote_port_stop: (Default value = 65535) |
| 904 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 905 | :param sa_id: Security Association ID for mapping it to SPD |
| 906 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 907 | (Default value = 0) |
| 908 | :param priority: value for the spd action (Default value = 100) |
| 909 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 910 | (Default value = 1) |
| 911 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 912 | """ |
| 913 | return self.api( |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 914 | self.papi.ipsec_spd_entry_add_del, |
| 915 | { |
| 916 | 'is_add': is_add, |
| 917 | 'entry': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 918 | { |
| 919 | 'spd_id': spd_id, |
| 920 | 'sa_id': sa_id, |
| 921 | 'local_address_start': local_address_start, |
| 922 | 'local_address_stop': local_address_stop, |
| 923 | 'remote_address_start': remote_address_start, |
| 924 | 'remote_address_stop': remote_address_stop, |
| 925 | 'local_port_start': local_port_start, |
| 926 | 'local_port_stop': local_port_stop, |
| 927 | 'remote_port_start': remote_port_start, |
| 928 | 'remote_port_stop': remote_port_stop, |
| 929 | 'protocol': protocol, |
| 930 | 'policy': policy, |
| 931 | 'priority': priority, |
| 932 | 'is_outbound': is_outbound, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 933 | } |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 934 | }) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 935 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 936 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 937 | return self.api(self.papi.ipsec_spd_dump, |
| 938 | {'spd_id': spd_id, |
| 939 | 'sa_id': sa_id}) |
| 940 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 941 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 942 | remote_spi, crypto_alg, local_crypto_key, |
| 943 | remote_crypto_key, integ_alg, local_integ_key, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 944 | remote_integ_key, is_add=1, esn=0, salt=0, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 945 | anti_replay=1, renumber=0, |
Neale Ranns | 12989b5 | 2019-09-26 16:20:19 +0000 | [diff] [blame] | 946 | udp_encap=0, show_instance=0xffffffff): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 947 | return self.api( |
| 948 | self.papi.ipsec_tunnel_if_add_del, |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 949 | { |
| 950 | 'local_ip': local_ip, |
| 951 | 'remote_ip': remote_ip, |
| 952 | 'local_spi': local_spi, |
| 953 | 'remote_spi': remote_spi, |
| 954 | 'crypto_alg': crypto_alg, |
| 955 | 'local_crypto_key_len': len(local_crypto_key), |
| 956 | 'local_crypto_key': local_crypto_key, |
| 957 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 958 | 'remote_crypto_key': remote_crypto_key, |
| 959 | 'integ_alg': integ_alg, |
| 960 | 'local_integ_key_len': len(local_integ_key), |
| 961 | 'local_integ_key': local_integ_key, |
| 962 | 'remote_integ_key_len': len(remote_integ_key), |
| 963 | 'remote_integ_key': remote_integ_key, |
| 964 | 'is_add': is_add, |
| 965 | 'esn': esn, |
| 966 | 'anti_replay': anti_replay, |
| 967 | 'renumber': renumber, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 968 | 'show_instance': show_instance, |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 969 | 'udp_encap': udp_encap, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 970 | 'salt': salt |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 971 | }) |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 972 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 973 | def ipsec_select_backend(self, protocol, index): |
| 974 | return self.api(self.papi.ipsec_select_backend, |
| 975 | {'protocol': protocol, 'index': index}) |
| 976 | |
| 977 | def ipsec_backend_dump(self): |
| 978 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 979 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 980 | def punt_socket_register(self, reg, pathname, |
| 981 | header_version=1): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 982 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 983 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 984 | {'header_version': header_version, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 985 | 'punt': reg, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 986 | 'pathname': pathname}) |
| 987 | |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 988 | def punt_socket_deregister(self, reg): |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 989 | """ Unregister punt socket """ |
| 990 | return self.api(self.papi.punt_socket_deregister, |
Neale Ranns | 50f0ac0 | 2019-05-15 02:13:37 -0700 | [diff] [blame] | 991 | {'punt': reg}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 992 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 993 | def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 994 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 995 | """ GBP endpoint Add """ |
| 996 | return self.api(self.papi.gbp_endpoint_add, |
| 997 | {'endpoint': { |
| 998 | 'sw_if_index': sw_if_index, |
| 999 | 'ips': ips, |
| 1000 | 'n_ips': len(ips), |
| 1001 | 'mac': mac, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1002 | 'sclass': sclass, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1003 | 'flags': flags, |
| 1004 | 'tun': { |
| 1005 | 'src': tun_src, |
| 1006 | 'dst': tun_dst, |
| 1007 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1008 | |
| 1009 | def gbp_endpoint_del(self, handle): |
| 1010 | """ GBP endpoint Del """ |
| 1011 | return self.api(self.papi.gbp_endpoint_del, |
| 1012 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1013 | |
| 1014 | def gbp_endpoint_dump(self): |
| 1015 | """ GBP endpoint Dump """ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1016 | return self.api(self.papi.gbp_endpoint_dump, {}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1017 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1018 | def gbp_endpoint_group_add(self, vnid, sclass, bd, |
Neale Ranns | 32f6d8e | 2019-03-05 04:22:08 -0800 | [diff] [blame] | 1019 | rd, uplink_sw_if_index, |
| 1020 | retention): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1021 | """ GBP endpoint group Add """ |
| 1022 | return self.api(self.papi.gbp_endpoint_group_add, |
| 1023 | {'epg': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1024 | { |
| 1025 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 1026 | 'bd_id': bd, |
| 1027 | 'rd_id': rd, |
| 1028 | 'vnid': vnid, |
| 1029 | 'sclass': sclass, |
| 1030 | 'retention': retention |
| 1031 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1032 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1033 | def gbp_endpoint_group_del(self, sclass): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1034 | """ GBP endpoint group Del """ |
| 1035 | return self.api(self.papi.gbp_endpoint_group_del, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1036 | {'sclass': sclass}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1037 | |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1038 | def gbp_bridge_domain_add(self, bd_id, rd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1039 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 1040 | uu_fwd_sw_if_index, |
| 1041 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1042 | """ GBP bridge-domain Add """ |
| 1043 | return self.api(self.papi.gbp_bridge_domain_add, |
| 1044 | {'bd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1045 | { |
| 1046 | 'flags': flags, |
| 1047 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 1048 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
| 1049 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1050 | 'bd_id': bd_id, |
| 1051 | 'rd_id': rd_id |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1052 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1053 | |
| 1054 | def gbp_bridge_domain_del(self, bd_id): |
| 1055 | """ GBP bridge-domain Del """ |
| 1056 | return self.api(self.papi.gbp_bridge_domain_del, |
| 1057 | {'bd_id': bd_id}) |
| 1058 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1059 | def gbp_route_domain_add(self, rd_id, |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1060 | scope, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1061 | ip4_table_id, |
| 1062 | ip6_table_id, |
| 1063 | ip4_uu_sw_if_index, |
| 1064 | ip6_uu_sw_if_index): |
| 1065 | """ GBP route-domain Add """ |
| 1066 | return self.api(self.papi.gbp_route_domain_add, |
| 1067 | {'rd': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1068 | { |
Neale Ranns | 160c923 | 2019-06-19 06:25:56 -0700 | [diff] [blame] | 1069 | 'scope': scope, |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1070 | 'ip4_table_id': ip4_table_id, |
| 1071 | 'ip6_table_id': ip6_table_id, |
| 1072 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 1073 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 1074 | 'rd_id': rd_id |
| 1075 | }}) |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1076 | |
| 1077 | def gbp_route_domain_del(self, rd_id): |
| 1078 | """ GBP route-domain Del """ |
| 1079 | return self.api(self.papi.gbp_route_domain_del, |
| 1080 | {'rd_id': rd_id}) |
| 1081 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1082 | 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] | 1083 | """ GBP recirc Add/Del """ |
| 1084 | return self.api(self.papi.gbp_recirc_add_del, |
| 1085 | {'is_add': is_add, |
| 1086 | 'recirc': { |
| 1087 | 'is_ext': is_ext, |
| 1088 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1089 | 'sclass': sclass}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1090 | |
| 1091 | def gbp_recirc_dump(self): |
| 1092 | """ GBP recirc Dump """ |
| 1093 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 1094 | |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 1095 | def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags): |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 1096 | """ GBP recirc Add/Del """ |
| 1097 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 1098 | {'is_add': is_add, |
| 1099 | 'ext_itf': { |
| 1100 | 'sw_if_index': sw_if_index, |
| 1101 | 'bd_id': bd_id, |
Benoît Ganne | ba6abfa | 2019-07-01 17:10:41 +0200 | [diff] [blame] | 1102 | 'rd_id': rd_id, |
| 1103 | 'flags': flags}}) |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 1104 | |
| 1105 | def gbp_ext_itf_dump(self): |
| 1106 | """ GBP recirc Dump """ |
| 1107 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 1108 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1109 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 1110 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1111 | sw_if_index=0xffffffff, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1112 | sclass=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1113 | """ GBP Subnet Add/Del """ |
| 1114 | return self.api(self.papi.gbp_subnet_add_del, |
| 1115 | {'is_add': is_add, |
| 1116 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1117 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1118 | 'sw_if_index': sw_if_index, |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 1119 | 'sclass': sclass, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 1120 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1121 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1122 | |
| 1123 | def gbp_subnet_dump(self): |
| 1124 | """ GBP Subnet Dump """ |
Neale Ranns | efd7bc2 | 2019-11-11 08:32:34 +0000 | [diff] [blame] | 1125 | return self.api(self.papi.gbp_subnet_dump, {}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 1126 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 1127 | def gbp_contract_dump(self): |
| 1128 | """ GBP contract Dump """ |
| 1129 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 1130 | |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1131 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1132 | """ GBP VXLAN tunnel add """ |
| 1133 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 1134 | { |
| 1135 | 'tunnel': { |
| 1136 | 'vni': vni, |
| 1137 | 'mode': mode, |
Neale Ranns | 8da9fc6 | 2019-03-04 14:08:11 -0800 | [diff] [blame] | 1138 | 'bd_rd_id': bd_rd_id, |
| 1139 | 'src': src |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 1140 | } |
| 1141 | }) |
| 1142 | |
| 1143 | def gbp_vxlan_tunnel_del(self, vni): |
| 1144 | """ GBP VXLAN tunnel del """ |
| 1145 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 1146 | { |
| 1147 | 'vni': vni, |
| 1148 | }) |
| 1149 | |
| 1150 | def gbp_vxlan_tunnel_dump(self): |
| 1151 | """ GBP VXLAN tunnel add/del """ |
| 1152 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 1153 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1154 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 1155 | """ Enable/disable IGMP on a given interface """ |
| 1156 | return self.api(self.papi.igmp_enable_disable, |
| 1157 | {'enable': enable, |
| 1158 | 'mode': host, |
| 1159 | 'sw_if_index': sw_if_index}) |
| 1160 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 1161 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 1162 | """ Add/del IGMP proxy device """ |
| 1163 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 1164 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 1165 | 'add': add}) |
| 1166 | |
| 1167 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 1168 | """ Add/del interface to/from IGMP proxy device """ |
| 1169 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 1170 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 1171 | 'add': add}) |
| 1172 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1173 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1174 | """ Listen for new (S,G) on specified interface |
| 1175 | |
| 1176 | :param enable: add/del |
| 1177 | :param sw_if_index: interface sw index |
| 1178 | :param saddr: source ip4 addr |
| 1179 | :param gaddr: group ip4 addr |
| 1180 | """ |
| 1181 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1182 | { |
| 1183 | 'group': |
Ole Troan | 9a47537 | 2019-03-05 16:58:24 +0100 | [diff] [blame] | 1184 | { |
| 1185 | 'filter': filter, |
| 1186 | 'sw_if_index': sw_if_index, |
| 1187 | 'n_srcs': len(saddrs), |
| 1188 | 'saddrs': saddrs, |
| 1189 | 'gaddr': gaddr |
| 1190 | } |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 1191 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1192 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 1193 | def igmp_clear_interface(self, sw_if_index): |
| 1194 | """ Remove all (S,G)s from specified interface |
| 1195 | doesn't send IGMP report! |
| 1196 | """ |
| 1197 | return self.api( |
| 1198 | self.papi.igmp_clear_interface, { |
| 1199 | 'sw_if_index': sw_if_index}) |
| 1200 | |
| 1201 | def want_igmp_events(self, enable=1): |
| 1202 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 1203 | 'pid': os.getpid()}) |