blob: 9ff616c18e8d57fd510be6d2ebf7ea3013d987e1 [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
Ole Troan4376ab22021-03-03 10:40:05 +010010import queue
Ole Troanf159f582019-02-28 20:20:47 +010011from six import moves, iteritems
Klement Sekerab23ffd72021-05-31 16:08:53 +020012from config import config
Klement Sekera77c821c2022-04-14 16:29:07 +020013from vpp_papi import VPPApiClient
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Klement Sekera77c821c2022-04-14 16:29:07 +020015from vpp_papi_exceptions import CliFailedCommandError, CliSyntaxError,\
16 UnexpectedApiReturnValueError
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
Klement Sekeraf62ae122016-10-11 11:47:09 +0200109class VppPapiProvider(object):
110 """VPP-api provider using vpp-papi
111
112 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200113 """
114
Klement Sekerae0545ef2017-01-25 08:00:40 +0100115 _zero, _negative = range(2)
116
Ole Troan4376ab22021-03-03 10:40:05 +0100117 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800118 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200119 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100120 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100121 self._expect_api_retval = self._zero
122 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100123
Paul Vinciguerra19542292019-03-17 17:34:46 -0700124 # install_dir is a class attribute. We need to set it before
125 # calling the constructor.
Klement Sekerab23ffd72021-05-31 16:08:53 +0200126 VPPApiClient.apidir = config.vpp_install_dir
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800127
Paul Vinciguerra19542292019-03-17 17:34:46 -0700128 self.vpp = VPPApiClient(logger=test_class.logger,
129 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100130 use_socket=True,
Klement Sekerae2636852021-03-16 12:52:12 +0100131 server_address=test_class.get_api_sock_path())
Ole Troan4376ab22021-03-03 10:40:05 +0100132 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200133
Klement Sekerae0545ef2017-01-25 08:00:40 +0100134 def __enter__(self):
135 return self
136
Klement Sekera7d6afb32018-11-08 11:52:04 +0100137 def assert_negative_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400138 """ Expect API failure - used with with, e.g.::
139
140 with self.vapi.assert_negative_api_retval():
141 self.vapi.<api call expected to fail>
142
143 ..
Klement Sekera7d6afb32018-11-08 11:52:04 +0100144 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100145 self._expect_stack.append(self._expect_api_retval)
146 self._expect_api_retval = self._negative
147 return self
148
Klement Sekera7d6afb32018-11-08 11:52:04 +0100149 def assert_zero_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400150 """ Expect API success - used with with, e.g.::
Klement Sekera7d6afb32018-11-08 11:52:04 +0100151
Dave Wallaced1706812021-08-12 18:36:02 -0400152 with self.vapi.assert_negative_api_retval():
153 self.vapi.<api call expected to succeed>
154
155 :note: this is useful only inside another with block
156 as success is the default expected value
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._zero
160 return self
161
162 def __exit__(self, exc_type, exc_value, traceback):
163 self._expect_api_retval = self._expect_stack.pop()
164
Klement Sekeraf62ae122016-10-11 11:47:09 +0200165 def register_hook(self, hook):
166 """Replace hook registration with new hook
167
168 :param hook:
169
170 """
171 self.hook = hook
172
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200173 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100174 """ Collect all events from the internal queue and clear the queue. """
Ole Troan4376ab22021-03-03 10:40:05 +0100175 result = []
176 while True:
177 try:
178 e = self._events.get(block=False)
179 result.append(e)
180 except queue.Empty:
181 return result
182 return result
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200183
184 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100185 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100186 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100187 self.test_class.logger.debug("Expecting event '%s' within %ss",
188 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300189 else:
190 self.test_class.logger.debug("Expecting event within %ss",
191 timeout)
Ole Troan4376ab22021-03-03 10:40:05 +0100192 try:
193 e = self._events.get(timeout=timeout)
194 except queue.Empty:
195 raise Exception("Event did not occur within timeout")
196 msgname = type(e).__name__
197 if name and msgname != name:
198 raise Exception("Unexpected event received: %s, expected: %s"
199 % msgname)
200 self.test_class.logger.debug("Returning event %s:%s" % (name, e))
201 return e
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200202
203 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100204 """ Enqueue event in the internal event queue. """
Klement Sekerae4504c62016-12-08 10:16:41 +0100205 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Ole Troan4376ab22021-03-03 10:40:05 +0100206 self._events.put(event)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200207
Ole Troanf159f582019-02-28 20:20:47 +0100208 def factory(self, name, apifn):
209 def f(*a, **ka):
210 fields = apifn._func.msg.fields
211
212 # add positional and kw arguments
213 d = ka
214 for i, o in enumerate(fields[3:]):
215 try:
216 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200217 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100218 break
219
220 # Default override
221 if name in defaultmapping:
222 for k, v in iteritems(defaultmapping[name]):
223 if k in d:
224 continue
225 d[k] = v
226 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100227
Ole Troanf159f582019-02-28 20:20:47 +0100228 return f
229
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800230 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100231 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800232 method = super(VppPapiProvider, self).__getattribute__(name)
233 except AttributeError:
234 method = self.factory(name, getattr(self.papi, name))
235 # lazily load the method so we don't need to call factory
236 # again for this name.
237 setattr(self, name, method)
238 return method
Ole Troanf159f582019-02-28 20:20:47 +0100239
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240 def connect(self):
241 """Connect the API to VPP"""
Ole Troan4376ab22021-03-03 10:40:05 +0100242 # This might be called before VPP is prepared to listen to the socket
243 retries = 0
Klement Sekerae2636852021-03-16 12:52:12 +0100244 while not os.path.exists(self.test_class.get_api_sock_path()):
Ole Troan4376ab22021-03-03 10:40:05 +0100245 time.sleep(0.5)
246 retries += 1
247 if retries > 120:
248 break
249 self.vpp.connect(self.name[:63])
Klement Sekera7112c542017-03-01 09:53:19 +0100250 self.papi = self.vpp.api
251 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200252
253 def disconnect(self):
254 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100255 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256
257 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100258 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200259 Call the appropriate hooks before and after the API call
260
261 :param api_fn: API function to call
262 :param api_args: tuple of API function arguments
263 :param expected_retval: Expected return value (Default value = 0)
264 :returns: reply from the API
265
266 """
267 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100268 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100269 if self._expect_api_retval == self._negative:
270 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400271 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100272 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400273 (api_fn.__name__, as_fn_signature(api_args),
274 reply.retval,
275 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100276 self.test_class.logger.info(msg)
Klement Sekera77c821c2022-04-14 16:29:07 +0200277 raise UnexpectedApiReturnValueError(reply.retval, msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100278 elif self._expect_api_retval == self._zero:
279 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400280 msg = "%s(%s) failed, expected %d return value instead " \
281 "of %d in %s" % (api_fn.__name__,
282 as_fn_signature(api_args),
283 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400284 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100285 self.test_class.logger.info(msg)
Klement Sekera77c821c2022-04-14 16:29:07 +0200286 raise UnexpectedApiReturnValueError(reply.retval, msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100287 else:
288 raise Exception("Internal error, unexpected value for "
289 "self._expect_api_retval %s" %
290 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200291 self.hook.after_api(api_fn.__name__, api_args)
292 return reply
293
Dave Barach5932ce12019-10-09 17:28:04 -0400294 def cli_return_response(self, cli):
295 """ Execute a CLI, calling the before/after hooks appropriately.
296 Return the reply without examining it
297
298 :param cli: CLI to execute
299 :returns: response object
300
301 """
302 self.hook.before_cli(cli)
303 cli += '\n'
304 r = self.papi.cli_inband(cmd=cli)
305 self.hook.after_cli(cli)
306 return r
307
Klement Sekeraf62ae122016-10-11 11:47:09 +0200308 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100309 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200310
311 :param cli: CLI to execute
312 :returns: CLI output
313
314 """
Dave Barach5932ce12019-10-09 17:28:04 -0400315 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400316 if r.retval == -156:
317 raise CliSyntaxError(r.reply)
318 if r.retval != 0:
319 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200320 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100321 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200322
Jan49c0fca2016-10-26 15:44:27 +0200323 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100324 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200325
326 :param cli: CLI to execute
327 :returns: CLI output
328 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200329 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200330
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100331 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
332 mrc=0, mrd=0):
333 return self.api(self.papi.ip6nd_send_router_solicitation,
334 {'irt': irt,
335 'mrt': mrt,
336 'mrc': mrc,
337 'mrd': mrd,
338 'sw_if_index': sw_if_index})
339
Juraj Slobodab3f90502018-10-04 15:15:16 +0200340 def want_interface_events(self, enable_disable=1):
341 return self.api(self.papi.want_interface_events,
342 {'enable_disable': enable_disable,
343 'pid': os.getpid(), })
344
Neale Rannsc819fc62018-02-16 02:44:05 -0800345 def sw_interface_set_mac_address(self, sw_if_index, mac):
346 return self.api(self.papi.sw_interface_set_mac_address,
347 {'sw_if_index': sw_if_index,
348 'mac_address': mac})
349
Ole Troane1ade682019-03-04 23:55:43 +0100350 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200351 """Create p2p ethernet subinterface
352
353 :param sw_if_index: main (parent) interface
354 :param remote_mac: client (remote) mac address
355
356 """
357 return self.api(
358 self.papi.p2p_ethernet_add,
359 {'parent_if_index': sw_if_index,
360 'remote_mac': remote_mac,
361 'subif_id': subif_id})
362
Ole Troane1ade682019-03-04 23:55:43 +0100363 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200364 """Delete 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_del,
372 {'parent_if_index': sw_if_index,
373 'remote_mac': remote_mac})
374
Klement Sekeraf62ae122016-10-11 11:47:09 +0200375 def create_vlan_subif(self, sw_if_index, vlan):
376 """
377
378 :param vlan:
379 :param sw_if_index:
380
381 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100382 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200383 {'sw_if_index': sw_if_index,
384 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200385
Matej Klotton0178d522016-11-04 11:11:44 +0100386 def create_loopback(self, mac=''):
387 """
388
389 :param mac: (Optional)
390 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100391 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200392 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100393
Neale Ranns097fa662018-05-01 05:17:55 -0700394 def ip_route_dump(self, table_id, is_ip6=False):
395 return self.api(self.papi.ip_route_dump,
396 {'table': {
397 'table_id': table_id,
398 'is_ip6': is_ip6
399 }})
400
Neale Ranns976b2592019-12-04 06:11:00 +0000401 def ip_route_v2_dump(self, table_id, is_ip6=False, src=0):
402 return self.api(self.papi.ip_route_v2_dump,
403 {
404 'src': src,
405 'table': {
406 'table_id': table_id,
407 'is_ip6': is_ip6
408 }
409 })
410
Matej Klotton0178d522016-11-04 11:11:44 +0100411 def ip_neighbor_add_del(self,
412 sw_if_index,
413 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700414 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100415 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700416 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100417 """ Add neighbor MAC to IPv4 or IPv6 address.
418
419 :param sw_if_index:
420 :param mac_address:
421 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100422 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700423 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100424 """
Matej Klotton0178d522016-11-04 11:11:44 +0100425 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100426 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700427 {
428 'is_add': is_add,
429 'neighbor': {
430 'sw_if_index': sw_if_index,
431 'flags': flags,
432 'mac_address': mac_address,
433 'ip_address': ip_address
434 }
435 }
Matej Klotton0178d522016-11-04 11:11:44 +0100436 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100437
Neale Rannsd0df49f2018-08-08 01:06:40 -0700438 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700439 src_ip,
440 dst_ip,
441 src_port,
442 dst_port,
443 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800444 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800445 :param src_ip:
446 :param dst_ip:
447 :param src_port:
448 :param dst_port:
449 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800450 """
451
452 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700453 self.papi.udp_encap_add,
454 {
455 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700456 'src_ip': src_ip,
457 'dst_ip': dst_ip,
458 'src_port': src_port,
459 'dst_port': dst_port,
460 'table_id': table_id
461 }
462 })
463
Neale Ranns097fa662018-05-01 05:17:55 -0700464 def udp_encap_del(self, id):
465 return self.api(self.papi.udp_encap_del, {'id': id})
466
467 def udp_encap_dump(self):
468 return self.api(self.papi.udp_encap_dump, {})
469
470 def want_udp_encap_stats(self, enable=1):
471 return self.api(self.papi.want_udp_encap_stats,
472 {'enable': enable,
473 'pid': os.getpid()})
474
475 def mpls_route_dump(self, table_id):
476 return self.api(self.papi.mpls_route_dump,
477 {'table': {
478 'mt_table_id': table_id
479 }})
480
481 def mpls_table_dump(self):
482 return self.api(self.papi.mpls_table_dump, {})
483
Neale Ranns15002542017-09-10 04:39:11 -0700484 def mpls_table_add_del(
485 self,
486 table_id,
487 is_add=1):
488 """
489
490 :param table_id
491 :param is_add: (Default value = 1)
492
493 """
494
495 return self.api(
496 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700497 {'mt_table':
498 {
499 'mt_table_id': table_id,
500 },
Neale Ranns15002542017-09-10 04:39:11 -0700501 'mt_is_add': is_add})
502
Neale Ranns097fa662018-05-01 05:17:55 -0700503 def mpls_route_add_del(self,
504 table_id,
505 label,
506 eos,
507 eos_proto,
508 is_multicast,
509 paths,
510 is_add,
511 is_multipath):
512 """ MPLS Route add/del """
513 return self.api(
514 self.papi.mpls_route_add_del,
515 {'mr_route':
516 {
517 'mr_table_id': table_id,
518 'mr_label': label,
519 'mr_eos': eos,
520 'mr_eos_proto': eos_proto,
521 'mr_is_multicast': is_multicast,
522 'mr_n_paths': len(paths),
523 'mr_paths': paths,
524 },
525 'mr_is_add': is_add,
526 'mr_is_multipath': is_multipath})
527
Neale Rannsad422ed2016-11-02 14:20:04 +0000528 def mpls_ip_bind_unbind(
529 self,
530 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700531 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000532 table_id=0,
533 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000534 is_bind=1):
535 """
536 """
537 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100538 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200539 {'mb_mpls_table_id': table_id,
540 'mb_label': label,
541 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200542 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700543 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000544
545 def mpls_tunnel_add_del(
546 self,
547 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700548 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000549 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800550 l2_only=0,
551 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000552 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000553 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000554 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100555 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700556 {'mt_is_add': is_add,
557 'mt_tunnel':
558 {
559 'mt_sw_if_index': tun_sw_if_index,
560 'mt_l2_only': l2_only,
561 'mt_is_multicast': is_multicast,
562 'mt_n_paths': len(paths),
563 'mt_paths': paths,
564 }})
Matus Fabiande886752016-12-07 03:38:19 -0800565
Steve Shin7957d6e2016-12-19 09:24:50 -0800566 def input_acl_set_interface(
567 self,
568 is_add,
569 sw_if_index,
570 ip4_table_index=0xFFFFFFFF,
571 ip6_table_index=0xFFFFFFFF,
572 l2_table_index=0xFFFFFFFF):
573 """
574 :param is_add:
575 :param sw_if_index:
576 :param ip4_table_index: (Default value = 0xFFFFFFFF)
577 :param ip6_table_index: (Default value = 0xFFFFFFFF)
578 :param l2_table_index: (Default value = 0xFFFFFFFF)
579 """
580
581 return self.api(
582 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100583 {'sw_if_index': sw_if_index,
584 'ip4_table_index': ip4_table_index,
585 'ip6_table_index': ip6_table_index,
586 'l2_table_index': l2_table_index,
587 'is_add': is_add})
588
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100589 def output_acl_set_interface(
590 self,
591 is_add,
592 sw_if_index,
593 ip4_table_index=0xFFFFFFFF,
594 ip6_table_index=0xFFFFFFFF,
595 l2_table_index=0xFFFFFFFF):
596 """
597 :param is_add:
598 :param sw_if_index:
599 :param ip4_table_index: (Default value = 0xFFFFFFFF)
600 :param ip6_table_index: (Default value = 0xFFFFFFFF)
601 :param l2_table_index: (Default value = 0xFFFFFFFF)
602 """
603
604 return self.api(
605 self.papi.output_acl_set_interface,
606 {'sw_if_index': sw_if_index,
607 'ip4_table_index': ip4_table_index,
608 'ip6_table_index': ip6_table_index,
609 'l2_table_index': l2_table_index,
610 'is_add': is_add})
611
Klement Sekera77fabdb2017-01-02 07:46:14 +0100612 def set_ipfix_exporter(
613 self,
614 collector_address,
615 src_address,
616 path_mtu,
617 template_interval,
618 vrf_id=0,
619 collector_port=4739,
620 udp_checksum=0):
621 return self.api(
622 self.papi.set_ipfix_exporter,
623 {
624 'collector_address': collector_address,
625 'collector_port': collector_port,
626 'src_address': src_address,
627 'vrf_id': vrf_id,
628 'path_mtu': path_mtu,
629 'template_interval': template_interval,
630 'udp_checksum': udp_checksum,
631 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800632
Neale Ranns097fa662018-05-01 05:17:55 -0700633 def mfib_signal_dump(self):
634 return self.api(self.papi.mfib_signal_dump, {})
635
636 def ip_mroute_dump(self, table_id, is_ip6=False):
637 return self.api(self.papi.ip_mroute_dump,
638 {'table': {
639 'table_id': table_id,
640 'is_ip6': is_ip6
641 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000642
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800643 def pppoe_add_del_session(
644 self,
645 client_ip,
646 client_mac,
647 session_id=0,
648 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800649 decap_vrf_id=0):
650 """
651
652 :param is_add: (Default value = 1)
653 :param is_ipv6: (Default value = 0)
654 :param client_ip:
655 :param session_id: (Default value = 0)
656 :param client_mac:
657 :param decap_vrf_id: (Default value = 0)
658
659 """
660 return self.api(self.papi.pppoe_add_del_session,
661 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800662 'session_id': session_id,
663 'client_ip': client_ip,
664 'decap_vrf_id': decap_vrf_id,
665 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200666
Neale Ranns7c922dc2018-08-30 06:12:27 -0700667 def sr_mpls_policy_add(self, bsid, weight, type, segments):
668 return self.api(self.papi.sr_mpls_policy_add,
669 {'bsid': bsid,
670 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100671 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700672 'n_segments': len(segments),
673 'segments': segments})
674
675 def sr_mpls_policy_del(self, bsid):
676 return self.api(self.papi.sr_mpls_policy_del,
677 {'bsid': bsid})
678
Neale Rannsd792d9c2017-10-21 10:53:20 -0700679 def bier_table_add_del(self,
680 bti,
681 mpls_label,
682 is_add=1):
683 """ BIER Table add/del """
684 return self.api(
685 self.papi.bier_table_add_del,
686 {'bt_tbl_id': {"bt_set": bti.set_id,
687 "bt_sub_domain": bti.sub_domain_id,
688 "bt_hdr_len_id": bti.hdr_len_id},
689 'bt_label': mpls_label,
690 'bt_is_add': is_add})
691
692 def bier_table_dump(self):
693 return self.api(self.papi.bier_table_dump, {})
694
695 def bier_route_add_del(self,
696 bti,
697 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800698 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700699 is_add=1,
700 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700701 """ BIER Route add/del """
702 return self.api(
703 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700704 {
705 'br_route': {
706 'br_tbl_id': {"bt_set": bti.set_id,
707 "bt_sub_domain": bti.sub_domain_id,
708 "bt_hdr_len_id": bti.hdr_len_id},
709 'br_bp': bp,
710 'br_n_paths': len(paths),
711 'br_paths': paths,
712 },
713 'br_is_add': is_add,
714 'br_is_replace': is_replace
715 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700716
717 def bier_route_dump(self, bti):
718 return self.api(
719 self.papi.bier_route_dump,
720 {'br_tbl_id': {"bt_set": bti.set_id,
721 "bt_sub_domain": bti.sub_domain_id,
722 "bt_hdr_len_id": bti.hdr_len_id}})
723
724 def bier_imp_add(self,
725 bti,
726 src,
727 ibytes,
728 is_add=1):
729 """ BIER Imposition Add """
730 return self.api(
731 self.papi.bier_imp_add,
732 {'bi_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 'bi_src': src,
736 'bi_n_bytes': len(ibytes),
737 'bi_bytes': ibytes})
738
739 def bier_imp_del(self, bi_index):
740 """ BIER Imposition del """
741 return self.api(
742 self.papi.bier_imp_del,
743 {'bi_index': bi_index})
744
745 def bier_imp_dump(self):
746 return self.api(self.papi.bier_imp_dump, {})
747
748 def bier_disp_table_add_del(self,
749 bdti,
750 is_add=1):
751 """ BIER Disposition Table add/del """
752 return self.api(
753 self.papi.bier_disp_table_add_del,
754 {'bdt_tbl_id': bdti,
755 'bdt_is_add': is_add})
756
757 def bier_disp_table_dump(self):
758 return self.api(self.papi.bier_disp_table_dump, {})
759
760 def bier_disp_entry_add_del(self,
761 bdti,
762 bp,
763 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800764 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700765 next_hop,
766 next_hop_tbl_id=0,
767 next_hop_rpf_id=~0,
768 next_hop_is_ip4=1,
769 is_add=1):
770 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800771 lstack = []
772 while (len(lstack) < 16):
773 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700774 return self.api(
775 self.papi.bier_disp_entry_add_del,
776 {'bde_tbl_id': bdti,
777 'bde_bp': bp,
778 'bde_payload_proto': payload_proto,
779 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400780 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700781 'rpf_id': next_hop_rpf_id,
782 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800783 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700784 'bde_is_add': is_add})
785
786 def bier_disp_entry_dump(self, bdti):
787 return self.api(
788 self.papi.bier_disp_entry_dump,
789 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200790
“mystarrocks”23f0c452017-12-11 07:11:51 -0800791 def ipsec_spd_add_del(self, spd_id, is_add=1):
792 """ SPD add/del - Wrapper to add or del ipsec SPD
793 Sample CLI : 'ipsec spd add 1'
794
795 :param spd_id - SPD ID to be created in the vpp . mandatory
796 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
Dave Wallaced1706812021-08-12 18:36:02 -0400797 optional
“mystarrocks”23f0c452017-12-11 07:11:51 -0800798 :returns: reply from the API
799 """
800 return self.api(
801 self.papi.ipsec_spd_add_del, {
802 'spd_id': spd_id, 'is_add': is_add})
803
Neale Ranns311124e2019-01-24 04:52:25 -0800804 def ipsec_spds_dump(self):
805 return self.api(self.papi.ipsec_spds_dump, {})
806
“mystarrocks”23f0c452017-12-11 07:11:51 -0800807 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
808 """ IPSEC interface SPD add/del - \
809 Wrapper to associate/disassociate SPD to interface in VPP
810 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
811
812 :param spd_id - SPD ID to associate with the interface . mandatory
813 :param sw_if_index - Interface Index which needs to ipsec \
814 association mandatory
815 :param is_add - add(1) or del(0) association with interface \
816 (Default 1 - add) . optional
817 :returns: reply from the API
818 """
819 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200820 self.papi.ipsec_interface_add_del_spd,
821 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800822
Neale Ranns311124e2019-01-24 04:52:25 -0800823 def ipsec_spd_interface_dump(self, spd_index=None):
824 return self.api(self.papi.ipsec_spd_interface_dump,
825 {'spd_index': spd_index if spd_index else 0,
826 'spd_index_valid': 1 if spd_index else 0})
827
Neale Ranns17dcec02019-01-09 21:22:20 -0800828 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800829 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200830 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800831 local_address_start,
832 local_address_stop,
833 remote_address_start,
834 remote_address_stop,
835 local_port_start=0,
836 local_port_stop=65535,
837 remote_port_start=0,
838 remote_port_stop=65535,
839 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800840 policy=0,
841 priority=100,
842 is_outbound=1,
843 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200844 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800845 is_ip_any=0):
846 """ IPSEC policy SPD add/del -
847 Wrapper to configure ipsec SPD policy entries in VPP
Dave Wallaced1706812021-08-12 18:36:02 -0400848
Klement Sekera31da2e32018-06-24 22:49:55 +0200849 :param spd_id: SPD ID for the policy
850 :param local_address_start: local-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400851 :param local_address_stop: local-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200852 :param remote_address_start: remote-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400853 :param remote_address_stop: remote-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200854 :param local_port_start: (Default value = 0)
855 :param local_port_stop: (Default value = 65535)
856 :param remote_port_start: (Default value = 0)
857 :param remote_port_stop: (Default value = 65535)
858 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
859 :param sa_id: Security Association ID for mapping it to SPD
860 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
Dave Wallaced1706812021-08-12 18:36:02 -0400861 (Default value = 0)
Klement Sekera31da2e32018-06-24 22:49:55 +0200862 :param priority: value for the spd action (Default value = 100)
863 :param is_outbound: flag for inbound(0) or outbound(1)
Dave Wallaced1706812021-08-12 18:36:02 -0400864 (Default value = 1)
Klement Sekera31da2e32018-06-24 22:49:55 +0200865 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800866 """
867 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800868 self.papi.ipsec_spd_entry_add_del,
869 {
870 'is_add': is_add,
871 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100872 {
873 'spd_id': spd_id,
874 'sa_id': sa_id,
875 'local_address_start': local_address_start,
876 'local_address_stop': local_address_stop,
877 'remote_address_start': remote_address_start,
878 'remote_address_stop': remote_address_stop,
879 'local_port_start': local_port_start,
880 'local_port_stop': local_port_stop,
881 'remote_port_start': remote_port_start,
882 'remote_port_stop': remote_port_stop,
883 'protocol': protocol,
884 'policy': policy,
885 'priority': priority,
886 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100887 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800888 })
Florin Corasb795bd02017-12-14 11:30:48 -0800889
Neale Ranns311124e2019-01-24 04:52:25 -0800890 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
891 return self.api(self.papi.ipsec_spd_dump,
892 {'spd_id': spd_id,
893 'sa_id': sa_id})
894
Klement Sekera31da2e32018-06-24 22:49:55 +0200895 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
896 remote_spi, crypto_alg, local_crypto_key,
897 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000898 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700899 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000900 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200901 return self.api(
902 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400903 {
904 'local_ip': local_ip,
905 'remote_ip': remote_ip,
906 'local_spi': local_spi,
907 'remote_spi': remote_spi,
908 'crypto_alg': crypto_alg,
909 'local_crypto_key_len': len(local_crypto_key),
910 'local_crypto_key': local_crypto_key,
911 'remote_crypto_key_len': len(remote_crypto_key),
912 'remote_crypto_key': remote_crypto_key,
913 'integ_alg': integ_alg,
914 'local_integ_key_len': len(local_integ_key),
915 'local_integ_key': local_integ_key,
916 'remote_integ_key_len': len(remote_integ_key),
917 'remote_integ_key': remote_integ_key,
918 'is_add': is_add,
919 'esn': esn,
920 'anti_replay': anti_replay,
921 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000922 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700923 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000924 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400925 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200926
Klement Sekerab4d30532018-11-08 13:00:02 +0100927 def ipsec_select_backend(self, protocol, index):
928 return self.api(self.papi.ipsec_select_backend,
929 {'protocol': protocol, 'index': index})
930
931 def ipsec_backend_dump(self):
932 return self.api(self.papi.ipsec_backend_dump, {})
933
Neale Ranns50f0ac02019-05-15 02:13:37 -0700934 def punt_socket_register(self, reg, pathname,
935 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100936 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200937 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100938 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700939 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100940 'pathname': pathname})
941
Neale Ranns50f0ac02019-05-15 02:13:37 -0700942 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100943 """ Unregister punt socket """
944 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700945 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200946
Neale Ranns947ea622018-06-07 23:48:20 -0700947 def igmp_enable_disable(self, sw_if_index, enable, host):
948 """ Enable/disable IGMP on a given interface """
949 return self.api(self.papi.igmp_enable_disable,
950 {'enable': enable,
951 'mode': host,
952 'sw_if_index': sw_if_index})
953
Jakub Grajciar97748ca2018-10-04 11:05:35 +0200954 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
955 """ Add/del IGMP proxy device """
956 return self.api(self.papi.igmp_proxy_device_add_del,
957 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
958 'add': add})
959
960 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
961 """ Add/del interface to/from IGMP proxy device """
962 return self.api(self.papi.igmp_proxy_device_add_del_interface,
963 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
964 'add': add})
965
Neale Ranns947ea622018-06-07 23:48:20 -0700966 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100967 """ Listen for new (S,G) on specified interface
968
Dave Wallaced1706812021-08-12 18:36:02 -0400969 :param enable: add/delas
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100970 :param sw_if_index: interface sw index
971 :param saddr: source ip4 addr
972 :param gaddr: group ip4 addr
973 """
974 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -0700975 {
976 'group':
Ole Troan9a475372019-03-05 16:58:24 +0100977 {
978 'filter': filter,
979 'sw_if_index': sw_if_index,
980 'n_srcs': len(saddrs),
981 'saddrs': saddrs,
982 'gaddr': gaddr
983 }
Neale Ranns947ea622018-06-07 23:48:20 -0700984 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100985
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100986 def igmp_clear_interface(self, sw_if_index):
987 """ Remove all (S,G)s from specified interface
988 doesn't send IGMP report!
989 """
990 return self.api(
991 self.papi.igmp_clear_interface, {
992 'sw_if_index': sw_if_index})
993
994 def want_igmp_events(self, enable=1):
995 return self.api(self.papi.want_igmp_events, {'enable': enable,
996 'pid': os.getpid()})