blob: 1c5b6c5084f0e8d8f04a72212b2c40cd4b646c59 [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
Paul Vinciguerra19542292019-03-17 17:34:46 -070013from vpp_papi import VPPApiClient, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070015from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020016
Ole Troanf159f582019-02-28 20:20:47 +010017#
18# Dictionary keyed on message name to override default values for
19# named parameters
20#
Ole Troan9a475372019-03-05 16:58:24 +010021defaultmapping = {
Paul Vinciguerrac0e94412020-04-28 01:12:04 -040022
Ole Troan9a475372019-03-05 16:58:24 +010023 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
Ole Troan9a475372019-03-05 16:58:24 +010024 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020025 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
26 'conf_key_id': None},
27 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
28 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010029 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
30 'is_add': 1, },
31 'bier_disp_table_add_del': {'is_add': 1, },
32 'bier_imp_add': {'is_add': 1, },
33 'bier_route_add_del': {'is_add': 1, },
34 'bier_table_add_del': {'is_add': 1, },
35 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
36 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070037 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010038 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
39 'decap_next_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010040 'input_acl_set_interface': {'ip4_table_index': 4294967295,
41 'ip6_table_index': 4294967295,
42 'l2_table_index': 4294967295, },
43 'ip6_add_del_address_using_prefix': {'is_add': 1, },
44 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
45 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
46 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010047 'classify_table_index': 4294967295, 'is_add': 1, },
48 'ip_mroute_add_del': {'is_add': 1, },
49 'ip_neighbor_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010050 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010051 'ipsec_spd_add_del': {'is_add': 1, },
52 'ipsec_spd_dump': {'sa_id': 4294967295, },
53 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
54 'remote_port_stop': 65535, 'priority': 100,
55 'is_outbound': 1,
56 'is_add': 1, },
57 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
58 'l2_emulation': {'enable': 1, },
59 'l2fib_add_del': {'is_add': 1, },
60 'lisp_add_del_adjacency': {'is_add': 1, },
61 'lisp_add_del_local_eid': {'is_add': 1, },
62 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
63 'lisp_add_del_locator_set': {'is_add': 1, },
64 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010065 'macip_acl_interface_add_del': {'is_add': 1, },
66 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010067 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
68 'mr_next_hop_weight': 1,
69 'mr_next_hop_via_label': 1048576,
70 'mr_is_add': 1,
71 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010072 'mpls_table_add_del': {'is_add': 1, },
73 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
74 'next_hop_weight': 1,
75 'next_hop_via_label': 1048576,
76 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010077 'output_acl_set_interface': {'ip4_table_index': 4294967295,
78 'ip6_table_index': 4294967295,
79 'l2_table_index': 4294967295, },
80 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010081 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010082 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010083 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010084 'sw_interface_add_del_address': {'is_add': 1, },
85 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
86 'pref_lifetime': 4294967295, },
87 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
88 'sw_interface_set_l2_bridge': {'enable': 1, },
89 'sw_interface_set_mpls_enable': {'enable': 1, },
90 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
91 'sw_interface_set_unnumbered': {'is_add': 1, },
92 'sw_interface_span_enable_disable': {'state': 1, },
93 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
94 'decap_next_index': 4294967295,
95 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010096 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010097 'want_igmp_events': {'enable': 1, },
98 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +020099 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100100 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100101}
Ole Troanf159f582019-02-28 20:20:47 +0100102
Matus Fabianb4515b42018-11-19 04:25:32 -0800103
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400104def as_fn_signature(d):
105 return ", ".join(f"{k}={v}" for k, v in d.items())
106
107
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400108class CliFailedCommandError(Exception):
109 """ cli command failed."""
110
111
112class CliSyntaxError(Exception):
113 """ cli command had a syntax error."""
114
115
Klement Sekera73884482017-02-23 09:26:30 +0100116class UnexpectedApiReturnValueError(Exception):
117 """ exception raised when the API return value is unexpected """
118 pass
119
120
Klement Sekeraf62ae122016-10-11 11:47:09 +0200121class VppPapiProvider(object):
122 """VPP-api provider using vpp-papi
123
124 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200125 """
126
Klement Sekerae0545ef2017-01-25 08:00:40 +0100127 _zero, _negative = range(2)
128
Ole Troan4376ab22021-03-03 10:40:05 +0100129 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800130 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200131 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100132 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100133 self._expect_api_retval = self._zero
134 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100135
Paul Vinciguerra19542292019-03-17 17:34:46 -0700136 # install_dir is a class attribute. We need to set it before
137 # calling the constructor.
138 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800139
Paul Vinciguerra19542292019-03-17 17:34:46 -0700140 self.vpp = VPPApiClient(logger=test_class.logger,
141 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100142 use_socket=True,
Klement Sekerae2636852021-03-16 12:52:12 +0100143 server_address=test_class.get_api_sock_path())
Ole Troan4376ab22021-03-03 10:40:05 +0100144 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200145
Klement Sekerae0545ef2017-01-25 08:00:40 +0100146 def __enter__(self):
147 return self
148
Klement Sekera7d6afb32018-11-08 11:52:04 +0100149 def assert_negative_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400150 """ Expect API failure - used with with, e.g.::
151
152 with self.vapi.assert_negative_api_retval():
153 self.vapi.<api call expected to fail>
154
155 ..
Klement Sekera7d6afb32018-11-08 11:52:04 +0100156 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100157 self._expect_stack.append(self._expect_api_retval)
158 self._expect_api_retval = self._negative
159 return self
160
Klement Sekera7d6afb32018-11-08 11:52:04 +0100161 def assert_zero_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400162 """ Expect API success - used with with, e.g.::
Klement Sekera7d6afb32018-11-08 11:52:04 +0100163
Dave Wallaced1706812021-08-12 18:36:02 -0400164 with self.vapi.assert_negative_api_retval():
165 self.vapi.<api call expected to succeed>
166
167 :note: this is useful only inside another with block
168 as success is the default expected value
Klement Sekera7d6afb32018-11-08 11:52:04 +0100169 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100170 self._expect_stack.append(self._expect_api_retval)
171 self._expect_api_retval = self._zero
172 return self
173
174 def __exit__(self, exc_type, exc_value, traceback):
175 self._expect_api_retval = self._expect_stack.pop()
176
Klement Sekeraf62ae122016-10-11 11:47:09 +0200177 def register_hook(self, hook):
178 """Replace hook registration with new hook
179
180 :param hook:
181
182 """
183 self.hook = hook
184
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200185 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100186 """ Collect all events from the internal queue and clear the queue. """
Ole Troan4376ab22021-03-03 10:40:05 +0100187 result = []
188 while True:
189 try:
190 e = self._events.get(block=False)
191 result.append(e)
192 except queue.Empty:
193 return result
194 return result
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200195
196 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100197 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100198 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100199 self.test_class.logger.debug("Expecting event '%s' within %ss",
200 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300201 else:
202 self.test_class.logger.debug("Expecting event within %ss",
203 timeout)
Ole Troan4376ab22021-03-03 10:40:05 +0100204 try:
205 e = self._events.get(timeout=timeout)
206 except queue.Empty:
207 raise Exception("Event did not occur within timeout")
208 msgname = type(e).__name__
209 if name and msgname != name:
210 raise Exception("Unexpected event received: %s, expected: %s"
211 % msgname)
212 self.test_class.logger.debug("Returning event %s:%s" % (name, e))
213 return e
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200214
215 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100216 """ Enqueue event in the internal event queue. """
Klement Sekerae4504c62016-12-08 10:16:41 +0100217 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Ole Troan4376ab22021-03-03 10:40:05 +0100218 self._events.put(event)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200219
Ole Troanf159f582019-02-28 20:20:47 +0100220 def factory(self, name, apifn):
221 def f(*a, **ka):
222 fields = apifn._func.msg.fields
223
224 # add positional and kw arguments
225 d = ka
226 for i, o in enumerate(fields[3:]):
227 try:
228 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200229 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100230 break
231
232 # Default override
233 if name in defaultmapping:
234 for k, v in iteritems(defaultmapping[name]):
235 if k in d:
236 continue
237 d[k] = v
238 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100239
Ole Troanf159f582019-02-28 20:20:47 +0100240 return f
241
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800242 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100243 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800244 method = super(VppPapiProvider, self).__getattribute__(name)
245 except AttributeError:
246 method = self.factory(name, getattr(self.papi, name))
247 # lazily load the method so we don't need to call factory
248 # again for this name.
249 setattr(self, name, method)
250 return method
Ole Troanf159f582019-02-28 20:20:47 +0100251
Klement Sekeraf62ae122016-10-11 11:47:09 +0200252 def connect(self):
253 """Connect the API to VPP"""
Ole Troan4376ab22021-03-03 10:40:05 +0100254 # This might be called before VPP is prepared to listen to the socket
255 retries = 0
Klement Sekerae2636852021-03-16 12:52:12 +0100256 while not os.path.exists(self.test_class.get_api_sock_path()):
Ole Troan4376ab22021-03-03 10:40:05 +0100257 time.sleep(0.5)
258 retries += 1
259 if retries > 120:
260 break
261 self.vpp.connect(self.name[:63])
Klement Sekera7112c542017-03-01 09:53:19 +0100262 self.papi = self.vpp.api
263 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200264
265 def disconnect(self):
266 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100267 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200268
269 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100270 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200271 Call the appropriate hooks before and after the API call
272
273 :param api_fn: API function to call
274 :param api_args: tuple of API function arguments
275 :param expected_retval: Expected return value (Default value = 0)
276 :returns: reply from the API
277
278 """
279 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100280 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100281 if self._expect_api_retval == self._negative:
282 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400283 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100284 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400285 (api_fn.__name__, as_fn_signature(api_args),
286 reply.retval,
287 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100288 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100289 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100290 elif self._expect_api_retval == self._zero:
291 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400292 msg = "%s(%s) failed, expected %d return value instead " \
293 "of %d in %s" % (api_fn.__name__,
294 as_fn_signature(api_args),
295 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400296 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100297 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100298 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100299 else:
300 raise Exception("Internal error, unexpected value for "
301 "self._expect_api_retval %s" %
302 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200303 self.hook.after_api(api_fn.__name__, api_args)
304 return reply
305
Dave Barach5932ce12019-10-09 17:28:04 -0400306 def cli_return_response(self, cli):
307 """ Execute a CLI, calling the before/after hooks appropriately.
308 Return the reply without examining it
309
310 :param cli: CLI to execute
311 :returns: response object
312
313 """
314 self.hook.before_cli(cli)
315 cli += '\n'
316 r = self.papi.cli_inband(cmd=cli)
317 self.hook.after_cli(cli)
318 return r
319
Klement Sekeraf62ae122016-10-11 11:47:09 +0200320 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100321 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200322
323 :param cli: CLI to execute
324 :returns: CLI output
325
326 """
Dave Barach5932ce12019-10-09 17:28:04 -0400327 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400328 if r.retval == -156:
329 raise CliSyntaxError(r.reply)
330 if r.retval != 0:
331 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200332 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100333 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200334
Jan49c0fca2016-10-26 15:44:27 +0200335 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100336 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200337
338 :param cli: CLI to execute
339 :returns: CLI output
340 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200341 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200342
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100343 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
344 mrc=0, mrd=0):
345 return self.api(self.papi.ip6nd_send_router_solicitation,
346 {'irt': irt,
347 'mrt': mrt,
348 'mrc': mrc,
349 'mrd': mrd,
350 'sw_if_index': sw_if_index})
351
Juraj Slobodab3f90502018-10-04 15:15:16 +0200352 def want_interface_events(self, enable_disable=1):
353 return self.api(self.papi.want_interface_events,
354 {'enable_disable': enable_disable,
355 'pid': os.getpid(), })
356
Neale Rannsc819fc62018-02-16 02:44:05 -0800357 def sw_interface_set_mac_address(self, sw_if_index, mac):
358 return self.api(self.papi.sw_interface_set_mac_address,
359 {'sw_if_index': sw_if_index,
360 'mac_address': mac})
361
Ole Troane1ade682019-03-04 23:55:43 +0100362 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200363 """Create p2p ethernet subinterface
364
365 :param sw_if_index: main (parent) interface
366 :param remote_mac: client (remote) mac address
367
368 """
369 return self.api(
370 self.papi.p2p_ethernet_add,
371 {'parent_if_index': sw_if_index,
372 'remote_mac': remote_mac,
373 'subif_id': subif_id})
374
Ole Troane1ade682019-03-04 23:55:43 +0100375 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200376 """Delete p2p ethernet subinterface
377
378 :param sw_if_index: main (parent) interface
379 :param remote_mac: client (remote) mac address
380
381 """
382 return self.api(
383 self.papi.p2p_ethernet_del,
384 {'parent_if_index': sw_if_index,
385 'remote_mac': remote_mac})
386
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387 def create_vlan_subif(self, sw_if_index, vlan):
388 """
389
390 :param vlan:
391 :param sw_if_index:
392
393 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100394 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200395 {'sw_if_index': sw_if_index,
396 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200397
Matej Klotton0178d522016-11-04 11:11:44 +0100398 def create_loopback(self, mac=''):
399 """
400
401 :param mac: (Optional)
402 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100403 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200404 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100405
Neale Ranns097fa662018-05-01 05:17:55 -0700406 def ip_route_dump(self, table_id, is_ip6=False):
407 return self.api(self.papi.ip_route_dump,
408 {'table': {
409 'table_id': table_id,
410 'is_ip6': is_ip6
411 }})
412
Neale Ranns976b2592019-12-04 06:11:00 +0000413 def ip_route_v2_dump(self, table_id, is_ip6=False, src=0):
414 return self.api(self.papi.ip_route_v2_dump,
415 {
416 'src': src,
417 'table': {
418 'table_id': table_id,
419 'is_ip6': is_ip6
420 }
421 })
422
Matej Klotton0178d522016-11-04 11:11:44 +0100423 def ip_neighbor_add_del(self,
424 sw_if_index,
425 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700426 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100427 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700428 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100429 """ Add neighbor MAC to IPv4 or IPv6 address.
430
431 :param sw_if_index:
432 :param mac_address:
433 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100434 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700435 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100436 """
Matej Klotton0178d522016-11-04 11:11:44 +0100437 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100438 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700439 {
440 'is_add': is_add,
441 'neighbor': {
442 'sw_if_index': sw_if_index,
443 'flags': flags,
444 'mac_address': mac_address,
445 'ip_address': ip_address
446 }
447 }
Matej Klotton0178d522016-11-04 11:11:44 +0100448 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100449
Neale Rannsd0df49f2018-08-08 01:06:40 -0700450 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700451 src_ip,
452 dst_ip,
453 src_port,
454 dst_port,
455 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800456 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800457 :param src_ip:
458 :param dst_ip:
459 :param src_port:
460 :param dst_port:
461 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800462 """
463
464 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700465 self.papi.udp_encap_add,
466 {
467 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700468 'src_ip': src_ip,
469 'dst_ip': dst_ip,
470 'src_port': src_port,
471 'dst_port': dst_port,
472 'table_id': table_id
473 }
474 })
475
Neale Ranns097fa662018-05-01 05:17:55 -0700476 def udp_encap_del(self, id):
477 return self.api(self.papi.udp_encap_del, {'id': id})
478
479 def udp_encap_dump(self):
480 return self.api(self.papi.udp_encap_dump, {})
481
482 def want_udp_encap_stats(self, enable=1):
483 return self.api(self.papi.want_udp_encap_stats,
484 {'enable': enable,
485 'pid': os.getpid()})
486
487 def mpls_route_dump(self, table_id):
488 return self.api(self.papi.mpls_route_dump,
489 {'table': {
490 'mt_table_id': table_id
491 }})
492
493 def mpls_table_dump(self):
494 return self.api(self.papi.mpls_table_dump, {})
495
Neale Ranns15002542017-09-10 04:39:11 -0700496 def mpls_table_add_del(
497 self,
498 table_id,
499 is_add=1):
500 """
501
502 :param table_id
503 :param is_add: (Default value = 1)
504
505 """
506
507 return self.api(
508 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700509 {'mt_table':
510 {
511 'mt_table_id': table_id,
512 },
Neale Ranns15002542017-09-10 04:39:11 -0700513 'mt_is_add': is_add})
514
Neale Ranns097fa662018-05-01 05:17:55 -0700515 def mpls_route_add_del(self,
516 table_id,
517 label,
518 eos,
519 eos_proto,
520 is_multicast,
521 paths,
522 is_add,
523 is_multipath):
524 """ MPLS Route add/del """
525 return self.api(
526 self.papi.mpls_route_add_del,
527 {'mr_route':
528 {
529 'mr_table_id': table_id,
530 'mr_label': label,
531 'mr_eos': eos,
532 'mr_eos_proto': eos_proto,
533 'mr_is_multicast': is_multicast,
534 'mr_n_paths': len(paths),
535 'mr_paths': paths,
536 },
537 'mr_is_add': is_add,
538 'mr_is_multipath': is_multipath})
539
Neale Rannsad422ed2016-11-02 14:20:04 +0000540 def mpls_ip_bind_unbind(
541 self,
542 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700543 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000544 table_id=0,
545 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000546 is_bind=1):
547 """
548 """
549 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100550 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200551 {'mb_mpls_table_id': table_id,
552 'mb_label': label,
553 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200554 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700555 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000556
557 def mpls_tunnel_add_del(
558 self,
559 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700560 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000561 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800562 l2_only=0,
563 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000564 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000565 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000566 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100567 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700568 {'mt_is_add': is_add,
569 'mt_tunnel':
570 {
571 'mt_sw_if_index': tun_sw_if_index,
572 'mt_l2_only': l2_only,
573 'mt_is_multicast': is_multicast,
574 'mt_n_paths': len(paths),
575 'mt_paths': paths,
576 }})
Matus Fabiande886752016-12-07 03:38:19 -0800577
Steve Shin7957d6e2016-12-19 09:24:50 -0800578 def input_acl_set_interface(
579 self,
580 is_add,
581 sw_if_index,
582 ip4_table_index=0xFFFFFFFF,
583 ip6_table_index=0xFFFFFFFF,
584 l2_table_index=0xFFFFFFFF):
585 """
586 :param is_add:
587 :param sw_if_index:
588 :param ip4_table_index: (Default value = 0xFFFFFFFF)
589 :param ip6_table_index: (Default value = 0xFFFFFFFF)
590 :param l2_table_index: (Default value = 0xFFFFFFFF)
591 """
592
593 return self.api(
594 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100595 {'sw_if_index': sw_if_index,
596 'ip4_table_index': ip4_table_index,
597 'ip6_table_index': ip6_table_index,
598 'l2_table_index': l2_table_index,
599 'is_add': is_add})
600
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100601 def output_acl_set_interface(
602 self,
603 is_add,
604 sw_if_index,
605 ip4_table_index=0xFFFFFFFF,
606 ip6_table_index=0xFFFFFFFF,
607 l2_table_index=0xFFFFFFFF):
608 """
609 :param is_add:
610 :param sw_if_index:
611 :param ip4_table_index: (Default value = 0xFFFFFFFF)
612 :param ip6_table_index: (Default value = 0xFFFFFFFF)
613 :param l2_table_index: (Default value = 0xFFFFFFFF)
614 """
615
616 return self.api(
617 self.papi.output_acl_set_interface,
618 {'sw_if_index': sw_if_index,
619 'ip4_table_index': ip4_table_index,
620 'ip6_table_index': ip6_table_index,
621 'l2_table_index': l2_table_index,
622 'is_add': is_add})
623
Klement Sekera77fabdb2017-01-02 07:46:14 +0100624 def set_ipfix_exporter(
625 self,
626 collector_address,
627 src_address,
628 path_mtu,
629 template_interval,
630 vrf_id=0,
631 collector_port=4739,
632 udp_checksum=0):
633 return self.api(
634 self.papi.set_ipfix_exporter,
635 {
636 'collector_address': collector_address,
637 'collector_port': collector_port,
638 'src_address': src_address,
639 'vrf_id': vrf_id,
640 'path_mtu': path_mtu,
641 'template_interval': template_interval,
642 'udp_checksum': udp_checksum,
643 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800644
Neale Ranns097fa662018-05-01 05:17:55 -0700645 def mfib_signal_dump(self):
646 return self.api(self.papi.mfib_signal_dump, {})
647
648 def ip_mroute_dump(self, table_id, is_ip6=False):
649 return self.api(self.papi.ip_mroute_dump,
650 {'table': {
651 'table_id': table_id,
652 'is_ip6': is_ip6
653 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000654
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800655 def pppoe_add_del_session(
656 self,
657 client_ip,
658 client_mac,
659 session_id=0,
660 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800661 decap_vrf_id=0):
662 """
663
664 :param is_add: (Default value = 1)
665 :param is_ipv6: (Default value = 0)
666 :param client_ip:
667 :param session_id: (Default value = 0)
668 :param client_mac:
669 :param decap_vrf_id: (Default value = 0)
670
671 """
672 return self.api(self.papi.pppoe_add_del_session,
673 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800674 'session_id': session_id,
675 'client_ip': client_ip,
676 'decap_vrf_id': decap_vrf_id,
677 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200678
Neale Ranns7c922dc2018-08-30 06:12:27 -0700679 def sr_mpls_policy_add(self, bsid, weight, type, segments):
680 return self.api(self.papi.sr_mpls_policy_add,
681 {'bsid': bsid,
682 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100683 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700684 'n_segments': len(segments),
685 'segments': segments})
686
687 def sr_mpls_policy_del(self, bsid):
688 return self.api(self.papi.sr_mpls_policy_del,
689 {'bsid': bsid})
690
Neale Rannsd792d9c2017-10-21 10:53:20 -0700691 def bier_table_add_del(self,
692 bti,
693 mpls_label,
694 is_add=1):
695 """ BIER Table add/del """
696 return self.api(
697 self.papi.bier_table_add_del,
698 {'bt_tbl_id': {"bt_set": bti.set_id,
699 "bt_sub_domain": bti.sub_domain_id,
700 "bt_hdr_len_id": bti.hdr_len_id},
701 'bt_label': mpls_label,
702 'bt_is_add': is_add})
703
704 def bier_table_dump(self):
705 return self.api(self.papi.bier_table_dump, {})
706
707 def bier_route_add_del(self,
708 bti,
709 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800710 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700711 is_add=1,
712 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700713 """ BIER Route add/del """
714 return self.api(
715 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700716 {
717 'br_route': {
718 'br_tbl_id': {"bt_set": bti.set_id,
719 "bt_sub_domain": bti.sub_domain_id,
720 "bt_hdr_len_id": bti.hdr_len_id},
721 'br_bp': bp,
722 'br_n_paths': len(paths),
723 'br_paths': paths,
724 },
725 'br_is_add': is_add,
726 'br_is_replace': is_replace
727 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700728
729 def bier_route_dump(self, bti):
730 return self.api(
731 self.papi.bier_route_dump,
732 {'br_tbl_id': {"bt_set": bti.set_id,
733 "bt_sub_domain": bti.sub_domain_id,
734 "bt_hdr_len_id": bti.hdr_len_id}})
735
736 def bier_imp_add(self,
737 bti,
738 src,
739 ibytes,
740 is_add=1):
741 """ BIER Imposition Add """
742 return self.api(
743 self.papi.bier_imp_add,
744 {'bi_tbl_id': {"bt_set": bti.set_id,
745 "bt_sub_domain": bti.sub_domain_id,
746 "bt_hdr_len_id": bti.hdr_len_id},
747 'bi_src': src,
748 'bi_n_bytes': len(ibytes),
749 'bi_bytes': ibytes})
750
751 def bier_imp_del(self, bi_index):
752 """ BIER Imposition del """
753 return self.api(
754 self.papi.bier_imp_del,
755 {'bi_index': bi_index})
756
757 def bier_imp_dump(self):
758 return self.api(self.papi.bier_imp_dump, {})
759
760 def bier_disp_table_add_del(self,
761 bdti,
762 is_add=1):
763 """ BIER Disposition Table add/del """
764 return self.api(
765 self.papi.bier_disp_table_add_del,
766 {'bdt_tbl_id': bdti,
767 'bdt_is_add': is_add})
768
769 def bier_disp_table_dump(self):
770 return self.api(self.papi.bier_disp_table_dump, {})
771
772 def bier_disp_entry_add_del(self,
773 bdti,
774 bp,
775 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800776 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700777 next_hop,
778 next_hop_tbl_id=0,
779 next_hop_rpf_id=~0,
780 next_hop_is_ip4=1,
781 is_add=1):
782 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800783 lstack = []
784 while (len(lstack) < 16):
785 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700786 return self.api(
787 self.papi.bier_disp_entry_add_del,
788 {'bde_tbl_id': bdti,
789 'bde_bp': bp,
790 'bde_payload_proto': payload_proto,
791 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400792 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700793 'rpf_id': next_hop_rpf_id,
794 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800795 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700796 'bde_is_add': is_add})
797
798 def bier_disp_entry_dump(self, bdti):
799 return self.api(
800 self.papi.bier_disp_entry_dump,
801 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200802
“mystarrocks”23f0c452017-12-11 07:11:51 -0800803 def ipsec_spd_add_del(self, spd_id, is_add=1):
804 """ SPD add/del - Wrapper to add or del ipsec SPD
805 Sample CLI : 'ipsec spd add 1'
806
807 :param spd_id - SPD ID to be created in the vpp . mandatory
808 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
Dave Wallaced1706812021-08-12 18:36:02 -0400809 optional
“mystarrocks”23f0c452017-12-11 07:11:51 -0800810 :returns: reply from the API
811 """
812 return self.api(
813 self.papi.ipsec_spd_add_del, {
814 'spd_id': spd_id, 'is_add': is_add})
815
Neale Ranns311124e2019-01-24 04:52:25 -0800816 def ipsec_spds_dump(self):
817 return self.api(self.papi.ipsec_spds_dump, {})
818
“mystarrocks”23f0c452017-12-11 07:11:51 -0800819 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
820 """ IPSEC interface SPD add/del - \
821 Wrapper to associate/disassociate SPD to interface in VPP
822 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
823
824 :param spd_id - SPD ID to associate with the interface . mandatory
825 :param sw_if_index - Interface Index which needs to ipsec \
826 association mandatory
827 :param is_add - add(1) or del(0) association with interface \
828 (Default 1 - add) . optional
829 :returns: reply from the API
830 """
831 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200832 self.papi.ipsec_interface_add_del_spd,
833 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800834
Neale Ranns311124e2019-01-24 04:52:25 -0800835 def ipsec_spd_interface_dump(self, spd_index=None):
836 return self.api(self.papi.ipsec_spd_interface_dump,
837 {'spd_index': spd_index if spd_index else 0,
838 'spd_index_valid': 1 if spd_index else 0})
839
Neale Ranns17dcec02019-01-09 21:22:20 -0800840 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800841 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200842 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800843 local_address_start,
844 local_address_stop,
845 remote_address_start,
846 remote_address_stop,
847 local_port_start=0,
848 local_port_stop=65535,
849 remote_port_start=0,
850 remote_port_stop=65535,
851 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800852 policy=0,
853 priority=100,
854 is_outbound=1,
855 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200856 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800857 is_ip_any=0):
858 """ IPSEC policy SPD add/del -
859 Wrapper to configure ipsec SPD policy entries in VPP
Dave Wallaced1706812021-08-12 18:36:02 -0400860
Klement Sekera31da2e32018-06-24 22:49:55 +0200861 :param spd_id: SPD ID for the policy
862 :param local_address_start: local-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400863 :param local_address_stop: local-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200864 :param remote_address_start: remote-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400865 :param remote_address_stop: remote-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200866 :param local_port_start: (Default value = 0)
867 :param local_port_stop: (Default value = 65535)
868 :param remote_port_start: (Default value = 0)
869 :param remote_port_stop: (Default value = 65535)
870 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
871 :param sa_id: Security Association ID for mapping it to SPD
872 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
Dave Wallaced1706812021-08-12 18:36:02 -0400873 (Default value = 0)
Klement Sekera31da2e32018-06-24 22:49:55 +0200874 :param priority: value for the spd action (Default value = 100)
875 :param is_outbound: flag for inbound(0) or outbound(1)
Dave Wallaced1706812021-08-12 18:36:02 -0400876 (Default value = 1)
Klement Sekera31da2e32018-06-24 22:49:55 +0200877 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800878 """
879 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800880 self.papi.ipsec_spd_entry_add_del,
881 {
882 'is_add': is_add,
883 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100884 {
885 'spd_id': spd_id,
886 'sa_id': sa_id,
887 'local_address_start': local_address_start,
888 'local_address_stop': local_address_stop,
889 'remote_address_start': remote_address_start,
890 'remote_address_stop': remote_address_stop,
891 'local_port_start': local_port_start,
892 'local_port_stop': local_port_stop,
893 'remote_port_start': remote_port_start,
894 'remote_port_stop': remote_port_stop,
895 'protocol': protocol,
896 'policy': policy,
897 'priority': priority,
898 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100899 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800900 })
Florin Corasb795bd02017-12-14 11:30:48 -0800901
Neale Ranns311124e2019-01-24 04:52:25 -0800902 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
903 return self.api(self.papi.ipsec_spd_dump,
904 {'spd_id': spd_id,
905 'sa_id': sa_id})
906
Klement Sekera31da2e32018-06-24 22:49:55 +0200907 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
908 remote_spi, crypto_alg, local_crypto_key,
909 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000910 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700911 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000912 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200913 return self.api(
914 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400915 {
916 'local_ip': local_ip,
917 'remote_ip': remote_ip,
918 'local_spi': local_spi,
919 'remote_spi': remote_spi,
920 'crypto_alg': crypto_alg,
921 'local_crypto_key_len': len(local_crypto_key),
922 'local_crypto_key': local_crypto_key,
923 'remote_crypto_key_len': len(remote_crypto_key),
924 'remote_crypto_key': remote_crypto_key,
925 'integ_alg': integ_alg,
926 'local_integ_key_len': len(local_integ_key),
927 'local_integ_key': local_integ_key,
928 'remote_integ_key_len': len(remote_integ_key),
929 'remote_integ_key': remote_integ_key,
930 'is_add': is_add,
931 'esn': esn,
932 'anti_replay': anti_replay,
933 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000934 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700935 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000936 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400937 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200938
Klement Sekerab4d30532018-11-08 13:00:02 +0100939 def ipsec_select_backend(self, protocol, index):
940 return self.api(self.papi.ipsec_select_backend,
941 {'protocol': protocol, 'index': index})
942
943 def ipsec_backend_dump(self):
944 return self.api(self.papi.ipsec_backend_dump, {})
945
Neale Ranns50f0ac02019-05-15 02:13:37 -0700946 def punt_socket_register(self, reg, pathname,
947 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100948 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200949 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100950 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700951 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100952 'pathname': pathname})
953
Neale Ranns50f0ac02019-05-15 02:13:37 -0700954 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100955 """ Unregister punt socket """
956 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700957 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200958
Neale Ranns947ea622018-06-07 23:48:20 -0700959 def igmp_enable_disable(self, sw_if_index, enable, host):
960 """ Enable/disable IGMP on a given interface """
961 return self.api(self.papi.igmp_enable_disable,
962 {'enable': enable,
963 'mode': host,
964 'sw_if_index': sw_if_index})
965
Jakub Grajciar97748ca2018-10-04 11:05:35 +0200966 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
967 """ Add/del IGMP proxy device """
968 return self.api(self.papi.igmp_proxy_device_add_del,
969 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
970 'add': add})
971
972 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
973 """ Add/del interface to/from IGMP proxy device """
974 return self.api(self.papi.igmp_proxy_device_add_del_interface,
975 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
976 'add': add})
977
Neale Ranns947ea622018-06-07 23:48:20 -0700978 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100979 """ Listen for new (S,G) on specified interface
980
Dave Wallaced1706812021-08-12 18:36:02 -0400981 :param enable: add/delas
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100982 :param sw_if_index: interface sw index
983 :param saddr: source ip4 addr
984 :param gaddr: group ip4 addr
985 """
986 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -0700987 {
988 'group':
Ole Troan9a475372019-03-05 16:58:24 +0100989 {
990 'filter': filter,
991 'sw_if_index': sw_if_index,
992 'n_srcs': len(saddrs),
993 'saddrs': saddrs,
994 'gaddr': gaddr
995 }
Neale Ranns947ea622018-06-07 23:48:20 -0700996 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100997
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100998 def igmp_clear_interface(self, sw_if_index):
999 """ Remove all (S,G)s from specified interface
1000 doesn't send IGMP report!
1001 """
1002 return self.api(
1003 self.papi.igmp_clear_interface, {
1004 'sw_if_index': sw_if_index})
1005
1006 def want_igmp_events(self, enable=1):
1007 return self.api(self.papi.want_igmp_events, {'enable': enable,
1008 'pid': os.getpid()})