blob: da693c73e2ac7a3be4c0160ce8d4bac4b1c64c3e [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 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
39 '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, },
Neale Ranns097fa662018-05-01 05:17:55 -070051 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010052 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010053 'ipsec_spd_add_del': {'is_add': 1, },
54 'ipsec_spd_dump': {'sa_id': 4294967295, },
55 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
56 'remote_port_stop': 65535, 'priority': 100,
57 'is_outbound': 1,
58 'is_add': 1, },
59 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
60 'l2_emulation': {'enable': 1, },
61 'l2fib_add_del': {'is_add': 1, },
62 'lisp_add_del_adjacency': {'is_add': 1, },
63 'lisp_add_del_local_eid': {'is_add': 1, },
64 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
65 'lisp_add_del_locator_set': {'is_add': 1, },
66 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010067 'macip_acl_interface_add_del': {'is_add': 1, },
68 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010069 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
70 'mr_next_hop_weight': 1,
71 'mr_next_hop_via_label': 1048576,
72 'mr_is_add': 1,
73 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010074 'mpls_table_add_del': {'is_add': 1, },
75 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
76 'next_hop_weight': 1,
77 'next_hop_via_label': 1048576,
78 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010079 'output_acl_set_interface': {'ip4_table_index': 4294967295,
80 'ip6_table_index': 4294967295,
81 'l2_table_index': 4294967295, },
82 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010083 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010084 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010085 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010086 'sw_interface_add_del_address': {'is_add': 1, },
87 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
88 'pref_lifetime': 4294967295, },
89 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
90 'sw_interface_set_l2_bridge': {'enable': 1, },
91 'sw_interface_set_mpls_enable': {'enable': 1, },
92 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
93 'sw_interface_set_unnumbered': {'is_add': 1, },
94 'sw_interface_span_enable_disable': {'state': 1, },
95 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
96 'decap_next_index': 4294967295,
97 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010098 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
99 'protocol': 3, },
100 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100101 'want_igmp_events': {'enable': 1, },
102 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200103 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100104 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100105}
Ole Troanf159f582019-02-28 20:20:47 +0100106
Matus Fabianb4515b42018-11-19 04:25:32 -0800107
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400108def as_fn_signature(d):
109 return ", ".join(f"{k}={v}" for k, v in d.items())
110
111
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400112class CliFailedCommandError(Exception):
113 """ cli command failed."""
114
115
116class CliSyntaxError(Exception):
117 """ cli command had a syntax error."""
118
119
Klement Sekera73884482017-02-23 09:26:30 +0100120class UnexpectedApiReturnValueError(Exception):
121 """ exception raised when the API return value is unexpected """
122 pass
123
124
Klement Sekeraf62ae122016-10-11 11:47:09 +0200125class VppPapiProvider(object):
126 """VPP-api provider using vpp-papi
127
128 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200129 """
130
Klement Sekerae0545ef2017-01-25 08:00:40 +0100131 _zero, _negative = range(2)
132
Ole Troan4376ab22021-03-03 10:40:05 +0100133 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800134 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200135 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100136 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100137 self._expect_api_retval = self._zero
138 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100139
Paul Vinciguerra19542292019-03-17 17:34:46 -0700140 # install_dir is a class attribute. We need to set it before
141 # calling the constructor.
142 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800143
Paul Vinciguerra19542292019-03-17 17:34:46 -0700144 self.vpp = VPPApiClient(logger=test_class.logger,
145 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100146 use_socket=True,
Paul Vinciguerra19542292019-03-17 17:34:46 -0700147 server_address=test_class.api_sock)
Ole Troan4376ab22021-03-03 10:40:05 +0100148 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200149
Klement Sekerae0545ef2017-01-25 08:00:40 +0100150 def __enter__(self):
151 return self
152
Klement Sekera7d6afb32018-11-08 11:52:04 +0100153 def assert_negative_api_retval(self):
154 """ Expect API failure - used with with, e.g.:
155 with self.vapi.assert_negative_api_retval():
156 self.vapi.<api call expected to fail>
157 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100158 self._expect_stack.append(self._expect_api_retval)
159 self._expect_api_retval = self._negative
160 return self
161
Klement Sekera7d6afb32018-11-08 11:52:04 +0100162 def assert_zero_api_retval(self):
163 """ Expect API success - used with with, e.g.:
164 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
169 """
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
256 while not os.path.exists(self.test_class.api_sock):
257 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
Matej Klotton0178d522016-11-04 11:11:44 +0100413 def ip_neighbor_add_del(self,
414 sw_if_index,
415 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700416 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100417 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700418 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100419 """ Add neighbor MAC to IPv4 or IPv6 address.
420
421 :param sw_if_index:
422 :param mac_address:
423 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100424 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700425 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100426 """
Matej Klotton0178d522016-11-04 11:11:44 +0100427 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100428 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700429 {
430 'is_add': is_add,
431 'neighbor': {
432 'sw_if_index': sw_if_index,
433 'flags': flags,
434 'mac_address': mac_address,
435 'ip_address': ip_address
436 }
437 }
Matej Klotton0178d522016-11-04 11:11:44 +0100438 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100439
Neale Rannsd0df49f2018-08-08 01:06:40 -0700440 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700441 src_ip,
442 dst_ip,
443 src_port,
444 dst_port,
445 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800446 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800447 :param src_ip:
448 :param dst_ip:
449 :param src_port:
450 :param dst_port:
451 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800452 """
453
454 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700455 self.papi.udp_encap_add,
456 {
457 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700458 'src_ip': src_ip,
459 'dst_ip': dst_ip,
460 'src_port': src_port,
461 'dst_port': dst_port,
462 'table_id': table_id
463 }
464 })
465
Neale Ranns097fa662018-05-01 05:17:55 -0700466 def udp_encap_del(self, id):
467 return self.api(self.papi.udp_encap_del, {'id': id})
468
469 def udp_encap_dump(self):
470 return self.api(self.papi.udp_encap_dump, {})
471
472 def want_udp_encap_stats(self, enable=1):
473 return self.api(self.papi.want_udp_encap_stats,
474 {'enable': enable,
475 'pid': os.getpid()})
476
477 def mpls_route_dump(self, table_id):
478 return self.api(self.papi.mpls_route_dump,
479 {'table': {
480 'mt_table_id': table_id
481 }})
482
483 def mpls_table_dump(self):
484 return self.api(self.papi.mpls_table_dump, {})
485
Neale Ranns15002542017-09-10 04:39:11 -0700486 def mpls_table_add_del(
487 self,
488 table_id,
489 is_add=1):
490 """
491
492 :param table_id
493 :param is_add: (Default value = 1)
494
495 """
496
497 return self.api(
498 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700499 {'mt_table':
500 {
501 'mt_table_id': table_id,
502 },
Neale Ranns15002542017-09-10 04:39:11 -0700503 'mt_is_add': is_add})
504
Neale Ranns097fa662018-05-01 05:17:55 -0700505 def mpls_route_add_del(self,
506 table_id,
507 label,
508 eos,
509 eos_proto,
510 is_multicast,
511 paths,
512 is_add,
513 is_multipath):
514 """ MPLS Route add/del """
515 return self.api(
516 self.papi.mpls_route_add_del,
517 {'mr_route':
518 {
519 'mr_table_id': table_id,
520 'mr_label': label,
521 'mr_eos': eos,
522 'mr_eos_proto': eos_proto,
523 'mr_is_multicast': is_multicast,
524 'mr_n_paths': len(paths),
525 'mr_paths': paths,
526 },
527 'mr_is_add': is_add,
528 'mr_is_multipath': is_multipath})
529
Neale Rannsad422ed2016-11-02 14:20:04 +0000530 def mpls_ip_bind_unbind(
531 self,
532 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700533 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000534 table_id=0,
535 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000536 is_bind=1):
537 """
538 """
539 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100540 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200541 {'mb_mpls_table_id': table_id,
542 'mb_label': label,
543 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200544 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700545 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000546
547 def mpls_tunnel_add_del(
548 self,
549 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700550 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000551 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800552 l2_only=0,
553 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000554 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000555 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000556 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100557 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700558 {'mt_is_add': is_add,
559 'mt_tunnel':
560 {
561 'mt_sw_if_index': tun_sw_if_index,
562 'mt_l2_only': l2_only,
563 'mt_is_multicast': is_multicast,
564 'mt_n_paths': len(paths),
565 'mt_paths': paths,
566 }})
Matus Fabiande886752016-12-07 03:38:19 -0800567
Steve Shin7957d6e2016-12-19 09:24:50 -0800568 def input_acl_set_interface(
569 self,
570 is_add,
571 sw_if_index,
572 ip4_table_index=0xFFFFFFFF,
573 ip6_table_index=0xFFFFFFFF,
574 l2_table_index=0xFFFFFFFF):
575 """
576 :param is_add:
577 :param sw_if_index:
578 :param ip4_table_index: (Default value = 0xFFFFFFFF)
579 :param ip6_table_index: (Default value = 0xFFFFFFFF)
580 :param l2_table_index: (Default value = 0xFFFFFFFF)
581 """
582
583 return self.api(
584 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100585 {'sw_if_index': sw_if_index,
586 'ip4_table_index': ip4_table_index,
587 'ip6_table_index': ip6_table_index,
588 'l2_table_index': l2_table_index,
589 'is_add': is_add})
590
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100591 def output_acl_set_interface(
592 self,
593 is_add,
594 sw_if_index,
595 ip4_table_index=0xFFFFFFFF,
596 ip6_table_index=0xFFFFFFFF,
597 l2_table_index=0xFFFFFFFF):
598 """
599 :param is_add:
600 :param sw_if_index:
601 :param ip4_table_index: (Default value = 0xFFFFFFFF)
602 :param ip6_table_index: (Default value = 0xFFFFFFFF)
603 :param l2_table_index: (Default value = 0xFFFFFFFF)
604 """
605
606 return self.api(
607 self.papi.output_acl_set_interface,
608 {'sw_if_index': sw_if_index,
609 'ip4_table_index': ip4_table_index,
610 'ip6_table_index': ip6_table_index,
611 'l2_table_index': l2_table_index,
612 'is_add': is_add})
613
Klement Sekera77fabdb2017-01-02 07:46:14 +0100614 def set_ipfix_exporter(
615 self,
616 collector_address,
617 src_address,
618 path_mtu,
619 template_interval,
620 vrf_id=0,
621 collector_port=4739,
622 udp_checksum=0):
623 return self.api(
624 self.papi.set_ipfix_exporter,
625 {
626 'collector_address': collector_address,
627 'collector_port': collector_port,
628 'src_address': src_address,
629 'vrf_id': vrf_id,
630 'path_mtu': path_mtu,
631 'template_interval': template_interval,
632 'udp_checksum': udp_checksum,
633 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800634
Neale Ranns097fa662018-05-01 05:17:55 -0700635 def mfib_signal_dump(self):
636 return self.api(self.papi.mfib_signal_dump, {})
637
638 def ip_mroute_dump(self, table_id, is_ip6=False):
639 return self.api(self.papi.ip_mroute_dump,
640 {'table': {
641 'table_id': table_id,
642 'is_ip6': is_ip6
643 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000644
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800645 def vxlan_gpe_add_del_tunnel(
646 self,
647 src_addr,
648 dst_addr,
649 mcast_sw_if_index=0xFFFFFFFF,
650 is_add=1,
651 is_ipv6=0,
652 encap_vrf_id=0,
653 decap_vrf_id=0,
654 protocol=3,
655 vni=0):
656 """
657
658 :param local:
659 :param remote:
660 :param is_add: (Default value = 1)
661 :param is_ipv6: (Default value = 0)
662 :param encap_vrf_id: (Default value = 0)
663 :param decap_vrf_id: (Default value = 0)
664 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
665 :param protocol: (Default value = 3)
666 :param vni: (Default value = 0)
667
668 """
669 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
670 {'is_add': is_add,
671 'is_ipv6': is_ipv6,
672 'local': src_addr,
673 'remote': dst_addr,
674 'mcast_sw_if_index': mcast_sw_if_index,
675 'encap_vrf_id': encap_vrf_id,
676 'decap_vrf_id': decap_vrf_id,
677 'protocol': protocol,
678 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800679
Neale Ranns79a05f52018-09-11 07:39:43 -0700680 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
681 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000682 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200683
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800684 def pppoe_add_del_session(
685 self,
686 client_ip,
687 client_mac,
688 session_id=0,
689 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800690 decap_vrf_id=0):
691 """
692
693 :param is_add: (Default value = 1)
694 :param is_ipv6: (Default value = 0)
695 :param client_ip:
696 :param session_id: (Default value = 0)
697 :param client_mac:
698 :param decap_vrf_id: (Default value = 0)
699
700 """
701 return self.api(self.papi.pppoe_add_del_session,
702 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800703 'session_id': session_id,
704 'client_ip': client_ip,
705 'decap_vrf_id': decap_vrf_id,
706 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200707
Neale Ranns7c922dc2018-08-30 06:12:27 -0700708 def sr_mpls_policy_add(self, bsid, weight, type, segments):
709 return self.api(self.papi.sr_mpls_policy_add,
710 {'bsid': bsid,
711 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100712 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700713 'n_segments': len(segments),
714 'segments': segments})
715
716 def sr_mpls_policy_del(self, bsid):
717 return self.api(self.papi.sr_mpls_policy_del,
718 {'bsid': bsid})
719
Neale Rannsd792d9c2017-10-21 10:53:20 -0700720 def bier_table_add_del(self,
721 bti,
722 mpls_label,
723 is_add=1):
724 """ BIER Table add/del """
725 return self.api(
726 self.papi.bier_table_add_del,
727 {'bt_tbl_id': {"bt_set": bti.set_id,
728 "bt_sub_domain": bti.sub_domain_id,
729 "bt_hdr_len_id": bti.hdr_len_id},
730 'bt_label': mpls_label,
731 'bt_is_add': is_add})
732
733 def bier_table_dump(self):
734 return self.api(self.papi.bier_table_dump, {})
735
736 def bier_route_add_del(self,
737 bti,
738 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800739 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700740 is_add=1,
741 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700742 """ BIER Route add/del """
743 return self.api(
744 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700745 {
746 'br_route': {
747 'br_tbl_id': {"bt_set": bti.set_id,
748 "bt_sub_domain": bti.sub_domain_id,
749 "bt_hdr_len_id": bti.hdr_len_id},
750 'br_bp': bp,
751 'br_n_paths': len(paths),
752 'br_paths': paths,
753 },
754 'br_is_add': is_add,
755 'br_is_replace': is_replace
756 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700757
758 def bier_route_dump(self, bti):
759 return self.api(
760 self.papi.bier_route_dump,
761 {'br_tbl_id': {"bt_set": bti.set_id,
762 "bt_sub_domain": bti.sub_domain_id,
763 "bt_hdr_len_id": bti.hdr_len_id}})
764
765 def bier_imp_add(self,
766 bti,
767 src,
768 ibytes,
769 is_add=1):
770 """ BIER Imposition Add """
771 return self.api(
772 self.papi.bier_imp_add,
773 {'bi_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 'bi_src': src,
777 'bi_n_bytes': len(ibytes),
778 'bi_bytes': ibytes})
779
780 def bier_imp_del(self, bi_index):
781 """ BIER Imposition del """
782 return self.api(
783 self.papi.bier_imp_del,
784 {'bi_index': bi_index})
785
786 def bier_imp_dump(self):
787 return self.api(self.papi.bier_imp_dump, {})
788
789 def bier_disp_table_add_del(self,
790 bdti,
791 is_add=1):
792 """ BIER Disposition Table add/del """
793 return self.api(
794 self.papi.bier_disp_table_add_del,
795 {'bdt_tbl_id': bdti,
796 'bdt_is_add': is_add})
797
798 def bier_disp_table_dump(self):
799 return self.api(self.papi.bier_disp_table_dump, {})
800
801 def bier_disp_entry_add_del(self,
802 bdti,
803 bp,
804 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800805 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700806 next_hop,
807 next_hop_tbl_id=0,
808 next_hop_rpf_id=~0,
809 next_hop_is_ip4=1,
810 is_add=1):
811 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800812 lstack = []
813 while (len(lstack) < 16):
814 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700815 return self.api(
816 self.papi.bier_disp_entry_add_del,
817 {'bde_tbl_id': bdti,
818 'bde_bp': bp,
819 'bde_payload_proto': payload_proto,
820 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400821 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700822 'rpf_id': next_hop_rpf_id,
823 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800824 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700825 'bde_is_add': is_add})
826
827 def bier_disp_entry_dump(self, bdti):
828 return self.api(
829 self.papi.bier_disp_entry_dump,
830 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200831
“mystarrocks”23f0c452017-12-11 07:11:51 -0800832 def ipsec_spd_add_del(self, spd_id, is_add=1):
833 """ SPD add/del - Wrapper to add or del ipsec SPD
834 Sample CLI : 'ipsec spd add 1'
835
836 :param spd_id - SPD ID to be created in the vpp . mandatory
837 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
838 optional
839 :returns: reply from the API
840 """
841 return self.api(
842 self.papi.ipsec_spd_add_del, {
843 'spd_id': spd_id, 'is_add': is_add})
844
Neale Ranns311124e2019-01-24 04:52:25 -0800845 def ipsec_spds_dump(self):
846 return self.api(self.papi.ipsec_spds_dump, {})
847
“mystarrocks”23f0c452017-12-11 07:11:51 -0800848 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
849 """ IPSEC interface SPD add/del - \
850 Wrapper to associate/disassociate SPD to interface in VPP
851 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
852
853 :param spd_id - SPD ID to associate with the interface . mandatory
854 :param sw_if_index - Interface Index which needs to ipsec \
855 association mandatory
856 :param is_add - add(1) or del(0) association with interface \
857 (Default 1 - add) . optional
858 :returns: reply from the API
859 """
860 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200861 self.papi.ipsec_interface_add_del_spd,
862 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800863
Neale Ranns311124e2019-01-24 04:52:25 -0800864 def ipsec_spd_interface_dump(self, spd_index=None):
865 return self.api(self.papi.ipsec_spd_interface_dump,
866 {'spd_index': spd_index if spd_index else 0,
867 'spd_index_valid': 1 if spd_index else 0})
868
Neale Ranns17dcec02019-01-09 21:22:20 -0800869 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800870 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200871 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800872 local_address_start,
873 local_address_stop,
874 remote_address_start,
875 remote_address_stop,
876 local_port_start=0,
877 local_port_stop=65535,
878 remote_port_start=0,
879 remote_port_stop=65535,
880 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800881 policy=0,
882 priority=100,
883 is_outbound=1,
884 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200885 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800886 is_ip_any=0):
887 """ IPSEC policy SPD add/del -
888 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +0200889 :param spd_id: SPD ID for the policy
890 :param local_address_start: local-ip-range start address
891 :param local_address_stop : local-ip-range stop address
892 :param remote_address_start: remote-ip-range start address
893 :param remote_address_stop : remote-ip-range stop address
894 :param local_port_start: (Default value = 0)
895 :param local_port_stop: (Default value = 65535)
896 :param remote_port_start: (Default value = 0)
897 :param remote_port_stop: (Default value = 65535)
898 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
899 :param sa_id: Security Association ID for mapping it to SPD
900 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
901 (Default value = 0)
902 :param priority: value for the spd action (Default value = 100)
903 :param is_outbound: flag for inbound(0) or outbound(1)
904 (Default value = 1)
905 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800906 """
907 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800908 self.papi.ipsec_spd_entry_add_del,
909 {
910 'is_add': is_add,
911 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100912 {
913 'spd_id': spd_id,
914 'sa_id': sa_id,
915 'local_address_start': local_address_start,
916 'local_address_stop': local_address_stop,
917 'remote_address_start': remote_address_start,
918 'remote_address_stop': remote_address_stop,
919 'local_port_start': local_port_start,
920 'local_port_stop': local_port_stop,
921 'remote_port_start': remote_port_start,
922 'remote_port_stop': remote_port_stop,
923 'protocol': protocol,
924 'policy': policy,
925 'priority': priority,
926 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100927 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800928 })
Florin Corasb795bd02017-12-14 11:30:48 -0800929
Neale Ranns311124e2019-01-24 04:52:25 -0800930 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
931 return self.api(self.papi.ipsec_spd_dump,
932 {'spd_id': spd_id,
933 'sa_id': sa_id})
934
Klement Sekera31da2e32018-06-24 22:49:55 +0200935 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
936 remote_spi, crypto_alg, local_crypto_key,
937 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000938 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700939 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000940 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200941 return self.api(
942 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400943 {
944 'local_ip': local_ip,
945 'remote_ip': remote_ip,
946 'local_spi': local_spi,
947 'remote_spi': remote_spi,
948 'crypto_alg': crypto_alg,
949 'local_crypto_key_len': len(local_crypto_key),
950 'local_crypto_key': local_crypto_key,
951 'remote_crypto_key_len': len(remote_crypto_key),
952 'remote_crypto_key': remote_crypto_key,
953 'integ_alg': integ_alg,
954 'local_integ_key_len': len(local_integ_key),
955 'local_integ_key': local_integ_key,
956 'remote_integ_key_len': len(remote_integ_key),
957 'remote_integ_key': remote_integ_key,
958 'is_add': is_add,
959 'esn': esn,
960 'anti_replay': anti_replay,
961 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000962 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700963 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000964 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400965 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200966
Klement Sekerab4d30532018-11-08 13:00:02 +0100967 def ipsec_select_backend(self, protocol, index):
968 return self.api(self.papi.ipsec_select_backend,
969 {'protocol': protocol, 'index': index})
970
971 def ipsec_backend_dump(self):
972 return self.api(self.papi.ipsec_backend_dump, {})
973
Neale Ranns50f0ac02019-05-15 02:13:37 -0700974 def punt_socket_register(self, reg, pathname,
975 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100976 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200977 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100978 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700979 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100980 'pathname': pathname})
981
Neale Ranns50f0ac02019-05-15 02:13:37 -0700982 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100983 """ Unregister punt socket """
984 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700985 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200986
Neale Ranns4ba67722019-02-28 11:11:39 +0000987 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700988 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -0700989 """ GBP endpoint Add """
990 return self.api(self.papi.gbp_endpoint_add,
991 {'endpoint': {
992 'sw_if_index': sw_if_index,
993 'ips': ips,
994 'n_ips': len(ips),
995 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +0000996 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700997 'flags': flags,
998 'tun': {
999 'src': tun_src,
1000 'dst': tun_dst,
1001 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001002
1003 def gbp_endpoint_del(self, handle):
1004 """ GBP endpoint Del """
1005 return self.api(self.papi.gbp_endpoint_del,
1006 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001007
1008 def gbp_endpoint_dump(self):
1009 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001010 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001011
Neale Ranns4ba67722019-02-28 11:11:39 +00001012 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001013 rd, uplink_sw_if_index,
1014 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001015 """ GBP endpoint group Add """
1016 return self.api(self.papi.gbp_endpoint_group_add,
1017 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001018 {
1019 'uplink_sw_if_index': uplink_sw_if_index,
1020 'bd_id': bd,
1021 'rd_id': rd,
1022 'vnid': vnid,
1023 'sclass': sclass,
1024 'retention': retention
1025 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001026
Neale Ranns4ba67722019-02-28 11:11:39 +00001027 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001028 """ GBP endpoint group Del """
1029 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001030 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001031
Neale Ranns160c9232019-06-19 06:25:56 -07001032 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001033 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001034 uu_fwd_sw_if_index,
1035 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001036 """ GBP bridge-domain Add """
1037 return self.api(self.papi.gbp_bridge_domain_add,
1038 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001039 {
1040 'flags': flags,
1041 'bvi_sw_if_index': bvi_sw_if_index,
1042 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1043 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001044 'bd_id': bd_id,
1045 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001046 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001047
1048 def gbp_bridge_domain_del(self, bd_id):
1049 """ GBP bridge-domain Del """
1050 return self.api(self.papi.gbp_bridge_domain_del,
1051 {'bd_id': bd_id})
1052
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001053 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001054 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001055 ip4_table_id,
1056 ip6_table_id,
1057 ip4_uu_sw_if_index,
1058 ip6_uu_sw_if_index):
1059 """ GBP route-domain Add """
1060 return self.api(self.papi.gbp_route_domain_add,
1061 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001062 {
Neale Ranns160c9232019-06-19 06:25:56 -07001063 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001064 'ip4_table_id': ip4_table_id,
1065 'ip6_table_id': ip6_table_id,
1066 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1067 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1068 'rd_id': rd_id
1069 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001070
1071 def gbp_route_domain_del(self, rd_id):
1072 """ GBP route-domain Del """
1073 return self.api(self.papi.gbp_route_domain_del,
1074 {'rd_id': rd_id})
1075
Neale Ranns4ba67722019-02-28 11:11:39 +00001076 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001077 """ GBP recirc Add/Del """
1078 return self.api(self.papi.gbp_recirc_add_del,
1079 {'is_add': is_add,
1080 'recirc': {
1081 'is_ext': is_ext,
1082 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001083 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001084
1085 def gbp_recirc_dump(self):
1086 """ GBP recirc Dump """
1087 return self.api(self.papi.gbp_recirc_dump, {})
1088
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001089 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001090 """ GBP recirc Add/Del """
1091 return self.api(self.papi.gbp_ext_itf_add_del,
1092 {'is_add': is_add,
1093 'ext_itf': {
1094 'sw_if_index': sw_if_index,
1095 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001096 'rd_id': rd_id,
1097 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001098
1099 def gbp_ext_itf_dump(self):
1100 """ GBP recirc Dump """
1101 return self.api(self.papi.gbp_ext_itf_dump, {})
1102
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001103 def gbp_subnet_add_del(self, is_add, rd_id,
1104 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001105 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001106 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001107 """ GBP Subnet Add/Del """
1108 return self.api(self.papi.gbp_subnet_add_del,
1109 {'is_add': is_add,
1110 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001111 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001112 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001113 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001114 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001115 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001116
1117 def gbp_subnet_dump(self):
1118 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001119 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001120
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001121 def gbp_contract_dump(self):
1122 """ GBP contract Dump """
1123 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001124
Neale Ranns8da9fc62019-03-04 14:08:11 -08001125 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001126 """ GBP VXLAN tunnel add """
1127 return self.api(self.papi.gbp_vxlan_tunnel_add,
1128 {
1129 'tunnel': {
1130 'vni': vni,
1131 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001132 'bd_rd_id': bd_rd_id,
1133 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001134 }
1135 })
1136
1137 def gbp_vxlan_tunnel_del(self, vni):
1138 """ GBP VXLAN tunnel del """
1139 return self.api(self.papi.gbp_vxlan_tunnel_del,
1140 {
1141 'vni': vni,
1142 })
1143
1144 def gbp_vxlan_tunnel_dump(self):
1145 """ GBP VXLAN tunnel add/del """
1146 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1147
Neale Ranns947ea622018-06-07 23:48:20 -07001148 def igmp_enable_disable(self, sw_if_index, enable, host):
1149 """ Enable/disable IGMP on a given interface """
1150 return self.api(self.papi.igmp_enable_disable,
1151 {'enable': enable,
1152 'mode': host,
1153 'sw_if_index': sw_if_index})
1154
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001155 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1156 """ Add/del IGMP proxy device """
1157 return self.api(self.papi.igmp_proxy_device_add_del,
1158 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1159 'add': add})
1160
1161 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1162 """ Add/del interface to/from IGMP proxy device """
1163 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1164 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1165 'add': add})
1166
Neale Ranns947ea622018-06-07 23:48:20 -07001167 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001168 """ Listen for new (S,G) on specified interface
1169
1170 :param enable: add/del
1171 :param sw_if_index: interface sw index
1172 :param saddr: source ip4 addr
1173 :param gaddr: group ip4 addr
1174 """
1175 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001176 {
1177 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001178 {
1179 'filter': filter,
1180 'sw_if_index': sw_if_index,
1181 'n_srcs': len(saddrs),
1182 'saddrs': saddrs,
1183 'gaddr': gaddr
1184 }
Neale Ranns947ea622018-06-07 23:48:20 -07001185 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001186
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001187 def igmp_clear_interface(self, sw_if_index):
1188 """ Remove all (S,G)s from specified interface
1189 doesn't send IGMP report!
1190 """
1191 return self.api(
1192 self.papi.igmp_clear_interface, {
1193 'sw_if_index': sw_if_index})
1194
1195 def want_igmp_events(self, enable=1):
1196 return self.api(self.papi.want_igmp_events, {'enable': enable,
1197 'pid': os.getpid()})