blob: 1fcc4ceeef293eda5e3024e4ae90e99ffc1efbfa [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import os
2import fnmatch
3import time
Klement Sekeraf62ae122016-10-11 11:47:09 +02004from hook import Hook
Klement Sekerae4504c62016-12-08 10:16:41 +01005from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02006
Klement Sekera0e3c0de2016-09-29 14:43:44 +02007# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +01008# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
9# the vpp_papi_provider.py file to be importable without having to build
10# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020011do_import = True
12try:
13 no_vpp_papi = os.getenv("NO_VPP_PAPI")
14 if no_vpp_papi == "1":
15 do_import = False
16except:
17 pass
18
19if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010020 from vpp_papi import VPP
Neale Ranns93cc3ee2018-10-10 07:22:51 -070021 from vpp_l2 import L2_PORT_TYPE
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030029 L2_DISABLED = 0
30 L2_PUSH_1 = 1
31 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000032 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030033 L2_POP_2 = 4
34 L2_TRANSLATE_1_1 = 5
35 L2_TRANSLATE_1_2 = 6
36 L2_TRANSLATE_2_1 = 7
37 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000038
Klement Sekera0e3c0de2016-09-29 14:43:44 +020039
Neale Ranns039cbfe2018-02-27 03:45:38 -080040class QOS_SOURCE:
41 EXT = 0
42 VLAN = 1
43 MPLS = 2
44 IP = 3
45
46
Klement Sekera73884482017-02-23 09:26:30 +010047class UnexpectedApiReturnValueError(Exception):
48 """ exception raised when the API return value is unexpected """
49 pass
50
51
Klement Sekeraf62ae122016-10-11 11:47:09 +020052class VppPapiProvider(object):
53 """VPP-api provider using vpp-papi
54
55 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020056 """
57
Klement Sekerae0545ef2017-01-25 08:00:40 +010058 _zero, _negative = range(2)
59
Klement Sekera611864f2018-09-26 11:19:00 +020060 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020061 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020062 self.name = name
63 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010064 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010065 self._expect_api_retval = self._zero
66 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010067 jsonfiles = []
68
Klement Sekera0e3c0de2016-09-29 14:43:44 +020069 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010070 for root, dirnames, filenames in os.walk(install_dir):
71 for filename in fnmatch.filter(filenames, '*.api.json'):
72 jsonfiles.append(os.path.join(root, filename))
73
Klement Sekera611864f2018-09-26 11:19:00 +020074 self.vpp = VPP(jsonfiles, logger=test_class.logger,
75 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010076 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020077
Klement Sekerae0545ef2017-01-25 08:00:40 +010078 def __enter__(self):
79 return self
80
Klement Sekera7d6afb32018-11-08 11:52:04 +010081 def assert_negative_api_retval(self):
82 """ Expect API failure - used with with, e.g.:
83 with self.vapi.assert_negative_api_retval():
84 self.vapi.<api call expected to fail>
85 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010086 self._expect_stack.append(self._expect_api_retval)
87 self._expect_api_retval = self._negative
88 return self
89
Klement Sekera7d6afb32018-11-08 11:52:04 +010090 def assert_zero_api_retval(self):
91 """ Expect API success - used with with, e.g.:
92 with self.vapi.assert_negative_api_retval():
93 self.vapi.<api call expected to succeed>
94
95 note: this is useful only inside another with block
96 as success is the default expected value
97 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010098 self._expect_stack.append(self._expect_api_retval)
99 self._expect_api_retval = self._zero
100 return self
101
102 def __exit__(self, exc_type, exc_value, traceback):
103 self._expect_api_retval = self._expect_stack.pop()
104
Klement Sekeraf62ae122016-10-11 11:47:09 +0200105 def register_hook(self, hook):
106 """Replace hook registration with new hook
107
108 :param hook:
109
110 """
111 self.hook = hook
112
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200113 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100114 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200115 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100116 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200117 return e
118
119 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100120 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100121 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100122 self.test_class.logger.debug("Expecting event '%s' within %ss",
123 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300124 else:
125 self.test_class.logger.debug("Expecting event within %ss",
126 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100127 if self._events:
128 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200129 limit = time.time() + timeout
130 while time.time() < limit:
131 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100132 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200133 if name and type(e).__name__ != name:
134 raise Exception(
135 "Unexpected event received: %s, expected: %s" %
136 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100137 self.test_class.logger.debug("Returning event %s:%s" %
138 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200139 return e
140 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200141 raise Exception("Event did not occur within timeout")
142
143 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100144 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200145 # FIXME use the name instead of relying on type(e).__name__ ?
146 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100147 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200148 self._events.append(event)
149
Klement Sekeraf62ae122016-10-11 11:47:09 +0200150 def connect(self):
151 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100152 self.vpp.connect(self.name, self.shm_prefix)
153 self.papi = self.vpp.api
154 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200155
156 def disconnect(self):
157 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100158 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200159
160 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100161 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200162 Call the appropriate hooks before and after the API call
163
164 :param api_fn: API function to call
165 :param api_args: tuple of API function arguments
166 :param expected_retval: Expected return value (Default value = 0)
167 :returns: reply from the API
168
169 """
170 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100171 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100172 if self._expect_api_retval == self._negative:
173 if hasattr(reply, 'retval') and reply.retval >= 0:
174 msg = "API call passed unexpectedly: expected negative "\
175 "return value instead of %d in %s" % \
176 (reply.retval, repr(reply))
177 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100178 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100179 elif self._expect_api_retval == self._zero:
180 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700181 msg = "API call failed, expected %d return value instead "\
182 "of %d in %s" % (expected_retval, reply.retval,
183 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100184 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100185 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100186 else:
187 raise Exception("Internal error, unexpected value for "
188 "self._expect_api_retval %s" %
189 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200190 self.hook.after_api(api_fn.__name__, api_args)
191 return reply
192
193 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100194 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195
196 :param cli: CLI to execute
197 :returns: CLI output
198
199 """
200 self.hook.before_cli(cli)
201 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100202 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200203 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200204 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100205 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206
Jan49c0fca2016-10-26 15:44:27 +0200207 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100208 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200209
210 :param cli: CLI to execute
211 :returns: CLI output
212 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600213 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200214
Jan4af521d2016-11-15 17:05:00 +0100215 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200216 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100217
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218 def show_version(self):
219 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100220 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221
222 def pg_create_interface(self, pg_index):
223 """
224
225 :param pg_index:
226
227 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100228 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200229 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200230
231 def sw_interface_dump(self, filter=None):
232 """
233
234 :param filter: (Default value = None)
235
236 """
237 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200238 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200239 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100240 args = {}
241 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200242
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000243 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100244 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000245
246 :param sw_if_index:
247 :param is_ipv6:
248 :param table_id:
249
250 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100251 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200252 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
253 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000254
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700255 def sw_interface_get_table(self, sw_if_index, is_ipv6):
256 """ Get the IPvX Table-id for the Interface
257
258 :param sw_if_index:
259 :param is_ipv6:
260 :return table_id
261
262 """
263 return self.api(self.papi.sw_interface_get_table,
264 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
265
Klement Sekeraf62ae122016-10-11 11:47:09 +0200266 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
267 is_ipv6=0, is_add=1, del_all=0):
268 """
269
270 :param addr: param is_ipv6: (Default value = 0)
271 :param sw_if_index:
272 :param addr_len:
273 :param is_ipv6: (Default value = 0)
274 :param is_add: (Default value = 1)
275 :param del_all: (Default value = 0)
276
277 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100278 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200279 {'sw_if_index': sw_if_index,
280 'is_add': is_add,
281 'is_ipv6': is_ipv6,
282 'del_all': del_all,
283 'address_length': addr_len,
284 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200285
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700286 def ip_address_dump(self, sw_if_index, is_ipv6=0):
287 return self.api(self.papi.ip_address_dump,
288 {'sw_if_index': sw_if_index,
289 'is_ipv6': is_ipv6})
290
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800291 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
292 is_add=1):
293 """ Set the Interface to be unnumbered
294
295 :param is_add: (Default value = 1)
296 :param sw_if_index - interface That will be unnumbered
297 :param ip_sw_if_index - interface with an IP addres
298
299 """
300 return self.api(self.papi.sw_interface_set_unnumbered,
301 {'sw_if_index': ip_sw_if_index,
302 'unnumbered_sw_if_index': sw_if_index,
303 'is_add': is_add})
304
Neale Ranns404d88e2018-08-08 06:37:33 -0700305 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
306 return self.api(self.papi.ip_unnumbered_dump,
307 {'sw_if_index': sw_if_index})
308
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000309 def sw_interface_enable_disable_mpls(self, sw_if_index,
310 is_enable=1):
311 """
312 Enable/Disable MPLS on the interface
313 :param sw_if_index:
314 :param is_enable: (Default value = 1)
315
316 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100317 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200318 {'sw_if_index': sw_if_index,
319 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000320
Jan Gelety057bb8c2016-12-20 17:32:45 +0100321 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100322 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100323 {'sw_if_index': sw_if_index,
324 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200325
Neale Ranns227038a2017-04-21 01:07:59 -0700326 def set_ip_flow_hash(self,
327 table_id,
328 src=1,
329 dst=1,
330 sport=1,
331 dport=1,
332 proto=1,
333 reverse=0,
334 is_ip6=0):
335 return self.api(self.papi.set_ip_flow_hash,
336 {'vrf_id': table_id,
337 'src': src,
338 'dst': dst,
339 'dport': dport,
340 'sport': sport,
341 'proto': proto,
342 'reverse': reverse,
343 'is_ipv6': is_ip6})
344
Neale Ranns3f844d02017-02-18 00:03:54 -0800345 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
346 return self.api(self.papi.ip6nd_proxy_add_del,
347 {'address': address,
348 'sw_if_index': sw_if_index,
349 'is_del': is_del})
350
Neale Ranns75152282017-01-09 01:00:45 -0800351 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000352 no,
Neale Ranns75152282017-01-09 01:00:45 -0800353 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000354 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800355 return self.api(self.papi.sw_interface_ip6nd_ra_config,
356 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000357 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100358 'suppress': suppress,
359 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800360
Neale Ranns87df12d2017-02-18 08:16:41 -0800361 def ip6_sw_interface_ra_prefix(self,
362 sw_if_index,
363 address,
364 address_length,
365 use_default=0,
366 no_advertise=0,
367 off_link=0,
368 no_autoconfig=0,
369 no_onlink=0,
370 is_no=0,
371 val_lifetime=0xffffffff,
372 pref_lifetime=0xffffffff):
373 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
374 {'sw_if_index': sw_if_index,
375 'address': address,
376 'address_length': address_length,
377 'use_default': use_default,
378 'no_advertise': no_advertise,
379 'off_link': off_link,
380 'no_autoconfig': no_autoconfig,
381 'no_onlink': no_onlink,
382 'is_no': is_no,
383 'val_lifetime': val_lifetime,
384 'pref_lifetime': pref_lifetime})
385
Neale Ranns75152282017-01-09 01:00:45 -0800386 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
387 """
388 Enable/Disable An interface for IPv6
389 """
390 return self.api(self.papi.sw_interface_ip6_enable_disable,
391 {'sw_if_index': sw_if_index,
392 'enable': enable})
393
Klement Sekeraf62ae122016-10-11 11:47:09 +0200394 def vxlan_add_del_tunnel(
395 self,
396 src_addr,
397 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200398 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200399 is_add=1,
400 is_ipv6=0,
401 encap_vrf_id=0,
402 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600403 vni=0,
404 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405 """
406
407 :param dst_addr:
408 :param src_addr:
409 :param is_add: (Default value = 1)
410 :param is_ipv6: (Default value = 0)
411 :param encap_vrf_id: (Default value = 0)
412 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200413 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200414 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600415 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200416
417 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100418 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200419 {'is_add': is_add,
420 'is_ipv6': is_ipv6,
421 'src_address': src_addr,
422 'dst_address': dst_addr,
423 'mcast_sw_if_index': mcast_sw_if_index,
424 'encap_vrf_id': encap_vrf_id,
425 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600426 'vni': vni,
427 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200428
Marco Varleseb598f1d2017-09-19 14:25:28 +0200429 def geneve_add_del_tunnel(
430 self,
431 local_addr,
432 remote_addr,
433 mcast_sw_if_index=0xFFFFFFFF,
434 is_add=1,
435 is_ipv6=0,
436 encap_vrf_id=0,
437 decap_next_index=0xFFFFFFFF,
438 vni=0):
439 """
440
441 :param remote_addr:
442 :param local_addr:
443 :param is_add: (Default value = 1)
444 :param is_ipv6: (Default value = 0)
445 :param encap_vrf_id: (Default value = 0)
446 :param decap_next_index: (Default value = 0xFFFFFFFF)
447 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
448 :param vni: (Default value = 0)
449
450 """
451 return self.api(self.papi.geneve_add_del_tunnel,
452 {'is_add': is_add,
453 'is_ipv6': is_ipv6,
454 'local_address': local_addr,
455 'remote_address': remote_addr,
456 'mcast_sw_if_index': mcast_sw_if_index,
457 'encap_vrf_id': encap_vrf_id,
458 'decap_next_index': decap_next_index,
459 'vni': vni})
460
Jan4af521d2016-11-15 17:05:00 +0100461 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
462 learn=1, arp_term=0, is_add=1):
463 """Create/delete bridge domain.
464
465 :param int bd_id: Bridge domain index.
466 :param int flood: Enable/disable bcast/mcast flooding in the BD.
467 (Default value = 1)
468 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
469 (Default value = 1)
470 :param int forward: Enable/disable forwarding on all interfaces in
471 the BD. (Default value = 1)
472 :param int learn: Enable/disable learning on all interfaces in the BD.
473 (Default value = 1)
474 :param int arp_term: Enable/disable arp termination in the BD.
475 (Default value = 1)
476 :param int is_add: Add or delete flag. (Default value = 1)
477 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100478 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200479 {'bd_id': bd_id,
480 'flood': flood,
481 'uu_flood': uu_flood,
482 'forward': forward,
483 'learn': learn,
484 'arp_term': arp_term,
485 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100486
Eyal Baric86e5922017-07-02 18:33:16 +0300487 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
488 return self.api(self.papi.bd_ip_mac_add_del,
489 {'bd_id': bd_id,
490 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700491 'ip': ip,
492 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300493
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700494 def bd_ip_mac_dump(self, bd_id):
495 return self.api(self.papi.bd_ip_mac_dump,
496 {'bd_id': bd_id})
497
Eyal Bari20197482017-09-13 12:29:08 +0300498 def want_ip4_arp_events(self, enable_disable=1, address=0):
499 return self.api(self.papi.want_ip4_arp_events,
500 {'enable_disable': enable_disable,
501 'address': address,
502 'pid': os.getpid(), })
503
Eyal Baric125ecc2017-09-20 11:29:17 +0300504 def want_ip6_nd_events(self, enable_disable=1, address=0):
505 return self.api(self.papi.want_ip6_nd_events,
506 {'enable_disable': enable_disable,
507 'address': address,
508 'pid': os.getpid(), })
509
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100510 def want_ip6_ra_events(self, enable_disable=1):
511 return self.api(self.papi.want_ip6_ra_events,
512 {'enable_disable': enable_disable,
513 'pid': os.getpid(), })
514
515 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
516 mrc=0, mrd=0):
517 return self.api(self.papi.ip6nd_send_router_solicitation,
518 {'irt': irt,
519 'mrt': mrt,
520 'mrc': mrc,
521 'mrd': mrd,
522 'sw_if_index': sw_if_index})
523
Juraj Slobodac0374232018-02-01 15:18:49 +0100524 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
525 install_default_routes):
526 return self.api(self.papi.ip6_nd_address_autoconfig,
527 {'sw_if_index': sw_if_index,
528 'enable': enable,
529 'install_default_routes': install_default_routes})
530
Juraj Slobodab3f90502018-10-04 15:15:16 +0200531 def want_interface_events(self, enable_disable=1):
532 return self.api(self.papi.want_interface_events,
533 {'enable_disable': enable_disable,
534 'pid': os.getpid(), })
535
Eyal Bari24db0ec2017-09-27 21:43:51 +0300536 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
537 max_macs_in_event=0, learn_limit=0):
538 return self.api(self.papi.want_l2_macs_events,
539 {'enable_disable': enable_disable,
540 'scan_delay': scan_delay,
541 'max_macs_in_event': max_macs_in_event,
542 'learn_limit': learn_limit,
543 'pid': os.getpid(), })
544
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200545 def want_dhcp6_reply_events(self, enable_disable=1):
546 return self.api(self.papi.want_dhcp6_reply_events,
547 {'enable_disable': enable_disable,
548 'pid': os.getpid()})
549
Juraj Sloboda81119e82018-05-25 14:02:20 +0200550 def want_dhcp6_pd_reply_events(self, enable_disable=1):
551 return self.api(self.papi.want_dhcp6_pd_reply_events,
552 {'enable_disable': enable_disable,
553 'pid': os.getpid()})
554
555 def dhcp6_clients_enable_disable(self, enable=1):
556 return self.api(self.papi.dhcp6_clients_enable_disable,
557 {'enable': enable})
558
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200559 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
560 addresses, server_index=0xFFFFFFFF,
561 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
562 ):
563 return self.api(self.papi.dhcp6_send_client_message,
564 {'sw_if_index': sw_if_index,
565 'server_index': server_index,
566 'irt': irt,
567 'mrt': mrt,
568 'mrc': mrc,
569 'mrd': mrd,
570 'stop': stop,
571 'msg_type': msg_type,
572 'T1': T1,
573 'T2': T2,
574 'n_addresses': len(addresses),
575 'addresses': addresses})
576
Juraj Sloboda81119e82018-05-25 14:02:20 +0200577 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
578 prefixes, server_index=0xFFFFFFFF,
579 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
580 ):
581 return self.api(self.papi.dhcp6_pd_send_client_message,
582 {'sw_if_index': sw_if_index,
583 'server_index': server_index,
584 'irt': irt,
585 'mrt': mrt,
586 'mrc': mrc,
587 'mrd': mrd,
588 'stop': stop,
589 'msg_type': msg_type,
590 'T1': T1,
591 'T2': T2,
592 'n_prefixes': len(prefixes),
593 'prefixes': prefixes})
594
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200595 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
596 enable=1):
597 return self.api(self.papi.dhcp6_client_enable_disable,
598 {'sw_if_index': sw_if_index,
599 'enable': enable})
600
Juraj Sloboda81119e82018-05-25 14:02:20 +0200601 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
602 enable=1):
603 return self.api(self.papi.dhcp6_pd_client_enable_disable,
604 {'sw_if_index': sw_if_index,
605 'prefix_group': prefix_group,
606 'enable': enable})
607
608 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
609 prefix_length, prefix_group,
610 is_add=1):
611 return self.api(self.papi.ip6_add_del_address_using_prefix,
612 {'sw_if_index': sw_if_index,
613 'prefix_group': prefix_group,
614 'address': address,
615 'prefix_length': prefix_length,
616 'is_add': is_add})
617
Jan4af521d2016-11-15 17:05:00 +0100618 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
619 filter_mac=0, bvi_mac=0):
620 """Create/delete L2 FIB entry.
621
622 :param str mac: MAC address to create FIB entry for.
623 :param int bd_id: Bridge domain index.
624 :param int sw_if_index: Software interface index of the interface.
625 :param int is_add: Add or delete flag. (Default value = 1)
626 :param int static_mac: Set to 1 to create static MAC entry.
627 (Default value = 0)
628 :param int filter_mac: Set to 1 to drop packet that's source or
629 destination MAC address contains defined MAC address.
630 (Default value = 0)
631 :param int bvi_mac: Set to 1 to create entry that points to BVI
632 interface. (Default value = 0)
633 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100634 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200635 {'mac': self._convert_mac(mac),
636 'bd_id': bd_id,
637 'sw_if_index': sw_if_index,
638 'is_add': is_add,
639 'static_mac': static_mac,
640 'filter_mac': filter_mac,
641 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100642
Eyal Bari93b503e2017-05-15 10:13:15 +0300643 def l2fib_flush_int(self, sw_if_index):
644 """Flush L2 FIB entries for sw_if_index.
645
646 :param int sw_if_index: Software interface index of the interface.
647 """
648 return self.api(self.papi.l2fib_flush_int,
649 {'sw_if_index': sw_if_index})
650
651 def l2fib_flush_bd(self, bd_id):
652 """Flush L2 FIB entries for bd_id.
653
654 :param int sw_if_index: Bridge Domain id.
655 """
656 return self.api(self.papi.l2fib_flush_bd,
657 {'bd_id': bd_id})
658
659 def l2fib_flush_all(self):
660 """Flush all L2 FIB.
661 """
662 return self.api(self.papi.l2fib_flush_all, {})
663
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700664 def l2_fib_table_dump(self, bd_id):
665 """ Dump the L2 FIB """
666 return self.api(self.papi.l2_fib_table_dump,
667 {'bd_id': bd_id})
668
Klement Sekeraf62ae122016-10-11 11:47:09 +0200669 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700670 shg=0, port_type=L2_PORT_TYPE.NORMAL,
671 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100672 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200673
Jan4af521d2016-11-15 17:05:00 +0100674 :param int sw_if_index: Software interface index of the interface.
675 :param int bd_id: Bridge domain index.
676 :param int shg: Split-horizon group index. (Default value = 0)
677 :param int bvi: Set interface as a bridge group virtual interface.
678 (Default value = 0)
679 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200680 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100681 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200682 {'rx_sw_if_index': sw_if_index,
683 'bd_id': bd_id,
684 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700685 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200686 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200687
Jan00dad122016-11-29 10:04:53 +0100688 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400689 """Enable/disable required feature of the bridge domain with defined
690 ID.
Jan00dad122016-11-29 10:04:53 +0100691
692 :param int bd_id: Bridge domain ID.
693 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700694 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100695 - learn (1 << 0),
696 - forward (1 << 1),
697 - flood (1 << 2),
698 - uu-flood (1 << 3) or
699 - arp-term (1 << 4).
700 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100701 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200702 {'bd_id': bd_id,
703 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700704 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100705
706 def bridge_domain_dump(self, bd_id=0):
707 """
708
709 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
710 existing bridge domains returned)
711 :return: Dictionary of bridge domain(s) data.
712 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100713 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200714 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100715
Klement Sekeraf62ae122016-10-11 11:47:09 +0200716 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
717 enable):
718 """Create or delete unidirectional cross-connect from Tx interface to
719 Rx interface.
720
Jan4af521d2016-11-15 17:05:00 +0100721 :param int rx_sw_if_index: Software interface index of Rx interface.
722 :param int tx_sw_if_index: Software interface index of Tx interface.
723 :param int enable: Create cross-connect if equal to 1, delete
724 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200725
726 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100727 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200728 {'rx_sw_if_index': rx_sw_if_index,
729 'tx_sw_if_index': tx_sw_if_index,
730 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200731
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200732 def sw_interface_set_l2_tag_rewrite(
733 self,
734 sw_if_index,
735 vtr_oper,
736 push=0,
737 tag1=0,
738 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000739 """L2 interface vlan tag rewrite configure request
740 :param client_index - opaque cookie to identify the sender
741 :param context - sender context, to match reply w/ request
742 :param sw_if_index - interface the operation is applied to
743 :param vtr_op - Choose from l2_vtr_op_t enum values
744 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
745 :param tag1 - Needed for any push or translate vtr op
746 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
747
748 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100749 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200750 {'sw_if_index': sw_if_index,
751 'vtr_op': vtr_oper,
752 'push_dot1q': push,
753 'tag1': tag1,
754 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000755
Neale Ranns55d03782017-10-21 06:34:22 -0700756 def sw_interface_set_l2_emulation(
757 self,
758 sw_if_index,
759 enable=1):
760 """L2 Emulation
761 :param sw_if_index - interface the operation is applied to
762
763 """
764 return self.api(self.papi.l2_emulation,
765 {'sw_if_index': sw_if_index,
766 'enable': enable})
767
Neale Ranns1855b8e2018-07-11 10:31:26 -0700768 def sw_interface_set_ip_directed_broadcast(
769 self,
770 sw_if_index,
771 enable=1):
772 """IP Directed broadcast
773 :param sw_if_index - interface the operation is applied to
774
775 """
776 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
777 {'sw_if_index': sw_if_index,
778 'enable': enable})
779
Neale Rannsa07bd702017-08-07 07:53:49 -0700780 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200781 """
782
783 :param admin_up_down:
784 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200785
786 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100787 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200788 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700789 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200790
Ole Troand7231612018-06-07 10:17:57 +0200791 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800792 """
793 :param sw_if_index:
794 :param mtu:
795
796 """
797 return self.api(self.papi.sw_interface_set_mtu,
798 {'sw_if_index': sw_if_index,
799 'mtu': mtu})
800
Neale Ranns25b04942018-04-04 09:34:50 -0700801 def sw_interface_set_promiscuous(self, sw_if_index, enable):
802 """
803 :param sw_if_index:
804 :param enable:
805
806 """
807 return self.api(self.papi.sw_interface_set_promiscuous,
808 {'sw_if_index': sw_if_index,
809 'enable': enable})
810
Neale Rannsc819fc62018-02-16 02:44:05 -0800811 def sw_interface_set_mac_address(self, sw_if_index, mac):
812 return self.api(self.papi.sw_interface_set_mac_address,
813 {'sw_if_index': sw_if_index,
814 'mac_address': mac})
815
Klement Sekeraf62ae122016-10-11 11:47:09 +0200816 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
817 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
818 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
819 """Create subinterface
820 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
821
822 :param sub_id: param inner_vlan:
823 :param sw_if_index:
824 :param outer_vlan:
825 :param inner_vlan:
826 :param no_tags: (Default value = 0)
827 :param one_tag: (Default value = 0)
828 :param two_tags: (Default value = 0)
829 :param dot1ad: (Default value = 0)
830 :param exact_match: (Default value = 0)
831 :param default_sub: (Default value = 0)
832 :param outer_vlan_id_any: (Default value = 0)
833 :param inner_vlan_id_any: (Default value = 0)
834
835 """
836 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100837 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200838 {'sw_if_index': sw_if_index,
839 'sub_id': sub_id,
840 'no_tags': no_tags,
841 'one_tag': one_tag,
842 'two_tags': two_tags,
843 'dot1ad': dot1ad,
844 'exact_match': exact_match,
845 'default_sub': default_sub,
846 'outer_vlan_id_any': outer_vlan_id_any,
847 'inner_vlan_id_any': inner_vlan_id_any,
848 'outer_vlan_id': outer_vlan,
849 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200850
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200851 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
852 """Create p2p ethernet subinterface
853
854 :param sw_if_index: main (parent) interface
855 :param remote_mac: client (remote) mac address
856
857 """
858 return self.api(
859 self.papi.p2p_ethernet_add,
860 {'parent_if_index': sw_if_index,
861 'remote_mac': remote_mac,
862 'subif_id': subif_id})
863
Neale Ranns177bbdc2016-11-15 09:46:51 +0000864 def delete_subif(self, sw_if_index):
865 """Delete subinterface
866
867 :param sw_if_index:
868 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100869 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200870 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000871
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200872 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
873 """Delete p2p ethernet subinterface
874
875 :param sw_if_index: main (parent) interface
876 :param remote_mac: client (remote) mac address
877
878 """
879 return self.api(
880 self.papi.p2p_ethernet_del,
881 {'parent_if_index': sw_if_index,
882 'remote_mac': remote_mac})
883
Klement Sekeraf62ae122016-10-11 11:47:09 +0200884 def create_vlan_subif(self, sw_if_index, vlan):
885 """
886
887 :param vlan:
888 :param sw_if_index:
889
890 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100891 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200892 {'sw_if_index': sw_if_index,
893 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200894
Matej Klotton0178d522016-11-04 11:11:44 +0100895 def create_loopback(self, mac=''):
896 """
897
898 :param mac: (Optional)
899 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100900 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200901 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100902
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100903 def delete_loopback(self, sw_if_index):
904 return self.api(self.papi.delete_loopback,
905 {'sw_if_index': sw_if_index, })
906
Neale Ranns15002542017-09-10 04:39:11 -0700907 def ip_table_add_del(self,
908 table_id,
909 is_add=1,
910 is_ipv6=0):
911 """
912
913 :param table_id
914 :param is_add: (Default value = 1)
915 :param is_ipv6: (Default value = 0)
916
917 """
918
919 return self.api(
920 self.papi.ip_table_add_del,
921 {'table_id': table_id,
922 'is_add': is_add,
923 'is_ipv6': is_ipv6})
924
Klement Sekeraf62ae122016-10-11 11:47:09 +0200925 def ip_add_del_route(
926 self,
927 dst_address,
928 dst_address_length,
929 next_hop_address,
930 next_hop_sw_if_index=0xFFFFFFFF,
931 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200932 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000933 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200934 next_hop_n_out_labels=0,
935 next_hop_out_label_stack=[],
936 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800937 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000938 is_resolve_host=0,
939 is_resolve_attached=0,
940 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200941 is_add=1,
942 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200943 is_unreach=0,
944 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200945 is_ipv6=0,
946 is_local=0,
947 is_classify=0,
948 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800949 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800950 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200951 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200952 """
953
954 :param dst_address_length:
955 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
956 :param dst_address:
957 :param next_hop_address:
958 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
959 :param vrf_id: (Default value = 0)
960 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200961 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200962 :param is_add: (Default value = 1)
963 :param is_drop: (Default value = 0)
964 :param is_ipv6: (Default value = 0)
965 :param is_local: (Default value = 0)
966 :param is_classify: (Default value = 0)
967 :param is_multipath: (Default value = 0)
968 :param is_resolve_host: (Default value = 0)
969 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800970 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700971 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200972 :param next_hop_weight: (Default value = 1)
973
974 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000975
Klement Sekeraf62ae122016-10-11 11:47:09 +0200976 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100977 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200978 {'next_hop_sw_if_index': next_hop_sw_if_index,
979 'table_id': table_id,
980 'classify_table_index': classify_table_index,
981 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200982 'is_add': is_add,
983 'is_drop': is_drop,
984 'is_unreach': is_unreach,
985 'is_prohibit': is_prohibit,
986 'is_ipv6': is_ipv6,
987 'is_local': is_local,
988 'is_classify': is_classify,
989 'is_multipath': is_multipath,
990 'is_resolve_host': is_resolve_host,
991 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800992 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700993 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800994 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200995 'next_hop_weight': next_hop_weight,
996 'dst_address_length': dst_address_length,
997 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800998 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200999 'next_hop_address': next_hop_address,
1000 'next_hop_n_out_labels': next_hop_n_out_labels,
1001 'next_hop_via_label': next_hop_via_label,
1002 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001003
Matej Klotton16a14cd2016-12-07 15:09:13 +01001004 def ip_fib_dump(self):
1005 return self.api(self.papi.ip_fib_dump, {})
1006
Jan Gelety057bb8c2016-12-20 17:32:45 +01001007 def ip6_fib_dump(self):
1008 return self.api(self.papi.ip6_fib_dump, {})
1009
Matej Klotton0178d522016-11-04 11:11:44 +01001010 def ip_neighbor_add_del(self,
1011 sw_if_index,
1012 mac_address,
1013 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001014 is_add=1,
1015 is_ipv6=0,
1016 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001017 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +01001018 ):
1019 """ Add neighbor MAC to IPv4 or IPv6 address.
1020
1021 :param sw_if_index:
1022 :param mac_address:
1023 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001024 :param is_add: (Default value = 1)
1025 :param is_ipv6: (Default value = 0)
1026 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001027 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001028 """
1029
1030 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001031 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001032 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001033 'is_add': is_add,
1034 'is_ipv6': is_ipv6,
1035 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001036 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001037 'mac_address': mac_address,
1038 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001039 }
Matej Klotton0178d522016-11-04 11:11:44 +01001040 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001041
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001042 def ip_neighbor_dump(self,
1043 sw_if_index,
1044 is_ipv6=0):
1045 """ Return IP neighbor dump.
1046
1047 :param sw_if_index:
1048 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1049 """
1050
1051 return self.api(
1052 self.papi.ip_neighbor_dump,
1053 {'is_ipv6': is_ipv6,
1054 'sw_if_index': sw_if_index
1055 }
1056 )
1057
1058 def proxy_arp_add_del(self,
1059 low_address,
1060 hi_address,
1061 vrf_id=0,
1062 is_add=1):
1063 """ Config Proxy Arp Range.
1064
1065 :param low_address: Start address in the rnage to Proxy for
1066 :param hi_address: End address in the rnage to Proxy for
1067 :param vrf_id: The VRF/table in which to proxy
1068 """
1069
1070 return self.api(
1071 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001072 {'proxy':
1073 {
1074 'vrf_id': vrf_id,
1075 'low_address': low_address,
1076 'hi_address': hi_address,
1077 },
1078 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001079
1080 def proxy_arp_intfc_enable_disable(self,
1081 sw_if_index,
1082 is_enable=1):
1083 """ Enable/Disable an interface for proxy ARP requests
1084
1085 :param sw_if_index: Interface
1086 :param enable_disable: Enable/Disable
1087 """
1088
1089 return self.api(
1090 self.papi.proxy_arp_intfc_enable_disable,
1091 {'sw_if_index': sw_if_index,
1092 'enable_disable': is_enable
1093 }
1094 )
1095
Jane546d3b2016-12-08 13:10:03 +01001096 def reset_vrf(self,
1097 vrf_id,
1098 is_ipv6=0,
1099 ):
1100 """ Reset VRF (remove all routes etc.) request.
1101
1102 :param int vrf_id: ID of the FIB table / VRF to reset.
1103 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1104 """
1105
1106 return self.api(
1107 self.papi.reset_vrf,
1108 {'vrf_id': vrf_id,
1109 'is_ipv6': is_ipv6,
1110 }
1111 )
1112
1113 def reset_fib(self,
1114 vrf_id,
1115 is_ipv6=0,
1116 ):
1117 """ Reset VRF (remove all routes etc.) request.
1118
1119 :param int vrf_id: ID of the FIB table / VRF to reset.
1120 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1121 """
1122
1123 return self.api(
1124 self.papi.reset_fib,
1125 {'vrf_id': vrf_id,
1126 'is_ipv6': is_ipv6,
1127 }
1128 )
1129
1130 def ip_dump(self,
1131 is_ipv6=0,
1132 ):
1133 """ Return IP dump.
1134
1135 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1136 """
1137
1138 return self.api(
1139 self.papi.ip_dump,
1140 {'is_ipv6': is_ipv6,
1141 }
1142 )
1143
Klement Sekera7bb873a2016-11-18 07:38:42 +01001144 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001145 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001146 """
1147
1148 :param sw_if_index_from:
1149 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001150 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001151 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001152 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001153 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001154 {'sw_if_index_from': sw_if_index_from,
1155 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001156 'state': state,
1157 'is_l2': is_l2,
1158 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001159
1160 def gre_tunnel_add_del(self,
1161 src_address,
1162 dst_address,
1163 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001164 tunnel_type=0,
1165 instance=0xFFFFFFFF,
1166 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001167 is_add=1,
1168 is_ip6=0):
1169 """ Add a GRE tunnel
1170
1171 :param src_address:
1172 :param dst_address:
1173 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001174 :param tunnel_type: (Default value = 0)
1175 :param instance: (Default value = 0xFFFFFFFF)
1176 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001177 :param is_add: (Default value = 1)
1178 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001179 """
1180
1181 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001182 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001183 {'is_add': is_add,
1184 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001185 'tunnel_type': tunnel_type,
1186 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001187 'src_address': src_address,
1188 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001189 'outer_fib_id': outer_fib_id,
1190 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001191 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001192
Neale Rannsd0df49f2018-08-08 01:06:40 -07001193 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001194 src_ip,
1195 dst_ip,
1196 src_port,
1197 dst_port,
1198 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001199 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001200 :param src_ip:
1201 :param dst_ip:
1202 :param src_port:
1203 :param dst_port:
1204 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001205 """
1206
1207 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001208 self.papi.udp_encap_add,
1209 {
1210 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001211 'src_ip': src_ip,
1212 'dst_ip': dst_ip,
1213 'src_port': src_port,
1214 'dst_port': dst_port,
1215 'table_id': table_id
1216 }
1217 })
1218
1219 def udp_encap_del(self, id):
1220 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001221
1222 def udp_encap_dump(self):
1223 return self.api(self.papi.udp_encap_dump, {})
1224
Neale Ranns43b1f442018-03-20 01:47:35 -07001225 def want_udp_encap_stats(self, enable=1):
1226 return self.api(self.papi.want_udp_encap_stats,
1227 {'enable': enable,
1228 'pid': os.getpid()})
1229
Neale Ranns5a8123b2017-01-26 01:18:23 -08001230 def mpls_fib_dump(self):
1231 return self.api(self.papi.mpls_fib_dump, {})
1232
Neale Ranns15002542017-09-10 04:39:11 -07001233 def mpls_table_add_del(
1234 self,
1235 table_id,
1236 is_add=1):
1237 """
1238
1239 :param table_id
1240 :param is_add: (Default value = 1)
1241
1242 """
1243
1244 return self.api(
1245 self.papi.mpls_table_add_del,
1246 {'mt_table_id': table_id,
1247 'mt_is_add': is_add})
1248
Neale Rannsad422ed2016-11-02 14:20:04 +00001249 def mpls_route_add_del(
1250 self,
1251 label,
1252 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001253 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001254 next_hop_address,
1255 next_hop_sw_if_index=0xFFFFFFFF,
1256 table_id=0,
1257 next_hop_table_id=0,
1258 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001259 next_hop_n_out_labels=0,
1260 next_hop_out_label_stack=[],
1261 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001262 is_resolve_host=0,
1263 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001264 is_interface_rx=0,
1265 is_rpf_id=0,
1266 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001267 is_add=1,
1268 is_drop=0,
1269 is_multipath=0,
1270 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001271 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001272 """
1273
1274 :param dst_address_length:
1275 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1276 :param dst_address:
1277 :param next_hop_address:
1278 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1279 :param vrf_id: (Default value = 0)
1280 :param lookup_in_vrf: (Default value = 0)
1281 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001282 :param is_add: (Default value = 1)
1283 :param is_drop: (Default value = 0)
1284 :param is_ipv6: (Default value = 0)
1285 :param is_local: (Default value = 0)
1286 :param is_classify: (Default value = 0)
1287 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001288 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001289 :param is_resolve_host: (Default value = 0)
1290 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001291 :param next_hop_weight: (Default value = 1)
1292
1293 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001294 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001295 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001296 {'mr_label': label,
1297 'mr_eos': eos,
1298 'mr_table_id': table_id,
1299 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001300 'mr_is_add': is_add,
1301 'mr_is_classify': is_classify,
1302 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001303 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001304 'mr_is_resolve_host': is_resolve_host,
1305 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001306 'mr_is_interface_rx': is_interface_rx,
1307 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001308 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001309 'mr_next_hop_weight': next_hop_weight,
1310 'mr_next_hop': next_hop_address,
1311 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1312 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1313 'mr_next_hop_table_id': next_hop_table_id,
1314 'mr_next_hop_via_label': next_hop_via_label,
1315 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001316
1317 def mpls_ip_bind_unbind(
1318 self,
1319 label,
1320 dst_address,
1321 dst_address_length,
1322 table_id=0,
1323 ip_table_id=0,
1324 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001325 is_bind=1):
1326 """
1327 """
1328 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001329 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001330 {'mb_mpls_table_id': table_id,
1331 'mb_label': label,
1332 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001333 'mb_is_bind': is_bind,
1334 'mb_is_ip4': is_ip4,
1335 'mb_address_length': dst_address_length,
1336 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001337
1338 def mpls_tunnel_add_del(
1339 self,
1340 tun_sw_if_index,
1341 next_hop_proto_is_ip4,
1342 next_hop_address,
1343 next_hop_sw_if_index=0xFFFFFFFF,
1344 next_hop_table_id=0,
1345 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001346 next_hop_n_out_labels=0,
1347 next_hop_out_label_stack=[],
1348 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001349 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001350 l2_only=0,
1351 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001352 """
1353
1354 :param dst_address_length:
1355 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1356 :param dst_address:
1357 :param next_hop_address:
1358 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1359 :param vrf_id: (Default value = 0)
1360 :param lookup_in_vrf: (Default value = 0)
1361 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001362 :param is_add: (Default value = 1)
1363 :param is_drop: (Default value = 0)
1364 :param is_ipv6: (Default value = 0)
1365 :param is_local: (Default value = 0)
1366 :param is_classify: (Default value = 0)
1367 :param is_multipath: (Default value = 0)
1368 :param is_resolve_host: (Default value = 0)
1369 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001370 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001371 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001372
1373 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001374 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001375 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001376 {'mt_sw_if_index': tun_sw_if_index,
1377 'mt_is_add': is_add,
1378 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001379 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001380 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1381 'mt_next_hop_weight': next_hop_weight,
1382 'mt_next_hop': next_hop_address,
1383 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1384 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1385 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001386 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001387 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001388
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001389 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1390 return self.api(self.papi.mpls_tunnel_dump,
1391 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001392
Matus Fabian2ba92e32017-08-21 07:05:03 -07001393 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001394 self,
1395 sw_if_index,
1396 is_inside=1,
1397 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001398 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001399
1400 :param sw_if_index: Software index of the interface
1401 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1402 :param is_add: 1 if add, 0 if delete (Default value = 1)
1403 """
1404 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001405 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001406 {'is_add': is_add,
1407 'is_inside': is_inside,
1408 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001409
Matus Fabian2ba92e32017-08-21 07:05:03 -07001410 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001411 self,
1412 sw_if_index,
1413 is_inside=1,
1414 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001415 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001416
1417 :param sw_if_index: Software index of the interface
1418 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1419 :param is_add: 1 if add, 0 if delete (Default value = 1)
1420 """
1421 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001422 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001423 {'is_add': is_add,
1424 'is_inside': is_inside,
1425 'sw_if_index': sw_if_index})
1426
Matus Fabian2ba92e32017-08-21 07:05:03 -07001427 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001428 self,
1429 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001430 external_ip=0,
1431 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001432 local_port=0,
1433 external_port=0,
1434 addr_only=1,
1435 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001436 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001437 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001438 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001439 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001440 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001441 is_add=1):
1442 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001443
1444 :param local_ip: Local IP address
1445 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001446 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001447 :param local_port: Local port number (Default value = 0)
1448 :param external_port: External port number (Default value = 0)
1449 :param addr_only: 1 if address only mapping, 0 if address and port
1450 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001451 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001452 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001453 :param self_twice_nat: 1 if translate external host address and port
1454 whenever external host address equals
1455 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001456 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001457 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001458 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001459 """
1460 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001461 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001462 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001463 'addr_only': addr_only,
1464 'local_ip_address': local_ip,
1465 'external_ip_address': external_ip,
1466 'local_port': local_port,
1467 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001468 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001469 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001470 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001471 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001472 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001473 'out2in_only': out2in_only,
1474 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001475
Matus Fabianab7a8052017-11-28 04:29:41 -08001476 def nat44_add_del_identity_mapping(
1477 self,
1478 ip='0',
1479 sw_if_index=0xFFFFFFFF,
1480 port=0,
1481 addr_only=1,
1482 vrf_id=0,
1483 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001484 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001485 is_add=1):
1486 """Add/delete NAT44 identity mapping
1487
1488 :param ip: IP address (Default value = 0)
1489 :param sw_if_index: Interface instead of IP address
1490 :param port: Port number (Default value = 0)
1491 :param addr_only: 1 if address only mapping, 0 if address and port
1492 :param vrf_id: VRF ID
1493 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001494 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001495 :param is_add: 1 if add, 0 if delete (Default value = 1)
1496 """
1497 return self.api(
1498 self.papi.nat44_add_del_identity_mapping,
1499 {'is_add': is_add,
1500 'addr_only': addr_only,
1501 'ip_address': ip,
1502 'port': port,
1503 'sw_if_index': sw_if_index,
1504 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001505 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001506 'protocol': protocol})
1507
Matus Fabian2ba92e32017-08-21 07:05:03 -07001508 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001509 self,
1510 first_ip_address,
1511 last_ip_address,
1512 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001513 vrf_id=0xFFFFFFFF,
1514 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001515 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001516
1517 :param first_ip_address: First IP address
1518 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001519 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001520 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001521 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001522 """
1523 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001524 self.papi.nat44_add_del_address_range,
1525 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001526 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001527 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001528 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001529 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001530
Matus Fabian2ba92e32017-08-21 07:05:03 -07001531 def nat44_address_dump(self):
1532 """Dump NAT44 addresses
1533 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001534 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001535 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001536
Matus Fabian2ba92e32017-08-21 07:05:03 -07001537 def nat44_interface_dump(self):
1538 """Dump interfaces with NAT44 feature
1539 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001540 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001542
Matus Fabian2ba92e32017-08-21 07:05:03 -07001543 def nat44_interface_output_feature_dump(self):
1544 """Dump interfaces with NAT44 output feature
1545 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001546 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001547 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001548
Matus Fabian2ba92e32017-08-21 07:05:03 -07001549 def nat44_static_mapping_dump(self):
1550 """Dump NAT44 static mappings
1551 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001552 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001554
Matus Fabianab7a8052017-11-28 04:29:41 -08001555 def nat44_identity_mapping_dump(self):
1556 """Dump NAT44 identity mappings
1557 :return: Dictionary of NAT44 identity mappings
1558 """
1559 return self.api(self.papi.nat44_identity_mapping_dump, {})
1560
Matus Fabian2ba92e32017-08-21 07:05:03 -07001561 def nat_show_config(self):
1562 """Show NAT plugin config
1563 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001564 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001566
Matus Fabian2ba92e32017-08-21 07:05:03 -07001567 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001568 self,
1569 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001570 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001571 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001573
1574 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001575 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001576 :param is_add: 1 if add, 0 if delete (Default value = 1)
1577 """
Matus Fabianb932d262017-12-18 05:38:24 -08001578 return self.api(
1579 self.papi.nat44_add_del_interface_addr,
1580 {'is_add': is_add,
1581 'sw_if_index': sw_if_index,
1582 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001583
Matus Fabian2ba92e32017-08-21 07:05:03 -07001584 def nat44_interface_addr_dump(self):
1585 """Dump NAT44 addresses interfaces
1586 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001587 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001588 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001589
Matus Fabian2ba92e32017-08-21 07:05:03 -07001590 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001591 self,
1592 domain_id=1,
1593 src_port=4739,
1594 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001595 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001596
1597 :param domain_id: Observation domain ID (Default value = 1)
1598 :param src_port: Source port number (Default value = 4739)
1599 :param enable: 1 if enable, 0 if disable (Default value = 1)
1600 """
1601 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001602 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001603 {'domain_id': domain_id,
1604 'src_port': src_port,
1605 'enable': enable})
1606
Matus Fabian2ba92e32017-08-21 07:05:03 -07001607 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001608 self,
1609 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001610 vrf_id):
1611 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001612
1613 :param ip_address: ip adress of the user to be dumped
1614 :param cpu_index: cpu_index on which the user is
1615 :param vrf_id: VRF ID
1616 :return: Dictionary of S-NAT sessions
1617 """
1618 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001619 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001620 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001621 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001622
Matus Fabian2ba92e32017-08-21 07:05:03 -07001623 def nat44_user_dump(self):
1624 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001625
Matus Fabian2ba92e32017-08-21 07:05:03 -07001626 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001627 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001628 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001629
Matus Fabian704018c2017-09-04 02:17:18 -07001630 def nat44_add_del_lb_static_mapping(
1631 self,
1632 external_addr,
1633 external_port,
1634 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001635 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001636 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001637 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001638 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001639 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001640 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001641 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001642 is_add=1):
1643 """Add/delete NAT44 load balancing static mapping
1644
Matus Fabianb932d262017-12-18 05:38:24 -08001645 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001646 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001647 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001648 :param is_add - 1 if add, 0 if delete
1649 """
1650 return self.api(
1651 self.papi.nat44_add_del_lb_static_mapping,
1652 {'is_add': is_add,
1653 'external_addr': external_addr,
1654 'external_port': external_port,
1655 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001656 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001657 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001658 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001659 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001660 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001661 'local_num': local_num,
1662 'locals': locals})
1663
1664 def nat44_lb_static_mapping_dump(self):
1665 """Dump NAT44 load balancing static mappings
1666
1667 :return: Dictionary of NAT44 load balancing static mapping
1668 """
1669 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1670
Matus Fabian5ba86f72017-10-26 03:37:38 -07001671 def nat44_del_session(
1672 self,
1673 addr,
1674 port,
1675 protocol,
1676 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001677 is_in=1,
1678 ext_host_address=None,
1679 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001680 """Delete NAT44 session
1681
1682 :param addr: IPv4 address
1683 :param por: port number
1684 :param protocol: IP protocol number
1685 :param vrf_id: VRF ID
1686 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001687 :param ext_host_address: external host IPv4 address
1688 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001689 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001690 if ext_host_address is None:
1691 return self.api(
1692 self.papi.nat44_del_session,
1693 {'address': addr,
1694 'port': port,
1695 'protocol': protocol,
1696 'vrf_id': vrf_id,
1697 'is_in': is_in})
1698 else:
1699 return self.api(
1700 self.papi.nat44_del_session,
1701 {'address': addr,
1702 'port': port,
1703 'protocol': protocol,
1704 'vrf_id': vrf_id,
1705 'is_in': is_in,
1706 'ext_host_valid': 1,
1707 'ext_host_address': ext_host_address,
1708 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001709
Juraj Sloboda7b929792017-11-23 13:20:48 +01001710 def nat44_forwarding_enable_disable(
1711 self,
1712 enable):
1713 """Enable/disable forwarding for NAT44
1714
1715 :param enable: 1 for enable, 0 for disable
1716 """
1717 return self.api(
1718 self.papi.nat44_forwarding_enable_disable,
1719 {'enable': enable})
1720
Matus Fabianefcd1e92017-08-15 06:59:19 -07001721 def nat_set_reass(
1722 self,
1723 timeout=2,
1724 max_reass=1024,
1725 max_frag=5,
1726 drop_frag=0,
1727 is_ip6=0):
1728 """Set NAT virtual fragmentation reassembly
1729
1730 :param timeout: reassembly timeout (Default 2sec)
1731 :param max_reass: maximum concurrent reassemblies (Default 1024)
1732 :param max_frag: maximum fragmets per reassembly (Default 5)
1733 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1734 :param is_ip6: 1 if IPv6, 0 if IPv4
1735 """
1736 return self.api(
1737 self.papi.nat_set_reass,
1738 {'timeout': timeout,
1739 'max_reass': max_reass,
1740 'max_frag': max_frag,
1741 'drop_frag': drop_frag,
1742 'is_ip6': is_ip6})
1743
1744 def nat_get_reass(self):
1745 """Get NAT virtual fragmentation reassembly configuration
1746
1747 :return: NAT virtual fragmentation reassembly configuration
1748 """
1749 return self.api(self.papi.nat_get_reass, {})
1750
1751 def nat_reass_dump(self):
1752 """Dump NAT virtual fragmentation reassemblies
1753
1754 :return: Dictionary of NAT virtual fragmentation reassemblies
1755 """
1756 return self.api(self.papi.nat_reass_dump, {})
1757
Matus Fabian2ba92e32017-08-21 07:05:03 -07001758 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001759 self,
1760 in_addr,
1761 in_plen,
1762 out_addr,
1763 out_plen,
1764 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001765 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001766
1767 :param is_add - 1 if add, 0 if delete
1768 :param in_addr - inside IP address
1769 :param in_plen - inside IP address prefix length
1770 :param out_addr - outside IP address
1771 :param out_plen - outside IP address prefix length
1772 """
1773 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001774 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001775 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001776 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001777 'in_addr': in_addr,
1778 'in_plen': in_plen,
1779 'out_addr': out_addr,
1780 'out_plen': out_plen})
1781
Matus Fabian2ba92e32017-08-21 07:05:03 -07001782 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001783 self,
1784 in_addr):
1785 """Get outside address and port range from inside address
1786
1787 :param in_addr - inside IP address
1788 """
1789 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001790 self.papi.nat_det_forward,
1791 {'in_addr': in_addr,
1792 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001793
Matus Fabian2ba92e32017-08-21 07:05:03 -07001794 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001795 self,
1796 out_addr,
1797 out_port):
1798 """Get inside address from outside address and port
1799
1800 :param out_addr - outside IP address
1801 :param out_port - outside port
1802 """
1803 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001804 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001805 {'out_addr': out_addr,
1806 'out_port': out_port})
1807
Matus Fabian2ba92e32017-08-21 07:05:03 -07001808 def nat_det_map_dump(self):
1809 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001810
Matus Fabian2ba92e32017-08-21 07:05:03 -07001811 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001812 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001813 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001814
Matus Fabian878c6462018-08-23 00:33:35 -07001815 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001816 self,
1817 udp=300,
1818 tcp_established=7440,
1819 tcp_transitory=240,
1820 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001821 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001822
1823 :param udp - UDP timeout (Default value = 300)
1824 :param tcp_established - TCP established timeout (Default value = 7440)
1825 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1826 :param icmp - ICMP timeout (Default value = 60)
1827 """
1828 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001829 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001830 {'udp': udp,
1831 'tcp_established': tcp_established,
1832 'tcp_transitory': tcp_transitory,
1833 'icmp': icmp})
1834
Matus Fabian878c6462018-08-23 00:33:35 -07001835 def nat_get_timeouts(self):
1836 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001837
Matus Fabian878c6462018-08-23 00:33:35 -07001838 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001839 """
Matus Fabian878c6462018-08-23 00:33:35 -07001840 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001841
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001842 def nat_set_addr_and_port_alloc_alg(
1843 self,
1844 alg=0,
1845 psid_offset=0,
1846 psid_length=0,
1847 psid=0,
1848 start_port=0,
1849 end_port=0):
1850 """Set address and port assignment algorithm
1851
1852 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1853 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1854 :param psid_length: length of PSID (valid only for MAP-E alg)
1855 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1856 :param start_port: beginning of the port range
1857 :param end_port: end of the port range
1858 """
1859 return self.api(
1860 self.papi.nat_set_addr_and_port_alloc_alg,
1861 {'alg': alg,
1862 'psid_offset': psid_offset,
1863 'psid_length': psid_length,
1864 'psid': psid,
1865 'start_port': start_port,
1866 'end_port': end_port})
1867
1868 def nat_get_addr_and_port_alloc_alg(self):
1869 """Get address and port assignment algorithm"""
1870 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1871
Matus Fabianbb4e0222018-09-13 02:36:25 -07001872 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1873 """Set TCP MSS rewriting configuration
1874
1875 :param enable: disable(0)/enable(1) MSS rewriting feature
1876 :param mss_value: MSS value to be used for MSS rewriting
1877 """
1878 return self.api(
1879 self.papi.nat_set_mss_clamping,
1880 {'enable': enable, 'mss_value': mss_value})
1881
1882 def nat_get_mss_clamping(self):
1883 """Get TCP MSS rewriting configuration"""
1884 return self.api(self.papi.nat_get_mss_clamping, {})
1885
Matus Fabian2ba92e32017-08-21 07:05:03 -07001886 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001887 self,
1888 out_addr,
1889 out_port,
1890 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001891 ext_port):
1892 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001893
1894 :param out_addr - outside IP address
1895 :param out_port - outside port
1896 :param ext_addr - external host IP address
1897 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001898 """
1899 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001900 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001901 {'out_addr': out_addr,
1902 'out_port': out_port,
1903 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001904 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001905
Matus Fabian2ba92e32017-08-21 07:05:03 -07001906 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001907 self,
1908 in_addr,
1909 in_port,
1910 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001911 ext_port):
1912 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001913
1914 :param in_addr - inside IP address
1915 :param in_port - inside port
1916 :param ext_addr - external host IP address
1917 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001918 """
1919 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001920 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001921 {'in_addr': in_addr,
1922 'in_port': in_port,
1923 'ext_addr': ext_addr,
1924 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001925 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001926
Matus Fabian2ba92e32017-08-21 07:05:03 -07001927 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001928 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001929 user_addr):
1930 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001931
1932 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001933 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001934 """
1935 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001936 self.papi.nat_det_session_dump,
1937 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001938 'user_addr': user_addr})
1939
Matus Fabian06596c52017-06-06 04:53:28 -07001940 def nat64_add_del_pool_addr_range(
1941 self,
1942 start_addr,
1943 end_addr,
1944 vrf_id=0xFFFFFFFF,
1945 is_add=1):
1946 """Add/del address range to NAT64 pool
1947
1948 :param start_addr: First IP address
1949 :param end_addr: Last IP address
1950 :param vrf_id: VRF id for the address range
1951 :param is_add: 1 if add, 0 if delete (Default value = 1)
1952 """
1953 return self.api(
1954 self.papi.nat64_add_del_pool_addr_range,
1955 {'start_addr': start_addr,
1956 'end_addr': end_addr,
1957 'vrf_id': vrf_id,
1958 'is_add': is_add})
1959
1960 def nat64_pool_addr_dump(self):
1961 """Dump NAT64 pool addresses
1962 :return: Dictionary of NAT64 pool addresses
1963 """
1964 return self.api(self.papi.nat64_pool_addr_dump, {})
1965
1966 def nat64_add_del_interface(
1967 self,
1968 sw_if_index,
1969 is_inside=1,
1970 is_add=1):
1971 """Enable/disable NAT64 feature on the interface
1972 :param sw_if_index: Index of the interface
1973 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1974 :param is_add: 1 if add, 0 if delete (Default value = 1)
1975 """
1976 return self.api(
1977 self.papi.nat64_add_del_interface,
1978 {'sw_if_index': sw_if_index,
1979 'is_inside': is_inside,
1980 'is_add': is_add})
1981
1982 def nat64_interface_dump(self):
1983 """Dump interfaces with NAT64 feature
1984 :return: Dictionary of interfaces with NAT64 feature
1985 """
1986 return self.api(self.papi.nat64_interface_dump, {})
1987
1988 def nat64_add_del_static_bib(
1989 self,
1990 in_ip,
1991 out_ip,
1992 in_port,
1993 out_port,
1994 protocol,
1995 vrf_id=0,
1996 is_add=1):
1997 """Add/delete S-NAT static BIB entry
1998
1999 :param in_ip: Inside IPv6 address
2000 :param out_ip: Outside IPv4 address
2001 :param in_port: Inside port number
2002 :param out_port: Outside port number
2003 :param protocol: IP protocol
2004 :param vrf_id: VRF ID (Default value = 0)
2005 :param is_add: 1 if add, 0 if delete (Default value = 1)
2006 """
2007 return self.api(
2008 self.papi.nat64_add_del_static_bib,
2009 {'i_addr': in_ip,
2010 'o_addr': out_ip,
2011 'i_port': in_port,
2012 'o_port': out_port,
2013 'vrf_id': vrf_id,
2014 'proto': protocol,
2015 'is_add': is_add})
2016
Matus Fabianab9a59c2017-08-16 05:37:36 -07002017 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002018 """Dump NAT64 BIB
2019
Matus Fabianab9a59c2017-08-16 05:37:36 -07002020 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002021 :returns: Dictionary of NAT64 BIB entries
2022 """
2023 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2024
2025 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2026 tcp_incoming_syn=6):
2027 """Set values of timeouts for NAT64 (in seconds)
2028
Matus Fabian428dc912017-06-21 06:15:18 -07002029 :param udpi: UDP timeout (Default value = 300)
2030 :param icmp: ICMP timeout (Default value = 60)
2031 :param tcp_trans: TCP transitory timeout (Default value = 240)
2032 :param tcp_est: TCP established timeout (Default value = 7440)
2033 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002034 """
2035 return self.api(
2036 self.papi.nat64_set_timeouts,
2037 {'udp': udp,
2038 'icmp': icmp,
2039 'tcp_trans': tcp_trans,
2040 'tcp_est': tcp_est,
2041 'tcp_incoming_syn': tcp_incoming_syn})
2042
2043 def nat64_get_timeouts(self):
2044 """Get values of timeouts for NAT64
2045
2046 :return: Timeouts for NAT64 (in seconds)
2047 """
2048 return self.api(self.papi.nat64_get_timeouts, {})
2049
Matus Fabianab9a59c2017-08-16 05:37:36 -07002050 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002051 """Dump NAT64 session table
2052
Matus Fabianab9a59c2017-08-16 05:37:36 -07002053 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002054 :returns: Dictionary of NAT64 sesstion table entries
2055 """
2056 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2057
Matus Fabian428dc912017-06-21 06:15:18 -07002058 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2059 """Add/del NAT64 prefix
2060
2061 :param prefix: NAT64 prefix
2062 :param plen: NAT64 prefix length
2063 :param vrf_id: VRF id of tenant (Default 0)
2064 :param is_add: 1 if add, 0 if delete (Default value = 1)
2065 """
2066 return self.api(
2067 self.papi.nat64_add_del_prefix,
2068 {'prefix': prefix,
2069 'prefix_len': plen,
2070 'vrf_id': vrf_id,
2071 'is_add': is_add})
2072
2073 def nat64_prefix_dump(self):
2074 """Dump NAT64 prefix
2075
2076 :returns: Dictionary of NAT64 prefixes
2077 """
2078 return self.api(self.papi.nat64_prefix_dump, {})
2079
Matus Fabian0938dcf2017-11-08 01:59:38 -08002080 def nat64_add_interface_addr(
2081 self,
2082 sw_if_index,
2083 is_add=1):
2084 """Add/del NAT64 address from interface
2085
2086 :param sw_if_index: Software index of the interface
2087 :param is_add: 1 if add, 0 if delete (Default value = 1)
2088 """
2089 return self.api(self.papi.nat64_add_del_interface_addr,
2090 {'is_add': is_add, 'sw_if_index': sw_if_index})
2091
Matus Fabian8ebe6252017-11-06 05:04:53 -08002092 def dslite_set_aftr_addr(self, ip6, ip4):
2093 """Set DS-Lite AFTR addresses
2094
2095 :param ip4: IPv4 address
2096 :param ip6: IPv6 address
2097 """
2098 return self.api(
2099 self.papi.dslite_set_aftr_addr,
2100 {'ip4_addr': ip4,
2101 'ip6_addr': ip6})
2102
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002103 def dslite_set_b4_addr(self, ip6, ip4):
2104 """Set DS-Lite B4 IPv6 address
2105
2106 :param ip4: IPv4 address
2107 :param ip6: IPv6 address
2108 """
2109 return self.api(
2110 self.papi.dslite_set_b4_addr,
2111 {'ip4_addr': ip4,
2112 'ip6_addr': ip6})
2113
Matus Fabian8ebe6252017-11-06 05:04:53 -08002114 def dslite_add_del_pool_addr_range(
2115 self,
2116 start_addr,
2117 end_addr,
2118 is_add=1):
2119 """Add/del address range to DS-Lite pool
2120
2121 :param start_addr: First IP address
2122 :param end_addr: Last IP address
2123 :param is_add: 1 if add, 0 if delete (Default value = 1)
2124 """
2125 return self.api(
2126 self.papi.dslite_add_del_pool_addr_range,
2127 {'start_addr': start_addr,
2128 'end_addr': end_addr,
2129 'is_add': is_add})
2130
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002131 def nat66_add_del_interface(
2132 self,
2133 sw_if_index,
2134 is_inside=1,
2135 is_add=1):
2136 """Enable/disable NAT66 feature on the interface
2137 :param sw_if_index: Index of the interface
2138 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2139 :param is_add: 1 if add, 0 if delete (Default value = 1)
2140 """
2141 return self.api(
2142 self.papi.nat66_add_del_interface,
2143 {'sw_if_index': sw_if_index,
2144 'is_inside': is_inside,
2145 'is_add': is_add})
2146
2147 def nat66_add_del_static_mapping(
2148 self,
2149 in_ip,
2150 out_ip,
2151 vrf_id=0,
2152 is_add=1):
2153 """Add/delete NAT66 static mapping
2154
2155 :param in_ip: Inside IPv6 address
2156 :param out_ip: Outside IPv6 address
2157 :param vrf_id: VRF ID (Default value = 0)
2158 :param is_add: 1 if add, 0 if delete (Default value = 1)
2159 """
2160 return self.api(
2161 self.papi.nat66_add_del_static_mapping,
2162 {'local_ip_address': in_ip,
2163 'external_ip_address': out_ip,
2164 'vrf_id': vrf_id,
2165 'is_add': is_add})
2166
2167 def nat66_interface_dump(self):
2168 """Dump interfaces with NAT66 feature
2169 :return: Dictionary of interfaces with NAT66 feature
2170 """
2171 return self.api(self.papi.nat66_interface_dump, {})
2172
2173 def nat66_static_mapping_dump(self):
2174 """Dump NAT66 static mappings
2175 :return: Dictionary of NAT66 static mappings
2176 """
2177 return self.api(self.papi.nat66_static_mapping_dump, {})
2178
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002179 def control_ping(self):
2180 self.api(self.papi.control_ping)
2181
2182 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002183 detect_mult, local_addr, peer_addr, is_ipv6=0,
2184 bfd_key_id=None, conf_key_id=None):
2185 if bfd_key_id is None:
2186 return self.api(self.papi.bfd_udp_add,
2187 {
2188 'sw_if_index': sw_if_index,
2189 'desired_min_tx': desired_min_tx,
2190 'required_min_rx': required_min_rx,
2191 'local_addr': local_addr,
2192 'peer_addr': peer_addr,
2193 'is_ipv6': is_ipv6,
2194 'detect_mult': detect_mult,
2195 })
2196 else:
2197 return self.api(self.papi.bfd_udp_add,
2198 {
2199 'sw_if_index': sw_if_index,
2200 'desired_min_tx': desired_min_tx,
2201 'required_min_rx': required_min_rx,
2202 'local_addr': local_addr,
2203 'peer_addr': peer_addr,
2204 'is_ipv6': is_ipv6,
2205 'detect_mult': detect_mult,
2206 'is_authenticated': 1,
2207 'bfd_key_id': bfd_key_id,
2208 'conf_key_id': conf_key_id,
2209 })
2210
Klement Sekeraa57a9702017-02-02 06:58:07 +01002211 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2212 detect_mult, local_addr, peer_addr, is_ipv6=0):
2213 return self.api(self.papi.bfd_udp_mod,
2214 {
2215 'sw_if_index': sw_if_index,
2216 'desired_min_tx': desired_min_tx,
2217 'required_min_rx': required_min_rx,
2218 'local_addr': local_addr,
2219 'peer_addr': peer_addr,
2220 'is_ipv6': is_ipv6,
2221 'detect_mult': detect_mult,
2222 })
2223
Klement Sekerab17dd962017-01-09 07:43:48 +01002224 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2225 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2226 is_delayed=False):
2227 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002228 {
2229 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002230 'local_addr': local_addr,
2231 'peer_addr': peer_addr,
2232 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002233 'is_delayed': 1 if is_delayed else 0,
2234 'bfd_key_id': bfd_key_id,
2235 'conf_key_id': conf_key_id,
2236 })
2237
2238 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2239 is_ipv6=0, is_delayed=False):
2240 return self.api(self.papi.bfd_udp_auth_deactivate,
2241 {
2242 'sw_if_index': sw_if_index,
2243 'local_addr': local_addr,
2244 'peer_addr': peer_addr,
2245 'is_ipv6': is_ipv6,
2246 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002247 })
2248
2249 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2250 return self.api(self.papi.bfd_udp_del,
2251 {
2252 'sw_if_index': sw_if_index,
2253 'local_addr': local_addr,
2254 'peer_addr': peer_addr,
2255 'is_ipv6': is_ipv6,
2256 })
2257
2258 def bfd_udp_session_dump(self):
2259 return self.api(self.papi.bfd_udp_session_dump, {})
2260
Klement Sekerab17dd962017-01-09 07:43:48 +01002261 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2262 peer_addr, is_ipv6=0):
2263 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002264 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002265 'sw_if_index': sw_if_index,
2266 'local_addr': local_addr,
2267 'peer_addr': peer_addr,
2268 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002269 })
2270
2271 def want_bfd_events(self, enable_disable=1):
2272 return self.api(self.papi.want_bfd_events, {
2273 'enable_disable': enable_disable,
2274 'pid': os.getpid(),
2275 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002276
Klement Sekerab17dd962017-01-09 07:43:48 +01002277 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2278 return self.api(self.papi.bfd_auth_set_key, {
2279 'conf_key_id': conf_key_id,
2280 'auth_type': auth_type,
2281 'key': key,
2282 'key_len': len(key),
2283 })
2284
2285 def bfd_auth_del_key(self, conf_key_id):
2286 return self.api(self.papi.bfd_auth_del_key, {
2287 'conf_key_id': conf_key_id,
2288 })
2289
2290 def bfd_auth_keys_dump(self):
2291 return self.api(self.papi.bfd_auth_keys_dump, {})
2292
Klement Sekera239790f2017-02-16 10:53:53 +01002293 def bfd_udp_set_echo_source(self, sw_if_index):
2294 return self.api(self.papi.bfd_udp_set_echo_source,
2295 {'sw_if_index': sw_if_index})
2296
Klement Sekera73884482017-02-23 09:26:30 +01002297 def bfd_udp_del_echo_source(self):
2298 return self.api(self.papi.bfd_udp_del_echo_source, {})
2299
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002300 def bfd_udp_get_echo_source(self):
2301 return self.api(self.papi.bfd_udp_get_echo_source, {})
2302
Steve Shin7957d6e2016-12-19 09:24:50 -08002303 def classify_add_del_table(
2304 self,
2305 is_add,
2306 mask,
2307 match_n_vectors=1,
2308 table_index=0xFFFFFFFF,
2309 nbuckets=2,
2310 memory_size=2097152,
2311 skip_n_vectors=0,
2312 next_table_index=0xFFFFFFFF,
2313 miss_next_index=0xFFFFFFFF,
2314 current_data_flag=0,
2315 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002316 """
2317 :param is_add:
2318 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002319 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002320 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002321 :param nbuckets: (Default value = 2)
2322 :param memory_size: (Default value = 2097152)
2323 :param skip_n_vectors: (Default value = 0)
2324 :param next_table_index: (Default value = 0xFFFFFFFF)
2325 :param miss_next_index: (Default value = 0xFFFFFFFF)
2326 :param current_data_flag: (Default value = 0)
2327 :param current_data_offset: (Default value = 0)
2328 """
2329
Juraj Sloboda75282452018-06-12 14:20:49 +02002330 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2331 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002332 return self.api(
2333 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002334 {'is_add': is_add,
2335 'table_index': table_index,
2336 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002337 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002338 'skip_n_vectors': skip_n_vectors,
2339 'match_n_vectors': match_n_vectors,
2340 'next_table_index': next_table_index,
2341 'miss_next_index': miss_next_index,
2342 'current_data_flag': current_data_flag,
2343 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002344 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002345 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002346
2347 def classify_add_del_session(
2348 self,
2349 is_add,
2350 table_index,
2351 match,
2352 opaque_index=0xFFFFFFFF,
2353 hit_next_index=0xFFFFFFFF,
2354 advance=0,
2355 action=0,
2356 metadata=0):
2357 """
2358 :param is_add:
2359 :param table_index:
2360 :param match:
2361 :param opaque_index: (Default value = 0xFFFFFFFF)
2362 :param hit_next_index: (Default value = 0xFFFFFFFF)
2363 :param advance: (Default value = 0)
2364 :param action: (Default value = 0)
2365 :param metadata: (Default value = 0)
2366 """
2367
Juraj Sloboda75282452018-06-12 14:20:49 +02002368 match_len = ((len(match) - 1) / 16 + 1) * 16
2369 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002370 return self.api(
2371 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002372 {'is_add': is_add,
2373 'table_index': table_index,
2374 'hit_next_index': hit_next_index,
2375 'opaque_index': opaque_index,
2376 'advance': advance,
2377 'action': action,
2378 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002379 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002380 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002381
2382 def input_acl_set_interface(
2383 self,
2384 is_add,
2385 sw_if_index,
2386 ip4_table_index=0xFFFFFFFF,
2387 ip6_table_index=0xFFFFFFFF,
2388 l2_table_index=0xFFFFFFFF):
2389 """
2390 :param is_add:
2391 :param sw_if_index:
2392 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2393 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2394 :param l2_table_index: (Default value = 0xFFFFFFFF)
2395 """
2396
2397 return self.api(
2398 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002399 {'sw_if_index': sw_if_index,
2400 'ip4_table_index': ip4_table_index,
2401 'ip6_table_index': ip6_table_index,
2402 'l2_table_index': l2_table_index,
2403 'is_add': is_add})
2404
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002405 def output_acl_set_interface(
2406 self,
2407 is_add,
2408 sw_if_index,
2409 ip4_table_index=0xFFFFFFFF,
2410 ip6_table_index=0xFFFFFFFF,
2411 l2_table_index=0xFFFFFFFF):
2412 """
2413 :param is_add:
2414 :param sw_if_index:
2415 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2416 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2417 :param l2_table_index: (Default value = 0xFFFFFFFF)
2418 """
2419
2420 return self.api(
2421 self.papi.output_acl_set_interface,
2422 {'sw_if_index': sw_if_index,
2423 'ip4_table_index': ip4_table_index,
2424 'ip6_table_index': ip6_table_index,
2425 'l2_table_index': l2_table_index,
2426 'is_add': is_add})
2427
Klement Sekera77fabdb2017-01-02 07:46:14 +01002428 def set_ipfix_exporter(
2429 self,
2430 collector_address,
2431 src_address,
2432 path_mtu,
2433 template_interval,
2434 vrf_id=0,
2435 collector_port=4739,
2436 udp_checksum=0):
2437 return self.api(
2438 self.papi.set_ipfix_exporter,
2439 {
2440 'collector_address': collector_address,
2441 'collector_port': collector_port,
2442 'src_address': src_address,
2443 'vrf_id': vrf_id,
2444 'path_mtu': path_mtu,
2445 'template_interval': template_interval,
2446 'udp_checksum': udp_checksum,
2447 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002448
2449 def dhcp_proxy_config(self,
2450 dhcp_server,
2451 dhcp_src_address,
2452 rx_table_id=0,
2453 server_table_id=0,
2454 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002455 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002456 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002457 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002458 {
2459 'rx_vrf_id': rx_table_id,
2460 'server_vrf_id': server_table_id,
2461 'is_ipv6': is_ipv6,
2462 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002463 'dhcp_server': dhcp_server,
2464 'dhcp_src_address': dhcp_src_address,
2465 })
2466
2467 def dhcp_proxy_set_vss(self,
2468 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002469 vss_type=255,
2470 vpn_ascii_id="",
2471 oui=0,
2472 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002473 is_add=1,
2474 is_ip6=0):
2475 return self.api(
2476 self.papi.dhcp_proxy_set_vss,
2477 {
2478 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002479 'vss_type': vss_type,
2480 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002481 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002482 'vpn_index': vpn_index,
2483 'is_add': is_add,
2484 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002485 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002486
Neale Rannsdaff1782018-05-16 04:12:18 -07002487 def dhcp_client_dump(self):
2488 return self.api(self.papi.dhcp_client_dump, {})
2489
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002490 def dhcp_client(self,
2491 sw_if_index,
2492 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002493 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002494 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002495 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002496 want_dhcp_events=0):
2497 return self.api(
2498 self.papi.dhcp_client_config,
2499 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002500 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002501 'client': {
2502 'sw_if_index': sw_if_index,
2503 'hostname': hostname,
2504 'id': client_id,
2505 'want_dhcp_event': want_dhcp_events,
2506 'set_broadcast_flag': set_broadcast_flag,
2507 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002508 })
2509
Neale Ranns32e1c012016-11-22 17:07:28 +00002510 def ip_mroute_add_del(self,
2511 src_address,
2512 grp_address,
2513 grp_address_length,
2514 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002515 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002516 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002517 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002518 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002519 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002520 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002521 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002522 is_add=1,
2523 is_ipv6=0,
2524 is_local=0):
2525 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002526 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002527 """
2528 return self.api(
2529 self.papi.ip_mroute_add_del,
2530 {'next_hop_sw_if_index': next_hop_sw_if_index,
2531 'entry_flags': e_flags,
2532 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002533 'table_id': table_id,
2534 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002535 'is_add': is_add,
2536 'is_ipv6': is_ipv6,
2537 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002538 'bier_imp': bier_imp,
2539 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002540 'grp_address_length': grp_address_length,
2541 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002542 'src_address': src_address,
2543 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002544
2545 def mfib_signal_dump(self):
2546 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002547
2548 def ip_mfib_dump(self):
2549 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002550
Neale Rannsd792d9c2017-10-21 10:53:20 -07002551 def ip6_mfib_dump(self):
2552 return self.api(self.papi.ip6_mfib_dump, {})
2553
Filip Tehlar770e89e2017-01-31 10:39:16 +01002554 def lisp_enable_disable(self, is_enabled):
2555 return self.api(
2556 self.papi.lisp_enable_disable,
2557 {
2558 'is_en': is_enabled,
2559 })
2560
2561 def lisp_locator_set(self,
2562 ls_name,
2563 is_add=1):
2564 return self.api(
2565 self.papi.lisp_add_del_locator_set,
2566 {
2567 'is_add': is_add,
2568 'locator_set_name': ls_name
2569 })
2570
2571 def lisp_locator_set_dump(self):
2572 return self.api(self.papi.lisp_locator_set_dump, {})
2573
2574 def lisp_locator(self,
2575 ls_name,
2576 sw_if_index,
2577 priority=1,
2578 weight=1,
2579 is_add=1):
2580 return self.api(
2581 self.papi.lisp_add_del_locator,
2582 {
2583 'is_add': is_add,
2584 'locator_set_name': ls_name,
2585 'sw_if_index': sw_if_index,
2586 'priority': priority,
2587 'weight': weight
2588 })
2589
2590 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2591 return self.api(
2592 self.papi.lisp_locator_dump,
2593 {
2594 'is_index_set': is_index_set,
2595 'ls_name': ls_name,
2596 'ls_index': ls_index,
2597 })
2598
2599 def lisp_local_mapping(self,
2600 ls_name,
2601 eid_type,
2602 eid,
2603 prefix_len,
2604 vni=0,
2605 key_id=0,
2606 key="",
2607 is_add=1):
2608 return self.api(
2609 self.papi.lisp_add_del_local_eid,
2610 {
2611 'locator_set_name': ls_name,
2612 'is_add': is_add,
2613 'eid_type': eid_type,
2614 'eid': eid,
2615 'prefix_len': prefix_len,
2616 'vni': vni,
2617 'key_id': key_id,
2618 'key': key
2619 })
2620
2621 def lisp_eid_table_dump(self,
2622 eid_set=0,
2623 prefix_length=0,
2624 vni=0,
2625 eid_type=0,
2626 eid=None,
2627 filter_opt=0):
2628 return self.api(
2629 self.papi.lisp_eid_table_dump,
2630 {
2631 'eid_set': eid_set,
2632 'prefix_length': prefix_length,
2633 'vni': vni,
2634 'eid_type': eid_type,
2635 'eid': eid,
2636 'filter': filter_opt,
2637 })
2638
2639 def lisp_remote_mapping(self,
2640 eid_type,
2641 eid,
2642 eid_prefix_len=0,
2643 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002644 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002645 rlocs_num=0,
2646 is_src_dst=0,
2647 is_add=1):
2648 return self.api(
2649 self.papi.lisp_add_del_remote_mapping,
2650 {
2651 'is_add': is_add,
2652 'eid_type': eid_type,
2653 'eid': eid,
2654 'eid_len': eid_prefix_len,
2655 'rloc_num': rlocs_num,
2656 'rlocs': rlocs,
2657 'vni': vni,
2658 'is_src_dst': is_src_dst,
2659 })
2660
2661 def lisp_adjacency(self,
2662 leid,
2663 reid,
2664 leid_len,
2665 reid_len,
2666 eid_type,
2667 is_add=1,
2668 vni=0):
2669 return self.api(
2670 self.papi.lisp_add_del_adjacency,
2671 {
2672 'is_add': is_add,
2673 'vni': vni,
2674 'eid_type': eid_type,
2675 'leid': leid,
2676 'reid': reid,
2677 'leid_len': leid_len,
2678 'reid_len': reid_len,
2679 })
2680
2681 def lisp_adjacencies_get(self, vni=0):
2682 return self.api(
2683 self.papi.lisp_adjacencies_get,
2684 {
2685 'vni': vni
2686 })
Neale Ranns80823802017-02-20 18:23:41 -08002687
2688 def map_add_domain(self,
2689 ip6_prefix,
2690 ip6_prefix_len,
2691 ip6_src,
2692 ip6_src_prefix_len,
2693 ip4_prefix,
2694 ip4_prefix_len,
2695 ea_bits_len=0,
2696 psid_offset=0,
2697 psid_length=0,
2698 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002699 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002700 mtu=1280):
2701 return self.api(
2702 self.papi.map_add_domain,
2703 {
2704 'ip6_prefix': ip6_prefix,
2705 'ip6_prefix_len': ip6_prefix_len,
2706 'ip4_prefix': ip4_prefix,
2707 'ip4_prefix_len': ip4_prefix_len,
2708 'ip6_src': ip6_src,
2709 'ip6_src_prefix_len': ip6_src_prefix_len,
2710 'ea_bits_len': ea_bits_len,
2711 'psid_offset': psid_offset,
2712 'psid_length': psid_length,
2713 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002714 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002715 'mtu': mtu
2716 })
Hongjun Nief486b12017-04-12 19:21:16 +08002717
2718 def gtpu_add_del_tunnel(
2719 self,
2720 src_addr,
2721 dst_addr,
2722 is_add=1,
2723 is_ipv6=0,
2724 mcast_sw_if_index=0xFFFFFFFF,
2725 encap_vrf_id=0,
2726 decap_next_index=0xFFFFFFFF,
2727 teid=0):
2728 """
2729
2730 :param is_add: (Default value = 1)
2731 :param is_ipv6: (Default value = 0)
2732 :param src_addr:
2733 :param dst_addr:
2734 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2735 :param encap_vrf_id: (Default value = 0)
2736 :param decap_next_index: (Default value = 0xFFFFFFFF)
2737 :param teid: (Default value = 0)
2738
2739 """
2740 return self.api(self.papi.gtpu_add_del_tunnel,
2741 {'is_add': is_add,
2742 'is_ipv6': is_ipv6,
2743 'src_address': src_addr,
2744 'dst_address': dst_addr,
2745 'mcast_sw_if_index': mcast_sw_if_index,
2746 'encap_vrf_id': encap_vrf_id,
2747 'decap_next_index': decap_next_index,
2748 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002749
2750 def vxlan_gpe_add_del_tunnel(
2751 self,
2752 src_addr,
2753 dst_addr,
2754 mcast_sw_if_index=0xFFFFFFFF,
2755 is_add=1,
2756 is_ipv6=0,
2757 encap_vrf_id=0,
2758 decap_vrf_id=0,
2759 protocol=3,
2760 vni=0):
2761 """
2762
2763 :param local:
2764 :param remote:
2765 :param is_add: (Default value = 1)
2766 :param is_ipv6: (Default value = 0)
2767 :param encap_vrf_id: (Default value = 0)
2768 :param decap_vrf_id: (Default value = 0)
2769 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2770 :param protocol: (Default value = 3)
2771 :param vni: (Default value = 0)
2772
2773 """
2774 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2775 {'is_add': is_add,
2776 'is_ipv6': is_ipv6,
2777 'local': src_addr,
2778 'remote': dst_addr,
2779 'mcast_sw_if_index': mcast_sw_if_index,
2780 'encap_vrf_id': encap_vrf_id,
2781 'decap_vrf_id': decap_vrf_id,
2782 'protocol': protocol,
2783 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002784
Neale Ranns79a05f52018-09-11 07:39:43 -07002785 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002786 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002787 src,
2788 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002789 mcast_sw_if_index=0xFFFFFFFF,
2790 is_add=1,
2791 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002792 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002793 vni=0,
2794 instance=0xFFFFFFFF):
2795 """
2796
2797 :param dst_addr:
2798 :param src_addr:
2799 :param is_add: (Default value = 1)
2800 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002801 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002802 :param decap_next_index: (Default value = 0xFFFFFFFF)
2803 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2804 :param vni: (Default value = 0)
2805 :param instance: (Default value = 0xFFFFFFFF)
2806
2807 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002808 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002809 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002810 'tunnel': {
2811 'src': src,
2812 'dst': dst,
2813 'mcast_sw_if_index': mcast_sw_if_index,
2814 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002815 'vni': vni,
2816 'instance': instance}})
2817
2818 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2819 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2820 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002821
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002822 def pppoe_add_del_session(
2823 self,
2824 client_ip,
2825 client_mac,
2826 session_id=0,
2827 is_add=1,
2828 is_ipv6=0,
2829 decap_vrf_id=0):
2830 """
2831
2832 :param is_add: (Default value = 1)
2833 :param is_ipv6: (Default value = 0)
2834 :param client_ip:
2835 :param session_id: (Default value = 0)
2836 :param client_mac:
2837 :param decap_vrf_id: (Default value = 0)
2838
2839 """
2840 return self.api(self.papi.pppoe_add_del_session,
2841 {'is_add': is_add,
2842 'is_ipv6': is_ipv6,
2843 'session_id': session_id,
2844 'client_ip': client_ip,
2845 'decap_vrf_id': decap_vrf_id,
2846 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002847
Neale Ranns7c922dc2018-08-30 06:12:27 -07002848 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2849 return self.api(self.papi.sr_mpls_policy_add,
2850 {'bsid': bsid,
2851 'weight': weight,
2852 'type': type,
2853 'n_segments': len(segments),
2854 'segments': segments})
2855
2856 def sr_mpls_policy_del(self, bsid):
2857 return self.api(self.papi.sr_mpls_policy_del,
2858 {'bsid': bsid})
2859
Kris Michielsen91074432017-06-22 13:00:20 +02002860 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002861 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002862 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002863 nh_addr4,
2864 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002865 is_del=0,
2866 end_psp=0,
2867 sw_if_index=0xFFFFFFFF,
2868 vlan_index=0,
2869 fib_table=0,
2870 ):
2871 """ Add/del IPv6 SR local-SID.
2872
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002873 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002874 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2875 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002876 :param nh_addr4:
2877 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002878 :param is_del: (Default value = 0)
2879 :param end_psp: (Default value = 0)
2880 :param sw_if_index: (Default value = 0xFFFFFFFF)
2881 :param vlan_index: (Default value = 0)
2882 :param fib_table: (Default value = 0)
2883 """
2884 return self.api(
2885 self.papi.sr_localsid_add_del,
2886 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002887 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002888 'end_psp': end_psp,
2889 'behavior': behavior,
2890 'sw_if_index': sw_if_index,
2891 'vlan_index': vlan_index,
2892 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002893 'nh_addr4': nh_addr4,
2894 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002895 }
2896 )
2897
2898 def sr_policy_add(
2899 self,
2900 bsid_addr,
2901 weight=1,
2902 is_encap=1,
2903 type=0,
2904 fib_table=0,
2905 n_segments=0,
2906 segments=[]):
2907 """
2908 :param bsid_addr: bindingSID of the SR Policy
2909 :param weight: weight of the sid list. optional. (default: 1)
2910 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2911 (default: Encap)
2912 :param type: type/behavior of the SR policy. (default or spray) \
2913 (default: default)
2914 :param fib_table: VRF where to install the FIB entry for the BSID \
2915 (default: 0)
2916 :param n_segments: number of segments \
2917 (default: 0)
2918 :param segments: a vector of IPv6 address composing the segment list \
2919 (default: [])
2920 """
2921 return self.api(
2922 self.papi.sr_policy_add,
2923 {'bsid_addr': bsid_addr,
2924 'weight': weight,
2925 'is_encap': is_encap,
2926 'type': type,
2927 'fib_table': fib_table,
2928 'n_segments': n_segments,
2929 'segments': segments
2930 }
2931 )
2932
2933 def sr_policy_del(
2934 self,
2935 bsid_addr,
2936 sr_policy_index=0):
2937 """
2938 :param bsid: bindingSID of the SR Policy
2939 :param sr_policy_index: index of the sr policy (default: 0)
2940 """
2941 return self.api(
2942 self.papi.sr_policy_del,
2943 {'bsid_addr': bsid_addr,
2944 'sr_policy_index': sr_policy_index
2945 })
2946
2947 def sr_steering_add_del(
2948 self,
2949 is_del,
2950 bsid_addr,
2951 sr_policy_index,
2952 table_id,
2953 prefix_addr,
2954 mask_width,
2955 sw_if_index,
2956 traffic_type):
2957 """
2958 Steer traffic L2 and L3 traffic through a given SR policy
2959
2960 :param is_del: delete or add
2961 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2962 :param sr_policy: is the index of the SR Policy (alt to bsid)
2963 :param table_id: is the VRF where to install the FIB entry for the BSID
2964 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2965 :param mask_width: is the mask for L3 traffic type
2966 :param sw_if_index: is the incoming interface for L2 traffic
2967 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2968 """
2969 return self.api(
2970 self.papi.sr_steering_add_del,
2971 {'is_del': is_del,
2972 'bsid_addr': bsid_addr,
2973 'sr_policy_index': sr_policy_index,
2974 'table_id': table_id,
2975 'prefix_addr': prefix_addr,
2976 'mask_width': mask_width,
2977 'sw_if_index': sw_if_index,
2978 'traffic_type': traffic_type
2979 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002980
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002981 def acl_add_replace(self, acl_index, r, tag='',
2982 expected_retval=0):
2983 """Add/replace an ACL
2984 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2985 :param acl_rule r: ACL rules array.
2986 :param str tag: symbolic tag (description) for this ACL.
2987 :param int count: number of rules.
2988 """
2989 return self.api(self.papi.acl_add_replace,
2990 {'acl_index': acl_index,
2991 'r': r,
2992 'count': len(r),
2993 'tag': tag},
2994 expected_retval=expected_retval)
2995
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002996 def acl_del(self, acl_index, expected_retval=0):
2997 """
2998
2999 :param acl_index:
3000 :return:
3001 """
3002 return self.api(self.papi.acl_del,
3003 {'acl_index': acl_index},
3004 expected_retval=expected_retval)
3005
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003006 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3007 expected_retval=0):
3008 return self.api(self.papi.acl_interface_set_acl_list,
3009 {'sw_if_index': sw_if_index,
3010 'count': len(acls),
3011 'n_input': n_input,
3012 'acls': acls},
3013 expected_retval=expected_retval)
3014
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003015 def acl_interface_set_etype_whitelist(self, sw_if_index,
3016 n_input, whitelist,
3017 expected_retval=0):
3018 return self.api(self.papi.acl_interface_set_etype_whitelist,
3019 {'sw_if_index': sw_if_index,
3020 'count': len(whitelist),
3021 'n_input': n_input,
3022 'whitelist': whitelist},
3023 expected_retval=expected_retval)
3024
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003025 def acl_interface_add_del(self,
3026 sw_if_index,
3027 acl_index,
3028 is_add=1):
3029 """ Add/Delete ACL to/from interface
3030
3031 :param sw_if_index:
3032 :param acl_index:
3033 :param is_add: (Default value = 1)
3034 """
3035
3036 return self.api(self.papi.acl_interface_add_del,
3037 {'is_add': is_add,
3038 'is_input': 1,
3039 'sw_if_index': sw_if_index,
3040 'acl_index': acl_index})
3041
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003042 def acl_dump(self, acl_index, expected_retval=0):
3043 return self.api(self.papi.acl_dump,
3044 {'acl_index': acl_index},
3045 expected_retval=expected_retval)
3046
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003047 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3048 expected_retval=0):
3049 return self.api(self.papi.acl_interface_list_dump,
3050 {'sw_if_index': sw_if_index},
3051 expected_retval=expected_retval)
3052
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003053 def macip_acl_add(self, rules, tag=""):
3054 """ Add MACIP acl
3055
3056 :param rules: list of rules for given acl
3057 :param tag: acl tag
3058 """
3059
3060 return self.api(self.papi.macip_acl_add,
3061 {'r': rules,
3062 'count': len(rules),
3063 'tag': tag})
3064
Pavel Kotucek932f7412017-09-07 14:44:52 +02003065 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3066 """ Add MACIP acl
3067
3068 :param rules: list of rules for given acl
3069 :param tag: acl tag
3070 """
3071
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003072 return self.api(self.papi.macip_acl_add_replace,
3073 {'acl_index': acl_index,
3074 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003075 'count': len(rules),
3076 'tag': tag})
3077
3078 def macip_acl_del(self, acl_index):
3079 """
3080
3081 :param acl_index:
3082 :return:
3083 """
3084 return self.api(self.papi.macip_acl_del,
3085 {'acl_index': acl_index})
3086
3087 def macip_acl_interface_add_del(self,
3088 sw_if_index,
3089 acl_index,
3090 is_add=1):
3091 """ Add MACIP acl to interface
3092
3093 :param sw_if_index:
3094 :param acl_index:
3095 :param is_add: (Default value = 1)
3096 """
3097
3098 return self.api(self.papi.macip_acl_interface_add_del,
3099 {'is_add': is_add,
3100 'sw_if_index': sw_if_index,
3101 'acl_index': acl_index})
3102
3103 def macip_acl_interface_get(self):
3104 """ Return interface acls dump
3105 """
3106 return self.api(
3107 self.papi.macip_acl_interface_get, {})
3108
3109 def macip_acl_dump(self, acl_index=4294967295):
3110 """ Return MACIP acl dump
3111 """
3112
3113 return self.api(
3114 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003115
3116 def policer_add_del(self,
3117 name,
3118 cir,
3119 eir,
3120 cb,
3121 eb,
3122 is_add=1,
3123 rate_type=0,
3124 round_type=0,
3125 ptype=0,
3126 color_aware=0,
3127 conform_action_type=1,
3128 conform_dscp=0,
3129 exceed_action_type=0,
3130 exceed_dscp=0,
3131 violate_action_type=0,
3132 violate_dscp=0):
3133 return self.api(self.papi.policer_add_del,
3134 {'name': name,
3135 'cir': cir,
3136 'eir': eir,
3137 'cb': cb,
3138 'eb': eb,
3139 'is_add': is_add,
3140 'rate_type': rate_type,
3141 'round_type': round_type,
3142 'type': ptype,
3143 'color_aware': color_aware,
3144 'conform_action_type': conform_action_type,
3145 'conform_dscp': conform_dscp,
3146 'exceed_action_type': exceed_action_type,
3147 'exceed_dscp': exceed_dscp,
3148 'violate_action_type': violate_action_type,
3149 'violate_dscp': violate_dscp})
3150
3151 def ip_punt_police(self,
3152 policer_index,
3153 is_ip6=0,
3154 is_add=1):
3155 return self.api(self.papi.ip_punt_police,
3156 {'policer_index': policer_index,
3157 'is_add': is_add,
3158 'is_ip6': is_ip6})
3159
3160 def ip_punt_redirect(self,
3161 rx_sw_if_index,
3162 tx_sw_if_index,
3163 nh,
3164 is_ip6=0,
3165 is_add=1):
3166 return self.api(self.papi.ip_punt_redirect,
3167 {'rx_sw_if_index': rx_sw_if_index,
3168 'tx_sw_if_index': tx_sw_if_index,
3169 'nh': nh,
3170 'is_add': is_add,
3171 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003172
3173 def bier_table_add_del(self,
3174 bti,
3175 mpls_label,
3176 is_add=1):
3177 """ BIER Table add/del """
3178 return self.api(
3179 self.papi.bier_table_add_del,
3180 {'bt_tbl_id': {"bt_set": bti.set_id,
3181 "bt_sub_domain": bti.sub_domain_id,
3182 "bt_hdr_len_id": bti.hdr_len_id},
3183 'bt_label': mpls_label,
3184 'bt_is_add': is_add})
3185
3186 def bier_table_dump(self):
3187 return self.api(self.papi.bier_table_dump, {})
3188
3189 def bier_route_add_del(self,
3190 bti,
3191 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003192 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003193 is_add=1,
3194 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003195 """ BIER Route add/del """
3196 return self.api(
3197 self.papi.bier_route_add_del,
3198 {'br_tbl_id': {"bt_set": bti.set_id,
3199 "bt_sub_domain": bti.sub_domain_id,
3200 "bt_hdr_len_id": bti.hdr_len_id},
3201 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003202 'br_n_paths': len(paths),
3203 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003204 'br_is_add': is_add,
3205 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003206
3207 def bier_route_dump(self, bti):
3208 return self.api(
3209 self.papi.bier_route_dump,
3210 {'br_tbl_id': {"bt_set": bti.set_id,
3211 "bt_sub_domain": bti.sub_domain_id,
3212 "bt_hdr_len_id": bti.hdr_len_id}})
3213
3214 def bier_imp_add(self,
3215 bti,
3216 src,
3217 ibytes,
3218 is_add=1):
3219 """ BIER Imposition Add """
3220 return self.api(
3221 self.papi.bier_imp_add,
3222 {'bi_tbl_id': {"bt_set": bti.set_id,
3223 "bt_sub_domain": bti.sub_domain_id,
3224 "bt_hdr_len_id": bti.hdr_len_id},
3225 'bi_src': src,
3226 'bi_n_bytes': len(ibytes),
3227 'bi_bytes': ibytes})
3228
3229 def bier_imp_del(self, bi_index):
3230 """ BIER Imposition del """
3231 return self.api(
3232 self.papi.bier_imp_del,
3233 {'bi_index': bi_index})
3234
3235 def bier_imp_dump(self):
3236 return self.api(self.papi.bier_imp_dump, {})
3237
3238 def bier_disp_table_add_del(self,
3239 bdti,
3240 is_add=1):
3241 """ BIER Disposition Table add/del """
3242 return self.api(
3243 self.papi.bier_disp_table_add_del,
3244 {'bdt_tbl_id': bdti,
3245 'bdt_is_add': is_add})
3246
3247 def bier_disp_table_dump(self):
3248 return self.api(self.papi.bier_disp_table_dump, {})
3249
3250 def bier_disp_entry_add_del(self,
3251 bdti,
3252 bp,
3253 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003254 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003255 next_hop,
3256 next_hop_tbl_id=0,
3257 next_hop_rpf_id=~0,
3258 next_hop_is_ip4=1,
3259 is_add=1):
3260 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003261 lstack = []
3262 while (len(lstack) < 16):
3263 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003264 return self.api(
3265 self.papi.bier_disp_entry_add_del,
3266 {'bde_tbl_id': bdti,
3267 'bde_bp': bp,
3268 'bde_payload_proto': payload_proto,
3269 'bde_n_paths': 1,
3270 'bde_paths': [{'next_hop': next_hop,
3271 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003272 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003273 'rpf_id': next_hop_rpf_id,
3274 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003275 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003276 'bde_is_add': is_add})
3277
3278 def bier_disp_entry_dump(self, bdti):
3279 return self.api(
3280 self.papi.bier_disp_entry_dump,
3281 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003282
3283 def add_node_next(self, node_name, next_name):
3284 """ Set the next node for a given node request
3285
3286 :param node_name:
3287 :param next_name:
3288 """
3289 return self.api(self.papi.add_node_next,
3290 {'node_name': node_name,
3291 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003292
3293 def session_enable_disable(self, is_enabled):
3294 return self.api(
3295 self.papi.session_enable_disable,
3296 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003297
3298 def ipsec_spd_add_del(self, spd_id, is_add=1):
3299 """ SPD add/del - Wrapper to add or del ipsec SPD
3300 Sample CLI : 'ipsec spd add 1'
3301
3302 :param spd_id - SPD ID to be created in the vpp . mandatory
3303 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3304 optional
3305 :returns: reply from the API
3306 """
3307 return self.api(
3308 self.papi.ipsec_spd_add_del, {
3309 'spd_id': spd_id, 'is_add': is_add})
3310
3311 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3312 """ IPSEC interface SPD add/del - \
3313 Wrapper to associate/disassociate SPD to interface in VPP
3314 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3315
3316 :param spd_id - SPD ID to associate with the interface . mandatory
3317 :param sw_if_index - Interface Index which needs to ipsec \
3318 association mandatory
3319 :param is_add - add(1) or del(0) association with interface \
3320 (Default 1 - add) . optional
3321 :returns: reply from the API
3322 """
3323 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003324 self.papi.ipsec_interface_add_del_spd,
3325 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003326
3327 def ipsec_sad_add_del_entry(self,
3328 sad_id,
3329 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003330 integrity_algorithm,
3331 integrity_key,
3332 crypto_algorithm,
3333 crypto_key,
3334 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003335 tunnel_src_address='',
3336 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003337 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003338 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003339 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003340 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003341 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003342 :param sad_id: security association ID
3343 :param spi: security param index of the SA in decimal
3344 :param integrity_algorithm:
3345 :param integrity_key:
3346 :param crypto_algorithm:
3347 :param crypto_key:
3348 :param protocol: AH(0) or ESP(1) protocol
3349 :param tunnel_src_address: tunnel mode outer src address
3350 :param tunnel_dst_address: tunnel mode outer dst address
3351 :param is_add:
3352 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003353 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3354 crypto and ipsec algorithms
3355 """
3356 return self.api(
3357 self.papi.ipsec_sad_add_del_entry,
3358 {'sad_id': sad_id,
3359 'spi': spi,
3360 'tunnel_src_address': tunnel_src_address,
3361 'tunnel_dst_address': tunnel_dst_address,
3362 'protocol': protocol,
3363 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003364 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003365 'integrity_key': integrity_key,
3366 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003367 'crypto_key_length': len(crypto_key) if crypto_key is not None
3368 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003369 'crypto_key': crypto_key,
3370 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003371 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003372 'is_tunnel_ipv6': is_tunnel_ipv6,
Klement Sekera4b089f22018-04-17 18:04:57 +02003373 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003374
3375 def ipsec_spd_add_del_entry(self,
3376 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003377 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003378 local_address_start,
3379 local_address_stop,
3380 remote_address_start,
3381 remote_address_stop,
3382 local_port_start=0,
3383 local_port_stop=65535,
3384 remote_port_start=0,
3385 remote_port_stop=65535,
3386 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003387 policy=0,
3388 priority=100,
3389 is_outbound=1,
3390 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003391 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003392 is_ip_any=0):
3393 """ IPSEC policy SPD add/del -
3394 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003395 :param spd_id: SPD ID for the policy
3396 :param local_address_start: local-ip-range start address
3397 :param local_address_stop : local-ip-range stop address
3398 :param remote_address_start: remote-ip-range start address
3399 :param remote_address_stop : remote-ip-range stop address
3400 :param local_port_start: (Default value = 0)
3401 :param local_port_stop: (Default value = 65535)
3402 :param remote_port_start: (Default value = 0)
3403 :param remote_port_stop: (Default value = 65535)
3404 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3405 :param sa_id: Security Association ID for mapping it to SPD
3406 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3407 (Default value = 0)
3408 :param priority: value for the spd action (Default value = 100)
3409 :param is_outbound: flag for inbound(0) or outbound(1)
3410 (Default value = 1)
3411 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003412 """
3413 return self.api(
3414 self.papi.ipsec_spd_add_del_entry,
3415 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003416 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003417 'local_address_start': local_address_start,
3418 'local_address_stop': local_address_stop,
3419 'remote_address_start': remote_address_start,
3420 'remote_address_stop': remote_address_stop,
3421 'local_port_start': local_port_start,
3422 'local_port_stop': local_port_stop,
3423 'remote_port_start': remote_port_start,
3424 'remote_port_stop': remote_port_stop,
3425 'is_add': is_add,
3426 'protocol': protocol,
3427 'policy': policy,
3428 'priority': priority,
3429 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003430 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003431 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003432
Klement Sekera31da2e32018-06-24 22:49:55 +02003433 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3434 remote_spi, crypto_alg, local_crypto_key,
3435 remote_crypto_key, integ_alg, local_integ_key,
3436 remote_integ_key, is_add=1, esn=0,
3437 anti_replay=1, renumber=0, show_instance=0):
3438 return self.api(
3439 self.papi.ipsec_tunnel_if_add_del,
3440 {'local_ip': local_ip, 'remote_ip': remote_ip,
3441 'local_spi': local_spi, 'remote_spi': remote_spi,
3442 'crypto_alg': crypto_alg,
3443 'local_crypto_key_len': len(local_crypto_key),
3444 'local_crypto_key': local_crypto_key,
3445 'remote_crypto_key_len': len(remote_crypto_key),
3446 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3447 'local_integ_key_len': len(local_integ_key),
3448 'local_integ_key': local_integ_key,
3449 'remote_integ_key_len': len(remote_integ_key),
3450 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3451 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3452 'show_instance': show_instance
3453 })
3454
Klement Sekerab4d30532018-11-08 13:00:02 +01003455 def ipsec_select_backend(self, protocol, index):
3456 return self.api(self.papi.ipsec_select_backend,
3457 {'protocol': protocol, 'index': index})
3458
3459 def ipsec_backend_dump(self):
3460 return self.api(self.papi.ipsec_backend_dump, {})
3461
Florin Corasb795bd02017-12-14 11:30:48 -08003462 def app_namespace_add(self,
3463 namespace_id,
3464 ip4_fib_id=0,
3465 ip6_fib_id=0,
3466 sw_if_index=0xFFFFFFFF,
3467 secret=0):
3468 return self.api(
3469 self.papi.app_namespace_add_del,
3470 {'secret': secret,
3471 'sw_if_index': sw_if_index,
3472 'ip4_fib_id': ip4_fib_id,
3473 'ip6_fib_id': ip6_fib_id,
3474 'namespace_id': namespace_id,
3475 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003476
3477 def punt_socket_register(self, l4_port, pathname, header_version=1,
3478 is_ip4=1, l4_protocol=0x11):
3479 """ Punt to socket """
3480 return self.api(self.papi.punt_socket_register,
3481 {'is_ip4': is_ip4,
3482 'l4_protocol': l4_protocol,
3483 'l4_port': l4_port,
3484 'pathname': pathname,
3485 'header_version': header_version})
3486
3487 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3488 expire_walk_interval_ms, is_ip6=0):
3489 """ Set IP reassembly parameters """
3490 return self.api(self.papi.ip_reassembly_set,
3491 {'is_ip6': is_ip6,
3492 'timeout_ms': timeout_ms,
3493 'expire_walk_interval_ms': expire_walk_interval_ms,
3494 'max_reassemblies': max_reassemblies})
3495
3496 def ip_reassembly_get(self, is_ip6=0):
3497 """ Get IP reassembly parameters """
3498 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003499
Klement Sekera4c533132018-02-22 11:41:12 +01003500 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3501 enable_ip6=False):
3502 """ Enable/disable IP reassembly """
3503 return self.api(self.papi.ip_reassembly_enable_disable,
3504 {'sw_if_index': sw_if_index,
3505 'enable_ip4': 1 if enable_ip4 else 0,
3506 'enable_ip6': 1 if enable_ip6 else 0,
3507 })
3508
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003509 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3510 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003511 """ GBP endpoint Add """
3512 return self.api(self.papi.gbp_endpoint_add,
3513 {'endpoint': {
3514 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003515 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003516 'ips': ips,
3517 'n_ips': len(ips),
3518 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003519 'epg_id': epg,
3520 'flags': flags,
3521 'tun': {
3522 'src': tun_src,
3523 'dst': tun_dst,
3524 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003525
3526 def gbp_endpoint_del(self, handle):
3527 """ GBP endpoint Del """
3528 return self.api(self.papi.gbp_endpoint_del,
3529 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003530
3531 def gbp_endpoint_dump(self):
3532 """ GBP endpoint Dump """
3533 return self.api(self.papi.gbp_endpoint_dump, {})
3534
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003535 def gbp_endpoint_group_add(self, epg, bd,
3536 rd, uplink_sw_if_index):
3537 """ GBP endpoint group Add """
3538 return self.api(self.papi.gbp_endpoint_group_add,
3539 {'epg':
3540 {
Neale Ranns25b04942018-04-04 09:34:50 -07003541 'uplink_sw_if_index': uplink_sw_if_index,
3542 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003543 'rd_id': rd,
3544 'epg_id': epg
3545 }})
3546
3547 def gbp_endpoint_group_del(self, epg):
3548 """ GBP endpoint group Del """
3549 return self.api(self.papi.gbp_endpoint_group_del,
3550 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003551
3552 def gbp_endpoint_group_dump(self):
3553 """ GBP endpoint group Dump """
3554 return self.api(self.papi.gbp_endpoint_group_dump, {})
3555
Neale Rannsc29c0af2018-11-07 04:21:12 -08003556 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003557 bvi_sw_if_index,
3558 uu_fwd_sw_if_index):
3559 """ GBP bridge-domain Add """
3560 return self.api(self.papi.gbp_bridge_domain_add,
3561 {'bd':
3562 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003563 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003564 'bvi_sw_if_index': bvi_sw_if_index,
3565 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3566 'bd_id': bd_id
3567 }})
3568
3569 def gbp_bridge_domain_del(self, bd_id):
3570 """ GBP bridge-domain Del """
3571 return self.api(self.papi.gbp_bridge_domain_del,
3572 {'bd_id': bd_id})
3573
3574 def gbp_bridge_domain_dump(self):
3575 """ GBP Bridge Domain Dump """
3576 return self.api(self.papi.gbp_bridge_domain_dump, {})
3577
3578 def gbp_route_domain_add(self, rd_id,
3579 ip4_table_id,
3580 ip6_table_id,
3581 ip4_uu_sw_if_index,
3582 ip6_uu_sw_if_index):
3583 """ GBP route-domain Add """
3584 return self.api(self.papi.gbp_route_domain_add,
3585 {'rd':
3586 {
3587 'ip4_table_id': ip4_table_id,
3588 'ip6_table_id': ip6_table_id,
3589 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3590 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3591 'rd_id': rd_id
3592 }})
3593
3594 def gbp_route_domain_del(self, rd_id):
3595 """ GBP route-domain Del """
3596 return self.api(self.papi.gbp_route_domain_del,
3597 {'rd_id': rd_id})
3598
3599 def gbp_route_domain_dump(self):
3600 """ GBP Route Domain Dump """
3601 return self.api(self.papi.gbp_route_domain_dump, {})
3602
Neale Ranns25b04942018-04-04 09:34:50 -07003603 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3604 """ GBP recirc Add/Del """
3605 return self.api(self.papi.gbp_recirc_add_del,
3606 {'is_add': is_add,
3607 'recirc': {
3608 'is_ext': is_ext,
3609 'sw_if_index': sw_if_index,
3610 'epg_id': epg}})
3611
3612 def gbp_recirc_dump(self):
3613 """ GBP recirc Dump """
3614 return self.api(self.papi.gbp_recirc_dump, {})
3615
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003616 def gbp_subnet_add_del(self, is_add, rd_id,
3617 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003618 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003619 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003620 """ GBP Subnet Add/Del """
3621 return self.api(self.papi.gbp_subnet_add_del,
3622 {'is_add': is_add,
3623 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003624 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003625 'sw_if_index': sw_if_index,
3626 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003627 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003628 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003629
3630 def gbp_subnet_dump(self):
3631 """ GBP Subnet Dump """
3632 return self.api(self.papi.gbp_subnet_dump, {})
3633
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003634 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3635 """ GBP contract Add/Del """
3636 return self.api(self.papi.gbp_contract_add_del,
3637 {'is_add': is_add,
3638 'contract': {
3639 'acl_index': acl_index,
3640 'src_epg': src_epg,
3641 'dst_epg': dst_epg}})
3642
3643 def gbp_contract_dump(self):
3644 """ GBP contract Dump """
3645 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003646
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003647 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3648 """ GBP set inactive threshold """
3649 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3650 {'threshold': threshold})
3651
3652 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3653 """ GBP VXLAN tunnel add """
3654 return self.api(self.papi.gbp_vxlan_tunnel_add,
3655 {
3656 'tunnel': {
3657 'vni': vni,
3658 'mode': mode,
3659 'bd_rd_id': bd_rd_id
3660 }
3661 })
3662
3663 def gbp_vxlan_tunnel_del(self, vni):
3664 """ GBP VXLAN tunnel del """
3665 return self.api(self.papi.gbp_vxlan_tunnel_del,
3666 {
3667 'vni': vni,
3668 })
3669
3670 def gbp_vxlan_tunnel_dump(self):
3671 """ GBP VXLAN tunnel add/del """
3672 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3673
Neale Ranns61502112018-08-22 00:21:14 -07003674 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3675 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003676 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003677 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003678 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003679 {'ip4_table_id': ip4_table_id,
3680 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003681 'ip6_prefix': ip6_prefix,
3682 'ip6_prefix_len': ip6_prefix_len,
3683 'ip4_prefix': ip4_prefix,
3684 'ip4_prefix_len': ip4_prefix_len,
3685 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003686 'security_check': security_check})
3687
Ole Troan298c6952018-03-08 12:30:43 +01003688 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003689 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003690 return self.api(self.papi.ipip_6rd_del_tunnel,
3691 {'sw_if_index': sw_if_index})
3692
3693 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003694 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003695 """ IPIP tunnel Add/Del """
3696 return self.api(self.papi.ipip_add_tunnel,
3697 {'is_ipv6': is_ipv6,
3698 'instance': instance,
3699 'src_address': src_address,
3700 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003701 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003702 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003703
3704 def ipip_del_tunnel(self, sw_if_index):
3705 """ IPIP tunnel Delete """
3706 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003707 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003708
3709 def qos_egress_map_update(self, id, outputs):
3710 """ QOS egress map update """
3711 return self.api(self.papi.qos_egress_map_update,
3712 {'map_id': id,
3713 'rows': outputs})
3714
3715 def qos_egress_map_delete(self, id):
3716 """ QOS egress map delete """
3717 return self.api(self.papi.qos_egress_map_delete,
3718 {'map_id': id})
3719
3720 def qos_mark_enable_disable(self, sw_if_index,
3721 output_source,
3722 map_id,
3723 enable):
3724 """ QOS Mark Enable/Disable """
3725 return self.api(self.papi.qos_mark_enable_disable,
3726 {'map_id': map_id,
3727 'sw_if_index': sw_if_index,
3728 'output_source': output_source,
3729 'enable': enable})
3730
3731 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3732 """ IP QoS recording Enble/Disable """
3733 return self.api(self.papi.qos_record_enable_disable,
3734 {'sw_if_index': sw_if_index,
3735 'input_source': input_source,
3736 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003737
Neale Ranns947ea622018-06-07 23:48:20 -07003738 def igmp_enable_disable(self, sw_if_index, enable, host):
3739 """ Enable/disable IGMP on a given interface """
3740 return self.api(self.papi.igmp_enable_disable,
3741 {'enable': enable,
3742 'mode': host,
3743 'sw_if_index': sw_if_index})
3744
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003745 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3746 """ Add/del IGMP proxy device """
3747 return self.api(self.papi.igmp_proxy_device_add_del,
3748 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3749 'add': add})
3750
3751 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3752 """ Add/del interface to/from IGMP proxy device """
3753 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3754 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3755 'add': add})
3756
Neale Ranns947ea622018-06-07 23:48:20 -07003757 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003758 """ Listen for new (S,G) on specified interface
3759
3760 :param enable: add/del
3761 :param sw_if_index: interface sw index
3762 :param saddr: source ip4 addr
3763 :param gaddr: group ip4 addr
3764 """
3765 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003766 {
3767 'group':
3768 {
3769 'filter': filter,
3770 'sw_if_index': sw_if_index,
3771 'n_srcs': len(saddrs),
3772 'saddrs': saddrs,
3773 'gaddr':
3774 {
3775 'address': gaddr
3776 }
3777 }
3778 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003779
3780 def igmp_dump(self, sw_if_index=None):
3781 """ Dump all (S,G) interface configurations """
3782 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003783 sw_if_index = 0xffffffff
3784 return self.api(self.papi.igmp_dump,
3785 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003786
3787 def igmp_clear_interface(self, sw_if_index):
3788 """ Remove all (S,G)s from specified interface
3789 doesn't send IGMP report!
3790 """
3791 return self.api(
3792 self.papi.igmp_clear_interface, {
3793 'sw_if_index': sw_if_index})
3794
3795 def want_igmp_events(self, enable=1):
3796 return self.api(self.papi.want_igmp_events, {'enable': enable,
3797 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003798
3799 def bond_create(
3800 self,
3801 mode,
3802 lb,
3803 use_custom_mac,
3804 mac_address=''):
3805 """
3806 :param mode: mode
3807 :param lb: load balance
3808 :param use_custom_mac: use custom mac
3809 :param mac_address: mac address
3810 """
3811 return self.api(
3812 self.papi.bond_create,
3813 {'mode': mode,
3814 'lb': lb,
3815 'use_custom_mac': use_custom_mac,
3816 'mac_address': mac_address
3817 })
3818
3819 def bond_delete(
3820 self,
3821 sw_if_index):
3822 """
3823 :param sw_if_index: interface the operation is applied to
3824 """
3825 return self.api(self.papi.bond_delete,
3826 {'sw_if_index': sw_if_index})
3827
3828 def bond_enslave(
3829 self,
3830 sw_if_index,
3831 bond_sw_if_index,
3832 is_passive,
3833 is_long_timeout):
3834 """
3835 :param sw_if_index: slave sw_if_index
3836 :param bond_sw_if_index: bond sw_if_index
3837 :param is_passive: is passive lacp speaker
3838 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3839 """
3840 return self.api(
3841 self.papi.bond_enslave,
3842 {'sw_if_index': sw_if_index,
3843 'bond_sw_if_index': bond_sw_if_index,
3844 'is_passive': is_passive,
3845 'is_long_timeout': is_long_timeout
3846 })
3847
3848 def bond_detach_slave(
3849 self,
3850 sw_if_index):
3851 """
3852 :param sw_if_index: slave interface the operation is applied to
3853 """
3854 return self.api(self.papi.bond_detach_slave,
3855 {'sw_if_index': sw_if_index})
3856
3857 def sw_interface_slave_dump(
3858 self,
3859 sw_if_index):
3860 """
3861 :param sw_if_index: bond sw_if_index
3862 """
3863 return self.api(self.papi.sw_interface_slave_dump,
3864 {'sw_if_index': sw_if_index})
3865
3866 def sw_interface_bond_dump(
3867 self):
3868 """
3869
3870 """
3871 return self.api(self.papi.sw_interface_bond_dump,
3872 {})
Stevene8fa6202017-08-30 14:36:45 -07003873
3874 def create_vhost_user_if(
3875 self,
3876 is_server,
3877 sock_filename,
3878 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003879 disable_mrg_rxbuf,
3880 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003881 custom_dev_instance,
3882 use_custom_mac,
3883 mac_address,
3884 tag=''):
3885 """
3886 :param is_server: is server
3887 :param sock_filename: socket name
3888 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003889 :param disable_mrg_rxbuf: disable mergable rx buffers
3890 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003891 :param custom_dev_instance: custom dev instance
3892 :param use_custom_mac: use custom mac
3893 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003894 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003895 """
3896 return self.api(
3897 self.papi.create_vhost_user_if,
3898 {'is_server': is_server,
3899 'sock_filename': sock_filename,
3900 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003901 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3902 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003903 'custom_dev_instance': custom_dev_instance,
3904 'use_custom_mac': use_custom_mac,
3905 'mac_address': mac_address,
3906 'tag': tag
3907 })
3908
3909 def delete_vhost_user_if(
3910 self,
3911 sw_if_index):
3912 """
3913 :param sw_if_index: interface the operation is applied to
3914 """
3915 return self.api(self.papi.delete_vhost_user_if,
3916 {'sw_if_index': sw_if_index, })
3917
3918 def sw_interface_vhost_user_dump(
3919 self):
3920 """
3921
3922 """
3923 return self.api(self.papi.sw_interface_vhost_user_dump,
3924 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003925
3926 def abf_policy_add_del(self, is_add, policy):
3927 return self.api(
3928 self.papi.abf_policy_add_del,
3929 {'is_add': is_add,
3930 'policy': policy})
3931
3932 def abf_itf_attach_add_del(self, is_add, attach):
3933 return self.api(
3934 self.papi.abf_itf_attach_add_del,
3935 {'is_add': is_add,
3936 'attach': attach})
3937
3938 def abf_policy_dump(self):
3939 return self.api(
3940 self.papi.abf_policy_dump, {})
3941
3942 def abf_itf_attach_dump(self):
3943 return self.api(
3944 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003945
3946 def pipe_create(self, is_specified, user_instance):
3947 return self.api(self.papi.pipe_create,
3948 {'is_specified': is_specified,
3949 'user_instance': user_instance})
3950
3951 def pipe_delete(self, parent_sw_if_index):
3952 return self.api(self.papi.pipe_delete,
3953 {'parent_sw_if_index': parent_sw_if_index})
3954
3955 def pipe_dump(self):
3956 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003957
3958 def memif_create(
3959 self,
3960 role,
3961 mode,
3962 rx_queues=None,
3963 tx_queues=None,
3964 _id=None,
3965 socket_id=None,
3966 secret=None,
3967 ring_size=None,
3968 buffer_size=None,
3969 hw_addr=None):
3970 return self.api(self.papi.memif_create,
3971 {'role': role,
3972 'mode': mode,
3973 'rx_queues': rx_queues,
3974 'tx_queues': tx_queues,
3975 'id': _id,
3976 'socket_id': socket_id,
3977 'secret': secret,
3978 'ring_size': ring_size,
3979 'buffer_size': buffer_size,
3980 'hw_addr': hw_addr})
3981
3982 def memif_delete(self, sw_if_index):
3983 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
3984
3985 def memif_dump(self):
3986 return self.api(self.papi.memif_dump, {})
3987
3988 def memif_socket_filename_add_del(
3989 self, is_add, socket_id, socket_filename):
3990 return self.api(
3991 self.papi.memif_socket_filename_add_del,
3992 {'is_add': is_add,
3993 'socket_id': socket_id,
3994 'socket_filename': socket_filename})
3995
3996 def memif_socket_filename_dump(self):
3997 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07003998
3999 def svs_table_add_del(self, af, table_id, is_add=1):
4000 return self.api(self.papi.svs_table_add_del,
4001 {
4002 'table_id': table_id,
4003 'is_add': is_add,
4004 'af': af,
4005 })
4006
4007 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4008 return self.api(self.papi.svs_route_add_del,
4009 {
4010 'table_id': table_id,
4011 'source_table_id': src_table_id,
4012 'prefix': prefix,
4013 'is_add': is_add,
4014 })
4015
4016 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4017 return self.api(self.papi.svs_enable_disable,
4018 {
4019 'af': af,
4020 'table_id': table_id,
4021 'sw_if_index': sw_if_index,
4022 'is_enable': is_enable,
4023 })
4024
4025 def svs_dump(self):
4026 return self.api(self.papi.svs_dump, {})