blob: 81e25ecc621ba3534229ac1280e446663ee13516 [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
Klement Sekeraf62ae122016-10-11 11:47:09 +020011
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
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017
Ole Troanf159f582019-02-28 20:20:47 +010018#
19# Dictionary keyed on message name to override default values for
20# named parameters
21#
Ole Troan9a475372019-03-05 16:58:24 +010022defaultmapping = {
Paul Vinciguerrac0e94412020-04-28 01:12:04 -040023
Ole Troan9a475372019-03-05 16:58:24 +010024 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
Ole Troan9a475372019-03-05 16:58:24 +010025 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020026 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
27 'conf_key_id': None},
28 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
29 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010030 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
31 'is_add': 1, },
32 'bier_disp_table_add_del': {'is_add': 1, },
33 'bier_imp_add': {'is_add': 1, },
34 'bier_route_add_del': {'is_add': 1, },
35 'bier_table_add_del': {'is_add': 1, },
36 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
37 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070038 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010039 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
40 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
41 'decap_next_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010042 'input_acl_set_interface': {'ip4_table_index': 4294967295,
43 'ip6_table_index': 4294967295,
44 'l2_table_index': 4294967295, },
45 'ip6_add_del_address_using_prefix': {'is_add': 1, },
46 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
47 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
48 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010049 'classify_table_index': 4294967295, 'is_add': 1, },
50 'ip_mroute_add_del': {'is_add': 1, },
51 'ip_neighbor_add_del': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070052 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010053 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010054 'ipsec_spd_add_del': {'is_add': 1, },
55 'ipsec_spd_dump': {'sa_id': 4294967295, },
56 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
57 'remote_port_stop': 65535, 'priority': 100,
58 'is_outbound': 1,
59 'is_add': 1, },
60 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
61 'l2_emulation': {'enable': 1, },
62 'l2fib_add_del': {'is_add': 1, },
63 'lisp_add_del_adjacency': {'is_add': 1, },
64 'lisp_add_del_local_eid': {'is_add': 1, },
65 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
66 'lisp_add_del_locator_set': {'is_add': 1, },
67 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010068 'macip_acl_interface_add_del': {'is_add': 1, },
69 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010070 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
71 'mr_next_hop_weight': 1,
72 'mr_next_hop_via_label': 1048576,
73 'mr_is_add': 1,
74 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010075 'mpls_table_add_del': {'is_add': 1, },
76 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
77 'next_hop_weight': 1,
78 'next_hop_via_label': 1048576,
79 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010080 'output_acl_set_interface': {'ip4_table_index': 4294967295,
81 'ip6_table_index': 4294967295,
82 'l2_table_index': 4294967295, },
83 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010084 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010085 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010086 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010087 'sw_interface_add_del_address': {'is_add': 1, },
88 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
89 'pref_lifetime': 4294967295, },
90 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
91 'sw_interface_set_l2_bridge': {'enable': 1, },
92 'sw_interface_set_mpls_enable': {'enable': 1, },
93 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
94 'sw_interface_set_unnumbered': {'is_add': 1, },
95 'sw_interface_span_enable_disable': {'state': 1, },
96 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
97 'decap_next_index': 4294967295,
98 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010099 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
100 'protocol': 3, },
101 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100102 'want_igmp_events': {'enable': 1, },
103 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200104 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100105 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100106}
Ole Troanf159f582019-02-28 20:20:47 +0100107
Matus Fabianb4515b42018-11-19 04:25:32 -0800108
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400109def as_fn_signature(d):
110 return ", ".join(f"{k}={v}" for k, v in d.items())
111
112
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400113class CliFailedCommandError(Exception):
114 """ cli command failed."""
115
116
117class CliSyntaxError(Exception):
118 """ cli command had a syntax error."""
119
120
Klement Sekera73884482017-02-23 09:26:30 +0100121class UnexpectedApiReturnValueError(Exception):
122 """ exception raised when the API return value is unexpected """
123 pass
124
125
Klement Sekeraf62ae122016-10-11 11:47:09 +0200126class VppPapiProvider(object):
127 """VPP-api provider using vpp-papi
128
129 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200130 """
131
Klement Sekerae0545ef2017-01-25 08:00:40 +0100132 _zero, _negative = range(2)
133
Klement Sekera611864f2018-09-26 11:19:00 +0200134 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800135 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200136 self.name = name
137 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100138 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100139 self._expect_api_retval = self._zero
140 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100141
Paul Vinciguerra19542292019-03-17 17:34:46 -0700142 # install_dir is a class attribute. We need to set it before
143 # calling the constructor.
144 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800145
Ole Troan4ff09ae2019-04-15 11:27:22 +0200146 use_socket = False
147 try:
148 if os.environ['SOCKET'] == '1':
149 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400150 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200151 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700152
153 self.vpp = VPPApiClient(logger=test_class.logger,
154 read_timeout=read_timeout,
155 use_socket=use_socket,
156 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100157 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200158
Klement Sekerae0545ef2017-01-25 08:00:40 +0100159 def __enter__(self):
160 return self
161
Klement Sekera7d6afb32018-11-08 11:52:04 +0100162 def assert_negative_api_retval(self):
163 """ Expect API failure - used with with, e.g.:
164 with self.vapi.assert_negative_api_retval():
165 self.vapi.<api call expected to fail>
166 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100167 self._expect_stack.append(self._expect_api_retval)
168 self._expect_api_retval = self._negative
169 return self
170
Klement Sekera7d6afb32018-11-08 11:52:04 +0100171 def assert_zero_api_retval(self):
172 """ Expect API success - used with with, e.g.:
173 with self.vapi.assert_negative_api_retval():
174 self.vapi.<api call expected to succeed>
175
176 note: this is useful only inside another with block
177 as success is the default expected value
178 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100179 self._expect_stack.append(self._expect_api_retval)
180 self._expect_api_retval = self._zero
181 return self
182
183 def __exit__(self, exc_type, exc_value, traceback):
184 self._expect_api_retval = self._expect_stack.pop()
185
Klement Sekeraf62ae122016-10-11 11:47:09 +0200186 def register_hook(self, hook):
187 """Replace hook registration with new hook
188
189 :param hook:
190
191 """
192 self.hook = hook
193
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200194 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100195 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200196 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100197 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200198 return e
199
200 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100201 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100202 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100203 self.test_class.logger.debug("Expecting event '%s' within %ss",
204 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300205 else:
206 self.test_class.logger.debug("Expecting event within %ss",
207 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100208 if self._events:
209 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200210 limit = time.time() + timeout
211 while time.time() < limit:
212 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100213 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200214 if name and type(e).__name__ != name:
215 raise Exception(
216 "Unexpected event received: %s, expected: %s" %
217 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100218 self.test_class.logger.debug("Returning event %s:%s" %
219 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700221 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200222 raise Exception("Event did not occur within timeout")
223
224 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100225 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200226 # FIXME use the name instead of relying on type(e).__name__ ?
227 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100228 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200229 self._events.append(event)
230
Ole Troanf159f582019-02-28 20:20:47 +0100231 def factory(self, name, apifn):
232 def f(*a, **ka):
233 fields = apifn._func.msg.fields
234
235 # add positional and kw arguments
236 d = ka
237 for i, o in enumerate(fields[3:]):
238 try:
239 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200240 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100241 break
242
243 # Default override
244 if name in defaultmapping:
245 for k, v in iteritems(defaultmapping[name]):
246 if k in d:
247 continue
248 d[k] = v
249 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100250
Ole Troanf159f582019-02-28 20:20:47 +0100251 return f
252
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800253 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100254 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800255 method = super(VppPapiProvider, self).__getattribute__(name)
256 except AttributeError:
257 method = self.factory(name, getattr(self.papi, name))
258 # lazily load the method so we don't need to call factory
259 # again for this name.
260 setattr(self, name, method)
261 return method
Ole Troanf159f582019-02-28 20:20:47 +0100262
Klement Sekeraf62ae122016-10-11 11:47:09 +0200263 def connect(self):
264 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100265 self.vpp.connect(self.name, self.shm_prefix)
266 self.papi = self.vpp.api
267 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200268
269 def disconnect(self):
270 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100271 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200272
273 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100274 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200275 Call the appropriate hooks before and after the API call
276
277 :param api_fn: API function to call
278 :param api_args: tuple of API function arguments
279 :param expected_retval: Expected return value (Default value = 0)
280 :returns: reply from the API
281
282 """
283 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100284 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100285 if self._expect_api_retval == self._negative:
286 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400287 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100288 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400289 (api_fn.__name__, as_fn_signature(api_args),
290 reply.retval,
291 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100292 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100293 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100294 elif self._expect_api_retval == self._zero:
295 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400296 msg = "%s(%s) failed, expected %d return value instead " \
297 "of %d in %s" % (api_fn.__name__,
298 as_fn_signature(api_args),
299 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400300 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100301 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100302 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100303 else:
304 raise Exception("Internal error, unexpected value for "
305 "self._expect_api_retval %s" %
306 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200307 self.hook.after_api(api_fn.__name__, api_args)
308 return reply
309
Dave Barach5932ce12019-10-09 17:28:04 -0400310 def cli_return_response(self, cli):
311 """ Execute a CLI, calling the before/after hooks appropriately.
312 Return the reply without examining it
313
314 :param cli: CLI to execute
315 :returns: response object
316
317 """
318 self.hook.before_cli(cli)
319 cli += '\n'
320 r = self.papi.cli_inband(cmd=cli)
321 self.hook.after_cli(cli)
322 return r
323
Klement Sekeraf62ae122016-10-11 11:47:09 +0200324 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100325 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200326
327 :param cli: CLI to execute
328 :returns: CLI output
329
330 """
Dave Barach5932ce12019-10-09 17:28:04 -0400331 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400332 if r.retval == -156:
333 raise CliSyntaxError(r.reply)
334 if r.retval != 0:
335 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200336 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100337 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200338
Jan49c0fca2016-10-26 15:44:27 +0200339 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100340 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200341
342 :param cli: CLI to execute
343 :returns: CLI output
344 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200345 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200346
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100347 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
348 mrc=0, mrd=0):
349 return self.api(self.papi.ip6nd_send_router_solicitation,
350 {'irt': irt,
351 'mrt': mrt,
352 'mrc': mrc,
353 'mrd': mrd,
354 'sw_if_index': sw_if_index})
355
Juraj Slobodab3f90502018-10-04 15:15:16 +0200356 def want_interface_events(self, enable_disable=1):
357 return self.api(self.papi.want_interface_events,
358 {'enable_disable': enable_disable,
359 'pid': os.getpid(), })
360
Neale Rannsc819fc62018-02-16 02:44:05 -0800361 def sw_interface_set_mac_address(self, sw_if_index, mac):
362 return self.api(self.papi.sw_interface_set_mac_address,
363 {'sw_if_index': sw_if_index,
364 'mac_address': mac})
365
Ole Troane1ade682019-03-04 23:55:43 +0100366 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200367 """Create p2p ethernet subinterface
368
369 :param sw_if_index: main (parent) interface
370 :param remote_mac: client (remote) mac address
371
372 """
373 return self.api(
374 self.papi.p2p_ethernet_add,
375 {'parent_if_index': sw_if_index,
376 'remote_mac': remote_mac,
377 'subif_id': subif_id})
378
Ole Troane1ade682019-03-04 23:55:43 +0100379 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200380 """Delete p2p ethernet subinterface
381
382 :param sw_if_index: main (parent) interface
383 :param remote_mac: client (remote) mac address
384
385 """
386 return self.api(
387 self.papi.p2p_ethernet_del,
388 {'parent_if_index': sw_if_index,
389 'remote_mac': remote_mac})
390
Klement Sekeraf62ae122016-10-11 11:47:09 +0200391 def create_vlan_subif(self, sw_if_index, vlan):
392 """
393
394 :param vlan:
395 :param sw_if_index:
396
397 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100398 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200399 {'sw_if_index': sw_if_index,
400 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200401
Matej Klotton0178d522016-11-04 11:11:44 +0100402 def create_loopback(self, mac=''):
403 """
404
405 :param mac: (Optional)
406 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100407 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200408 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100409
Neale Ranns097fa662018-05-01 05:17:55 -0700410 def ip_route_dump(self, table_id, is_ip6=False):
411 return self.api(self.papi.ip_route_dump,
412 {'table': {
413 'table_id': table_id,
414 'is_ip6': is_ip6
415 }})
416
Matej Klotton0178d522016-11-04 11:11:44 +0100417 def ip_neighbor_add_del(self,
418 sw_if_index,
419 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700420 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100421 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700422 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100423 """ Add neighbor MAC to IPv4 or IPv6 address.
424
425 :param sw_if_index:
426 :param mac_address:
427 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100428 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700429 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100430 """
Matej Klotton0178d522016-11-04 11:11:44 +0100431 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100432 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700433 {
434 'is_add': is_add,
435 'neighbor': {
436 'sw_if_index': sw_if_index,
437 'flags': flags,
438 'mac_address': mac_address,
439 'ip_address': ip_address
440 }
441 }
Matej Klotton0178d522016-11-04 11:11:44 +0100442 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100443
Neale Rannsd0df49f2018-08-08 01:06:40 -0700444 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700445 src_ip,
446 dst_ip,
447 src_port,
448 dst_port,
449 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800450 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800451 :param src_ip:
452 :param dst_ip:
453 :param src_port:
454 :param dst_port:
455 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800456 """
457
458 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700459 self.papi.udp_encap_add,
460 {
461 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700462 'src_ip': src_ip,
463 'dst_ip': dst_ip,
464 'src_port': src_port,
465 'dst_port': dst_port,
466 'table_id': table_id
467 }
468 })
469
Neale Ranns097fa662018-05-01 05:17:55 -0700470 def udp_encap_del(self, id):
471 return self.api(self.papi.udp_encap_del, {'id': id})
472
473 def udp_encap_dump(self):
474 return self.api(self.papi.udp_encap_dump, {})
475
476 def want_udp_encap_stats(self, enable=1):
477 return self.api(self.papi.want_udp_encap_stats,
478 {'enable': enable,
479 'pid': os.getpid()})
480
481 def mpls_route_dump(self, table_id):
482 return self.api(self.papi.mpls_route_dump,
483 {'table': {
484 'mt_table_id': table_id
485 }})
486
487 def mpls_table_dump(self):
488 return self.api(self.papi.mpls_table_dump, {})
489
Neale Ranns15002542017-09-10 04:39:11 -0700490 def mpls_table_add_del(
491 self,
492 table_id,
493 is_add=1):
494 """
495
496 :param table_id
497 :param is_add: (Default value = 1)
498
499 """
500
501 return self.api(
502 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700503 {'mt_table':
504 {
505 'mt_table_id': table_id,
506 },
Neale Ranns15002542017-09-10 04:39:11 -0700507 'mt_is_add': is_add})
508
Neale Ranns097fa662018-05-01 05:17:55 -0700509 def mpls_route_add_del(self,
510 table_id,
511 label,
512 eos,
513 eos_proto,
514 is_multicast,
515 paths,
516 is_add,
517 is_multipath):
518 """ MPLS Route add/del """
519 return self.api(
520 self.papi.mpls_route_add_del,
521 {'mr_route':
522 {
523 'mr_table_id': table_id,
524 'mr_label': label,
525 'mr_eos': eos,
526 'mr_eos_proto': eos_proto,
527 'mr_is_multicast': is_multicast,
528 'mr_n_paths': len(paths),
529 'mr_paths': paths,
530 },
531 'mr_is_add': is_add,
532 'mr_is_multipath': is_multipath})
533
Neale Rannsad422ed2016-11-02 14:20:04 +0000534 def mpls_ip_bind_unbind(
535 self,
536 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700537 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000538 table_id=0,
539 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000540 is_bind=1):
541 """
542 """
543 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100544 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200545 {'mb_mpls_table_id': table_id,
546 'mb_label': label,
547 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200548 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700549 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000550
551 def mpls_tunnel_add_del(
552 self,
553 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700554 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000555 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800556 l2_only=0,
557 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000558 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000559 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000560 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100561 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700562 {'mt_is_add': is_add,
563 'mt_tunnel':
564 {
565 'mt_sw_if_index': tun_sw_if_index,
566 'mt_l2_only': l2_only,
567 'mt_is_multicast': is_multicast,
568 'mt_n_paths': len(paths),
569 'mt_paths': paths,
570 }})
Matus Fabiande886752016-12-07 03:38:19 -0800571
Steve Shin7957d6e2016-12-19 09:24:50 -0800572 def input_acl_set_interface(
573 self,
574 is_add,
575 sw_if_index,
576 ip4_table_index=0xFFFFFFFF,
577 ip6_table_index=0xFFFFFFFF,
578 l2_table_index=0xFFFFFFFF):
579 """
580 :param is_add:
581 :param sw_if_index:
582 :param ip4_table_index: (Default value = 0xFFFFFFFF)
583 :param ip6_table_index: (Default value = 0xFFFFFFFF)
584 :param l2_table_index: (Default value = 0xFFFFFFFF)
585 """
586
587 return self.api(
588 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100589 {'sw_if_index': sw_if_index,
590 'ip4_table_index': ip4_table_index,
591 'ip6_table_index': ip6_table_index,
592 'l2_table_index': l2_table_index,
593 'is_add': is_add})
594
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100595 def output_acl_set_interface(
596 self,
597 is_add,
598 sw_if_index,
599 ip4_table_index=0xFFFFFFFF,
600 ip6_table_index=0xFFFFFFFF,
601 l2_table_index=0xFFFFFFFF):
602 """
603 :param is_add:
604 :param sw_if_index:
605 :param ip4_table_index: (Default value = 0xFFFFFFFF)
606 :param ip6_table_index: (Default value = 0xFFFFFFFF)
607 :param l2_table_index: (Default value = 0xFFFFFFFF)
608 """
609
610 return self.api(
611 self.papi.output_acl_set_interface,
612 {'sw_if_index': sw_if_index,
613 'ip4_table_index': ip4_table_index,
614 'ip6_table_index': ip6_table_index,
615 'l2_table_index': l2_table_index,
616 'is_add': is_add})
617
Klement Sekera77fabdb2017-01-02 07:46:14 +0100618 def set_ipfix_exporter(
619 self,
620 collector_address,
621 src_address,
622 path_mtu,
623 template_interval,
624 vrf_id=0,
625 collector_port=4739,
626 udp_checksum=0):
627 return self.api(
628 self.papi.set_ipfix_exporter,
629 {
630 'collector_address': collector_address,
631 'collector_port': collector_port,
632 'src_address': src_address,
633 'vrf_id': vrf_id,
634 'path_mtu': path_mtu,
635 'template_interval': template_interval,
636 'udp_checksum': udp_checksum,
637 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800638
Neale Ranns097fa662018-05-01 05:17:55 -0700639 def mfib_signal_dump(self):
640 return self.api(self.papi.mfib_signal_dump, {})
641
642 def ip_mroute_dump(self, table_id, is_ip6=False):
643 return self.api(self.papi.ip_mroute_dump,
644 {'table': {
645 'table_id': table_id,
646 'is_ip6': is_ip6
647 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000648
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800649 def vxlan_gpe_add_del_tunnel(
650 self,
651 src_addr,
652 dst_addr,
653 mcast_sw_if_index=0xFFFFFFFF,
654 is_add=1,
655 is_ipv6=0,
656 encap_vrf_id=0,
657 decap_vrf_id=0,
658 protocol=3,
659 vni=0):
660 """
661
662 :param local:
663 :param remote:
664 :param is_add: (Default value = 1)
665 :param is_ipv6: (Default value = 0)
666 :param encap_vrf_id: (Default value = 0)
667 :param decap_vrf_id: (Default value = 0)
668 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
669 :param protocol: (Default value = 3)
670 :param vni: (Default value = 0)
671
672 """
673 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
674 {'is_add': is_add,
675 'is_ipv6': is_ipv6,
676 'local': src_addr,
677 'remote': dst_addr,
678 'mcast_sw_if_index': mcast_sw_if_index,
679 'encap_vrf_id': encap_vrf_id,
680 'decap_vrf_id': decap_vrf_id,
681 'protocol': protocol,
682 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800683
Neale Ranns79a05f52018-09-11 07:39:43 -0700684 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
685 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000686 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200687
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800688 def pppoe_add_del_session(
689 self,
690 client_ip,
691 client_mac,
692 session_id=0,
693 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800694 decap_vrf_id=0):
695 """
696
697 :param is_add: (Default value = 1)
698 :param is_ipv6: (Default value = 0)
699 :param client_ip:
700 :param session_id: (Default value = 0)
701 :param client_mac:
702 :param decap_vrf_id: (Default value = 0)
703
704 """
705 return self.api(self.papi.pppoe_add_del_session,
706 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800707 'session_id': session_id,
708 'client_ip': client_ip,
709 'decap_vrf_id': decap_vrf_id,
710 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200711
Neale Ranns7c922dc2018-08-30 06:12:27 -0700712 def sr_mpls_policy_add(self, bsid, weight, type, segments):
713 return self.api(self.papi.sr_mpls_policy_add,
714 {'bsid': bsid,
715 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100716 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700717 'n_segments': len(segments),
718 'segments': segments})
719
720 def sr_mpls_policy_del(self, bsid):
721 return self.api(self.papi.sr_mpls_policy_del,
722 {'bsid': bsid})
723
Neale Rannsd792d9c2017-10-21 10:53:20 -0700724 def bier_table_add_del(self,
725 bti,
726 mpls_label,
727 is_add=1):
728 """ BIER Table add/del """
729 return self.api(
730 self.papi.bier_table_add_del,
731 {'bt_tbl_id': {"bt_set": bti.set_id,
732 "bt_sub_domain": bti.sub_domain_id,
733 "bt_hdr_len_id": bti.hdr_len_id},
734 'bt_label': mpls_label,
735 'bt_is_add': is_add})
736
737 def bier_table_dump(self):
738 return self.api(self.papi.bier_table_dump, {})
739
740 def bier_route_add_del(self,
741 bti,
742 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800743 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700744 is_add=1,
745 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700746 """ BIER Route add/del """
747 return self.api(
748 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700749 {
750 'br_route': {
751 'br_tbl_id': {"bt_set": bti.set_id,
752 "bt_sub_domain": bti.sub_domain_id,
753 "bt_hdr_len_id": bti.hdr_len_id},
754 'br_bp': bp,
755 'br_n_paths': len(paths),
756 'br_paths': paths,
757 },
758 'br_is_add': is_add,
759 'br_is_replace': is_replace
760 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700761
762 def bier_route_dump(self, bti):
763 return self.api(
764 self.papi.bier_route_dump,
765 {'br_tbl_id': {"bt_set": bti.set_id,
766 "bt_sub_domain": bti.sub_domain_id,
767 "bt_hdr_len_id": bti.hdr_len_id}})
768
769 def bier_imp_add(self,
770 bti,
771 src,
772 ibytes,
773 is_add=1):
774 """ BIER Imposition Add """
775 return self.api(
776 self.papi.bier_imp_add,
777 {'bi_tbl_id': {"bt_set": bti.set_id,
778 "bt_sub_domain": bti.sub_domain_id,
779 "bt_hdr_len_id": bti.hdr_len_id},
780 'bi_src': src,
781 'bi_n_bytes': len(ibytes),
782 'bi_bytes': ibytes})
783
784 def bier_imp_del(self, bi_index):
785 """ BIER Imposition del """
786 return self.api(
787 self.papi.bier_imp_del,
788 {'bi_index': bi_index})
789
790 def bier_imp_dump(self):
791 return self.api(self.papi.bier_imp_dump, {})
792
793 def bier_disp_table_add_del(self,
794 bdti,
795 is_add=1):
796 """ BIER Disposition Table add/del """
797 return self.api(
798 self.papi.bier_disp_table_add_del,
799 {'bdt_tbl_id': bdti,
800 'bdt_is_add': is_add})
801
802 def bier_disp_table_dump(self):
803 return self.api(self.papi.bier_disp_table_dump, {})
804
805 def bier_disp_entry_add_del(self,
806 bdti,
807 bp,
808 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800809 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700810 next_hop,
811 next_hop_tbl_id=0,
812 next_hop_rpf_id=~0,
813 next_hop_is_ip4=1,
814 is_add=1):
815 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800816 lstack = []
817 while (len(lstack) < 16):
818 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700819 return self.api(
820 self.papi.bier_disp_entry_add_del,
821 {'bde_tbl_id': bdti,
822 'bde_bp': bp,
823 'bde_payload_proto': payload_proto,
824 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400825 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700826 'rpf_id': next_hop_rpf_id,
827 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800828 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700829 'bde_is_add': is_add})
830
831 def bier_disp_entry_dump(self, bdti):
832 return self.api(
833 self.papi.bier_disp_entry_dump,
834 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200835
“mystarrocks”23f0c452017-12-11 07:11:51 -0800836 def ipsec_spd_add_del(self, spd_id, is_add=1):
837 """ SPD add/del - Wrapper to add or del ipsec SPD
838 Sample CLI : 'ipsec spd add 1'
839
840 :param spd_id - SPD ID to be created in the vpp . mandatory
841 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
842 optional
843 :returns: reply from the API
844 """
845 return self.api(
846 self.papi.ipsec_spd_add_del, {
847 'spd_id': spd_id, 'is_add': is_add})
848
Neale Ranns311124e2019-01-24 04:52:25 -0800849 def ipsec_spds_dump(self):
850 return self.api(self.papi.ipsec_spds_dump, {})
851
“mystarrocks”23f0c452017-12-11 07:11:51 -0800852 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
853 """ IPSEC interface SPD add/del - \
854 Wrapper to associate/disassociate SPD to interface in VPP
855 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
856
857 :param spd_id - SPD ID to associate with the interface . mandatory
858 :param sw_if_index - Interface Index which needs to ipsec \
859 association mandatory
860 :param is_add - add(1) or del(0) association with interface \
861 (Default 1 - add) . optional
862 :returns: reply from the API
863 """
864 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200865 self.papi.ipsec_interface_add_del_spd,
866 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800867
Neale Ranns311124e2019-01-24 04:52:25 -0800868 def ipsec_spd_interface_dump(self, spd_index=None):
869 return self.api(self.papi.ipsec_spd_interface_dump,
870 {'spd_index': spd_index if spd_index else 0,
871 'spd_index_valid': 1 if spd_index else 0})
872
Neale Ranns17dcec02019-01-09 21:22:20 -0800873 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800874 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200875 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800876 local_address_start,
877 local_address_stop,
878 remote_address_start,
879 remote_address_stop,
880 local_port_start=0,
881 local_port_stop=65535,
882 remote_port_start=0,
883 remote_port_stop=65535,
884 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800885 policy=0,
886 priority=100,
887 is_outbound=1,
888 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200889 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800890 is_ip_any=0):
891 """ IPSEC policy SPD add/del -
892 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +0200893 :param spd_id: SPD ID for the policy
894 :param local_address_start: local-ip-range start address
895 :param local_address_stop : local-ip-range stop address
896 :param remote_address_start: remote-ip-range start address
897 :param remote_address_stop : remote-ip-range stop address
898 :param local_port_start: (Default value = 0)
899 :param local_port_stop: (Default value = 65535)
900 :param remote_port_start: (Default value = 0)
901 :param remote_port_stop: (Default value = 65535)
902 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
903 :param sa_id: Security Association ID for mapping it to SPD
904 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
905 (Default value = 0)
906 :param priority: value for the spd action (Default value = 100)
907 :param is_outbound: flag for inbound(0) or outbound(1)
908 (Default value = 1)
909 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800910 """
911 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800912 self.papi.ipsec_spd_entry_add_del,
913 {
914 'is_add': is_add,
915 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100916 {
917 'spd_id': spd_id,
918 'sa_id': sa_id,
919 'local_address_start': local_address_start,
920 'local_address_stop': local_address_stop,
921 'remote_address_start': remote_address_start,
922 'remote_address_stop': remote_address_stop,
923 'local_port_start': local_port_start,
924 'local_port_stop': local_port_stop,
925 'remote_port_start': remote_port_start,
926 'remote_port_stop': remote_port_stop,
927 'protocol': protocol,
928 'policy': policy,
929 'priority': priority,
930 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100931 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800932 })
Florin Corasb795bd02017-12-14 11:30:48 -0800933
Neale Ranns311124e2019-01-24 04:52:25 -0800934 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
935 return self.api(self.papi.ipsec_spd_dump,
936 {'spd_id': spd_id,
937 'sa_id': sa_id})
938
Klement Sekera31da2e32018-06-24 22:49:55 +0200939 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
940 remote_spi, crypto_alg, local_crypto_key,
941 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000942 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700943 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000944 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200945 return self.api(
946 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400947 {
948 'local_ip': local_ip,
949 'remote_ip': remote_ip,
950 'local_spi': local_spi,
951 'remote_spi': remote_spi,
952 'crypto_alg': crypto_alg,
953 'local_crypto_key_len': len(local_crypto_key),
954 'local_crypto_key': local_crypto_key,
955 'remote_crypto_key_len': len(remote_crypto_key),
956 'remote_crypto_key': remote_crypto_key,
957 'integ_alg': integ_alg,
958 'local_integ_key_len': len(local_integ_key),
959 'local_integ_key': local_integ_key,
960 'remote_integ_key_len': len(remote_integ_key),
961 'remote_integ_key': remote_integ_key,
962 'is_add': is_add,
963 'esn': esn,
964 'anti_replay': anti_replay,
965 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000966 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700967 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000968 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400969 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200970
Klement Sekerab4d30532018-11-08 13:00:02 +0100971 def ipsec_select_backend(self, protocol, index):
972 return self.api(self.papi.ipsec_select_backend,
973 {'protocol': protocol, 'index': index})
974
975 def ipsec_backend_dump(self):
976 return self.api(self.papi.ipsec_backend_dump, {})
977
Neale Ranns50f0ac02019-05-15 02:13:37 -0700978 def punt_socket_register(self, reg, pathname,
979 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100980 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200981 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100982 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700983 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100984 'pathname': pathname})
985
Neale Ranns50f0ac02019-05-15 02:13:37 -0700986 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100987 """ Unregister punt socket """
988 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700989 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200990
Neale Ranns4ba67722019-02-28 11:11:39 +0000991 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700992 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -0700993 """ GBP endpoint Add """
994 return self.api(self.papi.gbp_endpoint_add,
995 {'endpoint': {
996 'sw_if_index': sw_if_index,
997 'ips': ips,
998 'n_ips': len(ips),
999 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001000 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001001 'flags': flags,
1002 'tun': {
1003 'src': tun_src,
1004 'dst': tun_dst,
1005 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001006
1007 def gbp_endpoint_del(self, handle):
1008 """ GBP endpoint Del """
1009 return self.api(self.papi.gbp_endpoint_del,
1010 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001011
1012 def gbp_endpoint_dump(self):
1013 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001014 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001015
Neale Ranns4ba67722019-02-28 11:11:39 +00001016 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001017 rd, uplink_sw_if_index,
1018 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001019 """ GBP endpoint group Add """
1020 return self.api(self.papi.gbp_endpoint_group_add,
1021 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001022 {
1023 'uplink_sw_if_index': uplink_sw_if_index,
1024 'bd_id': bd,
1025 'rd_id': rd,
1026 'vnid': vnid,
1027 'sclass': sclass,
1028 'retention': retention
1029 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001030
Neale Ranns4ba67722019-02-28 11:11:39 +00001031 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001032 """ GBP endpoint group Del """
1033 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001034 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001035
Neale Ranns160c9232019-06-19 06:25:56 -07001036 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001037 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001038 uu_fwd_sw_if_index,
1039 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001040 """ GBP bridge-domain Add """
1041 return self.api(self.papi.gbp_bridge_domain_add,
1042 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001043 {
1044 'flags': flags,
1045 'bvi_sw_if_index': bvi_sw_if_index,
1046 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1047 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001048 'bd_id': bd_id,
1049 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001050 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001051
1052 def gbp_bridge_domain_del(self, bd_id):
1053 """ GBP bridge-domain Del """
1054 return self.api(self.papi.gbp_bridge_domain_del,
1055 {'bd_id': bd_id})
1056
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001057 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001058 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001059 ip4_table_id,
1060 ip6_table_id,
1061 ip4_uu_sw_if_index,
1062 ip6_uu_sw_if_index):
1063 """ GBP route-domain Add """
1064 return self.api(self.papi.gbp_route_domain_add,
1065 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001066 {
Neale Ranns160c9232019-06-19 06:25:56 -07001067 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001068 'ip4_table_id': ip4_table_id,
1069 'ip6_table_id': ip6_table_id,
1070 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1071 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1072 'rd_id': rd_id
1073 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001074
1075 def gbp_route_domain_del(self, rd_id):
1076 """ GBP route-domain Del """
1077 return self.api(self.papi.gbp_route_domain_del,
1078 {'rd_id': rd_id})
1079
Neale Ranns4ba67722019-02-28 11:11:39 +00001080 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001081 """ GBP recirc Add/Del """
1082 return self.api(self.papi.gbp_recirc_add_del,
1083 {'is_add': is_add,
1084 'recirc': {
1085 'is_ext': is_ext,
1086 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001087 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001088
1089 def gbp_recirc_dump(self):
1090 """ GBP recirc Dump """
1091 return self.api(self.papi.gbp_recirc_dump, {})
1092
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001093 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001094 """ GBP recirc Add/Del """
1095 return self.api(self.papi.gbp_ext_itf_add_del,
1096 {'is_add': is_add,
1097 'ext_itf': {
1098 'sw_if_index': sw_if_index,
1099 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001100 'rd_id': rd_id,
1101 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001102
1103 def gbp_ext_itf_dump(self):
1104 """ GBP recirc Dump """
1105 return self.api(self.papi.gbp_ext_itf_dump, {})
1106
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001107 def gbp_subnet_add_del(self, is_add, rd_id,
1108 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001109 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001110 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001111 """ GBP Subnet Add/Del """
1112 return self.api(self.papi.gbp_subnet_add_del,
1113 {'is_add': is_add,
1114 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001115 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001116 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001117 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001118 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001119 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001120
1121 def gbp_subnet_dump(self):
1122 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001123 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001124
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001125 def gbp_contract_dump(self):
1126 """ GBP contract Dump """
1127 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001128
Neale Ranns8da9fc62019-03-04 14:08:11 -08001129 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001130 """ GBP VXLAN tunnel add """
1131 return self.api(self.papi.gbp_vxlan_tunnel_add,
1132 {
1133 'tunnel': {
1134 'vni': vni,
1135 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001136 'bd_rd_id': bd_rd_id,
1137 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001138 }
1139 })
1140
1141 def gbp_vxlan_tunnel_del(self, vni):
1142 """ GBP VXLAN tunnel del """
1143 return self.api(self.papi.gbp_vxlan_tunnel_del,
1144 {
1145 'vni': vni,
1146 })
1147
1148 def gbp_vxlan_tunnel_dump(self):
1149 """ GBP VXLAN tunnel add/del """
1150 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1151
Neale Ranns947ea622018-06-07 23:48:20 -07001152 def igmp_enable_disable(self, sw_if_index, enable, host):
1153 """ Enable/disable IGMP on a given interface """
1154 return self.api(self.papi.igmp_enable_disable,
1155 {'enable': enable,
1156 'mode': host,
1157 'sw_if_index': sw_if_index})
1158
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001159 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1160 """ Add/del IGMP proxy device """
1161 return self.api(self.papi.igmp_proxy_device_add_del,
1162 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1163 'add': add})
1164
1165 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1166 """ Add/del interface to/from IGMP proxy device """
1167 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1168 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1169 'add': add})
1170
Neale Ranns947ea622018-06-07 23:48:20 -07001171 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001172 """ Listen for new (S,G) on specified interface
1173
1174 :param enable: add/del
1175 :param sw_if_index: interface sw index
1176 :param saddr: source ip4 addr
1177 :param gaddr: group ip4 addr
1178 """
1179 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001180 {
1181 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001182 {
1183 'filter': filter,
1184 'sw_if_index': sw_if_index,
1185 'n_srcs': len(saddrs),
1186 'saddrs': saddrs,
1187 'gaddr': gaddr
1188 }
Neale Ranns947ea622018-06-07 23:48:20 -07001189 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001190
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001191 def igmp_clear_interface(self, sw_if_index):
1192 """ Remove all (S,G)s from specified interface
1193 doesn't send IGMP report!
1194 """
1195 return self.api(
1196 self.papi.igmp_clear_interface, {
1197 'sw_if_index': sw_if_index})
1198
1199 def want_igmp_events(self, enable=1):
1200 return self.api(self.papi.want_igmp_events, {'enable': enable,
1201 'pid': os.getpid()})