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