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