blob: 40c6045c517e3cc9d9806e87119ba56cc67085e4 [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,
1035 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001036 return self.api(
1037 self.papi.dhcp_client_config,
1038 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001039 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001040 'client': {
1041 'sw_if_index': sw_if_index,
1042 'hostname': hostname,
1043 'id': client_id,
1044 'want_dhcp_event': want_dhcp_events,
1045 'set_broadcast_flag': set_broadcast_flag,
1046 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001047 })
1048
Neale Ranns32e1c012016-11-22 17:07:28 +00001049 def ip_mroute_add_del(self,
Neale Ranns097fa662018-05-01 05:17:55 -07001050 table_id,
1051 prefix,
Neale Ranns32e1c012016-11-22 17:07:28 +00001052 e_flags,
Neale Ranns097fa662018-05-01 05:17:55 -07001053 rpf_id,
1054 paths,
Neale Ranns32e1c012016-11-22 17:07:28 +00001055 is_add=1,
Neale Ranns097fa662018-05-01 05:17:55 -07001056 is_multipath=1):
Neale Ranns32e1c012016-11-22 17:07:28 +00001057 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001058 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001059 """
1060 return self.api(
1061 self.papi.ip_mroute_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001062 {
1063 'is_add': is_add,
1064 'is_multipath': is_multipath,
1065 'route': {
1066 'table_id': table_id,
1067 'entry_flags': e_flags,
1068 'rpf_id': rpf_id,
1069 'prefix': prefix,
1070 'n_paths': len(paths),
1071 'paths': paths,
1072 }
1073 })
1074
1075 def mfib_signal_dump(self):
1076 return self.api(self.papi.mfib_signal_dump, {})
1077
1078 def ip_mroute_dump(self, table_id, is_ip6=False):
1079 return self.api(self.papi.ip_mroute_dump,
1080 {'table': {
1081 'table_id': table_id,
1082 'is_ip6': is_ip6
1083 }})
Neale Ranns32e1c012016-11-22 17:07:28 +00001084
Filip Tehlar770e89e2017-01-31 10:39:16 +01001085 def lisp_enable_disable(self, is_enabled):
1086 return self.api(
1087 self.papi.lisp_enable_disable,
1088 {
1089 'is_en': is_enabled,
1090 })
1091
Ole Troane1ade682019-03-04 23:55:43 +01001092 def lisp_add_del_locator_set(self,
1093 ls_name,
1094 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001095 return self.api(
1096 self.papi.lisp_add_del_locator_set,
1097 {
1098 'is_add': is_add,
1099 'locator_set_name': ls_name
1100 })
1101
Ole Troane1ade682019-03-04 23:55:43 +01001102 def lisp_add_del_locator(self,
1103 ls_name,
1104 sw_if_index,
1105 priority=1,
1106 weight=1,
1107 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001108 return self.api(
1109 self.papi.lisp_add_del_locator,
1110 {
1111 'is_add': is_add,
1112 'locator_set_name': ls_name,
1113 'sw_if_index': sw_if_index,
1114 'priority': priority,
1115 'weight': weight
1116 })
1117
1118 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1119 return self.api(
1120 self.papi.lisp_locator_dump,
1121 {
1122 'is_index_set': is_index_set,
1123 'ls_name': ls_name,
1124 'ls_index': ls_index,
1125 })
1126
Ole Troane1ade682019-03-04 23:55:43 +01001127 def lisp_add_del_local_eid(self,
1128 ls_name,
1129 eid_type,
1130 eid,
1131 prefix_len,
1132 vni=0,
1133 key_id=0,
1134 key="",
1135 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001136 return self.api(
1137 self.papi.lisp_add_del_local_eid,
1138 {
1139 'locator_set_name': ls_name,
1140 'is_add': is_add,
1141 'eid_type': eid_type,
1142 'eid': eid,
1143 'prefix_len': prefix_len,
1144 'vni': vni,
1145 'key_id': key_id,
1146 'key': key
1147 })
1148
1149 def lisp_eid_table_dump(self,
1150 eid_set=0,
1151 prefix_length=0,
1152 vni=0,
1153 eid_type=0,
1154 eid=None,
1155 filter_opt=0):
1156 return self.api(
1157 self.papi.lisp_eid_table_dump,
1158 {
1159 'eid_set': eid_set,
1160 'prefix_length': prefix_length,
1161 'vni': vni,
1162 'eid_type': eid_type,
1163 'eid': eid,
1164 'filter': filter_opt,
1165 })
1166
Ole Troane1ade682019-03-04 23:55:43 +01001167 def lisp_add_del_remote_mapping(self,
1168 eid_type,
1169 eid,
1170 eid_prefix_len=0,
1171 vni=0,
1172 rlocs=[],
1173 rlocs_num=0,
1174 is_src_dst=0,
1175 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001176 return self.api(
1177 self.papi.lisp_add_del_remote_mapping,
1178 {
1179 'is_add': is_add,
1180 'eid_type': eid_type,
1181 'eid': eid,
1182 'eid_len': eid_prefix_len,
1183 'rloc_num': rlocs_num,
1184 'rlocs': rlocs,
1185 'vni': vni,
1186 'is_src_dst': is_src_dst,
1187 })
1188
Ole Troane1ade682019-03-04 23:55:43 +01001189 def lisp_add_del_adjacency(self,
1190 leid,
1191 reid,
1192 leid_len,
1193 reid_len,
1194 eid_type,
1195 is_add=1,
1196 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001197 return self.api(
1198 self.papi.lisp_add_del_adjacency,
1199 {
1200 'is_add': is_add,
1201 'vni': vni,
1202 'eid_type': eid_type,
1203 'leid': leid,
1204 'reid': reid,
1205 'leid_len': leid_len,
1206 'reid_len': reid_len,
1207 })
1208
Hongjun Nief486b12017-04-12 19:21:16 +08001209 def gtpu_add_del_tunnel(
1210 self,
1211 src_addr,
1212 dst_addr,
1213 is_add=1,
1214 is_ipv6=0,
1215 mcast_sw_if_index=0xFFFFFFFF,
1216 encap_vrf_id=0,
1217 decap_next_index=0xFFFFFFFF,
1218 teid=0):
1219 """
1220
1221 :param is_add: (Default value = 1)
1222 :param is_ipv6: (Default value = 0)
1223 :param src_addr:
1224 :param dst_addr:
1225 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1226 :param encap_vrf_id: (Default value = 0)
1227 :param decap_next_index: (Default value = 0xFFFFFFFF)
1228 :param teid: (Default value = 0)
1229
1230 """
1231 return self.api(self.papi.gtpu_add_del_tunnel,
1232 {'is_add': is_add,
1233 'is_ipv6': is_ipv6,
1234 'src_address': src_addr,
1235 'dst_address': dst_addr,
1236 'mcast_sw_if_index': mcast_sw_if_index,
1237 'encap_vrf_id': encap_vrf_id,
1238 'decap_next_index': decap_next_index,
1239 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001240
1241 def vxlan_gpe_add_del_tunnel(
1242 self,
1243 src_addr,
1244 dst_addr,
1245 mcast_sw_if_index=0xFFFFFFFF,
1246 is_add=1,
1247 is_ipv6=0,
1248 encap_vrf_id=0,
1249 decap_vrf_id=0,
1250 protocol=3,
1251 vni=0):
1252 """
1253
1254 :param local:
1255 :param remote:
1256 :param is_add: (Default value = 1)
1257 :param is_ipv6: (Default value = 0)
1258 :param encap_vrf_id: (Default value = 0)
1259 :param decap_vrf_id: (Default value = 0)
1260 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1261 :param protocol: (Default value = 3)
1262 :param vni: (Default value = 0)
1263
1264 """
1265 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1266 {'is_add': is_add,
1267 'is_ipv6': is_ipv6,
1268 'local': src_addr,
1269 'remote': dst_addr,
1270 'mcast_sw_if_index': mcast_sw_if_index,
1271 'encap_vrf_id': encap_vrf_id,
1272 'decap_vrf_id': decap_vrf_id,
1273 'protocol': protocol,
1274 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001275
Neale Ranns79a05f52018-09-11 07:39:43 -07001276 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1277 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001278 {'sw_if_index': sw_if_index,
1279 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001280
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001281 def pppoe_add_del_session(
1282 self,
1283 client_ip,
1284 client_mac,
1285 session_id=0,
1286 is_add=1,
1287 is_ipv6=0,
1288 decap_vrf_id=0):
1289 """
1290
1291 :param is_add: (Default value = 1)
1292 :param is_ipv6: (Default value = 0)
1293 :param client_ip:
1294 :param session_id: (Default value = 0)
1295 :param client_mac:
1296 :param decap_vrf_id: (Default value = 0)
1297
1298 """
1299 return self.api(self.papi.pppoe_add_del_session,
1300 {'is_add': is_add,
1301 'is_ipv6': is_ipv6,
1302 'session_id': session_id,
1303 'client_ip': client_ip,
1304 'decap_vrf_id': decap_vrf_id,
1305 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001306
Neale Ranns7c922dc2018-08-30 06:12:27 -07001307 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1308 return self.api(self.papi.sr_mpls_policy_add,
1309 {'bsid': bsid,
1310 'weight': weight,
1311 'type': type,
1312 'n_segments': len(segments),
1313 'segments': segments})
1314
1315 def sr_mpls_policy_del(self, bsid):
1316 return self.api(self.papi.sr_mpls_policy_del,
1317 {'bsid': bsid})
1318
Kris Michielsen91074432017-06-22 13:00:20 +02001319 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001320 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001321 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001322 nh_addr4,
1323 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001324 is_del=0,
1325 end_psp=0,
1326 sw_if_index=0xFFFFFFFF,
1327 vlan_index=0,
1328 fib_table=0,
1329 ):
1330 """ Add/del IPv6 SR local-SID.
1331
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001332 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001333 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1334 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001335 :param nh_addr4:
1336 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001337 :param is_del: (Default value = 0)
1338 :param end_psp: (Default value = 0)
1339 :param sw_if_index: (Default value = 0xFFFFFFFF)
1340 :param vlan_index: (Default value = 0)
1341 :param fib_table: (Default value = 0)
1342 """
1343 return self.api(
1344 self.papi.sr_localsid_add_del,
1345 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001346 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001347 'end_psp': end_psp,
1348 'behavior': behavior,
1349 'sw_if_index': sw_if_index,
1350 'vlan_index': vlan_index,
1351 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001352 'nh_addr4': nh_addr4,
1353 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001354 }
1355 )
1356
1357 def sr_policy_add(
1358 self,
1359 bsid_addr,
1360 weight=1,
1361 is_encap=1,
1362 type=0,
1363 fib_table=0,
1364 n_segments=0,
1365 segments=[]):
1366 """
1367 :param bsid_addr: bindingSID of the SR Policy
1368 :param weight: weight of the sid list. optional. (default: 1)
1369 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1370 (default: Encap)
1371 :param type: type/behavior of the SR policy. (default or spray) \
1372 (default: default)
1373 :param fib_table: VRF where to install the FIB entry for the BSID \
1374 (default: 0)
1375 :param n_segments: number of segments \
1376 (default: 0)
1377 :param segments: a vector of IPv6 address composing the segment list \
1378 (default: [])
1379 """
1380 return self.api(
1381 self.papi.sr_policy_add,
1382 {'bsid_addr': bsid_addr,
1383 'weight': weight,
1384 'is_encap': is_encap,
1385 'type': type,
1386 'fib_table': fib_table,
1387 'n_segments': n_segments,
1388 'segments': segments
1389 }
1390 )
1391
1392 def sr_policy_del(
1393 self,
1394 bsid_addr,
1395 sr_policy_index=0):
1396 """
1397 :param bsid: bindingSID of the SR Policy
1398 :param sr_policy_index: index of the sr policy (default: 0)
1399 """
1400 return self.api(
1401 self.papi.sr_policy_del,
1402 {'bsid_addr': bsid_addr,
1403 'sr_policy_index': sr_policy_index
1404 })
1405
1406 def sr_steering_add_del(
1407 self,
1408 is_del,
1409 bsid_addr,
1410 sr_policy_index,
1411 table_id,
1412 prefix_addr,
1413 mask_width,
1414 sw_if_index,
1415 traffic_type):
1416 """
1417 Steer traffic L2 and L3 traffic through a given SR policy
1418
1419 :param is_del: delete or add
1420 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1421 :param sr_policy: is the index of the SR Policy (alt to bsid)
1422 :param table_id: is the VRF where to install the FIB entry for the BSID
1423 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1424 :param mask_width: is the mask for L3 traffic type
1425 :param sw_if_index: is the incoming interface for L2 traffic
1426 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1427 """
1428 return self.api(
1429 self.papi.sr_steering_add_del,
1430 {'is_del': is_del,
1431 'bsid_addr': bsid_addr,
1432 'sr_policy_index': sr_policy_index,
1433 'table_id': table_id,
1434 'prefix_addr': prefix_addr,
1435 'mask_width': mask_width,
1436 'sw_if_index': sw_if_index,
1437 'traffic_type': traffic_type
1438 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001439
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001440 def acl_add_replace(self, acl_index, r, tag='',
1441 expected_retval=0):
1442 """Add/replace an ACL
1443 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1444 :param acl_rule r: ACL rules array.
1445 :param str tag: symbolic tag (description) for this ACL.
1446 :param int count: number of rules.
1447 """
1448 return self.api(self.papi.acl_add_replace,
1449 {'acl_index': acl_index,
1450 'r': r,
1451 'count': len(r),
1452 'tag': tag},
1453 expected_retval=expected_retval)
1454
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001455 def acl_del(self, acl_index, expected_retval=0):
1456 """
1457
1458 :param acl_index:
1459 :return:
1460 """
1461 return self.api(self.papi.acl_del,
1462 {'acl_index': acl_index},
1463 expected_retval=expected_retval)
1464
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001465 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1466 expected_retval=0):
1467 return self.api(self.papi.acl_interface_set_acl_list,
1468 {'sw_if_index': sw_if_index,
1469 'count': len(acls),
1470 'n_input': n_input,
1471 'acls': acls},
1472 expected_retval=expected_retval)
1473
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001474 def acl_interface_set_etype_whitelist(self, sw_if_index,
1475 n_input, whitelist,
1476 expected_retval=0):
1477 return self.api(self.papi.acl_interface_set_etype_whitelist,
1478 {'sw_if_index': sw_if_index,
1479 'count': len(whitelist),
1480 'n_input': n_input,
1481 'whitelist': whitelist},
1482 expected_retval=expected_retval)
1483
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001484 def acl_interface_add_del(self,
1485 sw_if_index,
1486 acl_index,
1487 is_add=1):
1488 """ Add/Delete ACL to/from interface
1489
1490 :param sw_if_index:
1491 :param acl_index:
1492 :param is_add: (Default value = 1)
1493 """
1494
1495 return self.api(self.papi.acl_interface_add_del,
1496 {'is_add': is_add,
1497 'is_input': 1,
1498 'sw_if_index': sw_if_index,
1499 'acl_index': acl_index})
1500
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001501 def acl_dump(self, acl_index, expected_retval=0):
1502 return self.api(self.papi.acl_dump,
1503 {'acl_index': acl_index},
1504 expected_retval=expected_retval)
1505
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001506 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1507 expected_retval=0):
1508 return self.api(self.papi.acl_interface_list_dump,
1509 {'sw_if_index': sw_if_index},
1510 expected_retval=expected_retval)
1511
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001512 def macip_acl_add(self, rules, tag=""):
1513 """ Add MACIP acl
1514
1515 :param rules: list of rules for given acl
1516 :param tag: acl tag
1517 """
1518
1519 return self.api(self.papi.macip_acl_add,
1520 {'r': rules,
1521 'count': len(rules),
1522 'tag': tag})
1523
Pavel Kotucek932f7412017-09-07 14:44:52 +02001524 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1525 """ Add MACIP acl
1526
1527 :param rules: list of rules for given acl
1528 :param tag: acl tag
1529 """
1530
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001531 return self.api(self.papi.macip_acl_add_replace,
1532 {'acl_index': acl_index,
1533 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001534 'count': len(rules),
1535 'tag': tag})
1536
Pavel Kotucek932f7412017-09-07 14:44:52 +02001537 def macip_acl_interface_add_del(self,
1538 sw_if_index,
1539 acl_index,
1540 is_add=1):
1541 """ Add MACIP acl to interface
1542
1543 :param sw_if_index:
1544 :param acl_index:
1545 :param is_add: (Default value = 1)
1546 """
1547
1548 return self.api(self.papi.macip_acl_interface_add_del,
1549 {'is_add': is_add,
1550 'sw_if_index': sw_if_index,
1551 'acl_index': acl_index})
1552
Pavel Kotucek932f7412017-09-07 14:44:52 +02001553 def macip_acl_dump(self, acl_index=4294967295):
1554 """ Return MACIP acl dump
1555 """
1556
1557 return self.api(
1558 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001559
1560 def policer_add_del(self,
1561 name,
1562 cir,
1563 eir,
1564 cb,
1565 eb,
1566 is_add=1,
1567 rate_type=0,
1568 round_type=0,
1569 ptype=0,
1570 color_aware=0,
1571 conform_action_type=1,
1572 conform_dscp=0,
1573 exceed_action_type=0,
1574 exceed_dscp=0,
1575 violate_action_type=0,
1576 violate_dscp=0):
1577 return self.api(self.papi.policer_add_del,
1578 {'name': name,
1579 'cir': cir,
1580 'eir': eir,
1581 'cb': cb,
1582 'eb': eb,
1583 'is_add': is_add,
1584 'rate_type': rate_type,
1585 'round_type': round_type,
1586 'type': ptype,
1587 'color_aware': color_aware,
1588 'conform_action_type': conform_action_type,
1589 'conform_dscp': conform_dscp,
1590 'exceed_action_type': exceed_action_type,
1591 'exceed_dscp': exceed_dscp,
1592 'violate_action_type': violate_action_type,
1593 'violate_dscp': violate_dscp})
1594
1595 def ip_punt_police(self,
1596 policer_index,
1597 is_ip6=0,
1598 is_add=1):
1599 return self.api(self.papi.ip_punt_police,
1600 {'policer_index': policer_index,
1601 'is_add': is_add,
1602 'is_ip6': is_ip6})
1603
1604 def ip_punt_redirect(self,
1605 rx_sw_if_index,
1606 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001607 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001608 is_add=1):
1609 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001610 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1611 'tx_sw_if_index': tx_sw_if_index,
1612 'nh': address},
1613 'is_add': is_add})
1614
1615 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1616 return self.api(self.papi.ip_punt_redirect_dump,
1617 {'sw_if_index': sw_if_index,
1618 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001619
1620 def bier_table_add_del(self,
1621 bti,
1622 mpls_label,
1623 is_add=1):
1624 """ BIER Table add/del """
1625 return self.api(
1626 self.papi.bier_table_add_del,
1627 {'bt_tbl_id': {"bt_set": bti.set_id,
1628 "bt_sub_domain": bti.sub_domain_id,
1629 "bt_hdr_len_id": bti.hdr_len_id},
1630 'bt_label': mpls_label,
1631 'bt_is_add': is_add})
1632
1633 def bier_table_dump(self):
1634 return self.api(self.papi.bier_table_dump, {})
1635
1636 def bier_route_add_del(self,
1637 bti,
1638 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001639 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001640 is_add=1,
1641 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001642 """ BIER Route add/del """
1643 return self.api(
1644 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001645 {
1646 'br_route': {
1647 'br_tbl_id': {"bt_set": bti.set_id,
1648 "bt_sub_domain": bti.sub_domain_id,
1649 "bt_hdr_len_id": bti.hdr_len_id},
1650 'br_bp': bp,
1651 'br_n_paths': len(paths),
1652 'br_paths': paths,
1653 },
1654 'br_is_add': is_add,
1655 'br_is_replace': is_replace
1656 })
Neale Rannsd792d9c2017-10-21 10:53:20 -07001657
1658 def bier_route_dump(self, bti):
1659 return self.api(
1660 self.papi.bier_route_dump,
1661 {'br_tbl_id': {"bt_set": bti.set_id,
1662 "bt_sub_domain": bti.sub_domain_id,
1663 "bt_hdr_len_id": bti.hdr_len_id}})
1664
1665 def bier_imp_add(self,
1666 bti,
1667 src,
1668 ibytes,
1669 is_add=1):
1670 """ BIER Imposition Add """
1671 return self.api(
1672 self.papi.bier_imp_add,
1673 {'bi_tbl_id': {"bt_set": bti.set_id,
1674 "bt_sub_domain": bti.sub_domain_id,
1675 "bt_hdr_len_id": bti.hdr_len_id},
1676 'bi_src': src,
1677 'bi_n_bytes': len(ibytes),
1678 'bi_bytes': ibytes})
1679
1680 def bier_imp_del(self, bi_index):
1681 """ BIER Imposition del """
1682 return self.api(
1683 self.papi.bier_imp_del,
1684 {'bi_index': bi_index})
1685
1686 def bier_imp_dump(self):
1687 return self.api(self.papi.bier_imp_dump, {})
1688
1689 def bier_disp_table_add_del(self,
1690 bdti,
1691 is_add=1):
1692 """ BIER Disposition Table add/del """
1693 return self.api(
1694 self.papi.bier_disp_table_add_del,
1695 {'bdt_tbl_id': bdti,
1696 'bdt_is_add': is_add})
1697
1698 def bier_disp_table_dump(self):
1699 return self.api(self.papi.bier_disp_table_dump, {})
1700
1701 def bier_disp_entry_add_del(self,
1702 bdti,
1703 bp,
1704 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001705 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001706 next_hop,
1707 next_hop_tbl_id=0,
1708 next_hop_rpf_id=~0,
1709 next_hop_is_ip4=1,
1710 is_add=1):
1711 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001712 lstack = []
1713 while (len(lstack) < 16):
1714 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001715 return self.api(
1716 self.papi.bier_disp_entry_add_del,
1717 {'bde_tbl_id': bdti,
1718 'bde_bp': bp,
1719 'bde_payload_proto': payload_proto,
1720 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -04001721 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001722 'rpf_id': next_hop_rpf_id,
1723 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001724 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001725 'bde_is_add': is_add})
1726
1727 def bier_disp_entry_dump(self, bdti):
1728 return self.api(
1729 self.papi.bier_disp_entry_dump,
1730 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001731
Florin Coras3ea6ce22017-12-11 09:09:05 -08001732 def session_enable_disable(self, is_enabled):
1733 return self.api(
1734 self.papi.session_enable_disable,
1735 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001736
1737 def ipsec_spd_add_del(self, spd_id, is_add=1):
1738 """ SPD add/del - Wrapper to add or del ipsec SPD
1739 Sample CLI : 'ipsec spd add 1'
1740
1741 :param spd_id - SPD ID to be created in the vpp . mandatory
1742 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1743 optional
1744 :returns: reply from the API
1745 """
1746 return self.api(
1747 self.papi.ipsec_spd_add_del, {
1748 'spd_id': spd_id, 'is_add': is_add})
1749
Neale Ranns311124e2019-01-24 04:52:25 -08001750 def ipsec_spds_dump(self):
1751 return self.api(self.papi.ipsec_spds_dump, {})
1752
“mystarrocks”23f0c452017-12-11 07:11:51 -08001753 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1754 """ IPSEC interface SPD add/del - \
1755 Wrapper to associate/disassociate SPD to interface in VPP
1756 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1757
1758 :param spd_id - SPD ID to associate with the interface . mandatory
1759 :param sw_if_index - Interface Index which needs to ipsec \
1760 association mandatory
1761 :param is_add - add(1) or del(0) association with interface \
1762 (Default 1 - add) . optional
1763 :returns: reply from the API
1764 """
1765 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001766 self.papi.ipsec_interface_add_del_spd,
1767 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001768
Neale Ranns311124e2019-01-24 04:52:25 -08001769 def ipsec_spd_interface_dump(self, spd_index=None):
1770 return self.api(self.papi.ipsec_spd_interface_dump,
1771 {'spd_index': spd_index if spd_index else 0,
1772 'spd_index_valid': 1 if spd_index else 0})
1773
Neale Ranns17dcec02019-01-09 21:22:20 -08001774 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001775 sad_id,
1776 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001777 integrity_algorithm,
1778 integrity_key,
1779 crypto_algorithm,
1780 crypto_key,
1781 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001782 tunnel_src_address='',
1783 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001784 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001785 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001786 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001787 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001788 :param sad_id: security association ID
1789 :param spi: security param index of the SA in decimal
1790 :param integrity_algorithm:
1791 :param integrity_key:
1792 :param crypto_algorithm:
1793 :param crypto_key:
1794 :param protocol: AH(0) or ESP(1) protocol
1795 :param tunnel_src_address: tunnel mode outer src address
1796 :param tunnel_dst_address: tunnel mode outer dst address
1797 :param is_add:
1798 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001799 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1800 crypto and ipsec algorithms
1801 """
1802 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001803 self.papi.ipsec_sad_entry_add_del,
1804 {
1805 'is_add': is_add,
1806 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001807 {
1808 'sad_id': sad_id,
1809 'spi': spi,
1810 'tunnel_src': tunnel_src_address,
1811 'tunnel_dst': tunnel_dst_address,
1812 'protocol': protocol,
1813 'integrity_algorithm': integrity_algorithm,
1814 'integrity_key': {
1815 'length': len(integrity_key),
1816 'data': integrity_key,
1817 },
1818 'crypto_algorithm': crypto_algorithm,
1819 'crypto_key': {
1820 'length': len(crypto_key),
1821 'data': crypto_key,
1822 },
1823 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001824 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001825 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001826 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001827
Neale Ranns311124e2019-01-24 04:52:25 -08001828 def ipsec_sa_dump(self, sa_id=None):
1829 return self.api(self.papi.ipsec_sa_dump,
1830 {'sa_id': sa_id if sa_id else 0xffffffff})
1831
Neale Ranns17dcec02019-01-09 21:22:20 -08001832 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001833 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001834 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001835 local_address_start,
1836 local_address_stop,
1837 remote_address_start,
1838 remote_address_stop,
1839 local_port_start=0,
1840 local_port_stop=65535,
1841 remote_port_start=0,
1842 remote_port_stop=65535,
1843 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001844 policy=0,
1845 priority=100,
1846 is_outbound=1,
1847 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001848 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001849 is_ip_any=0):
1850 """ IPSEC policy SPD add/del -
1851 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001852 :param spd_id: SPD ID for the policy
1853 :param local_address_start: local-ip-range start address
1854 :param local_address_stop : local-ip-range stop address
1855 :param remote_address_start: remote-ip-range start address
1856 :param remote_address_stop : remote-ip-range stop address
1857 :param local_port_start: (Default value = 0)
1858 :param local_port_stop: (Default value = 65535)
1859 :param remote_port_start: (Default value = 0)
1860 :param remote_port_stop: (Default value = 65535)
1861 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1862 :param sa_id: Security Association ID for mapping it to SPD
1863 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1864 (Default value = 0)
1865 :param priority: value for the spd action (Default value = 100)
1866 :param is_outbound: flag for inbound(0) or outbound(1)
1867 (Default value = 1)
1868 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001869 """
1870 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001871 self.papi.ipsec_spd_entry_add_del,
1872 {
1873 'is_add': is_add,
1874 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001875 {
1876 'spd_id': spd_id,
1877 'sa_id': sa_id,
1878 'local_address_start': local_address_start,
1879 'local_address_stop': local_address_stop,
1880 'remote_address_start': remote_address_start,
1881 'remote_address_stop': remote_address_stop,
1882 'local_port_start': local_port_start,
1883 'local_port_stop': local_port_stop,
1884 'remote_port_start': remote_port_start,
1885 'remote_port_stop': remote_port_stop,
1886 'protocol': protocol,
1887 'policy': policy,
1888 'priority': priority,
1889 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +01001890 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001891 })
Florin Corasb795bd02017-12-14 11:30:48 -08001892
Neale Ranns311124e2019-01-24 04:52:25 -08001893 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1894 return self.api(self.papi.ipsec_spd_dump,
1895 {'spd_id': spd_id,
1896 'sa_id': sa_id})
1897
Klement Sekera31da2e32018-06-24 22:49:55 +02001898 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1899 remote_spi, crypto_alg, local_crypto_key,
1900 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001901 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001902 anti_replay=1, renumber=0,
1903 udp_encap=0, show_instance=0):
Klement Sekera31da2e32018-06-24 22:49:55 +02001904 return self.api(
1905 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001906 {
1907 'local_ip': local_ip,
1908 'remote_ip': remote_ip,
1909 'local_spi': local_spi,
1910 'remote_spi': remote_spi,
1911 'crypto_alg': crypto_alg,
1912 'local_crypto_key_len': len(local_crypto_key),
1913 'local_crypto_key': local_crypto_key,
1914 'remote_crypto_key_len': len(remote_crypto_key),
1915 'remote_crypto_key': remote_crypto_key,
1916 'integ_alg': integ_alg,
1917 'local_integ_key_len': len(local_integ_key),
1918 'local_integ_key': local_integ_key,
1919 'remote_integ_key_len': len(remote_integ_key),
1920 'remote_integ_key': remote_integ_key,
1921 'is_add': is_add,
1922 'esn': esn,
1923 'anti_replay': anti_replay,
1924 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001925 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001926 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001927 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001928 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001929
Klement Sekerab4d30532018-11-08 13:00:02 +01001930 def ipsec_select_backend(self, protocol, index):
1931 return self.api(self.papi.ipsec_select_backend,
1932 {'protocol': protocol, 'index': index})
1933
1934 def ipsec_backend_dump(self):
1935 return self.api(self.papi.ipsec_backend_dump, {})
1936
Ole Troane1ade682019-03-04 23:55:43 +01001937 def app_namespace_add_del(self,
1938 namespace_id,
1939 ip4_fib_id=0,
1940 ip6_fib_id=0,
1941 sw_if_index=0xFFFFFFFF,
1942 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001943 return self.api(
1944 self.papi.app_namespace_add_del,
1945 {'secret': secret,
1946 'sw_if_index': sw_if_index,
1947 'ip4_fib_id': ip4_fib_id,
1948 'ip6_fib_id': ip6_fib_id,
1949 'namespace_id': namespace_id,
1950 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001951
Neale Ranns50f0ac02019-05-15 02:13:37 -07001952 def punt_socket_register(self, reg, pathname,
1953 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001954 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001955 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001956 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001957 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001958 'pathname': pathname})
1959
Neale Ranns50f0ac02019-05-15 02:13:37 -07001960 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001961 """ Unregister punt socket """
1962 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001963 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001964
Neale Ranns4ba67722019-02-28 11:11:39 +00001965 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001966 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001967 """ GBP endpoint Add """
1968 return self.api(self.papi.gbp_endpoint_add,
1969 {'endpoint': {
1970 'sw_if_index': sw_if_index,
1971 'ips': ips,
1972 'n_ips': len(ips),
1973 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001974 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001975 'flags': flags,
1976 'tun': {
1977 'src': tun_src,
1978 'dst': tun_dst,
1979 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001980
1981 def gbp_endpoint_del(self, handle):
1982 """ GBP endpoint Del """
1983 return self.api(self.papi.gbp_endpoint_del,
1984 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001985
1986 def gbp_endpoint_dump(self):
1987 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01001988 return self.api(self.papi.gbp_endpoint_dump,
1989 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001990
Neale Ranns4ba67722019-02-28 11:11:39 +00001991 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001992 rd, uplink_sw_if_index,
1993 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001994 """ GBP endpoint group Add """
1995 return self.api(self.papi.gbp_endpoint_group_add,
1996 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001997 {
1998 'uplink_sw_if_index': uplink_sw_if_index,
1999 'bd_id': bd,
2000 'rd_id': rd,
2001 'vnid': vnid,
2002 'sclass': sclass,
2003 'retention': retention
2004 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002005
Neale Ranns4ba67722019-02-28 11:11:39 +00002006 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002007 """ GBP endpoint group Del """
2008 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002009 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002010
Neale Ranns160c9232019-06-19 06:25:56 -07002011 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002012 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002013 uu_fwd_sw_if_index,
2014 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002015 """ GBP bridge-domain Add """
2016 return self.api(self.papi.gbp_bridge_domain_add,
2017 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002018 {
2019 'flags': flags,
2020 'bvi_sw_if_index': bvi_sw_if_index,
2021 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2022 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07002023 'bd_id': bd_id,
2024 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01002025 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002026
2027 def gbp_bridge_domain_del(self, bd_id):
2028 """ GBP bridge-domain Del """
2029 return self.api(self.papi.gbp_bridge_domain_del,
2030 {'bd_id': bd_id})
2031
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002032 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07002033 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002034 ip4_table_id,
2035 ip6_table_id,
2036 ip4_uu_sw_if_index,
2037 ip6_uu_sw_if_index):
2038 """ GBP route-domain Add """
2039 return self.api(self.papi.gbp_route_domain_add,
2040 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002041 {
Neale Ranns160c9232019-06-19 06:25:56 -07002042 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01002043 'ip4_table_id': ip4_table_id,
2044 'ip6_table_id': ip6_table_id,
2045 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2046 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2047 'rd_id': rd_id
2048 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002049
2050 def gbp_route_domain_del(self, rd_id):
2051 """ GBP route-domain Del """
2052 return self.api(self.papi.gbp_route_domain_del,
2053 {'rd_id': rd_id})
2054
Neale Ranns4ba67722019-02-28 11:11:39 +00002055 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002056 """ GBP recirc Add/Del """
2057 return self.api(self.papi.gbp_recirc_add_del,
2058 {'is_add': is_add,
2059 'recirc': {
2060 'is_ext': is_ext,
2061 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002062 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002063
2064 def gbp_recirc_dump(self):
2065 """ GBP recirc Dump """
2066 return self.api(self.papi.gbp_recirc_dump, {})
2067
Benoît Ganneba6abfa2019-07-01 17:10:41 +02002068 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08002069 """ GBP recirc Add/Del """
2070 return self.api(self.papi.gbp_ext_itf_add_del,
2071 {'is_add': is_add,
2072 'ext_itf': {
2073 'sw_if_index': sw_if_index,
2074 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02002075 'rd_id': rd_id,
2076 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08002077
2078 def gbp_ext_itf_dump(self):
2079 """ GBP recirc Dump """
2080 return self.api(self.papi.gbp_ext_itf_dump, {})
2081
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002082 def gbp_subnet_add_del(self, is_add, rd_id,
2083 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002084 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002085 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002086 """ GBP Subnet Add/Del """
2087 return self.api(self.papi.gbp_subnet_add_del,
2088 {'is_add': is_add,
2089 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002090 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002091 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002092 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002093 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002094 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002095
2096 def gbp_subnet_dump(self):
2097 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002098 return self.api(self.papi.gbp_subnet_dump,
2099 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002100
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002101 def gbp_contract_dump(self):
2102 """ GBP contract Dump """
2103 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002104
Neale Ranns8da9fc62019-03-04 14:08:11 -08002105 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002106 """ GBP VXLAN tunnel add """
2107 return self.api(self.papi.gbp_vxlan_tunnel_add,
2108 {
2109 'tunnel': {
2110 'vni': vni,
2111 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002112 'bd_rd_id': bd_rd_id,
2113 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002114 }
2115 })
2116
2117 def gbp_vxlan_tunnel_del(self, vni):
2118 """ GBP VXLAN tunnel del """
2119 return self.api(self.papi.gbp_vxlan_tunnel_del,
2120 {
2121 'vni': vni,
2122 })
2123
2124 def gbp_vxlan_tunnel_dump(self):
2125 """ GBP VXLAN tunnel add/del """
2126 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2127
Neale Ranns039cbfe2018-02-27 03:45:38 -08002128 def qos_egress_map_update(self, id, outputs):
2129 """ QOS egress map update """
2130 return self.api(self.papi.qos_egress_map_update,
2131 {'map_id': id,
2132 'rows': outputs})
2133
2134 def qos_egress_map_delete(self, id):
2135 """ QOS egress map delete """
2136 return self.api(self.papi.qos_egress_map_delete,
2137 {'map_id': id})
2138
2139 def qos_mark_enable_disable(self, sw_if_index,
2140 output_source,
2141 map_id,
2142 enable):
2143 """ QOS Mark Enable/Disable """
2144 return self.api(self.papi.qos_mark_enable_disable,
2145 {'map_id': map_id,
2146 'sw_if_index': sw_if_index,
2147 'output_source': output_source,
2148 'enable': enable})
2149
Neale Ranns947ea622018-06-07 23:48:20 -07002150 def igmp_enable_disable(self, sw_if_index, enable, host):
2151 """ Enable/disable IGMP on a given interface """
2152 return self.api(self.papi.igmp_enable_disable,
2153 {'enable': enable,
2154 'mode': host,
2155 'sw_if_index': sw_if_index})
2156
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002157 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2158 """ Add/del IGMP proxy device """
2159 return self.api(self.papi.igmp_proxy_device_add_del,
2160 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2161 'add': add})
2162
2163 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2164 """ Add/del interface to/from IGMP proxy device """
2165 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2166 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2167 'add': add})
2168
Neale Ranns947ea622018-06-07 23:48:20 -07002169 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002170 """ Listen for new (S,G) on specified interface
2171
2172 :param enable: add/del
2173 :param sw_if_index: interface sw index
2174 :param saddr: source ip4 addr
2175 :param gaddr: group ip4 addr
2176 """
2177 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002178 {
2179 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002180 {
2181 'filter': filter,
2182 'sw_if_index': sw_if_index,
2183 'n_srcs': len(saddrs),
2184 'saddrs': saddrs,
2185 'gaddr': gaddr
2186 }
Neale Ranns947ea622018-06-07 23:48:20 -07002187 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002188
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002189 def igmp_clear_interface(self, sw_if_index):
2190 """ Remove all (S,G)s from specified interface
2191 doesn't send IGMP report!
2192 """
2193 return self.api(
2194 self.papi.igmp_clear_interface, {
2195 'sw_if_index': sw_if_index})
2196
2197 def want_igmp_events(self, enable=1):
2198 return self.api(self.papi.want_igmp_events, {'enable': enable,
2199 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002200
2201 def bond_create(
2202 self,
2203 mode,
2204 lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002205 numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08002206 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002207 mac_address='',
2208 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002209 """
2210 :param mode: mode
2211 :param lb: load balance
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002212 :param numa_only: tx on local numa node for lacp mode
Steven9cd2d7a2017-12-20 12:43:01 -08002213 :param use_custom_mac: use custom mac
2214 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002215 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002216 """
2217 return self.api(
2218 self.papi.bond_create,
2219 {'mode': mode,
2220 'lb': lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04002221 'numa_only': numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08002222 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002223 'mac_address': mac_address,
2224 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002225 })
2226
Neale Ranns17ff3c12018-07-04 10:24:24 -07002227 def pipe_delete(self, parent_sw_if_index):
2228 return self.api(self.papi.pipe_delete,
2229 {'parent_sw_if_index': parent_sw_if_index})
2230
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002231 def svs_table_add_del(self, af, table_id, is_add=1):
2232 return self.api(self.papi.svs_table_add_del,
2233 {
2234 'table_id': table_id,
2235 'is_add': is_add,
2236 'af': af,
2237 })
2238
2239 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2240 return self.api(self.papi.svs_route_add_del,
2241 {
2242 'table_id': table_id,
2243 'source_table_id': src_table_id,
2244 'prefix': prefix,
2245 'is_add': is_add,
2246 })
2247
2248 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2249 return self.api(self.papi.svs_enable_disable,
2250 {
2251 'af': af,
2252 'table_id': table_id,
2253 'sw_if_index': sw_if_index,
2254 'is_enable': is_enable,
2255 })