blob: 7e87b2c5cd388133c3b278b995bc1144d4bfe06f [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 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
97 'protocol': 3, },
98 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010099 'want_igmp_events': {'enable': 1, },
100 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200101 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100102 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100103}
Ole Troanf159f582019-02-28 20:20:47 +0100104
Matus Fabianb4515b42018-11-19 04:25:32 -0800105
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400106def as_fn_signature(d):
107 return ", ".join(f"{k}={v}" for k, v in d.items())
108
109
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400110class CliFailedCommandError(Exception):
111 """ cli command failed."""
112
113
114class CliSyntaxError(Exception):
115 """ cli command had a syntax error."""
116
117
Klement Sekera73884482017-02-23 09:26:30 +0100118class UnexpectedApiReturnValueError(Exception):
119 """ exception raised when the API return value is unexpected """
120 pass
121
122
Klement Sekeraf62ae122016-10-11 11:47:09 +0200123class VppPapiProvider(object):
124 """VPP-api provider using vpp-papi
125
126 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200127 """
128
Klement Sekerae0545ef2017-01-25 08:00:40 +0100129 _zero, _negative = range(2)
130
Ole Troan4376ab22021-03-03 10:40:05 +0100131 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800132 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200133 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100134 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100135 self._expect_api_retval = self._zero
136 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100137
Paul Vinciguerra19542292019-03-17 17:34:46 -0700138 # install_dir is a class attribute. We need to set it before
139 # calling the constructor.
140 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800141
Paul Vinciguerra19542292019-03-17 17:34:46 -0700142 self.vpp = VPPApiClient(logger=test_class.logger,
143 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100144 use_socket=True,
Klement Sekerae2636852021-03-16 12:52:12 +0100145 server_address=test_class.get_api_sock_path())
Ole Troan4376ab22021-03-03 10:40:05 +0100146 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200147
Klement Sekerae0545ef2017-01-25 08:00:40 +0100148 def __enter__(self):
149 return self
150
Klement Sekera7d6afb32018-11-08 11:52:04 +0100151 def assert_negative_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400152 """ Expect API failure - used with with, e.g.::
153
154 with self.vapi.assert_negative_api_retval():
155 self.vapi.<api call expected to fail>
156
157 ..
Klement Sekera7d6afb32018-11-08 11:52:04 +0100158 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100159 self._expect_stack.append(self._expect_api_retval)
160 self._expect_api_retval = self._negative
161 return self
162
Klement Sekera7d6afb32018-11-08 11:52:04 +0100163 def assert_zero_api_retval(self):
Dave Wallaced1706812021-08-12 18:36:02 -0400164 """ Expect API success - used with with, e.g.::
Klement Sekera7d6afb32018-11-08 11:52:04 +0100165
Dave Wallaced1706812021-08-12 18:36:02 -0400166 with self.vapi.assert_negative_api_retval():
167 self.vapi.<api call expected to succeed>
168
169 :note: this is useful only inside another with block
170 as success is the default expected value
Klement Sekera7d6afb32018-11-08 11:52:04 +0100171 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100172 self._expect_stack.append(self._expect_api_retval)
173 self._expect_api_retval = self._zero
174 return self
175
176 def __exit__(self, exc_type, exc_value, traceback):
177 self._expect_api_retval = self._expect_stack.pop()
178
Klement Sekeraf62ae122016-10-11 11:47:09 +0200179 def register_hook(self, hook):
180 """Replace hook registration with new hook
181
182 :param hook:
183
184 """
185 self.hook = hook
186
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200187 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100188 """ Collect all events from the internal queue and clear the queue. """
Ole Troan4376ab22021-03-03 10:40:05 +0100189 result = []
190 while True:
191 try:
192 e = self._events.get(block=False)
193 result.append(e)
194 except queue.Empty:
195 return result
196 return result
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200197
198 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100199 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100200 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100201 self.test_class.logger.debug("Expecting event '%s' within %ss",
202 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300203 else:
204 self.test_class.logger.debug("Expecting event within %ss",
205 timeout)
Ole Troan4376ab22021-03-03 10:40:05 +0100206 try:
207 e = self._events.get(timeout=timeout)
208 except queue.Empty:
209 raise Exception("Event did not occur within timeout")
210 msgname = type(e).__name__
211 if name and msgname != name:
212 raise Exception("Unexpected event received: %s, expected: %s"
213 % msgname)
214 self.test_class.logger.debug("Returning event %s:%s" % (name, e))
215 return e
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200216
217 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100218 """ Enqueue event in the internal event queue. """
Klement Sekerae4504c62016-12-08 10:16:41 +0100219 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Ole Troan4376ab22021-03-03 10:40:05 +0100220 self._events.put(event)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200221
Ole Troanf159f582019-02-28 20:20:47 +0100222 def factory(self, name, apifn):
223 def f(*a, **ka):
224 fields = apifn._func.msg.fields
225
226 # add positional and kw arguments
227 d = ka
228 for i, o in enumerate(fields[3:]):
229 try:
230 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200231 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100232 break
233
234 # Default override
235 if name in defaultmapping:
236 for k, v in iteritems(defaultmapping[name]):
237 if k in d:
238 continue
239 d[k] = v
240 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100241
Ole Troanf159f582019-02-28 20:20:47 +0100242 return f
243
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800244 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100245 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800246 method = super(VppPapiProvider, self).__getattribute__(name)
247 except AttributeError:
248 method = self.factory(name, getattr(self.papi, name))
249 # lazily load the method so we don't need to call factory
250 # again for this name.
251 setattr(self, name, method)
252 return method
Ole Troanf159f582019-02-28 20:20:47 +0100253
Klement Sekeraf62ae122016-10-11 11:47:09 +0200254 def connect(self):
255 """Connect the API to VPP"""
Ole Troan4376ab22021-03-03 10:40:05 +0100256 # This might be called before VPP is prepared to listen to the socket
257 retries = 0
Klement Sekerae2636852021-03-16 12:52:12 +0100258 while not os.path.exists(self.test_class.get_api_sock_path()):
Ole Troan4376ab22021-03-03 10:40:05 +0100259 time.sleep(0.5)
260 retries += 1
261 if retries > 120:
262 break
263 self.vpp.connect(self.name[:63])
Klement Sekera7112c542017-03-01 09:53:19 +0100264 self.papi = self.vpp.api
265 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200266
267 def disconnect(self):
268 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100269 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200270
271 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100272 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200273 Call the appropriate hooks before and after the API call
274
275 :param api_fn: API function to call
276 :param api_args: tuple of API function arguments
277 :param expected_retval: Expected return value (Default value = 0)
278 :returns: reply from the API
279
280 """
281 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100282 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100283 if self._expect_api_retval == self._negative:
284 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400285 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100286 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400287 (api_fn.__name__, as_fn_signature(api_args),
288 reply.retval,
289 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100290 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100291 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100292 elif self._expect_api_retval == self._zero:
293 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400294 msg = "%s(%s) failed, expected %d return value instead " \
295 "of %d in %s" % (api_fn.__name__,
296 as_fn_signature(api_args),
297 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400298 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100299 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100300 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100301 else:
302 raise Exception("Internal error, unexpected value for "
303 "self._expect_api_retval %s" %
304 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200305 self.hook.after_api(api_fn.__name__, api_args)
306 return reply
307
Dave Barach5932ce12019-10-09 17:28:04 -0400308 def cli_return_response(self, cli):
309 """ Execute a CLI, calling the before/after hooks appropriately.
310 Return the reply without examining it
311
312 :param cli: CLI to execute
313 :returns: response object
314
315 """
316 self.hook.before_cli(cli)
317 cli += '\n'
318 r = self.papi.cli_inband(cmd=cli)
319 self.hook.after_cli(cli)
320 return r
321
Klement Sekeraf62ae122016-10-11 11:47:09 +0200322 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100323 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200324
325 :param cli: CLI to execute
326 :returns: CLI output
327
328 """
Dave Barach5932ce12019-10-09 17:28:04 -0400329 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400330 if r.retval == -156:
331 raise CliSyntaxError(r.reply)
332 if r.retval != 0:
333 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200334 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100335 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200336
Jan49c0fca2016-10-26 15:44:27 +0200337 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100338 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200339
340 :param cli: CLI to execute
341 :returns: CLI output
342 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200343 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200344
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100345 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
346 mrc=0, mrd=0):
347 return self.api(self.papi.ip6nd_send_router_solicitation,
348 {'irt': irt,
349 'mrt': mrt,
350 'mrc': mrc,
351 'mrd': mrd,
352 'sw_if_index': sw_if_index})
353
Juraj Slobodab3f90502018-10-04 15:15:16 +0200354 def want_interface_events(self, enable_disable=1):
355 return self.api(self.papi.want_interface_events,
356 {'enable_disable': enable_disable,
357 'pid': os.getpid(), })
358
Neale Rannsc819fc62018-02-16 02:44:05 -0800359 def sw_interface_set_mac_address(self, sw_if_index, mac):
360 return self.api(self.papi.sw_interface_set_mac_address,
361 {'sw_if_index': sw_if_index,
362 'mac_address': mac})
363
Ole Troane1ade682019-03-04 23:55:43 +0100364 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200365 """Create p2p ethernet subinterface
366
367 :param sw_if_index: main (parent) interface
368 :param remote_mac: client (remote) mac address
369
370 """
371 return self.api(
372 self.papi.p2p_ethernet_add,
373 {'parent_if_index': sw_if_index,
374 'remote_mac': remote_mac,
375 'subif_id': subif_id})
376
Ole Troane1ade682019-03-04 23:55:43 +0100377 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200378 """Delete p2p ethernet subinterface
379
380 :param sw_if_index: main (parent) interface
381 :param remote_mac: client (remote) mac address
382
383 """
384 return self.api(
385 self.papi.p2p_ethernet_del,
386 {'parent_if_index': sw_if_index,
387 'remote_mac': remote_mac})
388
Klement Sekeraf62ae122016-10-11 11:47:09 +0200389 def create_vlan_subif(self, sw_if_index, vlan):
390 """
391
392 :param vlan:
393 :param sw_if_index:
394
395 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100396 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200397 {'sw_if_index': sw_if_index,
398 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200399
Matej Klotton0178d522016-11-04 11:11:44 +0100400 def create_loopback(self, mac=''):
401 """
402
403 :param mac: (Optional)
404 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100405 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200406 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100407
Neale Ranns097fa662018-05-01 05:17:55 -0700408 def ip_route_dump(self, table_id, is_ip6=False):
409 return self.api(self.papi.ip_route_dump,
410 {'table': {
411 'table_id': table_id,
412 'is_ip6': is_ip6
413 }})
414
Neale Ranns976b2592019-12-04 06:11:00 +0000415 def ip_route_v2_dump(self, table_id, is_ip6=False, src=0):
416 return self.api(self.papi.ip_route_v2_dump,
417 {
418 'src': src,
419 'table': {
420 'table_id': table_id,
421 'is_ip6': is_ip6
422 }
423 })
424
Matej Klotton0178d522016-11-04 11:11:44 +0100425 def ip_neighbor_add_del(self,
426 sw_if_index,
427 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700428 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100429 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700430 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100431 """ Add neighbor MAC to IPv4 or IPv6 address.
432
433 :param sw_if_index:
434 :param mac_address:
435 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100436 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700437 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100438 """
Matej Klotton0178d522016-11-04 11:11:44 +0100439 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100440 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700441 {
442 'is_add': is_add,
443 'neighbor': {
444 'sw_if_index': sw_if_index,
445 'flags': flags,
446 'mac_address': mac_address,
447 'ip_address': ip_address
448 }
449 }
Matej Klotton0178d522016-11-04 11:11:44 +0100450 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100451
Neale Rannsd0df49f2018-08-08 01:06:40 -0700452 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700453 src_ip,
454 dst_ip,
455 src_port,
456 dst_port,
457 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800458 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800459 :param src_ip:
460 :param dst_ip:
461 :param src_port:
462 :param dst_port:
463 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800464 """
465
466 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700467 self.papi.udp_encap_add,
468 {
469 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700470 'src_ip': src_ip,
471 'dst_ip': dst_ip,
472 'src_port': src_port,
473 'dst_port': dst_port,
474 'table_id': table_id
475 }
476 })
477
Neale Ranns097fa662018-05-01 05:17:55 -0700478 def udp_encap_del(self, id):
479 return self.api(self.papi.udp_encap_del, {'id': id})
480
481 def udp_encap_dump(self):
482 return self.api(self.papi.udp_encap_dump, {})
483
484 def want_udp_encap_stats(self, enable=1):
485 return self.api(self.papi.want_udp_encap_stats,
486 {'enable': enable,
487 'pid': os.getpid()})
488
489 def mpls_route_dump(self, table_id):
490 return self.api(self.papi.mpls_route_dump,
491 {'table': {
492 'mt_table_id': table_id
493 }})
494
495 def mpls_table_dump(self):
496 return self.api(self.papi.mpls_table_dump, {})
497
Neale Ranns15002542017-09-10 04:39:11 -0700498 def mpls_table_add_del(
499 self,
500 table_id,
501 is_add=1):
502 """
503
504 :param table_id
505 :param is_add: (Default value = 1)
506
507 """
508
509 return self.api(
510 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700511 {'mt_table':
512 {
513 'mt_table_id': table_id,
514 },
Neale Ranns15002542017-09-10 04:39:11 -0700515 'mt_is_add': is_add})
516
Neale Ranns097fa662018-05-01 05:17:55 -0700517 def mpls_route_add_del(self,
518 table_id,
519 label,
520 eos,
521 eos_proto,
522 is_multicast,
523 paths,
524 is_add,
525 is_multipath):
526 """ MPLS Route add/del """
527 return self.api(
528 self.papi.mpls_route_add_del,
529 {'mr_route':
530 {
531 'mr_table_id': table_id,
532 'mr_label': label,
533 'mr_eos': eos,
534 'mr_eos_proto': eos_proto,
535 'mr_is_multicast': is_multicast,
536 'mr_n_paths': len(paths),
537 'mr_paths': paths,
538 },
539 'mr_is_add': is_add,
540 'mr_is_multipath': is_multipath})
541
Neale Rannsad422ed2016-11-02 14:20:04 +0000542 def mpls_ip_bind_unbind(
543 self,
544 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700545 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000546 table_id=0,
547 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000548 is_bind=1):
549 """
550 """
551 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100552 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200553 {'mb_mpls_table_id': table_id,
554 'mb_label': label,
555 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200556 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700557 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000558
559 def mpls_tunnel_add_del(
560 self,
561 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700562 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000563 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800564 l2_only=0,
565 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000566 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000567 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000568 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100569 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700570 {'mt_is_add': is_add,
571 'mt_tunnel':
572 {
573 'mt_sw_if_index': tun_sw_if_index,
574 'mt_l2_only': l2_only,
575 'mt_is_multicast': is_multicast,
576 'mt_n_paths': len(paths),
577 'mt_paths': paths,
578 }})
Matus Fabiande886752016-12-07 03:38:19 -0800579
Steve Shin7957d6e2016-12-19 09:24:50 -0800580 def input_acl_set_interface(
581 self,
582 is_add,
583 sw_if_index,
584 ip4_table_index=0xFFFFFFFF,
585 ip6_table_index=0xFFFFFFFF,
586 l2_table_index=0xFFFFFFFF):
587 """
588 :param is_add:
589 :param sw_if_index:
590 :param ip4_table_index: (Default value = 0xFFFFFFFF)
591 :param ip6_table_index: (Default value = 0xFFFFFFFF)
592 :param l2_table_index: (Default value = 0xFFFFFFFF)
593 """
594
595 return self.api(
596 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100597 {'sw_if_index': sw_if_index,
598 'ip4_table_index': ip4_table_index,
599 'ip6_table_index': ip6_table_index,
600 'l2_table_index': l2_table_index,
601 'is_add': is_add})
602
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100603 def output_acl_set_interface(
604 self,
605 is_add,
606 sw_if_index,
607 ip4_table_index=0xFFFFFFFF,
608 ip6_table_index=0xFFFFFFFF,
609 l2_table_index=0xFFFFFFFF):
610 """
611 :param is_add:
612 :param sw_if_index:
613 :param ip4_table_index: (Default value = 0xFFFFFFFF)
614 :param ip6_table_index: (Default value = 0xFFFFFFFF)
615 :param l2_table_index: (Default value = 0xFFFFFFFF)
616 """
617
618 return self.api(
619 self.papi.output_acl_set_interface,
620 {'sw_if_index': sw_if_index,
621 'ip4_table_index': ip4_table_index,
622 'ip6_table_index': ip6_table_index,
623 'l2_table_index': l2_table_index,
624 'is_add': is_add})
625
Klement Sekera77fabdb2017-01-02 07:46:14 +0100626 def set_ipfix_exporter(
627 self,
628 collector_address,
629 src_address,
630 path_mtu,
631 template_interval,
632 vrf_id=0,
633 collector_port=4739,
634 udp_checksum=0):
635 return self.api(
636 self.papi.set_ipfix_exporter,
637 {
638 'collector_address': collector_address,
639 'collector_port': collector_port,
640 'src_address': src_address,
641 'vrf_id': vrf_id,
642 'path_mtu': path_mtu,
643 'template_interval': template_interval,
644 'udp_checksum': udp_checksum,
645 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800646
Neale Ranns097fa662018-05-01 05:17:55 -0700647 def mfib_signal_dump(self):
648 return self.api(self.papi.mfib_signal_dump, {})
649
650 def ip_mroute_dump(self, table_id, is_ip6=False):
651 return self.api(self.papi.ip_mroute_dump,
652 {'table': {
653 'table_id': table_id,
654 'is_ip6': is_ip6
655 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000656
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800657 def vxlan_gpe_add_del_tunnel(
658 self,
659 src_addr,
660 dst_addr,
661 mcast_sw_if_index=0xFFFFFFFF,
662 is_add=1,
663 is_ipv6=0,
664 encap_vrf_id=0,
665 decap_vrf_id=0,
666 protocol=3,
667 vni=0):
668 """
669
670 :param local:
671 :param remote:
672 :param is_add: (Default value = 1)
673 :param is_ipv6: (Default value = 0)
674 :param encap_vrf_id: (Default value = 0)
675 :param decap_vrf_id: (Default value = 0)
676 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
677 :param protocol: (Default value = 3)
678 :param vni: (Default value = 0)
679
680 """
681 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
682 {'is_add': is_add,
683 'is_ipv6': is_ipv6,
684 'local': src_addr,
685 'remote': dst_addr,
686 'mcast_sw_if_index': mcast_sw_if_index,
687 'encap_vrf_id': encap_vrf_id,
688 'decap_vrf_id': decap_vrf_id,
689 'protocol': protocol,
690 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800691
Neale Ranns79a05f52018-09-11 07:39:43 -0700692 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
693 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000694 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200695
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800696 def pppoe_add_del_session(
697 self,
698 client_ip,
699 client_mac,
700 session_id=0,
701 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800702 decap_vrf_id=0):
703 """
704
705 :param is_add: (Default value = 1)
706 :param is_ipv6: (Default value = 0)
707 :param client_ip:
708 :param session_id: (Default value = 0)
709 :param client_mac:
710 :param decap_vrf_id: (Default value = 0)
711
712 """
713 return self.api(self.papi.pppoe_add_del_session,
714 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800715 'session_id': session_id,
716 'client_ip': client_ip,
717 'decap_vrf_id': decap_vrf_id,
718 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200719
Neale Ranns7c922dc2018-08-30 06:12:27 -0700720 def sr_mpls_policy_add(self, bsid, weight, type, segments):
721 return self.api(self.papi.sr_mpls_policy_add,
722 {'bsid': bsid,
723 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100724 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700725 'n_segments': len(segments),
726 'segments': segments})
727
728 def sr_mpls_policy_del(self, bsid):
729 return self.api(self.papi.sr_mpls_policy_del,
730 {'bsid': bsid})
731
Neale Rannsd792d9c2017-10-21 10:53:20 -0700732 def bier_table_add_del(self,
733 bti,
734 mpls_label,
735 is_add=1):
736 """ BIER Table add/del """
737 return self.api(
738 self.papi.bier_table_add_del,
739 {'bt_tbl_id': {"bt_set": bti.set_id,
740 "bt_sub_domain": bti.sub_domain_id,
741 "bt_hdr_len_id": bti.hdr_len_id},
742 'bt_label': mpls_label,
743 'bt_is_add': is_add})
744
745 def bier_table_dump(self):
746 return self.api(self.papi.bier_table_dump, {})
747
748 def bier_route_add_del(self,
749 bti,
750 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800751 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700752 is_add=1,
753 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700754 """ BIER Route add/del """
755 return self.api(
756 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700757 {
758 'br_route': {
759 'br_tbl_id': {"bt_set": bti.set_id,
760 "bt_sub_domain": bti.sub_domain_id,
761 "bt_hdr_len_id": bti.hdr_len_id},
762 'br_bp': bp,
763 'br_n_paths': len(paths),
764 'br_paths': paths,
765 },
766 'br_is_add': is_add,
767 'br_is_replace': is_replace
768 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700769
770 def bier_route_dump(self, bti):
771 return self.api(
772 self.papi.bier_route_dump,
773 {'br_tbl_id': {"bt_set": bti.set_id,
774 "bt_sub_domain": bti.sub_domain_id,
775 "bt_hdr_len_id": bti.hdr_len_id}})
776
777 def bier_imp_add(self,
778 bti,
779 src,
780 ibytes,
781 is_add=1):
782 """ BIER Imposition Add """
783 return self.api(
784 self.papi.bier_imp_add,
785 {'bi_tbl_id': {"bt_set": bti.set_id,
786 "bt_sub_domain": bti.sub_domain_id,
787 "bt_hdr_len_id": bti.hdr_len_id},
788 'bi_src': src,
789 'bi_n_bytes': len(ibytes),
790 'bi_bytes': ibytes})
791
792 def bier_imp_del(self, bi_index):
793 """ BIER Imposition del """
794 return self.api(
795 self.papi.bier_imp_del,
796 {'bi_index': bi_index})
797
798 def bier_imp_dump(self):
799 return self.api(self.papi.bier_imp_dump, {})
800
801 def bier_disp_table_add_del(self,
802 bdti,
803 is_add=1):
804 """ BIER Disposition Table add/del """
805 return self.api(
806 self.papi.bier_disp_table_add_del,
807 {'bdt_tbl_id': bdti,
808 'bdt_is_add': is_add})
809
810 def bier_disp_table_dump(self):
811 return self.api(self.papi.bier_disp_table_dump, {})
812
813 def bier_disp_entry_add_del(self,
814 bdti,
815 bp,
816 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800817 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700818 next_hop,
819 next_hop_tbl_id=0,
820 next_hop_rpf_id=~0,
821 next_hop_is_ip4=1,
822 is_add=1):
823 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800824 lstack = []
825 while (len(lstack) < 16):
826 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700827 return self.api(
828 self.papi.bier_disp_entry_add_del,
829 {'bde_tbl_id': bdti,
830 'bde_bp': bp,
831 'bde_payload_proto': payload_proto,
832 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400833 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700834 'rpf_id': next_hop_rpf_id,
835 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800836 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700837 'bde_is_add': is_add})
838
839 def bier_disp_entry_dump(self, bdti):
840 return self.api(
841 self.papi.bier_disp_entry_dump,
842 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200843
“mystarrocks”23f0c452017-12-11 07:11:51 -0800844 def ipsec_spd_add_del(self, spd_id, is_add=1):
845 """ SPD add/del - Wrapper to add or del ipsec SPD
846 Sample CLI : 'ipsec spd add 1'
847
848 :param spd_id - SPD ID to be created in the vpp . mandatory
849 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
Dave Wallaced1706812021-08-12 18:36:02 -0400850 optional
“mystarrocks”23f0c452017-12-11 07:11:51 -0800851 :returns: reply from the API
852 """
853 return self.api(
854 self.papi.ipsec_spd_add_del, {
855 'spd_id': spd_id, 'is_add': is_add})
856
Neale Ranns311124e2019-01-24 04:52:25 -0800857 def ipsec_spds_dump(self):
858 return self.api(self.papi.ipsec_spds_dump, {})
859
“mystarrocks”23f0c452017-12-11 07:11:51 -0800860 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
861 """ IPSEC interface SPD add/del - \
862 Wrapper to associate/disassociate SPD to interface in VPP
863 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
864
865 :param spd_id - SPD ID to associate with the interface . mandatory
866 :param sw_if_index - Interface Index which needs to ipsec \
867 association mandatory
868 :param is_add - add(1) or del(0) association with interface \
869 (Default 1 - add) . optional
870 :returns: reply from the API
871 """
872 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200873 self.papi.ipsec_interface_add_del_spd,
874 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800875
Neale Ranns311124e2019-01-24 04:52:25 -0800876 def ipsec_spd_interface_dump(self, spd_index=None):
877 return self.api(self.papi.ipsec_spd_interface_dump,
878 {'spd_index': spd_index if spd_index else 0,
879 'spd_index_valid': 1 if spd_index else 0})
880
Neale Ranns17dcec02019-01-09 21:22:20 -0800881 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800882 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200883 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800884 local_address_start,
885 local_address_stop,
886 remote_address_start,
887 remote_address_stop,
888 local_port_start=0,
889 local_port_stop=65535,
890 remote_port_start=0,
891 remote_port_stop=65535,
892 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800893 policy=0,
894 priority=100,
895 is_outbound=1,
896 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200897 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800898 is_ip_any=0):
899 """ IPSEC policy SPD add/del -
900 Wrapper to configure ipsec SPD policy entries in VPP
Dave Wallaced1706812021-08-12 18:36:02 -0400901
Klement Sekera31da2e32018-06-24 22:49:55 +0200902 :param spd_id: SPD ID for the policy
903 :param local_address_start: local-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400904 :param local_address_stop: local-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200905 :param remote_address_start: remote-ip-range start address
Dave Wallaced1706812021-08-12 18:36:02 -0400906 :param remote_address_stop: remote-ip-range stop address
Klement Sekera31da2e32018-06-24 22:49:55 +0200907 :param local_port_start: (Default value = 0)
908 :param local_port_stop: (Default value = 65535)
909 :param remote_port_start: (Default value = 0)
910 :param remote_port_stop: (Default value = 65535)
911 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
912 :param sa_id: Security Association ID for mapping it to SPD
913 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
Dave Wallaced1706812021-08-12 18:36:02 -0400914 (Default value = 0)
Klement Sekera31da2e32018-06-24 22:49:55 +0200915 :param priority: value for the spd action (Default value = 100)
916 :param is_outbound: flag for inbound(0) or outbound(1)
Dave Wallaced1706812021-08-12 18:36:02 -0400917 (Default value = 1)
Klement Sekera31da2e32018-06-24 22:49:55 +0200918 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800919 """
920 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800921 self.papi.ipsec_spd_entry_add_del,
922 {
923 'is_add': is_add,
924 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100925 {
926 'spd_id': spd_id,
927 'sa_id': sa_id,
928 'local_address_start': local_address_start,
929 'local_address_stop': local_address_stop,
930 'remote_address_start': remote_address_start,
931 'remote_address_stop': remote_address_stop,
932 'local_port_start': local_port_start,
933 'local_port_stop': local_port_stop,
934 'remote_port_start': remote_port_start,
935 'remote_port_stop': remote_port_stop,
936 'protocol': protocol,
937 'policy': policy,
938 'priority': priority,
939 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100940 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800941 })
Florin Corasb795bd02017-12-14 11:30:48 -0800942
Neale Ranns311124e2019-01-24 04:52:25 -0800943 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
944 return self.api(self.papi.ipsec_spd_dump,
945 {'spd_id': spd_id,
946 'sa_id': sa_id})
947
Klement Sekera31da2e32018-06-24 22:49:55 +0200948 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
949 remote_spi, crypto_alg, local_crypto_key,
950 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000951 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700952 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000953 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200954 return self.api(
955 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400956 {
957 'local_ip': local_ip,
958 'remote_ip': remote_ip,
959 'local_spi': local_spi,
960 'remote_spi': remote_spi,
961 'crypto_alg': crypto_alg,
962 'local_crypto_key_len': len(local_crypto_key),
963 'local_crypto_key': local_crypto_key,
964 'remote_crypto_key_len': len(remote_crypto_key),
965 'remote_crypto_key': remote_crypto_key,
966 'integ_alg': integ_alg,
967 'local_integ_key_len': len(local_integ_key),
968 'local_integ_key': local_integ_key,
969 'remote_integ_key_len': len(remote_integ_key),
970 'remote_integ_key': remote_integ_key,
971 'is_add': is_add,
972 'esn': esn,
973 'anti_replay': anti_replay,
974 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000975 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700976 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000977 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400978 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200979
Klement Sekerab4d30532018-11-08 13:00:02 +0100980 def ipsec_select_backend(self, protocol, index):
981 return self.api(self.papi.ipsec_select_backend,
982 {'protocol': protocol, 'index': index})
983
984 def ipsec_backend_dump(self):
985 return self.api(self.papi.ipsec_backend_dump, {})
986
Neale Ranns50f0ac02019-05-15 02:13:37 -0700987 def punt_socket_register(self, reg, pathname,
988 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100989 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200990 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100991 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700992 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100993 'pathname': pathname})
994
Neale Ranns50f0ac02019-05-15 02:13:37 -0700995 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100996 """ Unregister punt socket """
997 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700998 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200999
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001000 def gbp_endpoint_dump(self):
1001 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001002 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001003
Neale Ranns25b04942018-04-04 09:34:50 -07001004 def gbp_recirc_dump(self):
1005 """ GBP recirc Dump """
1006 return self.api(self.papi.gbp_recirc_dump, {})
1007
Neale Rannsb6a47952018-11-21 05:44:35 -08001008 def gbp_ext_itf_dump(self):
1009 """ GBP recirc Dump """
1010 return self.api(self.papi.gbp_ext_itf_dump, {})
1011
Neale Ranns25b04942018-04-04 09:34:50 -07001012 def gbp_subnet_dump(self):
1013 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001014 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001015
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001016 def gbp_contract_dump(self):
1017 """ GBP contract Dump """
1018 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001019
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001020 def gbp_vxlan_tunnel_dump(self):
1021 """ GBP VXLAN tunnel add/del """
1022 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1023
Neale Ranns947ea622018-06-07 23:48:20 -07001024 def igmp_enable_disable(self, sw_if_index, enable, host):
1025 """ Enable/disable IGMP on a given interface """
1026 return self.api(self.papi.igmp_enable_disable,
1027 {'enable': enable,
1028 'mode': host,
1029 'sw_if_index': sw_if_index})
1030
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001031 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1032 """ Add/del IGMP proxy device """
1033 return self.api(self.papi.igmp_proxy_device_add_del,
1034 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1035 'add': add})
1036
1037 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1038 """ Add/del interface to/from IGMP proxy device """
1039 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1040 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1041 'add': add})
1042
Neale Ranns947ea622018-06-07 23:48:20 -07001043 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001044 """ Listen for new (S,G) on specified interface
1045
Dave Wallaced1706812021-08-12 18:36:02 -04001046 :param enable: add/delas
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001047 :param sw_if_index: interface sw index
1048 :param saddr: source ip4 addr
1049 :param gaddr: group ip4 addr
1050 """
1051 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001052 {
1053 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001054 {
1055 'filter': filter,
1056 'sw_if_index': sw_if_index,
1057 'n_srcs': len(saddrs),
1058 'saddrs': saddrs,
1059 'gaddr': gaddr
1060 }
Neale Ranns947ea622018-06-07 23:48:20 -07001061 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001062
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001063 def igmp_clear_interface(self, sw_if_index):
1064 """ Remove all (S,G)s from specified interface
1065 doesn't send IGMP report!
1066 """
1067 return self.api(
1068 self.papi.igmp_clear_interface, {
1069 'sw_if_index': sw_if_index})
1070
1071 def want_igmp_events(self, enable=1):
1072 return self.api(self.papi.want_igmp_events, {'enable': enable,
1073 'pid': os.getpid()})