blob: ad6d6bcf5746f50b5a594323b08bd024fae4d2c2 [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
Neale Ranns039cbfe2018-02-27 03:45:38 -080018class QOS_SOURCE:
19 EXT = 0
20 VLAN = 1
21 MPLS = 2
22 IP = 3
23
24
Matus Fabianb4515b42018-11-19 04:25:32 -080025class SYSLOG_SEVERITY:
26 EMERG = 0
27 ALERT = 1
28 CRIT = 2
29 ERR = 3
30 WARN = 4
31 NOTICE = 5
32 INFO = 6
33 DBG = 7
34
Ole Troan9a475372019-03-05 16:58:24 +010035
Ole Troanf159f582019-02-28 20:20:47 +010036#
37# Dictionary keyed on message name to override default values for
38# named parameters
39#
Ole Troan9a475372019-03-05 16:58:24 +010040defaultmapping = {
41 'map_add_domain': {'mtu': 1280},
42 'syslog_set_sender': {'collector_port': 514,
43 'max_msg_size': 480},
44 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
45 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
46 'app_namespace_add_del': {'sw_if_index': 4294967295, },
47 'bd_ip_mac_add_del': {'is_add': 1, },
48 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
49 'is_add': 1, },
50 'bier_disp_table_add_del': {'is_add': 1, },
51 'bier_imp_add': {'is_add': 1, },
52 'bier_route_add_del': {'is_add': 1, },
53 'bier_table_add_del': {'is_add': 1, },
54 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
55 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070056 'bvi_create': {'user_instance': 4294967295, },
57 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010058 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
59 'nbuckets': 2, 'memory_size': 2097152,
60 'next_table_index': 4294967295,
61 'miss_next_index': 4294967295, },
62 'dhcp6_client_enable_disable': {'enable': 1, },
63 'dhcp6_clients_enable_disable': {'enable': 1, },
64 'dhcp6_pd_client_enable_disable': {'enable': 1, },
65 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
66 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
67 'dhcp_proxy_config': {'is_add': 1, },
68 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010069 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
70 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
71 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000072 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010073 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
74 'decap_next_index': 4294967295, },
75 'input_acl_set_interface': {'ip4_table_index': 4294967295,
76 'ip6_table_index': 4294967295,
77 'l2_table_index': 4294967295, },
78 'ip6_add_del_address_using_prefix': {'is_add': 1, },
79 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
80 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
81 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
82 'next_hop_id': 4294967295,
83 'classify_table_index': 4294967295, 'is_add': 1, },
84 'ip_mroute_add_del': {'is_add': 1, },
85 'ip_neighbor_add_del': {'is_add': 1, },
86 'ip_punt_police': {'is_add': 1, },
87 'ip_punt_redirect': {'is_add': 1, },
88 'ip_table_add_del': {'is_add': 1, },
89 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
90 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
91 'ipsec_interface_add_del_spd': {'is_add': 1, },
92 'ipsec_sad_entry_add_del': {'is_add': 1, },
93 'ipsec_spd_add_del': {'is_add': 1, },
94 'ipsec_spd_dump': {'sa_id': 4294967295, },
95 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
96 'remote_port_stop': 65535, 'priority': 100,
97 'is_outbound': 1,
98 'is_add': 1, },
99 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
100 'l2_emulation': {'enable': 1, },
101 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700102 'lb_conf': {'sticky_buckets_per_core': 4294967295,
103 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100104 'lisp_add_del_adjacency': {'is_add': 1, },
105 'lisp_add_del_local_eid': {'is_add': 1, },
106 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
107 'lisp_add_del_locator_set': {'is_add': 1, },
108 'lisp_add_del_remote_mapping': {'is_add': 1, },
109 'macip_acl_add_replace': {'acl_index': 4294967295, },
110 'macip_acl_dump': {'acl_index': 4294967295, },
111 'macip_acl_interface_add_del': {'is_add': 1, },
112 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100113 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
114 'mr_next_hop_weight': 1,
115 'mr_next_hop_via_label': 1048576,
116 'mr_is_add': 1,
117 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100118 'mpls_table_add_del': {'is_add': 1, },
119 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
120 'next_hop_weight': 1,
121 'next_hop_via_label': 1048576,
122 'is_add': 1, },
123 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100124 'output_acl_set_interface': {'ip4_table_index': 4294967295,
125 'ip6_table_index': 4294967295,
126 'l2_table_index': 4294967295, },
127 'pppoe_add_del_session': {'is_add': 1, },
128 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
129 'proxy_arp_add_del': {'is_add': 1, },
130 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
131 'punt_socket_register': {'protocol': 17, 'header_version': 1,
132 'is_ip4': 1, },
133 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
134 'punt_socket_dump': {'is_ip6': 1, },
135 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
136 'proto': 1, },
137 'set_ipfix_exporter': {'collector_port': 4739, },
138 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
139 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
140 'svs_enable_disable': {'is_enable': 1, },
141 'svs_route_add_del': {'is_add': 1, },
142 'svs_table_add_del': {'is_add': 1, },
143 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700144 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100145 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
146 'pref_lifetime': 4294967295, },
147 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
148 'sw_interface_set_l2_bridge': {'enable': 1, },
149 'sw_interface_set_mpls_enable': {'enable': 1, },
150 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
151 'sw_interface_set_unnumbered': {'is_add': 1, },
152 'sw_interface_span_enable_disable': {'state': 1, },
153 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
154 'decap_next_index': 4294967295,
155 'instance': 4294967295, },
156 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
157 'instance': 4294967295, },
158 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
159 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
160 'protocol': 3, },
161 'want_bfd_events': {'enable_disable': 1, },
162 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
163 'want_dhcp6_reply_events': {'enable_disable': 1, },
164 'want_igmp_events': {'enable': 1, },
165 'want_interface_events': {'enable_disable': 1, },
166 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
167 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
168 'want_ip6_ra_events': {'enable_disable': 1, },
169 'want_l2_macs_events': {'enable_disable': 1, },
170}
Ole Troanf159f582019-02-28 20:20:47 +0100171
Matus Fabianb4515b42018-11-19 04:25:32 -0800172
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400173class CliFailedCommandError(Exception):
174 """ cli command failed."""
175
176
177class CliSyntaxError(Exception):
178 """ cli command had a syntax error."""
179
180
Klement Sekera73884482017-02-23 09:26:30 +0100181class UnexpectedApiReturnValueError(Exception):
182 """ exception raised when the API return value is unexpected """
183 pass
184
185
Klement Sekeraf62ae122016-10-11 11:47:09 +0200186class VppPapiProvider(object):
187 """VPP-api provider using vpp-papi
188
189 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200190 """
191
Klement Sekerae0545ef2017-01-25 08:00:40 +0100192 _zero, _negative = range(2)
193
Klement Sekera611864f2018-09-26 11:19:00 +0200194 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800195 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200196 self.name = name
197 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100198 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100199 self._expect_api_retval = self._zero
200 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100201
Paul Vinciguerra19542292019-03-17 17:34:46 -0700202 # install_dir is a class attribute. We need to set it before
203 # calling the constructor.
204 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800205
Ole Troan4ff09ae2019-04-15 11:27:22 +0200206 use_socket = False
207 try:
208 if os.environ['SOCKET'] == '1':
209 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400210 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200211 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700212
213 self.vpp = VPPApiClient(logger=test_class.logger,
214 read_timeout=read_timeout,
215 use_socket=use_socket,
216 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100217 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218
Klement Sekerae0545ef2017-01-25 08:00:40 +0100219 def __enter__(self):
220 return self
221
Klement Sekera7d6afb32018-11-08 11:52:04 +0100222 def assert_negative_api_retval(self):
223 """ Expect API failure - used with with, e.g.:
224 with self.vapi.assert_negative_api_retval():
225 self.vapi.<api call expected to fail>
226 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100227 self._expect_stack.append(self._expect_api_retval)
228 self._expect_api_retval = self._negative
229 return self
230
Klement Sekera7d6afb32018-11-08 11:52:04 +0100231 def assert_zero_api_retval(self):
232 """ Expect API success - used with with, e.g.:
233 with self.vapi.assert_negative_api_retval():
234 self.vapi.<api call expected to succeed>
235
236 note: this is useful only inside another with block
237 as success is the default expected value
238 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100239 self._expect_stack.append(self._expect_api_retval)
240 self._expect_api_retval = self._zero
241 return self
242
243 def __exit__(self, exc_type, exc_value, traceback):
244 self._expect_api_retval = self._expect_stack.pop()
245
Klement Sekeraf62ae122016-10-11 11:47:09 +0200246 def register_hook(self, hook):
247 """Replace hook registration with new hook
248
249 :param hook:
250
251 """
252 self.hook = hook
253
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200254 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100255 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200256 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100257 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200258 return e
259
260 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100261 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100262 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100263 self.test_class.logger.debug("Expecting event '%s' within %ss",
264 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300265 else:
266 self.test_class.logger.debug("Expecting event within %ss",
267 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100268 if self._events:
269 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200270 limit = time.time() + timeout
271 while time.time() < limit:
272 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100273 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200274 if name and type(e).__name__ != name:
275 raise Exception(
276 "Unexpected event received: %s, expected: %s" %
277 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100278 self.test_class.logger.debug("Returning event %s:%s" %
279 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200280 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700281 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200282 raise Exception("Event did not occur within timeout")
283
284 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100285 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200286 # FIXME use the name instead of relying on type(e).__name__ ?
287 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100288 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200289 self._events.append(event)
290
Ole Troanf159f582019-02-28 20:20:47 +0100291 def factory(self, name, apifn):
292 def f(*a, **ka):
293 fields = apifn._func.msg.fields
294
295 # add positional and kw arguments
296 d = ka
297 for i, o in enumerate(fields[3:]):
298 try:
299 d[o] = a[i]
300 except:
301 break
302
303 # Default override
304 if name in defaultmapping:
305 for k, v in iteritems(defaultmapping[name]):
306 if k in d:
307 continue
308 d[k] = v
309 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100310
Ole Troanf159f582019-02-28 20:20:47 +0100311 return f
312
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800313 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100314 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800315 method = super(VppPapiProvider, self).__getattribute__(name)
316 except AttributeError:
317 method = self.factory(name, getattr(self.papi, name))
318 # lazily load the method so we don't need to call factory
319 # again for this name.
320 setattr(self, name, method)
321 return method
Ole Troanf159f582019-02-28 20:20:47 +0100322
Klement Sekeraf62ae122016-10-11 11:47:09 +0200323 def connect(self):
324 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100325 self.vpp.connect(self.name, self.shm_prefix)
326 self.papi = self.vpp.api
327 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200328
329 def disconnect(self):
330 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100331 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200332
333 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100334 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200335 Call the appropriate hooks before and after the API call
336
337 :param api_fn: API function to call
338 :param api_args: tuple of API function arguments
339 :param expected_retval: Expected return value (Default value = 0)
340 :returns: reply from the API
341
342 """
343 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100344 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100345 if self._expect_api_retval == self._negative:
346 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100347 msg = "API call passed unexpectedly: expected negative " \
348 "return value instead of %d in %s" % \
349 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100350 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100351 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100352 elif self._expect_api_retval == self._zero:
353 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100354 msg = "API call failed, expected %d return value instead " \
355 "of %d in %s" % (expected_retval, reply.retval,
356 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100357 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100358 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100359 else:
360 raise Exception("Internal error, unexpected value for "
361 "self._expect_api_retval %s" %
362 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200363 self.hook.after_api(api_fn.__name__, api_args)
364 return reply
365
366 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100367 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200368
369 :param cli: CLI to execute
370 :returns: CLI output
371
372 """
373 self.hook.before_cli(cli)
374 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100375 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200376 self.hook.after_cli(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400377 if r.retval == -156:
378 raise CliSyntaxError(r.reply)
379 if r.retval != 0:
380 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200381 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100382 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200383
Jan49c0fca2016-10-26 15:44:27 +0200384 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100385 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200386
387 :param cli: CLI to execute
388 :returns: CLI output
389 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600390 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200391
Neale Ranns37029302018-08-10 05:30:06 -0700392 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300393 return self.api(self.papi.want_ip4_arp_events,
394 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700395 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300396 'pid': os.getpid(), })
397
Neale Ranns37029302018-08-10 05:30:06 -0700398 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300399 return self.api(self.papi.want_ip6_nd_events,
400 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700401 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300402 'pid': os.getpid(), })
403
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100404 def want_ip6_ra_events(self, enable_disable=1):
405 return self.api(self.papi.want_ip6_ra_events,
406 {'enable_disable': enable_disable,
407 'pid': os.getpid(), })
408
409 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
410 mrc=0, mrd=0):
411 return self.api(self.papi.ip6nd_send_router_solicitation,
412 {'irt': irt,
413 'mrt': mrt,
414 'mrc': mrc,
415 'mrd': mrd,
416 'sw_if_index': sw_if_index})
417
Juraj Slobodab3f90502018-10-04 15:15:16 +0200418 def want_interface_events(self, enable_disable=1):
419 return self.api(self.papi.want_interface_events,
420 {'enable_disable': enable_disable,
421 'pid': os.getpid(), })
422
Ole Troane1ade682019-03-04 23:55:43 +0100423 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
424 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300425 return self.api(self.papi.want_l2_macs_events,
426 {'enable_disable': enable_disable,
427 'scan_delay': scan_delay,
428 'max_macs_in_event': max_macs_in_event,
429 'learn_limit': learn_limit,
430 'pid': os.getpid(), })
431
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200432 def want_dhcp6_reply_events(self, enable_disable=1):
433 return self.api(self.papi.want_dhcp6_reply_events,
434 {'enable_disable': enable_disable,
435 'pid': os.getpid()})
436
Juraj Sloboda81119e82018-05-25 14:02:20 +0200437 def want_dhcp6_pd_reply_events(self, enable_disable=1):
438 return self.api(self.papi.want_dhcp6_pd_reply_events,
439 {'enable_disable': enable_disable,
440 'pid': os.getpid()})
441
Juraj Sloboda81119e82018-05-25 14:02:20 +0200442 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
443 prefixes, server_index=0xFFFFFFFF,
444 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
445 ):
446 return self.api(self.papi.dhcp6_pd_send_client_message,
447 {'sw_if_index': sw_if_index,
448 'server_index': server_index,
449 'irt': irt,
450 'mrt': mrt,
451 'mrc': mrc,
452 'mrd': mrd,
453 'stop': stop,
454 'msg_type': msg_type,
455 'T1': T1,
456 'T2': T2,
457 'n_prefixes': len(prefixes),
458 'prefixes': prefixes})
459
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200460 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
461 enable=1):
462 return self.api(self.papi.dhcp6_client_enable_disable,
463 {'sw_if_index': sw_if_index,
464 'enable': enable})
465
Juraj Sloboda81119e82018-05-25 14:02:20 +0200466 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
467 enable=1):
468 return self.api(self.papi.dhcp6_pd_client_enable_disable,
469 {'sw_if_index': sw_if_index,
470 'prefix_group': prefix_group,
471 'enable': enable})
472
473 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
474 prefix_length, prefix_group,
475 is_add=1):
476 return self.api(self.papi.ip6_add_del_address_using_prefix,
477 {'sw_if_index': sw_if_index,
478 'prefix_group': prefix_group,
479 'address': address,
480 'prefix_length': prefix_length,
481 'is_add': is_add})
482
Neale Rannsc819fc62018-02-16 02:44:05 -0800483 def sw_interface_set_mac_address(self, sw_if_index, mac):
484 return self.api(self.papi.sw_interface_set_mac_address,
485 {'sw_if_index': sw_if_index,
486 'mac_address': mac})
487
Ole Troane1ade682019-03-04 23:55:43 +0100488 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200489 """Create p2p ethernet subinterface
490
491 :param sw_if_index: main (parent) interface
492 :param remote_mac: client (remote) mac address
493
494 """
495 return self.api(
496 self.papi.p2p_ethernet_add,
497 {'parent_if_index': sw_if_index,
498 'remote_mac': remote_mac,
499 'subif_id': subif_id})
500
Ole Troane1ade682019-03-04 23:55:43 +0100501 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200502 """Delete p2p ethernet subinterface
503
504 :param sw_if_index: main (parent) interface
505 :param remote_mac: client (remote) mac address
506
507 """
508 return self.api(
509 self.papi.p2p_ethernet_del,
510 {'parent_if_index': sw_if_index,
511 'remote_mac': remote_mac})
512
Klement Sekeraf62ae122016-10-11 11:47:09 +0200513 def create_vlan_subif(self, sw_if_index, vlan):
514 """
515
516 :param vlan:
517 :param sw_if_index:
518
519 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100520 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200521 {'sw_if_index': sw_if_index,
522 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200523
Matej Klotton0178d522016-11-04 11:11:44 +0100524 def create_loopback(self, mac=''):
525 """
526
527 :param mac: (Optional)
528 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100529 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200530 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100531
Matej Klotton0178d522016-11-04 11:11:44 +0100532 def ip_neighbor_add_del(self,
533 sw_if_index,
534 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700535 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100536 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700537 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100538 """ Add neighbor MAC to IPv4 or IPv6 address.
539
540 :param sw_if_index:
541 :param mac_address:
542 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100543 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700544 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100545 """
Matej Klotton0178d522016-11-04 11:11:44 +0100546 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100547 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700548 {
549 'is_add': is_add,
550 'neighbor': {
551 'sw_if_index': sw_if_index,
552 'flags': flags,
553 'mac_address': mac_address,
554 'ip_address': ip_address
555 }
556 }
Matej Klotton0178d522016-11-04 11:11:44 +0100557 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100558
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800559 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700560 low,
561 hi,
562 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800563 is_add=1):
564 """ Config Proxy Arp Range.
565
566 :param low_address: Start address in the rnage to Proxy for
567 :param hi_address: End address in the rnage to Proxy for
568 :param vrf_id: The VRF/table in which to proxy
569 """
570
571 return self.api(
572 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700573 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100574 {
575 'table_id': table_id,
576 'low': low,
577 'hi': hi,
578 },
579 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800580
581 def proxy_arp_intfc_enable_disable(self,
582 sw_if_index,
583 is_enable=1):
584 """ Enable/Disable an interface for proxy ARP requests
585
586 :param sw_if_index: Interface
587 :param enable_disable: Enable/Disable
588 """
589
590 return self.api(
591 self.papi.proxy_arp_intfc_enable_disable,
592 {'sw_if_index': sw_if_index,
593 'enable_disable': is_enable
594 }
595 )
596
Neale Ranns5a8844b2019-04-16 07:15:35 +0000597 def gre_tunnel_add_del(self,
598 src,
599 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000600 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500601 tunnel_type=0,
602 instance=0xFFFFFFFF,
603 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000604 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000605 """ Add a GRE tunnel
606
607 :param src_address:
608 :param dst_address:
609 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500610 :param tunnel_type: (Default value = 0)
611 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700612 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000613 :param is_add: (Default value = 1)
614 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000615 """
616
617 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000618 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200619 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000620 'tunnel':
621 {
622 'type': tunnel_type,
623 'instance': instance,
624 'src': src,
625 'dst': dst,
626 'outer_fib_id': outer_fib_id,
627 'session_id': session_id}
628 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000629 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000630
Neale Rannsd0df49f2018-08-08 01:06:40 -0700631 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700632 src_ip,
633 dst_ip,
634 src_port,
635 dst_port,
636 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800637 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800638 :param src_ip:
639 :param dst_ip:
640 :param src_port:
641 :param dst_port:
642 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800643 """
644
645 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700646 self.papi.udp_encap_add,
647 {
648 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700649 'src_ip': src_ip,
650 'dst_ip': dst_ip,
651 'src_port': src_port,
652 'dst_port': dst_port,
653 'table_id': table_id
654 }
655 })
656
Neale Ranns15002542017-09-10 04:39:11 -0700657 def mpls_table_add_del(
658 self,
659 table_id,
660 is_add=1):
661 """
662
663 :param table_id
664 :param is_add: (Default value = 1)
665
666 """
667
668 return self.api(
669 self.papi.mpls_table_add_del,
670 {'mt_table_id': table_id,
671 'mt_is_add': is_add})
672
Neale Rannsad422ed2016-11-02 14:20:04 +0000673 def mpls_ip_bind_unbind(
674 self,
675 label,
676 dst_address,
677 dst_address_length,
678 table_id=0,
679 ip_table_id=0,
680 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000681 is_bind=1):
682 """
683 """
684 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100685 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200686 {'mb_mpls_table_id': table_id,
687 'mb_label': label,
688 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200689 'mb_is_bind': is_bind,
690 'mb_is_ip4': is_ip4,
691 'mb_address_length': dst_address_length,
692 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000693
694 def mpls_tunnel_add_del(
695 self,
696 tun_sw_if_index,
697 next_hop_proto_is_ip4,
698 next_hop_address,
699 next_hop_sw_if_index=0xFFFFFFFF,
700 next_hop_table_id=0,
701 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200702 next_hop_n_out_labels=0,
703 next_hop_out_label_stack=[],
704 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000705 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800706 l2_only=0,
707 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000708 """
709
710 :param dst_address_length:
711 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
712 :param dst_address:
713 :param next_hop_address:
714 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
715 :param vrf_id: (Default value = 0)
716 :param lookup_in_vrf: (Default value = 0)
717 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000718 :param is_add: (Default value = 1)
719 :param is_drop: (Default value = 0)
720 :param is_ipv6: (Default value = 0)
721 :param is_local: (Default value = 0)
722 :param is_classify: (Default value = 0)
723 :param is_multipath: (Default value = 0)
724 :param is_resolve_host: (Default value = 0)
725 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000726 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800727 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000728
729 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000730 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100731 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200732 {'mt_sw_if_index': tun_sw_if_index,
733 'mt_is_add': is_add,
734 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800735 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200736 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
737 'mt_next_hop_weight': next_hop_weight,
738 'mt_next_hop': next_hop_address,
739 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
740 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
741 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700742 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200743 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800744
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200745 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +0100746 detect_mult, local_addr, peer_addr, is_ipv6=0,
747 bfd_key_id=None, conf_key_id=None):
748 if bfd_key_id is None:
749 return self.api(self.papi.bfd_udp_add,
750 {
751 'sw_if_index': sw_if_index,
752 'desired_min_tx': desired_min_tx,
753 'required_min_rx': required_min_rx,
754 'local_addr': local_addr,
755 'peer_addr': peer_addr,
756 'is_ipv6': is_ipv6,
757 'detect_mult': detect_mult,
758 })
759 else:
760 return self.api(self.papi.bfd_udp_add,
761 {
762 'sw_if_index': sw_if_index,
763 'desired_min_tx': desired_min_tx,
764 'required_min_rx': required_min_rx,
765 'local_addr': local_addr,
766 'peer_addr': peer_addr,
767 'is_ipv6': is_ipv6,
768 'detect_mult': detect_mult,
769 'is_authenticated': 1,
770 'bfd_key_id': bfd_key_id,
771 'conf_key_id': conf_key_id,
772 })
773
Klement Sekeraa57a9702017-02-02 06:58:07 +0100774 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
775 detect_mult, local_addr, peer_addr, is_ipv6=0):
776 return self.api(self.papi.bfd_udp_mod,
777 {
778 'sw_if_index': sw_if_index,
779 'desired_min_tx': desired_min_tx,
780 'required_min_rx': required_min_rx,
781 'local_addr': local_addr,
782 'peer_addr': peer_addr,
783 'is_ipv6': is_ipv6,
784 'detect_mult': detect_mult,
785 })
786
Klement Sekerab17dd962017-01-09 07:43:48 +0100787 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
788 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
789 is_delayed=False):
790 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200791 {
792 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200793 'local_addr': local_addr,
794 'peer_addr': peer_addr,
795 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +0100796 'is_delayed': 1 if is_delayed else 0,
797 'bfd_key_id': bfd_key_id,
798 'conf_key_id': conf_key_id,
799 })
800
Klement Sekerab17dd962017-01-09 07:43:48 +0100801 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
802 peer_addr, is_ipv6=0):
803 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200804 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +0100805 'sw_if_index': sw_if_index,
806 'local_addr': local_addr,
807 'peer_addr': peer_addr,
808 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200809 })
810
811 def want_bfd_events(self, enable_disable=1):
812 return self.api(self.papi.want_bfd_events, {
813 'enable_disable': enable_disable,
814 'pid': os.getpid(),
815 })
Steve Shin7957d6e2016-12-19 09:24:50 -0800816
Klement Sekerab17dd962017-01-09 07:43:48 +0100817 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
818 return self.api(self.papi.bfd_auth_set_key, {
819 'conf_key_id': conf_key_id,
820 'auth_type': auth_type,
821 'key': key,
822 'key_len': len(key),
823 })
824
Steve Shin7957d6e2016-12-19 09:24:50 -0800825 def classify_add_del_table(
826 self,
827 is_add,
828 mask,
829 match_n_vectors=1,
830 table_index=0xFFFFFFFF,
831 nbuckets=2,
832 memory_size=2097152,
833 skip_n_vectors=0,
834 next_table_index=0xFFFFFFFF,
835 miss_next_index=0xFFFFFFFF,
836 current_data_flag=0,
837 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -0800838 """
839 :param is_add:
840 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +0100841 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100842 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -0800843 :param nbuckets: (Default value = 2)
844 :param memory_size: (Default value = 2097152)
845 :param skip_n_vectors: (Default value = 0)
846 :param next_table_index: (Default value = 0xFFFFFFFF)
847 :param miss_next_index: (Default value = 0xFFFFFFFF)
848 :param current_data_flag: (Default value = 0)
849 :param current_data_offset: (Default value = 0)
850 """
851
Juraj Sloboda75282452018-06-12 14:20:49 +0200852 mask_len = ((len(mask) - 1) / 16 + 1) * 16
853 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -0800854 return self.api(
855 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100856 {'is_add': is_add,
857 'table_index': table_index,
858 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -0800859 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100860 'skip_n_vectors': skip_n_vectors,
861 'match_n_vectors': match_n_vectors,
862 'next_table_index': next_table_index,
863 'miss_next_index': miss_next_index,
864 'current_data_flag': current_data_flag,
865 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +0200866 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100867 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -0800868
869 def classify_add_del_session(
870 self,
871 is_add,
872 table_index,
873 match,
874 opaque_index=0xFFFFFFFF,
875 hit_next_index=0xFFFFFFFF,
876 advance=0,
877 action=0,
878 metadata=0):
879 """
880 :param is_add:
881 :param table_index:
882 :param match:
883 :param opaque_index: (Default value = 0xFFFFFFFF)
884 :param hit_next_index: (Default value = 0xFFFFFFFF)
885 :param advance: (Default value = 0)
886 :param action: (Default value = 0)
887 :param metadata: (Default value = 0)
888 """
889
Juraj Sloboda75282452018-06-12 14:20:49 +0200890 match_len = ((len(match) - 1) / 16 + 1) * 16
891 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -0800892 return self.api(
893 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100894 {'is_add': is_add,
895 'table_index': table_index,
896 'hit_next_index': hit_next_index,
897 'opaque_index': opaque_index,
898 'advance': advance,
899 'action': action,
900 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +0200901 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100902 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -0800903
904 def input_acl_set_interface(
905 self,
906 is_add,
907 sw_if_index,
908 ip4_table_index=0xFFFFFFFF,
909 ip6_table_index=0xFFFFFFFF,
910 l2_table_index=0xFFFFFFFF):
911 """
912 :param is_add:
913 :param sw_if_index:
914 :param ip4_table_index: (Default value = 0xFFFFFFFF)
915 :param ip6_table_index: (Default value = 0xFFFFFFFF)
916 :param l2_table_index: (Default value = 0xFFFFFFFF)
917 """
918
919 return self.api(
920 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100921 {'sw_if_index': sw_if_index,
922 'ip4_table_index': ip4_table_index,
923 'ip6_table_index': ip6_table_index,
924 'l2_table_index': l2_table_index,
925 'is_add': is_add})
926
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100927 def output_acl_set_interface(
928 self,
929 is_add,
930 sw_if_index,
931 ip4_table_index=0xFFFFFFFF,
932 ip6_table_index=0xFFFFFFFF,
933 l2_table_index=0xFFFFFFFF):
934 """
935 :param is_add:
936 :param sw_if_index:
937 :param ip4_table_index: (Default value = 0xFFFFFFFF)
938 :param ip6_table_index: (Default value = 0xFFFFFFFF)
939 :param l2_table_index: (Default value = 0xFFFFFFFF)
940 """
941
942 return self.api(
943 self.papi.output_acl_set_interface,
944 {'sw_if_index': sw_if_index,
945 'ip4_table_index': ip4_table_index,
946 'ip6_table_index': ip6_table_index,
947 'l2_table_index': l2_table_index,
948 'is_add': is_add})
949
Klement Sekera77fabdb2017-01-02 07:46:14 +0100950 def set_ipfix_exporter(
951 self,
952 collector_address,
953 src_address,
954 path_mtu,
955 template_interval,
956 vrf_id=0,
957 collector_port=4739,
958 udp_checksum=0):
959 return self.api(
960 self.papi.set_ipfix_exporter,
961 {
962 'collector_address': collector_address,
963 'collector_port': collector_port,
964 'src_address': src_address,
965 'vrf_id': vrf_id,
966 'path_mtu': path_mtu,
967 'template_interval': template_interval,
968 'udp_checksum': udp_checksum,
969 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800970
971 def dhcp_proxy_config(self,
972 dhcp_server,
973 dhcp_src_address,
974 rx_table_id=0,
975 server_table_id=0,
976 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800977 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800978 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -0800979 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -0800980 {
981 'rx_vrf_id': rx_table_id,
982 'server_vrf_id': server_table_id,
983 'is_ipv6': is_ipv6,
984 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -0800985 'dhcp_server': dhcp_server,
986 'dhcp_src_address': dhcp_src_address,
987 })
988
989 def dhcp_proxy_set_vss(self,
990 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -0500991 vss_type=255,
992 vpn_ascii_id="",
993 oui=0,
994 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800995 is_add=1,
996 is_ip6=0):
997 return self.api(
998 self.papi.dhcp_proxy_set_vss,
999 {
1000 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001001 'vss_type': vss_type,
1002 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001003 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001004 'vpn_index': vpn_index,
1005 'is_add': is_add,
1006 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001007 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001008
Ole Troane1ade682019-03-04 23:55:43 +01001009 def dhcp_client_config(self,
1010 sw_if_index,
1011 hostname,
1012 client_id='',
1013 is_add=1,
1014 set_broadcast_flag=1,
1015 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001016 return self.api(
1017 self.papi.dhcp_client_config,
1018 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001019 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001020 'client': {
1021 'sw_if_index': sw_if_index,
1022 'hostname': hostname,
1023 'id': client_id,
1024 'want_dhcp_event': want_dhcp_events,
1025 'set_broadcast_flag': set_broadcast_flag,
1026 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001027 })
1028
Neale Ranns32e1c012016-11-22 17:07:28 +00001029 def ip_mroute_add_del(self,
1030 src_address,
1031 grp_address,
1032 grp_address_length,
1033 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001034 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001035 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001036 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001037 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001038 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001039 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001040 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001041 is_add=1,
1042 is_ipv6=0,
1043 is_local=0):
1044 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001045 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001046 """
1047 return self.api(
1048 self.papi.ip_mroute_add_del,
1049 {'next_hop_sw_if_index': next_hop_sw_if_index,
1050 'entry_flags': e_flags,
1051 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001052 'table_id': table_id,
1053 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001054 'is_add': is_add,
1055 'is_ipv6': is_ipv6,
1056 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001057 'bier_imp': bier_imp,
1058 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001059 'grp_address_length': grp_address_length,
1060 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001061 'src_address': src_address,
1062 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001063
Filip Tehlar770e89e2017-01-31 10:39:16 +01001064 def lisp_enable_disable(self, is_enabled):
1065 return self.api(
1066 self.papi.lisp_enable_disable,
1067 {
1068 'is_en': is_enabled,
1069 })
1070
Ole Troane1ade682019-03-04 23:55:43 +01001071 def lisp_add_del_locator_set(self,
1072 ls_name,
1073 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001074 return self.api(
1075 self.papi.lisp_add_del_locator_set,
1076 {
1077 'is_add': is_add,
1078 'locator_set_name': ls_name
1079 })
1080
Ole Troane1ade682019-03-04 23:55:43 +01001081 def lisp_add_del_locator(self,
1082 ls_name,
1083 sw_if_index,
1084 priority=1,
1085 weight=1,
1086 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001087 return self.api(
1088 self.papi.lisp_add_del_locator,
1089 {
1090 'is_add': is_add,
1091 'locator_set_name': ls_name,
1092 'sw_if_index': sw_if_index,
1093 'priority': priority,
1094 'weight': weight
1095 })
1096
1097 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1098 return self.api(
1099 self.papi.lisp_locator_dump,
1100 {
1101 'is_index_set': is_index_set,
1102 'ls_name': ls_name,
1103 'ls_index': ls_index,
1104 })
1105
Ole Troane1ade682019-03-04 23:55:43 +01001106 def lisp_add_del_local_eid(self,
1107 ls_name,
1108 eid_type,
1109 eid,
1110 prefix_len,
1111 vni=0,
1112 key_id=0,
1113 key="",
1114 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001115 return self.api(
1116 self.papi.lisp_add_del_local_eid,
1117 {
1118 'locator_set_name': ls_name,
1119 'is_add': is_add,
1120 'eid_type': eid_type,
1121 'eid': eid,
1122 'prefix_len': prefix_len,
1123 'vni': vni,
1124 'key_id': key_id,
1125 'key': key
1126 })
1127
1128 def lisp_eid_table_dump(self,
1129 eid_set=0,
1130 prefix_length=0,
1131 vni=0,
1132 eid_type=0,
1133 eid=None,
1134 filter_opt=0):
1135 return self.api(
1136 self.papi.lisp_eid_table_dump,
1137 {
1138 'eid_set': eid_set,
1139 'prefix_length': prefix_length,
1140 'vni': vni,
1141 'eid_type': eid_type,
1142 'eid': eid,
1143 'filter': filter_opt,
1144 })
1145
Ole Troane1ade682019-03-04 23:55:43 +01001146 def lisp_add_del_remote_mapping(self,
1147 eid_type,
1148 eid,
1149 eid_prefix_len=0,
1150 vni=0,
1151 rlocs=[],
1152 rlocs_num=0,
1153 is_src_dst=0,
1154 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001155 return self.api(
1156 self.papi.lisp_add_del_remote_mapping,
1157 {
1158 'is_add': is_add,
1159 'eid_type': eid_type,
1160 'eid': eid,
1161 'eid_len': eid_prefix_len,
1162 'rloc_num': rlocs_num,
1163 'rlocs': rlocs,
1164 'vni': vni,
1165 'is_src_dst': is_src_dst,
1166 })
1167
Ole Troane1ade682019-03-04 23:55:43 +01001168 def lisp_add_del_adjacency(self,
1169 leid,
1170 reid,
1171 leid_len,
1172 reid_len,
1173 eid_type,
1174 is_add=1,
1175 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001176 return self.api(
1177 self.papi.lisp_add_del_adjacency,
1178 {
1179 'is_add': is_add,
1180 'vni': vni,
1181 'eid_type': eid_type,
1182 'leid': leid,
1183 'reid': reid,
1184 'leid_len': leid_len,
1185 'reid_len': reid_len,
1186 })
1187
Hongjun Nief486b12017-04-12 19:21:16 +08001188 def gtpu_add_del_tunnel(
1189 self,
1190 src_addr,
1191 dst_addr,
1192 is_add=1,
1193 is_ipv6=0,
1194 mcast_sw_if_index=0xFFFFFFFF,
1195 encap_vrf_id=0,
1196 decap_next_index=0xFFFFFFFF,
1197 teid=0):
1198 """
1199
1200 :param is_add: (Default value = 1)
1201 :param is_ipv6: (Default value = 0)
1202 :param src_addr:
1203 :param dst_addr:
1204 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1205 :param encap_vrf_id: (Default value = 0)
1206 :param decap_next_index: (Default value = 0xFFFFFFFF)
1207 :param teid: (Default value = 0)
1208
1209 """
1210 return self.api(self.papi.gtpu_add_del_tunnel,
1211 {'is_add': is_add,
1212 'is_ipv6': is_ipv6,
1213 'src_address': src_addr,
1214 'dst_address': dst_addr,
1215 'mcast_sw_if_index': mcast_sw_if_index,
1216 'encap_vrf_id': encap_vrf_id,
1217 'decap_next_index': decap_next_index,
1218 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001219
1220 def vxlan_gpe_add_del_tunnel(
1221 self,
1222 src_addr,
1223 dst_addr,
1224 mcast_sw_if_index=0xFFFFFFFF,
1225 is_add=1,
1226 is_ipv6=0,
1227 encap_vrf_id=0,
1228 decap_vrf_id=0,
1229 protocol=3,
1230 vni=0):
1231 """
1232
1233 :param local:
1234 :param remote:
1235 :param is_add: (Default value = 1)
1236 :param is_ipv6: (Default value = 0)
1237 :param encap_vrf_id: (Default value = 0)
1238 :param decap_vrf_id: (Default value = 0)
1239 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1240 :param protocol: (Default value = 3)
1241 :param vni: (Default value = 0)
1242
1243 """
1244 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1245 {'is_add': is_add,
1246 'is_ipv6': is_ipv6,
1247 'local': src_addr,
1248 'remote': dst_addr,
1249 'mcast_sw_if_index': mcast_sw_if_index,
1250 'encap_vrf_id': encap_vrf_id,
1251 'decap_vrf_id': decap_vrf_id,
1252 'protocol': protocol,
1253 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001254
Neale Ranns79a05f52018-09-11 07:39:43 -07001255 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001256 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001257 src,
1258 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001259 mcast_sw_if_index=0xFFFFFFFF,
1260 is_add=1,
1261 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001262 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001263 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001264 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001265 instance=0xFFFFFFFF):
1266 """
1267
1268 :param dst_addr:
1269 :param src_addr:
1270 :param is_add: (Default value = 1)
1271 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001272 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001273 :param decap_next_index: (Default value = 0xFFFFFFFF)
1274 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1275 :param vni: (Default value = 0)
1276 :param instance: (Default value = 0xFFFFFFFF)
1277
1278 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001279 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001280 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001281 'tunnel': {
1282 'src': src,
1283 'dst': dst,
1284 'mcast_sw_if_index': mcast_sw_if_index,
1285 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001286 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001287 'instance': instance,
1288 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001289
1290 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1291 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001292 {'sw_if_index': sw_if_index,
1293 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001294
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001295 def pppoe_add_del_session(
1296 self,
1297 client_ip,
1298 client_mac,
1299 session_id=0,
1300 is_add=1,
1301 is_ipv6=0,
1302 decap_vrf_id=0):
1303 """
1304
1305 :param is_add: (Default value = 1)
1306 :param is_ipv6: (Default value = 0)
1307 :param client_ip:
1308 :param session_id: (Default value = 0)
1309 :param client_mac:
1310 :param decap_vrf_id: (Default value = 0)
1311
1312 """
1313 return self.api(self.papi.pppoe_add_del_session,
1314 {'is_add': is_add,
1315 'is_ipv6': is_ipv6,
1316 'session_id': session_id,
1317 'client_ip': client_ip,
1318 'decap_vrf_id': decap_vrf_id,
1319 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001320
Neale Ranns7c922dc2018-08-30 06:12:27 -07001321 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1322 return self.api(self.papi.sr_mpls_policy_add,
1323 {'bsid': bsid,
1324 'weight': weight,
1325 'type': type,
1326 'n_segments': len(segments),
1327 'segments': segments})
1328
1329 def sr_mpls_policy_del(self, bsid):
1330 return self.api(self.papi.sr_mpls_policy_del,
1331 {'bsid': bsid})
1332
Kris Michielsen91074432017-06-22 13:00:20 +02001333 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001334 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001335 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001336 nh_addr4,
1337 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001338 is_del=0,
1339 end_psp=0,
1340 sw_if_index=0xFFFFFFFF,
1341 vlan_index=0,
1342 fib_table=0,
1343 ):
1344 """ Add/del IPv6 SR local-SID.
1345
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001346 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001347 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1348 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001349 :param nh_addr4:
1350 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001351 :param is_del: (Default value = 0)
1352 :param end_psp: (Default value = 0)
1353 :param sw_if_index: (Default value = 0xFFFFFFFF)
1354 :param vlan_index: (Default value = 0)
1355 :param fib_table: (Default value = 0)
1356 """
1357 return self.api(
1358 self.papi.sr_localsid_add_del,
1359 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001360 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001361 'end_psp': end_psp,
1362 'behavior': behavior,
1363 'sw_if_index': sw_if_index,
1364 'vlan_index': vlan_index,
1365 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001366 'nh_addr4': nh_addr4,
1367 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001368 }
1369 )
1370
1371 def sr_policy_add(
1372 self,
1373 bsid_addr,
1374 weight=1,
1375 is_encap=1,
1376 type=0,
1377 fib_table=0,
1378 n_segments=0,
1379 segments=[]):
1380 """
1381 :param bsid_addr: bindingSID of the SR Policy
1382 :param weight: weight of the sid list. optional. (default: 1)
1383 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1384 (default: Encap)
1385 :param type: type/behavior of the SR policy. (default or spray) \
1386 (default: default)
1387 :param fib_table: VRF where to install the FIB entry for the BSID \
1388 (default: 0)
1389 :param n_segments: number of segments \
1390 (default: 0)
1391 :param segments: a vector of IPv6 address composing the segment list \
1392 (default: [])
1393 """
1394 return self.api(
1395 self.papi.sr_policy_add,
1396 {'bsid_addr': bsid_addr,
1397 'weight': weight,
1398 'is_encap': is_encap,
1399 'type': type,
1400 'fib_table': fib_table,
1401 'n_segments': n_segments,
1402 'segments': segments
1403 }
1404 )
1405
1406 def sr_policy_del(
1407 self,
1408 bsid_addr,
1409 sr_policy_index=0):
1410 """
1411 :param bsid: bindingSID of the SR Policy
1412 :param sr_policy_index: index of the sr policy (default: 0)
1413 """
1414 return self.api(
1415 self.papi.sr_policy_del,
1416 {'bsid_addr': bsid_addr,
1417 'sr_policy_index': sr_policy_index
1418 })
1419
1420 def sr_steering_add_del(
1421 self,
1422 is_del,
1423 bsid_addr,
1424 sr_policy_index,
1425 table_id,
1426 prefix_addr,
1427 mask_width,
1428 sw_if_index,
1429 traffic_type):
1430 """
1431 Steer traffic L2 and L3 traffic through a given SR policy
1432
1433 :param is_del: delete or add
1434 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1435 :param sr_policy: is the index of the SR Policy (alt to bsid)
1436 :param table_id: is the VRF where to install the FIB entry for the BSID
1437 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1438 :param mask_width: is the mask for L3 traffic type
1439 :param sw_if_index: is the incoming interface for L2 traffic
1440 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1441 """
1442 return self.api(
1443 self.papi.sr_steering_add_del,
1444 {'is_del': is_del,
1445 'bsid_addr': bsid_addr,
1446 'sr_policy_index': sr_policy_index,
1447 'table_id': table_id,
1448 'prefix_addr': prefix_addr,
1449 'mask_width': mask_width,
1450 'sw_if_index': sw_if_index,
1451 'traffic_type': traffic_type
1452 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001453
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001454 def acl_add_replace(self, acl_index, r, tag='',
1455 expected_retval=0):
1456 """Add/replace an ACL
1457 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1458 :param acl_rule r: ACL rules array.
1459 :param str tag: symbolic tag (description) for this ACL.
1460 :param int count: number of rules.
1461 """
1462 return self.api(self.papi.acl_add_replace,
1463 {'acl_index': acl_index,
1464 'r': r,
1465 'count': len(r),
1466 'tag': tag},
1467 expected_retval=expected_retval)
1468
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001469 def acl_del(self, acl_index, expected_retval=0):
1470 """
1471
1472 :param acl_index:
1473 :return:
1474 """
1475 return self.api(self.papi.acl_del,
1476 {'acl_index': acl_index},
1477 expected_retval=expected_retval)
1478
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001479 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1480 expected_retval=0):
1481 return self.api(self.papi.acl_interface_set_acl_list,
1482 {'sw_if_index': sw_if_index,
1483 'count': len(acls),
1484 'n_input': n_input,
1485 'acls': acls},
1486 expected_retval=expected_retval)
1487
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001488 def acl_interface_set_etype_whitelist(self, sw_if_index,
1489 n_input, whitelist,
1490 expected_retval=0):
1491 return self.api(self.papi.acl_interface_set_etype_whitelist,
1492 {'sw_if_index': sw_if_index,
1493 'count': len(whitelist),
1494 'n_input': n_input,
1495 'whitelist': whitelist},
1496 expected_retval=expected_retval)
1497
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001498 def acl_interface_add_del(self,
1499 sw_if_index,
1500 acl_index,
1501 is_add=1):
1502 """ Add/Delete ACL to/from interface
1503
1504 :param sw_if_index:
1505 :param acl_index:
1506 :param is_add: (Default value = 1)
1507 """
1508
1509 return self.api(self.papi.acl_interface_add_del,
1510 {'is_add': is_add,
1511 'is_input': 1,
1512 'sw_if_index': sw_if_index,
1513 'acl_index': acl_index})
1514
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001515 def acl_dump(self, acl_index, expected_retval=0):
1516 return self.api(self.papi.acl_dump,
1517 {'acl_index': acl_index},
1518 expected_retval=expected_retval)
1519
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001520 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1521 expected_retval=0):
1522 return self.api(self.papi.acl_interface_list_dump,
1523 {'sw_if_index': sw_if_index},
1524 expected_retval=expected_retval)
1525
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001526 def macip_acl_add(self, rules, tag=""):
1527 """ Add MACIP acl
1528
1529 :param rules: list of rules for given acl
1530 :param tag: acl tag
1531 """
1532
1533 return self.api(self.papi.macip_acl_add,
1534 {'r': rules,
1535 'count': len(rules),
1536 'tag': tag})
1537
Pavel Kotucek932f7412017-09-07 14:44:52 +02001538 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1539 """ Add MACIP acl
1540
1541 :param rules: list of rules for given acl
1542 :param tag: acl tag
1543 """
1544
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001545 return self.api(self.papi.macip_acl_add_replace,
1546 {'acl_index': acl_index,
1547 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001548 'count': len(rules),
1549 'tag': tag})
1550
Pavel Kotucek932f7412017-09-07 14:44:52 +02001551 def macip_acl_interface_add_del(self,
1552 sw_if_index,
1553 acl_index,
1554 is_add=1):
1555 """ Add MACIP acl to interface
1556
1557 :param sw_if_index:
1558 :param acl_index:
1559 :param is_add: (Default value = 1)
1560 """
1561
1562 return self.api(self.papi.macip_acl_interface_add_del,
1563 {'is_add': is_add,
1564 'sw_if_index': sw_if_index,
1565 'acl_index': acl_index})
1566
Pavel Kotucek932f7412017-09-07 14:44:52 +02001567 def macip_acl_dump(self, acl_index=4294967295):
1568 """ Return MACIP acl dump
1569 """
1570
1571 return self.api(
1572 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001573
1574 def policer_add_del(self,
1575 name,
1576 cir,
1577 eir,
1578 cb,
1579 eb,
1580 is_add=1,
1581 rate_type=0,
1582 round_type=0,
1583 ptype=0,
1584 color_aware=0,
1585 conform_action_type=1,
1586 conform_dscp=0,
1587 exceed_action_type=0,
1588 exceed_dscp=0,
1589 violate_action_type=0,
1590 violate_dscp=0):
1591 return self.api(self.papi.policer_add_del,
1592 {'name': name,
1593 'cir': cir,
1594 'eir': eir,
1595 'cb': cb,
1596 'eb': eb,
1597 'is_add': is_add,
1598 'rate_type': rate_type,
1599 'round_type': round_type,
1600 'type': ptype,
1601 'color_aware': color_aware,
1602 'conform_action_type': conform_action_type,
1603 'conform_dscp': conform_dscp,
1604 'exceed_action_type': exceed_action_type,
1605 'exceed_dscp': exceed_dscp,
1606 'violate_action_type': violate_action_type,
1607 'violate_dscp': violate_dscp})
1608
1609 def ip_punt_police(self,
1610 policer_index,
1611 is_ip6=0,
1612 is_add=1):
1613 return self.api(self.papi.ip_punt_police,
1614 {'policer_index': policer_index,
1615 'is_add': is_add,
1616 'is_ip6': is_ip6})
1617
1618 def ip_punt_redirect(self,
1619 rx_sw_if_index,
1620 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001621 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001622 is_add=1):
1623 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001624 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1625 'tx_sw_if_index': tx_sw_if_index,
1626 'nh': address},
1627 'is_add': is_add})
1628
1629 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1630 return self.api(self.papi.ip_punt_redirect_dump,
1631 {'sw_if_index': sw_if_index,
1632 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001633
1634 def bier_table_add_del(self,
1635 bti,
1636 mpls_label,
1637 is_add=1):
1638 """ BIER Table add/del """
1639 return self.api(
1640 self.papi.bier_table_add_del,
1641 {'bt_tbl_id': {"bt_set": bti.set_id,
1642 "bt_sub_domain": bti.sub_domain_id,
1643 "bt_hdr_len_id": bti.hdr_len_id},
1644 'bt_label': mpls_label,
1645 'bt_is_add': is_add})
1646
1647 def bier_table_dump(self):
1648 return self.api(self.papi.bier_table_dump, {})
1649
1650 def bier_route_add_del(self,
1651 bti,
1652 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001653 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001654 is_add=1,
1655 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001656 """ BIER Route add/del """
1657 return self.api(
1658 self.papi.bier_route_add_del,
1659 {'br_tbl_id': {"bt_set": bti.set_id,
1660 "bt_sub_domain": bti.sub_domain_id,
1661 "bt_hdr_len_id": bti.hdr_len_id},
1662 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08001663 'br_n_paths': len(paths),
1664 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001665 'br_is_add': is_add,
1666 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001667
1668 def bier_route_dump(self, bti):
1669 return self.api(
1670 self.papi.bier_route_dump,
1671 {'br_tbl_id': {"bt_set": bti.set_id,
1672 "bt_sub_domain": bti.sub_domain_id,
1673 "bt_hdr_len_id": bti.hdr_len_id}})
1674
1675 def bier_imp_add(self,
1676 bti,
1677 src,
1678 ibytes,
1679 is_add=1):
1680 """ BIER Imposition Add """
1681 return self.api(
1682 self.papi.bier_imp_add,
1683 {'bi_tbl_id': {"bt_set": bti.set_id,
1684 "bt_sub_domain": bti.sub_domain_id,
1685 "bt_hdr_len_id": bti.hdr_len_id},
1686 'bi_src': src,
1687 'bi_n_bytes': len(ibytes),
1688 'bi_bytes': ibytes})
1689
1690 def bier_imp_del(self, bi_index):
1691 """ BIER Imposition del """
1692 return self.api(
1693 self.papi.bier_imp_del,
1694 {'bi_index': bi_index})
1695
1696 def bier_imp_dump(self):
1697 return self.api(self.papi.bier_imp_dump, {})
1698
1699 def bier_disp_table_add_del(self,
1700 bdti,
1701 is_add=1):
1702 """ BIER Disposition Table add/del """
1703 return self.api(
1704 self.papi.bier_disp_table_add_del,
1705 {'bdt_tbl_id': bdti,
1706 'bdt_is_add': is_add})
1707
1708 def bier_disp_table_dump(self):
1709 return self.api(self.papi.bier_disp_table_dump, {})
1710
1711 def bier_disp_entry_add_del(self,
1712 bdti,
1713 bp,
1714 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001715 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001716 next_hop,
1717 next_hop_tbl_id=0,
1718 next_hop_rpf_id=~0,
1719 next_hop_is_ip4=1,
1720 is_add=1):
1721 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001722 lstack = []
1723 while (len(lstack) < 16):
1724 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001725 return self.api(
1726 self.papi.bier_disp_entry_add_del,
1727 {'bde_tbl_id': bdti,
1728 'bde_bp': bp,
1729 'bde_payload_proto': payload_proto,
1730 'bde_n_paths': 1,
1731 'bde_paths': [{'next_hop': next_hop,
1732 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08001733 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001734 'rpf_id': next_hop_rpf_id,
1735 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001736 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001737 'bde_is_add': is_add})
1738
1739 def bier_disp_entry_dump(self, bdti):
1740 return self.api(
1741 self.papi.bier_disp_entry_dump,
1742 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001743
Florin Coras3ea6ce22017-12-11 09:09:05 -08001744 def session_enable_disable(self, is_enabled):
1745 return self.api(
1746 self.papi.session_enable_disable,
1747 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001748
1749 def ipsec_spd_add_del(self, spd_id, is_add=1):
1750 """ SPD add/del - Wrapper to add or del ipsec SPD
1751 Sample CLI : 'ipsec spd add 1'
1752
1753 :param spd_id - SPD ID to be created in the vpp . mandatory
1754 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1755 optional
1756 :returns: reply from the API
1757 """
1758 return self.api(
1759 self.papi.ipsec_spd_add_del, {
1760 'spd_id': spd_id, 'is_add': is_add})
1761
Neale Ranns311124e2019-01-24 04:52:25 -08001762 def ipsec_spds_dump(self):
1763 return self.api(self.papi.ipsec_spds_dump, {})
1764
“mystarrocks”23f0c452017-12-11 07:11:51 -08001765 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1766 """ IPSEC interface SPD add/del - \
1767 Wrapper to associate/disassociate SPD to interface in VPP
1768 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1769
1770 :param spd_id - SPD ID to associate with the interface . mandatory
1771 :param sw_if_index - Interface Index which needs to ipsec \
1772 association mandatory
1773 :param is_add - add(1) or del(0) association with interface \
1774 (Default 1 - add) . optional
1775 :returns: reply from the API
1776 """
1777 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001778 self.papi.ipsec_interface_add_del_spd,
1779 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001780
Neale Ranns311124e2019-01-24 04:52:25 -08001781 def ipsec_spd_interface_dump(self, spd_index=None):
1782 return self.api(self.papi.ipsec_spd_interface_dump,
1783 {'spd_index': spd_index if spd_index else 0,
1784 'spd_index_valid': 1 if spd_index else 0})
1785
Neale Ranns17dcec02019-01-09 21:22:20 -08001786 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001787 sad_id,
1788 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001789 integrity_algorithm,
1790 integrity_key,
1791 crypto_algorithm,
1792 crypto_key,
1793 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001794 tunnel_src_address='',
1795 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001796 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001797 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001798 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001799 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001800 :param sad_id: security association ID
1801 :param spi: security param index of the SA in decimal
1802 :param integrity_algorithm:
1803 :param integrity_key:
1804 :param crypto_algorithm:
1805 :param crypto_key:
1806 :param protocol: AH(0) or ESP(1) protocol
1807 :param tunnel_src_address: tunnel mode outer src address
1808 :param tunnel_dst_address: tunnel mode outer dst address
1809 :param is_add:
1810 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001811 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1812 crypto and ipsec algorithms
1813 """
1814 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001815 self.papi.ipsec_sad_entry_add_del,
1816 {
1817 'is_add': is_add,
1818 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001819 {
1820 'sad_id': sad_id,
1821 'spi': spi,
1822 'tunnel_src': tunnel_src_address,
1823 'tunnel_dst': tunnel_dst_address,
1824 'protocol': protocol,
1825 'integrity_algorithm': integrity_algorithm,
1826 'integrity_key': {
1827 'length': len(integrity_key),
1828 'data': integrity_key,
1829 },
1830 'crypto_algorithm': crypto_algorithm,
1831 'crypto_key': {
1832 'length': len(crypto_key),
1833 'data': crypto_key,
1834 },
1835 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001836 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001837 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001838 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001839
Neale Ranns311124e2019-01-24 04:52:25 -08001840 def ipsec_sa_dump(self, sa_id=None):
1841 return self.api(self.papi.ipsec_sa_dump,
1842 {'sa_id': sa_id if sa_id else 0xffffffff})
1843
Neale Ranns17dcec02019-01-09 21:22:20 -08001844 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001845 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001846 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001847 local_address_start,
1848 local_address_stop,
1849 remote_address_start,
1850 remote_address_stop,
1851 local_port_start=0,
1852 local_port_stop=65535,
1853 remote_port_start=0,
1854 remote_port_stop=65535,
1855 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001856 policy=0,
1857 priority=100,
1858 is_outbound=1,
1859 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001860 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001861 is_ip_any=0):
1862 """ IPSEC policy SPD add/del -
1863 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001864 :param spd_id: SPD ID for the policy
1865 :param local_address_start: local-ip-range start address
1866 :param local_address_stop : local-ip-range stop address
1867 :param remote_address_start: remote-ip-range start address
1868 :param remote_address_stop : remote-ip-range stop address
1869 :param local_port_start: (Default value = 0)
1870 :param local_port_stop: (Default value = 65535)
1871 :param remote_port_start: (Default value = 0)
1872 :param remote_port_stop: (Default value = 65535)
1873 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1874 :param sa_id: Security Association ID for mapping it to SPD
1875 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1876 (Default value = 0)
1877 :param priority: value for the spd action (Default value = 100)
1878 :param is_outbound: flag for inbound(0) or outbound(1)
1879 (Default value = 1)
1880 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001881 """
1882 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001883 self.papi.ipsec_spd_entry_add_del,
1884 {
1885 'is_add': is_add,
1886 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001887 {
1888 'spd_id': spd_id,
1889 'sa_id': sa_id,
1890 'local_address_start': local_address_start,
1891 'local_address_stop': local_address_stop,
1892 'remote_address_start': remote_address_start,
1893 'remote_address_stop': remote_address_stop,
1894 'local_port_start': local_port_start,
1895 'local_port_stop': local_port_stop,
1896 'remote_port_start': remote_port_start,
1897 'remote_port_stop': remote_port_stop,
1898 'protocol': protocol,
1899 'policy': policy,
1900 'priority': priority,
1901 'is_outbound': is_outbound,
1902 'is_ip_any': is_ip_any
1903 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001904 })
Florin Corasb795bd02017-12-14 11:30:48 -08001905
Neale Ranns311124e2019-01-24 04:52:25 -08001906 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1907 return self.api(self.papi.ipsec_spd_dump,
1908 {'spd_id': spd_id,
1909 'sa_id': sa_id})
1910
Klement Sekera31da2e32018-06-24 22:49:55 +02001911 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1912 remote_spi, crypto_alg, local_crypto_key,
1913 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001914 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02001915 anti_replay=1, renumber=0, show_instance=0):
1916 return self.api(
1917 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001918 {
1919 'local_ip': local_ip,
1920 'remote_ip': remote_ip,
1921 'local_spi': local_spi,
1922 'remote_spi': remote_spi,
1923 'crypto_alg': crypto_alg,
1924 'local_crypto_key_len': len(local_crypto_key),
1925 'local_crypto_key': local_crypto_key,
1926 'remote_crypto_key_len': len(remote_crypto_key),
1927 'remote_crypto_key': remote_crypto_key,
1928 'integ_alg': integ_alg,
1929 'local_integ_key_len': len(local_integ_key),
1930 'local_integ_key': local_integ_key,
1931 'remote_integ_key_len': len(remote_integ_key),
1932 'remote_integ_key': remote_integ_key,
1933 'is_add': is_add,
1934 'esn': esn,
1935 'anti_replay': anti_replay,
1936 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001937 'show_instance': show_instance,
1938 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001939 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001940
Neale Rannsf05e7322019-03-29 20:23:58 +00001941 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
1942 sa_out, sa_in, is_add=1):
1943 return self.api(self.papi.ipsec_gre_tunnel_add_del,
1944 {
1945 'is_add': is_add,
1946 'tunnel': {
1947 'src': local_ip,
1948 'dst': remote_ip,
1949 'local_sa_id': sa_out,
1950 'remote_sa_id': sa_in
1951 }
1952 })
1953
Klement Sekerab4d30532018-11-08 13:00:02 +01001954 def ipsec_select_backend(self, protocol, index):
1955 return self.api(self.papi.ipsec_select_backend,
1956 {'protocol': protocol, 'index': index})
1957
1958 def ipsec_backend_dump(self):
1959 return self.api(self.papi.ipsec_backend_dump, {})
1960
Ole Troane1ade682019-03-04 23:55:43 +01001961 def app_namespace_add_del(self,
1962 namespace_id,
1963 ip4_fib_id=0,
1964 ip6_fib_id=0,
1965 sw_if_index=0xFFFFFFFF,
1966 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001967 return self.api(
1968 self.papi.app_namespace_add_del,
1969 {'secret': secret,
1970 'sw_if_index': sw_if_index,
1971 'ip4_fib_id': ip4_fib_id,
1972 'ip6_fib_id': ip6_fib_id,
1973 'namespace_id': namespace_id,
1974 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001975
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001976 def punt_socket_register(self, port, pathname, protocol=0x11,
1977 header_version=1, is_ip4=1):
1978 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001979 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001980 {'header_version': header_version,
1981 'punt': {'ipv': is_ip4,
1982 'l4_protocol': protocol,
1983 'l4_port': port},
1984 'pathname': pathname})
1985
1986 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
1987 """ Unregister punt socket """
1988 return self.api(self.papi.punt_socket_deregister,
1989 {'punt': {'ipv': is_ip4,
1990 'l4_protocol': protocol,
1991 'l4_port': port}})
1992
1993 def punt_socket_dump(self, is_ip6=1):
1994 """ Dump punt socket"""
1995 return self.api(self.papi.punt_socket_dump,
1996 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02001997
Neale Ranns4ba67722019-02-28 11:11:39 +00001998 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001999 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002000 """ GBP endpoint Add """
2001 return self.api(self.papi.gbp_endpoint_add,
2002 {'endpoint': {
2003 'sw_if_index': sw_if_index,
2004 'ips': ips,
2005 'n_ips': len(ips),
2006 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002007 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002008 'flags': flags,
2009 'tun': {
2010 'src': tun_src,
2011 'dst': tun_dst,
2012 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002013
2014 def gbp_endpoint_del(self, handle):
2015 """ GBP endpoint Del """
2016 return self.api(self.papi.gbp_endpoint_del,
2017 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002018
2019 def gbp_endpoint_dump(self):
2020 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002021 return self.api(self.papi.gbp_endpoint_dump,
2022 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002023
Neale Ranns4ba67722019-02-28 11:11:39 +00002024 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002025 rd, uplink_sw_if_index,
2026 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002027 """ GBP endpoint group Add """
2028 return self.api(self.papi.gbp_endpoint_group_add,
2029 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002030 {
2031 'uplink_sw_if_index': uplink_sw_if_index,
2032 'bd_id': bd,
2033 'rd_id': rd,
2034 'vnid': vnid,
2035 'sclass': sclass,
2036 'retention': retention
2037 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002038
Neale Ranns4ba67722019-02-28 11:11:39 +00002039 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002040 """ GBP endpoint group Del """
2041 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002042 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002043
Neale Rannsc29c0af2018-11-07 04:21:12 -08002044 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002045 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002046 uu_fwd_sw_if_index,
2047 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002048 """ GBP bridge-domain Add """
2049 return self.api(self.papi.gbp_bridge_domain_add,
2050 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002051 {
2052 'flags': flags,
2053 'bvi_sw_if_index': bvi_sw_if_index,
2054 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2055 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2056 'bd_id': bd_id
2057 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002058
2059 def gbp_bridge_domain_del(self, bd_id):
2060 """ GBP bridge-domain Del """
2061 return self.api(self.papi.gbp_bridge_domain_del,
2062 {'bd_id': bd_id})
2063
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002064 def gbp_route_domain_add(self, rd_id,
2065 ip4_table_id,
2066 ip6_table_id,
2067 ip4_uu_sw_if_index,
2068 ip6_uu_sw_if_index):
2069 """ GBP route-domain Add """
2070 return self.api(self.papi.gbp_route_domain_add,
2071 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002072 {
2073 'ip4_table_id': ip4_table_id,
2074 'ip6_table_id': ip6_table_id,
2075 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2076 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2077 'rd_id': rd_id
2078 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002079
2080 def gbp_route_domain_del(self, rd_id):
2081 """ GBP route-domain Del """
2082 return self.api(self.papi.gbp_route_domain_del,
2083 {'rd_id': rd_id})
2084
Neale Ranns4ba67722019-02-28 11:11:39 +00002085 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002086 """ GBP recirc Add/Del """
2087 return self.api(self.papi.gbp_recirc_add_del,
2088 {'is_add': is_add,
2089 'recirc': {
2090 'is_ext': is_ext,
2091 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002092 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002093
2094 def gbp_recirc_dump(self):
2095 """ GBP recirc Dump """
2096 return self.api(self.papi.gbp_recirc_dump, {})
2097
Neale Rannsb6a47952018-11-21 05:44:35 -08002098 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2099 """ GBP recirc Add/Del """
2100 return self.api(self.papi.gbp_ext_itf_add_del,
2101 {'is_add': is_add,
2102 'ext_itf': {
2103 'sw_if_index': sw_if_index,
2104 'bd_id': bd_id,
2105 'rd_id': rd_id}})
2106
2107 def gbp_ext_itf_dump(self):
2108 """ GBP recirc Dump """
2109 return self.api(self.papi.gbp_ext_itf_dump, {})
2110
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002111 def gbp_subnet_add_del(self, is_add, rd_id,
2112 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002113 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002114 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002115 """ GBP Subnet Add/Del """
2116 return self.api(self.papi.gbp_subnet_add_del,
2117 {'is_add': is_add,
2118 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002119 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002120 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002121 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002122 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002123 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002124
2125 def gbp_subnet_dump(self):
2126 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002127 return self.api(self.papi.gbp_subnet_dump,
2128 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002129
Neale Ranns4ba67722019-02-28 11:11:39 +00002130 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002131 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002132 """ GBP contract Add/Del """
2133 return self.api(self.papi.gbp_contract_add_del,
2134 {'is_add': is_add,
2135 'contract': {
2136 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002137 'sclass': sclass,
2138 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002139 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002140 'rules': rules,
2141 'n_ether_types': len(allowed_ethertypes),
2142 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002143
2144 def gbp_contract_dump(self):
2145 """ GBP contract Dump """
2146 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002147
Neale Ranns8da9fc62019-03-04 14:08:11 -08002148 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002149 """ GBP VXLAN tunnel add """
2150 return self.api(self.papi.gbp_vxlan_tunnel_add,
2151 {
2152 'tunnel': {
2153 'vni': vni,
2154 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002155 'bd_rd_id': bd_rd_id,
2156 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002157 }
2158 })
2159
2160 def gbp_vxlan_tunnel_del(self, vni):
2161 """ GBP VXLAN tunnel del """
2162 return self.api(self.papi.gbp_vxlan_tunnel_del,
2163 {
2164 'vni': vni,
2165 })
2166
2167 def gbp_vxlan_tunnel_dump(self):
2168 """ GBP VXLAN tunnel add/del """
2169 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2170
Neale Ranns039cbfe2018-02-27 03:45:38 -08002171 def qos_egress_map_update(self, id, outputs):
2172 """ QOS egress map update """
2173 return self.api(self.papi.qos_egress_map_update,
2174 {'map_id': id,
2175 'rows': outputs})
2176
2177 def qos_egress_map_delete(self, id):
2178 """ QOS egress map delete """
2179 return self.api(self.papi.qos_egress_map_delete,
2180 {'map_id': id})
2181
2182 def qos_mark_enable_disable(self, sw_if_index,
2183 output_source,
2184 map_id,
2185 enable):
2186 """ QOS Mark Enable/Disable """
2187 return self.api(self.papi.qos_mark_enable_disable,
2188 {'map_id': map_id,
2189 'sw_if_index': sw_if_index,
2190 'output_source': output_source,
2191 'enable': enable})
2192
Neale Ranns947ea622018-06-07 23:48:20 -07002193 def igmp_enable_disable(self, sw_if_index, enable, host):
2194 """ Enable/disable IGMP on a given interface """
2195 return self.api(self.papi.igmp_enable_disable,
2196 {'enable': enable,
2197 'mode': host,
2198 'sw_if_index': sw_if_index})
2199
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002200 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2201 """ Add/del IGMP proxy device """
2202 return self.api(self.papi.igmp_proxy_device_add_del,
2203 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2204 'add': add})
2205
2206 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2207 """ Add/del interface to/from IGMP proxy device """
2208 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2209 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2210 'add': add})
2211
Neale Ranns947ea622018-06-07 23:48:20 -07002212 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002213 """ Listen for new (S,G) on specified interface
2214
2215 :param enable: add/del
2216 :param sw_if_index: interface sw index
2217 :param saddr: source ip4 addr
2218 :param gaddr: group ip4 addr
2219 """
2220 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002221 {
2222 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002223 {
2224 'filter': filter,
2225 'sw_if_index': sw_if_index,
2226 'n_srcs': len(saddrs),
2227 'saddrs': saddrs,
2228 'gaddr': gaddr
2229 }
Neale Ranns947ea622018-06-07 23:48:20 -07002230 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002231
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002232 def igmp_clear_interface(self, sw_if_index):
2233 """ Remove all (S,G)s from specified interface
2234 doesn't send IGMP report!
2235 """
2236 return self.api(
2237 self.papi.igmp_clear_interface, {
2238 'sw_if_index': sw_if_index})
2239
2240 def want_igmp_events(self, enable=1):
2241 return self.api(self.papi.want_igmp_events, {'enable': enable,
2242 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002243
2244 def bond_create(
2245 self,
2246 mode,
2247 lb,
2248 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002249 mac_address='',
2250 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002251 """
2252 :param mode: mode
2253 :param lb: load balance
2254 :param use_custom_mac: use custom mac
2255 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002256 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002257 """
2258 return self.api(
2259 self.papi.bond_create,
2260 {'mode': mode,
2261 'lb': lb,
2262 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002263 'mac_address': mac_address,
2264 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002265 })
2266
Neale Ranns17ff3c12018-07-04 10:24:24 -07002267 def pipe_delete(self, parent_sw_if_index):
2268 return self.api(self.papi.pipe_delete,
2269 {'parent_sw_if_index': parent_sw_if_index})
2270
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002271 def memif_create(
2272 self,
2273 role,
2274 mode,
2275 rx_queues=None,
2276 tx_queues=None,
2277 _id=None,
2278 socket_id=None,
2279 secret=None,
2280 ring_size=None,
2281 buffer_size=None,
2282 hw_addr=None):
2283 return self.api(self.papi.memif_create,
2284 {'role': role,
2285 'mode': mode,
2286 'rx_queues': rx_queues,
2287 'tx_queues': tx_queues,
2288 'id': _id,
2289 'socket_id': socket_id,
2290 'secret': secret,
2291 'ring_size': ring_size,
2292 'buffer_size': buffer_size,
2293 'hw_addr': hw_addr})
2294
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002295 def svs_table_add_del(self, af, table_id, is_add=1):
2296 return self.api(self.papi.svs_table_add_del,
2297 {
2298 'table_id': table_id,
2299 'is_add': is_add,
2300 'af': af,
2301 })
2302
2303 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2304 return self.api(self.papi.svs_route_add_del,
2305 {
2306 'table_id': table_id,
2307 'source_table_id': src_table_id,
2308 'prefix': prefix,
2309 'is_add': is_add,
2310 })
2311
2312 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2313 return self.api(self.papi.svs_enable_disable,
2314 {
2315 'af': af,
2316 'table_id': table_id,
2317 'sw_if_index': sw_if_index,
2318 'is_enable': is_enable,
2319 })