blob: f9bb470ec1defcbdb88dfc797d4ffe8a711c8704 [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 = {
23 'map_add_domain': {'mtu': 1280},
24 'syslog_set_sender': {'collector_port': 514,
25 'max_msg_size': 480},
26 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
27 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
28 'app_namespace_add_del': {'sw_if_index': 4294967295, },
29 'bd_ip_mac_add_del': {'is_add': 1, },
30 '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_create': {'user_instance': 4294967295, },
39 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010040 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
41 'nbuckets': 2, 'memory_size': 2097152,
42 'next_table_index': 4294967295,
43 'miss_next_index': 4294967295, },
44 'dhcp6_client_enable_disable': {'enable': 1, },
45 'dhcp6_clients_enable_disable': {'enable': 1, },
46 'dhcp6_pd_client_enable_disable': {'enable': 1, },
47 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
48 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
49 'dhcp_proxy_config': {'is_add': 1, },
50 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010051 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
52 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
53 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000054 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010055 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
56 'decap_next_index': 4294967295, },
57 'input_acl_set_interface': {'ip4_table_index': 4294967295,
58 'ip6_table_index': 4294967295,
59 'l2_table_index': 4294967295, },
60 'ip6_add_del_address_using_prefix': {'is_add': 1, },
61 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
62 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
63 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010064 'classify_table_index': 4294967295, 'is_add': 1, },
65 'ip_mroute_add_del': {'is_add': 1, },
66 'ip_neighbor_add_del': {'is_add': 1, },
67 'ip_punt_police': {'is_add': 1, },
68 'ip_punt_redirect': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070069 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010070 'ip_table_add_del': {'is_add': 1, },
71 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010072 'ipsec_interface_add_del_spd': {'is_add': 1, },
73 'ipsec_sad_entry_add_del': {'is_add': 1, },
74 'ipsec_spd_add_del': {'is_add': 1, },
75 'ipsec_spd_dump': {'sa_id': 4294967295, },
76 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
77 'remote_port_stop': 65535, 'priority': 100,
78 'is_outbound': 1,
79 'is_add': 1, },
80 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
81 'l2_emulation': {'enable': 1, },
82 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070083 'lb_conf': {'sticky_buckets_per_core': 4294967295,
84 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +010085 'lisp_add_del_adjacency': {'is_add': 1, },
86 'lisp_add_del_local_eid': {'is_add': 1, },
87 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
88 'lisp_add_del_locator_set': {'is_add': 1, },
89 'lisp_add_del_remote_mapping': {'is_add': 1, },
90 'macip_acl_add_replace': {'acl_index': 4294967295, },
91 'macip_acl_dump': {'acl_index': 4294967295, },
92 'macip_acl_interface_add_del': {'is_add': 1, },
93 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010094 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
95 'mr_next_hop_weight': 1,
96 'mr_next_hop_via_label': 1048576,
97 'mr_is_add': 1,
98 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010099 'mpls_table_add_del': {'is_add': 1, },
100 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
101 'next_hop_weight': 1,
102 'next_hop_via_label': 1048576,
103 'is_add': 1, },
104 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100105 'output_acl_set_interface': {'ip4_table_index': 4294967295,
106 'ip6_table_index': 4294967295,
107 'l2_table_index': 4294967295, },
108 'pppoe_add_del_session': {'is_add': 1, },
109 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
110 'proxy_arp_add_del': {'is_add': 1, },
111 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100112 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
113 'proto': 1, },
114 'set_ipfix_exporter': {'collector_port': 4739, },
115 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
116 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
117 'svs_enable_disable': {'is_enable': 1, },
118 'svs_route_add_del': {'is_add': 1, },
119 'svs_table_add_del': {'is_add': 1, },
120 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700121 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100122 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
123 'pref_lifetime': 4294967295, },
124 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
125 'sw_interface_set_l2_bridge': {'enable': 1, },
126 'sw_interface_set_mpls_enable': {'enable': 1, },
127 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
128 'sw_interface_set_unnumbered': {'is_add': 1, },
129 'sw_interface_span_enable_disable': {'state': 1, },
130 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
131 'decap_next_index': 4294967295,
132 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100133 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
134 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
135 'protocol': 3, },
136 'want_bfd_events': {'enable_disable': 1, },
137 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
138 'want_dhcp6_reply_events': {'enable_disable': 1, },
139 'want_igmp_events': {'enable': 1, },
140 'want_interface_events': {'enable_disable': 1, },
141 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
142 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
143 'want_ip6_ra_events': {'enable_disable': 1, },
144 'want_l2_macs_events': {'enable_disable': 1, },
145}
Ole Troanf159f582019-02-28 20:20:47 +0100146
Matus Fabianb4515b42018-11-19 04:25:32 -0800147
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400148class CliFailedCommandError(Exception):
149 """ cli command failed."""
150
151
152class CliSyntaxError(Exception):
153 """ cli command had a syntax error."""
154
155
Klement Sekera73884482017-02-23 09:26:30 +0100156class UnexpectedApiReturnValueError(Exception):
157 """ exception raised when the API return value is unexpected """
158 pass
159
160
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161class VppPapiProvider(object):
162 """VPP-api provider using vpp-papi
163
164 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200165 """
166
Klement Sekerae0545ef2017-01-25 08:00:40 +0100167 _zero, _negative = range(2)
168
Klement Sekera611864f2018-09-26 11:19:00 +0200169 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800170 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200171 self.name = name
172 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100173 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100174 self._expect_api_retval = self._zero
175 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100176
Paul Vinciguerra19542292019-03-17 17:34:46 -0700177 # install_dir is a class attribute. We need to set it before
178 # calling the constructor.
179 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800180
Ole Troan4ff09ae2019-04-15 11:27:22 +0200181 use_socket = False
182 try:
183 if os.environ['SOCKET'] == '1':
184 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400185 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200186 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700187
188 self.vpp = VPPApiClient(logger=test_class.logger,
189 read_timeout=read_timeout,
190 use_socket=use_socket,
191 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100192 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200193
Klement Sekerae0545ef2017-01-25 08:00:40 +0100194 def __enter__(self):
195 return self
196
Klement Sekera7d6afb32018-11-08 11:52:04 +0100197 def assert_negative_api_retval(self):
198 """ Expect API failure - used with with, e.g.:
199 with self.vapi.assert_negative_api_retval():
200 self.vapi.<api call expected to fail>
201 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100202 self._expect_stack.append(self._expect_api_retval)
203 self._expect_api_retval = self._negative
204 return self
205
Klement Sekera7d6afb32018-11-08 11:52:04 +0100206 def assert_zero_api_retval(self):
207 """ Expect API success - used with with, e.g.:
208 with self.vapi.assert_negative_api_retval():
209 self.vapi.<api call expected to succeed>
210
211 note: this is useful only inside another with block
212 as success is the default expected value
213 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100214 self._expect_stack.append(self._expect_api_retval)
215 self._expect_api_retval = self._zero
216 return self
217
218 def __exit__(self, exc_type, exc_value, traceback):
219 self._expect_api_retval = self._expect_stack.pop()
220
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221 def register_hook(self, hook):
222 """Replace hook registration with new hook
223
224 :param hook:
225
226 """
227 self.hook = hook
228
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200229 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100230 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200231 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100232 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200233 return e
234
235 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100236 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100237 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100238 self.test_class.logger.debug("Expecting event '%s' within %ss",
239 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300240 else:
241 self.test_class.logger.debug("Expecting event within %ss",
242 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100243 if self._events:
244 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200245 limit = time.time() + timeout
246 while time.time() < limit:
247 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100248 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200249 if name and type(e).__name__ != name:
250 raise Exception(
251 "Unexpected event received: %s, expected: %s" %
252 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100253 self.test_class.logger.debug("Returning event %s:%s" %
254 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200255 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700256 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200257 raise Exception("Event did not occur within timeout")
258
259 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100260 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200261 # FIXME use the name instead of relying on type(e).__name__ ?
262 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100263 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200264 self._events.append(event)
265
Ole Troanf159f582019-02-28 20:20:47 +0100266 def factory(self, name, apifn):
267 def f(*a, **ka):
268 fields = apifn._func.msg.fields
269
270 # add positional and kw arguments
271 d = ka
272 for i, o in enumerate(fields[3:]):
273 try:
274 d[o] = a[i]
275 except:
276 break
277
278 # Default override
279 if name in defaultmapping:
280 for k, v in iteritems(defaultmapping[name]):
281 if k in d:
282 continue
283 d[k] = v
284 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100285
Ole Troanf159f582019-02-28 20:20:47 +0100286 return f
287
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800288 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100289 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800290 method = super(VppPapiProvider, self).__getattribute__(name)
291 except AttributeError:
292 method = self.factory(name, getattr(self.papi, name))
293 # lazily load the method so we don't need to call factory
294 # again for this name.
295 setattr(self, name, method)
296 return method
Ole Troanf159f582019-02-28 20:20:47 +0100297
Klement Sekeraf62ae122016-10-11 11:47:09 +0200298 def connect(self):
299 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100300 self.vpp.connect(self.name, self.shm_prefix)
301 self.papi = self.vpp.api
302 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200303
304 def disconnect(self):
305 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100306 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200307
308 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100309 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200310 Call the appropriate hooks before and after the API call
311
312 :param api_fn: API function to call
313 :param api_args: tuple of API function arguments
314 :param expected_retval: Expected return value (Default value = 0)
315 :returns: reply from the API
316
317 """
318 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100319 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100320 if self._expect_api_retval == self._negative:
321 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100322 msg = "API call passed unexpectedly: expected negative " \
323 "return value instead of %d in %s" % \
324 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100325 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100326 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100327 elif self._expect_api_retval == self._zero:
328 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100329 msg = "API call failed, expected %d return value instead " \
330 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400331 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100332 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100333 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100334 else:
335 raise Exception("Internal error, unexpected value for "
336 "self._expect_api_retval %s" %
337 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200338 self.hook.after_api(api_fn.__name__, api_args)
339 return reply
340
341 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100342 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200343
344 :param cli: CLI to execute
345 :returns: CLI output
346
347 """
348 self.hook.before_cli(cli)
349 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100350 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200351 self.hook.after_cli(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400352 if r.retval == -156:
353 raise CliSyntaxError(r.reply)
354 if r.retval != 0:
355 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200356 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100357 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200358
Jan49c0fca2016-10-26 15:44:27 +0200359 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100360 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200361
362 :param cli: CLI to execute
363 :returns: CLI output
364 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600365 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200366
Neale Ranns37029302018-08-10 05:30:06 -0700367 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300368 return self.api(self.papi.want_ip4_arp_events,
369 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700370 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300371 'pid': os.getpid(), })
372
Neale Ranns37029302018-08-10 05:30:06 -0700373 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300374 return self.api(self.papi.want_ip6_nd_events,
375 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700376 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300377 'pid': os.getpid(), })
378
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100379 def want_ip6_ra_events(self, enable_disable=1):
380 return self.api(self.papi.want_ip6_ra_events,
381 {'enable_disable': enable_disable,
382 'pid': os.getpid(), })
383
384 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
385 mrc=0, mrd=0):
386 return self.api(self.papi.ip6nd_send_router_solicitation,
387 {'irt': irt,
388 'mrt': mrt,
389 'mrc': mrc,
390 'mrd': mrd,
391 'sw_if_index': sw_if_index})
392
Juraj Slobodab3f90502018-10-04 15:15:16 +0200393 def want_interface_events(self, enable_disable=1):
394 return self.api(self.papi.want_interface_events,
395 {'enable_disable': enable_disable,
396 'pid': os.getpid(), })
397
Ole Troane1ade682019-03-04 23:55:43 +0100398 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
399 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300400 return self.api(self.papi.want_l2_macs_events,
401 {'enable_disable': enable_disable,
402 'scan_delay': scan_delay,
403 'max_macs_in_event': max_macs_in_event,
404 'learn_limit': learn_limit,
405 'pid': os.getpid(), })
406
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200407 def want_dhcp6_reply_events(self, enable_disable=1):
408 return self.api(self.papi.want_dhcp6_reply_events,
409 {'enable_disable': enable_disable,
410 'pid': os.getpid()})
411
Juraj Sloboda81119e82018-05-25 14:02:20 +0200412 def want_dhcp6_pd_reply_events(self, enable_disable=1):
413 return self.api(self.papi.want_dhcp6_pd_reply_events,
414 {'enable_disable': enable_disable,
415 'pid': os.getpid()})
416
Juraj Sloboda81119e82018-05-25 14:02:20 +0200417 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
418 prefixes, server_index=0xFFFFFFFF,
419 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
420 ):
421 return self.api(self.papi.dhcp6_pd_send_client_message,
422 {'sw_if_index': sw_if_index,
423 'server_index': server_index,
424 'irt': irt,
425 'mrt': mrt,
426 'mrc': mrc,
427 'mrd': mrd,
428 'stop': stop,
429 'msg_type': msg_type,
430 'T1': T1,
431 'T2': T2,
432 'n_prefixes': len(prefixes),
433 'prefixes': prefixes})
434
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200435 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
436 enable=1):
437 return self.api(self.papi.dhcp6_client_enable_disable,
438 {'sw_if_index': sw_if_index,
439 'enable': enable})
440
Juraj Sloboda81119e82018-05-25 14:02:20 +0200441 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
442 enable=1):
443 return self.api(self.papi.dhcp6_pd_client_enable_disable,
444 {'sw_if_index': sw_if_index,
445 'prefix_group': prefix_group,
446 'enable': enable})
447
448 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
449 prefix_length, prefix_group,
450 is_add=1):
451 return self.api(self.papi.ip6_add_del_address_using_prefix,
452 {'sw_if_index': sw_if_index,
453 'prefix_group': prefix_group,
454 'address': address,
455 'prefix_length': prefix_length,
456 'is_add': is_add})
457
Neale Rannsc819fc62018-02-16 02:44:05 -0800458 def sw_interface_set_mac_address(self, sw_if_index, mac):
459 return self.api(self.papi.sw_interface_set_mac_address,
460 {'sw_if_index': sw_if_index,
461 'mac_address': mac})
462
Ole Troane1ade682019-03-04 23:55:43 +0100463 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200464 """Create p2p ethernet subinterface
465
466 :param sw_if_index: main (parent) interface
467 :param remote_mac: client (remote) mac address
468
469 """
470 return self.api(
471 self.papi.p2p_ethernet_add,
472 {'parent_if_index': sw_if_index,
473 'remote_mac': remote_mac,
474 'subif_id': subif_id})
475
Ole Troane1ade682019-03-04 23:55:43 +0100476 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200477 """Delete p2p ethernet subinterface
478
479 :param sw_if_index: main (parent) interface
480 :param remote_mac: client (remote) mac address
481
482 """
483 return self.api(
484 self.papi.p2p_ethernet_del,
485 {'parent_if_index': sw_if_index,
486 'remote_mac': remote_mac})
487
Klement Sekeraf62ae122016-10-11 11:47:09 +0200488 def create_vlan_subif(self, sw_if_index, vlan):
489 """
490
491 :param vlan:
492 :param sw_if_index:
493
494 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100495 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200496 {'sw_if_index': sw_if_index,
497 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200498
Matej Klotton0178d522016-11-04 11:11:44 +0100499 def create_loopback(self, mac=''):
500 """
501
502 :param mac: (Optional)
503 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100504 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200505 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100506
Neale Ranns097fa662018-05-01 05:17:55 -0700507 def ip_table_add_del(self,
508 table_id,
509 is_add=1,
510 is_ipv6=0):
511 """
512
513 :param table_id
514 :param is_add: (Default value = 1)
515 :param is_ipv6: (Default value = 0)
516
517 """
518
519 return self.api(
520 self.papi.ip_table_add_del,
521 {'table':
522 {
523 'table_id': table_id,
524 'is_ip6': is_ipv6
525 },
526 'is_add': is_add})
527
528 def ip_table_dump(self):
529 return self.api(self.papi.ip_table_dump, {})
530
531 def ip_route_dump(self, table_id, is_ip6=False):
532 return self.api(self.papi.ip_route_dump,
533 {'table': {
534 'table_id': table_id,
535 'is_ip6': is_ip6
536 }})
537
Matej Klotton0178d522016-11-04 11:11:44 +0100538 def ip_neighbor_add_del(self,
539 sw_if_index,
540 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700541 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100542 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700543 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100544 """ Add neighbor MAC to IPv4 or IPv6 address.
545
546 :param sw_if_index:
547 :param mac_address:
548 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100549 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700550 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100551 """
Matej Klotton0178d522016-11-04 11:11:44 +0100552 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100553 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700554 {
555 'is_add': is_add,
556 'neighbor': {
557 'sw_if_index': sw_if_index,
558 'flags': flags,
559 'mac_address': mac_address,
560 'ip_address': ip_address
561 }
562 }
Matej Klotton0178d522016-11-04 11:11:44 +0100563 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100564
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800565 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700566 low,
567 hi,
568 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800569 is_add=1):
570 """ Config Proxy Arp Range.
571
572 :param low_address: Start address in the rnage to Proxy for
573 :param hi_address: End address in the rnage to Proxy for
574 :param vrf_id: The VRF/table in which to proxy
575 """
576
577 return self.api(
578 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700579 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100580 {
581 'table_id': table_id,
582 'low': low,
583 'hi': hi,
584 },
585 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800586
587 def proxy_arp_intfc_enable_disable(self,
588 sw_if_index,
589 is_enable=1):
590 """ Enable/Disable an interface for proxy ARP requests
591
592 :param sw_if_index: Interface
593 :param enable_disable: Enable/Disable
594 """
595
596 return self.api(
597 self.papi.proxy_arp_intfc_enable_disable,
598 {'sw_if_index': sw_if_index,
599 'enable_disable': is_enable
600 }
601 )
602
Neale Ranns5a8844b2019-04-16 07:15:35 +0000603 def gre_tunnel_add_del(self,
604 src,
605 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000606 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500607 tunnel_type=0,
608 instance=0xFFFFFFFF,
609 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000610 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000611 """ Add a GRE tunnel
612
613 :param src_address:
614 :param dst_address:
615 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500616 :param tunnel_type: (Default value = 0)
617 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700618 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000619 :param is_add: (Default value = 1)
620 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000621 """
622
623 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000624 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200625 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000626 'tunnel':
627 {
628 'type': tunnel_type,
629 'instance': instance,
630 'src': src,
631 'dst': dst,
632 'outer_fib_id': outer_fib_id,
633 'session_id': session_id}
634 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000635 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000636
Neale Rannsd0df49f2018-08-08 01:06:40 -0700637 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700638 src_ip,
639 dst_ip,
640 src_port,
641 dst_port,
642 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800643 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800644 :param src_ip:
645 :param dst_ip:
646 :param src_port:
647 :param dst_port:
648 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800649 """
650
651 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700652 self.papi.udp_encap_add,
653 {
654 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700655 'src_ip': src_ip,
656 'dst_ip': dst_ip,
657 'src_port': src_port,
658 'dst_port': dst_port,
659 'table_id': table_id
660 }
661 })
662
Neale Ranns097fa662018-05-01 05:17:55 -0700663 def udp_encap_del(self, id):
664 return self.api(self.papi.udp_encap_del, {'id': id})
665
666 def udp_encap_dump(self):
667 return self.api(self.papi.udp_encap_dump, {})
668
669 def want_udp_encap_stats(self, enable=1):
670 return self.api(self.papi.want_udp_encap_stats,
671 {'enable': enable,
672 'pid': os.getpid()})
673
674 def mpls_route_dump(self, table_id):
675 return self.api(self.papi.mpls_route_dump,
676 {'table': {
677 'mt_table_id': table_id
678 }})
679
680 def mpls_table_dump(self):
681 return self.api(self.papi.mpls_table_dump, {})
682
Neale Ranns15002542017-09-10 04:39:11 -0700683 def mpls_table_add_del(
684 self,
685 table_id,
686 is_add=1):
687 """
688
689 :param table_id
690 :param is_add: (Default value = 1)
691
692 """
693
694 return self.api(
695 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700696 {'mt_table':
697 {
698 'mt_table_id': table_id,
699 },
Neale Ranns15002542017-09-10 04:39:11 -0700700 'mt_is_add': is_add})
701
Neale Ranns097fa662018-05-01 05:17:55 -0700702 def mpls_route_add_del(self,
703 table_id,
704 label,
705 eos,
706 eos_proto,
707 is_multicast,
708 paths,
709 is_add,
710 is_multipath):
711 """ MPLS Route add/del """
712 return self.api(
713 self.papi.mpls_route_add_del,
714 {'mr_route':
715 {
716 'mr_table_id': table_id,
717 'mr_label': label,
718 'mr_eos': eos,
719 'mr_eos_proto': eos_proto,
720 'mr_is_multicast': is_multicast,
721 'mr_n_paths': len(paths),
722 'mr_paths': paths,
723 },
724 'mr_is_add': is_add,
725 'mr_is_multipath': is_multipath})
726
Neale Rannsad422ed2016-11-02 14:20:04 +0000727 def mpls_ip_bind_unbind(
728 self,
729 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700730 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000731 table_id=0,
732 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000733 is_bind=1):
734 """
735 """
736 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100737 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200738 {'mb_mpls_table_id': table_id,
739 'mb_label': label,
740 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200741 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700742 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000743
744 def mpls_tunnel_add_del(
745 self,
746 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700747 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000748 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800749 l2_only=0,
750 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000751 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000752 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000753 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100754 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700755 {'mt_is_add': is_add,
756 'mt_tunnel':
757 {
758 'mt_sw_if_index': tun_sw_if_index,
759 'mt_l2_only': l2_only,
760 'mt_is_multicast': is_multicast,
761 'mt_n_paths': len(paths),
762 'mt_paths': paths,
763 }})
Matus Fabiande886752016-12-07 03:38:19 -0800764
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200765 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +0100766 detect_mult, local_addr, peer_addr, is_ipv6=0,
767 bfd_key_id=None, conf_key_id=None):
768 if bfd_key_id is None:
769 return self.api(self.papi.bfd_udp_add,
770 {
771 'sw_if_index': sw_if_index,
772 'desired_min_tx': desired_min_tx,
773 'required_min_rx': required_min_rx,
774 'local_addr': local_addr,
775 'peer_addr': peer_addr,
776 'is_ipv6': is_ipv6,
777 'detect_mult': detect_mult,
778 })
779 else:
780 return self.api(self.papi.bfd_udp_add,
781 {
782 'sw_if_index': sw_if_index,
783 'desired_min_tx': desired_min_tx,
784 'required_min_rx': required_min_rx,
785 'local_addr': local_addr,
786 'peer_addr': peer_addr,
787 'is_ipv6': is_ipv6,
788 'detect_mult': detect_mult,
789 'is_authenticated': 1,
790 'bfd_key_id': bfd_key_id,
791 'conf_key_id': conf_key_id,
792 })
793
Klement Sekeraa57a9702017-02-02 06:58:07 +0100794 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
795 detect_mult, local_addr, peer_addr, is_ipv6=0):
796 return self.api(self.papi.bfd_udp_mod,
797 {
798 'sw_if_index': sw_if_index,
799 'desired_min_tx': desired_min_tx,
800 'required_min_rx': required_min_rx,
801 'local_addr': local_addr,
802 'peer_addr': peer_addr,
803 'is_ipv6': is_ipv6,
804 'detect_mult': detect_mult,
805 })
806
Klement Sekerab17dd962017-01-09 07:43:48 +0100807 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
808 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
809 is_delayed=False):
810 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200811 {
812 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200813 'local_addr': local_addr,
814 'peer_addr': peer_addr,
815 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +0100816 'is_delayed': 1 if is_delayed else 0,
817 'bfd_key_id': bfd_key_id,
818 'conf_key_id': conf_key_id,
819 })
820
Klement Sekerab17dd962017-01-09 07:43:48 +0100821 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
822 peer_addr, is_ipv6=0):
823 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200824 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +0100825 'sw_if_index': sw_if_index,
826 'local_addr': local_addr,
827 'peer_addr': peer_addr,
828 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200829 })
830
831 def want_bfd_events(self, enable_disable=1):
832 return self.api(self.papi.want_bfd_events, {
833 'enable_disable': enable_disable,
834 'pid': os.getpid(),
835 })
Steve Shin7957d6e2016-12-19 09:24:50 -0800836
Klement Sekerab17dd962017-01-09 07:43:48 +0100837 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
838 return self.api(self.papi.bfd_auth_set_key, {
839 'conf_key_id': conf_key_id,
840 'auth_type': auth_type,
841 'key': key,
842 'key_len': len(key),
843 })
844
Steve Shin7957d6e2016-12-19 09:24:50 -0800845 def classify_add_del_table(
846 self,
847 is_add,
848 mask,
849 match_n_vectors=1,
850 table_index=0xFFFFFFFF,
851 nbuckets=2,
852 memory_size=2097152,
853 skip_n_vectors=0,
854 next_table_index=0xFFFFFFFF,
855 miss_next_index=0xFFFFFFFF,
856 current_data_flag=0,
857 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -0800858 """
859 :param is_add:
860 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +0100861 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100862 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -0800863 :param nbuckets: (Default value = 2)
864 :param memory_size: (Default value = 2097152)
865 :param skip_n_vectors: (Default value = 0)
866 :param next_table_index: (Default value = 0xFFFFFFFF)
867 :param miss_next_index: (Default value = 0xFFFFFFFF)
868 :param current_data_flag: (Default value = 0)
869 :param current_data_offset: (Default value = 0)
870 """
871
Juraj Sloboda75282452018-06-12 14:20:49 +0200872 mask_len = ((len(mask) - 1) / 16 + 1) * 16
873 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -0800874 return self.api(
875 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100876 {'is_add': is_add,
877 'table_index': table_index,
878 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -0800879 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100880 'skip_n_vectors': skip_n_vectors,
881 'match_n_vectors': match_n_vectors,
882 'next_table_index': next_table_index,
883 'miss_next_index': miss_next_index,
884 'current_data_flag': current_data_flag,
885 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +0200886 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100887 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -0800888
889 def classify_add_del_session(
890 self,
891 is_add,
892 table_index,
893 match,
894 opaque_index=0xFFFFFFFF,
895 hit_next_index=0xFFFFFFFF,
896 advance=0,
897 action=0,
898 metadata=0):
899 """
900 :param is_add:
901 :param table_index:
902 :param match:
903 :param opaque_index: (Default value = 0xFFFFFFFF)
904 :param hit_next_index: (Default value = 0xFFFFFFFF)
905 :param advance: (Default value = 0)
906 :param action: (Default value = 0)
907 :param metadata: (Default value = 0)
908 """
909
Juraj Sloboda75282452018-06-12 14:20:49 +0200910 match_len = ((len(match) - 1) / 16 + 1) * 16
911 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -0800912 return self.api(
913 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100914 {'is_add': is_add,
915 'table_index': table_index,
916 'hit_next_index': hit_next_index,
917 'opaque_index': opaque_index,
918 'advance': advance,
919 'action': action,
920 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +0200921 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100922 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -0800923
924 def input_acl_set_interface(
925 self,
926 is_add,
927 sw_if_index,
928 ip4_table_index=0xFFFFFFFF,
929 ip6_table_index=0xFFFFFFFF,
930 l2_table_index=0xFFFFFFFF):
931 """
932 :param is_add:
933 :param sw_if_index:
934 :param ip4_table_index: (Default value = 0xFFFFFFFF)
935 :param ip6_table_index: (Default value = 0xFFFFFFFF)
936 :param l2_table_index: (Default value = 0xFFFFFFFF)
937 """
938
939 return self.api(
940 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100941 {'sw_if_index': sw_if_index,
942 'ip4_table_index': ip4_table_index,
943 'ip6_table_index': ip6_table_index,
944 'l2_table_index': l2_table_index,
945 'is_add': is_add})
946
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100947 def output_acl_set_interface(
948 self,
949 is_add,
950 sw_if_index,
951 ip4_table_index=0xFFFFFFFF,
952 ip6_table_index=0xFFFFFFFF,
953 l2_table_index=0xFFFFFFFF):
954 """
955 :param is_add:
956 :param sw_if_index:
957 :param ip4_table_index: (Default value = 0xFFFFFFFF)
958 :param ip6_table_index: (Default value = 0xFFFFFFFF)
959 :param l2_table_index: (Default value = 0xFFFFFFFF)
960 """
961
962 return self.api(
963 self.papi.output_acl_set_interface,
964 {'sw_if_index': sw_if_index,
965 'ip4_table_index': ip4_table_index,
966 'ip6_table_index': ip6_table_index,
967 'l2_table_index': l2_table_index,
968 'is_add': is_add})
969
Klement Sekera77fabdb2017-01-02 07:46:14 +0100970 def set_ipfix_exporter(
971 self,
972 collector_address,
973 src_address,
974 path_mtu,
975 template_interval,
976 vrf_id=0,
977 collector_port=4739,
978 udp_checksum=0):
979 return self.api(
980 self.papi.set_ipfix_exporter,
981 {
982 'collector_address': collector_address,
983 'collector_port': collector_port,
984 'src_address': src_address,
985 'vrf_id': vrf_id,
986 'path_mtu': path_mtu,
987 'template_interval': template_interval,
988 'udp_checksum': udp_checksum,
989 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800990
991 def dhcp_proxy_config(self,
992 dhcp_server,
993 dhcp_src_address,
994 rx_table_id=0,
995 server_table_id=0,
996 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800997 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800998 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -0800999 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001000 {
1001 'rx_vrf_id': rx_table_id,
1002 'server_vrf_id': server_table_id,
1003 'is_ipv6': is_ipv6,
1004 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001005 'dhcp_server': dhcp_server,
1006 'dhcp_src_address': dhcp_src_address,
1007 })
1008
1009 def dhcp_proxy_set_vss(self,
1010 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001011 vss_type=255,
1012 vpn_ascii_id="",
1013 oui=0,
1014 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001015 is_add=1,
1016 is_ip6=0):
1017 return self.api(
1018 self.papi.dhcp_proxy_set_vss,
1019 {
1020 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001021 'vss_type': vss_type,
1022 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001023 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001024 'vpn_index': vpn_index,
1025 'is_add': is_add,
1026 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001027 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001028
Ole Troane1ade682019-03-04 23:55:43 +01001029 def dhcp_client_config(self,
1030 sw_if_index,
1031 hostname,
1032 client_id='',
1033 is_add=1,
1034 set_broadcast_flag=1,
Neale Ranns038e1df2019-07-19 14:01:02 +00001035 want_dhcp_events=0,
1036 dscp=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001037 return self.api(
1038 self.papi.dhcp_client_config,
1039 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001040 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001041 'client': {
1042 'sw_if_index': sw_if_index,
1043 'hostname': hostname,
1044 'id': client_id,
1045 'want_dhcp_event': want_dhcp_events,
1046 'set_broadcast_flag': set_broadcast_flag,
Neale Ranns038e1df2019-07-19 14:01:02 +00001047 'dscp': dscp,
Neale Rannsdaff1782018-05-16 04:12:18 -07001048 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001049 })
1050
Neale Ranns32e1c012016-11-22 17:07:28 +00001051 def ip_mroute_add_del(self,
Neale Ranns097fa662018-05-01 05:17:55 -07001052 table_id,
1053 prefix,
Neale Ranns32e1c012016-11-22 17:07:28 +00001054 e_flags,
Neale Ranns097fa662018-05-01 05:17:55 -07001055 rpf_id,
1056 paths,
Neale Ranns32e1c012016-11-22 17:07:28 +00001057 is_add=1,
Neale Ranns097fa662018-05-01 05:17:55 -07001058 is_multipath=1):
Neale Ranns32e1c012016-11-22 17:07:28 +00001059 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001060 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001061 """
1062 return self.api(
1063 self.papi.ip_mroute_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001064 {
1065 'is_add': is_add,
1066 'is_multipath': is_multipath,
1067 'route': {
1068 'table_id': table_id,
1069 'entry_flags': e_flags,
1070 'rpf_id': rpf_id,
1071 'prefix': prefix,
1072 'n_paths': len(paths),
1073 'paths': paths,
1074 }
1075 })
1076
1077 def mfib_signal_dump(self):
1078 return self.api(self.papi.mfib_signal_dump, {})
1079
1080 def ip_mroute_dump(self, table_id, is_ip6=False):
1081 return self.api(self.papi.ip_mroute_dump,
1082 {'table': {
1083 'table_id': table_id,
1084 'is_ip6': is_ip6
1085 }})
Neale Ranns32e1c012016-11-22 17:07:28 +00001086
Filip Tehlar770e89e2017-01-31 10:39:16 +01001087 def lisp_enable_disable(self, is_enabled):
1088 return self.api(
1089 self.papi.lisp_enable_disable,
1090 {
1091 'is_en': is_enabled,
1092 })
1093
Ole Troane1ade682019-03-04 23:55:43 +01001094 def lisp_add_del_locator_set(self,
1095 ls_name,
1096 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001097 return self.api(
1098 self.papi.lisp_add_del_locator_set,
1099 {
1100 'is_add': is_add,
1101 'locator_set_name': ls_name
1102 })
1103
Ole Troane1ade682019-03-04 23:55:43 +01001104 def lisp_add_del_locator(self,
1105 ls_name,
1106 sw_if_index,
1107 priority=1,
1108 weight=1,
1109 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001110 return self.api(
1111 self.papi.lisp_add_del_locator,
1112 {
1113 'is_add': is_add,
1114 'locator_set_name': ls_name,
1115 'sw_if_index': sw_if_index,
1116 'priority': priority,
1117 'weight': weight
1118 })
1119
1120 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1121 return self.api(
1122 self.papi.lisp_locator_dump,
1123 {
1124 'is_index_set': is_index_set,
1125 'ls_name': ls_name,
1126 'ls_index': ls_index,
1127 })
1128
Ole Troane1ade682019-03-04 23:55:43 +01001129 def lisp_add_del_local_eid(self,
1130 ls_name,
1131 eid_type,
1132 eid,
1133 prefix_len,
1134 vni=0,
1135 key_id=0,
1136 key="",
1137 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001138 return self.api(
1139 self.papi.lisp_add_del_local_eid,
1140 {
1141 'locator_set_name': ls_name,
1142 'is_add': is_add,
1143 'eid_type': eid_type,
1144 'eid': eid,
1145 'prefix_len': prefix_len,
1146 'vni': vni,
1147 'key_id': key_id,
1148 'key': key
1149 })
1150
1151 def lisp_eid_table_dump(self,
1152 eid_set=0,
1153 prefix_length=0,
1154 vni=0,
1155 eid_type=0,
1156 eid=None,
1157 filter_opt=0):
1158 return self.api(
1159 self.papi.lisp_eid_table_dump,
1160 {
1161 'eid_set': eid_set,
1162 'prefix_length': prefix_length,
1163 'vni': vni,
1164 'eid_type': eid_type,
1165 'eid': eid,
1166 'filter': filter_opt,
1167 })
1168
Ole Troane1ade682019-03-04 23:55:43 +01001169 def lisp_add_del_remote_mapping(self,
1170 eid_type,
1171 eid,
1172 eid_prefix_len=0,
1173 vni=0,
1174 rlocs=[],
1175 rlocs_num=0,
1176 is_src_dst=0,
1177 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001178 return self.api(
1179 self.papi.lisp_add_del_remote_mapping,
1180 {
1181 'is_add': is_add,
1182 'eid_type': eid_type,
1183 'eid': eid,
1184 'eid_len': eid_prefix_len,
1185 'rloc_num': rlocs_num,
1186 'rlocs': rlocs,
1187 'vni': vni,
1188 'is_src_dst': is_src_dst,
1189 })
1190
Ole Troane1ade682019-03-04 23:55:43 +01001191 def lisp_add_del_adjacency(self,
1192 leid,
1193 reid,
1194 leid_len,
1195 reid_len,
1196 eid_type,
1197 is_add=1,
1198 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001199 return self.api(
1200 self.papi.lisp_add_del_adjacency,
1201 {
1202 'is_add': is_add,
1203 'vni': vni,
1204 'eid_type': eid_type,
1205 'leid': leid,
1206 'reid': reid,
1207 'leid_len': leid_len,
1208 'reid_len': reid_len,
1209 })
1210
Hongjun Nief486b12017-04-12 19:21:16 +08001211 def gtpu_add_del_tunnel(
1212 self,
1213 src_addr,
1214 dst_addr,
1215 is_add=1,
1216 is_ipv6=0,
1217 mcast_sw_if_index=0xFFFFFFFF,
1218 encap_vrf_id=0,
1219 decap_next_index=0xFFFFFFFF,
1220 teid=0):
1221 """
1222
1223 :param is_add: (Default value = 1)
1224 :param is_ipv6: (Default value = 0)
1225 :param src_addr:
1226 :param dst_addr:
1227 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1228 :param encap_vrf_id: (Default value = 0)
1229 :param decap_next_index: (Default value = 0xFFFFFFFF)
1230 :param teid: (Default value = 0)
1231
1232 """
1233 return self.api(self.papi.gtpu_add_del_tunnel,
1234 {'is_add': is_add,
1235 'is_ipv6': is_ipv6,
1236 'src_address': src_addr,
1237 'dst_address': dst_addr,
1238 'mcast_sw_if_index': mcast_sw_if_index,
1239 'encap_vrf_id': encap_vrf_id,
1240 'decap_next_index': decap_next_index,
1241 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001242
1243 def vxlan_gpe_add_del_tunnel(
1244 self,
1245 src_addr,
1246 dst_addr,
1247 mcast_sw_if_index=0xFFFFFFFF,
1248 is_add=1,
1249 is_ipv6=0,
1250 encap_vrf_id=0,
1251 decap_vrf_id=0,
1252 protocol=3,
1253 vni=0):
1254 """
1255
1256 :param local:
1257 :param remote:
1258 :param is_add: (Default value = 1)
1259 :param is_ipv6: (Default value = 0)
1260 :param encap_vrf_id: (Default value = 0)
1261 :param decap_vrf_id: (Default value = 0)
1262 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1263 :param protocol: (Default value = 3)
1264 :param vni: (Default value = 0)
1265
1266 """
1267 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1268 {'is_add': is_add,
1269 'is_ipv6': is_ipv6,
1270 'local': src_addr,
1271 'remote': dst_addr,
1272 'mcast_sw_if_index': mcast_sw_if_index,
1273 'encap_vrf_id': encap_vrf_id,
1274 'decap_vrf_id': decap_vrf_id,
1275 'protocol': protocol,
1276 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001277
Neale Ranns79a05f52018-09-11 07:39:43 -07001278 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1279 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001280 {'sw_if_index': sw_if_index,
1281 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001282
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001283 def pppoe_add_del_session(
1284 self,
1285 client_ip,
1286 client_mac,
1287 session_id=0,
1288 is_add=1,
1289 is_ipv6=0,
1290 decap_vrf_id=0):
1291 """
1292
1293 :param is_add: (Default value = 1)
1294 :param is_ipv6: (Default value = 0)
1295 :param client_ip:
1296 :param session_id: (Default value = 0)
1297 :param client_mac:
1298 :param decap_vrf_id: (Default value = 0)
1299
1300 """
1301 return self.api(self.papi.pppoe_add_del_session,
1302 {'is_add': is_add,
1303 'is_ipv6': is_ipv6,
1304 'session_id': session_id,
1305 'client_ip': client_ip,
1306 'decap_vrf_id': decap_vrf_id,
1307 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001308
Neale Ranns7c922dc2018-08-30 06:12:27 -07001309 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1310 return self.api(self.papi.sr_mpls_policy_add,
1311 {'bsid': bsid,
1312 'weight': weight,
1313 'type': type,
1314 'n_segments': len(segments),
1315 'segments': segments})
1316
1317 def sr_mpls_policy_del(self, bsid):
1318 return self.api(self.papi.sr_mpls_policy_del,
1319 {'bsid': bsid})
1320
Kris Michielsen91074432017-06-22 13:00:20 +02001321 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001322 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001323 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001324 nh_addr4,
1325 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001326 is_del=0,
1327 end_psp=0,
1328 sw_if_index=0xFFFFFFFF,
1329 vlan_index=0,
1330 fib_table=0,
1331 ):
1332 """ Add/del IPv6 SR local-SID.
1333
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001334 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001335 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1336 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001337 :param nh_addr4:
1338 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001339 :param is_del: (Default value = 0)
1340 :param end_psp: (Default value = 0)
1341 :param sw_if_index: (Default value = 0xFFFFFFFF)
1342 :param vlan_index: (Default value = 0)
1343 :param fib_table: (Default value = 0)
1344 """
1345 return self.api(
1346 self.papi.sr_localsid_add_del,
1347 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001348 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001349 'end_psp': end_psp,
1350 'behavior': behavior,
1351 'sw_if_index': sw_if_index,
1352 'vlan_index': vlan_index,
1353 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001354 'nh_addr4': nh_addr4,
1355 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001356 }
1357 )
1358
1359 def sr_policy_add(
1360 self,
1361 bsid_addr,
1362 weight=1,
1363 is_encap=1,
1364 type=0,
1365 fib_table=0,
1366 n_segments=0,
1367 segments=[]):
1368 """
1369 :param bsid_addr: bindingSID of the SR Policy
1370 :param weight: weight of the sid list. optional. (default: 1)
1371 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1372 (default: Encap)
1373 :param type: type/behavior of the SR policy. (default or spray) \
1374 (default: default)
1375 :param fib_table: VRF where to install the FIB entry for the BSID \
1376 (default: 0)
1377 :param n_segments: number of segments \
1378 (default: 0)
1379 :param segments: a vector of IPv6 address composing the segment list \
1380 (default: [])
1381 """
1382 return self.api(
1383 self.papi.sr_policy_add,
1384 {'bsid_addr': bsid_addr,
1385 'weight': weight,
1386 'is_encap': is_encap,
1387 'type': type,
1388 'fib_table': fib_table,
1389 'n_segments': n_segments,
1390 'segments': segments
1391 }
1392 )
1393
1394 def sr_policy_del(
1395 self,
1396 bsid_addr,
1397 sr_policy_index=0):
1398 """
1399 :param bsid: bindingSID of the SR Policy
1400 :param sr_policy_index: index of the sr policy (default: 0)
1401 """
1402 return self.api(
1403 self.papi.sr_policy_del,
1404 {'bsid_addr': bsid_addr,
1405 'sr_policy_index': sr_policy_index
1406 })
1407
1408 def sr_steering_add_del(
1409 self,
1410 is_del,
1411 bsid_addr,
1412 sr_policy_index,
1413 table_id,
1414 prefix_addr,
1415 mask_width,
1416 sw_if_index,
1417 traffic_type):
1418 """
1419 Steer traffic L2 and L3 traffic through a given SR policy
1420
1421 :param is_del: delete or add
1422 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1423 :param sr_policy: is the index of the SR Policy (alt to bsid)
1424 :param table_id: is the VRF where to install the FIB entry for the BSID
1425 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1426 :param mask_width: is the mask for L3 traffic type
1427 :param sw_if_index: is the incoming interface for L2 traffic
1428 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1429 """
1430 return self.api(
1431 self.papi.sr_steering_add_del,
1432 {'is_del': is_del,
1433 'bsid_addr': bsid_addr,
1434 'sr_policy_index': sr_policy_index,
1435 'table_id': table_id,
1436 'prefix_addr': prefix_addr,
1437 'mask_width': mask_width,
1438 'sw_if_index': sw_if_index,
1439 'traffic_type': traffic_type
1440 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001441
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001442 def acl_add_replace(self, acl_index, r, tag='',
1443 expected_retval=0):
1444 """Add/replace an ACL
1445 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1446 :param acl_rule r: ACL rules array.
1447 :param str tag: symbolic tag (description) for this ACL.
1448 :param int count: number of rules.
1449 """
1450 return self.api(self.papi.acl_add_replace,
1451 {'acl_index': acl_index,
1452 'r': r,
1453 'count': len(r),
1454 'tag': tag},
1455 expected_retval=expected_retval)
1456
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001457 def acl_del(self, acl_index, expected_retval=0):
1458 """
1459
1460 :param acl_index:
1461 :return:
1462 """
1463 return self.api(self.papi.acl_del,
1464 {'acl_index': acl_index},
1465 expected_retval=expected_retval)
1466
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001467 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1468 expected_retval=0):
1469 return self.api(self.papi.acl_interface_set_acl_list,
1470 {'sw_if_index': sw_if_index,
1471 'count': len(acls),
1472 'n_input': n_input,
1473 'acls': acls},
1474 expected_retval=expected_retval)
1475
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001476 def acl_interface_set_etype_whitelist(self, sw_if_index,
1477 n_input, whitelist,
1478 expected_retval=0):
1479 return self.api(self.papi.acl_interface_set_etype_whitelist,
1480 {'sw_if_index': sw_if_index,
1481 'count': len(whitelist),
1482 'n_input': n_input,
1483 'whitelist': whitelist},
1484 expected_retval=expected_retval)
1485
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001486 def acl_interface_add_del(self,
1487 sw_if_index,
1488 acl_index,
1489 is_add=1):
1490 """ Add/Delete ACL to/from interface
1491
1492 :param sw_if_index:
1493 :param acl_index:
1494 :param is_add: (Default value = 1)
1495 """
1496
1497 return self.api(self.papi.acl_interface_add_del,
1498 {'is_add': is_add,
1499 'is_input': 1,
1500 'sw_if_index': sw_if_index,
1501 'acl_index': acl_index})
1502
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001503 def acl_dump(self, acl_index, expected_retval=0):
1504 return self.api(self.papi.acl_dump,
1505 {'acl_index': acl_index},
1506 expected_retval=expected_retval)
1507
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001508 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1509 expected_retval=0):
1510 return self.api(self.papi.acl_interface_list_dump,
1511 {'sw_if_index': sw_if_index},
1512 expected_retval=expected_retval)
1513
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001514 def macip_acl_add(self, rules, tag=""):
1515 """ Add MACIP acl
1516
1517 :param rules: list of rules for given acl
1518 :param tag: acl tag
1519 """
1520
1521 return self.api(self.papi.macip_acl_add,
1522 {'r': rules,
1523 'count': len(rules),
1524 'tag': tag})
1525
Pavel Kotucek932f7412017-09-07 14:44:52 +02001526 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1527 """ Add MACIP acl
1528
1529 :param rules: list of rules for given acl
1530 :param tag: acl tag
1531 """
1532
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001533 return self.api(self.papi.macip_acl_add_replace,
1534 {'acl_index': acl_index,
1535 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001536 'count': len(rules),
1537 'tag': tag})
1538
Pavel Kotucek932f7412017-09-07 14:44:52 +02001539 def macip_acl_interface_add_del(self,
1540 sw_if_index,
1541 acl_index,
1542 is_add=1):
1543 """ Add MACIP acl to interface
1544
1545 :param sw_if_index:
1546 :param acl_index:
1547 :param is_add: (Default value = 1)
1548 """
1549
1550 return self.api(self.papi.macip_acl_interface_add_del,
1551 {'is_add': is_add,
1552 'sw_if_index': sw_if_index,
1553 'acl_index': acl_index})
1554
Pavel Kotucek932f7412017-09-07 14:44:52 +02001555 def macip_acl_dump(self, acl_index=4294967295):
1556 """ Return MACIP acl dump
1557 """
1558
1559 return self.api(
1560 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001561
1562 def policer_add_del(self,
1563 name,
1564 cir,
1565 eir,
1566 cb,
1567 eb,
1568 is_add=1,
1569 rate_type=0,
1570 round_type=0,
1571 ptype=0,
1572 color_aware=0,
1573 conform_action_type=1,
1574 conform_dscp=0,
1575 exceed_action_type=0,
1576 exceed_dscp=0,
1577 violate_action_type=0,
1578 violate_dscp=0):
1579 return self.api(self.papi.policer_add_del,
1580 {'name': name,
1581 'cir': cir,
1582 'eir': eir,
1583 'cb': cb,
1584 'eb': eb,
1585 'is_add': is_add,
1586 'rate_type': rate_type,
1587 'round_type': round_type,
1588 'type': ptype,
1589 'color_aware': color_aware,
1590 'conform_action_type': conform_action_type,
1591 'conform_dscp': conform_dscp,
1592 'exceed_action_type': exceed_action_type,
1593 'exceed_dscp': exceed_dscp,
1594 'violate_action_type': violate_action_type,
1595 'violate_dscp': violate_dscp})
1596
1597 def ip_punt_police(self,
1598 policer_index,
1599 is_ip6=0,
1600 is_add=1):
1601 return self.api(self.papi.ip_punt_police,
1602 {'policer_index': policer_index,
1603 'is_add': is_add,
1604 'is_ip6': is_ip6})
1605
1606 def ip_punt_redirect(self,
1607 rx_sw_if_index,
1608 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001609 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001610 is_add=1):
1611 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001612 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1613 'tx_sw_if_index': tx_sw_if_index,
1614 'nh': address},
1615 'is_add': is_add})
1616
1617 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1618 return self.api(self.papi.ip_punt_redirect_dump,
1619 {'sw_if_index': sw_if_index,
1620 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001621
1622 def bier_table_add_del(self,
1623 bti,
1624 mpls_label,
1625 is_add=1):
1626 """ BIER Table add/del """
1627 return self.api(
1628 self.papi.bier_table_add_del,
1629 {'bt_tbl_id': {"bt_set": bti.set_id,
1630 "bt_sub_domain": bti.sub_domain_id,
1631 "bt_hdr_len_id": bti.hdr_len_id},
1632 'bt_label': mpls_label,
1633 'bt_is_add': is_add})
1634
1635 def bier_table_dump(self):
1636 return self.api(self.papi.bier_table_dump, {})
1637
1638 def bier_route_add_del(self,
1639 bti,
1640 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001641 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001642 is_add=1,
1643 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001644 """ BIER Route add/del """
1645 return self.api(
1646 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001647 {
1648 'br_route': {
1649 'br_tbl_id': {"bt_set": bti.set_id,
1650 "bt_sub_domain": bti.sub_domain_id,
1651 "bt_hdr_len_id": bti.hdr_len_id},
1652 'br_bp': bp,
1653 'br_n_paths': len(paths),
1654 'br_paths': paths,
1655 },
1656 'br_is_add': is_add,
1657 'br_is_replace': is_replace
1658 })
Neale Rannsd792d9c2017-10-21 10:53:20 -07001659
1660 def bier_route_dump(self, bti):
1661 return self.api(
1662 self.papi.bier_route_dump,
1663 {'br_tbl_id': {"bt_set": bti.set_id,
1664 "bt_sub_domain": bti.sub_domain_id,
1665 "bt_hdr_len_id": bti.hdr_len_id}})
1666
1667 def bier_imp_add(self,
1668 bti,
1669 src,
1670 ibytes,
1671 is_add=1):
1672 """ BIER Imposition Add """
1673 return self.api(
1674 self.papi.bier_imp_add,
1675 {'bi_tbl_id': {"bt_set": bti.set_id,
1676 "bt_sub_domain": bti.sub_domain_id,
1677 "bt_hdr_len_id": bti.hdr_len_id},
1678 'bi_src': src,
1679 'bi_n_bytes': len(ibytes),
1680 'bi_bytes': ibytes})
1681
1682 def bier_imp_del(self, bi_index):
1683 """ BIER Imposition del """
1684 return self.api(
1685 self.papi.bier_imp_del,
1686 {'bi_index': bi_index})
1687
1688 def bier_imp_dump(self):
1689 return self.api(self.papi.bier_imp_dump, {})
1690
1691 def bier_disp_table_add_del(self,
1692 bdti,
1693 is_add=1):
1694 """ BIER Disposition Table add/del """
1695 return self.api(
1696 self.papi.bier_disp_table_add_del,
1697 {'bdt_tbl_id': bdti,
1698 'bdt_is_add': is_add})
1699
1700 def bier_disp_table_dump(self):
1701 return self.api(self.papi.bier_disp_table_dump, {})
1702
1703 def bier_disp_entry_add_del(self,
1704 bdti,
1705 bp,
1706 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001707 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001708 next_hop,
1709 next_hop_tbl_id=0,
1710 next_hop_rpf_id=~0,
1711 next_hop_is_ip4=1,
1712 is_add=1):
1713 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001714 lstack = []
1715 while (len(lstack) < 16):
1716 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001717 return self.api(
1718 self.papi.bier_disp_entry_add_del,
1719 {'bde_tbl_id': bdti,
1720 'bde_bp': bp,
1721 'bde_payload_proto': payload_proto,
1722 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -04001723 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001724 'rpf_id': next_hop_rpf_id,
1725 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001726 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001727 'bde_is_add': is_add})
1728
1729 def bier_disp_entry_dump(self, bdti):
1730 return self.api(
1731 self.papi.bier_disp_entry_dump,
1732 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001733
Florin Coras3ea6ce22017-12-11 09:09:05 -08001734 def session_enable_disable(self, is_enabled):
1735 return self.api(
1736 self.papi.session_enable_disable,
1737 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001738
1739 def ipsec_spd_add_del(self, spd_id, is_add=1):
1740 """ SPD add/del - Wrapper to add or del ipsec SPD
1741 Sample CLI : 'ipsec spd add 1'
1742
1743 :param spd_id - SPD ID to be created in the vpp . mandatory
1744 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1745 optional
1746 :returns: reply from the API
1747 """
1748 return self.api(
1749 self.papi.ipsec_spd_add_del, {
1750 'spd_id': spd_id, 'is_add': is_add})
1751
Neale Ranns311124e2019-01-24 04:52:25 -08001752 def ipsec_spds_dump(self):
1753 return self.api(self.papi.ipsec_spds_dump, {})
1754
“mystarrocks”23f0c452017-12-11 07:11:51 -08001755 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1756 """ IPSEC interface SPD add/del - \
1757 Wrapper to associate/disassociate SPD to interface in VPP
1758 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1759
1760 :param spd_id - SPD ID to associate with the interface . mandatory
1761 :param sw_if_index - Interface Index which needs to ipsec \
1762 association mandatory
1763 :param is_add - add(1) or del(0) association with interface \
1764 (Default 1 - add) . optional
1765 :returns: reply from the API
1766 """
1767 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001768 self.papi.ipsec_interface_add_del_spd,
1769 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001770
Neale Ranns311124e2019-01-24 04:52:25 -08001771 def ipsec_spd_interface_dump(self, spd_index=None):
1772 return self.api(self.papi.ipsec_spd_interface_dump,
1773 {'spd_index': spd_index if spd_index else 0,
1774 'spd_index_valid': 1 if spd_index else 0})
1775
Neale Ranns17dcec02019-01-09 21:22:20 -08001776 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001777 sad_id,
1778 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001779 integrity_algorithm,
1780 integrity_key,
1781 crypto_algorithm,
1782 crypto_key,
1783 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001784 tunnel_src_address='',
1785 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001786 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001787 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001788 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001789 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001790 :param sad_id: security association ID
1791 :param spi: security param index of the SA in decimal
1792 :param integrity_algorithm:
1793 :param integrity_key:
1794 :param crypto_algorithm:
1795 :param crypto_key:
1796 :param protocol: AH(0) or ESP(1) protocol
1797 :param tunnel_src_address: tunnel mode outer src address
1798 :param tunnel_dst_address: tunnel mode outer dst address
1799 :param is_add:
1800 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001801 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1802 crypto and ipsec algorithms
1803 """
1804 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001805 self.papi.ipsec_sad_entry_add_del,
1806 {
1807 'is_add': is_add,
1808 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001809 {
1810 'sad_id': sad_id,
1811 'spi': spi,
1812 'tunnel_src': tunnel_src_address,
1813 'tunnel_dst': tunnel_dst_address,
1814 'protocol': protocol,
1815 'integrity_algorithm': integrity_algorithm,
1816 'integrity_key': {
1817 'length': len(integrity_key),
1818 'data': integrity_key,
1819 },
1820 'crypto_algorithm': crypto_algorithm,
1821 'crypto_key': {
1822 'length': len(crypto_key),
1823 'data': crypto_key,
1824 },
1825 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001826 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001827 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001828 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001829
Neale Ranns311124e2019-01-24 04:52:25 -08001830 def ipsec_sa_dump(self, sa_id=None):
1831 return self.api(self.papi.ipsec_sa_dump,
1832 {'sa_id': sa_id if sa_id else 0xffffffff})
1833
Neale Ranns17dcec02019-01-09 21:22:20 -08001834 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001835 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001836 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001837 local_address_start,
1838 local_address_stop,
1839 remote_address_start,
1840 remote_address_stop,
1841 local_port_start=0,
1842 local_port_stop=65535,
1843 remote_port_start=0,
1844 remote_port_stop=65535,
1845 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001846 policy=0,
1847 priority=100,
1848 is_outbound=1,
1849 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001850 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001851 is_ip_any=0):
1852 """ IPSEC policy SPD add/del -
1853 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001854 :param spd_id: SPD ID for the policy
1855 :param local_address_start: local-ip-range start address
1856 :param local_address_stop : local-ip-range stop address
1857 :param remote_address_start: remote-ip-range start address
1858 :param remote_address_stop : remote-ip-range stop address
1859 :param local_port_start: (Default value = 0)
1860 :param local_port_stop: (Default value = 65535)
1861 :param remote_port_start: (Default value = 0)
1862 :param remote_port_stop: (Default value = 65535)
1863 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1864 :param sa_id: Security Association ID for mapping it to SPD
1865 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1866 (Default value = 0)
1867 :param priority: value for the spd action (Default value = 100)
1868 :param is_outbound: flag for inbound(0) or outbound(1)
1869 (Default value = 1)
1870 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001871 """
1872 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001873 self.papi.ipsec_spd_entry_add_del,
1874 {
1875 'is_add': is_add,
1876 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001877 {
1878 'spd_id': spd_id,
1879 'sa_id': sa_id,
1880 'local_address_start': local_address_start,
1881 'local_address_stop': local_address_stop,
1882 'remote_address_start': remote_address_start,
1883 'remote_address_stop': remote_address_stop,
1884 'local_port_start': local_port_start,
1885 'local_port_stop': local_port_stop,
1886 'remote_port_start': remote_port_start,
1887 'remote_port_stop': remote_port_stop,
1888 'protocol': protocol,
1889 'policy': policy,
1890 'priority': priority,
1891 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +01001892 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001893 })
Florin Corasb795bd02017-12-14 11:30:48 -08001894
Neale Ranns311124e2019-01-24 04:52:25 -08001895 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1896 return self.api(self.papi.ipsec_spd_dump,
1897 {'spd_id': spd_id,
1898 'sa_id': sa_id})
1899
Klement Sekera31da2e32018-06-24 22:49:55 +02001900 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1901 remote_spi, crypto_alg, local_crypto_key,
1902 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001903 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001904 anti_replay=1, renumber=0,
1905 udp_encap=0, show_instance=0):
Klement Sekera31da2e32018-06-24 22:49:55 +02001906 return self.api(
1907 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001908 {
1909 'local_ip': local_ip,
1910 'remote_ip': remote_ip,
1911 'local_spi': local_spi,
1912 'remote_spi': remote_spi,
1913 'crypto_alg': crypto_alg,
1914 'local_crypto_key_len': len(local_crypto_key),
1915 'local_crypto_key': local_crypto_key,
1916 'remote_crypto_key_len': len(remote_crypto_key),
1917 'remote_crypto_key': remote_crypto_key,
1918 'integ_alg': integ_alg,
1919 'local_integ_key_len': len(local_integ_key),
1920 'local_integ_key': local_integ_key,
1921 'remote_integ_key_len': len(remote_integ_key),
1922 'remote_integ_key': remote_integ_key,
1923 'is_add': is_add,
1924 'esn': esn,
1925 'anti_replay': anti_replay,
1926 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001927 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001928 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001929 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001930 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001931
Klement Sekerab4d30532018-11-08 13:00:02 +01001932 def ipsec_select_backend(self, protocol, index):
1933 return self.api(self.papi.ipsec_select_backend,
1934 {'protocol': protocol, 'index': index})
1935
1936 def ipsec_backend_dump(self):
1937 return self.api(self.papi.ipsec_backend_dump, {})
1938
Ole Troane1ade682019-03-04 23:55:43 +01001939 def app_namespace_add_del(self,
1940 namespace_id,
1941 ip4_fib_id=0,
1942 ip6_fib_id=0,
1943 sw_if_index=0xFFFFFFFF,
1944 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001945 return self.api(
1946 self.papi.app_namespace_add_del,
1947 {'secret': secret,
1948 'sw_if_index': sw_if_index,
1949 'ip4_fib_id': ip4_fib_id,
1950 'ip6_fib_id': ip6_fib_id,
1951 'namespace_id': namespace_id,
1952 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001953
Neale Ranns50f0ac02019-05-15 02:13:37 -07001954 def punt_socket_register(self, reg, pathname,
1955 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001956 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001957 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001958 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001959 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001960 'pathname': pathname})
1961
Neale Ranns50f0ac02019-05-15 02:13:37 -07001962 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001963 """ Unregister punt socket """
1964 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001965 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001966
Neale Ranns4ba67722019-02-28 11:11:39 +00001967 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001968 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001969 """ GBP endpoint Add """
1970 return self.api(self.papi.gbp_endpoint_add,
1971 {'endpoint': {
1972 'sw_if_index': sw_if_index,
1973 'ips': ips,
1974 'n_ips': len(ips),
1975 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001976 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001977 'flags': flags,
1978 'tun': {
1979 'src': tun_src,
1980 'dst': tun_dst,
1981 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001982
1983 def gbp_endpoint_del(self, handle):
1984 """ GBP endpoint Del """
1985 return self.api(self.papi.gbp_endpoint_del,
1986 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001987
1988 def gbp_endpoint_dump(self):
1989 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01001990 return self.api(self.papi.gbp_endpoint_dump,
1991 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001992
Neale Ranns4ba67722019-02-28 11:11:39 +00001993 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001994 rd, uplink_sw_if_index,
1995 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001996 """ GBP endpoint group Add """
1997 return self.api(self.papi.gbp_endpoint_group_add,
1998 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001999 {
2000 'uplink_sw_if_index': uplink_sw_if_index,
2001 'bd_id': bd,
2002 'rd_id': rd,
2003 'vnid': vnid,
2004 'sclass': sclass,
2005 'retention': retention
2006 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002007
Neale Ranns4ba67722019-02-28 11:11:39 +00002008 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002009 """ GBP endpoint group Del """
2010 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002011 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002012
Neale Ranns160c9232019-06-19 06:25:56 -07002013 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002014 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002015 uu_fwd_sw_if_index,
2016 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002017 """ GBP bridge-domain Add """
2018 return self.api(self.papi.gbp_bridge_domain_add,
2019 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002020 {
2021 'flags': flags,
2022 'bvi_sw_if_index': bvi_sw_if_index,
2023 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2024 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07002025 'bd_id': bd_id,
2026 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01002027 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002028
2029 def gbp_bridge_domain_del(self, bd_id):
2030 """ GBP bridge-domain Del """
2031 return self.api(self.papi.gbp_bridge_domain_del,
2032 {'bd_id': bd_id})
2033
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002034 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07002035 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002036 ip4_table_id,
2037 ip6_table_id,
2038 ip4_uu_sw_if_index,
2039 ip6_uu_sw_if_index):
2040 """ GBP route-domain Add """
2041 return self.api(self.papi.gbp_route_domain_add,
2042 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002043 {
Neale Ranns160c9232019-06-19 06:25:56 -07002044 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01002045 'ip4_table_id': ip4_table_id,
2046 'ip6_table_id': ip6_table_id,
2047 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2048 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2049 'rd_id': rd_id
2050 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002051
2052 def gbp_route_domain_del(self, rd_id):
2053 """ GBP route-domain Del """
2054 return self.api(self.papi.gbp_route_domain_del,
2055 {'rd_id': rd_id})
2056
Neale Ranns4ba67722019-02-28 11:11:39 +00002057 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002058 """ GBP recirc Add/Del """
2059 return self.api(self.papi.gbp_recirc_add_del,
2060 {'is_add': is_add,
2061 'recirc': {
2062 'is_ext': is_ext,
2063 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002064 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002065
2066 def gbp_recirc_dump(self):
2067 """ GBP recirc Dump """
2068 return self.api(self.papi.gbp_recirc_dump, {})
2069
Benoît Ganneba6abfa2019-07-01 17:10:41 +02002070 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08002071 """ GBP recirc Add/Del """
2072 return self.api(self.papi.gbp_ext_itf_add_del,
2073 {'is_add': is_add,
2074 'ext_itf': {
2075 'sw_if_index': sw_if_index,
2076 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02002077 'rd_id': rd_id,
2078 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08002079
2080 def gbp_ext_itf_dump(self):
2081 """ GBP recirc Dump """
2082 return self.api(self.papi.gbp_ext_itf_dump, {})
2083
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002084 def gbp_subnet_add_del(self, is_add, rd_id,
2085 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002086 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002087 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002088 """ GBP Subnet Add/Del """
2089 return self.api(self.papi.gbp_subnet_add_del,
2090 {'is_add': is_add,
2091 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002092 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002093 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002094 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002095 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002096 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002097
2098 def gbp_subnet_dump(self):
2099 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002100 return self.api(self.papi.gbp_subnet_dump,
2101 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002102
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002103 def gbp_contract_dump(self):
2104 """ GBP contract Dump """
2105 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002106
Neale Ranns8da9fc62019-03-04 14:08:11 -08002107 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002108 """ GBP VXLAN tunnel add """
2109 return self.api(self.papi.gbp_vxlan_tunnel_add,
2110 {
2111 'tunnel': {
2112 'vni': vni,
2113 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002114 'bd_rd_id': bd_rd_id,
2115 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002116 }
2117 })
2118
2119 def gbp_vxlan_tunnel_del(self, vni):
2120 """ GBP VXLAN tunnel del """
2121 return self.api(self.papi.gbp_vxlan_tunnel_del,
2122 {
2123 'vni': vni,
2124 })
2125
2126 def gbp_vxlan_tunnel_dump(self):
2127 """ GBP VXLAN tunnel add/del """
2128 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2129
Neale Ranns947ea622018-06-07 23:48:20 -07002130 def igmp_enable_disable(self, sw_if_index, enable, host):
2131 """ Enable/disable IGMP on a given interface """
2132 return self.api(self.papi.igmp_enable_disable,
2133 {'enable': enable,
2134 'mode': host,
2135 'sw_if_index': sw_if_index})
2136
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002137 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2138 """ Add/del IGMP proxy device """
2139 return self.api(self.papi.igmp_proxy_device_add_del,
2140 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2141 'add': add})
2142
2143 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2144 """ Add/del interface to/from IGMP proxy device """
2145 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2146 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2147 'add': add})
2148
Neale Ranns947ea622018-06-07 23:48:20 -07002149 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002150 """ Listen for new (S,G) on specified interface
2151
2152 :param enable: add/del
2153 :param sw_if_index: interface sw index
2154 :param saddr: source ip4 addr
2155 :param gaddr: group ip4 addr
2156 """
2157 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002158 {
2159 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002160 {
2161 'filter': filter,
2162 'sw_if_index': sw_if_index,
2163 'n_srcs': len(saddrs),
2164 'saddrs': saddrs,
2165 'gaddr': gaddr
2166 }
Neale Ranns947ea622018-06-07 23:48:20 -07002167 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002168
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002169 def igmp_clear_interface(self, sw_if_index):
2170 """ Remove all (S,G)s from specified interface
2171 doesn't send IGMP report!
2172 """
2173 return self.api(
2174 self.papi.igmp_clear_interface, {
2175 'sw_if_index': sw_if_index})
2176
2177 def want_igmp_events(self, enable=1):
2178 return self.api(self.papi.want_igmp_events, {'enable': enable,
2179 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002180
2181 def bond_create(
2182 self,
2183 mode,
2184 lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002185 numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08002186 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002187 mac_address='',
2188 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002189 """
2190 :param mode: mode
2191 :param lb: load balance
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002192 :param numa_only: tx on local numa node for lacp mode
Steven9cd2d7a2017-12-20 12:43:01 -08002193 :param use_custom_mac: use custom mac
2194 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002195 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002196 """
2197 return self.api(
2198 self.papi.bond_create,
2199 {'mode': mode,
2200 'lb': lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002201 'numa_only': numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08002202 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002203 'mac_address': mac_address,
2204 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002205 })
2206
Neale Ranns17ff3c12018-07-04 10:24:24 -07002207 def pipe_delete(self, parent_sw_if_index):
2208 return self.api(self.papi.pipe_delete,
2209 {'parent_sw_if_index': parent_sw_if_index})
2210
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002211 def svs_table_add_del(self, af, table_id, is_add=1):
2212 return self.api(self.papi.svs_table_add_del,
2213 {
2214 'table_id': table_id,
2215 'is_add': is_add,
2216 'af': af,
2217 })
2218
2219 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2220 return self.api(self.papi.svs_route_add_del,
2221 {
2222 'table_id': table_id,
2223 'source_table_id': src_table_id,
2224 'prefix': prefix,
2225 'is_add': is_add,
2226 })
2227
2228 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2229 return self.api(self.papi.svs_enable_disable,
2230 {
2231 'af': af,
2232 'table_id': table_id,
2233 'sw_if_index': sw_if_index,
2234 'is_enable': is_enable,
2235 })