blob: c0e88f826e0f0dd1cf9894cc531c62645a9817cd [file] [log] [blame]
Ole Troan9a475372019-03-05 16:58:24 +01001# 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 Vinciguerra00671cf2018-11-25 12:47:04 -08008import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02009import time
Klement Sekerae4504c62016-12-08 10:16:41 +010010from collections import deque
Ole Troan4376ab22021-03-03 10:40:05 +010011import queue
Ole Troanf159f582019-02-28 20:20:47 +010012from six import moves, iteritems
Klement Sekerab23ffd72021-05-31 16:08:53 +020013from config import config
Paul Vinciguerra19542292019-03-17 17:34:46 -070014from vpp_papi import VPPApiClient, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080015from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070016from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020017
Ole Troanf159f582019-02-28 20:20:47 +010018#
19# Dictionary keyed on message name to override default values for
20# named parameters
21#
Ole Troan9a475372019-03-05 16:58:24 +010022defaultmapping = {
Paul Vinciguerrac0e94412020-04-28 01:12:04 -040023
Ole Troan9a475372019-03-05 16:58:24 +010024 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
Ole Troan9a475372019-03-05 16:58:24 +010025 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020026 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
27 'conf_key_id': None},
28 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
29 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010030 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
31 'is_add': 1, },
32 'bier_disp_table_add_del': {'is_add': 1, },
33 'bier_imp_add': {'is_add': 1, },
34 'bier_route_add_del': {'is_add': 1, },
35 'bier_table_add_del': {'is_add': 1, },
36 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
37 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070038 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010039 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
40 'decap_next_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010041 'input_acl_set_interface': {'ip4_table_index': 4294967295,
42 'ip6_table_index': 4294967295,
43 'l2_table_index': 4294967295, },
44 'ip6_add_del_address_using_prefix': {'is_add': 1, },
45 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
46 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
47 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010048 'classify_table_index': 4294967295, 'is_add': 1, },
49 'ip_mroute_add_del': {'is_add': 1, },
50 'ip_neighbor_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010051 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010052 'ipsec_spd_add_del': {'is_add': 1, },
53 'ipsec_spd_dump': {'sa_id': 4294967295, },
54 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
55 'remote_port_stop': 65535, 'priority': 100,
56 'is_outbound': 1,
57 'is_add': 1, },
58 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
59 'l2_emulation': {'enable': 1, },
60 'l2fib_add_del': {'is_add': 1, },
61 'lisp_add_del_adjacency': {'is_add': 1, },
62 'lisp_add_del_local_eid': {'is_add': 1, },
63 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
64 'lisp_add_del_locator_set': {'is_add': 1, },
65 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010066 'macip_acl_interface_add_del': {'is_add': 1, },
67 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010068 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
69 'mr_next_hop_weight': 1,
70 'mr_next_hop_via_label': 1048576,
71 'mr_is_add': 1,
72 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010073 'mpls_table_add_del': {'is_add': 1, },
74 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
75 'next_hop_weight': 1,
76 'next_hop_via_label': 1048576,
77 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010078 'output_acl_set_interface': {'ip4_table_index': 4294967295,
79 'ip6_table_index': 4294967295,
80 'l2_table_index': 4294967295, },
81 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010082 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010083 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010084 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010085 'sw_interface_add_del_address': {'is_add': 1, },
86 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
87 'pref_lifetime': 4294967295, },
88 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
89 'sw_interface_set_l2_bridge': {'enable': 1, },
90 'sw_interface_set_mpls_enable': {'enable': 1, },
91 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
92 'sw_interface_set_unnumbered': {'is_add': 1, },
93 'sw_interface_span_enable_disable': {'state': 1, },
94 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
95 'decap_next_index': 4294967295,
96 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010097 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010098 'want_igmp_events': {'enable': 1, },
99 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200100 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100101 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100102}
Ole Troanf159f582019-02-28 20:20:47 +0100103
Matus Fabianb4515b42018-11-19 04:25:32 -0800104
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400105def as_fn_signature(d):
106 return ", ".join(f"{k}={v}" for k, v in d.items())
107
108
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400109class CliFailedCommandError(Exception):
110 """ cli command failed."""
111
112
113class CliSyntaxError(Exception):
114 """ cli command had a syntax error."""
115
116
Klement Sekera73884482017-02-23 09:26:30 +0100117class UnexpectedApiReturnValueError(Exception):
118 """ exception raised when the API return value is unexpected """
119 pass
120
121
Klement Sekeraf62ae122016-10-11 11:47:09 +0200122class VppPapiProvider(object):
123 """VPP-api provider using vpp-papi
124
125 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200126 """
127
Klement Sekerae0545ef2017-01-25 08:00:40 +0100128 _zero, _negative = range(2)
129
Ole Troan4376ab22021-03-03 10:40:05 +0100130 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800131 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200132 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100133 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100134 self._expect_api_retval = self._zero
135 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100136
Paul Vinciguerra19542292019-03-17 17:34:46 -0700137 # install_dir is a class attribute. We need to set it before
138 # calling the constructor.
Klement Sekerab23ffd72021-05-31 16:08:53 +0200139 VPPApiClient.apidir = config.vpp_install_dir
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800140
Paul Vinciguerra19542292019-03-17 17:34:46 -0700141 self.vpp = VPPApiClient(logger=test_class.logger,
142 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100143 use_socket=True,
Klement Sekerae2636852021-03-16 12:52:12 +0100144 server_address=test_class.get_api_sock_path())
Ole Troan4376ab22021-03-03 10:40:05 +0100145 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200146
Klement Sekerae0545ef2017-01-25 08:00:40 +0100147 def __enter__(self):
148 return self
149
Klement Sekera7d6afb32018-11-08 11:52:04 +0100150 def assert_negative_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400151 """ Expect API failure - used with with, e.g.::
152
153 with self.vapi.assert_negative_api_retval():
154 self.vapi.<api call expected to fail>
155
156 ..
Klement Sekera7d6afb32018-11-08 11:52:04 +0100157 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100158 self._expect_stack.append(self._expect_api_retval)
159 self._expect_api_retval = self._negative
160 return self
161
Klement Sekera7d6afb32018-11-08 11:52:04 +0100162 def assert_zero_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400163 """ Expect API success - used with with, e.g.::
Klement Sekera7d6afb32018-11-08 11:52:04 +0100164
Dave Wallaced1706812021-08-12 18:36:02 -0400165 with self.vapi.assert_negative_api_retval():
166 self.vapi.<api call expected to succeed>
167
168 :note: this is useful only inside another with block
169 as success is the default expected value
Klement Sekera7d6afb32018-11-08 11:52:04 +0100170 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100171 self._expect_stack.append(self._expect_api_retval)
172 self._expect_api_retval = self._zero
173 return self
174
175 def __exit__(self, exc_type, exc_value, traceback):
176 self._expect_api_retval = self._expect_stack.pop()
177
Klement Sekeraf62ae122016-10-11 11:47:09 +0200178 def register_hook(self, hook):
179 """Replace hook registration with new hook
180
181 :param hook:
182
183 """
184 self.hook = hook
185
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200186 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100187 """ Collect all events from the internal queue and clear the queue. """
Ole Troan4376ab22021-03-03 10:40:05 +0100188 result = []
189 while True:
190 try:
191 e = self._events.get(block=False)
192 result.append(e)
193 except queue.Empty:
194 return result
195 return result
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200196
197 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100198 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100199 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100200 self.test_class.logger.debug("Expecting event '%s' within %ss",
201 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300202 else:
203 self.test_class.logger.debug("Expecting event within %ss",
204 timeout)
Ole Troan4376ab22021-03-03 10:40:05 +0100205 try:
206 e = self._events.get(timeout=timeout)
207 except queue.Empty:
208 raise Exception("Event did not occur within timeout")
209 msgname = type(e).__name__
210 if name and msgname != name:
211 raise Exception("Unexpected event received: %s, expected: %s"
212 % msgname)
213 self.test_class.logger.debug("Returning event %s:%s" % (name, e))
214 return e
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200215
216 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100217 """ Enqueue event in the internal event queue. """
Klement Sekerae4504c62016-12-08 10:16:41 +0100218 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Ole Troan4376ab22021-03-03 10:40:05 +0100219 self._events.put(event)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220
Ole Troanf159f582019-02-28 20:20:47 +0100221 def factory(self, name, apifn):
222 def f(*a, **ka):
223 fields = apifn._func.msg.fields
224
225 # add positional and kw arguments
226 d = ka
227 for i, o in enumerate(fields[3:]):
228 try:
229 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200230 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100231 break
232
233 # Default override
234 if name in defaultmapping:
235 for k, v in iteritems(defaultmapping[name]):
236 if k in d:
237 continue
238 d[k] = v
239 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100240
Ole Troanf159f582019-02-28 20:20:47 +0100241 return f
242
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800243 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100244 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800245 method = super(VppPapiProvider, self).__getattribute__(name)
246 except AttributeError:
247 method = self.factory(name, getattr(self.papi, name))
248 # lazily load the method so we don't need to call factory
249 # again for this name.
250 setattr(self, name, method)
251 return method
Ole Troanf159f582019-02-28 20:20:47 +0100252
Klement Sekeraf62ae122016-10-11 11:47:09 +0200253 def connect(self):
254 """Connect the API to VPP"""
Ole Troan4376ab22021-03-03 10:40:05 +0100255 # This might be called before VPP is prepared to listen to the socket
256 retries = 0
Klement Sekerae2636852021-03-16 12:52:12 +0100257 while not os.path.exists(self.test_class.get_api_sock_path()):
Ole Troan4376ab22021-03-03 10:40:05 +0100258 time.sleep(0.5)
259 retries += 1
260 if retries > 120:
261 break
262 self.vpp.connect(self.name[:63])
Klement Sekera7112c542017-03-01 09:53:19 +0100263 self.papi = self.vpp.api
264 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200265
266 def disconnect(self):
267 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100268 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200269
270 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100271 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200272 Call the appropriate hooks before and after the API call
273
274 :param api_fn: API function to call
275 :param api_args: tuple of API function arguments
276 :param expected_retval: Expected return value (Default value = 0)
277 :returns: reply from the API
278
279 """
280 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100281 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100282 if self._expect_api_retval == self._negative:
283 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400284 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100285 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400286 (api_fn.__name__, as_fn_signature(api_args),
287 reply.retval,
288 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100289 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100290 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100291 elif self._expect_api_retval == self._zero:
292 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400293 msg = "%s(%s) failed, expected %d return value instead " \
294 "of %d in %s" % (api_fn.__name__,
295 as_fn_signature(api_args),
296 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400297 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100298 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100299 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100300 else:
301 raise Exception("Internal error, unexpected value for "
302 "self._expect_api_retval %s" %
303 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200304 self.hook.after_api(api_fn.__name__, api_args)
305 return reply
306
Dave Barach5932ce12019-10-09 17:28:04 -0400307 def cli_return_response(self, cli):
308 """ Execute a CLI, calling the before/after hooks appropriately.
309 Return the reply without examining it
310
311 :param cli: CLI to execute
312 :returns: response object
313
314 """
315 self.hook.before_cli(cli)
316 cli += '\n'
317 r = self.papi.cli_inband(cmd=cli)
318 self.hook.after_cli(cli)
319 return r
320
Klement Sekeraf62ae122016-10-11 11:47:09 +0200321 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100322 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200323
324 :param cli: CLI to execute
325 :returns: CLI output
326
327 """
Dave Barach5932ce12019-10-09 17:28:04 -0400328 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400329 if r.retval == -156:
330 raise CliSyntaxError(r.reply)
331 if r.retval != 0:
332 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200333 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100334 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200335
Jan49c0fca2016-10-26 15:44:27 +0200336 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100337 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200338
339 :param cli: CLI to execute
340 :returns: CLI output
341 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200342 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200343
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100344 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
345 mrc=0, mrd=0):
346 return self.api(self.papi.ip6nd_send_router_solicitation,
347 {'irt': irt,
348 'mrt': mrt,
349 'mrc': mrc,
350 'mrd': mrd,
351 'sw_if_index': sw_if_index})
352
Juraj Slobodab3f90502018-10-04 15:15:16 +0200353 def want_interface_events(self, enable_disable=1):
354 return self.api(self.papi.want_interface_events,
355 {'enable_disable': enable_disable,
356 'pid': os.getpid(), })
357
Neale Rannsc819fc62018-02-16 02:44:05 -0800358 def sw_interface_set_mac_address(self, sw_if_index, mac):
359 return self.api(self.papi.sw_interface_set_mac_address,
360 {'sw_if_index': sw_if_index,
361 'mac_address': mac})
362
Ole Troane1ade682019-03-04 23:55:43 +0100363 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200364 """Create p2p ethernet subinterface
365
366 :param sw_if_index: main (parent) interface
367 :param remote_mac: client (remote) mac address
368
369 """
370 return self.api(
371 self.papi.p2p_ethernet_add,
372 {'parent_if_index': sw_if_index,
373 'remote_mac': remote_mac,
374 'subif_id': subif_id})
375
Ole Troane1ade682019-03-04 23:55:43 +0100376 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200377 """Delete p2p ethernet subinterface
378
379 :param sw_if_index: main (parent) interface
380 :param remote_mac: client (remote) mac address
381
382 """
383 return self.api(
384 self.papi.p2p_ethernet_del,
385 {'parent_if_index': sw_if_index,
386 'remote_mac': remote_mac})
387
Klement Sekeraf62ae122016-10-11 11:47:09 +0200388 def create_vlan_subif(self, sw_if_index, vlan):
389 """
390
391 :param vlan:
392 :param sw_if_index:
393
394 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100395 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200396 {'sw_if_index': sw_if_index,
397 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200398
Matej Klotton0178d522016-11-04 11:11:44 +0100399 def create_loopback(self, mac=''):
400 """
401
402 :param mac: (Optional)
403 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100404 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200405 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100406
Neale Ranns097fa662018-05-01 05:17:55 -0700407 def ip_route_dump(self, table_id, is_ip6=False):
408 return self.api(self.papi.ip_route_dump,
409 {'table': {
410 'table_id': table_id,
411 'is_ip6': is_ip6
412 }})
413
Neale Ranns976b2592019-12-04 06:11:00 +0000414 def ip_route_v2_dump(self, table_id, is_ip6=False, src=0):
415 return self.api(self.papi.ip_route_v2_dump,
416 {
417 'src': src,
418 'table': {
419 'table_id': table_id,
420 'is_ip6': is_ip6
421 }
422 })
423
Matej Klotton0178d522016-11-04 11:11:44 +0100424 def ip_neighbor_add_del(self,
425 sw_if_index,
426 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700427 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100428 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700429 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100430 """ Add neighbor MAC to IPv4 or IPv6 address.
431
432 :param sw_if_index:
433 :param mac_address:
434 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100435 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700436 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100437 """
Matej Klotton0178d522016-11-04 11:11:44 +0100438 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100439 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700440 {
441 'is_add': is_add,
442 'neighbor': {
443 'sw_if_index': sw_if_index,
444 'flags': flags,
445 'mac_address': mac_address,
446 'ip_address': ip_address
447 }
448 }
Matej Klotton0178d522016-11-04 11:11:44 +0100449 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100450
Neale Rannsd0df49f2018-08-08 01:06:40 -0700451 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700452 src_ip,
453 dst_ip,
454 src_port,
455 dst_port,
456 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800457 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800458 :param src_ip:
459 :param dst_ip:
460 :param src_port:
461 :param dst_port:
462 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800463 """
464
465 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700466 self.papi.udp_encap_add,
467 {
468 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700469 'src_ip': src_ip,
470 'dst_ip': dst_ip,
471 'src_port': src_port,
472 'dst_port': dst_port,
473 'table_id': table_id
474 }
475 })
476
Neale Ranns097fa662018-05-01 05:17:55 -0700477 def udp_encap_del(self, id):
478 return self.api(self.papi.udp_encap_del, {'id': id})
479
480 def udp_encap_dump(self):
481 return self.api(self.papi.udp_encap_dump, {})
482
483 def want_udp_encap_stats(self, enable=1):
484 return self.api(self.papi.want_udp_encap_stats,
485 {'enable': enable,
486 'pid': os.getpid()})
487
488 def mpls_route_dump(self, table_id):
489 return self.api(self.papi.mpls_route_dump,
490 {'table': {
491 'mt_table_id': table_id
492 }})
493
494 def mpls_table_dump(self):
495 return self.api(self.papi.mpls_table_dump, {})
496
Neale Ranns15002542017-09-10 04:39:11 -0700497 def mpls_table_add_del(
498 self,
499 table_id,
500 is_add=1):
501 """
502
503 :param table_id
504 :param is_add: (Default value = 1)
505
506 """
507
508 return self.api(
509 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700510 {'mt_table':
511 {
512 'mt_table_id': table_id,
513 },
Neale Ranns15002542017-09-10 04:39:11 -0700514 'mt_is_add': is_add})
515
Neale Ranns097fa662018-05-01 05:17:55 -0700516 def mpls_route_add_del(self,
517 table_id,
518 label,
519 eos,
520 eos_proto,
521 is_multicast,
522 paths,
523 is_add,
524 is_multipath):
525 """ MPLS Route add/del """
526 return self.api(
527 self.papi.mpls_route_add_del,
528 {'mr_route':
529 {
530 'mr_table_id': table_id,
531 'mr_label': label,
532 'mr_eos': eos,
533 'mr_eos_proto': eos_proto,
534 'mr_is_multicast': is_multicast,
535 'mr_n_paths': len(paths),
536 'mr_paths': paths,
537 },
538 'mr_is_add': is_add,
539 'mr_is_multipath': is_multipath})
540
Neale Rannsad422ed2016-11-02 14:20:04 +0000541 def mpls_ip_bind_unbind(
542 self,
543 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700544 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000545 table_id=0,
546 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000547 is_bind=1):
548 """
549 """
550 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100551 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200552 {'mb_mpls_table_id': table_id,
553 'mb_label': label,
554 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200555 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700556 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000557
558 def mpls_tunnel_add_del(
559 self,
560 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700561 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000562 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800563 l2_only=0,
564 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000565 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000566 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000567 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100568 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700569 {'mt_is_add': is_add,
570 'mt_tunnel':
571 {
572 'mt_sw_if_index': tun_sw_if_index,
573 'mt_l2_only': l2_only,
574 'mt_is_multicast': is_multicast,
575 'mt_n_paths': len(paths),
576 'mt_paths': paths,
577 }})
Matus Fabiande886752016-12-07 03:38:19 -0800578
Steve Shin7957d6e2016-12-19 09:24:50 -0800579 def input_acl_set_interface(
580 self,
581 is_add,
582 sw_if_index,
583 ip4_table_index=0xFFFFFFFF,
584 ip6_table_index=0xFFFFFFFF,
585 l2_table_index=0xFFFFFFFF):
586 """
587 :param is_add:
588 :param sw_if_index:
589 :param ip4_table_index: (Default value = 0xFFFFFFFF)
590 :param ip6_table_index: (Default value = 0xFFFFFFFF)
591 :param l2_table_index: (Default value = 0xFFFFFFFF)
592 """
593
594 return self.api(
595 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100596 {'sw_if_index': sw_if_index,
597 'ip4_table_index': ip4_table_index,
598 'ip6_table_index': ip6_table_index,
599 'l2_table_index': l2_table_index,
600 'is_add': is_add})
601
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100602 def output_acl_set_interface(
603 self,
604 is_add,
605 sw_if_index,
606 ip4_table_index=0xFFFFFFFF,
607 ip6_table_index=0xFFFFFFFF,
608 l2_table_index=0xFFFFFFFF):
609 """
610 :param is_add:
611 :param sw_if_index:
612 :param ip4_table_index: (Default value = 0xFFFFFFFF)
613 :param ip6_table_index: (Default value = 0xFFFFFFFF)
614 :param l2_table_index: (Default value = 0xFFFFFFFF)
615 """
616
617 return self.api(
618 self.papi.output_acl_set_interface,
619 {'sw_if_index': sw_if_index,
620 'ip4_table_index': ip4_table_index,
621 'ip6_table_index': ip6_table_index,
622 'l2_table_index': l2_table_index,
623 'is_add': is_add})
624
Klement Sekera77fabdb2017-01-02 07:46:14 +0100625 def set_ipfix_exporter(
626 self,
627 collector_address,
628 src_address,
629 path_mtu,
630 template_interval,
631 vrf_id=0,
632 collector_port=4739,
633 udp_checksum=0):
634 return self.api(
635 self.papi.set_ipfix_exporter,
636 {
637 'collector_address': collector_address,
638 'collector_port': collector_port,
639 'src_address': src_address,
640 'vrf_id': vrf_id,
641 'path_mtu': path_mtu,
642 'template_interval': template_interval,
643 'udp_checksum': udp_checksum,
644 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800645
Neale Ranns097fa662018-05-01 05:17:55 -0700646 def mfib_signal_dump(self):
647 return self.api(self.papi.mfib_signal_dump, {})
648
649 def ip_mroute_dump(self, table_id, is_ip6=False):
650 return self.api(self.papi.ip_mroute_dump,
651 {'table': {
652 'table_id': table_id,
653 'is_ip6': is_ip6
654 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000655
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800656 def pppoe_add_del_session(
657 self,
658 client_ip,
659 client_mac,
660 session_id=0,
661 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800662 decap_vrf_id=0):
663 """
664
665 :param is_add: (Default value = 1)
666 :param is_ipv6: (Default value = 0)
667 :param client_ip:
668 :param session_id: (Default value = 0)
669 :param client_mac:
670 :param decap_vrf_id: (Default value = 0)
671
672 """
673 return self.api(self.papi.pppoe_add_del_session,
674 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800675 'session_id': session_id,
676 'client_ip': client_ip,
677 'decap_vrf_id': decap_vrf_id,
678 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200679
Neale Ranns7c922dc2018-08-30 06:12:27 -0700680 def sr_mpls_policy_add(self, bsid, weight, type, segments):
681 return self.api(self.papi.sr_mpls_policy_add,
682 {'bsid': bsid,
683 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100684 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700685 'n_segments': len(segments),
686 'segments': segments})
687
688 def sr_mpls_policy_del(self, bsid):
689 return self.api(self.papi.sr_mpls_policy_del,
690 {'bsid': bsid})
691
Neale Rannsd792d9c2017-10-21 10:53:20 -0700692 def bier_table_add_del(self,
693 bti,
694 mpls_label,
695 is_add=1):
696 """ BIER Table add/del """
697 return self.api(
698 self.papi.bier_table_add_del,
699 {'bt_tbl_id': {"bt_set": bti.set_id,
700 "bt_sub_domain": bti.sub_domain_id,
701 "bt_hdr_len_id": bti.hdr_len_id},
702 'bt_label': mpls_label,
703 'bt_is_add': is_add})
704
705 def bier_table_dump(self):
706 return self.api(self.papi.bier_table_dump, {})
707
708 def bier_route_add_del(self,
709 bti,
710 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800711 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700712 is_add=1,
713 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700714 """ BIER Route add/del """
715 return self.api(
716 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700717 {
718 'br_route': {
719 'br_tbl_id': {"bt_set": bti.set_id,
720 "bt_sub_domain": bti.sub_domain_id,
721 "bt_hdr_len_id": bti.hdr_len_id},
722 'br_bp': bp,
723 'br_n_paths': len(paths),
724 'br_paths': paths,
725 },
726 'br_is_add': is_add,
727 'br_is_replace': is_replace
728 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700729
730 def bier_route_dump(self, bti):
731 return self.api(
732 self.papi.bier_route_dump,
733 {'br_tbl_id': {"bt_set": bti.set_id,
734 "bt_sub_domain": bti.sub_domain_id,
735 "bt_hdr_len_id": bti.hdr_len_id}})
736
737 def bier_imp_add(self,
738 bti,
739 src,
740 ibytes,
741 is_add=1):
742 """ BIER Imposition Add """
743 return self.api(
744 self.papi.bier_imp_add,
745 {'bi_tbl_id': {"bt_set": bti.set_id,
746 "bt_sub_domain": bti.sub_domain_id,
747 "bt_hdr_len_id": bti.hdr_len_id},
748 'bi_src': src,
749 'bi_n_bytes': len(ibytes),
750 'bi_bytes': ibytes})
751
752 def bier_imp_del(self, bi_index):
753 """ BIER Imposition del """
754 return self.api(
755 self.papi.bier_imp_del,
756 {'bi_index': bi_index})
757
758 def bier_imp_dump(self):
759 return self.api(self.papi.bier_imp_dump, {})
760
761 def bier_disp_table_add_del(self,
762 bdti,
763 is_add=1):
764 """ BIER Disposition Table add/del """
765 return self.api(
766 self.papi.bier_disp_table_add_del,
767 {'bdt_tbl_id': bdti,
768 'bdt_is_add': is_add})
769
770 def bier_disp_table_dump(self):
771 return self.api(self.papi.bier_disp_table_dump, {})
772
773 def bier_disp_entry_add_del(self,
774 bdti,
775 bp,
776 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800777 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700778 next_hop,
779 next_hop_tbl_id=0,
780 next_hop_rpf_id=~0,
781 next_hop_is_ip4=1,
782 is_add=1):
783 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800784 lstack = []
785 while (len(lstack) < 16):
786 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700787 return self.api(
788 self.papi.bier_disp_entry_add_del,
789 {'bde_tbl_id': bdti,
790 'bde_bp': bp,
791 'bde_payload_proto': payload_proto,
792 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400793 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700794 'rpf_id': next_hop_rpf_id,
795 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800796 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700797 'bde_is_add': is_add})
798
799 def bier_disp_entry_dump(self, bdti):
800 return self.api(
801 self.papi.bier_disp_entry_dump,
802 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200803
“mystarrocks”23f0c452017-12-11 07:11:51 -0800804 def ipsec_spd_add_del(self, spd_id, is_add=1):
805 """ SPD add/del - Wrapper to add or del ipsec SPD
806 Sample CLI : 'ipsec spd add 1'
807
808 :param spd_id - SPD ID to be created in the vpp . mandatory
809 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
Dave Wallaced1706812021-08-12 18:36:02 -0400810 optional
“mystarrocks”23f0c452017-12-11 07:11:51 -0800811 :returns: reply from the API
812 """
813 return self.api(
814 self.papi.ipsec_spd_add_del, {
815 'spd_id': spd_id, 'is_add': is_add})
816
Neale Ranns311124e2019-01-24 04:52:25 -0800817 def ipsec_spds_dump(self):
818 return self.api(self.papi.ipsec_spds_dump, {})
819
“mystarrocks”23f0c452017-12-11 07:11:51 -0800820 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
821 """ IPSEC interface SPD add/del - \
822 Wrapper to associate/disassociate SPD to interface in VPP
823 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
824
825 :param spd_id - SPD ID to associate with the interface . mandatory
826 :param sw_if_index - Interface Index which needs to ipsec \
827 association mandatory
828 :param is_add - add(1) or del(0) association with interface \
829 (Default 1 - add) . optional
830 :returns: reply from the API
831 """
832 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200833 self.papi.ipsec_interface_add_del_spd,
834 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800835
Neale Ranns311124e2019-01-24 04:52:25 -0800836 def ipsec_spd_interface_dump(self, spd_index=None):
837 return self.api(self.papi.ipsec_spd_interface_dump,
838 {'spd_index': spd_index if spd_index else 0,
839 'spd_index_valid': 1 if spd_index else 0})
840
Neale Ranns17dcec02019-01-09 21:22:20 -0800841 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800842 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200843 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800844 local_address_start,
845 local_address_stop,
846 remote_address_start,
847 remote_address_stop,
848 local_port_start=0,
849 local_port_stop=65535,
850 remote_port_start=0,
851 remote_port_stop=65535,
852 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800853 policy=0,
854 priority=100,
855 is_outbound=1,
856 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200857 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800858 is_ip_any=0):
859 """ IPSEC policy SPD add/del -
860 Wrapper to configure ipsec SPD policy entries in VPP
Dave Wallaced1706812021-08-12 18:36:02 -0400861
Klement Sekera31da2e32018-06-24 22:49:55 +0200862 :param spd_id: SPD ID for the policy
863 :param local_address_start: local-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400864 :param local_address_stop: local-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200865 :param remote_address_start: remote-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400866 :param remote_address_stop: remote-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200867 :param local_port_start: (Default value = 0)
868 :param local_port_stop: (Default value = 65535)
869 :param remote_port_start: (Default value = 0)
870 :param remote_port_stop: (Default value = 65535)
871 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
872 :param sa_id: Security Association ID for mapping it to SPD
873 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
Dave Wallaced1706812021-08-12 18:36:02 -0400874 (Default value = 0)
Klement Sekera31da2e32018-06-24 22:49:55 +0200875 :param priority: value for the spd action (Default value = 100)
876 :param is_outbound: flag for inbound(0) or outbound(1)
Dave Wallaced1706812021-08-12 18:36:02 -0400877 (Default value = 1)
Klement Sekera31da2e32018-06-24 22:49:55 +0200878 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800879 """
880 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800881 self.papi.ipsec_spd_entry_add_del,
882 {
883 'is_add': is_add,
884 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100885 {
886 'spd_id': spd_id,
887 'sa_id': sa_id,
888 'local_address_start': local_address_start,
889 'local_address_stop': local_address_stop,
890 'remote_address_start': remote_address_start,
891 'remote_address_stop': remote_address_stop,
892 'local_port_start': local_port_start,
893 'local_port_stop': local_port_stop,
894 'remote_port_start': remote_port_start,
895 'remote_port_stop': remote_port_stop,
896 'protocol': protocol,
897 'policy': policy,
898 'priority': priority,
899 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100900 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800901 })
Florin Corasb795bd02017-12-14 11:30:48 -0800902
Neale Ranns311124e2019-01-24 04:52:25 -0800903 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
904 return self.api(self.papi.ipsec_spd_dump,
905 {'spd_id': spd_id,
906 'sa_id': sa_id})
907
Klement Sekera31da2e32018-06-24 22:49:55 +0200908 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
909 remote_spi, crypto_alg, local_crypto_key,
910 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000911 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700912 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000913 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200914 return self.api(
915 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400916 {
917 'local_ip': local_ip,
918 'remote_ip': remote_ip,
919 'local_spi': local_spi,
920 'remote_spi': remote_spi,
921 'crypto_alg': crypto_alg,
922 'local_crypto_key_len': len(local_crypto_key),
923 'local_crypto_key': local_crypto_key,
924 'remote_crypto_key_len': len(remote_crypto_key),
925 'remote_crypto_key': remote_crypto_key,
926 'integ_alg': integ_alg,
927 'local_integ_key_len': len(local_integ_key),
928 'local_integ_key': local_integ_key,
929 'remote_integ_key_len': len(remote_integ_key),
930 'remote_integ_key': remote_integ_key,
931 'is_add': is_add,
932 'esn': esn,
933 'anti_replay': anti_replay,
934 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000935 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700936 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000937 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400938 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200939
Klement Sekerab4d30532018-11-08 13:00:02 +0100940 def ipsec_select_backend(self, protocol, index):
941 return self.api(self.papi.ipsec_select_backend,
942 {'protocol': protocol, 'index': index})
943
944 def ipsec_backend_dump(self):
945 return self.api(self.papi.ipsec_backend_dump, {})
946
Neale Ranns50f0ac02019-05-15 02:13:37 -0700947 def punt_socket_register(self, reg, pathname,
948 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100949 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200950 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100951 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700952 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100953 'pathname': pathname})
954
Neale Ranns50f0ac02019-05-15 02:13:37 -0700955 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100956 """ Unregister punt socket """
957 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700958 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200959
Neale Ranns947ea622018-06-07 23:48:20 -0700960 def igmp_enable_disable(self, sw_if_index, enable, host):
961 """ Enable/disable IGMP on a given interface """
962 return self.api(self.papi.igmp_enable_disable,
963 {'enable': enable,
964 'mode': host,
965 'sw_if_index': sw_if_index})
966
Jakub Grajciar97748ca2018-10-04 11:05:35 +0200967 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
968 """ Add/del IGMP proxy device """
969 return self.api(self.papi.igmp_proxy_device_add_del,
970 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
971 'add': add})
972
973 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
974 """ Add/del interface to/from IGMP proxy device """
975 return self.api(self.papi.igmp_proxy_device_add_del_interface,
976 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
977 'add': add})
978
Neale Ranns947ea622018-06-07 23:48:20 -0700979 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100980 """ Listen for new (S,G) on specified interface
981
Dave Wallaced1706812021-08-12 18:36:02 -0400982 :param enable: add/delas
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100983 :param sw_if_index: interface sw index
984 :param saddr: source ip4 addr
985 :param gaddr: group ip4 addr
986 """
987 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -0700988 {
989 'group':
Ole Troan9a475372019-03-05 16:58:24 +0100990 {
991 'filter': filter,
992 'sw_if_index': sw_if_index,
993 'n_srcs': len(saddrs),
994 'saddrs': saddrs,
995 'gaddr': gaddr
996 }
Neale Ranns947ea622018-06-07 23:48:20 -0700997 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100998
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100999 def igmp_clear_interface(self, sw_if_index):
1000 """ Remove all (S,G)s from specified interface
1001 doesn't send IGMP report!
1002 """
1003 return self.api(
1004 self.papi.igmp_clear_interface, {
1005 'sw_if_index': sw_if_index})
1006
1007 def want_igmp_events(self, enable=1):
1008 return self.api(self.papi.want_igmp_events, {'enable': enable,
1009 'pid': os.getpid()})