blob: 370758764dfafa4e941142101cb83ade9be840e2 [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import fnmatch
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08002import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02003import time
Klement Sekerae4504c62016-12-08 10:16:41 +01004from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02005
Paul Vinciguerra6c746172018-11-26 09:57:21 -08006from six import moves
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08007
8from hook import Hook
9
Klement Sekera0e3c0de2016-09-29 14:43:44 +020010# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +010011# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
12# the vpp_papi_provider.py file to be importable without having to build
13# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020014do_import = True
15try:
16 no_vpp_papi = os.getenv("NO_VPP_PAPI")
17 if no_vpp_papi == "1":
18 do_import = False
19except:
20 pass
21
22if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010023 from vpp_papi import VPP
Neale Ranns93cc3ee2018-10-10 07:22:51 -070024 from vpp_l2 import L2_PORT_TYPE
Klement Sekera277b89c2016-10-28 13:20:27 +020025
Klement Sekeraf62ae122016-10-11 11:47:09 +020026# from vnet/vnet/mpls/mpls_types.h
27MPLS_IETF_MAX_LABEL = 0xfffff
28MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
29
Klement Sekera0e3c0de2016-09-29 14:43:44 +020030
Neale Ranns177bbdc2016-11-15 09:46:51 +000031class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030032 L2_DISABLED = 0
33 L2_PUSH_1 = 1
34 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000035 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030036 L2_POP_2 = 4
37 L2_TRANSLATE_1_1 = 5
38 L2_TRANSLATE_1_2 = 6
39 L2_TRANSLATE_2_1 = 7
40 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000041
Klement Sekera0e3c0de2016-09-29 14:43:44 +020042
Neale Ranns039cbfe2018-02-27 03:45:38 -080043class QOS_SOURCE:
44 EXT = 0
45 VLAN = 1
46 MPLS = 2
47 IP = 3
48
49
Matus Fabianb4515b42018-11-19 04:25:32 -080050class SYSLOG_SEVERITY:
51 EMERG = 0
52 ALERT = 1
53 CRIT = 2
54 ERR = 3
55 WARN = 4
56 NOTICE = 5
57 INFO = 6
58 DBG = 7
59
60
Klement Sekera73884482017-02-23 09:26:30 +010061class UnexpectedApiReturnValueError(Exception):
62 """ exception raised when the API return value is unexpected """
63 pass
64
65
Klement Sekeraf62ae122016-10-11 11:47:09 +020066class VppPapiProvider(object):
67 """VPP-api provider using vpp-papi
68
69 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020070 """
71
Klement Sekerae0545ef2017-01-25 08:00:40 +010072 _zero, _negative = range(2)
73
Klement Sekera611864f2018-09-26 11:19:00 +020074 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020075 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020076 self.name = name
77 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010078 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010079 self._expect_api_retval = self._zero
80 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010081 jsonfiles = []
82
Klement Sekerab8c72a42018-11-08 11:21:39 +010083 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010084 for root, dirnames, filenames in os.walk(install_dir):
85 for filename in fnmatch.filter(filenames, '*.api.json'):
86 jsonfiles.append(os.path.join(root, filename))
87
Klement Sekera611864f2018-09-26 11:19:00 +020088 self.vpp = VPP(jsonfiles, logger=test_class.logger,
89 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010090 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020091
Klement Sekerae0545ef2017-01-25 08:00:40 +010092 def __enter__(self):
93 return self
94
Klement Sekera7d6afb32018-11-08 11:52:04 +010095 def assert_negative_api_retval(self):
96 """ Expect API failure - used with with, e.g.:
97 with self.vapi.assert_negative_api_retval():
98 self.vapi.<api call expected to fail>
99 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100100 self._expect_stack.append(self._expect_api_retval)
101 self._expect_api_retval = self._negative
102 return self
103
Klement Sekera7d6afb32018-11-08 11:52:04 +0100104 def assert_zero_api_retval(self):
105 """ Expect API success - used with with, e.g.:
106 with self.vapi.assert_negative_api_retval():
107 self.vapi.<api call expected to succeed>
108
109 note: this is useful only inside another with block
110 as success is the default expected value
111 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100112 self._expect_stack.append(self._expect_api_retval)
113 self._expect_api_retval = self._zero
114 return self
115
116 def __exit__(self, exc_type, exc_value, traceback):
117 self._expect_api_retval = self._expect_stack.pop()
118
Klement Sekeraf62ae122016-10-11 11:47:09 +0200119 def register_hook(self, hook):
120 """Replace hook registration with new hook
121
122 :param hook:
123
124 """
125 self.hook = hook
126
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200127 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100128 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200129 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100130 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200131 return e
132
133 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100134 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100135 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100136 self.test_class.logger.debug("Expecting event '%s' within %ss",
137 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300138 else:
139 self.test_class.logger.debug("Expecting event within %ss",
140 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100141 if self._events:
142 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200143 limit = time.time() + timeout
144 while time.time() < limit:
145 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100146 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200147 if name and type(e).__name__ != name:
148 raise Exception(
149 "Unexpected event received: %s, expected: %s" %
150 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100151 self.test_class.logger.debug("Returning event %s:%s" %
152 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200153 return e
154 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200155 raise Exception("Event did not occur within timeout")
156
157 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100158 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200159 # FIXME use the name instead of relying on type(e).__name__ ?
160 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100161 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200162 self._events.append(event)
163
Klement Sekeraf62ae122016-10-11 11:47:09 +0200164 def connect(self):
165 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100166 self.vpp.connect(self.name, self.shm_prefix)
167 self.papi = self.vpp.api
168 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200169
170 def disconnect(self):
171 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100172 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200173
174 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100175 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200176 Call the appropriate hooks before and after the API call
177
178 :param api_fn: API function to call
179 :param api_args: tuple of API function arguments
180 :param expected_retval: Expected return value (Default value = 0)
181 :returns: reply from the API
182
183 """
184 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100185 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100186 if self._expect_api_retval == self._negative:
187 if hasattr(reply, 'retval') and reply.retval >= 0:
188 msg = "API call passed unexpectedly: expected negative "\
189 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800190 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100191 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100192 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100193 elif self._expect_api_retval == self._zero:
194 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700195 msg = "API call failed, expected %d return value instead "\
196 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800197 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100198 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100199 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100200 else:
201 raise Exception("Internal error, unexpected value for "
202 "self._expect_api_retval %s" %
203 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200204 self.hook.after_api(api_fn.__name__, api_args)
205 return reply
206
207 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100208 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200209
210 :param cli: CLI to execute
211 :returns: CLI output
212
213 """
214 self.hook.before_cli(cli)
215 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100216 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200218 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100219 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200220
Jan49c0fca2016-10-26 15:44:27 +0200221 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100222 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200223
224 :param cli: CLI to execute
225 :returns: CLI output
226 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600227 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200228
Jan4af521d2016-11-15 17:05:00 +0100229 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200230 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100231
Klement Sekeraf62ae122016-10-11 11:47:09 +0200232 def show_version(self):
233 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100234 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200235
236 def pg_create_interface(self, pg_index):
237 """
238
239 :param pg_index:
240
241 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100242 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200243 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200244
245 def sw_interface_dump(self, filter=None):
246 """
247
248 :param filter: (Default value = None)
249
250 """
251 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200252 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200253 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100254 args = {}
255 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200256
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000257 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100258 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000259
260 :param sw_if_index:
261 :param is_ipv6:
262 :param table_id:
263
264 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100265 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200266 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
267 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000268
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700269 def sw_interface_get_table(self, sw_if_index, is_ipv6):
270 """ Get the IPvX Table-id for the Interface
271
272 :param sw_if_index:
273 :param is_ipv6:
274 :return table_id
275
276 """
277 return self.api(self.papi.sw_interface_get_table,
278 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
279
Klement Sekeraf62ae122016-10-11 11:47:09 +0200280 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
281 is_ipv6=0, is_add=1, del_all=0):
282 """
283
284 :param addr: param is_ipv6: (Default value = 0)
285 :param sw_if_index:
286 :param addr_len:
287 :param is_ipv6: (Default value = 0)
288 :param is_add: (Default value = 1)
289 :param del_all: (Default value = 0)
290
291 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100292 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200293 {'sw_if_index': sw_if_index,
294 'is_add': is_add,
295 'is_ipv6': is_ipv6,
296 'del_all': del_all,
297 'address_length': addr_len,
298 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200299
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700300 def ip_address_dump(self, sw_if_index, is_ipv6=0):
301 return self.api(self.papi.ip_address_dump,
302 {'sw_if_index': sw_if_index,
303 'is_ipv6': is_ipv6})
304
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800305 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
306 is_add=1):
307 """ Set the Interface to be unnumbered
308
309 :param is_add: (Default value = 1)
310 :param sw_if_index - interface That will be unnumbered
311 :param ip_sw_if_index - interface with an IP addres
312
313 """
314 return self.api(self.papi.sw_interface_set_unnumbered,
315 {'sw_if_index': ip_sw_if_index,
316 'unnumbered_sw_if_index': sw_if_index,
317 'is_add': is_add})
318
Neale Ranns404d88e2018-08-08 06:37:33 -0700319 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
320 return self.api(self.papi.ip_unnumbered_dump,
321 {'sw_if_index': sw_if_index})
322
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000323 def sw_interface_enable_disable_mpls(self, sw_if_index,
324 is_enable=1):
325 """
326 Enable/Disable MPLS on the interface
327 :param sw_if_index:
328 :param is_enable: (Default value = 1)
329
330 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100331 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200332 {'sw_if_index': sw_if_index,
333 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000334
Jan Gelety057bb8c2016-12-20 17:32:45 +0100335 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100336 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100337 {'sw_if_index': sw_if_index,
338 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200339
Neale Ranns227038a2017-04-21 01:07:59 -0700340 def set_ip_flow_hash(self,
341 table_id,
342 src=1,
343 dst=1,
344 sport=1,
345 dport=1,
346 proto=1,
347 reverse=0,
348 is_ip6=0):
349 return self.api(self.papi.set_ip_flow_hash,
350 {'vrf_id': table_id,
351 'src': src,
352 'dst': dst,
353 'dport': dport,
354 'sport': sport,
355 'proto': proto,
356 'reverse': reverse,
357 'is_ipv6': is_ip6})
358
Neale Ranns3f844d02017-02-18 00:03:54 -0800359 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
360 return self.api(self.papi.ip6nd_proxy_add_del,
361 {'address': address,
362 'sw_if_index': sw_if_index,
363 'is_del': is_del})
364
Neale Ranns75152282017-01-09 01:00:45 -0800365 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000366 no,
Neale Ranns75152282017-01-09 01:00:45 -0800367 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000368 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800369 return self.api(self.papi.sw_interface_ip6nd_ra_config,
370 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000371 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100372 'suppress': suppress,
373 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800374
Neale Ranns87df12d2017-02-18 08:16:41 -0800375 def ip6_sw_interface_ra_prefix(self,
376 sw_if_index,
377 address,
378 address_length,
379 use_default=0,
380 no_advertise=0,
381 off_link=0,
382 no_autoconfig=0,
383 no_onlink=0,
384 is_no=0,
385 val_lifetime=0xffffffff,
386 pref_lifetime=0xffffffff):
387 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
388 {'sw_if_index': sw_if_index,
389 'address': address,
390 'address_length': address_length,
391 'use_default': use_default,
392 'no_advertise': no_advertise,
393 'off_link': off_link,
394 'no_autoconfig': no_autoconfig,
395 'no_onlink': no_onlink,
396 'is_no': is_no,
397 'val_lifetime': val_lifetime,
398 'pref_lifetime': pref_lifetime})
399
Neale Ranns75152282017-01-09 01:00:45 -0800400 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
401 """
402 Enable/Disable An interface for IPv6
403 """
404 return self.api(self.papi.sw_interface_ip6_enable_disable,
405 {'sw_if_index': sw_if_index,
406 'enable': enable})
407
Klement Sekeraf62ae122016-10-11 11:47:09 +0200408 def vxlan_add_del_tunnel(
409 self,
410 src_addr,
411 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200412 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200413 is_add=1,
414 is_ipv6=0,
415 encap_vrf_id=0,
416 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600417 vni=0,
418 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200419 """
420
421 :param dst_addr:
422 :param src_addr:
423 :param is_add: (Default value = 1)
424 :param is_ipv6: (Default value = 0)
425 :param encap_vrf_id: (Default value = 0)
426 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200427 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200428 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600429 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200430
431 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100432 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200433 {'is_add': is_add,
434 'is_ipv6': is_ipv6,
435 'src_address': src_addr,
436 'dst_address': dst_addr,
437 'mcast_sw_if_index': mcast_sw_if_index,
438 'encap_vrf_id': encap_vrf_id,
439 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600440 'vni': vni,
441 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200442
Marco Varleseb598f1d2017-09-19 14:25:28 +0200443 def geneve_add_del_tunnel(
444 self,
445 local_addr,
446 remote_addr,
447 mcast_sw_if_index=0xFFFFFFFF,
448 is_add=1,
449 is_ipv6=0,
450 encap_vrf_id=0,
451 decap_next_index=0xFFFFFFFF,
452 vni=0):
453 """
454
455 :param remote_addr:
456 :param local_addr:
457 :param is_add: (Default value = 1)
458 :param is_ipv6: (Default value = 0)
459 :param encap_vrf_id: (Default value = 0)
460 :param decap_next_index: (Default value = 0xFFFFFFFF)
461 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
462 :param vni: (Default value = 0)
463
464 """
465 return self.api(self.papi.geneve_add_del_tunnel,
466 {'is_add': is_add,
467 'is_ipv6': is_ipv6,
468 'local_address': local_addr,
469 'remote_address': remote_addr,
470 'mcast_sw_if_index': mcast_sw_if_index,
471 'encap_vrf_id': encap_vrf_id,
472 'decap_next_index': decap_next_index,
473 'vni': vni})
474
Jan4af521d2016-11-15 17:05:00 +0100475 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
476 learn=1, arp_term=0, is_add=1):
477 """Create/delete bridge domain.
478
479 :param int bd_id: Bridge domain index.
480 :param int flood: Enable/disable bcast/mcast flooding in the BD.
481 (Default value = 1)
482 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
483 (Default value = 1)
484 :param int forward: Enable/disable forwarding on all interfaces in
485 the BD. (Default value = 1)
486 :param int learn: Enable/disable learning on all interfaces in the BD.
487 (Default value = 1)
488 :param int arp_term: Enable/disable arp termination in the BD.
489 (Default value = 1)
490 :param int is_add: Add or delete flag. (Default value = 1)
491 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100492 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200493 {'bd_id': bd_id,
494 'flood': flood,
495 'uu_flood': uu_flood,
496 'forward': forward,
497 'learn': learn,
498 'arp_term': arp_term,
499 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100500
Eyal Baric86e5922017-07-02 18:33:16 +0300501 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
502 return self.api(self.papi.bd_ip_mac_add_del,
503 {'bd_id': bd_id,
504 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700505 'ip': ip,
506 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300507
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700508 def bd_ip_mac_dump(self, bd_id):
509 return self.api(self.papi.bd_ip_mac_dump,
510 {'bd_id': bd_id})
511
Eyal Bari20197482017-09-13 12:29:08 +0300512 def want_ip4_arp_events(self, enable_disable=1, address=0):
513 return self.api(self.papi.want_ip4_arp_events,
514 {'enable_disable': enable_disable,
515 'address': address,
516 'pid': os.getpid(), })
517
Eyal Baric125ecc2017-09-20 11:29:17 +0300518 def want_ip6_nd_events(self, enable_disable=1, address=0):
519 return self.api(self.papi.want_ip6_nd_events,
520 {'enable_disable': enable_disable,
521 'address': address,
522 'pid': os.getpid(), })
523
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100524 def want_ip6_ra_events(self, enable_disable=1):
525 return self.api(self.papi.want_ip6_ra_events,
526 {'enable_disable': enable_disable,
527 'pid': os.getpid(), })
528
529 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
530 mrc=0, mrd=0):
531 return self.api(self.papi.ip6nd_send_router_solicitation,
532 {'irt': irt,
533 'mrt': mrt,
534 'mrc': mrc,
535 'mrd': mrd,
536 'sw_if_index': sw_if_index})
537
Juraj Slobodac0374232018-02-01 15:18:49 +0100538 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
539 install_default_routes):
540 return self.api(self.papi.ip6_nd_address_autoconfig,
541 {'sw_if_index': sw_if_index,
542 'enable': enable,
543 'install_default_routes': install_default_routes})
544
Juraj Slobodab3f90502018-10-04 15:15:16 +0200545 def want_interface_events(self, enable_disable=1):
546 return self.api(self.papi.want_interface_events,
547 {'enable_disable': enable_disable,
548 'pid': os.getpid(), })
549
Eyal Bari24db0ec2017-09-27 21:43:51 +0300550 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
551 max_macs_in_event=0, learn_limit=0):
552 return self.api(self.papi.want_l2_macs_events,
553 {'enable_disable': enable_disable,
554 'scan_delay': scan_delay,
555 'max_macs_in_event': max_macs_in_event,
556 'learn_limit': learn_limit,
557 'pid': os.getpid(), })
558
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200559 def want_dhcp6_reply_events(self, enable_disable=1):
560 return self.api(self.papi.want_dhcp6_reply_events,
561 {'enable_disable': enable_disable,
562 'pid': os.getpid()})
563
Juraj Sloboda81119e82018-05-25 14:02:20 +0200564 def want_dhcp6_pd_reply_events(self, enable_disable=1):
565 return self.api(self.papi.want_dhcp6_pd_reply_events,
566 {'enable_disable': enable_disable,
567 'pid': os.getpid()})
568
569 def dhcp6_clients_enable_disable(self, enable=1):
570 return self.api(self.papi.dhcp6_clients_enable_disable,
571 {'enable': enable})
572
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200573 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
574 addresses, server_index=0xFFFFFFFF,
575 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
576 ):
577 return self.api(self.papi.dhcp6_send_client_message,
578 {'sw_if_index': sw_if_index,
579 'server_index': server_index,
580 'irt': irt,
581 'mrt': mrt,
582 'mrc': mrc,
583 'mrd': mrd,
584 'stop': stop,
585 'msg_type': msg_type,
586 'T1': T1,
587 'T2': T2,
588 'n_addresses': len(addresses),
589 'addresses': addresses})
590
Juraj Sloboda81119e82018-05-25 14:02:20 +0200591 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
592 prefixes, server_index=0xFFFFFFFF,
593 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
594 ):
595 return self.api(self.papi.dhcp6_pd_send_client_message,
596 {'sw_if_index': sw_if_index,
597 'server_index': server_index,
598 'irt': irt,
599 'mrt': mrt,
600 'mrc': mrc,
601 'mrd': mrd,
602 'stop': stop,
603 'msg_type': msg_type,
604 'T1': T1,
605 'T2': T2,
606 'n_prefixes': len(prefixes),
607 'prefixes': prefixes})
608
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200609 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
610 enable=1):
611 return self.api(self.papi.dhcp6_client_enable_disable,
612 {'sw_if_index': sw_if_index,
613 'enable': enable})
614
Juraj Sloboda81119e82018-05-25 14:02:20 +0200615 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
616 enable=1):
617 return self.api(self.papi.dhcp6_pd_client_enable_disable,
618 {'sw_if_index': sw_if_index,
619 'prefix_group': prefix_group,
620 'enable': enable})
621
622 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
623 prefix_length, prefix_group,
624 is_add=1):
625 return self.api(self.papi.ip6_add_del_address_using_prefix,
626 {'sw_if_index': sw_if_index,
627 'prefix_group': prefix_group,
628 'address': address,
629 'prefix_length': prefix_length,
630 'is_add': is_add})
631
Jan4af521d2016-11-15 17:05:00 +0100632 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
633 filter_mac=0, bvi_mac=0):
634 """Create/delete L2 FIB entry.
635
636 :param str mac: MAC address to create FIB entry for.
637 :param int bd_id: Bridge domain index.
638 :param int sw_if_index: Software interface index of the interface.
639 :param int is_add: Add or delete flag. (Default value = 1)
640 :param int static_mac: Set to 1 to create static MAC entry.
641 (Default value = 0)
642 :param int filter_mac: Set to 1 to drop packet that's source or
643 destination MAC address contains defined MAC address.
644 (Default value = 0)
645 :param int bvi_mac: Set to 1 to create entry that points to BVI
646 interface. (Default value = 0)
647 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100648 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200649 {'mac': self._convert_mac(mac),
650 'bd_id': bd_id,
651 'sw_if_index': sw_if_index,
652 'is_add': is_add,
653 'static_mac': static_mac,
654 'filter_mac': filter_mac,
655 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100656
Eyal Bari93b503e2017-05-15 10:13:15 +0300657 def l2fib_flush_int(self, sw_if_index):
658 """Flush L2 FIB entries for sw_if_index.
659
660 :param int sw_if_index: Software interface index of the interface.
661 """
662 return self.api(self.papi.l2fib_flush_int,
663 {'sw_if_index': sw_if_index})
664
665 def l2fib_flush_bd(self, bd_id):
666 """Flush L2 FIB entries for bd_id.
667
668 :param int sw_if_index: Bridge Domain id.
669 """
670 return self.api(self.papi.l2fib_flush_bd,
671 {'bd_id': bd_id})
672
673 def l2fib_flush_all(self):
674 """Flush all L2 FIB.
675 """
676 return self.api(self.papi.l2fib_flush_all, {})
677
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700678 def l2_fib_table_dump(self, bd_id):
679 """ Dump the L2 FIB """
680 return self.api(self.papi.l2_fib_table_dump,
681 {'bd_id': bd_id})
682
Klement Sekeraf62ae122016-10-11 11:47:09 +0200683 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700684 shg=0, port_type=L2_PORT_TYPE.NORMAL,
685 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100686 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200687
Jan4af521d2016-11-15 17:05:00 +0100688 :param int sw_if_index: Software interface index of the interface.
689 :param int bd_id: Bridge domain index.
690 :param int shg: Split-horizon group index. (Default value = 0)
691 :param int bvi: Set interface as a bridge group virtual interface.
692 (Default value = 0)
693 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200694 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100695 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200696 {'rx_sw_if_index': sw_if_index,
697 'bd_id': bd_id,
698 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700699 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200700 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200701
Jan00dad122016-11-29 10:04:53 +0100702 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400703 """Enable/disable required feature of the bridge domain with defined
704 ID.
Jan00dad122016-11-29 10:04:53 +0100705
706 :param int bd_id: Bridge domain ID.
707 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700708 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100709 - learn (1 << 0),
710 - forward (1 << 1),
711 - flood (1 << 2),
712 - uu-flood (1 << 3) or
713 - arp-term (1 << 4).
714 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100715 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200716 {'bd_id': bd_id,
717 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700718 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100719
720 def bridge_domain_dump(self, bd_id=0):
721 """
722
723 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
724 existing bridge domains returned)
725 :return: Dictionary of bridge domain(s) data.
726 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100727 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200728 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100729
Klement Sekeraf62ae122016-10-11 11:47:09 +0200730 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
731 enable):
732 """Create or delete unidirectional cross-connect from Tx interface to
733 Rx interface.
734
Jan4af521d2016-11-15 17:05:00 +0100735 :param int rx_sw_if_index: Software interface index of Rx interface.
736 :param int tx_sw_if_index: Software interface index of Tx interface.
737 :param int enable: Create cross-connect if equal to 1, delete
738 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200739
740 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100741 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200742 {'rx_sw_if_index': rx_sw_if_index,
743 'tx_sw_if_index': tx_sw_if_index,
744 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200745
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200746 def sw_interface_set_l2_tag_rewrite(
747 self,
748 sw_if_index,
749 vtr_oper,
750 push=0,
751 tag1=0,
752 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000753 """L2 interface vlan tag rewrite configure request
754 :param client_index - opaque cookie to identify the sender
755 :param context - sender context, to match reply w/ request
756 :param sw_if_index - interface the operation is applied to
757 :param vtr_op - Choose from l2_vtr_op_t enum values
758 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
759 :param tag1 - Needed for any push or translate vtr op
760 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
761
762 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100763 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200764 {'sw_if_index': sw_if_index,
765 'vtr_op': vtr_oper,
766 'push_dot1q': push,
767 'tag1': tag1,
768 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000769
Neale Ranns55d03782017-10-21 06:34:22 -0700770 def sw_interface_set_l2_emulation(
771 self,
772 sw_if_index,
773 enable=1):
774 """L2 Emulation
775 :param sw_if_index - interface the operation is applied to
776
777 """
778 return self.api(self.papi.l2_emulation,
779 {'sw_if_index': sw_if_index,
780 'enable': enable})
781
Neale Ranns1855b8e2018-07-11 10:31:26 -0700782 def sw_interface_set_ip_directed_broadcast(
783 self,
784 sw_if_index,
785 enable=1):
786 """IP Directed broadcast
787 :param sw_if_index - interface the operation is applied to
788
789 """
790 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
791 {'sw_if_index': sw_if_index,
792 'enable': enable})
793
Neale Rannsa07bd702017-08-07 07:53:49 -0700794 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200795 """
796
797 :param admin_up_down:
798 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200799
800 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100801 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200802 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700803 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200804
Ole Troand7231612018-06-07 10:17:57 +0200805 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800806 """
807 :param sw_if_index:
808 :param mtu:
809
810 """
811 return self.api(self.papi.sw_interface_set_mtu,
812 {'sw_if_index': sw_if_index,
813 'mtu': mtu})
814
Neale Ranns25b04942018-04-04 09:34:50 -0700815 def sw_interface_set_promiscuous(self, sw_if_index, enable):
816 """
817 :param sw_if_index:
818 :param enable:
819
820 """
821 return self.api(self.papi.sw_interface_set_promiscuous,
822 {'sw_if_index': sw_if_index,
823 'enable': enable})
824
Neale Rannsc819fc62018-02-16 02:44:05 -0800825 def sw_interface_set_mac_address(self, sw_if_index, mac):
826 return self.api(self.papi.sw_interface_set_mac_address,
827 {'sw_if_index': sw_if_index,
828 'mac_address': mac})
829
Klement Sekeraf62ae122016-10-11 11:47:09 +0200830 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
831 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
832 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
833 """Create subinterface
834 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
835
836 :param sub_id: param inner_vlan:
837 :param sw_if_index:
838 :param outer_vlan:
839 :param inner_vlan:
840 :param no_tags: (Default value = 0)
841 :param one_tag: (Default value = 0)
842 :param two_tags: (Default value = 0)
843 :param dot1ad: (Default value = 0)
844 :param exact_match: (Default value = 0)
845 :param default_sub: (Default value = 0)
846 :param outer_vlan_id_any: (Default value = 0)
847 :param inner_vlan_id_any: (Default value = 0)
848
849 """
850 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100851 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200852 {'sw_if_index': sw_if_index,
853 'sub_id': sub_id,
854 'no_tags': no_tags,
855 'one_tag': one_tag,
856 'two_tags': two_tags,
857 'dot1ad': dot1ad,
858 'exact_match': exact_match,
859 'default_sub': default_sub,
860 'outer_vlan_id_any': outer_vlan_id_any,
861 'inner_vlan_id_any': inner_vlan_id_any,
862 'outer_vlan_id': outer_vlan,
863 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200864
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200865 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
866 """Create p2p ethernet subinterface
867
868 :param sw_if_index: main (parent) interface
869 :param remote_mac: client (remote) mac address
870
871 """
872 return self.api(
873 self.papi.p2p_ethernet_add,
874 {'parent_if_index': sw_if_index,
875 'remote_mac': remote_mac,
876 'subif_id': subif_id})
877
Neale Ranns177bbdc2016-11-15 09:46:51 +0000878 def delete_subif(self, sw_if_index):
879 """Delete subinterface
880
881 :param sw_if_index:
882 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100883 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200884 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000885
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200886 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
887 """Delete p2p ethernet subinterface
888
889 :param sw_if_index: main (parent) interface
890 :param remote_mac: client (remote) mac address
891
892 """
893 return self.api(
894 self.papi.p2p_ethernet_del,
895 {'parent_if_index': sw_if_index,
896 'remote_mac': remote_mac})
897
Klement Sekeraf62ae122016-10-11 11:47:09 +0200898 def create_vlan_subif(self, sw_if_index, vlan):
899 """
900
901 :param vlan:
902 :param sw_if_index:
903
904 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100905 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200906 {'sw_if_index': sw_if_index,
907 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200908
Matej Klotton0178d522016-11-04 11:11:44 +0100909 def create_loopback(self, mac=''):
910 """
911
912 :param mac: (Optional)
913 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100914 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200915 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100916
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100917 def delete_loopback(self, sw_if_index):
918 return self.api(self.papi.delete_loopback,
919 {'sw_if_index': sw_if_index, })
920
Neale Ranns15002542017-09-10 04:39:11 -0700921 def ip_table_add_del(self,
922 table_id,
923 is_add=1,
924 is_ipv6=0):
925 """
926
927 :param table_id
928 :param is_add: (Default value = 1)
929 :param is_ipv6: (Default value = 0)
930
931 """
932
933 return self.api(
934 self.papi.ip_table_add_del,
935 {'table_id': table_id,
936 'is_add': is_add,
937 'is_ipv6': is_ipv6})
938
Klement Sekeraf62ae122016-10-11 11:47:09 +0200939 def ip_add_del_route(
940 self,
941 dst_address,
942 dst_address_length,
943 next_hop_address,
944 next_hop_sw_if_index=0xFFFFFFFF,
945 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200946 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000947 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200948 next_hop_n_out_labels=0,
949 next_hop_out_label_stack=[],
950 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800951 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000952 is_resolve_host=0,
953 is_resolve_attached=0,
954 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200955 is_add=1,
956 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200957 is_unreach=0,
958 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200959 is_ipv6=0,
960 is_local=0,
961 is_classify=0,
962 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800963 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800964 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200965 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200966 """
967
968 :param dst_address_length:
969 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
970 :param dst_address:
971 :param next_hop_address:
972 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
973 :param vrf_id: (Default value = 0)
974 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200975 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200976 :param is_add: (Default value = 1)
977 :param is_drop: (Default value = 0)
978 :param is_ipv6: (Default value = 0)
979 :param is_local: (Default value = 0)
980 :param is_classify: (Default value = 0)
981 :param is_multipath: (Default value = 0)
982 :param is_resolve_host: (Default value = 0)
983 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800984 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700985 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200986 :param next_hop_weight: (Default value = 1)
987
988 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000989
Klement Sekeraf62ae122016-10-11 11:47:09 +0200990 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100991 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 {'next_hop_sw_if_index': next_hop_sw_if_index,
993 'table_id': table_id,
994 'classify_table_index': classify_table_index,
995 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 'is_add': is_add,
997 'is_drop': is_drop,
998 'is_unreach': is_unreach,
999 'is_prohibit': is_prohibit,
1000 'is_ipv6': is_ipv6,
1001 'is_local': is_local,
1002 'is_classify': is_classify,
1003 'is_multipath': is_multipath,
1004 'is_resolve_host': is_resolve_host,
1005 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -08001006 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -07001007 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -08001008 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001009 'next_hop_weight': next_hop_weight,
1010 'dst_address_length': dst_address_length,
1011 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -08001012 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001013 'next_hop_address': next_hop_address,
1014 'next_hop_n_out_labels': next_hop_n_out_labels,
1015 'next_hop_via_label': next_hop_via_label,
1016 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001017
Matej Klotton16a14cd2016-12-07 15:09:13 +01001018 def ip_fib_dump(self):
1019 return self.api(self.papi.ip_fib_dump, {})
1020
Jan Gelety057bb8c2016-12-20 17:32:45 +01001021 def ip6_fib_dump(self):
1022 return self.api(self.papi.ip6_fib_dump, {})
1023
Matej Klotton0178d522016-11-04 11:11:44 +01001024 def ip_neighbor_add_del(self,
1025 sw_if_index,
1026 mac_address,
1027 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001028 is_add=1,
1029 is_ipv6=0,
1030 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001031 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +01001032 ):
1033 """ Add neighbor MAC to IPv4 or IPv6 address.
1034
1035 :param sw_if_index:
1036 :param mac_address:
1037 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001038 :param is_add: (Default value = 1)
1039 :param is_ipv6: (Default value = 0)
1040 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001041 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001042 """
1043
1044 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001045 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001046 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001047 'is_add': is_add,
1048 'is_ipv6': is_ipv6,
1049 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001050 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001051 'mac_address': mac_address,
1052 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001053 }
Matej Klotton0178d522016-11-04 11:11:44 +01001054 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001055
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001056 def ip_neighbor_dump(self,
1057 sw_if_index,
1058 is_ipv6=0):
1059 """ Return IP neighbor dump.
1060
1061 :param sw_if_index:
1062 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1063 """
1064
1065 return self.api(
1066 self.papi.ip_neighbor_dump,
1067 {'is_ipv6': is_ipv6,
1068 'sw_if_index': sw_if_index
1069 }
1070 )
1071
1072 def proxy_arp_add_del(self,
1073 low_address,
1074 hi_address,
1075 vrf_id=0,
1076 is_add=1):
1077 """ Config Proxy Arp Range.
1078
1079 :param low_address: Start address in the rnage to Proxy for
1080 :param hi_address: End address in the rnage to Proxy for
1081 :param vrf_id: The VRF/table in which to proxy
1082 """
1083
1084 return self.api(
1085 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001086 {'proxy':
1087 {
1088 'vrf_id': vrf_id,
1089 'low_address': low_address,
1090 'hi_address': hi_address,
1091 },
1092 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001093
1094 def proxy_arp_intfc_enable_disable(self,
1095 sw_if_index,
1096 is_enable=1):
1097 """ Enable/Disable an interface for proxy ARP requests
1098
1099 :param sw_if_index: Interface
1100 :param enable_disable: Enable/Disable
1101 """
1102
1103 return self.api(
1104 self.papi.proxy_arp_intfc_enable_disable,
1105 {'sw_if_index': sw_if_index,
1106 'enable_disable': is_enable
1107 }
1108 )
1109
Jane546d3b2016-12-08 13:10:03 +01001110 def reset_vrf(self,
1111 vrf_id,
1112 is_ipv6=0,
1113 ):
1114 """ Reset VRF (remove all routes etc.) request.
1115
1116 :param int vrf_id: ID of the FIB table / VRF to reset.
1117 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1118 """
1119
1120 return self.api(
1121 self.papi.reset_vrf,
1122 {'vrf_id': vrf_id,
1123 'is_ipv6': is_ipv6,
1124 }
1125 )
1126
1127 def reset_fib(self,
1128 vrf_id,
1129 is_ipv6=0,
1130 ):
1131 """ Reset VRF (remove all routes etc.) request.
1132
1133 :param int vrf_id: ID of the FIB table / VRF to reset.
1134 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1135 """
1136
1137 return self.api(
1138 self.papi.reset_fib,
1139 {'vrf_id': vrf_id,
1140 'is_ipv6': is_ipv6,
1141 }
1142 )
1143
1144 def ip_dump(self,
1145 is_ipv6=0,
1146 ):
1147 """ Return IP dump.
1148
1149 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1150 """
1151
1152 return self.api(
1153 self.papi.ip_dump,
1154 {'is_ipv6': is_ipv6,
1155 }
1156 )
1157
Klement Sekera7bb873a2016-11-18 07:38:42 +01001158 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001159 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001160 """
1161
1162 :param sw_if_index_from:
1163 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001164 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001165 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001166 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001167 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001168 {'sw_if_index_from': sw_if_index_from,
1169 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001170 'state': state,
1171 'is_l2': is_l2,
1172 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001173
1174 def gre_tunnel_add_del(self,
1175 src_address,
1176 dst_address,
1177 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001178 tunnel_type=0,
1179 instance=0xFFFFFFFF,
1180 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001181 is_add=1,
1182 is_ip6=0):
1183 """ Add a GRE tunnel
1184
1185 :param src_address:
1186 :param dst_address:
1187 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001188 :param tunnel_type: (Default value = 0)
1189 :param instance: (Default value = 0xFFFFFFFF)
1190 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001191 :param is_add: (Default value = 1)
1192 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001193 """
1194
1195 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001196 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001197 {'is_add': is_add,
1198 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001199 'tunnel_type': tunnel_type,
1200 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001201 'src_address': src_address,
1202 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001203 'outer_fib_id': outer_fib_id,
1204 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001205 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001206
Neale Rannsd0df49f2018-08-08 01:06:40 -07001207 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001208 src_ip,
1209 dst_ip,
1210 src_port,
1211 dst_port,
1212 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001213 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001214 :param src_ip:
1215 :param dst_ip:
1216 :param src_port:
1217 :param dst_port:
1218 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001219 """
1220
1221 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001222 self.papi.udp_encap_add,
1223 {
1224 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001225 'src_ip': src_ip,
1226 'dst_ip': dst_ip,
1227 'src_port': src_port,
1228 'dst_port': dst_port,
1229 'table_id': table_id
1230 }
1231 })
1232
1233 def udp_encap_del(self, id):
1234 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001235
1236 def udp_encap_dump(self):
1237 return self.api(self.papi.udp_encap_dump, {})
1238
Neale Ranns43b1f442018-03-20 01:47:35 -07001239 def want_udp_encap_stats(self, enable=1):
1240 return self.api(self.papi.want_udp_encap_stats,
1241 {'enable': enable,
1242 'pid': os.getpid()})
1243
Neale Ranns5a8123b2017-01-26 01:18:23 -08001244 def mpls_fib_dump(self):
1245 return self.api(self.papi.mpls_fib_dump, {})
1246
Neale Ranns15002542017-09-10 04:39:11 -07001247 def mpls_table_add_del(
1248 self,
1249 table_id,
1250 is_add=1):
1251 """
1252
1253 :param table_id
1254 :param is_add: (Default value = 1)
1255
1256 """
1257
1258 return self.api(
1259 self.papi.mpls_table_add_del,
1260 {'mt_table_id': table_id,
1261 'mt_is_add': is_add})
1262
Neale Rannsad422ed2016-11-02 14:20:04 +00001263 def mpls_route_add_del(
1264 self,
1265 label,
1266 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001267 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001268 next_hop_address,
1269 next_hop_sw_if_index=0xFFFFFFFF,
1270 table_id=0,
1271 next_hop_table_id=0,
1272 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001273 next_hop_n_out_labels=0,
1274 next_hop_out_label_stack=[],
1275 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001276 is_resolve_host=0,
1277 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001278 is_interface_rx=0,
1279 is_rpf_id=0,
1280 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001281 is_add=1,
1282 is_drop=0,
1283 is_multipath=0,
1284 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001285 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001286 """
1287
1288 :param dst_address_length:
1289 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1290 :param dst_address:
1291 :param next_hop_address:
1292 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1293 :param vrf_id: (Default value = 0)
1294 :param lookup_in_vrf: (Default value = 0)
1295 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001296 :param is_add: (Default value = 1)
1297 :param is_drop: (Default value = 0)
1298 :param is_ipv6: (Default value = 0)
1299 :param is_local: (Default value = 0)
1300 :param is_classify: (Default value = 0)
1301 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001302 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001303 :param is_resolve_host: (Default value = 0)
1304 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001305 :param next_hop_weight: (Default value = 1)
1306
1307 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001308 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001309 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001310 {'mr_label': label,
1311 'mr_eos': eos,
1312 'mr_table_id': table_id,
1313 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001314 'mr_is_add': is_add,
1315 'mr_is_classify': is_classify,
1316 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001317 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001318 'mr_is_resolve_host': is_resolve_host,
1319 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001320 'mr_is_interface_rx': is_interface_rx,
1321 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001322 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001323 'mr_next_hop_weight': next_hop_weight,
1324 'mr_next_hop': next_hop_address,
1325 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1326 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1327 'mr_next_hop_table_id': next_hop_table_id,
1328 'mr_next_hop_via_label': next_hop_via_label,
1329 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001330
1331 def mpls_ip_bind_unbind(
1332 self,
1333 label,
1334 dst_address,
1335 dst_address_length,
1336 table_id=0,
1337 ip_table_id=0,
1338 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001339 is_bind=1):
1340 """
1341 """
1342 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001343 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001344 {'mb_mpls_table_id': table_id,
1345 'mb_label': label,
1346 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001347 'mb_is_bind': is_bind,
1348 'mb_is_ip4': is_ip4,
1349 'mb_address_length': dst_address_length,
1350 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001351
1352 def mpls_tunnel_add_del(
1353 self,
1354 tun_sw_if_index,
1355 next_hop_proto_is_ip4,
1356 next_hop_address,
1357 next_hop_sw_if_index=0xFFFFFFFF,
1358 next_hop_table_id=0,
1359 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001360 next_hop_n_out_labels=0,
1361 next_hop_out_label_stack=[],
1362 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001363 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001364 l2_only=0,
1365 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001366 """
1367
1368 :param dst_address_length:
1369 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1370 :param dst_address:
1371 :param next_hop_address:
1372 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1373 :param vrf_id: (Default value = 0)
1374 :param lookup_in_vrf: (Default value = 0)
1375 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001376 :param is_add: (Default value = 1)
1377 :param is_drop: (Default value = 0)
1378 :param is_ipv6: (Default value = 0)
1379 :param is_local: (Default value = 0)
1380 :param is_classify: (Default value = 0)
1381 :param is_multipath: (Default value = 0)
1382 :param is_resolve_host: (Default value = 0)
1383 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001384 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001385 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001386
1387 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001388 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001389 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001390 {'mt_sw_if_index': tun_sw_if_index,
1391 'mt_is_add': is_add,
1392 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001393 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001394 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1395 'mt_next_hop_weight': next_hop_weight,
1396 'mt_next_hop': next_hop_address,
1397 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1398 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1399 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001400 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001401 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001402
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001403 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1404 return self.api(self.papi.mpls_tunnel_dump,
1405 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001406
Matus Fabian2ba92e32017-08-21 07:05:03 -07001407 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001408 self,
1409 sw_if_index,
1410 is_inside=1,
1411 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001412 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001413
1414 :param sw_if_index: Software index of the interface
1415 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1416 :param is_add: 1 if add, 0 if delete (Default value = 1)
1417 """
1418 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001419 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001420 {'is_add': is_add,
1421 'is_inside': is_inside,
1422 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001423
Matus Fabian2ba92e32017-08-21 07:05:03 -07001424 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001425 self,
1426 sw_if_index,
1427 is_inside=1,
1428 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001429 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001430
1431 :param sw_if_index: Software index of the interface
1432 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1433 :param is_add: 1 if add, 0 if delete (Default value = 1)
1434 """
1435 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001436 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001437 {'is_add': is_add,
1438 'is_inside': is_inside,
1439 'sw_if_index': sw_if_index})
1440
Matus Fabian2ba92e32017-08-21 07:05:03 -07001441 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001442 self,
1443 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001444 external_ip=0,
1445 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001446 local_port=0,
1447 external_port=0,
1448 addr_only=1,
1449 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001450 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001451 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001452 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001453 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001454 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001455 is_add=1):
1456 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001457
1458 :param local_ip: Local IP address
1459 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001460 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001461 :param local_port: Local port number (Default value = 0)
1462 :param external_port: External port number (Default value = 0)
1463 :param addr_only: 1 if address only mapping, 0 if address and port
1464 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001465 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001466 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001467 :param self_twice_nat: 1 if translate external host address and port
1468 whenever external host address equals
1469 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001470 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001471 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001472 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001473 """
1474 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001475 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001476 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001477 'addr_only': addr_only,
1478 'local_ip_address': local_ip,
1479 'external_ip_address': external_ip,
1480 'local_port': local_port,
1481 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001482 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001483 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001484 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001485 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001486 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001487 'out2in_only': out2in_only,
1488 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001489
Matus Fabianab7a8052017-11-28 04:29:41 -08001490 def nat44_add_del_identity_mapping(
1491 self,
1492 ip='0',
1493 sw_if_index=0xFFFFFFFF,
1494 port=0,
1495 addr_only=1,
1496 vrf_id=0,
1497 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001498 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001499 is_add=1):
1500 """Add/delete NAT44 identity mapping
1501
1502 :param ip: IP address (Default value = 0)
1503 :param sw_if_index: Interface instead of IP address
1504 :param port: Port number (Default value = 0)
1505 :param addr_only: 1 if address only mapping, 0 if address and port
1506 :param vrf_id: VRF ID
1507 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001508 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001509 :param is_add: 1 if add, 0 if delete (Default value = 1)
1510 """
1511 return self.api(
1512 self.papi.nat44_add_del_identity_mapping,
1513 {'is_add': is_add,
1514 'addr_only': addr_only,
1515 'ip_address': ip,
1516 'port': port,
1517 'sw_if_index': sw_if_index,
1518 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001519 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001520 'protocol': protocol})
1521
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001523 self,
1524 first_ip_address,
1525 last_ip_address,
1526 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001527 vrf_id=0xFFFFFFFF,
1528 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001529 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001530
1531 :param first_ip_address: First IP address
1532 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001533 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001534 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001535 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001536 """
1537 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001538 self.papi.nat44_add_del_address_range,
1539 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001540 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001541 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001542 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001543 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001544
Matus Fabian2ba92e32017-08-21 07:05:03 -07001545 def nat44_address_dump(self):
1546 """Dump NAT44 addresses
1547 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001548 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001549 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001550
Matus Fabian2ba92e32017-08-21 07:05:03 -07001551 def nat44_interface_dump(self):
1552 """Dump interfaces with NAT44 feature
1553 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001554 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001555 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001556
Matus Fabian2ba92e32017-08-21 07:05:03 -07001557 def nat44_interface_output_feature_dump(self):
1558 """Dump interfaces with NAT44 output feature
1559 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001560 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001561 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001562
Matus Fabian2ba92e32017-08-21 07:05:03 -07001563 def nat44_static_mapping_dump(self):
1564 """Dump NAT44 static mappings
1565 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001566 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001567 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001568
Matus Fabianab7a8052017-11-28 04:29:41 -08001569 def nat44_identity_mapping_dump(self):
1570 """Dump NAT44 identity mappings
1571 :return: Dictionary of NAT44 identity mappings
1572 """
1573 return self.api(self.papi.nat44_identity_mapping_dump, {})
1574
Matus Fabian2ba92e32017-08-21 07:05:03 -07001575 def nat_show_config(self):
1576 """Show NAT plugin config
1577 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001578 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001580
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001582 self,
1583 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001584 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001585 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001586 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001587
1588 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001589 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001590 :param is_add: 1 if add, 0 if delete (Default value = 1)
1591 """
Matus Fabianb932d262017-12-18 05:38:24 -08001592 return self.api(
1593 self.papi.nat44_add_del_interface_addr,
1594 {'is_add': is_add,
1595 'sw_if_index': sw_if_index,
1596 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001597
Matus Fabian2ba92e32017-08-21 07:05:03 -07001598 def nat44_interface_addr_dump(self):
1599 """Dump NAT44 addresses interfaces
1600 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001601 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001602 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001603
Matus Fabian2ba92e32017-08-21 07:05:03 -07001604 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001605 self,
1606 domain_id=1,
1607 src_port=4739,
1608 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001609 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001610
1611 :param domain_id: Observation domain ID (Default value = 1)
1612 :param src_port: Source port number (Default value = 4739)
1613 :param enable: 1 if enable, 0 if disable (Default value = 1)
1614 """
1615 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001616 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001617 {'domain_id': domain_id,
1618 'src_port': src_port,
1619 'enable': enable})
1620
Matus Fabian2ba92e32017-08-21 07:05:03 -07001621 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001622 self,
1623 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001624 vrf_id):
1625 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001626
1627 :param ip_address: ip adress of the user to be dumped
1628 :param cpu_index: cpu_index on which the user is
1629 :param vrf_id: VRF ID
1630 :return: Dictionary of S-NAT sessions
1631 """
1632 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001633 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001634 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001635 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001636
Matus Fabian2ba92e32017-08-21 07:05:03 -07001637 def nat44_user_dump(self):
1638 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001639
Matus Fabian2ba92e32017-08-21 07:05:03 -07001640 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001641 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001642 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001643
Matus Fabian704018c2017-09-04 02:17:18 -07001644 def nat44_add_del_lb_static_mapping(
1645 self,
1646 external_addr,
1647 external_port,
1648 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001649 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001650 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001651 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001652 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001653 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001654 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001655 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001656 is_add=1):
1657 """Add/delete NAT44 load balancing static mapping
1658
Matus Fabianb932d262017-12-18 05:38:24 -08001659 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001660 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001661 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001662 :param is_add - 1 if add, 0 if delete
1663 """
1664 return self.api(
1665 self.papi.nat44_add_del_lb_static_mapping,
1666 {'is_add': is_add,
1667 'external_addr': external_addr,
1668 'external_port': external_port,
1669 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001670 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001671 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001672 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001673 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001674 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001675 'local_num': local_num,
1676 'locals': locals})
1677
1678 def nat44_lb_static_mapping_dump(self):
1679 """Dump NAT44 load balancing static mappings
1680
1681 :return: Dictionary of NAT44 load balancing static mapping
1682 """
1683 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1684
Matus Fabian5ba86f72017-10-26 03:37:38 -07001685 def nat44_del_session(
1686 self,
1687 addr,
1688 port,
1689 protocol,
1690 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001691 is_in=1,
1692 ext_host_address=None,
1693 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001694 """Delete NAT44 session
1695
1696 :param addr: IPv4 address
1697 :param por: port number
1698 :param protocol: IP protocol number
1699 :param vrf_id: VRF ID
1700 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001701 :param ext_host_address: external host IPv4 address
1702 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001703 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001704 if ext_host_address is None:
1705 return self.api(
1706 self.papi.nat44_del_session,
1707 {'address': addr,
1708 'port': port,
1709 'protocol': protocol,
1710 'vrf_id': vrf_id,
1711 'is_in': is_in})
1712 else:
1713 return self.api(
1714 self.papi.nat44_del_session,
1715 {'address': addr,
1716 'port': port,
1717 'protocol': protocol,
1718 'vrf_id': vrf_id,
1719 'is_in': is_in,
1720 'ext_host_valid': 1,
1721 'ext_host_address': ext_host_address,
1722 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001723
Juraj Sloboda7b929792017-11-23 13:20:48 +01001724 def nat44_forwarding_enable_disable(
1725 self,
1726 enable):
1727 """Enable/disable forwarding for NAT44
1728
1729 :param enable: 1 for enable, 0 for disable
1730 """
1731 return self.api(
1732 self.papi.nat44_forwarding_enable_disable,
1733 {'enable': enable})
1734
Matus Fabianefcd1e92017-08-15 06:59:19 -07001735 def nat_set_reass(
1736 self,
1737 timeout=2,
1738 max_reass=1024,
1739 max_frag=5,
1740 drop_frag=0,
1741 is_ip6=0):
1742 """Set NAT virtual fragmentation reassembly
1743
1744 :param timeout: reassembly timeout (Default 2sec)
1745 :param max_reass: maximum concurrent reassemblies (Default 1024)
1746 :param max_frag: maximum fragmets per reassembly (Default 5)
1747 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1748 :param is_ip6: 1 if IPv6, 0 if IPv4
1749 """
1750 return self.api(
1751 self.papi.nat_set_reass,
1752 {'timeout': timeout,
1753 'max_reass': max_reass,
1754 'max_frag': max_frag,
1755 'drop_frag': drop_frag,
1756 'is_ip6': is_ip6})
1757
1758 def nat_get_reass(self):
1759 """Get NAT virtual fragmentation reassembly configuration
1760
1761 :return: NAT virtual fragmentation reassembly configuration
1762 """
1763 return self.api(self.papi.nat_get_reass, {})
1764
1765 def nat_reass_dump(self):
1766 """Dump NAT virtual fragmentation reassemblies
1767
1768 :return: Dictionary of NAT virtual fragmentation reassemblies
1769 """
1770 return self.api(self.papi.nat_reass_dump, {})
1771
Matus Fabian2ba92e32017-08-21 07:05:03 -07001772 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001773 self,
1774 in_addr,
1775 in_plen,
1776 out_addr,
1777 out_plen,
1778 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001779 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001780
1781 :param is_add - 1 if add, 0 if delete
1782 :param in_addr - inside IP address
1783 :param in_plen - inside IP address prefix length
1784 :param out_addr - outside IP address
1785 :param out_plen - outside IP address prefix length
1786 """
1787 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001788 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001789 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001790 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001791 'in_addr': in_addr,
1792 'in_plen': in_plen,
1793 'out_addr': out_addr,
1794 'out_plen': out_plen})
1795
Matus Fabian2ba92e32017-08-21 07:05:03 -07001796 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001797 self,
1798 in_addr):
1799 """Get outside address and port range from inside address
1800
1801 :param in_addr - inside IP address
1802 """
1803 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001804 self.papi.nat_det_forward,
1805 {'in_addr': in_addr,
1806 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001807
Matus Fabian2ba92e32017-08-21 07:05:03 -07001808 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001809 self,
1810 out_addr,
1811 out_port):
1812 """Get inside address from outside address and port
1813
1814 :param out_addr - outside IP address
1815 :param out_port - outside port
1816 """
1817 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001818 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001819 {'out_addr': out_addr,
1820 'out_port': out_port})
1821
Matus Fabian2ba92e32017-08-21 07:05:03 -07001822 def nat_det_map_dump(self):
1823 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001824
Matus Fabian2ba92e32017-08-21 07:05:03 -07001825 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001826 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001827 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001828
Matus Fabian878c6462018-08-23 00:33:35 -07001829 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001830 self,
1831 udp=300,
1832 tcp_established=7440,
1833 tcp_transitory=240,
1834 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001835 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001836
1837 :param udp - UDP timeout (Default value = 300)
1838 :param tcp_established - TCP established timeout (Default value = 7440)
1839 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1840 :param icmp - ICMP timeout (Default value = 60)
1841 """
1842 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001843 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001844 {'udp': udp,
1845 'tcp_established': tcp_established,
1846 'tcp_transitory': tcp_transitory,
1847 'icmp': icmp})
1848
Matus Fabian878c6462018-08-23 00:33:35 -07001849 def nat_get_timeouts(self):
1850 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001851
Matus Fabian878c6462018-08-23 00:33:35 -07001852 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001853 """
Matus Fabian878c6462018-08-23 00:33:35 -07001854 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001855
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001856 def nat_set_addr_and_port_alloc_alg(
1857 self,
1858 alg=0,
1859 psid_offset=0,
1860 psid_length=0,
1861 psid=0,
1862 start_port=0,
1863 end_port=0):
1864 """Set address and port assignment algorithm
1865
1866 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1867 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1868 :param psid_length: length of PSID (valid only for MAP-E alg)
1869 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1870 :param start_port: beginning of the port range
1871 :param end_port: end of the port range
1872 """
1873 return self.api(
1874 self.papi.nat_set_addr_and_port_alloc_alg,
1875 {'alg': alg,
1876 'psid_offset': psid_offset,
1877 'psid_length': psid_length,
1878 'psid': psid,
1879 'start_port': start_port,
1880 'end_port': end_port})
1881
1882 def nat_get_addr_and_port_alloc_alg(self):
1883 """Get address and port assignment algorithm"""
1884 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1885
Matus Fabianbb4e0222018-09-13 02:36:25 -07001886 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1887 """Set TCP MSS rewriting configuration
1888
1889 :param enable: disable(0)/enable(1) MSS rewriting feature
1890 :param mss_value: MSS value to be used for MSS rewriting
1891 """
1892 return self.api(
1893 self.papi.nat_set_mss_clamping,
1894 {'enable': enable, 'mss_value': mss_value})
1895
1896 def nat_get_mss_clamping(self):
1897 """Get TCP MSS rewriting configuration"""
1898 return self.api(self.papi.nat_get_mss_clamping, {})
1899
Matus Fabian2ba92e32017-08-21 07:05:03 -07001900 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001901 self,
1902 out_addr,
1903 out_port,
1904 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001905 ext_port):
1906 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001907
1908 :param out_addr - outside IP address
1909 :param out_port - outside port
1910 :param ext_addr - external host IP address
1911 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001912 """
1913 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001914 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001915 {'out_addr': out_addr,
1916 'out_port': out_port,
1917 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001918 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001919
Matus Fabian2ba92e32017-08-21 07:05:03 -07001920 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001921 self,
1922 in_addr,
1923 in_port,
1924 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001925 ext_port):
1926 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001927
1928 :param in_addr - inside IP address
1929 :param in_port - inside port
1930 :param ext_addr - external host IP address
1931 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001932 """
1933 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001934 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001935 {'in_addr': in_addr,
1936 'in_port': in_port,
1937 'ext_addr': ext_addr,
1938 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001939 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001940
Matus Fabian2ba92e32017-08-21 07:05:03 -07001941 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001942 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001943 user_addr):
1944 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001945
1946 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001947 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001948 """
1949 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001950 self.papi.nat_det_session_dump,
1951 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001952 'user_addr': user_addr})
1953
Matus Fabian06596c52017-06-06 04:53:28 -07001954 def nat64_add_del_pool_addr_range(
1955 self,
1956 start_addr,
1957 end_addr,
1958 vrf_id=0xFFFFFFFF,
1959 is_add=1):
1960 """Add/del address range to NAT64 pool
1961
1962 :param start_addr: First IP address
1963 :param end_addr: Last IP address
1964 :param vrf_id: VRF id for the address range
1965 :param is_add: 1 if add, 0 if delete (Default value = 1)
1966 """
1967 return self.api(
1968 self.papi.nat64_add_del_pool_addr_range,
1969 {'start_addr': start_addr,
1970 'end_addr': end_addr,
1971 'vrf_id': vrf_id,
1972 'is_add': is_add})
1973
1974 def nat64_pool_addr_dump(self):
1975 """Dump NAT64 pool addresses
1976 :return: Dictionary of NAT64 pool addresses
1977 """
1978 return self.api(self.papi.nat64_pool_addr_dump, {})
1979
1980 def nat64_add_del_interface(
1981 self,
1982 sw_if_index,
1983 is_inside=1,
1984 is_add=1):
1985 """Enable/disable NAT64 feature on the interface
1986 :param sw_if_index: Index of the interface
1987 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1988 :param is_add: 1 if add, 0 if delete (Default value = 1)
1989 """
1990 return self.api(
1991 self.papi.nat64_add_del_interface,
1992 {'sw_if_index': sw_if_index,
1993 'is_inside': is_inside,
1994 'is_add': is_add})
1995
1996 def nat64_interface_dump(self):
1997 """Dump interfaces with NAT64 feature
1998 :return: Dictionary of interfaces with NAT64 feature
1999 """
2000 return self.api(self.papi.nat64_interface_dump, {})
2001
2002 def nat64_add_del_static_bib(
2003 self,
2004 in_ip,
2005 out_ip,
2006 in_port,
2007 out_port,
2008 protocol,
2009 vrf_id=0,
2010 is_add=1):
2011 """Add/delete S-NAT static BIB entry
2012
2013 :param in_ip: Inside IPv6 address
2014 :param out_ip: Outside IPv4 address
2015 :param in_port: Inside port number
2016 :param out_port: Outside port number
2017 :param protocol: IP protocol
2018 :param vrf_id: VRF ID (Default value = 0)
2019 :param is_add: 1 if add, 0 if delete (Default value = 1)
2020 """
2021 return self.api(
2022 self.papi.nat64_add_del_static_bib,
2023 {'i_addr': in_ip,
2024 'o_addr': out_ip,
2025 'i_port': in_port,
2026 'o_port': out_port,
2027 'vrf_id': vrf_id,
2028 'proto': protocol,
2029 'is_add': is_add})
2030
Matus Fabianab9a59c2017-08-16 05:37:36 -07002031 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002032 """Dump NAT64 BIB
2033
Matus Fabianab9a59c2017-08-16 05:37:36 -07002034 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002035 :returns: Dictionary of NAT64 BIB entries
2036 """
2037 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2038
2039 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2040 tcp_incoming_syn=6):
2041 """Set values of timeouts for NAT64 (in seconds)
2042
Matus Fabian428dc912017-06-21 06:15:18 -07002043 :param udpi: UDP timeout (Default value = 300)
2044 :param icmp: ICMP timeout (Default value = 60)
2045 :param tcp_trans: TCP transitory timeout (Default value = 240)
2046 :param tcp_est: TCP established timeout (Default value = 7440)
2047 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002048 """
2049 return self.api(
2050 self.papi.nat64_set_timeouts,
2051 {'udp': udp,
2052 'icmp': icmp,
2053 'tcp_trans': tcp_trans,
2054 'tcp_est': tcp_est,
2055 'tcp_incoming_syn': tcp_incoming_syn})
2056
2057 def nat64_get_timeouts(self):
2058 """Get values of timeouts for NAT64
2059
2060 :return: Timeouts for NAT64 (in seconds)
2061 """
2062 return self.api(self.papi.nat64_get_timeouts, {})
2063
Matus Fabianab9a59c2017-08-16 05:37:36 -07002064 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002065 """Dump NAT64 session table
2066
Matus Fabianab9a59c2017-08-16 05:37:36 -07002067 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002068 :returns: Dictionary of NAT64 sesstion table entries
2069 """
2070 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2071
Matus Fabian428dc912017-06-21 06:15:18 -07002072 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2073 """Add/del NAT64 prefix
2074
2075 :param prefix: NAT64 prefix
2076 :param plen: NAT64 prefix length
2077 :param vrf_id: VRF id of tenant (Default 0)
2078 :param is_add: 1 if add, 0 if delete (Default value = 1)
2079 """
2080 return self.api(
2081 self.papi.nat64_add_del_prefix,
2082 {'prefix': prefix,
2083 'prefix_len': plen,
2084 'vrf_id': vrf_id,
2085 'is_add': is_add})
2086
2087 def nat64_prefix_dump(self):
2088 """Dump NAT64 prefix
2089
2090 :returns: Dictionary of NAT64 prefixes
2091 """
2092 return self.api(self.papi.nat64_prefix_dump, {})
2093
Matus Fabian0938dcf2017-11-08 01:59:38 -08002094 def nat64_add_interface_addr(
2095 self,
2096 sw_if_index,
2097 is_add=1):
2098 """Add/del NAT64 address from interface
2099
2100 :param sw_if_index: Software index of the interface
2101 :param is_add: 1 if add, 0 if delete (Default value = 1)
2102 """
2103 return self.api(self.papi.nat64_add_del_interface_addr,
2104 {'is_add': is_add, 'sw_if_index': sw_if_index})
2105
Matus Fabian8ebe6252017-11-06 05:04:53 -08002106 def dslite_set_aftr_addr(self, ip6, ip4):
2107 """Set DS-Lite AFTR addresses
2108
2109 :param ip4: IPv4 address
2110 :param ip6: IPv6 address
2111 """
2112 return self.api(
2113 self.papi.dslite_set_aftr_addr,
2114 {'ip4_addr': ip4,
2115 'ip6_addr': ip6})
2116
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002117 def dslite_set_b4_addr(self, ip6, ip4):
2118 """Set DS-Lite B4 IPv6 address
2119
2120 :param ip4: IPv4 address
2121 :param ip6: IPv6 address
2122 """
2123 return self.api(
2124 self.papi.dslite_set_b4_addr,
2125 {'ip4_addr': ip4,
2126 'ip6_addr': ip6})
2127
Matus Fabian8ebe6252017-11-06 05:04:53 -08002128 def dslite_add_del_pool_addr_range(
2129 self,
2130 start_addr,
2131 end_addr,
2132 is_add=1):
2133 """Add/del address range to DS-Lite pool
2134
2135 :param start_addr: First IP address
2136 :param end_addr: Last IP address
2137 :param is_add: 1 if add, 0 if delete (Default value = 1)
2138 """
2139 return self.api(
2140 self.papi.dslite_add_del_pool_addr_range,
2141 {'start_addr': start_addr,
2142 'end_addr': end_addr,
2143 'is_add': is_add})
2144
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002145 def nat66_add_del_interface(
2146 self,
2147 sw_if_index,
2148 is_inside=1,
2149 is_add=1):
2150 """Enable/disable NAT66 feature on the interface
2151 :param sw_if_index: Index of the interface
2152 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2153 :param is_add: 1 if add, 0 if delete (Default value = 1)
2154 """
2155 return self.api(
2156 self.papi.nat66_add_del_interface,
2157 {'sw_if_index': sw_if_index,
2158 'is_inside': is_inside,
2159 'is_add': is_add})
2160
2161 def nat66_add_del_static_mapping(
2162 self,
2163 in_ip,
2164 out_ip,
2165 vrf_id=0,
2166 is_add=1):
2167 """Add/delete NAT66 static mapping
2168
2169 :param in_ip: Inside IPv6 address
2170 :param out_ip: Outside IPv6 address
2171 :param vrf_id: VRF ID (Default value = 0)
2172 :param is_add: 1 if add, 0 if delete (Default value = 1)
2173 """
2174 return self.api(
2175 self.papi.nat66_add_del_static_mapping,
2176 {'local_ip_address': in_ip,
2177 'external_ip_address': out_ip,
2178 'vrf_id': vrf_id,
2179 'is_add': is_add})
2180
2181 def nat66_interface_dump(self):
2182 """Dump interfaces with NAT66 feature
2183 :return: Dictionary of interfaces with NAT66 feature
2184 """
2185 return self.api(self.papi.nat66_interface_dump, {})
2186
2187 def nat66_static_mapping_dump(self):
2188 """Dump NAT66 static mappings
2189 :return: Dictionary of NAT66 static mappings
2190 """
2191 return self.api(self.papi.nat66_static_mapping_dump, {})
2192
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002193 def control_ping(self):
2194 self.api(self.papi.control_ping)
2195
2196 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002197 detect_mult, local_addr, peer_addr, is_ipv6=0,
2198 bfd_key_id=None, conf_key_id=None):
2199 if bfd_key_id is None:
2200 return self.api(self.papi.bfd_udp_add,
2201 {
2202 'sw_if_index': sw_if_index,
2203 'desired_min_tx': desired_min_tx,
2204 'required_min_rx': required_min_rx,
2205 'local_addr': local_addr,
2206 'peer_addr': peer_addr,
2207 'is_ipv6': is_ipv6,
2208 'detect_mult': detect_mult,
2209 })
2210 else:
2211 return self.api(self.papi.bfd_udp_add,
2212 {
2213 'sw_if_index': sw_if_index,
2214 'desired_min_tx': desired_min_tx,
2215 'required_min_rx': required_min_rx,
2216 'local_addr': local_addr,
2217 'peer_addr': peer_addr,
2218 'is_ipv6': is_ipv6,
2219 'detect_mult': detect_mult,
2220 'is_authenticated': 1,
2221 'bfd_key_id': bfd_key_id,
2222 'conf_key_id': conf_key_id,
2223 })
2224
Klement Sekeraa57a9702017-02-02 06:58:07 +01002225 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2226 detect_mult, local_addr, peer_addr, is_ipv6=0):
2227 return self.api(self.papi.bfd_udp_mod,
2228 {
2229 'sw_if_index': sw_if_index,
2230 'desired_min_tx': desired_min_tx,
2231 'required_min_rx': required_min_rx,
2232 'local_addr': local_addr,
2233 'peer_addr': peer_addr,
2234 'is_ipv6': is_ipv6,
2235 'detect_mult': detect_mult,
2236 })
2237
Klement Sekerab17dd962017-01-09 07:43:48 +01002238 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2239 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2240 is_delayed=False):
2241 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002242 {
2243 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002244 'local_addr': local_addr,
2245 'peer_addr': peer_addr,
2246 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002247 'is_delayed': 1 if is_delayed else 0,
2248 'bfd_key_id': bfd_key_id,
2249 'conf_key_id': conf_key_id,
2250 })
2251
2252 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2253 is_ipv6=0, is_delayed=False):
2254 return self.api(self.papi.bfd_udp_auth_deactivate,
2255 {
2256 'sw_if_index': sw_if_index,
2257 'local_addr': local_addr,
2258 'peer_addr': peer_addr,
2259 'is_ipv6': is_ipv6,
2260 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002261 })
2262
2263 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2264 return self.api(self.papi.bfd_udp_del,
2265 {
2266 'sw_if_index': sw_if_index,
2267 'local_addr': local_addr,
2268 'peer_addr': peer_addr,
2269 'is_ipv6': is_ipv6,
2270 })
2271
2272 def bfd_udp_session_dump(self):
2273 return self.api(self.papi.bfd_udp_session_dump, {})
2274
Klement Sekerab17dd962017-01-09 07:43:48 +01002275 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2276 peer_addr, is_ipv6=0):
2277 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002278 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002279 'sw_if_index': sw_if_index,
2280 'local_addr': local_addr,
2281 'peer_addr': peer_addr,
2282 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002283 })
2284
2285 def want_bfd_events(self, enable_disable=1):
2286 return self.api(self.papi.want_bfd_events, {
2287 'enable_disable': enable_disable,
2288 'pid': os.getpid(),
2289 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002290
Klement Sekerab17dd962017-01-09 07:43:48 +01002291 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2292 return self.api(self.papi.bfd_auth_set_key, {
2293 'conf_key_id': conf_key_id,
2294 'auth_type': auth_type,
2295 'key': key,
2296 'key_len': len(key),
2297 })
2298
2299 def bfd_auth_del_key(self, conf_key_id):
2300 return self.api(self.papi.bfd_auth_del_key, {
2301 'conf_key_id': conf_key_id,
2302 })
2303
2304 def bfd_auth_keys_dump(self):
2305 return self.api(self.papi.bfd_auth_keys_dump, {})
2306
Klement Sekera239790f2017-02-16 10:53:53 +01002307 def bfd_udp_set_echo_source(self, sw_if_index):
2308 return self.api(self.papi.bfd_udp_set_echo_source,
2309 {'sw_if_index': sw_if_index})
2310
Klement Sekera73884482017-02-23 09:26:30 +01002311 def bfd_udp_del_echo_source(self):
2312 return self.api(self.papi.bfd_udp_del_echo_source, {})
2313
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002314 def bfd_udp_get_echo_source(self):
2315 return self.api(self.papi.bfd_udp_get_echo_source, {})
2316
Steve Shin7957d6e2016-12-19 09:24:50 -08002317 def classify_add_del_table(
2318 self,
2319 is_add,
2320 mask,
2321 match_n_vectors=1,
2322 table_index=0xFFFFFFFF,
2323 nbuckets=2,
2324 memory_size=2097152,
2325 skip_n_vectors=0,
2326 next_table_index=0xFFFFFFFF,
2327 miss_next_index=0xFFFFFFFF,
2328 current_data_flag=0,
2329 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002330 """
2331 :param is_add:
2332 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002333 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002334 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002335 :param nbuckets: (Default value = 2)
2336 :param memory_size: (Default value = 2097152)
2337 :param skip_n_vectors: (Default value = 0)
2338 :param next_table_index: (Default value = 0xFFFFFFFF)
2339 :param miss_next_index: (Default value = 0xFFFFFFFF)
2340 :param current_data_flag: (Default value = 0)
2341 :param current_data_offset: (Default value = 0)
2342 """
2343
Juraj Sloboda75282452018-06-12 14:20:49 +02002344 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2345 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002346 return self.api(
2347 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002348 {'is_add': is_add,
2349 'table_index': table_index,
2350 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002351 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002352 'skip_n_vectors': skip_n_vectors,
2353 'match_n_vectors': match_n_vectors,
2354 'next_table_index': next_table_index,
2355 'miss_next_index': miss_next_index,
2356 'current_data_flag': current_data_flag,
2357 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002358 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002359 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002360
2361 def classify_add_del_session(
2362 self,
2363 is_add,
2364 table_index,
2365 match,
2366 opaque_index=0xFFFFFFFF,
2367 hit_next_index=0xFFFFFFFF,
2368 advance=0,
2369 action=0,
2370 metadata=0):
2371 """
2372 :param is_add:
2373 :param table_index:
2374 :param match:
2375 :param opaque_index: (Default value = 0xFFFFFFFF)
2376 :param hit_next_index: (Default value = 0xFFFFFFFF)
2377 :param advance: (Default value = 0)
2378 :param action: (Default value = 0)
2379 :param metadata: (Default value = 0)
2380 """
2381
Juraj Sloboda75282452018-06-12 14:20:49 +02002382 match_len = ((len(match) - 1) / 16 + 1) * 16
2383 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002384 return self.api(
2385 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002386 {'is_add': is_add,
2387 'table_index': table_index,
2388 'hit_next_index': hit_next_index,
2389 'opaque_index': opaque_index,
2390 'advance': advance,
2391 'action': action,
2392 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002393 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002394 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002395
2396 def input_acl_set_interface(
2397 self,
2398 is_add,
2399 sw_if_index,
2400 ip4_table_index=0xFFFFFFFF,
2401 ip6_table_index=0xFFFFFFFF,
2402 l2_table_index=0xFFFFFFFF):
2403 """
2404 :param is_add:
2405 :param sw_if_index:
2406 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2407 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2408 :param l2_table_index: (Default value = 0xFFFFFFFF)
2409 """
2410
2411 return self.api(
2412 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002413 {'sw_if_index': sw_if_index,
2414 'ip4_table_index': ip4_table_index,
2415 'ip6_table_index': ip6_table_index,
2416 'l2_table_index': l2_table_index,
2417 'is_add': is_add})
2418
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002419 def output_acl_set_interface(
2420 self,
2421 is_add,
2422 sw_if_index,
2423 ip4_table_index=0xFFFFFFFF,
2424 ip6_table_index=0xFFFFFFFF,
2425 l2_table_index=0xFFFFFFFF):
2426 """
2427 :param is_add:
2428 :param sw_if_index:
2429 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2430 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2431 :param l2_table_index: (Default value = 0xFFFFFFFF)
2432 """
2433
2434 return self.api(
2435 self.papi.output_acl_set_interface,
2436 {'sw_if_index': sw_if_index,
2437 'ip4_table_index': ip4_table_index,
2438 'ip6_table_index': ip6_table_index,
2439 'l2_table_index': l2_table_index,
2440 'is_add': is_add})
2441
Klement Sekera77fabdb2017-01-02 07:46:14 +01002442 def set_ipfix_exporter(
2443 self,
2444 collector_address,
2445 src_address,
2446 path_mtu,
2447 template_interval,
2448 vrf_id=0,
2449 collector_port=4739,
2450 udp_checksum=0):
2451 return self.api(
2452 self.papi.set_ipfix_exporter,
2453 {
2454 'collector_address': collector_address,
2455 'collector_port': collector_port,
2456 'src_address': src_address,
2457 'vrf_id': vrf_id,
2458 'path_mtu': path_mtu,
2459 'template_interval': template_interval,
2460 'udp_checksum': udp_checksum,
2461 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002462
2463 def dhcp_proxy_config(self,
2464 dhcp_server,
2465 dhcp_src_address,
2466 rx_table_id=0,
2467 server_table_id=0,
2468 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002469 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002470 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002471 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002472 {
2473 'rx_vrf_id': rx_table_id,
2474 'server_vrf_id': server_table_id,
2475 'is_ipv6': is_ipv6,
2476 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002477 'dhcp_server': dhcp_server,
2478 'dhcp_src_address': dhcp_src_address,
2479 })
2480
2481 def dhcp_proxy_set_vss(self,
2482 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002483 vss_type=255,
2484 vpn_ascii_id="",
2485 oui=0,
2486 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002487 is_add=1,
2488 is_ip6=0):
2489 return self.api(
2490 self.papi.dhcp_proxy_set_vss,
2491 {
2492 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002493 'vss_type': vss_type,
2494 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002495 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002496 'vpn_index': vpn_index,
2497 'is_add': is_add,
2498 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002499 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002500
Neale Rannsdaff1782018-05-16 04:12:18 -07002501 def dhcp_client_dump(self):
2502 return self.api(self.papi.dhcp_client_dump, {})
2503
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002504 def dhcp_client(self,
2505 sw_if_index,
2506 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002507 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002508 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002509 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002510 want_dhcp_events=0):
2511 return self.api(
2512 self.papi.dhcp_client_config,
2513 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002514 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002515 'client': {
2516 'sw_if_index': sw_if_index,
2517 'hostname': hostname,
2518 'id': client_id,
2519 'want_dhcp_event': want_dhcp_events,
2520 'set_broadcast_flag': set_broadcast_flag,
2521 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002522 })
2523
Neale Ranns32e1c012016-11-22 17:07:28 +00002524 def ip_mroute_add_del(self,
2525 src_address,
2526 grp_address,
2527 grp_address_length,
2528 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002529 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002530 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002531 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002532 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002533 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002534 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002535 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002536 is_add=1,
2537 is_ipv6=0,
2538 is_local=0):
2539 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002540 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002541 """
2542 return self.api(
2543 self.papi.ip_mroute_add_del,
2544 {'next_hop_sw_if_index': next_hop_sw_if_index,
2545 'entry_flags': e_flags,
2546 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002547 'table_id': table_id,
2548 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002549 'is_add': is_add,
2550 'is_ipv6': is_ipv6,
2551 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002552 'bier_imp': bier_imp,
2553 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002554 'grp_address_length': grp_address_length,
2555 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002556 'src_address': src_address,
2557 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002558
2559 def mfib_signal_dump(self):
2560 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002561
2562 def ip_mfib_dump(self):
2563 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002564
Neale Rannsd792d9c2017-10-21 10:53:20 -07002565 def ip6_mfib_dump(self):
2566 return self.api(self.papi.ip6_mfib_dump, {})
2567
Filip Tehlar770e89e2017-01-31 10:39:16 +01002568 def lisp_enable_disable(self, is_enabled):
2569 return self.api(
2570 self.papi.lisp_enable_disable,
2571 {
2572 'is_en': is_enabled,
2573 })
2574
2575 def lisp_locator_set(self,
2576 ls_name,
2577 is_add=1):
2578 return self.api(
2579 self.papi.lisp_add_del_locator_set,
2580 {
2581 'is_add': is_add,
2582 'locator_set_name': ls_name
2583 })
2584
2585 def lisp_locator_set_dump(self):
2586 return self.api(self.papi.lisp_locator_set_dump, {})
2587
2588 def lisp_locator(self,
2589 ls_name,
2590 sw_if_index,
2591 priority=1,
2592 weight=1,
2593 is_add=1):
2594 return self.api(
2595 self.papi.lisp_add_del_locator,
2596 {
2597 'is_add': is_add,
2598 'locator_set_name': ls_name,
2599 'sw_if_index': sw_if_index,
2600 'priority': priority,
2601 'weight': weight
2602 })
2603
2604 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2605 return self.api(
2606 self.papi.lisp_locator_dump,
2607 {
2608 'is_index_set': is_index_set,
2609 'ls_name': ls_name,
2610 'ls_index': ls_index,
2611 })
2612
2613 def lisp_local_mapping(self,
2614 ls_name,
2615 eid_type,
2616 eid,
2617 prefix_len,
2618 vni=0,
2619 key_id=0,
2620 key="",
2621 is_add=1):
2622 return self.api(
2623 self.papi.lisp_add_del_local_eid,
2624 {
2625 'locator_set_name': ls_name,
2626 'is_add': is_add,
2627 'eid_type': eid_type,
2628 'eid': eid,
2629 'prefix_len': prefix_len,
2630 'vni': vni,
2631 'key_id': key_id,
2632 'key': key
2633 })
2634
2635 def lisp_eid_table_dump(self,
2636 eid_set=0,
2637 prefix_length=0,
2638 vni=0,
2639 eid_type=0,
2640 eid=None,
2641 filter_opt=0):
2642 return self.api(
2643 self.papi.lisp_eid_table_dump,
2644 {
2645 'eid_set': eid_set,
2646 'prefix_length': prefix_length,
2647 'vni': vni,
2648 'eid_type': eid_type,
2649 'eid': eid,
2650 'filter': filter_opt,
2651 })
2652
2653 def lisp_remote_mapping(self,
2654 eid_type,
2655 eid,
2656 eid_prefix_len=0,
2657 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002658 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002659 rlocs_num=0,
2660 is_src_dst=0,
2661 is_add=1):
2662 return self.api(
2663 self.papi.lisp_add_del_remote_mapping,
2664 {
2665 'is_add': is_add,
2666 'eid_type': eid_type,
2667 'eid': eid,
2668 'eid_len': eid_prefix_len,
2669 'rloc_num': rlocs_num,
2670 'rlocs': rlocs,
2671 'vni': vni,
2672 'is_src_dst': is_src_dst,
2673 })
2674
2675 def lisp_adjacency(self,
2676 leid,
2677 reid,
2678 leid_len,
2679 reid_len,
2680 eid_type,
2681 is_add=1,
2682 vni=0):
2683 return self.api(
2684 self.papi.lisp_add_del_adjacency,
2685 {
2686 'is_add': is_add,
2687 'vni': vni,
2688 'eid_type': eid_type,
2689 'leid': leid,
2690 'reid': reid,
2691 'leid_len': leid_len,
2692 'reid_len': reid_len,
2693 })
2694
2695 def lisp_adjacencies_get(self, vni=0):
2696 return self.api(
2697 self.papi.lisp_adjacencies_get,
2698 {
2699 'vni': vni
2700 })
Neale Ranns80823802017-02-20 18:23:41 -08002701
2702 def map_add_domain(self,
2703 ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002704 ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002705 ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002706 ea_bits_len=0,
2707 psid_offset=0,
2708 psid_length=0,
2709 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002710 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002711 mtu=1280):
2712 return self.api(
2713 self.papi.map_add_domain,
2714 {
2715 'ip6_prefix': ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002716 'ip4_prefix': ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002717 'ip6_src': ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002718 'ea_bits_len': ea_bits_len,
2719 'psid_offset': psid_offset,
2720 'psid_length': psid_length,
2721 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002722 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002723 'mtu': mtu
2724 })
Hongjun Nief486b12017-04-12 19:21:16 +08002725
2726 def gtpu_add_del_tunnel(
2727 self,
2728 src_addr,
2729 dst_addr,
2730 is_add=1,
2731 is_ipv6=0,
2732 mcast_sw_if_index=0xFFFFFFFF,
2733 encap_vrf_id=0,
2734 decap_next_index=0xFFFFFFFF,
2735 teid=0):
2736 """
2737
2738 :param is_add: (Default value = 1)
2739 :param is_ipv6: (Default value = 0)
2740 :param src_addr:
2741 :param dst_addr:
2742 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2743 :param encap_vrf_id: (Default value = 0)
2744 :param decap_next_index: (Default value = 0xFFFFFFFF)
2745 :param teid: (Default value = 0)
2746
2747 """
2748 return self.api(self.papi.gtpu_add_del_tunnel,
2749 {'is_add': is_add,
2750 'is_ipv6': is_ipv6,
2751 'src_address': src_addr,
2752 'dst_address': dst_addr,
2753 'mcast_sw_if_index': mcast_sw_if_index,
2754 'encap_vrf_id': encap_vrf_id,
2755 'decap_next_index': decap_next_index,
2756 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002757
2758 def vxlan_gpe_add_del_tunnel(
2759 self,
2760 src_addr,
2761 dst_addr,
2762 mcast_sw_if_index=0xFFFFFFFF,
2763 is_add=1,
2764 is_ipv6=0,
2765 encap_vrf_id=0,
2766 decap_vrf_id=0,
2767 protocol=3,
2768 vni=0):
2769 """
2770
2771 :param local:
2772 :param remote:
2773 :param is_add: (Default value = 1)
2774 :param is_ipv6: (Default value = 0)
2775 :param encap_vrf_id: (Default value = 0)
2776 :param decap_vrf_id: (Default value = 0)
2777 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2778 :param protocol: (Default value = 3)
2779 :param vni: (Default value = 0)
2780
2781 """
2782 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2783 {'is_add': is_add,
2784 'is_ipv6': is_ipv6,
2785 'local': src_addr,
2786 'remote': dst_addr,
2787 'mcast_sw_if_index': mcast_sw_if_index,
2788 'encap_vrf_id': encap_vrf_id,
2789 'decap_vrf_id': decap_vrf_id,
2790 'protocol': protocol,
2791 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002792
Neale Ranns79a05f52018-09-11 07:39:43 -07002793 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002794 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002795 src,
2796 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002797 mcast_sw_if_index=0xFFFFFFFF,
2798 is_add=1,
2799 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002800 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002801 vni=0,
2802 instance=0xFFFFFFFF):
2803 """
2804
2805 :param dst_addr:
2806 :param src_addr:
2807 :param is_add: (Default value = 1)
2808 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002809 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002810 :param decap_next_index: (Default value = 0xFFFFFFFF)
2811 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2812 :param vni: (Default value = 0)
2813 :param instance: (Default value = 0xFFFFFFFF)
2814
2815 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002816 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002817 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002818 'tunnel': {
2819 'src': src,
2820 'dst': dst,
2821 'mcast_sw_if_index': mcast_sw_if_index,
2822 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002823 'vni': vni,
2824 'instance': instance}})
2825
2826 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2827 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2828 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002829
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002830 def pppoe_add_del_session(
2831 self,
2832 client_ip,
2833 client_mac,
2834 session_id=0,
2835 is_add=1,
2836 is_ipv6=0,
2837 decap_vrf_id=0):
2838 """
2839
2840 :param is_add: (Default value = 1)
2841 :param is_ipv6: (Default value = 0)
2842 :param client_ip:
2843 :param session_id: (Default value = 0)
2844 :param client_mac:
2845 :param decap_vrf_id: (Default value = 0)
2846
2847 """
2848 return self.api(self.papi.pppoe_add_del_session,
2849 {'is_add': is_add,
2850 'is_ipv6': is_ipv6,
2851 'session_id': session_id,
2852 'client_ip': client_ip,
2853 'decap_vrf_id': decap_vrf_id,
2854 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002855
Neale Ranns7c922dc2018-08-30 06:12:27 -07002856 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2857 return self.api(self.papi.sr_mpls_policy_add,
2858 {'bsid': bsid,
2859 'weight': weight,
2860 'type': type,
2861 'n_segments': len(segments),
2862 'segments': segments})
2863
2864 def sr_mpls_policy_del(self, bsid):
2865 return self.api(self.papi.sr_mpls_policy_del,
2866 {'bsid': bsid})
2867
Kris Michielsen91074432017-06-22 13:00:20 +02002868 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002869 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002870 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002871 nh_addr4,
2872 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002873 is_del=0,
2874 end_psp=0,
2875 sw_if_index=0xFFFFFFFF,
2876 vlan_index=0,
2877 fib_table=0,
2878 ):
2879 """ Add/del IPv6 SR local-SID.
2880
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002881 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002882 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2883 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002884 :param nh_addr4:
2885 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002886 :param is_del: (Default value = 0)
2887 :param end_psp: (Default value = 0)
2888 :param sw_if_index: (Default value = 0xFFFFFFFF)
2889 :param vlan_index: (Default value = 0)
2890 :param fib_table: (Default value = 0)
2891 """
2892 return self.api(
2893 self.papi.sr_localsid_add_del,
2894 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002895 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002896 'end_psp': end_psp,
2897 'behavior': behavior,
2898 'sw_if_index': sw_if_index,
2899 'vlan_index': vlan_index,
2900 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002901 'nh_addr4': nh_addr4,
2902 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002903 }
2904 )
2905
2906 def sr_policy_add(
2907 self,
2908 bsid_addr,
2909 weight=1,
2910 is_encap=1,
2911 type=0,
2912 fib_table=0,
2913 n_segments=0,
2914 segments=[]):
2915 """
2916 :param bsid_addr: bindingSID of the SR Policy
2917 :param weight: weight of the sid list. optional. (default: 1)
2918 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2919 (default: Encap)
2920 :param type: type/behavior of the SR policy. (default or spray) \
2921 (default: default)
2922 :param fib_table: VRF where to install the FIB entry for the BSID \
2923 (default: 0)
2924 :param n_segments: number of segments \
2925 (default: 0)
2926 :param segments: a vector of IPv6 address composing the segment list \
2927 (default: [])
2928 """
2929 return self.api(
2930 self.papi.sr_policy_add,
2931 {'bsid_addr': bsid_addr,
2932 'weight': weight,
2933 'is_encap': is_encap,
2934 'type': type,
2935 'fib_table': fib_table,
2936 'n_segments': n_segments,
2937 'segments': segments
2938 }
2939 )
2940
2941 def sr_policy_del(
2942 self,
2943 bsid_addr,
2944 sr_policy_index=0):
2945 """
2946 :param bsid: bindingSID of the SR Policy
2947 :param sr_policy_index: index of the sr policy (default: 0)
2948 """
2949 return self.api(
2950 self.papi.sr_policy_del,
2951 {'bsid_addr': bsid_addr,
2952 'sr_policy_index': sr_policy_index
2953 })
2954
2955 def sr_steering_add_del(
2956 self,
2957 is_del,
2958 bsid_addr,
2959 sr_policy_index,
2960 table_id,
2961 prefix_addr,
2962 mask_width,
2963 sw_if_index,
2964 traffic_type):
2965 """
2966 Steer traffic L2 and L3 traffic through a given SR policy
2967
2968 :param is_del: delete or add
2969 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2970 :param sr_policy: is the index of the SR Policy (alt to bsid)
2971 :param table_id: is the VRF where to install the FIB entry for the BSID
2972 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2973 :param mask_width: is the mask for L3 traffic type
2974 :param sw_if_index: is the incoming interface for L2 traffic
2975 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2976 """
2977 return self.api(
2978 self.papi.sr_steering_add_del,
2979 {'is_del': is_del,
2980 'bsid_addr': bsid_addr,
2981 'sr_policy_index': sr_policy_index,
2982 'table_id': table_id,
2983 'prefix_addr': prefix_addr,
2984 'mask_width': mask_width,
2985 'sw_if_index': sw_if_index,
2986 'traffic_type': traffic_type
2987 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002988
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002989 def acl_add_replace(self, acl_index, r, tag='',
2990 expected_retval=0):
2991 """Add/replace an ACL
2992 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2993 :param acl_rule r: ACL rules array.
2994 :param str tag: symbolic tag (description) for this ACL.
2995 :param int count: number of rules.
2996 """
2997 return self.api(self.papi.acl_add_replace,
2998 {'acl_index': acl_index,
2999 'r': r,
3000 'count': len(r),
3001 'tag': tag},
3002 expected_retval=expected_retval)
3003
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003004 def acl_del(self, acl_index, expected_retval=0):
3005 """
3006
3007 :param acl_index:
3008 :return:
3009 """
3010 return self.api(self.papi.acl_del,
3011 {'acl_index': acl_index},
3012 expected_retval=expected_retval)
3013
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003014 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3015 expected_retval=0):
3016 return self.api(self.papi.acl_interface_set_acl_list,
3017 {'sw_if_index': sw_if_index,
3018 'count': len(acls),
3019 'n_input': n_input,
3020 'acls': acls},
3021 expected_retval=expected_retval)
3022
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003023 def acl_interface_set_etype_whitelist(self, sw_if_index,
3024 n_input, whitelist,
3025 expected_retval=0):
3026 return self.api(self.papi.acl_interface_set_etype_whitelist,
3027 {'sw_if_index': sw_if_index,
3028 'count': len(whitelist),
3029 'n_input': n_input,
3030 'whitelist': whitelist},
3031 expected_retval=expected_retval)
3032
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003033 def acl_interface_add_del(self,
3034 sw_if_index,
3035 acl_index,
3036 is_add=1):
3037 """ Add/Delete ACL to/from interface
3038
3039 :param sw_if_index:
3040 :param acl_index:
3041 :param is_add: (Default value = 1)
3042 """
3043
3044 return self.api(self.papi.acl_interface_add_del,
3045 {'is_add': is_add,
3046 'is_input': 1,
3047 'sw_if_index': sw_if_index,
3048 'acl_index': acl_index})
3049
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003050 def acl_dump(self, acl_index, expected_retval=0):
3051 return self.api(self.papi.acl_dump,
3052 {'acl_index': acl_index},
3053 expected_retval=expected_retval)
3054
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003055 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3056 expected_retval=0):
3057 return self.api(self.papi.acl_interface_list_dump,
3058 {'sw_if_index': sw_if_index},
3059 expected_retval=expected_retval)
3060
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003061 def macip_acl_add(self, rules, tag=""):
3062 """ Add MACIP acl
3063
3064 :param rules: list of rules for given acl
3065 :param tag: acl tag
3066 """
3067
3068 return self.api(self.papi.macip_acl_add,
3069 {'r': rules,
3070 'count': len(rules),
3071 'tag': tag})
3072
Pavel Kotucek932f7412017-09-07 14:44:52 +02003073 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3074 """ Add MACIP acl
3075
3076 :param rules: list of rules for given acl
3077 :param tag: acl tag
3078 """
3079
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003080 return self.api(self.papi.macip_acl_add_replace,
3081 {'acl_index': acl_index,
3082 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003083 'count': len(rules),
3084 'tag': tag})
3085
3086 def macip_acl_del(self, acl_index):
3087 """
3088
3089 :param acl_index:
3090 :return:
3091 """
3092 return self.api(self.papi.macip_acl_del,
3093 {'acl_index': acl_index})
3094
3095 def macip_acl_interface_add_del(self,
3096 sw_if_index,
3097 acl_index,
3098 is_add=1):
3099 """ Add MACIP acl to interface
3100
3101 :param sw_if_index:
3102 :param acl_index:
3103 :param is_add: (Default value = 1)
3104 """
3105
3106 return self.api(self.papi.macip_acl_interface_add_del,
3107 {'is_add': is_add,
3108 'sw_if_index': sw_if_index,
3109 'acl_index': acl_index})
3110
3111 def macip_acl_interface_get(self):
3112 """ Return interface acls dump
3113 """
3114 return self.api(
3115 self.papi.macip_acl_interface_get, {})
3116
3117 def macip_acl_dump(self, acl_index=4294967295):
3118 """ Return MACIP acl dump
3119 """
3120
3121 return self.api(
3122 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003123
3124 def policer_add_del(self,
3125 name,
3126 cir,
3127 eir,
3128 cb,
3129 eb,
3130 is_add=1,
3131 rate_type=0,
3132 round_type=0,
3133 ptype=0,
3134 color_aware=0,
3135 conform_action_type=1,
3136 conform_dscp=0,
3137 exceed_action_type=0,
3138 exceed_dscp=0,
3139 violate_action_type=0,
3140 violate_dscp=0):
3141 return self.api(self.papi.policer_add_del,
3142 {'name': name,
3143 'cir': cir,
3144 'eir': eir,
3145 'cb': cb,
3146 'eb': eb,
3147 'is_add': is_add,
3148 'rate_type': rate_type,
3149 'round_type': round_type,
3150 'type': ptype,
3151 'color_aware': color_aware,
3152 'conform_action_type': conform_action_type,
3153 'conform_dscp': conform_dscp,
3154 'exceed_action_type': exceed_action_type,
3155 'exceed_dscp': exceed_dscp,
3156 'violate_action_type': violate_action_type,
3157 'violate_dscp': violate_dscp})
3158
3159 def ip_punt_police(self,
3160 policer_index,
3161 is_ip6=0,
3162 is_add=1):
3163 return self.api(self.papi.ip_punt_police,
3164 {'policer_index': policer_index,
3165 'is_add': is_add,
3166 'is_ip6': is_ip6})
3167
3168 def ip_punt_redirect(self,
3169 rx_sw_if_index,
3170 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003171 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003172 is_add=1):
3173 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003174 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3175 'tx_sw_if_index': tx_sw_if_index,
3176 'nh': address},
3177 'is_add': is_add})
3178
3179 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3180 return self.api(self.papi.ip_punt_redirect_dump,
3181 {'sw_if_index': sw_if_index,
3182 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003183
3184 def bier_table_add_del(self,
3185 bti,
3186 mpls_label,
3187 is_add=1):
3188 """ BIER Table add/del """
3189 return self.api(
3190 self.papi.bier_table_add_del,
3191 {'bt_tbl_id': {"bt_set": bti.set_id,
3192 "bt_sub_domain": bti.sub_domain_id,
3193 "bt_hdr_len_id": bti.hdr_len_id},
3194 'bt_label': mpls_label,
3195 'bt_is_add': is_add})
3196
3197 def bier_table_dump(self):
3198 return self.api(self.papi.bier_table_dump, {})
3199
3200 def bier_route_add_del(self,
3201 bti,
3202 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003203 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003204 is_add=1,
3205 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003206 """ BIER Route add/del """
3207 return self.api(
3208 self.papi.bier_route_add_del,
3209 {'br_tbl_id': {"bt_set": bti.set_id,
3210 "bt_sub_domain": bti.sub_domain_id,
3211 "bt_hdr_len_id": bti.hdr_len_id},
3212 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003213 'br_n_paths': len(paths),
3214 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003215 'br_is_add': is_add,
3216 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003217
3218 def bier_route_dump(self, bti):
3219 return self.api(
3220 self.papi.bier_route_dump,
3221 {'br_tbl_id': {"bt_set": bti.set_id,
3222 "bt_sub_domain": bti.sub_domain_id,
3223 "bt_hdr_len_id": bti.hdr_len_id}})
3224
3225 def bier_imp_add(self,
3226 bti,
3227 src,
3228 ibytes,
3229 is_add=1):
3230 """ BIER Imposition Add """
3231 return self.api(
3232 self.papi.bier_imp_add,
3233 {'bi_tbl_id': {"bt_set": bti.set_id,
3234 "bt_sub_domain": bti.sub_domain_id,
3235 "bt_hdr_len_id": bti.hdr_len_id},
3236 'bi_src': src,
3237 'bi_n_bytes': len(ibytes),
3238 'bi_bytes': ibytes})
3239
3240 def bier_imp_del(self, bi_index):
3241 """ BIER Imposition del """
3242 return self.api(
3243 self.papi.bier_imp_del,
3244 {'bi_index': bi_index})
3245
3246 def bier_imp_dump(self):
3247 return self.api(self.papi.bier_imp_dump, {})
3248
3249 def bier_disp_table_add_del(self,
3250 bdti,
3251 is_add=1):
3252 """ BIER Disposition Table add/del """
3253 return self.api(
3254 self.papi.bier_disp_table_add_del,
3255 {'bdt_tbl_id': bdti,
3256 'bdt_is_add': is_add})
3257
3258 def bier_disp_table_dump(self):
3259 return self.api(self.papi.bier_disp_table_dump, {})
3260
3261 def bier_disp_entry_add_del(self,
3262 bdti,
3263 bp,
3264 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003265 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003266 next_hop,
3267 next_hop_tbl_id=0,
3268 next_hop_rpf_id=~0,
3269 next_hop_is_ip4=1,
3270 is_add=1):
3271 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003272 lstack = []
3273 while (len(lstack) < 16):
3274 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003275 return self.api(
3276 self.papi.bier_disp_entry_add_del,
3277 {'bde_tbl_id': bdti,
3278 'bde_bp': bp,
3279 'bde_payload_proto': payload_proto,
3280 'bde_n_paths': 1,
3281 'bde_paths': [{'next_hop': next_hop,
3282 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003283 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003284 'rpf_id': next_hop_rpf_id,
3285 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003286 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003287 'bde_is_add': is_add})
3288
3289 def bier_disp_entry_dump(self, bdti):
3290 return self.api(
3291 self.papi.bier_disp_entry_dump,
3292 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003293
3294 def add_node_next(self, node_name, next_name):
3295 """ Set the next node for a given node request
3296
3297 :param node_name:
3298 :param next_name:
3299 """
3300 return self.api(self.papi.add_node_next,
3301 {'node_name': node_name,
3302 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003303
3304 def session_enable_disable(self, is_enabled):
3305 return self.api(
3306 self.papi.session_enable_disable,
3307 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003308
3309 def ipsec_spd_add_del(self, spd_id, is_add=1):
3310 """ SPD add/del - Wrapper to add or del ipsec SPD
3311 Sample CLI : 'ipsec spd add 1'
3312
3313 :param spd_id - SPD ID to be created in the vpp . mandatory
3314 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3315 optional
3316 :returns: reply from the API
3317 """
3318 return self.api(
3319 self.papi.ipsec_spd_add_del, {
3320 'spd_id': spd_id, 'is_add': is_add})
3321
3322 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3323 """ IPSEC interface SPD add/del - \
3324 Wrapper to associate/disassociate SPD to interface in VPP
3325 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3326
3327 :param spd_id - SPD ID to associate with the interface . mandatory
3328 :param sw_if_index - Interface Index which needs to ipsec \
3329 association mandatory
3330 :param is_add - add(1) or del(0) association with interface \
3331 (Default 1 - add) . optional
3332 :returns: reply from the API
3333 """
3334 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003335 self.papi.ipsec_interface_add_del_spd,
3336 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003337
3338 def ipsec_sad_add_del_entry(self,
3339 sad_id,
3340 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003341 integrity_algorithm,
3342 integrity_key,
3343 crypto_algorithm,
3344 crypto_key,
3345 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003346 tunnel_src_address='',
3347 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003348 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003349 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003350 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003351 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003352 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003353 :param sad_id: security association ID
3354 :param spi: security param index of the SA in decimal
3355 :param integrity_algorithm:
3356 :param integrity_key:
3357 :param crypto_algorithm:
3358 :param crypto_key:
3359 :param protocol: AH(0) or ESP(1) protocol
3360 :param tunnel_src_address: tunnel mode outer src address
3361 :param tunnel_dst_address: tunnel mode outer dst address
3362 :param is_add:
3363 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003364 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3365 crypto and ipsec algorithms
3366 """
3367 return self.api(
3368 self.papi.ipsec_sad_add_del_entry,
3369 {'sad_id': sad_id,
3370 'spi': spi,
3371 'tunnel_src_address': tunnel_src_address,
3372 'tunnel_dst_address': tunnel_dst_address,
3373 'protocol': protocol,
3374 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003375 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003376 'integrity_key': integrity_key,
3377 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003378 'crypto_key_length': len(crypto_key) if crypto_key is not None
3379 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003380 'crypto_key': crypto_key,
3381 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003382 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003383 'is_tunnel_ipv6': is_tunnel_ipv6,
Klement Sekera4b089f22018-04-17 18:04:57 +02003384 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003385
3386 def ipsec_spd_add_del_entry(self,
3387 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003388 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003389 local_address_start,
3390 local_address_stop,
3391 remote_address_start,
3392 remote_address_stop,
3393 local_port_start=0,
3394 local_port_stop=65535,
3395 remote_port_start=0,
3396 remote_port_stop=65535,
3397 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003398 policy=0,
3399 priority=100,
3400 is_outbound=1,
3401 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003402 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003403 is_ip_any=0):
3404 """ IPSEC policy SPD add/del -
3405 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003406 :param spd_id: SPD ID for the policy
3407 :param local_address_start: local-ip-range start address
3408 :param local_address_stop : local-ip-range stop address
3409 :param remote_address_start: remote-ip-range start address
3410 :param remote_address_stop : remote-ip-range stop address
3411 :param local_port_start: (Default value = 0)
3412 :param local_port_stop: (Default value = 65535)
3413 :param remote_port_start: (Default value = 0)
3414 :param remote_port_stop: (Default value = 65535)
3415 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3416 :param sa_id: Security Association ID for mapping it to SPD
3417 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3418 (Default value = 0)
3419 :param priority: value for the spd action (Default value = 100)
3420 :param is_outbound: flag for inbound(0) or outbound(1)
3421 (Default value = 1)
3422 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003423 """
3424 return self.api(
3425 self.papi.ipsec_spd_add_del_entry,
3426 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003427 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003428 'local_address_start': local_address_start,
3429 'local_address_stop': local_address_stop,
3430 'remote_address_start': remote_address_start,
3431 'remote_address_stop': remote_address_stop,
3432 'local_port_start': local_port_start,
3433 'local_port_stop': local_port_stop,
3434 'remote_port_start': remote_port_start,
3435 'remote_port_stop': remote_port_stop,
3436 'is_add': is_add,
3437 'protocol': protocol,
3438 'policy': policy,
3439 'priority': priority,
3440 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003441 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003442 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003443
Klement Sekera31da2e32018-06-24 22:49:55 +02003444 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3445 remote_spi, crypto_alg, local_crypto_key,
3446 remote_crypto_key, integ_alg, local_integ_key,
3447 remote_integ_key, is_add=1, esn=0,
3448 anti_replay=1, renumber=0, show_instance=0):
3449 return self.api(
3450 self.papi.ipsec_tunnel_if_add_del,
3451 {'local_ip': local_ip, 'remote_ip': remote_ip,
3452 'local_spi': local_spi, 'remote_spi': remote_spi,
3453 'crypto_alg': crypto_alg,
3454 'local_crypto_key_len': len(local_crypto_key),
3455 'local_crypto_key': local_crypto_key,
3456 'remote_crypto_key_len': len(remote_crypto_key),
3457 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3458 'local_integ_key_len': len(local_integ_key),
3459 'local_integ_key': local_integ_key,
3460 'remote_integ_key_len': len(remote_integ_key),
3461 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3462 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3463 'show_instance': show_instance
3464 })
3465
Klement Sekerab4d30532018-11-08 13:00:02 +01003466 def ipsec_select_backend(self, protocol, index):
3467 return self.api(self.papi.ipsec_select_backend,
3468 {'protocol': protocol, 'index': index})
3469
3470 def ipsec_backend_dump(self):
3471 return self.api(self.papi.ipsec_backend_dump, {})
3472
Florin Corasb795bd02017-12-14 11:30:48 -08003473 def app_namespace_add(self,
3474 namespace_id,
3475 ip4_fib_id=0,
3476 ip6_fib_id=0,
3477 sw_if_index=0xFFFFFFFF,
3478 secret=0):
3479 return self.api(
3480 self.papi.app_namespace_add_del,
3481 {'secret': secret,
3482 'sw_if_index': sw_if_index,
3483 'ip4_fib_id': ip4_fib_id,
3484 'ip6_fib_id': ip6_fib_id,
3485 'namespace_id': namespace_id,
3486 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003487
3488 def punt_socket_register(self, l4_port, pathname, header_version=1,
3489 is_ip4=1, l4_protocol=0x11):
3490 """ Punt to socket """
3491 return self.api(self.papi.punt_socket_register,
3492 {'is_ip4': is_ip4,
3493 'l4_protocol': l4_protocol,
3494 'l4_port': l4_port,
3495 'pathname': pathname,
3496 'header_version': header_version})
3497
3498 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3499 expire_walk_interval_ms, is_ip6=0):
3500 """ Set IP reassembly parameters """
3501 return self.api(self.papi.ip_reassembly_set,
3502 {'is_ip6': is_ip6,
3503 'timeout_ms': timeout_ms,
3504 'expire_walk_interval_ms': expire_walk_interval_ms,
3505 'max_reassemblies': max_reassemblies})
3506
3507 def ip_reassembly_get(self, is_ip6=0):
3508 """ Get IP reassembly parameters """
3509 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003510
Klement Sekera4c533132018-02-22 11:41:12 +01003511 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3512 enable_ip6=False):
3513 """ Enable/disable IP reassembly """
3514 return self.api(self.papi.ip_reassembly_enable_disable,
3515 {'sw_if_index': sw_if_index,
3516 'enable_ip4': 1 if enable_ip4 else 0,
3517 'enable_ip6': 1 if enable_ip6 else 0,
3518 })
3519
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003520 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3521 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003522 """ GBP endpoint Add """
3523 return self.api(self.papi.gbp_endpoint_add,
3524 {'endpoint': {
3525 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003526 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003527 'ips': ips,
3528 'n_ips': len(ips),
3529 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003530 'epg_id': epg,
3531 'flags': flags,
3532 'tun': {
3533 'src': tun_src,
3534 'dst': tun_dst,
3535 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003536
3537 def gbp_endpoint_del(self, handle):
3538 """ GBP endpoint Del """
3539 return self.api(self.papi.gbp_endpoint_del,
3540 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003541
3542 def gbp_endpoint_dump(self):
3543 """ GBP endpoint Dump """
3544 return self.api(self.papi.gbp_endpoint_dump, {})
3545
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003546 def gbp_endpoint_group_add(self, epg, bd,
3547 rd, uplink_sw_if_index):
3548 """ GBP endpoint group Add """
3549 return self.api(self.papi.gbp_endpoint_group_add,
3550 {'epg':
3551 {
Neale Ranns25b04942018-04-04 09:34:50 -07003552 'uplink_sw_if_index': uplink_sw_if_index,
3553 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003554 'rd_id': rd,
3555 'epg_id': epg
3556 }})
3557
3558 def gbp_endpoint_group_del(self, epg):
3559 """ GBP endpoint group Del """
3560 return self.api(self.papi.gbp_endpoint_group_del,
3561 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003562
3563 def gbp_endpoint_group_dump(self):
3564 """ GBP endpoint group Dump """
3565 return self.api(self.papi.gbp_endpoint_group_dump, {})
3566
Neale Rannsc29c0af2018-11-07 04:21:12 -08003567 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003568 bvi_sw_if_index,
3569 uu_fwd_sw_if_index):
3570 """ GBP bridge-domain Add """
3571 return self.api(self.papi.gbp_bridge_domain_add,
3572 {'bd':
3573 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003574 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003575 'bvi_sw_if_index': bvi_sw_if_index,
3576 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3577 'bd_id': bd_id
3578 }})
3579
3580 def gbp_bridge_domain_del(self, bd_id):
3581 """ GBP bridge-domain Del """
3582 return self.api(self.papi.gbp_bridge_domain_del,
3583 {'bd_id': bd_id})
3584
3585 def gbp_bridge_domain_dump(self):
3586 """ GBP Bridge Domain Dump """
3587 return self.api(self.papi.gbp_bridge_domain_dump, {})
3588
3589 def gbp_route_domain_add(self, rd_id,
3590 ip4_table_id,
3591 ip6_table_id,
3592 ip4_uu_sw_if_index,
3593 ip6_uu_sw_if_index):
3594 """ GBP route-domain Add """
3595 return self.api(self.papi.gbp_route_domain_add,
3596 {'rd':
3597 {
3598 'ip4_table_id': ip4_table_id,
3599 'ip6_table_id': ip6_table_id,
3600 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3601 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3602 'rd_id': rd_id
3603 }})
3604
3605 def gbp_route_domain_del(self, rd_id):
3606 """ GBP route-domain Del """
3607 return self.api(self.papi.gbp_route_domain_del,
3608 {'rd_id': rd_id})
3609
3610 def gbp_route_domain_dump(self):
3611 """ GBP Route Domain Dump """
3612 return self.api(self.papi.gbp_route_domain_dump, {})
3613
Neale Ranns25b04942018-04-04 09:34:50 -07003614 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3615 """ GBP recirc Add/Del """
3616 return self.api(self.papi.gbp_recirc_add_del,
3617 {'is_add': is_add,
3618 'recirc': {
3619 'is_ext': is_ext,
3620 'sw_if_index': sw_if_index,
3621 'epg_id': epg}})
3622
3623 def gbp_recirc_dump(self):
3624 """ GBP recirc Dump """
3625 return self.api(self.papi.gbp_recirc_dump, {})
3626
Neale Rannsb6a47952018-11-21 05:44:35 -08003627 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3628 """ GBP recirc Add/Del """
3629 return self.api(self.papi.gbp_ext_itf_add_del,
3630 {'is_add': is_add,
3631 'ext_itf': {
3632 'sw_if_index': sw_if_index,
3633 'bd_id': bd_id,
3634 'rd_id': rd_id}})
3635
3636 def gbp_ext_itf_dump(self):
3637 """ GBP recirc Dump """
3638 return self.api(self.papi.gbp_ext_itf_dump, {})
3639
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003640 def gbp_subnet_add_del(self, is_add, rd_id,
3641 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003642 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003643 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003644 """ GBP Subnet Add/Del """
3645 return self.api(self.papi.gbp_subnet_add_del,
3646 {'is_add': is_add,
3647 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003648 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003649 'sw_if_index': sw_if_index,
3650 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003651 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003652 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003653
3654 def gbp_subnet_dump(self):
3655 """ GBP Subnet Dump """
3656 return self.api(self.papi.gbp_subnet_dump, {})
3657
Neale Ranns13a08cc2018-11-07 09:25:54 -08003658 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003659 """ GBP contract Add/Del """
3660 return self.api(self.papi.gbp_contract_add_del,
3661 {'is_add': is_add,
3662 'contract': {
3663 'acl_index': acl_index,
3664 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003665 'dst_epg': dst_epg,
3666 'n_rules': len(rules),
3667 'rules': rules}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003668
3669 def gbp_contract_dump(self):
3670 """ GBP contract Dump """
3671 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003672
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003673 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3674 """ GBP set inactive threshold """
3675 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3676 {'threshold': threshold})
3677
3678 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3679 """ GBP VXLAN tunnel add """
3680 return self.api(self.papi.gbp_vxlan_tunnel_add,
3681 {
3682 'tunnel': {
3683 'vni': vni,
3684 'mode': mode,
3685 'bd_rd_id': bd_rd_id
3686 }
3687 })
3688
3689 def gbp_vxlan_tunnel_del(self, vni):
3690 """ GBP VXLAN tunnel del """
3691 return self.api(self.papi.gbp_vxlan_tunnel_del,
3692 {
3693 'vni': vni,
3694 })
3695
3696 def gbp_vxlan_tunnel_dump(self):
3697 """ GBP VXLAN tunnel add/del """
3698 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3699
Neale Ranns61502112018-08-22 00:21:14 -07003700 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3701 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003702 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003703 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003704 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003705 {'ip4_table_id': ip4_table_id,
3706 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003707 'ip6_prefix': ip6_prefix,
3708 'ip6_prefix_len': ip6_prefix_len,
3709 'ip4_prefix': ip4_prefix,
3710 'ip4_prefix_len': ip4_prefix_len,
3711 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003712 'security_check': security_check})
3713
Ole Troan298c6952018-03-08 12:30:43 +01003714 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003715 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003716 return self.api(self.papi.ipip_6rd_del_tunnel,
3717 {'sw_if_index': sw_if_index})
3718
3719 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003720 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003721 """ IPIP tunnel Add/Del """
3722 return self.api(self.papi.ipip_add_tunnel,
3723 {'is_ipv6': is_ipv6,
3724 'instance': instance,
3725 'src_address': src_address,
3726 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003727 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003728 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003729
3730 def ipip_del_tunnel(self, sw_if_index):
3731 """ IPIP tunnel Delete """
3732 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003733 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003734
3735 def qos_egress_map_update(self, id, outputs):
3736 """ QOS egress map update """
3737 return self.api(self.papi.qos_egress_map_update,
3738 {'map_id': id,
3739 'rows': outputs})
3740
3741 def qos_egress_map_delete(self, id):
3742 """ QOS egress map delete """
3743 return self.api(self.papi.qos_egress_map_delete,
3744 {'map_id': id})
3745
3746 def qos_mark_enable_disable(self, sw_if_index,
3747 output_source,
3748 map_id,
3749 enable):
3750 """ QOS Mark Enable/Disable """
3751 return self.api(self.papi.qos_mark_enable_disable,
3752 {'map_id': map_id,
3753 'sw_if_index': sw_if_index,
3754 'output_source': output_source,
3755 'enable': enable})
3756
3757 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3758 """ IP QoS recording Enble/Disable """
3759 return self.api(self.papi.qos_record_enable_disable,
3760 {'sw_if_index': sw_if_index,
3761 'input_source': input_source,
3762 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003763
Neale Ranns947ea622018-06-07 23:48:20 -07003764 def igmp_enable_disable(self, sw_if_index, enable, host):
3765 """ Enable/disable IGMP on a given interface """
3766 return self.api(self.papi.igmp_enable_disable,
3767 {'enable': enable,
3768 'mode': host,
3769 'sw_if_index': sw_if_index})
3770
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003771 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3772 """ Add/del IGMP proxy device """
3773 return self.api(self.papi.igmp_proxy_device_add_del,
3774 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3775 'add': add})
3776
3777 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3778 """ Add/del interface to/from IGMP proxy device """
3779 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3780 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3781 'add': add})
3782
Neale Ranns947ea622018-06-07 23:48:20 -07003783 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003784 """ Listen for new (S,G) on specified interface
3785
3786 :param enable: add/del
3787 :param sw_if_index: interface sw index
3788 :param saddr: source ip4 addr
3789 :param gaddr: group ip4 addr
3790 """
3791 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003792 {
3793 'group':
3794 {
3795 'filter': filter,
3796 'sw_if_index': sw_if_index,
3797 'n_srcs': len(saddrs),
3798 'saddrs': saddrs,
3799 'gaddr':
3800 {
3801 'address': gaddr
3802 }
3803 }
3804 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003805
3806 def igmp_dump(self, sw_if_index=None):
3807 """ Dump all (S,G) interface configurations """
3808 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003809 sw_if_index = 0xffffffff
3810 return self.api(self.papi.igmp_dump,
3811 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003812
3813 def igmp_clear_interface(self, sw_if_index):
3814 """ Remove all (S,G)s from specified interface
3815 doesn't send IGMP report!
3816 """
3817 return self.api(
3818 self.papi.igmp_clear_interface, {
3819 'sw_if_index': sw_if_index})
3820
3821 def want_igmp_events(self, enable=1):
3822 return self.api(self.papi.want_igmp_events, {'enable': enable,
3823 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003824
3825 def bond_create(
3826 self,
3827 mode,
3828 lb,
3829 use_custom_mac,
3830 mac_address=''):
3831 """
3832 :param mode: mode
3833 :param lb: load balance
3834 :param use_custom_mac: use custom mac
3835 :param mac_address: mac address
3836 """
3837 return self.api(
3838 self.papi.bond_create,
3839 {'mode': mode,
3840 'lb': lb,
3841 'use_custom_mac': use_custom_mac,
3842 'mac_address': mac_address
3843 })
3844
3845 def bond_delete(
3846 self,
3847 sw_if_index):
3848 """
3849 :param sw_if_index: interface the operation is applied to
3850 """
3851 return self.api(self.papi.bond_delete,
3852 {'sw_if_index': sw_if_index})
3853
3854 def bond_enslave(
3855 self,
3856 sw_if_index,
3857 bond_sw_if_index,
3858 is_passive,
3859 is_long_timeout):
3860 """
3861 :param sw_if_index: slave sw_if_index
3862 :param bond_sw_if_index: bond sw_if_index
3863 :param is_passive: is passive lacp speaker
3864 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3865 """
3866 return self.api(
3867 self.papi.bond_enslave,
3868 {'sw_if_index': sw_if_index,
3869 'bond_sw_if_index': bond_sw_if_index,
3870 'is_passive': is_passive,
3871 'is_long_timeout': is_long_timeout
3872 })
3873
3874 def bond_detach_slave(
3875 self,
3876 sw_if_index):
3877 """
3878 :param sw_if_index: slave interface the operation is applied to
3879 """
3880 return self.api(self.papi.bond_detach_slave,
3881 {'sw_if_index': sw_if_index})
3882
3883 def sw_interface_slave_dump(
3884 self,
3885 sw_if_index):
3886 """
3887 :param sw_if_index: bond sw_if_index
3888 """
3889 return self.api(self.papi.sw_interface_slave_dump,
3890 {'sw_if_index': sw_if_index})
3891
3892 def sw_interface_bond_dump(
3893 self):
3894 """
3895
3896 """
3897 return self.api(self.papi.sw_interface_bond_dump,
3898 {})
Stevene8fa6202017-08-30 14:36:45 -07003899
3900 def create_vhost_user_if(
3901 self,
3902 is_server,
3903 sock_filename,
3904 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003905 disable_mrg_rxbuf,
3906 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003907 custom_dev_instance,
3908 use_custom_mac,
3909 mac_address,
3910 tag=''):
3911 """
3912 :param is_server: is server
3913 :param sock_filename: socket name
3914 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003915 :param disable_mrg_rxbuf: disable mergable rx buffers
3916 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003917 :param custom_dev_instance: custom dev instance
3918 :param use_custom_mac: use custom mac
3919 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003920 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003921 """
3922 return self.api(
3923 self.papi.create_vhost_user_if,
3924 {'is_server': is_server,
3925 'sock_filename': sock_filename,
3926 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003927 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3928 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003929 'custom_dev_instance': custom_dev_instance,
3930 'use_custom_mac': use_custom_mac,
3931 'mac_address': mac_address,
3932 'tag': tag
3933 })
3934
3935 def delete_vhost_user_if(
3936 self,
3937 sw_if_index):
3938 """
3939 :param sw_if_index: interface the operation is applied to
3940 """
3941 return self.api(self.papi.delete_vhost_user_if,
3942 {'sw_if_index': sw_if_index, })
3943
3944 def sw_interface_vhost_user_dump(
3945 self):
3946 """
3947
3948 """
3949 return self.api(self.papi.sw_interface_vhost_user_dump,
3950 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003951
3952 def abf_policy_add_del(self, is_add, policy):
3953 return self.api(
3954 self.papi.abf_policy_add_del,
3955 {'is_add': is_add,
3956 'policy': policy})
3957
3958 def abf_itf_attach_add_del(self, is_add, attach):
3959 return self.api(
3960 self.papi.abf_itf_attach_add_del,
3961 {'is_add': is_add,
3962 'attach': attach})
3963
3964 def abf_policy_dump(self):
3965 return self.api(
3966 self.papi.abf_policy_dump, {})
3967
3968 def abf_itf_attach_dump(self):
3969 return self.api(
3970 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003971
3972 def pipe_create(self, is_specified, user_instance):
3973 return self.api(self.papi.pipe_create,
3974 {'is_specified': is_specified,
3975 'user_instance': user_instance})
3976
3977 def pipe_delete(self, parent_sw_if_index):
3978 return self.api(self.papi.pipe_delete,
3979 {'parent_sw_if_index': parent_sw_if_index})
3980
3981 def pipe_dump(self):
3982 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003983
3984 def memif_create(
3985 self,
3986 role,
3987 mode,
3988 rx_queues=None,
3989 tx_queues=None,
3990 _id=None,
3991 socket_id=None,
3992 secret=None,
3993 ring_size=None,
3994 buffer_size=None,
3995 hw_addr=None):
3996 return self.api(self.papi.memif_create,
3997 {'role': role,
3998 'mode': mode,
3999 'rx_queues': rx_queues,
4000 'tx_queues': tx_queues,
4001 'id': _id,
4002 'socket_id': socket_id,
4003 'secret': secret,
4004 'ring_size': ring_size,
4005 'buffer_size': buffer_size,
4006 'hw_addr': hw_addr})
4007
4008 def memif_delete(self, sw_if_index):
4009 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4010
4011 def memif_dump(self):
4012 return self.api(self.papi.memif_dump, {})
4013
4014 def memif_socket_filename_add_del(
4015 self, is_add, socket_id, socket_filename):
4016 return self.api(
4017 self.papi.memif_socket_filename_add_del,
4018 {'is_add': is_add,
4019 'socket_id': socket_id,
4020 'socket_filename': socket_filename})
4021
4022 def memif_socket_filename_dump(self):
4023 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004024
4025 def svs_table_add_del(self, af, table_id, is_add=1):
4026 return self.api(self.papi.svs_table_add_del,
4027 {
4028 'table_id': table_id,
4029 'is_add': is_add,
4030 'af': af,
4031 })
4032
4033 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4034 return self.api(self.papi.svs_route_add_del,
4035 {
4036 'table_id': table_id,
4037 'source_table_id': src_table_id,
4038 'prefix': prefix,
4039 'is_add': is_add,
4040 })
4041
4042 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4043 return self.api(self.papi.svs_enable_disable,
4044 {
4045 'af': af,
4046 'table_id': table_id,
4047 'sw_if_index': sw_if_index,
4048 'is_enable': is_enable,
4049 })
4050
4051 def svs_dump(self):
4052 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004053
4054 def syslog_set_sender(
4055 self,
4056 collector,
4057 src,
4058 collector_port=514,
4059 vrf_id=0,
4060 max_msg_size=480):
4061 """Set syslog sender configuration
4062
4063 :param collector: colector IP address
4064 :param src: source IP address
4065 :param collector_port: collector UDP port (Default value = 514)
4066 :param vrf_id: VRF id (Default value = 0)
4067 :param max_msg_size: maximum message length (Default value = 480)
4068 """
4069 return self.api(self.papi.syslog_set_sender,
4070 {'collector_address': {
4071 'address': collector},
4072 'src_address': {
4073 'address': src},
4074 'collector_port': collector_port,
4075 'vrf_id': vrf_id,
4076 'max_msg_size': max_msg_size})
4077
4078 def syslog_get_sender(self):
4079 """Return syslog sender configuration"""
4080 return self.api(self.papi.syslog_get_sender, {})
4081
4082 def syslog_set_filter(self, severity):
4083 """Set syslog filter parameters
4084
4085 :param severity: severity filter (specified severity and greater match)
4086 """
4087 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4088
4089 def syslog_get_filter(self):
4090 """Return syslog filter parameters"""
4091 return self.api(self.papi.syslog_get_filter, {})