blob: 291a904dd6fa64446089d6a78ee74513380c0f74 [file] [log] [blame]
Ole Troan9a475372019-03-05 16:58:24 +01001# NB NB NB NB NB NB NB NB NB NB NB
2#
3# NOTE: The API binary wrappers in this file are in the process of being
4# deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using
5# named arguments directly instead.
6#
7
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02009import time
Klement Sekerae4504c62016-12-08 10:16:41 +010010from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +020011
Ole Troanf159f582019-02-28 20:20:47 +010012from six import moves, iteritems
Paul Vinciguerra19542292019-03-17 17:34:46 -070013from vpp_papi import VPPApiClient, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070015from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020016
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017
Neale Ranns039cbfe2018-02-27 03:45:38 -080018class QOS_SOURCE:
19 EXT = 0
20 VLAN = 1
21 MPLS = 2
22 IP = 3
23
24
Matus Fabianb4515b42018-11-19 04:25:32 -080025class SYSLOG_SEVERITY:
26 EMERG = 0
27 ALERT = 1
28 CRIT = 2
29 ERR = 3
30 WARN = 4
31 NOTICE = 5
32 INFO = 6
33 DBG = 7
34
Ole Troan9a475372019-03-05 16:58:24 +010035
Ole Troanf159f582019-02-28 20:20:47 +010036#
37# Dictionary keyed on message name to override default values for
38# named parameters
39#
Ole Troan9a475372019-03-05 16:58:24 +010040defaultmapping = {
41 'map_add_domain': {'mtu': 1280},
42 'syslog_set_sender': {'collector_port': 514,
43 'max_msg_size': 480},
44 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
45 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
46 'app_namespace_add_del': {'sw_if_index': 4294967295, },
47 'bd_ip_mac_add_del': {'is_add': 1, },
48 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
49 'is_add': 1, },
50 'bier_disp_table_add_del': {'is_add': 1, },
51 'bier_imp_add': {'is_add': 1, },
52 'bier_route_add_del': {'is_add': 1, },
53 'bier_table_add_del': {'is_add': 1, },
54 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
55 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070056 'bvi_create': {'user_instance': 4294967295, },
57 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010058 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
59 'nbuckets': 2, 'memory_size': 2097152,
60 'next_table_index': 4294967295,
61 'miss_next_index': 4294967295, },
62 'dhcp6_client_enable_disable': {'enable': 1, },
63 'dhcp6_clients_enable_disable': {'enable': 1, },
64 'dhcp6_pd_client_enable_disable': {'enable': 1, },
65 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
66 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
67 'dhcp_proxy_config': {'is_add': 1, },
68 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010069 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
70 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
71 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000072 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010073 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
74 'decap_next_index': 4294967295, },
75 'input_acl_set_interface': {'ip4_table_index': 4294967295,
76 'ip6_table_index': 4294967295,
77 'l2_table_index': 4294967295, },
78 'ip6_add_del_address_using_prefix': {'is_add': 1, },
79 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
80 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
81 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
82 'next_hop_id': 4294967295,
83 'classify_table_index': 4294967295, 'is_add': 1, },
84 'ip_mroute_add_del': {'is_add': 1, },
85 'ip_neighbor_add_del': {'is_add': 1, },
86 'ip_punt_police': {'is_add': 1, },
87 'ip_punt_redirect': {'is_add': 1, },
88 'ip_table_add_del': {'is_add': 1, },
89 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
90 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
91 'ipsec_interface_add_del_spd': {'is_add': 1, },
92 'ipsec_sad_entry_add_del': {'is_add': 1, },
93 'ipsec_spd_add_del': {'is_add': 1, },
94 'ipsec_spd_dump': {'sa_id': 4294967295, },
95 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
96 'remote_port_stop': 65535, 'priority': 100,
97 'is_outbound': 1,
98 'is_add': 1, },
99 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
100 'l2_emulation': {'enable': 1, },
101 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700102 'lb_conf': {'sticky_buckets_per_core': 4294967295,
103 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100104 'lisp_add_del_adjacency': {'is_add': 1, },
105 'lisp_add_del_local_eid': {'is_add': 1, },
106 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
107 'lisp_add_del_locator_set': {'is_add': 1, },
108 'lisp_add_del_remote_mapping': {'is_add': 1, },
109 'macip_acl_add_replace': {'acl_index': 4294967295, },
110 'macip_acl_dump': {'acl_index': 4294967295, },
111 'macip_acl_interface_add_del': {'is_add': 1, },
112 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100113 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
114 'mr_next_hop_weight': 1,
115 'mr_next_hop_via_label': 1048576,
116 'mr_is_add': 1,
117 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100118 'mpls_table_add_del': {'is_add': 1, },
119 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
120 'next_hop_weight': 1,
121 'next_hop_via_label': 1048576,
122 'is_add': 1, },
123 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100124 'output_acl_set_interface': {'ip4_table_index': 4294967295,
125 'ip6_table_index': 4294967295,
126 'l2_table_index': 4294967295, },
127 'pppoe_add_del_session': {'is_add': 1, },
128 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
129 'proxy_arp_add_del': {'is_add': 1, },
130 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
131 'punt_socket_register': {'protocol': 17, 'header_version': 1,
132 'is_ip4': 1, },
133 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
134 'punt_socket_dump': {'is_ip6': 1, },
135 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
136 'proto': 1, },
137 'set_ipfix_exporter': {'collector_port': 4739, },
138 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
139 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
140 'svs_enable_disable': {'is_enable': 1, },
141 'svs_route_add_del': {'is_add': 1, },
142 'svs_table_add_del': {'is_add': 1, },
143 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700144 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100145 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
146 'pref_lifetime': 4294967295, },
147 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
148 'sw_interface_set_l2_bridge': {'enable': 1, },
149 'sw_interface_set_mpls_enable': {'enable': 1, },
150 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
151 'sw_interface_set_unnumbered': {'is_add': 1, },
152 'sw_interface_span_enable_disable': {'state': 1, },
153 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
154 'decap_next_index': 4294967295,
155 'instance': 4294967295, },
156 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
157 'instance': 4294967295, },
158 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
159 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
160 'protocol': 3, },
161 'want_bfd_events': {'enable_disable': 1, },
162 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
163 'want_dhcp6_reply_events': {'enable_disable': 1, },
164 'want_igmp_events': {'enable': 1, },
165 'want_interface_events': {'enable_disable': 1, },
166 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
167 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
168 'want_ip6_ra_events': {'enable_disable': 1, },
169 'want_l2_macs_events': {'enable_disable': 1, },
170}
Ole Troanf159f582019-02-28 20:20:47 +0100171
Matus Fabianb4515b42018-11-19 04:25:32 -0800172
Klement Sekera73884482017-02-23 09:26:30 +0100173class UnexpectedApiReturnValueError(Exception):
174 """ exception raised when the API return value is unexpected """
175 pass
176
177
Klement Sekeraf62ae122016-10-11 11:47:09 +0200178class VppPapiProvider(object):
179 """VPP-api provider using vpp-papi
180
181 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200182 """
183
Klement Sekerae0545ef2017-01-25 08:00:40 +0100184 _zero, _negative = range(2)
185
Klement Sekera611864f2018-09-26 11:19:00 +0200186 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800187 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200188 self.name = name
189 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100190 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100191 self._expect_api_retval = self._zero
192 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100193
Paul Vinciguerra19542292019-03-17 17:34:46 -0700194 # install_dir is a class attribute. We need to set it before
195 # calling the constructor.
196 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800197
Ole Troan4ff09ae2019-04-15 11:27:22 +0200198 use_socket = False
199 try:
200 if os.environ['SOCKET'] == '1':
201 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400202 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200203 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700204
205 self.vpp = VPPApiClient(logger=test_class.logger,
206 read_timeout=read_timeout,
207 use_socket=use_socket,
208 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100209 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210
Klement Sekerae0545ef2017-01-25 08:00:40 +0100211 def __enter__(self):
212 return self
213
Klement Sekera7d6afb32018-11-08 11:52:04 +0100214 def assert_negative_api_retval(self):
215 """ Expect API failure - used with with, e.g.:
216 with self.vapi.assert_negative_api_retval():
217 self.vapi.<api call expected to fail>
218 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100219 self._expect_stack.append(self._expect_api_retval)
220 self._expect_api_retval = self._negative
221 return self
222
Klement Sekera7d6afb32018-11-08 11:52:04 +0100223 def assert_zero_api_retval(self):
224 """ Expect API success - used with with, e.g.:
225 with self.vapi.assert_negative_api_retval():
226 self.vapi.<api call expected to succeed>
227
228 note: this is useful only inside another with block
229 as success is the default expected value
230 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100231 self._expect_stack.append(self._expect_api_retval)
232 self._expect_api_retval = self._zero
233 return self
234
235 def __exit__(self, exc_type, exc_value, traceback):
236 self._expect_api_retval = self._expect_stack.pop()
237
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238 def register_hook(self, hook):
239 """Replace hook registration with new hook
240
241 :param hook:
242
243 """
244 self.hook = hook
245
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200246 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100247 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200248 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100249 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 return e
251
252 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100253 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100254 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100255 self.test_class.logger.debug("Expecting event '%s' within %ss",
256 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300257 else:
258 self.test_class.logger.debug("Expecting event within %ss",
259 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100260 if self._events:
261 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200262 limit = time.time() + timeout
263 while time.time() < limit:
264 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100265 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200266 if name and type(e).__name__ != name:
267 raise Exception(
268 "Unexpected event received: %s, expected: %s" %
269 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100270 self.test_class.logger.debug("Returning event %s:%s" %
271 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200272 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700273 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200274 raise Exception("Event did not occur within timeout")
275
276 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100277 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200278 # FIXME use the name instead of relying on type(e).__name__ ?
279 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100280 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200281 self._events.append(event)
282
Ole Troanf159f582019-02-28 20:20:47 +0100283 def factory(self, name, apifn):
284 def f(*a, **ka):
285 fields = apifn._func.msg.fields
286
287 # add positional and kw arguments
288 d = ka
289 for i, o in enumerate(fields[3:]):
290 try:
291 d[o] = a[i]
292 except:
293 break
294
295 # Default override
296 if name in defaultmapping:
297 for k, v in iteritems(defaultmapping[name]):
298 if k in d:
299 continue
300 d[k] = v
301 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100302
Ole Troanf159f582019-02-28 20:20:47 +0100303 return f
304
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800305 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100306 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800307 method = super(VppPapiProvider, self).__getattribute__(name)
308 except AttributeError:
309 method = self.factory(name, getattr(self.papi, name))
310 # lazily load the method so we don't need to call factory
311 # again for this name.
312 setattr(self, name, method)
313 return method
Ole Troanf159f582019-02-28 20:20:47 +0100314
Klement Sekeraf62ae122016-10-11 11:47:09 +0200315 def connect(self):
316 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100317 self.vpp.connect(self.name, self.shm_prefix)
318 self.papi = self.vpp.api
319 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200320
321 def disconnect(self):
322 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100323 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200324
325 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100326 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200327 Call the appropriate hooks before and after the API call
328
329 :param api_fn: API function to call
330 :param api_args: tuple of API function arguments
331 :param expected_retval: Expected return value (Default value = 0)
332 :returns: reply from the API
333
334 """
335 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100336 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100337 if self._expect_api_retval == self._negative:
338 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100339 msg = "API call passed unexpectedly: expected negative " \
340 "return value instead of %d in %s" % \
341 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100342 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100343 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100344 elif self._expect_api_retval == self._zero:
345 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100346 msg = "API call failed, expected %d return value instead " \
347 "of %d in %s" % (expected_retval, reply.retval,
348 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100349 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100350 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100351 else:
352 raise Exception("Internal error, unexpected value for "
353 "self._expect_api_retval %s" %
354 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200355 self.hook.after_api(api_fn.__name__, api_args)
356 return reply
357
358 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100359 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200360
361 :param cli: CLI to execute
362 :returns: CLI output
363
364 """
365 self.hook.before_cli(cli)
366 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100367 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200368 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200369 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100370 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200371
Jan49c0fca2016-10-26 15:44:27 +0200372 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100373 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200374
375 :param cli: CLI to execute
376 :returns: CLI output
377 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600378 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200379
Neale Ranns37029302018-08-10 05:30:06 -0700380 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300381 return self.api(self.papi.want_ip4_arp_events,
382 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700383 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300384 'pid': os.getpid(), })
385
Neale Ranns37029302018-08-10 05:30:06 -0700386 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300387 return self.api(self.papi.want_ip6_nd_events,
388 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700389 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300390 'pid': os.getpid(), })
391
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100392 def want_ip6_ra_events(self, enable_disable=1):
393 return self.api(self.papi.want_ip6_ra_events,
394 {'enable_disable': enable_disable,
395 'pid': os.getpid(), })
396
397 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
398 mrc=0, mrd=0):
399 return self.api(self.papi.ip6nd_send_router_solicitation,
400 {'irt': irt,
401 'mrt': mrt,
402 'mrc': mrc,
403 'mrd': mrd,
404 'sw_if_index': sw_if_index})
405
Juraj Slobodab3f90502018-10-04 15:15:16 +0200406 def want_interface_events(self, enable_disable=1):
407 return self.api(self.papi.want_interface_events,
408 {'enable_disable': enable_disable,
409 'pid': os.getpid(), })
410
Ole Troane1ade682019-03-04 23:55:43 +0100411 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
412 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300413 return self.api(self.papi.want_l2_macs_events,
414 {'enable_disable': enable_disable,
415 'scan_delay': scan_delay,
416 'max_macs_in_event': max_macs_in_event,
417 'learn_limit': learn_limit,
418 'pid': os.getpid(), })
419
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200420 def want_dhcp6_reply_events(self, enable_disable=1):
421 return self.api(self.papi.want_dhcp6_reply_events,
422 {'enable_disable': enable_disable,
423 'pid': os.getpid()})
424
Juraj Sloboda81119e82018-05-25 14:02:20 +0200425 def want_dhcp6_pd_reply_events(self, enable_disable=1):
426 return self.api(self.papi.want_dhcp6_pd_reply_events,
427 {'enable_disable': enable_disable,
428 'pid': os.getpid()})
429
Juraj Sloboda81119e82018-05-25 14:02:20 +0200430 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
431 prefixes, server_index=0xFFFFFFFF,
432 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
433 ):
434 return self.api(self.papi.dhcp6_pd_send_client_message,
435 {'sw_if_index': sw_if_index,
436 'server_index': server_index,
437 'irt': irt,
438 'mrt': mrt,
439 'mrc': mrc,
440 'mrd': mrd,
441 'stop': stop,
442 'msg_type': msg_type,
443 'T1': T1,
444 'T2': T2,
445 'n_prefixes': len(prefixes),
446 'prefixes': prefixes})
447
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200448 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
449 enable=1):
450 return self.api(self.papi.dhcp6_client_enable_disable,
451 {'sw_if_index': sw_if_index,
452 'enable': enable})
453
Juraj Sloboda81119e82018-05-25 14:02:20 +0200454 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
455 enable=1):
456 return self.api(self.papi.dhcp6_pd_client_enable_disable,
457 {'sw_if_index': sw_if_index,
458 'prefix_group': prefix_group,
459 'enable': enable})
460
461 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
462 prefix_length, prefix_group,
463 is_add=1):
464 return self.api(self.papi.ip6_add_del_address_using_prefix,
465 {'sw_if_index': sw_if_index,
466 'prefix_group': prefix_group,
467 'address': address,
468 'prefix_length': prefix_length,
469 'is_add': is_add})
470
Neale Rannsc819fc62018-02-16 02:44:05 -0800471 def sw_interface_set_mac_address(self, sw_if_index, mac):
472 return self.api(self.papi.sw_interface_set_mac_address,
473 {'sw_if_index': sw_if_index,
474 'mac_address': mac})
475
Ole Troane1ade682019-03-04 23:55:43 +0100476 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200477 """Create 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_add,
485 {'parent_if_index': sw_if_index,
486 'remote_mac': remote_mac,
487 'subif_id': subif_id})
488
Ole Troane1ade682019-03-04 23:55:43 +0100489 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200490 """Delete p2p ethernet subinterface
491
492 :param sw_if_index: main (parent) interface
493 :param remote_mac: client (remote) mac address
494
495 """
496 return self.api(
497 self.papi.p2p_ethernet_del,
498 {'parent_if_index': sw_if_index,
499 'remote_mac': remote_mac})
500
Klement Sekeraf62ae122016-10-11 11:47:09 +0200501 def create_vlan_subif(self, sw_if_index, vlan):
502 """
503
504 :param vlan:
505 :param sw_if_index:
506
507 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100508 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200509 {'sw_if_index': sw_if_index,
510 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200511
Matej Klotton0178d522016-11-04 11:11:44 +0100512 def create_loopback(self, mac=''):
513 """
514
515 :param mac: (Optional)
516 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100517 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200518 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100519
Matej Klotton0178d522016-11-04 11:11:44 +0100520 def ip_neighbor_add_del(self,
521 sw_if_index,
522 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700523 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100524 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700525 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100526 """ Add neighbor MAC to IPv4 or IPv6 address.
527
528 :param sw_if_index:
529 :param mac_address:
530 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100531 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700532 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100533 """
Matej Klotton0178d522016-11-04 11:11:44 +0100534 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100535 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700536 {
537 'is_add': is_add,
538 'neighbor': {
539 'sw_if_index': sw_if_index,
540 'flags': flags,
541 'mac_address': mac_address,
542 'ip_address': ip_address
543 }
544 }
Matej Klotton0178d522016-11-04 11:11:44 +0100545 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100546
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800547 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700548 low,
549 hi,
550 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800551 is_add=1):
552 """ Config Proxy Arp Range.
553
554 :param low_address: Start address in the rnage to Proxy for
555 :param hi_address: End address in the rnage to Proxy for
556 :param vrf_id: The VRF/table in which to proxy
557 """
558
559 return self.api(
560 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700561 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100562 {
563 'table_id': table_id,
564 'low': low,
565 'hi': hi,
566 },
567 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800568
569 def proxy_arp_intfc_enable_disable(self,
570 sw_if_index,
571 is_enable=1):
572 """ Enable/Disable an interface for proxy ARP requests
573
574 :param sw_if_index: Interface
575 :param enable_disable: Enable/Disable
576 """
577
578 return self.api(
579 self.papi.proxy_arp_intfc_enable_disable,
580 {'sw_if_index': sw_if_index,
581 'enable_disable': is_enable
582 }
583 )
584
Neale Ranns5a8844b2019-04-16 07:15:35 +0000585 def gre_tunnel_add_del(self,
586 src,
587 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000588 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500589 tunnel_type=0,
590 instance=0xFFFFFFFF,
591 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000592 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000593 """ Add a GRE tunnel
594
595 :param src_address:
596 :param dst_address:
597 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500598 :param tunnel_type: (Default value = 0)
599 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700600 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000601 :param is_add: (Default value = 1)
602 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000603 """
604
605 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000606 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200607 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000608 'tunnel':
609 {
610 'type': tunnel_type,
611 'instance': instance,
612 'src': src,
613 'dst': dst,
614 'outer_fib_id': outer_fib_id,
615 'session_id': session_id}
616 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000617 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000618
Neale Rannsd0df49f2018-08-08 01:06:40 -0700619 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700620 src_ip,
621 dst_ip,
622 src_port,
623 dst_port,
624 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800625 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800626 :param src_ip:
627 :param dst_ip:
628 :param src_port:
629 :param dst_port:
630 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800631 """
632
633 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700634 self.papi.udp_encap_add,
635 {
636 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700637 'src_ip': src_ip,
638 'dst_ip': dst_ip,
639 'src_port': src_port,
640 'dst_port': dst_port,
641 'table_id': table_id
642 }
643 })
644
Neale Ranns15002542017-09-10 04:39:11 -0700645 def mpls_table_add_del(
646 self,
647 table_id,
648 is_add=1):
649 """
650
651 :param table_id
652 :param is_add: (Default value = 1)
653
654 """
655
656 return self.api(
657 self.papi.mpls_table_add_del,
658 {'mt_table_id': table_id,
659 'mt_is_add': is_add})
660
Neale Rannsad422ed2016-11-02 14:20:04 +0000661 def mpls_ip_bind_unbind(
662 self,
663 label,
664 dst_address,
665 dst_address_length,
666 table_id=0,
667 ip_table_id=0,
668 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000669 is_bind=1):
670 """
671 """
672 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100673 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200674 {'mb_mpls_table_id': table_id,
675 'mb_label': label,
676 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200677 'mb_is_bind': is_bind,
678 'mb_is_ip4': is_ip4,
679 'mb_address_length': dst_address_length,
680 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000681
682 def mpls_tunnel_add_del(
683 self,
684 tun_sw_if_index,
685 next_hop_proto_is_ip4,
686 next_hop_address,
687 next_hop_sw_if_index=0xFFFFFFFF,
688 next_hop_table_id=0,
689 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200690 next_hop_n_out_labels=0,
691 next_hop_out_label_stack=[],
692 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000693 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800694 l2_only=0,
695 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000696 """
697
698 :param dst_address_length:
699 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
700 :param dst_address:
701 :param next_hop_address:
702 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
703 :param vrf_id: (Default value = 0)
704 :param lookup_in_vrf: (Default value = 0)
705 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000706 :param is_add: (Default value = 1)
707 :param is_drop: (Default value = 0)
708 :param is_ipv6: (Default value = 0)
709 :param is_local: (Default value = 0)
710 :param is_classify: (Default value = 0)
711 :param is_multipath: (Default value = 0)
712 :param is_resolve_host: (Default value = 0)
713 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000714 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800715 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000716
717 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000718 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100719 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200720 {'mt_sw_if_index': tun_sw_if_index,
721 'mt_is_add': is_add,
722 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800723 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200724 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
725 'mt_next_hop_weight': next_hop_weight,
726 'mt_next_hop': next_hop_address,
727 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
728 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
729 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700730 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200731 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800732
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200733 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +0100734 detect_mult, local_addr, peer_addr, is_ipv6=0,
735 bfd_key_id=None, conf_key_id=None):
736 if bfd_key_id is None:
737 return self.api(self.papi.bfd_udp_add,
738 {
739 'sw_if_index': sw_if_index,
740 'desired_min_tx': desired_min_tx,
741 'required_min_rx': required_min_rx,
742 'local_addr': local_addr,
743 'peer_addr': peer_addr,
744 'is_ipv6': is_ipv6,
745 'detect_mult': detect_mult,
746 })
747 else:
748 return self.api(self.papi.bfd_udp_add,
749 {
750 'sw_if_index': sw_if_index,
751 'desired_min_tx': desired_min_tx,
752 'required_min_rx': required_min_rx,
753 'local_addr': local_addr,
754 'peer_addr': peer_addr,
755 'is_ipv6': is_ipv6,
756 'detect_mult': detect_mult,
757 'is_authenticated': 1,
758 'bfd_key_id': bfd_key_id,
759 'conf_key_id': conf_key_id,
760 })
761
Klement Sekeraa57a9702017-02-02 06:58:07 +0100762 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
763 detect_mult, local_addr, peer_addr, is_ipv6=0):
764 return self.api(self.papi.bfd_udp_mod,
765 {
766 'sw_if_index': sw_if_index,
767 'desired_min_tx': desired_min_tx,
768 'required_min_rx': required_min_rx,
769 'local_addr': local_addr,
770 'peer_addr': peer_addr,
771 'is_ipv6': is_ipv6,
772 'detect_mult': detect_mult,
773 })
774
Klement Sekerab17dd962017-01-09 07:43:48 +0100775 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
776 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
777 is_delayed=False):
778 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200779 {
780 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200781 'local_addr': local_addr,
782 'peer_addr': peer_addr,
783 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +0100784 'is_delayed': 1 if is_delayed else 0,
785 'bfd_key_id': bfd_key_id,
786 'conf_key_id': conf_key_id,
787 })
788
Klement Sekerab17dd962017-01-09 07:43:48 +0100789 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
790 peer_addr, is_ipv6=0):
791 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200792 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +0100793 'sw_if_index': sw_if_index,
794 'local_addr': local_addr,
795 'peer_addr': peer_addr,
796 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200797 })
798
799 def want_bfd_events(self, enable_disable=1):
800 return self.api(self.papi.want_bfd_events, {
801 'enable_disable': enable_disable,
802 'pid': os.getpid(),
803 })
Steve Shin7957d6e2016-12-19 09:24:50 -0800804
Klement Sekerab17dd962017-01-09 07:43:48 +0100805 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
806 return self.api(self.papi.bfd_auth_set_key, {
807 'conf_key_id': conf_key_id,
808 'auth_type': auth_type,
809 'key': key,
810 'key_len': len(key),
811 })
812
Steve Shin7957d6e2016-12-19 09:24:50 -0800813 def classify_add_del_table(
814 self,
815 is_add,
816 mask,
817 match_n_vectors=1,
818 table_index=0xFFFFFFFF,
819 nbuckets=2,
820 memory_size=2097152,
821 skip_n_vectors=0,
822 next_table_index=0xFFFFFFFF,
823 miss_next_index=0xFFFFFFFF,
824 current_data_flag=0,
825 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -0800826 """
827 :param is_add:
828 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +0100829 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100830 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -0800831 :param nbuckets: (Default value = 2)
832 :param memory_size: (Default value = 2097152)
833 :param skip_n_vectors: (Default value = 0)
834 :param next_table_index: (Default value = 0xFFFFFFFF)
835 :param miss_next_index: (Default value = 0xFFFFFFFF)
836 :param current_data_flag: (Default value = 0)
837 :param current_data_offset: (Default value = 0)
838 """
839
Juraj Sloboda75282452018-06-12 14:20:49 +0200840 mask_len = ((len(mask) - 1) / 16 + 1) * 16
841 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -0800842 return self.api(
843 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100844 {'is_add': is_add,
845 'table_index': table_index,
846 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -0800847 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100848 'skip_n_vectors': skip_n_vectors,
849 'match_n_vectors': match_n_vectors,
850 'next_table_index': next_table_index,
851 'miss_next_index': miss_next_index,
852 'current_data_flag': current_data_flag,
853 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +0200854 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100855 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -0800856
857 def classify_add_del_session(
858 self,
859 is_add,
860 table_index,
861 match,
862 opaque_index=0xFFFFFFFF,
863 hit_next_index=0xFFFFFFFF,
864 advance=0,
865 action=0,
866 metadata=0):
867 """
868 :param is_add:
869 :param table_index:
870 :param match:
871 :param opaque_index: (Default value = 0xFFFFFFFF)
872 :param hit_next_index: (Default value = 0xFFFFFFFF)
873 :param advance: (Default value = 0)
874 :param action: (Default value = 0)
875 :param metadata: (Default value = 0)
876 """
877
Juraj Sloboda75282452018-06-12 14:20:49 +0200878 match_len = ((len(match) - 1) / 16 + 1) * 16
879 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -0800880 return self.api(
881 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100882 {'is_add': is_add,
883 'table_index': table_index,
884 'hit_next_index': hit_next_index,
885 'opaque_index': opaque_index,
886 'advance': advance,
887 'action': action,
888 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +0200889 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100890 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -0800891
892 def input_acl_set_interface(
893 self,
894 is_add,
895 sw_if_index,
896 ip4_table_index=0xFFFFFFFF,
897 ip6_table_index=0xFFFFFFFF,
898 l2_table_index=0xFFFFFFFF):
899 """
900 :param is_add:
901 :param sw_if_index:
902 :param ip4_table_index: (Default value = 0xFFFFFFFF)
903 :param ip6_table_index: (Default value = 0xFFFFFFFF)
904 :param l2_table_index: (Default value = 0xFFFFFFFF)
905 """
906
907 return self.api(
908 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100909 {'sw_if_index': sw_if_index,
910 'ip4_table_index': ip4_table_index,
911 'ip6_table_index': ip6_table_index,
912 'l2_table_index': l2_table_index,
913 'is_add': is_add})
914
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100915 def output_acl_set_interface(
916 self,
917 is_add,
918 sw_if_index,
919 ip4_table_index=0xFFFFFFFF,
920 ip6_table_index=0xFFFFFFFF,
921 l2_table_index=0xFFFFFFFF):
922 """
923 :param is_add:
924 :param sw_if_index:
925 :param ip4_table_index: (Default value = 0xFFFFFFFF)
926 :param ip6_table_index: (Default value = 0xFFFFFFFF)
927 :param l2_table_index: (Default value = 0xFFFFFFFF)
928 """
929
930 return self.api(
931 self.papi.output_acl_set_interface,
932 {'sw_if_index': sw_if_index,
933 'ip4_table_index': ip4_table_index,
934 'ip6_table_index': ip6_table_index,
935 'l2_table_index': l2_table_index,
936 'is_add': is_add})
937
Klement Sekera77fabdb2017-01-02 07:46:14 +0100938 def set_ipfix_exporter(
939 self,
940 collector_address,
941 src_address,
942 path_mtu,
943 template_interval,
944 vrf_id=0,
945 collector_port=4739,
946 udp_checksum=0):
947 return self.api(
948 self.papi.set_ipfix_exporter,
949 {
950 'collector_address': collector_address,
951 'collector_port': collector_port,
952 'src_address': src_address,
953 'vrf_id': vrf_id,
954 'path_mtu': path_mtu,
955 'template_interval': template_interval,
956 'udp_checksum': udp_checksum,
957 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800958
959 def dhcp_proxy_config(self,
960 dhcp_server,
961 dhcp_src_address,
962 rx_table_id=0,
963 server_table_id=0,
964 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800965 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800966 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -0800967 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -0800968 {
969 'rx_vrf_id': rx_table_id,
970 'server_vrf_id': server_table_id,
971 'is_ipv6': is_ipv6,
972 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -0800973 'dhcp_server': dhcp_server,
974 'dhcp_src_address': dhcp_src_address,
975 })
976
977 def dhcp_proxy_set_vss(self,
978 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -0500979 vss_type=255,
980 vpn_ascii_id="",
981 oui=0,
982 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800983 is_add=1,
984 is_ip6=0):
985 return self.api(
986 self.papi.dhcp_proxy_set_vss,
987 {
988 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -0500989 'vss_type': vss_type,
990 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800991 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -0500992 'vpn_index': vpn_index,
993 'is_add': is_add,
994 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -0800995 })
Neale Ranns32e1c012016-11-22 17:07:28 +0000996
Ole Troane1ade682019-03-04 23:55:43 +0100997 def dhcp_client_config(self,
998 sw_if_index,
999 hostname,
1000 client_id='',
1001 is_add=1,
1002 set_broadcast_flag=1,
1003 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001004 return self.api(
1005 self.papi.dhcp_client_config,
1006 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001007 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001008 'client': {
1009 'sw_if_index': sw_if_index,
1010 'hostname': hostname,
1011 'id': client_id,
1012 'want_dhcp_event': want_dhcp_events,
1013 'set_broadcast_flag': set_broadcast_flag,
1014 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001015 })
1016
Neale Ranns32e1c012016-11-22 17:07:28 +00001017 def ip_mroute_add_del(self,
1018 src_address,
1019 grp_address,
1020 grp_address_length,
1021 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001022 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001023 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001024 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001025 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001026 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001027 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001028 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001029 is_add=1,
1030 is_ipv6=0,
1031 is_local=0):
1032 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001033 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001034 """
1035 return self.api(
1036 self.papi.ip_mroute_add_del,
1037 {'next_hop_sw_if_index': next_hop_sw_if_index,
1038 'entry_flags': e_flags,
1039 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001040 'table_id': table_id,
1041 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001042 'is_add': is_add,
1043 'is_ipv6': is_ipv6,
1044 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001045 'bier_imp': bier_imp,
1046 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001047 'grp_address_length': grp_address_length,
1048 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001049 'src_address': src_address,
1050 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001051
Filip Tehlar770e89e2017-01-31 10:39:16 +01001052 def lisp_enable_disable(self, is_enabled):
1053 return self.api(
1054 self.papi.lisp_enable_disable,
1055 {
1056 'is_en': is_enabled,
1057 })
1058
Ole Troane1ade682019-03-04 23:55:43 +01001059 def lisp_add_del_locator_set(self,
1060 ls_name,
1061 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001062 return self.api(
1063 self.papi.lisp_add_del_locator_set,
1064 {
1065 'is_add': is_add,
1066 'locator_set_name': ls_name
1067 })
1068
Ole Troane1ade682019-03-04 23:55:43 +01001069 def lisp_add_del_locator(self,
1070 ls_name,
1071 sw_if_index,
1072 priority=1,
1073 weight=1,
1074 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001075 return self.api(
1076 self.papi.lisp_add_del_locator,
1077 {
1078 'is_add': is_add,
1079 'locator_set_name': ls_name,
1080 'sw_if_index': sw_if_index,
1081 'priority': priority,
1082 'weight': weight
1083 })
1084
1085 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1086 return self.api(
1087 self.papi.lisp_locator_dump,
1088 {
1089 'is_index_set': is_index_set,
1090 'ls_name': ls_name,
1091 'ls_index': ls_index,
1092 })
1093
Ole Troane1ade682019-03-04 23:55:43 +01001094 def lisp_add_del_local_eid(self,
1095 ls_name,
1096 eid_type,
1097 eid,
1098 prefix_len,
1099 vni=0,
1100 key_id=0,
1101 key="",
1102 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001103 return self.api(
1104 self.papi.lisp_add_del_local_eid,
1105 {
1106 'locator_set_name': ls_name,
1107 'is_add': is_add,
1108 'eid_type': eid_type,
1109 'eid': eid,
1110 'prefix_len': prefix_len,
1111 'vni': vni,
1112 'key_id': key_id,
1113 'key': key
1114 })
1115
1116 def lisp_eid_table_dump(self,
1117 eid_set=0,
1118 prefix_length=0,
1119 vni=0,
1120 eid_type=0,
1121 eid=None,
1122 filter_opt=0):
1123 return self.api(
1124 self.papi.lisp_eid_table_dump,
1125 {
1126 'eid_set': eid_set,
1127 'prefix_length': prefix_length,
1128 'vni': vni,
1129 'eid_type': eid_type,
1130 'eid': eid,
1131 'filter': filter_opt,
1132 })
1133
Ole Troane1ade682019-03-04 23:55:43 +01001134 def lisp_add_del_remote_mapping(self,
1135 eid_type,
1136 eid,
1137 eid_prefix_len=0,
1138 vni=0,
1139 rlocs=[],
1140 rlocs_num=0,
1141 is_src_dst=0,
1142 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001143 return self.api(
1144 self.papi.lisp_add_del_remote_mapping,
1145 {
1146 'is_add': is_add,
1147 'eid_type': eid_type,
1148 'eid': eid,
1149 'eid_len': eid_prefix_len,
1150 'rloc_num': rlocs_num,
1151 'rlocs': rlocs,
1152 'vni': vni,
1153 'is_src_dst': is_src_dst,
1154 })
1155
Ole Troane1ade682019-03-04 23:55:43 +01001156 def lisp_add_del_adjacency(self,
1157 leid,
1158 reid,
1159 leid_len,
1160 reid_len,
1161 eid_type,
1162 is_add=1,
1163 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001164 return self.api(
1165 self.papi.lisp_add_del_adjacency,
1166 {
1167 'is_add': is_add,
1168 'vni': vni,
1169 'eid_type': eid_type,
1170 'leid': leid,
1171 'reid': reid,
1172 'leid_len': leid_len,
1173 'reid_len': reid_len,
1174 })
1175
Hongjun Nief486b12017-04-12 19:21:16 +08001176 def gtpu_add_del_tunnel(
1177 self,
1178 src_addr,
1179 dst_addr,
1180 is_add=1,
1181 is_ipv6=0,
1182 mcast_sw_if_index=0xFFFFFFFF,
1183 encap_vrf_id=0,
1184 decap_next_index=0xFFFFFFFF,
1185 teid=0):
1186 """
1187
1188 :param is_add: (Default value = 1)
1189 :param is_ipv6: (Default value = 0)
1190 :param src_addr:
1191 :param dst_addr:
1192 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1193 :param encap_vrf_id: (Default value = 0)
1194 :param decap_next_index: (Default value = 0xFFFFFFFF)
1195 :param teid: (Default value = 0)
1196
1197 """
1198 return self.api(self.papi.gtpu_add_del_tunnel,
1199 {'is_add': is_add,
1200 'is_ipv6': is_ipv6,
1201 'src_address': src_addr,
1202 'dst_address': dst_addr,
1203 'mcast_sw_if_index': mcast_sw_if_index,
1204 'encap_vrf_id': encap_vrf_id,
1205 'decap_next_index': decap_next_index,
1206 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001207
1208 def vxlan_gpe_add_del_tunnel(
1209 self,
1210 src_addr,
1211 dst_addr,
1212 mcast_sw_if_index=0xFFFFFFFF,
1213 is_add=1,
1214 is_ipv6=0,
1215 encap_vrf_id=0,
1216 decap_vrf_id=0,
1217 protocol=3,
1218 vni=0):
1219 """
1220
1221 :param local:
1222 :param remote:
1223 :param is_add: (Default value = 1)
1224 :param is_ipv6: (Default value = 0)
1225 :param encap_vrf_id: (Default value = 0)
1226 :param decap_vrf_id: (Default value = 0)
1227 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1228 :param protocol: (Default value = 3)
1229 :param vni: (Default value = 0)
1230
1231 """
1232 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1233 {'is_add': is_add,
1234 'is_ipv6': is_ipv6,
1235 'local': src_addr,
1236 'remote': dst_addr,
1237 'mcast_sw_if_index': mcast_sw_if_index,
1238 'encap_vrf_id': encap_vrf_id,
1239 'decap_vrf_id': decap_vrf_id,
1240 'protocol': protocol,
1241 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001242
Neale Ranns79a05f52018-09-11 07:39:43 -07001243 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001244 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001245 src,
1246 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001247 mcast_sw_if_index=0xFFFFFFFF,
1248 is_add=1,
1249 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001250 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001251 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001252 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001253 instance=0xFFFFFFFF):
1254 """
1255
1256 :param dst_addr:
1257 :param src_addr:
1258 :param is_add: (Default value = 1)
1259 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001260 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001261 :param decap_next_index: (Default value = 0xFFFFFFFF)
1262 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1263 :param vni: (Default value = 0)
1264 :param instance: (Default value = 0xFFFFFFFF)
1265
1266 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001267 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001268 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001269 'tunnel': {
1270 'src': src,
1271 'dst': dst,
1272 'mcast_sw_if_index': mcast_sw_if_index,
1273 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001274 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001275 'instance': instance,
1276 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001277
1278 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,
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,
Neale Ranns31ed7442018-02-23 05:29:09 -08001651 'br_n_paths': len(paths),
1652 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001653 'br_is_add': is_add,
1654 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001655
1656 def bier_route_dump(self, bti):
1657 return self.api(
1658 self.papi.bier_route_dump,
1659 {'br_tbl_id': {"bt_set": bti.set_id,
1660 "bt_sub_domain": bti.sub_domain_id,
1661 "bt_hdr_len_id": bti.hdr_len_id}})
1662
1663 def bier_imp_add(self,
1664 bti,
1665 src,
1666 ibytes,
1667 is_add=1):
1668 """ BIER Imposition Add """
1669 return self.api(
1670 self.papi.bier_imp_add,
1671 {'bi_tbl_id': {"bt_set": bti.set_id,
1672 "bt_sub_domain": bti.sub_domain_id,
1673 "bt_hdr_len_id": bti.hdr_len_id},
1674 'bi_src': src,
1675 'bi_n_bytes': len(ibytes),
1676 'bi_bytes': ibytes})
1677
1678 def bier_imp_del(self, bi_index):
1679 """ BIER Imposition del """
1680 return self.api(
1681 self.papi.bier_imp_del,
1682 {'bi_index': bi_index})
1683
1684 def bier_imp_dump(self):
1685 return self.api(self.papi.bier_imp_dump, {})
1686
1687 def bier_disp_table_add_del(self,
1688 bdti,
1689 is_add=1):
1690 """ BIER Disposition Table add/del """
1691 return self.api(
1692 self.papi.bier_disp_table_add_del,
1693 {'bdt_tbl_id': bdti,
1694 'bdt_is_add': is_add})
1695
1696 def bier_disp_table_dump(self):
1697 return self.api(self.papi.bier_disp_table_dump, {})
1698
1699 def bier_disp_entry_add_del(self,
1700 bdti,
1701 bp,
1702 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001703 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001704 next_hop,
1705 next_hop_tbl_id=0,
1706 next_hop_rpf_id=~0,
1707 next_hop_is_ip4=1,
1708 is_add=1):
1709 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001710 lstack = []
1711 while (len(lstack) < 16):
1712 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001713 return self.api(
1714 self.papi.bier_disp_entry_add_del,
1715 {'bde_tbl_id': bdti,
1716 'bde_bp': bp,
1717 'bde_payload_proto': payload_proto,
1718 'bde_n_paths': 1,
1719 'bde_paths': [{'next_hop': next_hop,
1720 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08001721 'afi': next_hop_afi,
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,
1890 'is_ip_any': is_ip_any
1891 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001892 })
Florin Corasb795bd02017-12-14 11:30:48 -08001893
Neale Ranns311124e2019-01-24 04:52:25 -08001894 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1895 return self.api(self.papi.ipsec_spd_dump,
1896 {'spd_id': spd_id,
1897 'sa_id': sa_id})
1898
Klement Sekera31da2e32018-06-24 22:49:55 +02001899 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1900 remote_spi, crypto_alg, local_crypto_key,
1901 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001902 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02001903 anti_replay=1, renumber=0, show_instance=0):
1904 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,
1926 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001927 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001928
Neale Rannsf05e7322019-03-29 20:23:58 +00001929 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
1930 sa_out, sa_in, is_add=1):
1931 return self.api(self.papi.ipsec_gre_tunnel_add_del,
1932 {
1933 'is_add': is_add,
1934 'tunnel': {
1935 'src': local_ip,
1936 'dst': remote_ip,
1937 'local_sa_id': sa_out,
1938 'remote_sa_id': sa_in
1939 }
1940 })
1941
Klement Sekerab4d30532018-11-08 13:00:02 +01001942 def ipsec_select_backend(self, protocol, index):
1943 return self.api(self.papi.ipsec_select_backend,
1944 {'protocol': protocol, 'index': index})
1945
1946 def ipsec_backend_dump(self):
1947 return self.api(self.papi.ipsec_backend_dump, {})
1948
Ole Troane1ade682019-03-04 23:55:43 +01001949 def app_namespace_add_del(self,
1950 namespace_id,
1951 ip4_fib_id=0,
1952 ip6_fib_id=0,
1953 sw_if_index=0xFFFFFFFF,
1954 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001955 return self.api(
1956 self.papi.app_namespace_add_del,
1957 {'secret': secret,
1958 'sw_if_index': sw_if_index,
1959 'ip4_fib_id': ip4_fib_id,
1960 'ip6_fib_id': ip6_fib_id,
1961 'namespace_id': namespace_id,
1962 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001963
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001964 def punt_socket_register(self, port, pathname, protocol=0x11,
1965 header_version=1, is_ip4=1):
1966 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001967 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001968 {'header_version': header_version,
1969 'punt': {'ipv': is_ip4,
1970 'l4_protocol': protocol,
1971 'l4_port': port},
1972 'pathname': pathname})
1973
1974 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
1975 """ Unregister punt socket """
1976 return self.api(self.papi.punt_socket_deregister,
1977 {'punt': {'ipv': is_ip4,
1978 'l4_protocol': protocol,
1979 'l4_port': port}})
1980
1981 def punt_socket_dump(self, is_ip6=1):
1982 """ Dump punt socket"""
1983 return self.api(self.papi.punt_socket_dump,
1984 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02001985
Neale Ranns4ba67722019-02-28 11:11:39 +00001986 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001987 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001988 """ GBP endpoint Add """
1989 return self.api(self.papi.gbp_endpoint_add,
1990 {'endpoint': {
1991 'sw_if_index': sw_if_index,
1992 'ips': ips,
1993 'n_ips': len(ips),
1994 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001995 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001996 'flags': flags,
1997 'tun': {
1998 'src': tun_src,
1999 'dst': tun_dst,
2000 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002001
2002 def gbp_endpoint_del(self, handle):
2003 """ GBP endpoint Del """
2004 return self.api(self.papi.gbp_endpoint_del,
2005 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002006
2007 def gbp_endpoint_dump(self):
2008 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002009 return self.api(self.papi.gbp_endpoint_dump,
2010 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002011
Neale Ranns4ba67722019-02-28 11:11:39 +00002012 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002013 rd, uplink_sw_if_index,
2014 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002015 """ GBP endpoint group Add """
2016 return self.api(self.papi.gbp_endpoint_group_add,
2017 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002018 {
2019 'uplink_sw_if_index': uplink_sw_if_index,
2020 'bd_id': bd,
2021 'rd_id': rd,
2022 'vnid': vnid,
2023 'sclass': sclass,
2024 'retention': retention
2025 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002026
Neale Ranns4ba67722019-02-28 11:11:39 +00002027 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002028 """ GBP endpoint group Del """
2029 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002030 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002031
Neale Rannsc29c0af2018-11-07 04:21:12 -08002032 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002033 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002034 uu_fwd_sw_if_index,
2035 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002036 """ GBP bridge-domain Add """
2037 return self.api(self.papi.gbp_bridge_domain_add,
2038 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002039 {
2040 'flags': flags,
2041 'bvi_sw_if_index': bvi_sw_if_index,
2042 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2043 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2044 'bd_id': bd_id
2045 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002046
2047 def gbp_bridge_domain_del(self, bd_id):
2048 """ GBP bridge-domain Del """
2049 return self.api(self.papi.gbp_bridge_domain_del,
2050 {'bd_id': bd_id})
2051
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002052 def gbp_route_domain_add(self, rd_id,
2053 ip4_table_id,
2054 ip6_table_id,
2055 ip4_uu_sw_if_index,
2056 ip6_uu_sw_if_index):
2057 """ GBP route-domain Add """
2058 return self.api(self.papi.gbp_route_domain_add,
2059 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002060 {
2061 'ip4_table_id': ip4_table_id,
2062 'ip6_table_id': ip6_table_id,
2063 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2064 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2065 'rd_id': rd_id
2066 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002067
2068 def gbp_route_domain_del(self, rd_id):
2069 """ GBP route-domain Del """
2070 return self.api(self.papi.gbp_route_domain_del,
2071 {'rd_id': rd_id})
2072
Neale Ranns4ba67722019-02-28 11:11:39 +00002073 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002074 """ GBP recirc Add/Del """
2075 return self.api(self.papi.gbp_recirc_add_del,
2076 {'is_add': is_add,
2077 'recirc': {
2078 'is_ext': is_ext,
2079 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002080 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002081
2082 def gbp_recirc_dump(self):
2083 """ GBP recirc Dump """
2084 return self.api(self.papi.gbp_recirc_dump, {})
2085
Neale Rannsb6a47952018-11-21 05:44:35 -08002086 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2087 """ GBP recirc Add/Del """
2088 return self.api(self.papi.gbp_ext_itf_add_del,
2089 {'is_add': is_add,
2090 'ext_itf': {
2091 'sw_if_index': sw_if_index,
2092 'bd_id': bd_id,
2093 'rd_id': rd_id}})
2094
2095 def gbp_ext_itf_dump(self):
2096 """ GBP recirc Dump """
2097 return self.api(self.papi.gbp_ext_itf_dump, {})
2098
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002099 def gbp_subnet_add_del(self, is_add, rd_id,
2100 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002101 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002102 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002103 """ GBP Subnet Add/Del """
2104 return self.api(self.papi.gbp_subnet_add_del,
2105 {'is_add': is_add,
2106 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002107 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002108 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002109 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002110 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002111 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002112
2113 def gbp_subnet_dump(self):
2114 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002115 return self.api(self.papi.gbp_subnet_dump,
2116 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002117
Neale Ranns4ba67722019-02-28 11:11:39 +00002118 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002119 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002120 """ GBP contract Add/Del """
2121 return self.api(self.papi.gbp_contract_add_del,
2122 {'is_add': is_add,
2123 'contract': {
2124 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002125 'sclass': sclass,
2126 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002127 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002128 'rules': rules,
2129 'n_ether_types': len(allowed_ethertypes),
2130 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002131
2132 def gbp_contract_dump(self):
2133 """ GBP contract Dump """
2134 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002135
Neale Ranns8da9fc62019-03-04 14:08:11 -08002136 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002137 """ GBP VXLAN tunnel add """
2138 return self.api(self.papi.gbp_vxlan_tunnel_add,
2139 {
2140 'tunnel': {
2141 'vni': vni,
2142 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002143 'bd_rd_id': bd_rd_id,
2144 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002145 }
2146 })
2147
2148 def gbp_vxlan_tunnel_del(self, vni):
2149 """ GBP VXLAN tunnel del """
2150 return self.api(self.papi.gbp_vxlan_tunnel_del,
2151 {
2152 'vni': vni,
2153 })
2154
2155 def gbp_vxlan_tunnel_dump(self):
2156 """ GBP VXLAN tunnel add/del """
2157 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2158
Neale Ranns039cbfe2018-02-27 03:45:38 -08002159 def qos_egress_map_update(self, id, outputs):
2160 """ QOS egress map update """
2161 return self.api(self.papi.qos_egress_map_update,
2162 {'map_id': id,
2163 'rows': outputs})
2164
2165 def qos_egress_map_delete(self, id):
2166 """ QOS egress map delete """
2167 return self.api(self.papi.qos_egress_map_delete,
2168 {'map_id': id})
2169
2170 def qos_mark_enable_disable(self, sw_if_index,
2171 output_source,
2172 map_id,
2173 enable):
2174 """ QOS Mark Enable/Disable """
2175 return self.api(self.papi.qos_mark_enable_disable,
2176 {'map_id': map_id,
2177 'sw_if_index': sw_if_index,
2178 'output_source': output_source,
2179 'enable': enable})
2180
Neale Ranns947ea622018-06-07 23:48:20 -07002181 def igmp_enable_disable(self, sw_if_index, enable, host):
2182 """ Enable/disable IGMP on a given interface """
2183 return self.api(self.papi.igmp_enable_disable,
2184 {'enable': enable,
2185 'mode': host,
2186 'sw_if_index': sw_if_index})
2187
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002188 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2189 """ Add/del IGMP proxy device """
2190 return self.api(self.papi.igmp_proxy_device_add_del,
2191 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2192 'add': add})
2193
2194 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2195 """ Add/del interface to/from IGMP proxy device """
2196 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2197 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2198 'add': add})
2199
Neale Ranns947ea622018-06-07 23:48:20 -07002200 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002201 """ Listen for new (S,G) on specified interface
2202
2203 :param enable: add/del
2204 :param sw_if_index: interface sw index
2205 :param saddr: source ip4 addr
2206 :param gaddr: group ip4 addr
2207 """
2208 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002209 {
2210 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002211 {
2212 'filter': filter,
2213 'sw_if_index': sw_if_index,
2214 'n_srcs': len(saddrs),
2215 'saddrs': saddrs,
2216 'gaddr': gaddr
2217 }
Neale Ranns947ea622018-06-07 23:48:20 -07002218 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002219
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002220 def igmp_clear_interface(self, sw_if_index):
2221 """ Remove all (S,G)s from specified interface
2222 doesn't send IGMP report!
2223 """
2224 return self.api(
2225 self.papi.igmp_clear_interface, {
2226 'sw_if_index': sw_if_index})
2227
2228 def want_igmp_events(self, enable=1):
2229 return self.api(self.papi.want_igmp_events, {'enable': enable,
2230 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002231
2232 def bond_create(
2233 self,
2234 mode,
2235 lb,
2236 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002237 mac_address='',
2238 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002239 """
2240 :param mode: mode
2241 :param lb: load balance
2242 :param use_custom_mac: use custom mac
2243 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002244 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002245 """
2246 return self.api(
2247 self.papi.bond_create,
2248 {'mode': mode,
2249 'lb': lb,
2250 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002251 'mac_address': mac_address,
2252 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002253 })
2254
Neale Ranns17ff3c12018-07-04 10:24:24 -07002255 def pipe_delete(self, parent_sw_if_index):
2256 return self.api(self.papi.pipe_delete,
2257 {'parent_sw_if_index': parent_sw_if_index})
2258
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002259 def memif_create(
2260 self,
2261 role,
2262 mode,
2263 rx_queues=None,
2264 tx_queues=None,
2265 _id=None,
2266 socket_id=None,
2267 secret=None,
2268 ring_size=None,
2269 buffer_size=None,
2270 hw_addr=None):
2271 return self.api(self.papi.memif_create,
2272 {'role': role,
2273 'mode': mode,
2274 'rx_queues': rx_queues,
2275 'tx_queues': tx_queues,
2276 'id': _id,
2277 'socket_id': socket_id,
2278 'secret': secret,
2279 'ring_size': ring_size,
2280 'buffer_size': buffer_size,
2281 'hw_addr': hw_addr})
2282
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002283 def svs_table_add_del(self, af, table_id, is_add=1):
2284 return self.api(self.papi.svs_table_add_del,
2285 {
2286 'table_id': table_id,
2287 'is_add': is_add,
2288 'af': af,
2289 })
2290
2291 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2292 return self.api(self.papi.svs_route_add_del,
2293 {
2294 'table_id': table_id,
2295 'source_table_id': src_table_id,
2296 'prefix': prefix,
2297 'is_add': is_add,
2298 })
2299
2300 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2301 return self.api(self.papi.svs_enable_disable,
2302 {
2303 'af': af,
2304 'table_id': table_id,
2305 'sw_if_index': sw_if_index,
2306 'is_enable': is_enable,
2307 })