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