blob: a3d20bf30885613a3307cde2e320671f9d364923 [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 Vinciguerra84679192019-01-13 11:33:52 -080013from vpp_papi import VPP, 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
Klement Sekerab8c72a42018-11-08 11:21:39 +0100194 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +0100195
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800196 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
197 if 'VPP_API_DIR' not in os.environ:
198 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
199
Ole Troan4ff09ae2019-04-15 11:27:22 +0200200 use_socket = False
201 try:
202 if os.environ['SOCKET'] == '1':
203 use_socket = True
204 except:
205 pass
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800206 self.vpp = VPP(logger=test_class.logger,
Ole Troan4ff09ae2019-04-15 11:27:22 +0200207 read_timeout=read_timeout,
208 use_socket=use_socket,
209 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100210 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211
Klement Sekerae0545ef2017-01-25 08:00:40 +0100212 def __enter__(self):
213 return self
214
Klement Sekera7d6afb32018-11-08 11:52:04 +0100215 def assert_negative_api_retval(self):
216 """ Expect API failure - used with with, e.g.:
217 with self.vapi.assert_negative_api_retval():
218 self.vapi.<api call expected to fail>
219 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100220 self._expect_stack.append(self._expect_api_retval)
221 self._expect_api_retval = self._negative
222 return self
223
Klement Sekera7d6afb32018-11-08 11:52:04 +0100224 def assert_zero_api_retval(self):
225 """ Expect API success - used with with, e.g.:
226 with self.vapi.assert_negative_api_retval():
227 self.vapi.<api call expected to succeed>
228
229 note: this is useful only inside another with block
230 as success is the default expected value
231 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100232 self._expect_stack.append(self._expect_api_retval)
233 self._expect_api_retval = self._zero
234 return self
235
236 def __exit__(self, exc_type, exc_value, traceback):
237 self._expect_api_retval = self._expect_stack.pop()
238
Klement Sekeraf62ae122016-10-11 11:47:09 +0200239 def register_hook(self, hook):
240 """Replace hook registration with new hook
241
242 :param hook:
243
244 """
245 self.hook = hook
246
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200247 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100248 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200249 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100250 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200251 return e
252
253 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100254 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100255 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100256 self.test_class.logger.debug("Expecting event '%s' within %ss",
257 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300258 else:
259 self.test_class.logger.debug("Expecting event within %ss",
260 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100261 if self._events:
262 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200263 limit = time.time() + timeout
264 while time.time() < limit:
265 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100266 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200267 if name and type(e).__name__ != name:
268 raise Exception(
269 "Unexpected event received: %s, expected: %s" %
270 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100271 self.test_class.logger.debug("Returning event %s:%s" %
272 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200273 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700274 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200275 raise Exception("Event did not occur within timeout")
276
277 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100278 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200279 # FIXME use the name instead of relying on type(e).__name__ ?
280 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100281 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200282 self._events.append(event)
283
Ole Troanf159f582019-02-28 20:20:47 +0100284 def factory(self, name, apifn):
285 def f(*a, **ka):
286 fields = apifn._func.msg.fields
287
288 # add positional and kw arguments
289 d = ka
290 for i, o in enumerate(fields[3:]):
291 try:
292 d[o] = a[i]
293 except:
294 break
295
296 # Default override
297 if name in defaultmapping:
298 for k, v in iteritems(defaultmapping[name]):
299 if k in d:
300 continue
301 d[k] = v
302 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100303
Ole Troanf159f582019-02-28 20:20:47 +0100304 return f
305
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800306 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100307 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800308 method = super(VppPapiProvider, self).__getattribute__(name)
309 except AttributeError:
310 method = self.factory(name, getattr(self.papi, name))
311 # lazily load the method so we don't need to call factory
312 # again for this name.
313 setattr(self, name, method)
314 return method
Ole Troanf159f582019-02-28 20:20:47 +0100315
Klement Sekeraf62ae122016-10-11 11:47:09 +0200316 def connect(self):
317 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100318 self.vpp.connect(self.name, self.shm_prefix)
319 self.papi = self.vpp.api
320 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200321
322 def disconnect(self):
323 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100324 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200325
326 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100327 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200328 Call the appropriate hooks before and after the API call
329
330 :param api_fn: API function to call
331 :param api_args: tuple of API function arguments
332 :param expected_retval: Expected return value (Default value = 0)
333 :returns: reply from the API
334
335 """
336 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100337 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100338 if self._expect_api_retval == self._negative:
339 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100340 msg = "API call passed unexpectedly: expected negative " \
341 "return value instead of %d in %s" % \
342 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100343 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100344 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100345 elif self._expect_api_retval == self._zero:
346 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100347 msg = "API call failed, expected %d return value instead " \
348 "of %d in %s" % (expected_retval, reply.retval,
349 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100350 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100351 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100352 else:
353 raise Exception("Internal error, unexpected value for "
354 "self._expect_api_retval %s" %
355 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200356 self.hook.after_api(api_fn.__name__, api_args)
357 return reply
358
359 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100360 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200361
362 :param cli: CLI to execute
363 :returns: CLI output
364
365 """
366 self.hook.before_cli(cli)
367 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100368 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200369 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200370 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100371 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372
Jan49c0fca2016-10-26 15:44:27 +0200373 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100374 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200375
376 :param cli: CLI to execute
377 :returns: CLI output
378 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600379 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200380
Neale Ranns37029302018-08-10 05:30:06 -0700381 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300382 return self.api(self.papi.want_ip4_arp_events,
383 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700384 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300385 'pid': os.getpid(), })
386
Neale Ranns37029302018-08-10 05:30:06 -0700387 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300388 return self.api(self.papi.want_ip6_nd_events,
389 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700390 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300391 'pid': os.getpid(), })
392
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100393 def want_ip6_ra_events(self, enable_disable=1):
394 return self.api(self.papi.want_ip6_ra_events,
395 {'enable_disable': enable_disable,
396 'pid': os.getpid(), })
397
398 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
399 mrc=0, mrd=0):
400 return self.api(self.papi.ip6nd_send_router_solicitation,
401 {'irt': irt,
402 'mrt': mrt,
403 'mrc': mrc,
404 'mrd': mrd,
405 'sw_if_index': sw_if_index})
406
Juraj Slobodab3f90502018-10-04 15:15:16 +0200407 def want_interface_events(self, enable_disable=1):
408 return self.api(self.papi.want_interface_events,
409 {'enable_disable': enable_disable,
410 'pid': os.getpid(), })
411
Ole Troane1ade682019-03-04 23:55:43 +0100412 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
413 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300414 return self.api(self.papi.want_l2_macs_events,
415 {'enable_disable': enable_disable,
416 'scan_delay': scan_delay,
417 'max_macs_in_event': max_macs_in_event,
418 'learn_limit': learn_limit,
419 'pid': os.getpid(), })
420
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200421 def want_dhcp6_reply_events(self, enable_disable=1):
422 return self.api(self.papi.want_dhcp6_reply_events,
423 {'enable_disable': enable_disable,
424 'pid': os.getpid()})
425
Juraj Sloboda81119e82018-05-25 14:02:20 +0200426 def want_dhcp6_pd_reply_events(self, enable_disable=1):
427 return self.api(self.papi.want_dhcp6_pd_reply_events,
428 {'enable_disable': enable_disable,
429 'pid': os.getpid()})
430
Juraj Sloboda81119e82018-05-25 14:02:20 +0200431 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
432 prefixes, server_index=0xFFFFFFFF,
433 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
434 ):
435 return self.api(self.papi.dhcp6_pd_send_client_message,
436 {'sw_if_index': sw_if_index,
437 'server_index': server_index,
438 'irt': irt,
439 'mrt': mrt,
440 'mrc': mrc,
441 'mrd': mrd,
442 'stop': stop,
443 'msg_type': msg_type,
444 'T1': T1,
445 'T2': T2,
446 'n_prefixes': len(prefixes),
447 'prefixes': prefixes})
448
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200449 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
450 enable=1):
451 return self.api(self.papi.dhcp6_client_enable_disable,
452 {'sw_if_index': sw_if_index,
453 'enable': enable})
454
Juraj Sloboda81119e82018-05-25 14:02:20 +0200455 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
456 enable=1):
457 return self.api(self.papi.dhcp6_pd_client_enable_disable,
458 {'sw_if_index': sw_if_index,
459 'prefix_group': prefix_group,
460 'enable': enable})
461
462 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
463 prefix_length, prefix_group,
464 is_add=1):
465 return self.api(self.papi.ip6_add_del_address_using_prefix,
466 {'sw_if_index': sw_if_index,
467 'prefix_group': prefix_group,
468 'address': address,
469 'prefix_length': prefix_length,
470 'is_add': is_add})
471
Neale Rannsc819fc62018-02-16 02:44:05 -0800472 def sw_interface_set_mac_address(self, sw_if_index, mac):
473 return self.api(self.papi.sw_interface_set_mac_address,
474 {'sw_if_index': sw_if_index,
475 'mac_address': mac})
476
Ole Troane1ade682019-03-04 23:55:43 +0100477 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200478 """Create p2p ethernet subinterface
479
480 :param sw_if_index: main (parent) interface
481 :param remote_mac: client (remote) mac address
482
483 """
484 return self.api(
485 self.papi.p2p_ethernet_add,
486 {'parent_if_index': sw_if_index,
487 'remote_mac': remote_mac,
488 'subif_id': subif_id})
489
Ole Troane1ade682019-03-04 23:55:43 +0100490 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200491 """Delete p2p ethernet subinterface
492
493 :param sw_if_index: main (parent) interface
494 :param remote_mac: client (remote) mac address
495
496 """
497 return self.api(
498 self.papi.p2p_ethernet_del,
499 {'parent_if_index': sw_if_index,
500 'remote_mac': remote_mac})
501
Klement Sekeraf62ae122016-10-11 11:47:09 +0200502 def create_vlan_subif(self, sw_if_index, vlan):
503 """
504
505 :param vlan:
506 :param sw_if_index:
507
508 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100509 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200510 {'sw_if_index': sw_if_index,
511 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200512
Matej Klotton0178d522016-11-04 11:11:44 +0100513 def create_loopback(self, mac=''):
514 """
515
516 :param mac: (Optional)
517 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100518 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200519 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100520
Matej Klotton0178d522016-11-04 11:11:44 +0100521 def ip_neighbor_add_del(self,
522 sw_if_index,
523 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700524 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100525 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700526 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100527 """ Add neighbor MAC to IPv4 or IPv6 address.
528
529 :param sw_if_index:
530 :param mac_address:
531 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100532 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700533 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100534 """
Matej Klotton0178d522016-11-04 11:11:44 +0100535 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100536 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700537 {
538 'is_add': is_add,
539 'neighbor': {
540 'sw_if_index': sw_if_index,
541 'flags': flags,
542 'mac_address': mac_address,
543 'ip_address': ip_address
544 }
545 }
Matej Klotton0178d522016-11-04 11:11:44 +0100546 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100547
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800548 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700549 low,
550 hi,
551 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800552 is_add=1):
553 """ Config Proxy Arp Range.
554
555 :param low_address: Start address in the rnage to Proxy for
556 :param hi_address: End address in the rnage to Proxy for
557 :param vrf_id: The VRF/table in which to proxy
558 """
559
560 return self.api(
561 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700562 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100563 {
564 'table_id': table_id,
565 'low': low,
566 'hi': hi,
567 },
568 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800569
570 def proxy_arp_intfc_enable_disable(self,
571 sw_if_index,
572 is_enable=1):
573 """ Enable/Disable an interface for proxy ARP requests
574
575 :param sw_if_index: Interface
576 :param enable_disable: Enable/Disable
577 """
578
579 return self.api(
580 self.papi.proxy_arp_intfc_enable_disable,
581 {'sw_if_index': sw_if_index,
582 'enable_disable': is_enable
583 }
584 )
585
Neale Ranns5a8844b2019-04-16 07:15:35 +0000586 def gre_tunnel_add_del(self,
587 src,
588 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000589 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500590 tunnel_type=0,
591 instance=0xFFFFFFFF,
592 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000593 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000594 """ Add a GRE tunnel
595
596 :param src_address:
597 :param dst_address:
598 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500599 :param tunnel_type: (Default value = 0)
600 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700601 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000602 :param is_add: (Default value = 1)
603 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000604 """
605
606 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000607 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200608 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000609 'tunnel':
610 {
611 'type': tunnel_type,
612 'instance': instance,
613 'src': src,
614 'dst': dst,
615 'outer_fib_id': outer_fib_id,
616 'session_id': session_id}
617 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000618 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000619
Neale Rannsd0df49f2018-08-08 01:06:40 -0700620 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700621 src_ip,
622 dst_ip,
623 src_port,
624 dst_port,
625 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800626 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800627 :param src_ip:
628 :param dst_ip:
629 :param src_port:
630 :param dst_port:
631 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800632 """
633
634 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700635 self.papi.udp_encap_add,
636 {
637 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700638 'src_ip': src_ip,
639 'dst_ip': dst_ip,
640 'src_port': src_port,
641 'dst_port': dst_port,
642 'table_id': table_id
643 }
644 })
645
Neale Ranns15002542017-09-10 04:39:11 -0700646 def mpls_table_add_del(
647 self,
648 table_id,
649 is_add=1):
650 """
651
652 :param table_id
653 :param is_add: (Default value = 1)
654
655 """
656
657 return self.api(
658 self.papi.mpls_table_add_del,
659 {'mt_table_id': table_id,
660 'mt_is_add': is_add})
661
Neale Rannsad422ed2016-11-02 14:20:04 +0000662 def mpls_ip_bind_unbind(
663 self,
664 label,
665 dst_address,
666 dst_address_length,
667 table_id=0,
668 ip_table_id=0,
669 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000670 is_bind=1):
671 """
672 """
673 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100674 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200675 {'mb_mpls_table_id': table_id,
676 'mb_label': label,
677 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200678 'mb_is_bind': is_bind,
679 'mb_is_ip4': is_ip4,
680 'mb_address_length': dst_address_length,
681 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000682
683 def mpls_tunnel_add_del(
684 self,
685 tun_sw_if_index,
686 next_hop_proto_is_ip4,
687 next_hop_address,
688 next_hop_sw_if_index=0xFFFFFFFF,
689 next_hop_table_id=0,
690 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200691 next_hop_n_out_labels=0,
692 next_hop_out_label_stack=[],
693 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000694 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800695 l2_only=0,
696 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000697 """
698
699 :param dst_address_length:
700 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
701 :param dst_address:
702 :param next_hop_address:
703 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
704 :param vrf_id: (Default value = 0)
705 :param lookup_in_vrf: (Default value = 0)
706 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000707 :param is_add: (Default value = 1)
708 :param is_drop: (Default value = 0)
709 :param is_ipv6: (Default value = 0)
710 :param is_local: (Default value = 0)
711 :param is_classify: (Default value = 0)
712 :param is_multipath: (Default value = 0)
713 :param is_resolve_host: (Default value = 0)
714 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000715 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800716 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000717
718 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000719 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100720 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200721 {'mt_sw_if_index': tun_sw_if_index,
722 'mt_is_add': is_add,
723 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800724 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200725 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
726 'mt_next_hop_weight': next_hop_weight,
727 'mt_next_hop': next_hop_address,
728 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
729 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
730 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700731 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200732 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800733
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200734 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +0100735 detect_mult, local_addr, peer_addr, is_ipv6=0,
736 bfd_key_id=None, conf_key_id=None):
737 if bfd_key_id is None:
738 return self.api(self.papi.bfd_udp_add,
739 {
740 'sw_if_index': sw_if_index,
741 'desired_min_tx': desired_min_tx,
742 'required_min_rx': required_min_rx,
743 'local_addr': local_addr,
744 'peer_addr': peer_addr,
745 'is_ipv6': is_ipv6,
746 'detect_mult': detect_mult,
747 })
748 else:
749 return self.api(self.papi.bfd_udp_add,
750 {
751 'sw_if_index': sw_if_index,
752 'desired_min_tx': desired_min_tx,
753 'required_min_rx': required_min_rx,
754 'local_addr': local_addr,
755 'peer_addr': peer_addr,
756 'is_ipv6': is_ipv6,
757 'detect_mult': detect_mult,
758 'is_authenticated': 1,
759 'bfd_key_id': bfd_key_id,
760 'conf_key_id': conf_key_id,
761 })
762
Klement Sekeraa57a9702017-02-02 06:58:07 +0100763 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
764 detect_mult, local_addr, peer_addr, is_ipv6=0):
765 return self.api(self.papi.bfd_udp_mod,
766 {
767 'sw_if_index': sw_if_index,
768 'desired_min_tx': desired_min_tx,
769 'required_min_rx': required_min_rx,
770 'local_addr': local_addr,
771 'peer_addr': peer_addr,
772 'is_ipv6': is_ipv6,
773 'detect_mult': detect_mult,
774 })
775
Klement Sekerab17dd962017-01-09 07:43:48 +0100776 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
777 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
778 is_delayed=False):
779 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200780 {
781 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200782 'local_addr': local_addr,
783 'peer_addr': peer_addr,
784 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +0100785 'is_delayed': 1 if is_delayed else 0,
786 'bfd_key_id': bfd_key_id,
787 'conf_key_id': conf_key_id,
788 })
789
Klement Sekerab17dd962017-01-09 07:43:48 +0100790 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
791 peer_addr, is_ipv6=0):
792 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200793 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +0100794 'sw_if_index': sw_if_index,
795 'local_addr': local_addr,
796 'peer_addr': peer_addr,
797 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200798 })
799
800 def want_bfd_events(self, enable_disable=1):
801 return self.api(self.papi.want_bfd_events, {
802 'enable_disable': enable_disable,
803 'pid': os.getpid(),
804 })
Steve Shin7957d6e2016-12-19 09:24:50 -0800805
Klement Sekerab17dd962017-01-09 07:43:48 +0100806 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
807 return self.api(self.papi.bfd_auth_set_key, {
808 'conf_key_id': conf_key_id,
809 'auth_type': auth_type,
810 'key': key,
811 'key_len': len(key),
812 })
813
Steve Shin7957d6e2016-12-19 09:24:50 -0800814 def classify_add_del_table(
815 self,
816 is_add,
817 mask,
818 match_n_vectors=1,
819 table_index=0xFFFFFFFF,
820 nbuckets=2,
821 memory_size=2097152,
822 skip_n_vectors=0,
823 next_table_index=0xFFFFFFFF,
824 miss_next_index=0xFFFFFFFF,
825 current_data_flag=0,
826 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -0800827 """
828 :param is_add:
829 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +0100830 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100831 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -0800832 :param nbuckets: (Default value = 2)
833 :param memory_size: (Default value = 2097152)
834 :param skip_n_vectors: (Default value = 0)
835 :param next_table_index: (Default value = 0xFFFFFFFF)
836 :param miss_next_index: (Default value = 0xFFFFFFFF)
837 :param current_data_flag: (Default value = 0)
838 :param current_data_offset: (Default value = 0)
839 """
840
Juraj Sloboda75282452018-06-12 14:20:49 +0200841 mask_len = ((len(mask) - 1) / 16 + 1) * 16
842 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -0800843 return self.api(
844 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100845 {'is_add': is_add,
846 'table_index': table_index,
847 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -0800848 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100849 'skip_n_vectors': skip_n_vectors,
850 'match_n_vectors': match_n_vectors,
851 'next_table_index': next_table_index,
852 'miss_next_index': miss_next_index,
853 'current_data_flag': current_data_flag,
854 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +0200855 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100856 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -0800857
858 def classify_add_del_session(
859 self,
860 is_add,
861 table_index,
862 match,
863 opaque_index=0xFFFFFFFF,
864 hit_next_index=0xFFFFFFFF,
865 advance=0,
866 action=0,
867 metadata=0):
868 """
869 :param is_add:
870 :param table_index:
871 :param match:
872 :param opaque_index: (Default value = 0xFFFFFFFF)
873 :param hit_next_index: (Default value = 0xFFFFFFFF)
874 :param advance: (Default value = 0)
875 :param action: (Default value = 0)
876 :param metadata: (Default value = 0)
877 """
878
Juraj Sloboda75282452018-06-12 14:20:49 +0200879 match_len = ((len(match) - 1) / 16 + 1) * 16
880 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -0800881 return self.api(
882 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100883 {'is_add': is_add,
884 'table_index': table_index,
885 'hit_next_index': hit_next_index,
886 'opaque_index': opaque_index,
887 'advance': advance,
888 'action': action,
889 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +0200890 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100891 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -0800892
893 def input_acl_set_interface(
894 self,
895 is_add,
896 sw_if_index,
897 ip4_table_index=0xFFFFFFFF,
898 ip6_table_index=0xFFFFFFFF,
899 l2_table_index=0xFFFFFFFF):
900 """
901 :param is_add:
902 :param sw_if_index:
903 :param ip4_table_index: (Default value = 0xFFFFFFFF)
904 :param ip6_table_index: (Default value = 0xFFFFFFFF)
905 :param l2_table_index: (Default value = 0xFFFFFFFF)
906 """
907
908 return self.api(
909 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100910 {'sw_if_index': sw_if_index,
911 'ip4_table_index': ip4_table_index,
912 'ip6_table_index': ip6_table_index,
913 'l2_table_index': l2_table_index,
914 'is_add': is_add})
915
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100916 def output_acl_set_interface(
917 self,
918 is_add,
919 sw_if_index,
920 ip4_table_index=0xFFFFFFFF,
921 ip6_table_index=0xFFFFFFFF,
922 l2_table_index=0xFFFFFFFF):
923 """
924 :param is_add:
925 :param sw_if_index:
926 :param ip4_table_index: (Default value = 0xFFFFFFFF)
927 :param ip6_table_index: (Default value = 0xFFFFFFFF)
928 :param l2_table_index: (Default value = 0xFFFFFFFF)
929 """
930
931 return self.api(
932 self.papi.output_acl_set_interface,
933 {'sw_if_index': sw_if_index,
934 'ip4_table_index': ip4_table_index,
935 'ip6_table_index': ip6_table_index,
936 'l2_table_index': l2_table_index,
937 'is_add': is_add})
938
Klement Sekera77fabdb2017-01-02 07:46:14 +0100939 def set_ipfix_exporter(
940 self,
941 collector_address,
942 src_address,
943 path_mtu,
944 template_interval,
945 vrf_id=0,
946 collector_port=4739,
947 udp_checksum=0):
948 return self.api(
949 self.papi.set_ipfix_exporter,
950 {
951 'collector_address': collector_address,
952 'collector_port': collector_port,
953 'src_address': src_address,
954 'vrf_id': vrf_id,
955 'path_mtu': path_mtu,
956 'template_interval': template_interval,
957 'udp_checksum': udp_checksum,
958 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800959
960 def dhcp_proxy_config(self,
961 dhcp_server,
962 dhcp_src_address,
963 rx_table_id=0,
964 server_table_id=0,
965 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800966 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800967 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -0800968 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -0800969 {
970 'rx_vrf_id': rx_table_id,
971 'server_vrf_id': server_table_id,
972 'is_ipv6': is_ipv6,
973 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -0800974 'dhcp_server': dhcp_server,
975 'dhcp_src_address': dhcp_src_address,
976 })
977
978 def dhcp_proxy_set_vss(self,
979 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -0500980 vss_type=255,
981 vpn_ascii_id="",
982 oui=0,
983 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -0800984 is_add=1,
985 is_ip6=0):
986 return self.api(
987 self.papi.dhcp_proxy_set_vss,
988 {
989 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -0500990 'vss_type': vss_type,
991 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800992 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -0500993 'vpn_index': vpn_index,
994 'is_add': is_add,
995 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -0800996 })
Neale Ranns32e1c012016-11-22 17:07:28 +0000997
Ole Troane1ade682019-03-04 23:55:43 +0100998 def dhcp_client_config(self,
999 sw_if_index,
1000 hostname,
1001 client_id='',
1002 is_add=1,
1003 set_broadcast_flag=1,
1004 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001005 return self.api(
1006 self.papi.dhcp_client_config,
1007 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001008 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001009 'client': {
1010 'sw_if_index': sw_if_index,
1011 'hostname': hostname,
1012 'id': client_id,
1013 'want_dhcp_event': want_dhcp_events,
1014 'set_broadcast_flag': set_broadcast_flag,
1015 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001016 })
1017
Neale Ranns32e1c012016-11-22 17:07:28 +00001018 def ip_mroute_add_del(self,
1019 src_address,
1020 grp_address,
1021 grp_address_length,
1022 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001023 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001024 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001025 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001026 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001027 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001028 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001029 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001030 is_add=1,
1031 is_ipv6=0,
1032 is_local=0):
1033 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001034 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001035 """
1036 return self.api(
1037 self.papi.ip_mroute_add_del,
1038 {'next_hop_sw_if_index': next_hop_sw_if_index,
1039 'entry_flags': e_flags,
1040 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001041 'table_id': table_id,
1042 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001043 'is_add': is_add,
1044 'is_ipv6': is_ipv6,
1045 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001046 'bier_imp': bier_imp,
1047 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001048 'grp_address_length': grp_address_length,
1049 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001050 'src_address': src_address,
1051 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001052
Filip Tehlar770e89e2017-01-31 10:39:16 +01001053 def lisp_enable_disable(self, is_enabled):
1054 return self.api(
1055 self.papi.lisp_enable_disable,
1056 {
1057 'is_en': is_enabled,
1058 })
1059
Ole Troane1ade682019-03-04 23:55:43 +01001060 def lisp_add_del_locator_set(self,
1061 ls_name,
1062 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001063 return self.api(
1064 self.papi.lisp_add_del_locator_set,
1065 {
1066 'is_add': is_add,
1067 'locator_set_name': ls_name
1068 })
1069
Ole Troane1ade682019-03-04 23:55:43 +01001070 def lisp_add_del_locator(self,
1071 ls_name,
1072 sw_if_index,
1073 priority=1,
1074 weight=1,
1075 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001076 return self.api(
1077 self.papi.lisp_add_del_locator,
1078 {
1079 'is_add': is_add,
1080 'locator_set_name': ls_name,
1081 'sw_if_index': sw_if_index,
1082 'priority': priority,
1083 'weight': weight
1084 })
1085
1086 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1087 return self.api(
1088 self.papi.lisp_locator_dump,
1089 {
1090 'is_index_set': is_index_set,
1091 'ls_name': ls_name,
1092 'ls_index': ls_index,
1093 })
1094
Ole Troane1ade682019-03-04 23:55:43 +01001095 def lisp_add_del_local_eid(self,
1096 ls_name,
1097 eid_type,
1098 eid,
1099 prefix_len,
1100 vni=0,
1101 key_id=0,
1102 key="",
1103 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001104 return self.api(
1105 self.papi.lisp_add_del_local_eid,
1106 {
1107 'locator_set_name': ls_name,
1108 'is_add': is_add,
1109 'eid_type': eid_type,
1110 'eid': eid,
1111 'prefix_len': prefix_len,
1112 'vni': vni,
1113 'key_id': key_id,
1114 'key': key
1115 })
1116
1117 def lisp_eid_table_dump(self,
1118 eid_set=0,
1119 prefix_length=0,
1120 vni=0,
1121 eid_type=0,
1122 eid=None,
1123 filter_opt=0):
1124 return self.api(
1125 self.papi.lisp_eid_table_dump,
1126 {
1127 'eid_set': eid_set,
1128 'prefix_length': prefix_length,
1129 'vni': vni,
1130 'eid_type': eid_type,
1131 'eid': eid,
1132 'filter': filter_opt,
1133 })
1134
Ole Troane1ade682019-03-04 23:55:43 +01001135 def lisp_add_del_remote_mapping(self,
1136 eid_type,
1137 eid,
1138 eid_prefix_len=0,
1139 vni=0,
1140 rlocs=[],
1141 rlocs_num=0,
1142 is_src_dst=0,
1143 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001144 return self.api(
1145 self.papi.lisp_add_del_remote_mapping,
1146 {
1147 'is_add': is_add,
1148 'eid_type': eid_type,
1149 'eid': eid,
1150 'eid_len': eid_prefix_len,
1151 'rloc_num': rlocs_num,
1152 'rlocs': rlocs,
1153 'vni': vni,
1154 'is_src_dst': is_src_dst,
1155 })
1156
Ole Troane1ade682019-03-04 23:55:43 +01001157 def lisp_add_del_adjacency(self,
1158 leid,
1159 reid,
1160 leid_len,
1161 reid_len,
1162 eid_type,
1163 is_add=1,
1164 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001165 return self.api(
1166 self.papi.lisp_add_del_adjacency,
1167 {
1168 'is_add': is_add,
1169 'vni': vni,
1170 'eid_type': eid_type,
1171 'leid': leid,
1172 'reid': reid,
1173 'leid_len': leid_len,
1174 'reid_len': reid_len,
1175 })
1176
Hongjun Nief486b12017-04-12 19:21:16 +08001177 def gtpu_add_del_tunnel(
1178 self,
1179 src_addr,
1180 dst_addr,
1181 is_add=1,
1182 is_ipv6=0,
1183 mcast_sw_if_index=0xFFFFFFFF,
1184 encap_vrf_id=0,
1185 decap_next_index=0xFFFFFFFF,
1186 teid=0):
1187 """
1188
1189 :param is_add: (Default value = 1)
1190 :param is_ipv6: (Default value = 0)
1191 :param src_addr:
1192 :param dst_addr:
1193 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1194 :param encap_vrf_id: (Default value = 0)
1195 :param decap_next_index: (Default value = 0xFFFFFFFF)
1196 :param teid: (Default value = 0)
1197
1198 """
1199 return self.api(self.papi.gtpu_add_del_tunnel,
1200 {'is_add': is_add,
1201 'is_ipv6': is_ipv6,
1202 'src_address': src_addr,
1203 'dst_address': dst_addr,
1204 'mcast_sw_if_index': mcast_sw_if_index,
1205 'encap_vrf_id': encap_vrf_id,
1206 'decap_next_index': decap_next_index,
1207 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001208
1209 def vxlan_gpe_add_del_tunnel(
1210 self,
1211 src_addr,
1212 dst_addr,
1213 mcast_sw_if_index=0xFFFFFFFF,
1214 is_add=1,
1215 is_ipv6=0,
1216 encap_vrf_id=0,
1217 decap_vrf_id=0,
1218 protocol=3,
1219 vni=0):
1220 """
1221
1222 :param local:
1223 :param remote:
1224 :param is_add: (Default value = 1)
1225 :param is_ipv6: (Default value = 0)
1226 :param encap_vrf_id: (Default value = 0)
1227 :param decap_vrf_id: (Default value = 0)
1228 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1229 :param protocol: (Default value = 3)
1230 :param vni: (Default value = 0)
1231
1232 """
1233 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1234 {'is_add': is_add,
1235 'is_ipv6': is_ipv6,
1236 'local': src_addr,
1237 'remote': dst_addr,
1238 'mcast_sw_if_index': mcast_sw_if_index,
1239 'encap_vrf_id': encap_vrf_id,
1240 'decap_vrf_id': decap_vrf_id,
1241 'protocol': protocol,
1242 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001243
Neale Ranns79a05f52018-09-11 07:39:43 -07001244 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001245 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001246 src,
1247 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001248 mcast_sw_if_index=0xFFFFFFFF,
1249 is_add=1,
1250 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001251 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001252 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001253 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001254 instance=0xFFFFFFFF):
1255 """
1256
1257 :param dst_addr:
1258 :param src_addr:
1259 :param is_add: (Default value = 1)
1260 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001261 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001262 :param decap_next_index: (Default value = 0xFFFFFFFF)
1263 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1264 :param vni: (Default value = 0)
1265 :param instance: (Default value = 0xFFFFFFFF)
1266
1267 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001268 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001269 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001270 'tunnel': {
1271 'src': src,
1272 'dst': dst,
1273 'mcast_sw_if_index': mcast_sw_if_index,
1274 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001275 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001276 'instance': instance,
1277 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001278
1279 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1280 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001281 {'sw_if_index': sw_if_index,
1282 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001283
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001284 def pppoe_add_del_session(
1285 self,
1286 client_ip,
1287 client_mac,
1288 session_id=0,
1289 is_add=1,
1290 is_ipv6=0,
1291 decap_vrf_id=0):
1292 """
1293
1294 :param is_add: (Default value = 1)
1295 :param is_ipv6: (Default value = 0)
1296 :param client_ip:
1297 :param session_id: (Default value = 0)
1298 :param client_mac:
1299 :param decap_vrf_id: (Default value = 0)
1300
1301 """
1302 return self.api(self.papi.pppoe_add_del_session,
1303 {'is_add': is_add,
1304 'is_ipv6': is_ipv6,
1305 'session_id': session_id,
1306 'client_ip': client_ip,
1307 'decap_vrf_id': decap_vrf_id,
1308 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001309
Neale Ranns7c922dc2018-08-30 06:12:27 -07001310 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1311 return self.api(self.papi.sr_mpls_policy_add,
1312 {'bsid': bsid,
1313 'weight': weight,
1314 'type': type,
1315 'n_segments': len(segments),
1316 'segments': segments})
1317
1318 def sr_mpls_policy_del(self, bsid):
1319 return self.api(self.papi.sr_mpls_policy_del,
1320 {'bsid': bsid})
1321
Kris Michielsen91074432017-06-22 13:00:20 +02001322 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001323 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001324 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001325 nh_addr4,
1326 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001327 is_del=0,
1328 end_psp=0,
1329 sw_if_index=0xFFFFFFFF,
1330 vlan_index=0,
1331 fib_table=0,
1332 ):
1333 """ Add/del IPv6 SR local-SID.
1334
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001335 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001336 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1337 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001338 :param nh_addr4:
1339 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001340 :param is_del: (Default value = 0)
1341 :param end_psp: (Default value = 0)
1342 :param sw_if_index: (Default value = 0xFFFFFFFF)
1343 :param vlan_index: (Default value = 0)
1344 :param fib_table: (Default value = 0)
1345 """
1346 return self.api(
1347 self.papi.sr_localsid_add_del,
1348 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001349 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001350 'end_psp': end_psp,
1351 'behavior': behavior,
1352 'sw_if_index': sw_if_index,
1353 'vlan_index': vlan_index,
1354 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001355 'nh_addr4': nh_addr4,
1356 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001357 }
1358 )
1359
1360 def sr_policy_add(
1361 self,
1362 bsid_addr,
1363 weight=1,
1364 is_encap=1,
1365 type=0,
1366 fib_table=0,
1367 n_segments=0,
1368 segments=[]):
1369 """
1370 :param bsid_addr: bindingSID of the SR Policy
1371 :param weight: weight of the sid list. optional. (default: 1)
1372 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1373 (default: Encap)
1374 :param type: type/behavior of the SR policy. (default or spray) \
1375 (default: default)
1376 :param fib_table: VRF where to install the FIB entry for the BSID \
1377 (default: 0)
1378 :param n_segments: number of segments \
1379 (default: 0)
1380 :param segments: a vector of IPv6 address composing the segment list \
1381 (default: [])
1382 """
1383 return self.api(
1384 self.papi.sr_policy_add,
1385 {'bsid_addr': bsid_addr,
1386 'weight': weight,
1387 'is_encap': is_encap,
1388 'type': type,
1389 'fib_table': fib_table,
1390 'n_segments': n_segments,
1391 'segments': segments
1392 }
1393 )
1394
1395 def sr_policy_del(
1396 self,
1397 bsid_addr,
1398 sr_policy_index=0):
1399 """
1400 :param bsid: bindingSID of the SR Policy
1401 :param sr_policy_index: index of the sr policy (default: 0)
1402 """
1403 return self.api(
1404 self.papi.sr_policy_del,
1405 {'bsid_addr': bsid_addr,
1406 'sr_policy_index': sr_policy_index
1407 })
1408
1409 def sr_steering_add_del(
1410 self,
1411 is_del,
1412 bsid_addr,
1413 sr_policy_index,
1414 table_id,
1415 prefix_addr,
1416 mask_width,
1417 sw_if_index,
1418 traffic_type):
1419 """
1420 Steer traffic L2 and L3 traffic through a given SR policy
1421
1422 :param is_del: delete or add
1423 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1424 :param sr_policy: is the index of the SR Policy (alt to bsid)
1425 :param table_id: is the VRF where to install the FIB entry for the BSID
1426 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1427 :param mask_width: is the mask for L3 traffic type
1428 :param sw_if_index: is the incoming interface for L2 traffic
1429 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1430 """
1431 return self.api(
1432 self.papi.sr_steering_add_del,
1433 {'is_del': is_del,
1434 'bsid_addr': bsid_addr,
1435 'sr_policy_index': sr_policy_index,
1436 'table_id': table_id,
1437 'prefix_addr': prefix_addr,
1438 'mask_width': mask_width,
1439 'sw_if_index': sw_if_index,
1440 'traffic_type': traffic_type
1441 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001442
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001443 def acl_add_replace(self, acl_index, r, tag='',
1444 expected_retval=0):
1445 """Add/replace an ACL
1446 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1447 :param acl_rule r: ACL rules array.
1448 :param str tag: symbolic tag (description) for this ACL.
1449 :param int count: number of rules.
1450 """
1451 return self.api(self.papi.acl_add_replace,
1452 {'acl_index': acl_index,
1453 'r': r,
1454 'count': len(r),
1455 'tag': tag},
1456 expected_retval=expected_retval)
1457
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001458 def acl_del(self, acl_index, expected_retval=0):
1459 """
1460
1461 :param acl_index:
1462 :return:
1463 """
1464 return self.api(self.papi.acl_del,
1465 {'acl_index': acl_index},
1466 expected_retval=expected_retval)
1467
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001468 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1469 expected_retval=0):
1470 return self.api(self.papi.acl_interface_set_acl_list,
1471 {'sw_if_index': sw_if_index,
1472 'count': len(acls),
1473 'n_input': n_input,
1474 'acls': acls},
1475 expected_retval=expected_retval)
1476
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001477 def acl_interface_set_etype_whitelist(self, sw_if_index,
1478 n_input, whitelist,
1479 expected_retval=0):
1480 return self.api(self.papi.acl_interface_set_etype_whitelist,
1481 {'sw_if_index': sw_if_index,
1482 'count': len(whitelist),
1483 'n_input': n_input,
1484 'whitelist': whitelist},
1485 expected_retval=expected_retval)
1486
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001487 def acl_interface_add_del(self,
1488 sw_if_index,
1489 acl_index,
1490 is_add=1):
1491 """ Add/Delete ACL to/from interface
1492
1493 :param sw_if_index:
1494 :param acl_index:
1495 :param is_add: (Default value = 1)
1496 """
1497
1498 return self.api(self.papi.acl_interface_add_del,
1499 {'is_add': is_add,
1500 'is_input': 1,
1501 'sw_if_index': sw_if_index,
1502 'acl_index': acl_index})
1503
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001504 def acl_dump(self, acl_index, expected_retval=0):
1505 return self.api(self.papi.acl_dump,
1506 {'acl_index': acl_index},
1507 expected_retval=expected_retval)
1508
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001509 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1510 expected_retval=0):
1511 return self.api(self.papi.acl_interface_list_dump,
1512 {'sw_if_index': sw_if_index},
1513 expected_retval=expected_retval)
1514
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001515 def macip_acl_add(self, rules, tag=""):
1516 """ Add MACIP acl
1517
1518 :param rules: list of rules for given acl
1519 :param tag: acl tag
1520 """
1521
1522 return self.api(self.papi.macip_acl_add,
1523 {'r': rules,
1524 'count': len(rules),
1525 'tag': tag})
1526
Pavel Kotucek932f7412017-09-07 14:44:52 +02001527 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1528 """ Add MACIP acl
1529
1530 :param rules: list of rules for given acl
1531 :param tag: acl tag
1532 """
1533
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001534 return self.api(self.papi.macip_acl_add_replace,
1535 {'acl_index': acl_index,
1536 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001537 'count': len(rules),
1538 'tag': tag})
1539
Pavel Kotucek932f7412017-09-07 14:44:52 +02001540 def macip_acl_interface_add_del(self,
1541 sw_if_index,
1542 acl_index,
1543 is_add=1):
1544 """ Add MACIP acl to interface
1545
1546 :param sw_if_index:
1547 :param acl_index:
1548 :param is_add: (Default value = 1)
1549 """
1550
1551 return self.api(self.papi.macip_acl_interface_add_del,
1552 {'is_add': is_add,
1553 'sw_if_index': sw_if_index,
1554 'acl_index': acl_index})
1555
Pavel Kotucek932f7412017-09-07 14:44:52 +02001556 def macip_acl_dump(self, acl_index=4294967295):
1557 """ Return MACIP acl dump
1558 """
1559
1560 return self.api(
1561 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001562
1563 def policer_add_del(self,
1564 name,
1565 cir,
1566 eir,
1567 cb,
1568 eb,
1569 is_add=1,
1570 rate_type=0,
1571 round_type=0,
1572 ptype=0,
1573 color_aware=0,
1574 conform_action_type=1,
1575 conform_dscp=0,
1576 exceed_action_type=0,
1577 exceed_dscp=0,
1578 violate_action_type=0,
1579 violate_dscp=0):
1580 return self.api(self.papi.policer_add_del,
1581 {'name': name,
1582 'cir': cir,
1583 'eir': eir,
1584 'cb': cb,
1585 'eb': eb,
1586 'is_add': is_add,
1587 'rate_type': rate_type,
1588 'round_type': round_type,
1589 'type': ptype,
1590 'color_aware': color_aware,
1591 'conform_action_type': conform_action_type,
1592 'conform_dscp': conform_dscp,
1593 'exceed_action_type': exceed_action_type,
1594 'exceed_dscp': exceed_dscp,
1595 'violate_action_type': violate_action_type,
1596 'violate_dscp': violate_dscp})
1597
1598 def ip_punt_police(self,
1599 policer_index,
1600 is_ip6=0,
1601 is_add=1):
1602 return self.api(self.papi.ip_punt_police,
1603 {'policer_index': policer_index,
1604 'is_add': is_add,
1605 'is_ip6': is_ip6})
1606
1607 def ip_punt_redirect(self,
1608 rx_sw_if_index,
1609 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001610 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001611 is_add=1):
1612 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001613 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1614 'tx_sw_if_index': tx_sw_if_index,
1615 'nh': address},
1616 'is_add': is_add})
1617
1618 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1619 return self.api(self.papi.ip_punt_redirect_dump,
1620 {'sw_if_index': sw_if_index,
1621 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001622
1623 def bier_table_add_del(self,
1624 bti,
1625 mpls_label,
1626 is_add=1):
1627 """ BIER Table add/del """
1628 return self.api(
1629 self.papi.bier_table_add_del,
1630 {'bt_tbl_id': {"bt_set": bti.set_id,
1631 "bt_sub_domain": bti.sub_domain_id,
1632 "bt_hdr_len_id": bti.hdr_len_id},
1633 'bt_label': mpls_label,
1634 'bt_is_add': is_add})
1635
1636 def bier_table_dump(self):
1637 return self.api(self.papi.bier_table_dump, {})
1638
1639 def bier_route_add_del(self,
1640 bti,
1641 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001642 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001643 is_add=1,
1644 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001645 """ BIER Route add/del """
1646 return self.api(
1647 self.papi.bier_route_add_del,
1648 {'br_tbl_id': {"bt_set": bti.set_id,
1649 "bt_sub_domain": bti.sub_domain_id,
1650 "bt_hdr_len_id": bti.hdr_len_id},
1651 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08001652 'br_n_paths': len(paths),
1653 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001654 'br_is_add': is_add,
1655 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001656
1657 def bier_route_dump(self, bti):
1658 return self.api(
1659 self.papi.bier_route_dump,
1660 {'br_tbl_id': {"bt_set": bti.set_id,
1661 "bt_sub_domain": bti.sub_domain_id,
1662 "bt_hdr_len_id": bti.hdr_len_id}})
1663
1664 def bier_imp_add(self,
1665 bti,
1666 src,
1667 ibytes,
1668 is_add=1):
1669 """ BIER Imposition Add """
1670 return self.api(
1671 self.papi.bier_imp_add,
1672 {'bi_tbl_id': {"bt_set": bti.set_id,
1673 "bt_sub_domain": bti.sub_domain_id,
1674 "bt_hdr_len_id": bti.hdr_len_id},
1675 'bi_src': src,
1676 'bi_n_bytes': len(ibytes),
1677 'bi_bytes': ibytes})
1678
1679 def bier_imp_del(self, bi_index):
1680 """ BIER Imposition del """
1681 return self.api(
1682 self.papi.bier_imp_del,
1683 {'bi_index': bi_index})
1684
1685 def bier_imp_dump(self):
1686 return self.api(self.papi.bier_imp_dump, {})
1687
1688 def bier_disp_table_add_del(self,
1689 bdti,
1690 is_add=1):
1691 """ BIER Disposition Table add/del """
1692 return self.api(
1693 self.papi.bier_disp_table_add_del,
1694 {'bdt_tbl_id': bdti,
1695 'bdt_is_add': is_add})
1696
1697 def bier_disp_table_dump(self):
1698 return self.api(self.papi.bier_disp_table_dump, {})
1699
1700 def bier_disp_entry_add_del(self,
1701 bdti,
1702 bp,
1703 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001704 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001705 next_hop,
1706 next_hop_tbl_id=0,
1707 next_hop_rpf_id=~0,
1708 next_hop_is_ip4=1,
1709 is_add=1):
1710 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001711 lstack = []
1712 while (len(lstack) < 16):
1713 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001714 return self.api(
1715 self.papi.bier_disp_entry_add_del,
1716 {'bde_tbl_id': bdti,
1717 'bde_bp': bp,
1718 'bde_payload_proto': payload_proto,
1719 'bde_n_paths': 1,
1720 'bde_paths': [{'next_hop': next_hop,
1721 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08001722 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001723 'rpf_id': next_hop_rpf_id,
1724 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001725 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001726 'bde_is_add': is_add})
1727
1728 def bier_disp_entry_dump(self, bdti):
1729 return self.api(
1730 self.papi.bier_disp_entry_dump,
1731 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001732
Florin Coras3ea6ce22017-12-11 09:09:05 -08001733 def session_enable_disable(self, is_enabled):
1734 return self.api(
1735 self.papi.session_enable_disable,
1736 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001737
1738 def ipsec_spd_add_del(self, spd_id, is_add=1):
1739 """ SPD add/del - Wrapper to add or del ipsec SPD
1740 Sample CLI : 'ipsec spd add 1'
1741
1742 :param spd_id - SPD ID to be created in the vpp . mandatory
1743 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1744 optional
1745 :returns: reply from the API
1746 """
1747 return self.api(
1748 self.papi.ipsec_spd_add_del, {
1749 'spd_id': spd_id, 'is_add': is_add})
1750
Neale Ranns311124e2019-01-24 04:52:25 -08001751 def ipsec_spds_dump(self):
1752 return self.api(self.papi.ipsec_spds_dump, {})
1753
“mystarrocks”23f0c452017-12-11 07:11:51 -08001754 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1755 """ IPSEC interface SPD add/del - \
1756 Wrapper to associate/disassociate SPD to interface in VPP
1757 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1758
1759 :param spd_id - SPD ID to associate with the interface . mandatory
1760 :param sw_if_index - Interface Index which needs to ipsec \
1761 association mandatory
1762 :param is_add - add(1) or del(0) association with interface \
1763 (Default 1 - add) . optional
1764 :returns: reply from the API
1765 """
1766 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001767 self.papi.ipsec_interface_add_del_spd,
1768 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001769
Neale Ranns311124e2019-01-24 04:52:25 -08001770 def ipsec_spd_interface_dump(self, spd_index=None):
1771 return self.api(self.papi.ipsec_spd_interface_dump,
1772 {'spd_index': spd_index if spd_index else 0,
1773 'spd_index_valid': 1 if spd_index else 0})
1774
Neale Ranns17dcec02019-01-09 21:22:20 -08001775 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001776 sad_id,
1777 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001778 integrity_algorithm,
1779 integrity_key,
1780 crypto_algorithm,
1781 crypto_key,
1782 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001783 tunnel_src_address='',
1784 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001785 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001786 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001787 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001788 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001789 :param sad_id: security association ID
1790 :param spi: security param index of the SA in decimal
1791 :param integrity_algorithm:
1792 :param integrity_key:
1793 :param crypto_algorithm:
1794 :param crypto_key:
1795 :param protocol: AH(0) or ESP(1) protocol
1796 :param tunnel_src_address: tunnel mode outer src address
1797 :param tunnel_dst_address: tunnel mode outer dst address
1798 :param is_add:
1799 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001800 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1801 crypto and ipsec algorithms
1802 """
1803 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001804 self.papi.ipsec_sad_entry_add_del,
1805 {
1806 'is_add': is_add,
1807 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001808 {
1809 'sad_id': sad_id,
1810 'spi': spi,
1811 'tunnel_src': tunnel_src_address,
1812 'tunnel_dst': tunnel_dst_address,
1813 'protocol': protocol,
1814 'integrity_algorithm': integrity_algorithm,
1815 'integrity_key': {
1816 'length': len(integrity_key),
1817 'data': integrity_key,
1818 },
1819 'crypto_algorithm': crypto_algorithm,
1820 'crypto_key': {
1821 'length': len(crypto_key),
1822 'data': crypto_key,
1823 },
1824 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001825 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001826 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001827 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001828
Neale Ranns311124e2019-01-24 04:52:25 -08001829 def ipsec_sa_dump(self, sa_id=None):
1830 return self.api(self.papi.ipsec_sa_dump,
1831 {'sa_id': sa_id if sa_id else 0xffffffff})
1832
Neale Ranns17dcec02019-01-09 21:22:20 -08001833 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001834 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001835 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001836 local_address_start,
1837 local_address_stop,
1838 remote_address_start,
1839 remote_address_stop,
1840 local_port_start=0,
1841 local_port_stop=65535,
1842 remote_port_start=0,
1843 remote_port_stop=65535,
1844 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001845 policy=0,
1846 priority=100,
1847 is_outbound=1,
1848 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001849 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001850 is_ip_any=0):
1851 """ IPSEC policy SPD add/del -
1852 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001853 :param spd_id: SPD ID for the policy
1854 :param local_address_start: local-ip-range start address
1855 :param local_address_stop : local-ip-range stop address
1856 :param remote_address_start: remote-ip-range start address
1857 :param remote_address_stop : remote-ip-range stop address
1858 :param local_port_start: (Default value = 0)
1859 :param local_port_stop: (Default value = 65535)
1860 :param remote_port_start: (Default value = 0)
1861 :param remote_port_stop: (Default value = 65535)
1862 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1863 :param sa_id: Security Association ID for mapping it to SPD
1864 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1865 (Default value = 0)
1866 :param priority: value for the spd action (Default value = 100)
1867 :param is_outbound: flag for inbound(0) or outbound(1)
1868 (Default value = 1)
1869 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001870 """
1871 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001872 self.papi.ipsec_spd_entry_add_del,
1873 {
1874 'is_add': is_add,
1875 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001876 {
1877 'spd_id': spd_id,
1878 'sa_id': sa_id,
1879 'local_address_start': local_address_start,
1880 'local_address_stop': local_address_stop,
1881 'remote_address_start': remote_address_start,
1882 'remote_address_stop': remote_address_stop,
1883 'local_port_start': local_port_start,
1884 'local_port_stop': local_port_stop,
1885 'remote_port_start': remote_port_start,
1886 'remote_port_stop': remote_port_stop,
1887 'protocol': protocol,
1888 'policy': policy,
1889 'priority': priority,
1890 'is_outbound': is_outbound,
1891 'is_ip_any': is_ip_any
1892 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001893 })
Florin Corasb795bd02017-12-14 11:30:48 -08001894
Neale Ranns311124e2019-01-24 04:52:25 -08001895 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1896 return self.api(self.papi.ipsec_spd_dump,
1897 {'spd_id': spd_id,
1898 'sa_id': sa_id})
1899
Klement Sekera31da2e32018-06-24 22:49:55 +02001900 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1901 remote_spi, crypto_alg, local_crypto_key,
1902 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001903 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02001904 anti_replay=1, renumber=0, show_instance=0):
1905 return self.api(
1906 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001907 {
1908 'local_ip': local_ip,
1909 'remote_ip': remote_ip,
1910 'local_spi': local_spi,
1911 'remote_spi': remote_spi,
1912 'crypto_alg': crypto_alg,
1913 'local_crypto_key_len': len(local_crypto_key),
1914 'local_crypto_key': local_crypto_key,
1915 'remote_crypto_key_len': len(remote_crypto_key),
1916 'remote_crypto_key': remote_crypto_key,
1917 'integ_alg': integ_alg,
1918 'local_integ_key_len': len(local_integ_key),
1919 'local_integ_key': local_integ_key,
1920 'remote_integ_key_len': len(remote_integ_key),
1921 'remote_integ_key': remote_integ_key,
1922 'is_add': is_add,
1923 'esn': esn,
1924 'anti_replay': anti_replay,
1925 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001926 'show_instance': show_instance,
1927 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001928 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001929
Neale Rannsf05e7322019-03-29 20:23:58 +00001930 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
1931 sa_out, sa_in, is_add=1):
1932 return self.api(self.papi.ipsec_gre_tunnel_add_del,
1933 {
1934 'is_add': is_add,
1935 'tunnel': {
1936 'src': local_ip,
1937 'dst': remote_ip,
1938 'local_sa_id': sa_out,
1939 'remote_sa_id': sa_in
1940 }
1941 })
1942
Klement Sekerab4d30532018-11-08 13:00:02 +01001943 def ipsec_select_backend(self, protocol, index):
1944 return self.api(self.papi.ipsec_select_backend,
1945 {'protocol': protocol, 'index': index})
1946
1947 def ipsec_backend_dump(self):
1948 return self.api(self.papi.ipsec_backend_dump, {})
1949
Ole Troane1ade682019-03-04 23:55:43 +01001950 def app_namespace_add_del(self,
1951 namespace_id,
1952 ip4_fib_id=0,
1953 ip6_fib_id=0,
1954 sw_if_index=0xFFFFFFFF,
1955 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001956 return self.api(
1957 self.papi.app_namespace_add_del,
1958 {'secret': secret,
1959 'sw_if_index': sw_if_index,
1960 'ip4_fib_id': ip4_fib_id,
1961 'ip6_fib_id': ip6_fib_id,
1962 'namespace_id': namespace_id,
1963 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001964
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001965 def punt_socket_register(self, port, pathname, protocol=0x11,
1966 header_version=1, is_ip4=1):
1967 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001968 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001969 {'header_version': header_version,
1970 'punt': {'ipv': is_ip4,
1971 'l4_protocol': protocol,
1972 'l4_port': port},
1973 'pathname': pathname})
1974
1975 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
1976 """ Unregister punt socket """
1977 return self.api(self.papi.punt_socket_deregister,
1978 {'punt': {'ipv': is_ip4,
1979 'l4_protocol': protocol,
1980 'l4_port': port}})
1981
1982 def punt_socket_dump(self, is_ip6=1):
1983 """ Dump punt socket"""
1984 return self.api(self.papi.punt_socket_dump,
1985 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02001986
Neale Ranns4ba67722019-02-28 11:11:39 +00001987 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001988 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001989 """ GBP endpoint Add """
1990 return self.api(self.papi.gbp_endpoint_add,
1991 {'endpoint': {
1992 'sw_if_index': sw_if_index,
1993 'ips': ips,
1994 'n_ips': len(ips),
1995 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001996 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001997 'flags': flags,
1998 'tun': {
1999 'src': tun_src,
2000 'dst': tun_dst,
2001 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002002
2003 def gbp_endpoint_del(self, handle):
2004 """ GBP endpoint Del """
2005 return self.api(self.papi.gbp_endpoint_del,
2006 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002007
2008 def gbp_endpoint_dump(self):
2009 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002010 return self.api(self.papi.gbp_endpoint_dump,
2011 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002012
Neale Ranns4ba67722019-02-28 11:11:39 +00002013 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002014 rd, uplink_sw_if_index,
2015 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002016 """ GBP endpoint group Add """
2017 return self.api(self.papi.gbp_endpoint_group_add,
2018 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002019 {
2020 'uplink_sw_if_index': uplink_sw_if_index,
2021 'bd_id': bd,
2022 'rd_id': rd,
2023 'vnid': vnid,
2024 'sclass': sclass,
2025 'retention': retention
2026 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002027
Neale Ranns4ba67722019-02-28 11:11:39 +00002028 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002029 """ GBP endpoint group Del """
2030 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002031 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002032
Neale Rannsc29c0af2018-11-07 04:21:12 -08002033 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002034 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002035 uu_fwd_sw_if_index,
2036 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002037 """ GBP bridge-domain Add """
2038 return self.api(self.papi.gbp_bridge_domain_add,
2039 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002040 {
2041 'flags': flags,
2042 'bvi_sw_if_index': bvi_sw_if_index,
2043 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2044 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2045 'bd_id': bd_id
2046 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002047
2048 def gbp_bridge_domain_del(self, bd_id):
2049 """ GBP bridge-domain Del """
2050 return self.api(self.papi.gbp_bridge_domain_del,
2051 {'bd_id': bd_id})
2052
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002053 def gbp_route_domain_add(self, rd_id,
2054 ip4_table_id,
2055 ip6_table_id,
2056 ip4_uu_sw_if_index,
2057 ip6_uu_sw_if_index):
2058 """ GBP route-domain Add """
2059 return self.api(self.papi.gbp_route_domain_add,
2060 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002061 {
2062 'ip4_table_id': ip4_table_id,
2063 'ip6_table_id': ip6_table_id,
2064 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2065 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2066 'rd_id': rd_id
2067 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002068
2069 def gbp_route_domain_del(self, rd_id):
2070 """ GBP route-domain Del """
2071 return self.api(self.papi.gbp_route_domain_del,
2072 {'rd_id': rd_id})
2073
Neale Ranns4ba67722019-02-28 11:11:39 +00002074 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002075 """ GBP recirc Add/Del """
2076 return self.api(self.papi.gbp_recirc_add_del,
2077 {'is_add': is_add,
2078 'recirc': {
2079 'is_ext': is_ext,
2080 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002081 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002082
2083 def gbp_recirc_dump(self):
2084 """ GBP recirc Dump """
2085 return self.api(self.papi.gbp_recirc_dump, {})
2086
Neale Rannsb6a47952018-11-21 05:44:35 -08002087 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2088 """ GBP recirc Add/Del """
2089 return self.api(self.papi.gbp_ext_itf_add_del,
2090 {'is_add': is_add,
2091 'ext_itf': {
2092 'sw_if_index': sw_if_index,
2093 'bd_id': bd_id,
2094 'rd_id': rd_id}})
2095
2096 def gbp_ext_itf_dump(self):
2097 """ GBP recirc Dump """
2098 return self.api(self.papi.gbp_ext_itf_dump, {})
2099
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002100 def gbp_subnet_add_del(self, is_add, rd_id,
2101 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002102 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002103 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002104 """ GBP Subnet Add/Del """
2105 return self.api(self.papi.gbp_subnet_add_del,
2106 {'is_add': is_add,
2107 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002108 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002109 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002110 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002111 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002112 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002113
2114 def gbp_subnet_dump(self):
2115 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002116 return self.api(self.papi.gbp_subnet_dump,
2117 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002118
Neale Ranns4ba67722019-02-28 11:11:39 +00002119 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002120 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002121 """ GBP contract Add/Del """
2122 return self.api(self.papi.gbp_contract_add_del,
2123 {'is_add': is_add,
2124 'contract': {
2125 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002126 'sclass': sclass,
2127 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002128 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002129 'rules': rules,
2130 'n_ether_types': len(allowed_ethertypes),
2131 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002132
2133 def gbp_contract_dump(self):
2134 """ GBP contract Dump """
2135 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002136
Neale Ranns8da9fc62019-03-04 14:08:11 -08002137 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002138 """ GBP VXLAN tunnel add """
2139 return self.api(self.papi.gbp_vxlan_tunnel_add,
2140 {
2141 'tunnel': {
2142 'vni': vni,
2143 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002144 'bd_rd_id': bd_rd_id,
2145 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002146 }
2147 })
2148
2149 def gbp_vxlan_tunnel_del(self, vni):
2150 """ GBP VXLAN tunnel del """
2151 return self.api(self.papi.gbp_vxlan_tunnel_del,
2152 {
2153 'vni': vni,
2154 })
2155
2156 def gbp_vxlan_tunnel_dump(self):
2157 """ GBP VXLAN tunnel add/del """
2158 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2159
Neale Ranns039cbfe2018-02-27 03:45:38 -08002160 def qos_egress_map_update(self, id, outputs):
2161 """ QOS egress map update """
2162 return self.api(self.papi.qos_egress_map_update,
2163 {'map_id': id,
2164 'rows': outputs})
2165
2166 def qos_egress_map_delete(self, id):
2167 """ QOS egress map delete """
2168 return self.api(self.papi.qos_egress_map_delete,
2169 {'map_id': id})
2170
2171 def qos_mark_enable_disable(self, sw_if_index,
2172 output_source,
2173 map_id,
2174 enable):
2175 """ QOS Mark Enable/Disable """
2176 return self.api(self.papi.qos_mark_enable_disable,
2177 {'map_id': map_id,
2178 'sw_if_index': sw_if_index,
2179 'output_source': output_source,
2180 'enable': enable})
2181
Neale Ranns947ea622018-06-07 23:48:20 -07002182 def igmp_enable_disable(self, sw_if_index, enable, host):
2183 """ Enable/disable IGMP on a given interface """
2184 return self.api(self.papi.igmp_enable_disable,
2185 {'enable': enable,
2186 'mode': host,
2187 'sw_if_index': sw_if_index})
2188
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002189 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2190 """ Add/del IGMP proxy device """
2191 return self.api(self.papi.igmp_proxy_device_add_del,
2192 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2193 'add': add})
2194
2195 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2196 """ Add/del interface to/from IGMP proxy device """
2197 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2198 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2199 'add': add})
2200
Neale Ranns947ea622018-06-07 23:48:20 -07002201 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002202 """ Listen for new (S,G) on specified interface
2203
2204 :param enable: add/del
2205 :param sw_if_index: interface sw index
2206 :param saddr: source ip4 addr
2207 :param gaddr: group ip4 addr
2208 """
2209 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002210 {
2211 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002212 {
2213 'filter': filter,
2214 'sw_if_index': sw_if_index,
2215 'n_srcs': len(saddrs),
2216 'saddrs': saddrs,
2217 'gaddr': gaddr
2218 }
Neale Ranns947ea622018-06-07 23:48:20 -07002219 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002220
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002221 def igmp_clear_interface(self, sw_if_index):
2222 """ Remove all (S,G)s from specified interface
2223 doesn't send IGMP report!
2224 """
2225 return self.api(
2226 self.papi.igmp_clear_interface, {
2227 'sw_if_index': sw_if_index})
2228
2229 def want_igmp_events(self, enable=1):
2230 return self.api(self.papi.want_igmp_events, {'enable': enable,
2231 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002232
2233 def bond_create(
2234 self,
2235 mode,
2236 lb,
2237 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002238 mac_address='',
2239 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002240 """
2241 :param mode: mode
2242 :param lb: load balance
2243 :param use_custom_mac: use custom mac
2244 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002245 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002246 """
2247 return self.api(
2248 self.papi.bond_create,
2249 {'mode': mode,
2250 'lb': lb,
2251 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002252 'mac_address': mac_address,
2253 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002254 })
2255
Neale Ranns17ff3c12018-07-04 10:24:24 -07002256 def pipe_delete(self, parent_sw_if_index):
2257 return self.api(self.papi.pipe_delete,
2258 {'parent_sw_if_index': parent_sw_if_index})
2259
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002260 def memif_create(
2261 self,
2262 role,
2263 mode,
2264 rx_queues=None,
2265 tx_queues=None,
2266 _id=None,
2267 socket_id=None,
2268 secret=None,
2269 ring_size=None,
2270 buffer_size=None,
2271 hw_addr=None):
2272 return self.api(self.papi.memif_create,
2273 {'role': role,
2274 'mode': mode,
2275 'rx_queues': rx_queues,
2276 'tx_queues': tx_queues,
2277 'id': _id,
2278 'socket_id': socket_id,
2279 'secret': secret,
2280 'ring_size': ring_size,
2281 'buffer_size': buffer_size,
2282 'hw_addr': hw_addr})
2283
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002284 def svs_table_add_del(self, af, table_id, is_add=1):
2285 return self.api(self.papi.svs_table_add_del,
2286 {
2287 'table_id': table_id,
2288 'is_add': is_add,
2289 'af': af,
2290 })
2291
2292 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2293 return self.api(self.papi.svs_route_add_del,
2294 {
2295 'table_id': table_id,
2296 'source_table_id': src_table_id,
2297 'prefix': prefix,
2298 'is_add': is_add,
2299 })
2300
2301 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2302 return self.api(self.papi.svs_enable_disable,
2303 {
2304 'af': af,
2305 'table_id': table_id,
2306 'sw_if_index': sw_if_index,
2307 'is_enable': is_enable,
2308 })