blob: 55bf7ed39cb1de219033971f1df329f54e7c6992 [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
Ole Troan8006c6a2018-12-17 12:02:26 +01007from vpp_papi import mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008from hook import Hook
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -08009from vpp_l2 import L2_PORT_TYPE
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080010
Klement Sekera0e3c0de2016-09-29 14:43:44 +020011# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +010012# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
13# the vpp_papi_provider.py file to be importable without having to build
14# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020015
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -080016try:
Ole Troan7e3a8752016-12-05 10:27:09 +010017 from vpp_papi import VPP
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -080018except ImportError:
19 if not os.getenv("NO_VPP_PAPI") == 1:
20 raise
21 pass
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030029 L2_DISABLED = 0
30 L2_PUSH_1 = 1
31 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000032 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030033 L2_POP_2 = 4
34 L2_TRANSLATE_1_1 = 5
35 L2_TRANSLATE_1_2 = 6
36 L2_TRANSLATE_2_1 = 7
37 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000038
Klement Sekera0e3c0de2016-09-29 14:43:44 +020039
Neale Ranns039cbfe2018-02-27 03:45:38 -080040class QOS_SOURCE:
41 EXT = 0
42 VLAN = 1
43 MPLS = 2
44 IP = 3
45
46
Matus Fabianb4515b42018-11-19 04:25:32 -080047class SYSLOG_SEVERITY:
48 EMERG = 0
49 ALERT = 1
50 CRIT = 2
51 ERR = 3
52 WARN = 4
53 NOTICE = 5
54 INFO = 6
55 DBG = 7
56
57
Klement Sekera73884482017-02-23 09:26:30 +010058class UnexpectedApiReturnValueError(Exception):
59 """ exception raised when the API return value is unexpected """
60 pass
61
62
Klement Sekeraf62ae122016-10-11 11:47:09 +020063class VppPapiProvider(object):
64 """VPP-api provider using vpp-papi
65
66 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020067 """
68
Klement Sekerae0545ef2017-01-25 08:00:40 +010069 _zero, _negative = range(2)
70
Klement Sekera611864f2018-09-26 11:19:00 +020071 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020072 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020073 self.name = name
74 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010075 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010076 self._expect_api_retval = self._zero
77 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010078 jsonfiles = []
79
Klement Sekerab8c72a42018-11-08 11:21:39 +010080 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010081 for root, dirnames, filenames in os.walk(install_dir):
82 for filename in fnmatch.filter(filenames, '*.api.json'):
83 jsonfiles.append(os.path.join(root, filename))
84
Klement Sekera611864f2018-09-26 11:19:00 +020085 self.vpp = VPP(jsonfiles, logger=test_class.logger,
86 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010087 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020088
Klement Sekerae0545ef2017-01-25 08:00:40 +010089 def __enter__(self):
90 return self
91
Klement Sekera7d6afb32018-11-08 11:52:04 +010092 def assert_negative_api_retval(self):
93 """ Expect API failure - used with with, e.g.:
94 with self.vapi.assert_negative_api_retval():
95 self.vapi.<api call expected to fail>
96 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010097 self._expect_stack.append(self._expect_api_retval)
98 self._expect_api_retval = self._negative
99 return self
100
Klement Sekera7d6afb32018-11-08 11:52:04 +0100101 def assert_zero_api_retval(self):
102 """ Expect API success - used with with, e.g.:
103 with self.vapi.assert_negative_api_retval():
104 self.vapi.<api call expected to succeed>
105
106 note: this is useful only inside another with block
107 as success is the default expected value
108 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100109 self._expect_stack.append(self._expect_api_retval)
110 self._expect_api_retval = self._zero
111 return self
112
113 def __exit__(self, exc_type, exc_value, traceback):
114 self._expect_api_retval = self._expect_stack.pop()
115
Klement Sekeraf62ae122016-10-11 11:47:09 +0200116 def register_hook(self, hook):
117 """Replace hook registration with new hook
118
119 :param hook:
120
121 """
122 self.hook = hook
123
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200124 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100125 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200126 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100127 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 return e
129
130 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100131 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100132 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100133 self.test_class.logger.debug("Expecting event '%s' within %ss",
134 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300135 else:
136 self.test_class.logger.debug("Expecting event within %ss",
137 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100138 if self._events:
139 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200140 limit = time.time() + timeout
141 while time.time() < limit:
142 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200144 if name and type(e).__name__ != name:
145 raise Exception(
146 "Unexpected event received: %s, expected: %s" %
147 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100148 self.test_class.logger.debug("Returning event %s:%s" %
149 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200150 return e
151 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200152 raise Exception("Event did not occur within timeout")
153
154 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100155 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200156 # FIXME use the name instead of relying on type(e).__name__ ?
157 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100158 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200159 self._events.append(event)
160
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161 def connect(self):
162 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100163 self.vpp.connect(self.name, self.shm_prefix)
164 self.papi = self.vpp.api
165 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166
167 def disconnect(self):
168 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100169 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200170
171 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100172 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200173 Call the appropriate hooks before and after the API call
174
175 :param api_fn: API function to call
176 :param api_args: tuple of API function arguments
177 :param expected_retval: Expected return value (Default value = 0)
178 :returns: reply from the API
179
180 """
181 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100182 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100183 if self._expect_api_retval == self._negative:
184 if hasattr(reply, 'retval') and reply.retval >= 0:
185 msg = "API call passed unexpectedly: expected negative "\
186 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800187 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100188 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100189 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100190 elif self._expect_api_retval == self._zero:
191 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700192 msg = "API call failed, expected %d return value instead "\
193 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800194 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100195 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100196 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100197 else:
198 raise Exception("Internal error, unexpected value for "
199 "self._expect_api_retval %s" %
200 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 self.hook.after_api(api_fn.__name__, api_args)
202 return reply
203
204 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100205 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206
207 :param cli: CLI to execute
208 :returns: CLI output
209
210 """
211 self.hook.before_cli(cli)
212 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100213 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200214 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200215 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100216 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217
Jan49c0fca2016-10-26 15:44:27 +0200218 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100219 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200220
221 :param cli: CLI to execute
222 :returns: CLI output
223 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600224 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200225
Klement Sekeraf62ae122016-10-11 11:47:09 +0200226 def show_version(self):
227 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100228 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200229
230 def pg_create_interface(self, pg_index):
231 """
232
233 :param pg_index:
234
235 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100236 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200237 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200238
239 def sw_interface_dump(self, filter=None):
240 """
241
242 :param filter: (Default value = None)
243
244 """
245 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200246 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200247 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100248 args = {}
249 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200250
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000251 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100252 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000253
254 :param sw_if_index:
255 :param is_ipv6:
256 :param table_id:
257
258 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100259 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200260 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
261 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000262
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700263 def sw_interface_get_table(self, sw_if_index, is_ipv6):
264 """ Get the IPvX Table-id for the Interface
265
266 :param sw_if_index:
267 :param is_ipv6:
268 :return table_id
269
270 """
271 return self.api(self.papi.sw_interface_get_table,
272 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
273
Klement Sekeraf62ae122016-10-11 11:47:09 +0200274 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
275 is_ipv6=0, is_add=1, del_all=0):
276 """
277
278 :param addr: param is_ipv6: (Default value = 0)
279 :param sw_if_index:
280 :param addr_len:
281 :param is_ipv6: (Default value = 0)
282 :param is_add: (Default value = 1)
283 :param del_all: (Default value = 0)
284
285 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100286 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200287 {'sw_if_index': sw_if_index,
288 'is_add': is_add,
289 'is_ipv6': is_ipv6,
290 'del_all': del_all,
291 'address_length': addr_len,
292 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200293
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700294 def ip_address_dump(self, sw_if_index, is_ipv6=0):
295 return self.api(self.papi.ip_address_dump,
296 {'sw_if_index': sw_if_index,
297 'is_ipv6': is_ipv6})
298
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800299 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
300 is_add=1):
301 """ Set the Interface to be unnumbered
302
303 :param is_add: (Default value = 1)
304 :param sw_if_index - interface That will be unnumbered
305 :param ip_sw_if_index - interface with an IP addres
306
307 """
308 return self.api(self.papi.sw_interface_set_unnumbered,
309 {'sw_if_index': ip_sw_if_index,
310 'unnumbered_sw_if_index': sw_if_index,
311 'is_add': is_add})
312
Neale Ranns404d88e2018-08-08 06:37:33 -0700313 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
314 return self.api(self.papi.ip_unnumbered_dump,
315 {'sw_if_index': sw_if_index})
316
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000317 def sw_interface_enable_disable_mpls(self, sw_if_index,
318 is_enable=1):
319 """
320 Enable/Disable MPLS on the interface
321 :param sw_if_index:
322 :param is_enable: (Default value = 1)
323
324 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100325 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200326 {'sw_if_index': sw_if_index,
327 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000328
Jan Gelety057bb8c2016-12-20 17:32:45 +0100329 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100330 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100331 {'sw_if_index': sw_if_index,
332 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200333
Neale Ranns227038a2017-04-21 01:07:59 -0700334 def set_ip_flow_hash(self,
335 table_id,
336 src=1,
337 dst=1,
338 sport=1,
339 dport=1,
340 proto=1,
341 reverse=0,
342 is_ip6=0):
343 return self.api(self.papi.set_ip_flow_hash,
344 {'vrf_id': table_id,
345 'src': src,
346 'dst': dst,
347 'dport': dport,
348 'sport': sport,
349 'proto': proto,
350 'reverse': reverse,
351 'is_ipv6': is_ip6})
352
Neale Ranns3f844d02017-02-18 00:03:54 -0800353 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
354 return self.api(self.papi.ip6nd_proxy_add_del,
355 {'address': address,
356 'sw_if_index': sw_if_index,
357 'is_del': is_del})
358
Neale Ranns75152282017-01-09 01:00:45 -0800359 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000360 no,
Neale Ranns75152282017-01-09 01:00:45 -0800361 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000362 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800363 return self.api(self.papi.sw_interface_ip6nd_ra_config,
364 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000365 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100366 'suppress': suppress,
367 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800368
Neale Ranns87df12d2017-02-18 08:16:41 -0800369 def ip6_sw_interface_ra_prefix(self,
370 sw_if_index,
371 address,
372 address_length,
373 use_default=0,
374 no_advertise=0,
375 off_link=0,
376 no_autoconfig=0,
377 no_onlink=0,
378 is_no=0,
379 val_lifetime=0xffffffff,
380 pref_lifetime=0xffffffff):
381 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
382 {'sw_if_index': sw_if_index,
383 'address': address,
384 'address_length': address_length,
385 'use_default': use_default,
386 'no_advertise': no_advertise,
387 'off_link': off_link,
388 'no_autoconfig': no_autoconfig,
389 'no_onlink': no_onlink,
390 'is_no': is_no,
391 'val_lifetime': val_lifetime,
392 'pref_lifetime': pref_lifetime})
393
Neale Ranns75152282017-01-09 01:00:45 -0800394 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
395 """
396 Enable/Disable An interface for IPv6
397 """
398 return self.api(self.papi.sw_interface_ip6_enable_disable,
399 {'sw_if_index': sw_if_index,
400 'enable': enable})
401
Klement Sekeraf62ae122016-10-11 11:47:09 +0200402 def vxlan_add_del_tunnel(
403 self,
404 src_addr,
405 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200406 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200407 is_add=1,
408 is_ipv6=0,
409 encap_vrf_id=0,
410 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600411 vni=0,
412 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200413 """
414
415 :param dst_addr:
416 :param src_addr:
417 :param is_add: (Default value = 1)
418 :param is_ipv6: (Default value = 0)
419 :param encap_vrf_id: (Default value = 0)
420 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200421 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200422 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600423 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200424
425 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100426 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200427 {'is_add': is_add,
428 'is_ipv6': is_ipv6,
429 'src_address': src_addr,
430 'dst_address': dst_addr,
431 'mcast_sw_if_index': mcast_sw_if_index,
432 'encap_vrf_id': encap_vrf_id,
433 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600434 'vni': vni,
435 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200436
Marco Varleseb598f1d2017-09-19 14:25:28 +0200437 def geneve_add_del_tunnel(
438 self,
439 local_addr,
440 remote_addr,
441 mcast_sw_if_index=0xFFFFFFFF,
442 is_add=1,
443 is_ipv6=0,
444 encap_vrf_id=0,
445 decap_next_index=0xFFFFFFFF,
446 vni=0):
447 """
448
449 :param remote_addr:
450 :param local_addr:
451 :param is_add: (Default value = 1)
452 :param is_ipv6: (Default value = 0)
453 :param encap_vrf_id: (Default value = 0)
454 :param decap_next_index: (Default value = 0xFFFFFFFF)
455 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
456 :param vni: (Default value = 0)
457
458 """
459 return self.api(self.papi.geneve_add_del_tunnel,
460 {'is_add': is_add,
461 'is_ipv6': is_ipv6,
462 'local_address': local_addr,
463 'remote_address': remote_addr,
464 'mcast_sw_if_index': mcast_sw_if_index,
465 'encap_vrf_id': encap_vrf_id,
466 'decap_next_index': decap_next_index,
467 'vni': vni})
468
Jan4af521d2016-11-15 17:05:00 +0100469 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
470 learn=1, arp_term=0, is_add=1):
471 """Create/delete bridge domain.
472
473 :param int bd_id: Bridge domain index.
474 :param int flood: Enable/disable bcast/mcast flooding in the BD.
475 (Default value = 1)
476 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
477 (Default value = 1)
478 :param int forward: Enable/disable forwarding on all interfaces in
479 the BD. (Default value = 1)
480 :param int learn: Enable/disable learning on all interfaces in the BD.
481 (Default value = 1)
482 :param int arp_term: Enable/disable arp termination in the BD.
483 (Default value = 1)
484 :param int is_add: Add or delete flag. (Default value = 1)
485 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100486 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200487 {'bd_id': bd_id,
488 'flood': flood,
489 'uu_flood': uu_flood,
490 'forward': forward,
491 'learn': learn,
492 'arp_term': arp_term,
493 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100494
Eyal Baric86e5922017-07-02 18:33:16 +0300495 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
496 return self.api(self.papi.bd_ip_mac_add_del,
497 {'bd_id': bd_id,
498 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700499 'ip': ip,
500 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300501
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700502 def bd_ip_mac_dump(self, bd_id):
503 return self.api(self.papi.bd_ip_mac_dump,
504 {'bd_id': bd_id})
505
Eyal Bari20197482017-09-13 12:29:08 +0300506 def want_ip4_arp_events(self, enable_disable=1, address=0):
507 return self.api(self.papi.want_ip4_arp_events,
508 {'enable_disable': enable_disable,
509 'address': address,
510 'pid': os.getpid(), })
511
Eyal Baric125ecc2017-09-20 11:29:17 +0300512 def want_ip6_nd_events(self, enable_disable=1, address=0):
513 return self.api(self.papi.want_ip6_nd_events,
514 {'enable_disable': enable_disable,
515 'address': address,
516 'pid': os.getpid(), })
517
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100518 def want_ip6_ra_events(self, enable_disable=1):
519 return self.api(self.papi.want_ip6_ra_events,
520 {'enable_disable': enable_disable,
521 'pid': os.getpid(), })
522
523 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
524 mrc=0, mrd=0):
525 return self.api(self.papi.ip6nd_send_router_solicitation,
526 {'irt': irt,
527 'mrt': mrt,
528 'mrc': mrc,
529 'mrd': mrd,
530 'sw_if_index': sw_if_index})
531
Juraj Slobodac0374232018-02-01 15:18:49 +0100532 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
533 install_default_routes):
534 return self.api(self.papi.ip6_nd_address_autoconfig,
535 {'sw_if_index': sw_if_index,
536 'enable': enable,
537 'install_default_routes': install_default_routes})
538
Juraj Slobodab3f90502018-10-04 15:15:16 +0200539 def want_interface_events(self, enable_disable=1):
540 return self.api(self.papi.want_interface_events,
541 {'enable_disable': enable_disable,
542 'pid': os.getpid(), })
543
Eyal Bari24db0ec2017-09-27 21:43:51 +0300544 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
545 max_macs_in_event=0, learn_limit=0):
546 return self.api(self.papi.want_l2_macs_events,
547 {'enable_disable': enable_disable,
548 'scan_delay': scan_delay,
549 'max_macs_in_event': max_macs_in_event,
550 'learn_limit': learn_limit,
551 'pid': os.getpid(), })
552
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200553 def want_dhcp6_reply_events(self, enable_disable=1):
554 return self.api(self.papi.want_dhcp6_reply_events,
555 {'enable_disable': enable_disable,
556 'pid': os.getpid()})
557
Juraj Sloboda81119e82018-05-25 14:02:20 +0200558 def want_dhcp6_pd_reply_events(self, enable_disable=1):
559 return self.api(self.papi.want_dhcp6_pd_reply_events,
560 {'enable_disable': enable_disable,
561 'pid': os.getpid()})
562
563 def dhcp6_clients_enable_disable(self, enable=1):
564 return self.api(self.papi.dhcp6_clients_enable_disable,
565 {'enable': enable})
566
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200567 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
568 addresses, server_index=0xFFFFFFFF,
569 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
570 ):
571 return self.api(self.papi.dhcp6_send_client_message,
572 {'sw_if_index': sw_if_index,
573 'server_index': server_index,
574 'irt': irt,
575 'mrt': mrt,
576 'mrc': mrc,
577 'mrd': mrd,
578 'stop': stop,
579 'msg_type': msg_type,
580 'T1': T1,
581 'T2': T2,
582 'n_addresses': len(addresses),
583 'addresses': addresses})
584
Juraj Sloboda81119e82018-05-25 14:02:20 +0200585 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
586 prefixes, server_index=0xFFFFFFFF,
587 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
588 ):
589 return self.api(self.papi.dhcp6_pd_send_client_message,
590 {'sw_if_index': sw_if_index,
591 'server_index': server_index,
592 'irt': irt,
593 'mrt': mrt,
594 'mrc': mrc,
595 'mrd': mrd,
596 'stop': stop,
597 'msg_type': msg_type,
598 'T1': T1,
599 'T2': T2,
600 'n_prefixes': len(prefixes),
601 'prefixes': prefixes})
602
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200603 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
604 enable=1):
605 return self.api(self.papi.dhcp6_client_enable_disable,
606 {'sw_if_index': sw_if_index,
607 'enable': enable})
608
Juraj Sloboda81119e82018-05-25 14:02:20 +0200609 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
610 enable=1):
611 return self.api(self.papi.dhcp6_pd_client_enable_disable,
612 {'sw_if_index': sw_if_index,
613 'prefix_group': prefix_group,
614 'enable': enable})
615
616 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
617 prefix_length, prefix_group,
618 is_add=1):
619 return self.api(self.papi.ip6_add_del_address_using_prefix,
620 {'sw_if_index': sw_if_index,
621 'prefix_group': prefix_group,
622 'address': address,
623 'prefix_length': prefix_length,
624 'is_add': is_add})
625
Jan4af521d2016-11-15 17:05:00 +0100626 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
627 filter_mac=0, bvi_mac=0):
628 """Create/delete L2 FIB entry.
629
630 :param str mac: MAC address to create FIB entry for.
631 :param int bd_id: Bridge domain index.
632 :param int sw_if_index: Software interface index of the interface.
633 :param int is_add: Add or delete flag. (Default value = 1)
634 :param int static_mac: Set to 1 to create static MAC entry.
635 (Default value = 0)
636 :param int filter_mac: Set to 1 to drop packet that's source or
637 destination MAC address contains defined MAC address.
638 (Default value = 0)
639 :param int bvi_mac: Set to 1 to create entry that points to BVI
640 interface. (Default value = 0)
641 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100642 return self.api(self.papi.l2fib_add_del,
Ole Troan8006c6a2018-12-17 12:02:26 +0100643 {'mac': mac,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200644 'bd_id': bd_id,
645 'sw_if_index': sw_if_index,
646 'is_add': is_add,
647 'static_mac': static_mac,
648 'filter_mac': filter_mac,
649 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100650
Eyal Bari93b503e2017-05-15 10:13:15 +0300651 def l2fib_flush_int(self, sw_if_index):
652 """Flush L2 FIB entries for sw_if_index.
653
654 :param int sw_if_index: Software interface index of the interface.
655 """
656 return self.api(self.papi.l2fib_flush_int,
657 {'sw_if_index': sw_if_index})
658
659 def l2fib_flush_bd(self, bd_id):
660 """Flush L2 FIB entries for bd_id.
661
662 :param int sw_if_index: Bridge Domain id.
663 """
664 return self.api(self.papi.l2fib_flush_bd,
665 {'bd_id': bd_id})
666
667 def l2fib_flush_all(self):
668 """Flush all L2 FIB.
669 """
670 return self.api(self.papi.l2fib_flush_all, {})
671
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700672 def l2_fib_table_dump(self, bd_id):
673 """ Dump the L2 FIB """
674 return self.api(self.papi.l2_fib_table_dump,
675 {'bd_id': bd_id})
676
Klement Sekeraf62ae122016-10-11 11:47:09 +0200677 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700678 shg=0, port_type=L2_PORT_TYPE.NORMAL,
679 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100680 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200681
Jan4af521d2016-11-15 17:05:00 +0100682 :param int sw_if_index: Software interface index of the interface.
683 :param int bd_id: Bridge domain index.
684 :param int shg: Split-horizon group index. (Default value = 0)
685 :param int bvi: Set interface as a bridge group virtual interface.
686 (Default value = 0)
687 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200688 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100689 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200690 {'rx_sw_if_index': sw_if_index,
691 'bd_id': bd_id,
692 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700693 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200694 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200695
Jan00dad122016-11-29 10:04:53 +0100696 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400697 """Enable/disable required feature of the bridge domain with defined
698 ID.
Jan00dad122016-11-29 10:04:53 +0100699
700 :param int bd_id: Bridge domain ID.
701 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700702 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100703 - learn (1 << 0),
704 - forward (1 << 1),
705 - flood (1 << 2),
706 - uu-flood (1 << 3) or
707 - arp-term (1 << 4).
708 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100709 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200710 {'bd_id': bd_id,
711 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700712 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100713
714 def bridge_domain_dump(self, bd_id=0):
715 """
716
717 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
718 existing bridge domains returned)
719 :return: Dictionary of bridge domain(s) data.
720 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100721 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200722 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100723
Klement Sekeraf62ae122016-10-11 11:47:09 +0200724 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
725 enable):
726 """Create or delete unidirectional cross-connect from Tx interface to
727 Rx interface.
728
Jan4af521d2016-11-15 17:05:00 +0100729 :param int rx_sw_if_index: Software interface index of Rx interface.
730 :param int tx_sw_if_index: Software interface index of Tx interface.
731 :param int enable: Create cross-connect if equal to 1, delete
732 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200733
734 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100735 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200736 {'rx_sw_if_index': rx_sw_if_index,
737 'tx_sw_if_index': tx_sw_if_index,
738 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200739
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200740 def sw_interface_set_l2_tag_rewrite(
741 self,
742 sw_if_index,
743 vtr_oper,
744 push=0,
745 tag1=0,
746 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000747 """L2 interface vlan tag rewrite configure request
748 :param client_index - opaque cookie to identify the sender
749 :param context - sender context, to match reply w/ request
750 :param sw_if_index - interface the operation is applied to
751 :param vtr_op - Choose from l2_vtr_op_t enum values
752 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
753 :param tag1 - Needed for any push or translate vtr op
754 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
755
756 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100757 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200758 {'sw_if_index': sw_if_index,
759 'vtr_op': vtr_oper,
760 'push_dot1q': push,
761 'tag1': tag1,
762 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000763
Neale Ranns55d03782017-10-21 06:34:22 -0700764 def sw_interface_set_l2_emulation(
765 self,
766 sw_if_index,
767 enable=1):
768 """L2 Emulation
769 :param sw_if_index - interface the operation is applied to
770
771 """
772 return self.api(self.papi.l2_emulation,
773 {'sw_if_index': sw_if_index,
774 'enable': enable})
775
Neale Ranns1855b8e2018-07-11 10:31:26 -0700776 def sw_interface_set_ip_directed_broadcast(
777 self,
778 sw_if_index,
779 enable=1):
780 """IP Directed broadcast
781 :param sw_if_index - interface the operation is applied to
782
783 """
784 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
785 {'sw_if_index': sw_if_index,
786 'enable': enable})
787
Neale Rannsa07bd702017-08-07 07:53:49 -0700788 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200789 """
790
791 :param admin_up_down:
792 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200793
794 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100795 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200796 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700797 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200798
Ole Troand7231612018-06-07 10:17:57 +0200799 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800800 """
801 :param sw_if_index:
802 :param mtu:
803
804 """
805 return self.api(self.papi.sw_interface_set_mtu,
806 {'sw_if_index': sw_if_index,
807 'mtu': mtu})
808
Neale Ranns25b04942018-04-04 09:34:50 -0700809 def sw_interface_set_promiscuous(self, sw_if_index, enable):
810 """
811 :param sw_if_index:
812 :param enable:
813
814 """
815 return self.api(self.papi.sw_interface_set_promiscuous,
816 {'sw_if_index': sw_if_index,
817 'enable': enable})
818
Neale Rannsc819fc62018-02-16 02:44:05 -0800819 def sw_interface_set_mac_address(self, sw_if_index, mac):
820 return self.api(self.papi.sw_interface_set_mac_address,
821 {'sw_if_index': sw_if_index,
822 'mac_address': mac})
823
Klement Sekeraf62ae122016-10-11 11:47:09 +0200824 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
825 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
826 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
827 """Create subinterface
828 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
829
830 :param sub_id: param inner_vlan:
831 :param sw_if_index:
832 :param outer_vlan:
833 :param inner_vlan:
834 :param no_tags: (Default value = 0)
835 :param one_tag: (Default value = 0)
836 :param two_tags: (Default value = 0)
837 :param dot1ad: (Default value = 0)
838 :param exact_match: (Default value = 0)
839 :param default_sub: (Default value = 0)
840 :param outer_vlan_id_any: (Default value = 0)
841 :param inner_vlan_id_any: (Default value = 0)
842
843 """
844 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100845 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200846 {'sw_if_index': sw_if_index,
847 'sub_id': sub_id,
848 'no_tags': no_tags,
849 'one_tag': one_tag,
850 'two_tags': two_tags,
851 'dot1ad': dot1ad,
852 'exact_match': exact_match,
853 'default_sub': default_sub,
854 'outer_vlan_id_any': outer_vlan_id_any,
855 'inner_vlan_id_any': inner_vlan_id_any,
856 'outer_vlan_id': outer_vlan,
857 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200858
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200859 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
860 """Create p2p ethernet subinterface
861
862 :param sw_if_index: main (parent) interface
863 :param remote_mac: client (remote) mac address
864
865 """
866 return self.api(
867 self.papi.p2p_ethernet_add,
868 {'parent_if_index': sw_if_index,
869 'remote_mac': remote_mac,
870 'subif_id': subif_id})
871
Neale Ranns177bbdc2016-11-15 09:46:51 +0000872 def delete_subif(self, sw_if_index):
873 """Delete subinterface
874
875 :param sw_if_index:
876 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100877 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200878 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000879
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200880 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
881 """Delete p2p ethernet subinterface
882
883 :param sw_if_index: main (parent) interface
884 :param remote_mac: client (remote) mac address
885
886 """
887 return self.api(
888 self.papi.p2p_ethernet_del,
889 {'parent_if_index': sw_if_index,
890 'remote_mac': remote_mac})
891
Klement Sekeraf62ae122016-10-11 11:47:09 +0200892 def create_vlan_subif(self, sw_if_index, vlan):
893 """
894
895 :param vlan:
896 :param sw_if_index:
897
898 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100899 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200900 {'sw_if_index': sw_if_index,
901 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200902
Matej Klotton0178d522016-11-04 11:11:44 +0100903 def create_loopback(self, mac=''):
904 """
905
906 :param mac: (Optional)
907 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100908 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200909 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100910
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100911 def delete_loopback(self, sw_if_index):
912 return self.api(self.papi.delete_loopback,
913 {'sw_if_index': sw_if_index, })
914
Neale Ranns15002542017-09-10 04:39:11 -0700915 def ip_table_add_del(self,
916 table_id,
917 is_add=1,
918 is_ipv6=0):
919 """
920
921 :param table_id
922 :param is_add: (Default value = 1)
923 :param is_ipv6: (Default value = 0)
924
925 """
926
927 return self.api(
928 self.papi.ip_table_add_del,
929 {'table_id': table_id,
930 'is_add': is_add,
931 'is_ipv6': is_ipv6})
932
Klement Sekeraf62ae122016-10-11 11:47:09 +0200933 def ip_add_del_route(
934 self,
935 dst_address,
936 dst_address_length,
937 next_hop_address,
938 next_hop_sw_if_index=0xFFFFFFFF,
939 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200940 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000941 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200942 next_hop_n_out_labels=0,
943 next_hop_out_label_stack=[],
944 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800945 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000946 is_resolve_host=0,
947 is_resolve_attached=0,
948 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200949 is_add=1,
950 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200951 is_unreach=0,
952 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200953 is_ipv6=0,
954 is_local=0,
955 is_classify=0,
956 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800957 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800958 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200959 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200960 """
961
962 :param dst_address_length:
963 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
964 :param dst_address:
965 :param next_hop_address:
966 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
967 :param vrf_id: (Default value = 0)
968 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200969 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200970 :param is_add: (Default value = 1)
971 :param is_drop: (Default value = 0)
972 :param is_ipv6: (Default value = 0)
973 :param is_local: (Default value = 0)
974 :param is_classify: (Default value = 0)
975 :param is_multipath: (Default value = 0)
976 :param is_resolve_host: (Default value = 0)
977 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800978 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700979 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200980 :param next_hop_weight: (Default value = 1)
981
982 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000983
Klement Sekeraf62ae122016-10-11 11:47:09 +0200984 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100985 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200986 {'next_hop_sw_if_index': next_hop_sw_if_index,
987 'table_id': table_id,
988 'classify_table_index': classify_table_index,
989 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200990 'is_add': is_add,
991 'is_drop': is_drop,
992 'is_unreach': is_unreach,
993 'is_prohibit': is_prohibit,
994 'is_ipv6': is_ipv6,
995 'is_local': is_local,
996 'is_classify': is_classify,
997 'is_multipath': is_multipath,
998 'is_resolve_host': is_resolve_host,
999 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -08001000 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -07001001 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -08001002 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001003 'next_hop_weight': next_hop_weight,
1004 'dst_address_length': dst_address_length,
1005 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -08001006 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001007 'next_hop_address': next_hop_address,
1008 'next_hop_n_out_labels': next_hop_n_out_labels,
1009 'next_hop_via_label': next_hop_via_label,
1010 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001011
Matej Klotton16a14cd2016-12-07 15:09:13 +01001012 def ip_fib_dump(self):
1013 return self.api(self.papi.ip_fib_dump, {})
1014
Jan Gelety057bb8c2016-12-20 17:32:45 +01001015 def ip6_fib_dump(self):
1016 return self.api(self.papi.ip6_fib_dump, {})
1017
Matej Klotton0178d522016-11-04 11:11:44 +01001018 def ip_neighbor_add_del(self,
1019 sw_if_index,
1020 mac_address,
1021 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001022 is_add=1,
1023 is_ipv6=0,
1024 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001025 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +01001026 ):
1027 """ Add neighbor MAC to IPv4 or IPv6 address.
1028
1029 :param sw_if_index:
1030 :param mac_address:
1031 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001032 :param is_add: (Default value = 1)
1033 :param is_ipv6: (Default value = 0)
1034 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001035 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001036 """
Matej Klotton0178d522016-11-04 11:11:44 +01001037 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001038 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001039 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001040 'is_add': is_add,
1041 'is_ipv6': is_ipv6,
1042 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001043 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001044 'mac_address': mac_address,
1045 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001046 }
Matej Klotton0178d522016-11-04 11:11:44 +01001047 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001048
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001049 def ip_neighbor_dump(self,
1050 sw_if_index,
1051 is_ipv6=0):
1052 """ Return IP neighbor dump.
1053
1054 :param sw_if_index:
1055 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1056 """
1057
1058 return self.api(
1059 self.papi.ip_neighbor_dump,
1060 {'is_ipv6': is_ipv6,
1061 'sw_if_index': sw_if_index
1062 }
1063 )
1064
1065 def proxy_arp_add_del(self,
1066 low_address,
1067 hi_address,
1068 vrf_id=0,
1069 is_add=1):
1070 """ Config Proxy Arp Range.
1071
1072 :param low_address: Start address in the rnage to Proxy for
1073 :param hi_address: End address in the rnage to Proxy for
1074 :param vrf_id: The VRF/table in which to proxy
1075 """
1076
1077 return self.api(
1078 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001079 {'proxy':
1080 {
1081 'vrf_id': vrf_id,
1082 'low_address': low_address,
1083 'hi_address': hi_address,
1084 },
1085 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001086
1087 def proxy_arp_intfc_enable_disable(self,
1088 sw_if_index,
1089 is_enable=1):
1090 """ Enable/Disable an interface for proxy ARP requests
1091
1092 :param sw_if_index: Interface
1093 :param enable_disable: Enable/Disable
1094 """
1095
1096 return self.api(
1097 self.papi.proxy_arp_intfc_enable_disable,
1098 {'sw_if_index': sw_if_index,
1099 'enable_disable': is_enable
1100 }
1101 )
1102
Jane546d3b2016-12-08 13:10:03 +01001103 def reset_vrf(self,
1104 vrf_id,
1105 is_ipv6=0,
1106 ):
1107 """ Reset VRF (remove all routes etc.) request.
1108
1109 :param int vrf_id: ID of the FIB table / VRF to reset.
1110 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1111 """
1112
1113 return self.api(
1114 self.papi.reset_vrf,
1115 {'vrf_id': vrf_id,
1116 'is_ipv6': is_ipv6,
1117 }
1118 )
1119
1120 def reset_fib(self,
1121 vrf_id,
1122 is_ipv6=0,
1123 ):
1124 """ Reset VRF (remove all routes etc.) request.
1125
1126 :param int vrf_id: ID of the FIB table / VRF to reset.
1127 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1128 """
1129
1130 return self.api(
1131 self.papi.reset_fib,
1132 {'vrf_id': vrf_id,
1133 'is_ipv6': is_ipv6,
1134 }
1135 )
1136
1137 def ip_dump(self,
1138 is_ipv6=0,
1139 ):
1140 """ Return IP dump.
1141
1142 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1143 """
1144
1145 return self.api(
1146 self.papi.ip_dump,
1147 {'is_ipv6': is_ipv6,
1148 }
1149 )
1150
Klement Sekera7bb873a2016-11-18 07:38:42 +01001151 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001152 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001153 """
1154
1155 :param sw_if_index_from:
1156 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001157 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001158 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001159 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001160 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001161 {'sw_if_index_from': sw_if_index_from,
1162 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001163 'state': state,
1164 'is_l2': is_l2,
1165 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001166
1167 def gre_tunnel_add_del(self,
1168 src_address,
1169 dst_address,
1170 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001171 tunnel_type=0,
1172 instance=0xFFFFFFFF,
1173 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001174 is_add=1,
1175 is_ip6=0):
1176 """ Add a GRE tunnel
1177
1178 :param src_address:
1179 :param dst_address:
1180 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001181 :param tunnel_type: (Default value = 0)
1182 :param instance: (Default value = 0xFFFFFFFF)
1183 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001184 :param is_add: (Default value = 1)
1185 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001186 """
1187
1188 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001189 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001190 {'is_add': is_add,
1191 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001192 'tunnel_type': tunnel_type,
1193 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001194 'src_address': src_address,
1195 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001196 'outer_fib_id': outer_fib_id,
1197 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001198 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001199
Neale Rannsd0df49f2018-08-08 01:06:40 -07001200 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001201 src_ip,
1202 dst_ip,
1203 src_port,
1204 dst_port,
1205 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001206 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001207 :param src_ip:
1208 :param dst_ip:
1209 :param src_port:
1210 :param dst_port:
1211 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001212 """
1213
1214 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001215 self.papi.udp_encap_add,
1216 {
1217 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001218 'src_ip': src_ip,
1219 'dst_ip': dst_ip,
1220 'src_port': src_port,
1221 'dst_port': dst_port,
1222 'table_id': table_id
1223 }
1224 })
1225
1226 def udp_encap_del(self, id):
1227 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001228
1229 def udp_encap_dump(self):
1230 return self.api(self.papi.udp_encap_dump, {})
1231
Neale Ranns43b1f442018-03-20 01:47:35 -07001232 def want_udp_encap_stats(self, enable=1):
1233 return self.api(self.papi.want_udp_encap_stats,
1234 {'enable': enable,
1235 'pid': os.getpid()})
1236
Neale Ranns5a8123b2017-01-26 01:18:23 -08001237 def mpls_fib_dump(self):
1238 return self.api(self.papi.mpls_fib_dump, {})
1239
Neale Ranns15002542017-09-10 04:39:11 -07001240 def mpls_table_add_del(
1241 self,
1242 table_id,
1243 is_add=1):
1244 """
1245
1246 :param table_id
1247 :param is_add: (Default value = 1)
1248
1249 """
1250
1251 return self.api(
1252 self.papi.mpls_table_add_del,
1253 {'mt_table_id': table_id,
1254 'mt_is_add': is_add})
1255
Neale Rannsad422ed2016-11-02 14:20:04 +00001256 def mpls_route_add_del(
1257 self,
1258 label,
1259 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001260 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001261 next_hop_address,
1262 next_hop_sw_if_index=0xFFFFFFFF,
1263 table_id=0,
1264 next_hop_table_id=0,
1265 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001266 next_hop_n_out_labels=0,
1267 next_hop_out_label_stack=[],
1268 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001269 is_resolve_host=0,
1270 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001271 is_interface_rx=0,
1272 is_rpf_id=0,
1273 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001274 is_add=1,
1275 is_drop=0,
1276 is_multipath=0,
1277 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001278 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001279 """
1280
1281 :param dst_address_length:
1282 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1283 :param dst_address:
1284 :param next_hop_address:
1285 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1286 :param vrf_id: (Default value = 0)
1287 :param lookup_in_vrf: (Default value = 0)
1288 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001289 :param is_add: (Default value = 1)
1290 :param is_drop: (Default value = 0)
1291 :param is_ipv6: (Default value = 0)
1292 :param is_local: (Default value = 0)
1293 :param is_classify: (Default value = 0)
1294 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001295 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001296 :param is_resolve_host: (Default value = 0)
1297 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001298 :param next_hop_weight: (Default value = 1)
1299
1300 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001301 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001302 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001303 {'mr_label': label,
1304 'mr_eos': eos,
1305 'mr_table_id': table_id,
1306 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001307 'mr_is_add': is_add,
1308 'mr_is_classify': is_classify,
1309 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001310 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001311 'mr_is_resolve_host': is_resolve_host,
1312 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001313 'mr_is_interface_rx': is_interface_rx,
1314 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001315 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001316 'mr_next_hop_weight': next_hop_weight,
1317 'mr_next_hop': next_hop_address,
1318 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1319 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1320 'mr_next_hop_table_id': next_hop_table_id,
1321 'mr_next_hop_via_label': next_hop_via_label,
1322 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001323
1324 def mpls_ip_bind_unbind(
1325 self,
1326 label,
1327 dst_address,
1328 dst_address_length,
1329 table_id=0,
1330 ip_table_id=0,
1331 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001332 is_bind=1):
1333 """
1334 """
1335 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001336 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001337 {'mb_mpls_table_id': table_id,
1338 'mb_label': label,
1339 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001340 'mb_is_bind': is_bind,
1341 'mb_is_ip4': is_ip4,
1342 'mb_address_length': dst_address_length,
1343 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001344
1345 def mpls_tunnel_add_del(
1346 self,
1347 tun_sw_if_index,
1348 next_hop_proto_is_ip4,
1349 next_hop_address,
1350 next_hop_sw_if_index=0xFFFFFFFF,
1351 next_hop_table_id=0,
1352 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001353 next_hop_n_out_labels=0,
1354 next_hop_out_label_stack=[],
1355 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001356 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001357 l2_only=0,
1358 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001359 """
1360
1361 :param dst_address_length:
1362 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1363 :param dst_address:
1364 :param next_hop_address:
1365 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1366 :param vrf_id: (Default value = 0)
1367 :param lookup_in_vrf: (Default value = 0)
1368 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001369 :param is_add: (Default value = 1)
1370 :param is_drop: (Default value = 0)
1371 :param is_ipv6: (Default value = 0)
1372 :param is_local: (Default value = 0)
1373 :param is_classify: (Default value = 0)
1374 :param is_multipath: (Default value = 0)
1375 :param is_resolve_host: (Default value = 0)
1376 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001377 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001378 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001379
1380 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001381 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001382 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001383 {'mt_sw_if_index': tun_sw_if_index,
1384 'mt_is_add': is_add,
1385 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001386 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001387 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1388 'mt_next_hop_weight': next_hop_weight,
1389 'mt_next_hop': next_hop_address,
1390 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1391 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1392 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001393 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001394 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001395
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001396 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1397 return self.api(self.papi.mpls_tunnel_dump,
1398 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001399
Matus Fabian2ba92e32017-08-21 07:05:03 -07001400 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001401 self,
1402 sw_if_index,
1403 is_inside=1,
1404 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001405 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001406
1407 :param sw_if_index: Software index of the interface
1408 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1409 :param is_add: 1 if add, 0 if delete (Default value = 1)
1410 """
1411 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001412 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001413 {'is_add': is_add,
1414 'is_inside': is_inside,
1415 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001416
Matus Fabian2ba92e32017-08-21 07:05:03 -07001417 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001418 self,
1419 sw_if_index,
1420 is_inside=1,
1421 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001422 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001423
1424 :param sw_if_index: Software index of the interface
1425 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1426 :param is_add: 1 if add, 0 if delete (Default value = 1)
1427 """
1428 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001429 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001430 {'is_add': is_add,
1431 'is_inside': is_inside,
1432 'sw_if_index': sw_if_index})
1433
Matus Fabian2ba92e32017-08-21 07:05:03 -07001434 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001435 self,
1436 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001437 external_ip=0,
1438 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001439 local_port=0,
1440 external_port=0,
1441 addr_only=1,
1442 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001443 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001444 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001445 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001446 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001447 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001448 is_add=1):
1449 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001450
1451 :param local_ip: Local IP address
1452 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001453 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001454 :param local_port: Local port number (Default value = 0)
1455 :param external_port: External port number (Default value = 0)
1456 :param addr_only: 1 if address only mapping, 0 if address and port
1457 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001458 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001459 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001460 :param self_twice_nat: 1 if translate external host address and port
1461 whenever external host address equals
1462 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001463 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001464 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001465 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001466 """
1467 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001468 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001469 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001470 'addr_only': addr_only,
1471 'local_ip_address': local_ip,
1472 'external_ip_address': external_ip,
1473 'local_port': local_port,
1474 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001475 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001476 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001477 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001478 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001479 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001480 'out2in_only': out2in_only,
1481 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001482
Matus Fabianab7a8052017-11-28 04:29:41 -08001483 def nat44_add_del_identity_mapping(
1484 self,
1485 ip='0',
1486 sw_if_index=0xFFFFFFFF,
1487 port=0,
1488 addr_only=1,
1489 vrf_id=0,
1490 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001491 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001492 is_add=1):
1493 """Add/delete NAT44 identity mapping
1494
1495 :param ip: IP address (Default value = 0)
1496 :param sw_if_index: Interface instead of IP address
1497 :param port: Port number (Default value = 0)
1498 :param addr_only: 1 if address only mapping, 0 if address and port
1499 :param vrf_id: VRF ID
1500 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001501 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001502 :param is_add: 1 if add, 0 if delete (Default value = 1)
1503 """
1504 return self.api(
1505 self.papi.nat44_add_del_identity_mapping,
1506 {'is_add': is_add,
1507 'addr_only': addr_only,
1508 'ip_address': ip,
1509 'port': port,
1510 'sw_if_index': sw_if_index,
1511 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001512 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001513 'protocol': protocol})
1514
Matus Fabian2ba92e32017-08-21 07:05:03 -07001515 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001516 self,
1517 first_ip_address,
1518 last_ip_address,
1519 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001520 vrf_id=0xFFFFFFFF,
1521 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001523
1524 :param first_ip_address: First IP address
1525 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001526 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001527 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001528 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001529 """
1530 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001531 self.papi.nat44_add_del_address_range,
1532 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001533 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001534 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001535 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001536 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001537
Matus Fabian2ba92e32017-08-21 07:05:03 -07001538 def nat44_address_dump(self):
1539 """Dump NAT44 addresses
1540 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001541 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001543
Matus Fabian2ba92e32017-08-21 07:05:03 -07001544 def nat44_interface_dump(self):
1545 """Dump interfaces with NAT44 feature
1546 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001547 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001549
Matus Fabian2ba92e32017-08-21 07:05:03 -07001550 def nat44_interface_output_feature_dump(self):
1551 """Dump interfaces with NAT44 output feature
1552 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001553 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001554 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001555
Matus Fabian2ba92e32017-08-21 07:05:03 -07001556 def nat44_static_mapping_dump(self):
1557 """Dump NAT44 static mappings
1558 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001559 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001561
Matus Fabianab7a8052017-11-28 04:29:41 -08001562 def nat44_identity_mapping_dump(self):
1563 """Dump NAT44 identity mappings
1564 :return: Dictionary of NAT44 identity mappings
1565 """
1566 return self.api(self.papi.nat44_identity_mapping_dump, {})
1567
Matus Fabian2ba92e32017-08-21 07:05:03 -07001568 def nat_show_config(self):
1569 """Show NAT plugin config
1570 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001571 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001573
Matus Fabian2ba92e32017-08-21 07:05:03 -07001574 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001575 self,
1576 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001577 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001578 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001580
1581 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001582 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001583 :param is_add: 1 if add, 0 if delete (Default value = 1)
1584 """
Matus Fabianb932d262017-12-18 05:38:24 -08001585 return self.api(
1586 self.papi.nat44_add_del_interface_addr,
1587 {'is_add': is_add,
1588 'sw_if_index': sw_if_index,
1589 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001590
Matus Fabian2ba92e32017-08-21 07:05:03 -07001591 def nat44_interface_addr_dump(self):
1592 """Dump NAT44 addresses interfaces
1593 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001594 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001595 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001596
Matus Fabian2ba92e32017-08-21 07:05:03 -07001597 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001598 self,
1599 domain_id=1,
1600 src_port=4739,
1601 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001602 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001603
1604 :param domain_id: Observation domain ID (Default value = 1)
1605 :param src_port: Source port number (Default value = 4739)
1606 :param enable: 1 if enable, 0 if disable (Default value = 1)
1607 """
1608 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001609 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001610 {'domain_id': domain_id,
1611 'src_port': src_port,
1612 'enable': enable})
1613
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001615 self,
1616 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001617 vrf_id):
1618 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001619
1620 :param ip_address: ip adress of the user to be dumped
1621 :param cpu_index: cpu_index on which the user is
1622 :param vrf_id: VRF ID
1623 :return: Dictionary of S-NAT sessions
1624 """
1625 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001626 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001627 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001628 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001629
Matus Fabian2ba92e32017-08-21 07:05:03 -07001630 def nat44_user_dump(self):
1631 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001632
Matus Fabian2ba92e32017-08-21 07:05:03 -07001633 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001634 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001635 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001636
Matus Fabian704018c2017-09-04 02:17:18 -07001637 def nat44_add_del_lb_static_mapping(
1638 self,
1639 external_addr,
1640 external_port,
1641 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001642 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001643 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001644 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001645 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001646 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001647 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001648 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001649 is_add=1):
1650 """Add/delete NAT44 load balancing static mapping
1651
Matus Fabianb932d262017-12-18 05:38:24 -08001652 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001653 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001654 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001655 :param is_add - 1 if add, 0 if delete
1656 """
1657 return self.api(
1658 self.papi.nat44_add_del_lb_static_mapping,
1659 {'is_add': is_add,
1660 'external_addr': external_addr,
1661 'external_port': external_port,
1662 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001663 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001664 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001665 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001666 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001667 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001668 'local_num': local_num,
1669 'locals': locals})
1670
Matus Fabianb6865082018-12-06 03:11:09 -08001671 def nat44_lb_static_mapping_add_del_local(
1672 self,
1673 external_addr,
1674 external_port,
1675 local_addr,
1676 local_port,
1677 protocol,
1678 probability,
1679 vrf_id=0,
1680 is_add=1):
1681 """Add/delete NAT44 load-balancing static mapping rule backend
1682
1683 :param external_addr: external IPv4 address of the servic
1684 :param external_port: external L4 port number of the service
1685 :param local_addr: IPv4 address of the internal node
1686 :param local_port: L4 port number of the internal node
1687 :param protocol: IP protocol number
1688 :param probability: probability of the internal node
1689 :param vrf_id: VRF id of the internal node
1690 :param is_add: 1 if add, 0 if delete
1691 """
1692 return self.api(
1693 self.papi.nat44_lb_static_mapping_add_del_local,
1694 {'is_add': is_add,
1695 'external_addr': external_addr,
1696 'external_port': external_port,
1697 'local': {
1698 'addr': local_addr,
1699 'port': local_port,
1700 'probability': probability,
1701 'vrf_id': vrf_id},
1702 'protocol': protocol})
1703
Matus Fabian704018c2017-09-04 02:17:18 -07001704 def nat44_lb_static_mapping_dump(self):
1705 """Dump NAT44 load balancing static mappings
1706
1707 :return: Dictionary of NAT44 load balancing static mapping
1708 """
1709 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1710
Matus Fabian5ba86f72017-10-26 03:37:38 -07001711 def nat44_del_session(
1712 self,
1713 addr,
1714 port,
1715 protocol,
1716 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001717 is_in=1,
1718 ext_host_address=None,
1719 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001720 """Delete NAT44 session
1721
1722 :param addr: IPv4 address
1723 :param por: port number
1724 :param protocol: IP protocol number
1725 :param vrf_id: VRF ID
1726 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001727 :param ext_host_address: external host IPv4 address
1728 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001729 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001730 if ext_host_address is None:
1731 return self.api(
1732 self.papi.nat44_del_session,
1733 {'address': addr,
1734 'port': port,
1735 'protocol': protocol,
1736 'vrf_id': vrf_id,
1737 'is_in': is_in})
1738 else:
1739 return self.api(
1740 self.papi.nat44_del_session,
1741 {'address': addr,
1742 'port': port,
1743 'protocol': protocol,
1744 'vrf_id': vrf_id,
1745 'is_in': is_in,
1746 'ext_host_valid': 1,
1747 'ext_host_address': ext_host_address,
1748 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001749
Juraj Sloboda7b929792017-11-23 13:20:48 +01001750 def nat44_forwarding_enable_disable(
1751 self,
1752 enable):
1753 """Enable/disable forwarding for NAT44
1754
1755 :param enable: 1 for enable, 0 for disable
1756 """
1757 return self.api(
1758 self.papi.nat44_forwarding_enable_disable,
1759 {'enable': enable})
1760
Matus Fabianefcd1e92017-08-15 06:59:19 -07001761 def nat_set_reass(
1762 self,
1763 timeout=2,
1764 max_reass=1024,
1765 max_frag=5,
1766 drop_frag=0,
1767 is_ip6=0):
1768 """Set NAT virtual fragmentation reassembly
1769
1770 :param timeout: reassembly timeout (Default 2sec)
1771 :param max_reass: maximum concurrent reassemblies (Default 1024)
1772 :param max_frag: maximum fragmets per reassembly (Default 5)
1773 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1774 :param is_ip6: 1 if IPv6, 0 if IPv4
1775 """
1776 return self.api(
1777 self.papi.nat_set_reass,
1778 {'timeout': timeout,
1779 'max_reass': max_reass,
1780 'max_frag': max_frag,
1781 'drop_frag': drop_frag,
1782 'is_ip6': is_ip6})
1783
1784 def nat_get_reass(self):
1785 """Get NAT virtual fragmentation reassembly configuration
1786
1787 :return: NAT virtual fragmentation reassembly configuration
1788 """
1789 return self.api(self.papi.nat_get_reass, {})
1790
1791 def nat_reass_dump(self):
1792 """Dump NAT virtual fragmentation reassemblies
1793
1794 :return: Dictionary of NAT virtual fragmentation reassemblies
1795 """
1796 return self.api(self.papi.nat_reass_dump, {})
1797
Matus Fabian2ba92e32017-08-21 07:05:03 -07001798 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001799 self,
1800 in_addr,
1801 in_plen,
1802 out_addr,
1803 out_plen,
1804 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001805 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001806
1807 :param is_add - 1 if add, 0 if delete
1808 :param in_addr - inside IP address
1809 :param in_plen - inside IP address prefix length
1810 :param out_addr - outside IP address
1811 :param out_plen - outside IP address prefix length
1812 """
1813 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001814 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001815 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001816 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001817 'in_addr': in_addr,
1818 'in_plen': in_plen,
1819 'out_addr': out_addr,
1820 'out_plen': out_plen})
1821
Matus Fabian2ba92e32017-08-21 07:05:03 -07001822 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001823 self,
1824 in_addr):
1825 """Get outside address and port range from inside address
1826
1827 :param in_addr - inside IP address
1828 """
1829 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001830 self.papi.nat_det_forward,
1831 {'in_addr': in_addr,
1832 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001833
Matus Fabian2ba92e32017-08-21 07:05:03 -07001834 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001835 self,
1836 out_addr,
1837 out_port):
1838 """Get inside address from outside address and port
1839
1840 :param out_addr - outside IP address
1841 :param out_port - outside port
1842 """
1843 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001844 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001845 {'out_addr': out_addr,
1846 'out_port': out_port})
1847
Matus Fabian2ba92e32017-08-21 07:05:03 -07001848 def nat_det_map_dump(self):
1849 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001850
Matus Fabian2ba92e32017-08-21 07:05:03 -07001851 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001852 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001853 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001854
Matus Fabian878c6462018-08-23 00:33:35 -07001855 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001856 self,
1857 udp=300,
1858 tcp_established=7440,
1859 tcp_transitory=240,
1860 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001861 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001862
1863 :param udp - UDP timeout (Default value = 300)
1864 :param tcp_established - TCP established timeout (Default value = 7440)
1865 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1866 :param icmp - ICMP timeout (Default value = 60)
1867 """
1868 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001869 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001870 {'udp': udp,
1871 'tcp_established': tcp_established,
1872 'tcp_transitory': tcp_transitory,
1873 'icmp': icmp})
1874
Matus Fabian878c6462018-08-23 00:33:35 -07001875 def nat_get_timeouts(self):
1876 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001877
Matus Fabian878c6462018-08-23 00:33:35 -07001878 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001879 """
Matus Fabian878c6462018-08-23 00:33:35 -07001880 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001881
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001882 def nat_set_addr_and_port_alloc_alg(
1883 self,
1884 alg=0,
1885 psid_offset=0,
1886 psid_length=0,
1887 psid=0,
1888 start_port=0,
1889 end_port=0):
1890 """Set address and port assignment algorithm
1891
1892 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1893 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1894 :param psid_length: length of PSID (valid only for MAP-E alg)
1895 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1896 :param start_port: beginning of the port range
1897 :param end_port: end of the port range
1898 """
1899 return self.api(
1900 self.papi.nat_set_addr_and_port_alloc_alg,
1901 {'alg': alg,
1902 'psid_offset': psid_offset,
1903 'psid_length': psid_length,
1904 'psid': psid,
1905 'start_port': start_port,
1906 'end_port': end_port})
1907
1908 def nat_get_addr_and_port_alloc_alg(self):
1909 """Get address and port assignment algorithm"""
1910 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1911
Matus Fabianbb4e0222018-09-13 02:36:25 -07001912 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1913 """Set TCP MSS rewriting configuration
1914
1915 :param enable: disable(0)/enable(1) MSS rewriting feature
1916 :param mss_value: MSS value to be used for MSS rewriting
1917 """
1918 return self.api(
1919 self.papi.nat_set_mss_clamping,
1920 {'enable': enable, 'mss_value': mss_value})
1921
1922 def nat_get_mss_clamping(self):
1923 """Get TCP MSS rewriting configuration"""
1924 return self.api(self.papi.nat_get_mss_clamping, {})
1925
Matus Fabian2ba92e32017-08-21 07:05:03 -07001926 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001927 self,
1928 out_addr,
1929 out_port,
1930 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001931 ext_port):
1932 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001933
1934 :param out_addr - outside IP address
1935 :param out_port - outside port
1936 :param ext_addr - external host IP address
1937 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001938 """
1939 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001940 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001941 {'out_addr': out_addr,
1942 'out_port': out_port,
1943 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001944 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001945
Matus Fabian2ba92e32017-08-21 07:05:03 -07001946 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001947 self,
1948 in_addr,
1949 in_port,
1950 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001951 ext_port):
1952 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001953
1954 :param in_addr - inside IP address
1955 :param in_port - inside port
1956 :param ext_addr - external host IP address
1957 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001958 """
1959 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001960 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001961 {'in_addr': in_addr,
1962 'in_port': in_port,
1963 'ext_addr': ext_addr,
1964 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001965 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001966
Matus Fabian2ba92e32017-08-21 07:05:03 -07001967 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001968 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001969 user_addr):
1970 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001971
1972 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001973 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001974 """
1975 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001976 self.papi.nat_det_session_dump,
1977 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001978 'user_addr': user_addr})
1979
Matus Fabian06596c52017-06-06 04:53:28 -07001980 def nat64_add_del_pool_addr_range(
1981 self,
1982 start_addr,
1983 end_addr,
1984 vrf_id=0xFFFFFFFF,
1985 is_add=1):
1986 """Add/del address range to NAT64 pool
1987
1988 :param start_addr: First IP address
1989 :param end_addr: Last IP address
1990 :param vrf_id: VRF id for the address range
1991 :param is_add: 1 if add, 0 if delete (Default value = 1)
1992 """
1993 return self.api(
1994 self.papi.nat64_add_del_pool_addr_range,
1995 {'start_addr': start_addr,
1996 'end_addr': end_addr,
1997 'vrf_id': vrf_id,
1998 'is_add': is_add})
1999
2000 def nat64_pool_addr_dump(self):
2001 """Dump NAT64 pool addresses
2002 :return: Dictionary of NAT64 pool addresses
2003 """
2004 return self.api(self.papi.nat64_pool_addr_dump, {})
2005
2006 def nat64_add_del_interface(
2007 self,
2008 sw_if_index,
2009 is_inside=1,
2010 is_add=1):
2011 """Enable/disable NAT64 feature on the interface
2012 :param sw_if_index: Index of the interface
2013 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2014 :param is_add: 1 if add, 0 if delete (Default value = 1)
2015 """
2016 return self.api(
2017 self.papi.nat64_add_del_interface,
2018 {'sw_if_index': sw_if_index,
2019 'is_inside': is_inside,
2020 'is_add': is_add})
2021
2022 def nat64_interface_dump(self):
2023 """Dump interfaces with NAT64 feature
2024 :return: Dictionary of interfaces with NAT64 feature
2025 """
2026 return self.api(self.papi.nat64_interface_dump, {})
2027
2028 def nat64_add_del_static_bib(
2029 self,
2030 in_ip,
2031 out_ip,
2032 in_port,
2033 out_port,
2034 protocol,
2035 vrf_id=0,
2036 is_add=1):
2037 """Add/delete S-NAT static BIB entry
2038
2039 :param in_ip: Inside IPv6 address
2040 :param out_ip: Outside IPv4 address
2041 :param in_port: Inside port number
2042 :param out_port: Outside port number
2043 :param protocol: IP protocol
2044 :param vrf_id: VRF ID (Default value = 0)
2045 :param is_add: 1 if add, 0 if delete (Default value = 1)
2046 """
2047 return self.api(
2048 self.papi.nat64_add_del_static_bib,
2049 {'i_addr': in_ip,
2050 'o_addr': out_ip,
2051 'i_port': in_port,
2052 'o_port': out_port,
2053 'vrf_id': vrf_id,
2054 'proto': protocol,
2055 'is_add': is_add})
2056
Matus Fabianab9a59c2017-08-16 05:37:36 -07002057 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002058 """Dump NAT64 BIB
2059
Matus Fabianab9a59c2017-08-16 05:37:36 -07002060 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002061 :returns: Dictionary of NAT64 BIB entries
2062 """
2063 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2064
2065 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2066 tcp_incoming_syn=6):
2067 """Set values of timeouts for NAT64 (in seconds)
2068
Matus Fabian428dc912017-06-21 06:15:18 -07002069 :param udpi: UDP timeout (Default value = 300)
2070 :param icmp: ICMP timeout (Default value = 60)
2071 :param tcp_trans: TCP transitory timeout (Default value = 240)
2072 :param tcp_est: TCP established timeout (Default value = 7440)
2073 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002074 """
2075 return self.api(
2076 self.papi.nat64_set_timeouts,
2077 {'udp': udp,
2078 'icmp': icmp,
2079 'tcp_trans': tcp_trans,
2080 'tcp_est': tcp_est,
2081 'tcp_incoming_syn': tcp_incoming_syn})
2082
2083 def nat64_get_timeouts(self):
2084 """Get values of timeouts for NAT64
2085
2086 :return: Timeouts for NAT64 (in seconds)
2087 """
2088 return self.api(self.papi.nat64_get_timeouts, {})
2089
Matus Fabianab9a59c2017-08-16 05:37:36 -07002090 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002091 """Dump NAT64 session table
2092
Matus Fabianab9a59c2017-08-16 05:37:36 -07002093 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002094 :returns: Dictionary of NAT64 sesstion table entries
2095 """
2096 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2097
Matus Fabian428dc912017-06-21 06:15:18 -07002098 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2099 """Add/del NAT64 prefix
2100
2101 :param prefix: NAT64 prefix
2102 :param plen: NAT64 prefix length
2103 :param vrf_id: VRF id of tenant (Default 0)
2104 :param is_add: 1 if add, 0 if delete (Default value = 1)
2105 """
2106 return self.api(
2107 self.papi.nat64_add_del_prefix,
2108 {'prefix': prefix,
2109 'prefix_len': plen,
2110 'vrf_id': vrf_id,
2111 'is_add': is_add})
2112
2113 def nat64_prefix_dump(self):
2114 """Dump NAT64 prefix
2115
2116 :returns: Dictionary of NAT64 prefixes
2117 """
2118 return self.api(self.papi.nat64_prefix_dump, {})
2119
Matus Fabian0938dcf2017-11-08 01:59:38 -08002120 def nat64_add_interface_addr(
2121 self,
2122 sw_if_index,
2123 is_add=1):
2124 """Add/del NAT64 address from interface
2125
2126 :param sw_if_index: Software index of the interface
2127 :param is_add: 1 if add, 0 if delete (Default value = 1)
2128 """
2129 return self.api(self.papi.nat64_add_del_interface_addr,
2130 {'is_add': is_add, 'sw_if_index': sw_if_index})
2131
Matus Fabian8ebe6252017-11-06 05:04:53 -08002132 def dslite_set_aftr_addr(self, ip6, ip4):
2133 """Set DS-Lite AFTR addresses
2134
2135 :param ip4: IPv4 address
2136 :param ip6: IPv6 address
2137 """
2138 return self.api(
2139 self.papi.dslite_set_aftr_addr,
2140 {'ip4_addr': ip4,
2141 'ip6_addr': ip6})
2142
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002143 def dslite_set_b4_addr(self, ip6, ip4):
2144 """Set DS-Lite B4 IPv6 address
2145
2146 :param ip4: IPv4 address
2147 :param ip6: IPv6 address
2148 """
2149 return self.api(
2150 self.papi.dslite_set_b4_addr,
2151 {'ip4_addr': ip4,
2152 'ip6_addr': ip6})
2153
Matus Fabian8ebe6252017-11-06 05:04:53 -08002154 def dslite_add_del_pool_addr_range(
2155 self,
2156 start_addr,
2157 end_addr,
2158 is_add=1):
2159 """Add/del address range to DS-Lite pool
2160
2161 :param start_addr: First IP address
2162 :param end_addr: Last IP address
2163 :param is_add: 1 if add, 0 if delete (Default value = 1)
2164 """
2165 return self.api(
2166 self.papi.dslite_add_del_pool_addr_range,
2167 {'start_addr': start_addr,
2168 'end_addr': end_addr,
2169 'is_add': is_add})
2170
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002171 def nat66_add_del_interface(
2172 self,
2173 sw_if_index,
2174 is_inside=1,
2175 is_add=1):
2176 """Enable/disable NAT66 feature on the interface
2177 :param sw_if_index: Index of the interface
2178 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2179 :param is_add: 1 if add, 0 if delete (Default value = 1)
2180 """
2181 return self.api(
2182 self.papi.nat66_add_del_interface,
2183 {'sw_if_index': sw_if_index,
2184 'is_inside': is_inside,
2185 'is_add': is_add})
2186
2187 def nat66_add_del_static_mapping(
2188 self,
2189 in_ip,
2190 out_ip,
2191 vrf_id=0,
2192 is_add=1):
2193 """Add/delete NAT66 static mapping
2194
2195 :param in_ip: Inside IPv6 address
2196 :param out_ip: Outside IPv6 address
2197 :param vrf_id: VRF ID (Default value = 0)
2198 :param is_add: 1 if add, 0 if delete (Default value = 1)
2199 """
2200 return self.api(
2201 self.papi.nat66_add_del_static_mapping,
2202 {'local_ip_address': in_ip,
2203 'external_ip_address': out_ip,
2204 'vrf_id': vrf_id,
2205 'is_add': is_add})
2206
2207 def nat66_interface_dump(self):
2208 """Dump interfaces with NAT66 feature
2209 :return: Dictionary of interfaces with NAT66 feature
2210 """
2211 return self.api(self.papi.nat66_interface_dump, {})
2212
2213 def nat66_static_mapping_dump(self):
2214 """Dump NAT66 static mappings
2215 :return: Dictionary of NAT66 static mappings
2216 """
2217 return self.api(self.papi.nat66_static_mapping_dump, {})
2218
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002219 def control_ping(self):
2220 self.api(self.papi.control_ping)
2221
2222 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002223 detect_mult, local_addr, peer_addr, is_ipv6=0,
2224 bfd_key_id=None, conf_key_id=None):
2225 if bfd_key_id is None:
2226 return self.api(self.papi.bfd_udp_add,
2227 {
2228 'sw_if_index': sw_if_index,
2229 'desired_min_tx': desired_min_tx,
2230 'required_min_rx': required_min_rx,
2231 'local_addr': local_addr,
2232 'peer_addr': peer_addr,
2233 'is_ipv6': is_ipv6,
2234 'detect_mult': detect_mult,
2235 })
2236 else:
2237 return self.api(self.papi.bfd_udp_add,
2238 {
2239 'sw_if_index': sw_if_index,
2240 'desired_min_tx': desired_min_tx,
2241 'required_min_rx': required_min_rx,
2242 'local_addr': local_addr,
2243 'peer_addr': peer_addr,
2244 'is_ipv6': is_ipv6,
2245 'detect_mult': detect_mult,
2246 'is_authenticated': 1,
2247 'bfd_key_id': bfd_key_id,
2248 'conf_key_id': conf_key_id,
2249 })
2250
Klement Sekeraa57a9702017-02-02 06:58:07 +01002251 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2252 detect_mult, local_addr, peer_addr, is_ipv6=0):
2253 return self.api(self.papi.bfd_udp_mod,
2254 {
2255 'sw_if_index': sw_if_index,
2256 'desired_min_tx': desired_min_tx,
2257 'required_min_rx': required_min_rx,
2258 'local_addr': local_addr,
2259 'peer_addr': peer_addr,
2260 'is_ipv6': is_ipv6,
2261 'detect_mult': detect_mult,
2262 })
2263
Klement Sekerab17dd962017-01-09 07:43:48 +01002264 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2265 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2266 is_delayed=False):
2267 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002268 {
2269 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002270 'local_addr': local_addr,
2271 'peer_addr': peer_addr,
2272 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002273 'is_delayed': 1 if is_delayed else 0,
2274 'bfd_key_id': bfd_key_id,
2275 'conf_key_id': conf_key_id,
2276 })
2277
2278 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2279 is_ipv6=0, is_delayed=False):
2280 return self.api(self.papi.bfd_udp_auth_deactivate,
2281 {
2282 'sw_if_index': sw_if_index,
2283 'local_addr': local_addr,
2284 'peer_addr': peer_addr,
2285 'is_ipv6': is_ipv6,
2286 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002287 })
2288
2289 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2290 return self.api(self.papi.bfd_udp_del,
2291 {
2292 'sw_if_index': sw_if_index,
2293 'local_addr': local_addr,
2294 'peer_addr': peer_addr,
2295 'is_ipv6': is_ipv6,
2296 })
2297
2298 def bfd_udp_session_dump(self):
2299 return self.api(self.papi.bfd_udp_session_dump, {})
2300
Klement Sekerab17dd962017-01-09 07:43:48 +01002301 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2302 peer_addr, is_ipv6=0):
2303 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002304 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002305 'sw_if_index': sw_if_index,
2306 'local_addr': local_addr,
2307 'peer_addr': peer_addr,
2308 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002309 })
2310
2311 def want_bfd_events(self, enable_disable=1):
2312 return self.api(self.papi.want_bfd_events, {
2313 'enable_disable': enable_disable,
2314 'pid': os.getpid(),
2315 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002316
Klement Sekerab17dd962017-01-09 07:43:48 +01002317 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2318 return self.api(self.papi.bfd_auth_set_key, {
2319 'conf_key_id': conf_key_id,
2320 'auth_type': auth_type,
2321 'key': key,
2322 'key_len': len(key),
2323 })
2324
2325 def bfd_auth_del_key(self, conf_key_id):
2326 return self.api(self.papi.bfd_auth_del_key, {
2327 'conf_key_id': conf_key_id,
2328 })
2329
2330 def bfd_auth_keys_dump(self):
2331 return self.api(self.papi.bfd_auth_keys_dump, {})
2332
Klement Sekera239790f2017-02-16 10:53:53 +01002333 def bfd_udp_set_echo_source(self, sw_if_index):
2334 return self.api(self.papi.bfd_udp_set_echo_source,
2335 {'sw_if_index': sw_if_index})
2336
Klement Sekera73884482017-02-23 09:26:30 +01002337 def bfd_udp_del_echo_source(self):
2338 return self.api(self.papi.bfd_udp_del_echo_source, {})
2339
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002340 def bfd_udp_get_echo_source(self):
2341 return self.api(self.papi.bfd_udp_get_echo_source, {})
2342
Steve Shin7957d6e2016-12-19 09:24:50 -08002343 def classify_add_del_table(
2344 self,
2345 is_add,
2346 mask,
2347 match_n_vectors=1,
2348 table_index=0xFFFFFFFF,
2349 nbuckets=2,
2350 memory_size=2097152,
2351 skip_n_vectors=0,
2352 next_table_index=0xFFFFFFFF,
2353 miss_next_index=0xFFFFFFFF,
2354 current_data_flag=0,
2355 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002356 """
2357 :param is_add:
2358 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002359 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002360 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002361 :param nbuckets: (Default value = 2)
2362 :param memory_size: (Default value = 2097152)
2363 :param skip_n_vectors: (Default value = 0)
2364 :param next_table_index: (Default value = 0xFFFFFFFF)
2365 :param miss_next_index: (Default value = 0xFFFFFFFF)
2366 :param current_data_flag: (Default value = 0)
2367 :param current_data_offset: (Default value = 0)
2368 """
2369
Juraj Sloboda75282452018-06-12 14:20:49 +02002370 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2371 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002372 return self.api(
2373 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002374 {'is_add': is_add,
2375 'table_index': table_index,
2376 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002377 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002378 'skip_n_vectors': skip_n_vectors,
2379 'match_n_vectors': match_n_vectors,
2380 'next_table_index': next_table_index,
2381 'miss_next_index': miss_next_index,
2382 'current_data_flag': current_data_flag,
2383 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002384 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002385 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002386
2387 def classify_add_del_session(
2388 self,
2389 is_add,
2390 table_index,
2391 match,
2392 opaque_index=0xFFFFFFFF,
2393 hit_next_index=0xFFFFFFFF,
2394 advance=0,
2395 action=0,
2396 metadata=0):
2397 """
2398 :param is_add:
2399 :param table_index:
2400 :param match:
2401 :param opaque_index: (Default value = 0xFFFFFFFF)
2402 :param hit_next_index: (Default value = 0xFFFFFFFF)
2403 :param advance: (Default value = 0)
2404 :param action: (Default value = 0)
2405 :param metadata: (Default value = 0)
2406 """
2407
Juraj Sloboda75282452018-06-12 14:20:49 +02002408 match_len = ((len(match) - 1) / 16 + 1) * 16
2409 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002410 return self.api(
2411 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002412 {'is_add': is_add,
2413 'table_index': table_index,
2414 'hit_next_index': hit_next_index,
2415 'opaque_index': opaque_index,
2416 'advance': advance,
2417 'action': action,
2418 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002419 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002420 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002421
2422 def input_acl_set_interface(
2423 self,
2424 is_add,
2425 sw_if_index,
2426 ip4_table_index=0xFFFFFFFF,
2427 ip6_table_index=0xFFFFFFFF,
2428 l2_table_index=0xFFFFFFFF):
2429 """
2430 :param is_add:
2431 :param sw_if_index:
2432 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2433 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2434 :param l2_table_index: (Default value = 0xFFFFFFFF)
2435 """
2436
2437 return self.api(
2438 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002439 {'sw_if_index': sw_if_index,
2440 'ip4_table_index': ip4_table_index,
2441 'ip6_table_index': ip6_table_index,
2442 'l2_table_index': l2_table_index,
2443 'is_add': is_add})
2444
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002445 def output_acl_set_interface(
2446 self,
2447 is_add,
2448 sw_if_index,
2449 ip4_table_index=0xFFFFFFFF,
2450 ip6_table_index=0xFFFFFFFF,
2451 l2_table_index=0xFFFFFFFF):
2452 """
2453 :param is_add:
2454 :param sw_if_index:
2455 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2456 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2457 :param l2_table_index: (Default value = 0xFFFFFFFF)
2458 """
2459
2460 return self.api(
2461 self.papi.output_acl_set_interface,
2462 {'sw_if_index': sw_if_index,
2463 'ip4_table_index': ip4_table_index,
2464 'ip6_table_index': ip6_table_index,
2465 'l2_table_index': l2_table_index,
2466 'is_add': is_add})
2467
Klement Sekera77fabdb2017-01-02 07:46:14 +01002468 def set_ipfix_exporter(
2469 self,
2470 collector_address,
2471 src_address,
2472 path_mtu,
2473 template_interval,
2474 vrf_id=0,
2475 collector_port=4739,
2476 udp_checksum=0):
2477 return self.api(
2478 self.papi.set_ipfix_exporter,
2479 {
2480 'collector_address': collector_address,
2481 'collector_port': collector_port,
2482 'src_address': src_address,
2483 'vrf_id': vrf_id,
2484 'path_mtu': path_mtu,
2485 'template_interval': template_interval,
2486 'udp_checksum': udp_checksum,
2487 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002488
2489 def dhcp_proxy_config(self,
2490 dhcp_server,
2491 dhcp_src_address,
2492 rx_table_id=0,
2493 server_table_id=0,
2494 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002495 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002496 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002497 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002498 {
2499 'rx_vrf_id': rx_table_id,
2500 'server_vrf_id': server_table_id,
2501 'is_ipv6': is_ipv6,
2502 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002503 'dhcp_server': dhcp_server,
2504 'dhcp_src_address': dhcp_src_address,
2505 })
2506
2507 def dhcp_proxy_set_vss(self,
2508 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002509 vss_type=255,
2510 vpn_ascii_id="",
2511 oui=0,
2512 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002513 is_add=1,
2514 is_ip6=0):
2515 return self.api(
2516 self.papi.dhcp_proxy_set_vss,
2517 {
2518 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002519 'vss_type': vss_type,
2520 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002521 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002522 'vpn_index': vpn_index,
2523 'is_add': is_add,
2524 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002525 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002526
Neale Rannsdaff1782018-05-16 04:12:18 -07002527 def dhcp_client_dump(self):
2528 return self.api(self.papi.dhcp_client_dump, {})
2529
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002530 def dhcp_client(self,
2531 sw_if_index,
2532 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002533 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002534 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002535 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002536 want_dhcp_events=0):
2537 return self.api(
2538 self.papi.dhcp_client_config,
2539 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002540 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002541 'client': {
2542 'sw_if_index': sw_if_index,
2543 'hostname': hostname,
2544 'id': client_id,
2545 'want_dhcp_event': want_dhcp_events,
2546 'set_broadcast_flag': set_broadcast_flag,
2547 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002548 })
2549
Neale Ranns32e1c012016-11-22 17:07:28 +00002550 def ip_mroute_add_del(self,
2551 src_address,
2552 grp_address,
2553 grp_address_length,
2554 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002555 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002556 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002557 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002558 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002559 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002560 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002561 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002562 is_add=1,
2563 is_ipv6=0,
2564 is_local=0):
2565 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002566 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002567 """
2568 return self.api(
2569 self.papi.ip_mroute_add_del,
2570 {'next_hop_sw_if_index': next_hop_sw_if_index,
2571 'entry_flags': e_flags,
2572 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002573 'table_id': table_id,
2574 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002575 'is_add': is_add,
2576 'is_ipv6': is_ipv6,
2577 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002578 'bier_imp': bier_imp,
2579 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002580 'grp_address_length': grp_address_length,
2581 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002582 'src_address': src_address,
2583 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002584
2585 def mfib_signal_dump(self):
2586 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002587
2588 def ip_mfib_dump(self):
2589 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002590
Neale Rannsd792d9c2017-10-21 10:53:20 -07002591 def ip6_mfib_dump(self):
2592 return self.api(self.papi.ip6_mfib_dump, {})
2593
Filip Tehlar770e89e2017-01-31 10:39:16 +01002594 def lisp_enable_disable(self, is_enabled):
2595 return self.api(
2596 self.papi.lisp_enable_disable,
2597 {
2598 'is_en': is_enabled,
2599 })
2600
2601 def lisp_locator_set(self,
2602 ls_name,
2603 is_add=1):
2604 return self.api(
2605 self.papi.lisp_add_del_locator_set,
2606 {
2607 'is_add': is_add,
2608 'locator_set_name': ls_name
2609 })
2610
2611 def lisp_locator_set_dump(self):
2612 return self.api(self.papi.lisp_locator_set_dump, {})
2613
2614 def lisp_locator(self,
2615 ls_name,
2616 sw_if_index,
2617 priority=1,
2618 weight=1,
2619 is_add=1):
2620 return self.api(
2621 self.papi.lisp_add_del_locator,
2622 {
2623 'is_add': is_add,
2624 'locator_set_name': ls_name,
2625 'sw_if_index': sw_if_index,
2626 'priority': priority,
2627 'weight': weight
2628 })
2629
2630 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2631 return self.api(
2632 self.papi.lisp_locator_dump,
2633 {
2634 'is_index_set': is_index_set,
2635 'ls_name': ls_name,
2636 'ls_index': ls_index,
2637 })
2638
2639 def lisp_local_mapping(self,
2640 ls_name,
2641 eid_type,
2642 eid,
2643 prefix_len,
2644 vni=0,
2645 key_id=0,
2646 key="",
2647 is_add=1):
2648 return self.api(
2649 self.papi.lisp_add_del_local_eid,
2650 {
2651 'locator_set_name': ls_name,
2652 'is_add': is_add,
2653 'eid_type': eid_type,
2654 'eid': eid,
2655 'prefix_len': prefix_len,
2656 'vni': vni,
2657 'key_id': key_id,
2658 'key': key
2659 })
2660
2661 def lisp_eid_table_dump(self,
2662 eid_set=0,
2663 prefix_length=0,
2664 vni=0,
2665 eid_type=0,
2666 eid=None,
2667 filter_opt=0):
2668 return self.api(
2669 self.papi.lisp_eid_table_dump,
2670 {
2671 'eid_set': eid_set,
2672 'prefix_length': prefix_length,
2673 'vni': vni,
2674 'eid_type': eid_type,
2675 'eid': eid,
2676 'filter': filter_opt,
2677 })
2678
2679 def lisp_remote_mapping(self,
2680 eid_type,
2681 eid,
2682 eid_prefix_len=0,
2683 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002684 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002685 rlocs_num=0,
2686 is_src_dst=0,
2687 is_add=1):
2688 return self.api(
2689 self.papi.lisp_add_del_remote_mapping,
2690 {
2691 'is_add': is_add,
2692 'eid_type': eid_type,
2693 'eid': eid,
2694 'eid_len': eid_prefix_len,
2695 'rloc_num': rlocs_num,
2696 'rlocs': rlocs,
2697 'vni': vni,
2698 'is_src_dst': is_src_dst,
2699 })
2700
2701 def lisp_adjacency(self,
2702 leid,
2703 reid,
2704 leid_len,
2705 reid_len,
2706 eid_type,
2707 is_add=1,
2708 vni=0):
2709 return self.api(
2710 self.papi.lisp_add_del_adjacency,
2711 {
2712 'is_add': is_add,
2713 'vni': vni,
2714 'eid_type': eid_type,
2715 'leid': leid,
2716 'reid': reid,
2717 'leid_len': leid_len,
2718 'reid_len': reid_len,
2719 })
2720
2721 def lisp_adjacencies_get(self, vni=0):
2722 return self.api(
2723 self.papi.lisp_adjacencies_get,
2724 {
2725 'vni': vni
2726 })
Neale Ranns80823802017-02-20 18:23:41 -08002727
2728 def map_add_domain(self,
2729 ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002730 ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002731 ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002732 ea_bits_len=0,
2733 psid_offset=0,
2734 psid_length=0,
Neale Ranns80823802017-02-20 18:23:41 -08002735 mtu=1280):
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002736
Neale Ranns80823802017-02-20 18:23:41 -08002737 return self.api(
2738 self.papi.map_add_domain,
2739 {
2740 'ip6_prefix': ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002741 'ip4_prefix': ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002742 'ip6_src': ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002743 'ea_bits_len': ea_bits_len,
2744 'psid_offset': psid_offset,
2745 'psid_length': psid_length,
Neale Ranns80823802017-02-20 18:23:41 -08002746 'mtu': mtu
2747 })
Hongjun Nief486b12017-04-12 19:21:16 +08002748
Jon Loeligerfc7344f2018-12-20 11:47:30 -06002749 def map_if_enable_disable(self, is_enable, sw_if_index, is_translation):
2750 return self.api(
2751 self.papi.map_if_enable_disable,
2752 {
2753 'is_enable': is_enable,
2754 'sw_if_index': sw_if_index,
2755 'is_translation': is_translation,
2756 })
2757
2758 def map_param_set_tcp(self, tcp_mss):
2759 return self.api(
2760 self.papi.map_param_set_tcp,
2761 {
2762 'tcp_mss': tcp_mss,
2763 })
2764
Hongjun Nief486b12017-04-12 19:21:16 +08002765 def gtpu_add_del_tunnel(
2766 self,
2767 src_addr,
2768 dst_addr,
2769 is_add=1,
2770 is_ipv6=0,
2771 mcast_sw_if_index=0xFFFFFFFF,
2772 encap_vrf_id=0,
2773 decap_next_index=0xFFFFFFFF,
2774 teid=0):
2775 """
2776
2777 :param is_add: (Default value = 1)
2778 :param is_ipv6: (Default value = 0)
2779 :param src_addr:
2780 :param dst_addr:
2781 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2782 :param encap_vrf_id: (Default value = 0)
2783 :param decap_next_index: (Default value = 0xFFFFFFFF)
2784 :param teid: (Default value = 0)
2785
2786 """
2787 return self.api(self.papi.gtpu_add_del_tunnel,
2788 {'is_add': is_add,
2789 'is_ipv6': is_ipv6,
2790 'src_address': src_addr,
2791 'dst_address': dst_addr,
2792 'mcast_sw_if_index': mcast_sw_if_index,
2793 'encap_vrf_id': encap_vrf_id,
2794 'decap_next_index': decap_next_index,
2795 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002796
2797 def vxlan_gpe_add_del_tunnel(
2798 self,
2799 src_addr,
2800 dst_addr,
2801 mcast_sw_if_index=0xFFFFFFFF,
2802 is_add=1,
2803 is_ipv6=0,
2804 encap_vrf_id=0,
2805 decap_vrf_id=0,
2806 protocol=3,
2807 vni=0):
2808 """
2809
2810 :param local:
2811 :param remote:
2812 :param is_add: (Default value = 1)
2813 :param is_ipv6: (Default value = 0)
2814 :param encap_vrf_id: (Default value = 0)
2815 :param decap_vrf_id: (Default value = 0)
2816 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2817 :param protocol: (Default value = 3)
2818 :param vni: (Default value = 0)
2819
2820 """
2821 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2822 {'is_add': is_add,
2823 'is_ipv6': is_ipv6,
2824 'local': src_addr,
2825 'remote': dst_addr,
2826 'mcast_sw_if_index': mcast_sw_if_index,
2827 'encap_vrf_id': encap_vrf_id,
2828 'decap_vrf_id': decap_vrf_id,
2829 'protocol': protocol,
2830 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002831
Neale Ranns79a05f52018-09-11 07:39:43 -07002832 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002833 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002834 src,
2835 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002836 mcast_sw_if_index=0xFFFFFFFF,
2837 is_add=1,
2838 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002839 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002840 vni=0,
2841 instance=0xFFFFFFFF):
2842 """
2843
2844 :param dst_addr:
2845 :param src_addr:
2846 :param is_add: (Default value = 1)
2847 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002848 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002849 :param decap_next_index: (Default value = 0xFFFFFFFF)
2850 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2851 :param vni: (Default value = 0)
2852 :param instance: (Default value = 0xFFFFFFFF)
2853
2854 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002855 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002856 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002857 'tunnel': {
2858 'src': src,
2859 'dst': dst,
2860 'mcast_sw_if_index': mcast_sw_if_index,
2861 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002862 'vni': vni,
2863 'instance': instance}})
2864
2865 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2866 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01002867 {'sw_if_index': sw_if_index,
2868 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002869
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002870 def pppoe_add_del_session(
2871 self,
2872 client_ip,
2873 client_mac,
2874 session_id=0,
2875 is_add=1,
2876 is_ipv6=0,
2877 decap_vrf_id=0):
2878 """
2879
2880 :param is_add: (Default value = 1)
2881 :param is_ipv6: (Default value = 0)
2882 :param client_ip:
2883 :param session_id: (Default value = 0)
2884 :param client_mac:
2885 :param decap_vrf_id: (Default value = 0)
2886
2887 """
2888 return self.api(self.papi.pppoe_add_del_session,
2889 {'is_add': is_add,
2890 'is_ipv6': is_ipv6,
2891 'session_id': session_id,
2892 'client_ip': client_ip,
2893 'decap_vrf_id': decap_vrf_id,
2894 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002895
Neale Ranns7c922dc2018-08-30 06:12:27 -07002896 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2897 return self.api(self.papi.sr_mpls_policy_add,
2898 {'bsid': bsid,
2899 'weight': weight,
2900 'type': type,
2901 'n_segments': len(segments),
2902 'segments': segments})
2903
2904 def sr_mpls_policy_del(self, bsid):
2905 return self.api(self.papi.sr_mpls_policy_del,
2906 {'bsid': bsid})
2907
Kris Michielsen91074432017-06-22 13:00:20 +02002908 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002909 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002910 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002911 nh_addr4,
2912 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002913 is_del=0,
2914 end_psp=0,
2915 sw_if_index=0xFFFFFFFF,
2916 vlan_index=0,
2917 fib_table=0,
2918 ):
2919 """ Add/del IPv6 SR local-SID.
2920
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002921 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002922 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2923 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002924 :param nh_addr4:
2925 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002926 :param is_del: (Default value = 0)
2927 :param end_psp: (Default value = 0)
2928 :param sw_if_index: (Default value = 0xFFFFFFFF)
2929 :param vlan_index: (Default value = 0)
2930 :param fib_table: (Default value = 0)
2931 """
2932 return self.api(
2933 self.papi.sr_localsid_add_del,
2934 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002935 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002936 'end_psp': end_psp,
2937 'behavior': behavior,
2938 'sw_if_index': sw_if_index,
2939 'vlan_index': vlan_index,
2940 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002941 'nh_addr4': nh_addr4,
2942 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002943 }
2944 )
2945
2946 def sr_policy_add(
2947 self,
2948 bsid_addr,
2949 weight=1,
2950 is_encap=1,
2951 type=0,
2952 fib_table=0,
2953 n_segments=0,
2954 segments=[]):
2955 """
2956 :param bsid_addr: bindingSID of the SR Policy
2957 :param weight: weight of the sid list. optional. (default: 1)
2958 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2959 (default: Encap)
2960 :param type: type/behavior of the SR policy. (default or spray) \
2961 (default: default)
2962 :param fib_table: VRF where to install the FIB entry for the BSID \
2963 (default: 0)
2964 :param n_segments: number of segments \
2965 (default: 0)
2966 :param segments: a vector of IPv6 address composing the segment list \
2967 (default: [])
2968 """
2969 return self.api(
2970 self.papi.sr_policy_add,
2971 {'bsid_addr': bsid_addr,
2972 'weight': weight,
2973 'is_encap': is_encap,
2974 'type': type,
2975 'fib_table': fib_table,
2976 'n_segments': n_segments,
2977 'segments': segments
2978 }
2979 )
2980
2981 def sr_policy_del(
2982 self,
2983 bsid_addr,
2984 sr_policy_index=0):
2985 """
2986 :param bsid: bindingSID of the SR Policy
2987 :param sr_policy_index: index of the sr policy (default: 0)
2988 """
2989 return self.api(
2990 self.papi.sr_policy_del,
2991 {'bsid_addr': bsid_addr,
2992 'sr_policy_index': sr_policy_index
2993 })
2994
2995 def sr_steering_add_del(
2996 self,
2997 is_del,
2998 bsid_addr,
2999 sr_policy_index,
3000 table_id,
3001 prefix_addr,
3002 mask_width,
3003 sw_if_index,
3004 traffic_type):
3005 """
3006 Steer traffic L2 and L3 traffic through a given SR policy
3007
3008 :param is_del: delete or add
3009 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
3010 :param sr_policy: is the index of the SR Policy (alt to bsid)
3011 :param table_id: is the VRF where to install the FIB entry for the BSID
3012 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
3013 :param mask_width: is the mask for L3 traffic type
3014 :param sw_if_index: is the incoming interface for L2 traffic
3015 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
3016 """
3017 return self.api(
3018 self.papi.sr_steering_add_del,
3019 {'is_del': is_del,
3020 'bsid_addr': bsid_addr,
3021 'sr_policy_index': sr_policy_index,
3022 'table_id': table_id,
3023 'prefix_addr': prefix_addr,
3024 'mask_width': mask_width,
3025 'sw_if_index': sw_if_index,
3026 'traffic_type': traffic_type
3027 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02003028
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003029 def acl_add_replace(self, acl_index, r, tag='',
3030 expected_retval=0):
3031 """Add/replace an ACL
3032 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
3033 :param acl_rule r: ACL rules array.
3034 :param str tag: symbolic tag (description) for this ACL.
3035 :param int count: number of rules.
3036 """
3037 return self.api(self.papi.acl_add_replace,
3038 {'acl_index': acl_index,
3039 'r': r,
3040 'count': len(r),
3041 'tag': tag},
3042 expected_retval=expected_retval)
3043
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003044 def acl_del(self, acl_index, expected_retval=0):
3045 """
3046
3047 :param acl_index:
3048 :return:
3049 """
3050 return self.api(self.papi.acl_del,
3051 {'acl_index': acl_index},
3052 expected_retval=expected_retval)
3053
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003054 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3055 expected_retval=0):
3056 return self.api(self.papi.acl_interface_set_acl_list,
3057 {'sw_if_index': sw_if_index,
3058 'count': len(acls),
3059 'n_input': n_input,
3060 'acls': acls},
3061 expected_retval=expected_retval)
3062
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003063 def acl_interface_set_etype_whitelist(self, sw_if_index,
3064 n_input, whitelist,
3065 expected_retval=0):
3066 return self.api(self.papi.acl_interface_set_etype_whitelist,
3067 {'sw_if_index': sw_if_index,
3068 'count': len(whitelist),
3069 'n_input': n_input,
3070 'whitelist': whitelist},
3071 expected_retval=expected_retval)
3072
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003073 def acl_interface_add_del(self,
3074 sw_if_index,
3075 acl_index,
3076 is_add=1):
3077 """ Add/Delete ACL to/from interface
3078
3079 :param sw_if_index:
3080 :param acl_index:
3081 :param is_add: (Default value = 1)
3082 """
3083
3084 return self.api(self.papi.acl_interface_add_del,
3085 {'is_add': is_add,
3086 'is_input': 1,
3087 'sw_if_index': sw_if_index,
3088 'acl_index': acl_index})
3089
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003090 def acl_dump(self, acl_index, expected_retval=0):
3091 return self.api(self.papi.acl_dump,
3092 {'acl_index': acl_index},
3093 expected_retval=expected_retval)
3094
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003095 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3096 expected_retval=0):
3097 return self.api(self.papi.acl_interface_list_dump,
3098 {'sw_if_index': sw_if_index},
3099 expected_retval=expected_retval)
3100
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003101 def macip_acl_add(self, rules, tag=""):
3102 """ Add MACIP acl
3103
3104 :param rules: list of rules for given acl
3105 :param tag: acl tag
3106 """
3107
3108 return self.api(self.papi.macip_acl_add,
3109 {'r': rules,
3110 'count': len(rules),
3111 'tag': tag})
3112
Pavel Kotucek932f7412017-09-07 14:44:52 +02003113 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3114 """ Add MACIP acl
3115
3116 :param rules: list of rules for given acl
3117 :param tag: acl tag
3118 """
3119
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003120 return self.api(self.papi.macip_acl_add_replace,
3121 {'acl_index': acl_index,
3122 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003123 'count': len(rules),
3124 'tag': tag})
3125
3126 def macip_acl_del(self, acl_index):
3127 """
3128
3129 :param acl_index:
3130 :return:
3131 """
3132 return self.api(self.papi.macip_acl_del,
3133 {'acl_index': acl_index})
3134
3135 def macip_acl_interface_add_del(self,
3136 sw_if_index,
3137 acl_index,
3138 is_add=1):
3139 """ Add MACIP acl to interface
3140
3141 :param sw_if_index:
3142 :param acl_index:
3143 :param is_add: (Default value = 1)
3144 """
3145
3146 return self.api(self.papi.macip_acl_interface_add_del,
3147 {'is_add': is_add,
3148 'sw_if_index': sw_if_index,
3149 'acl_index': acl_index})
3150
3151 def macip_acl_interface_get(self):
3152 """ Return interface acls dump
3153 """
3154 return self.api(
3155 self.papi.macip_acl_interface_get, {})
3156
3157 def macip_acl_dump(self, acl_index=4294967295):
3158 """ Return MACIP acl dump
3159 """
3160
3161 return self.api(
3162 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003163
3164 def policer_add_del(self,
3165 name,
3166 cir,
3167 eir,
3168 cb,
3169 eb,
3170 is_add=1,
3171 rate_type=0,
3172 round_type=0,
3173 ptype=0,
3174 color_aware=0,
3175 conform_action_type=1,
3176 conform_dscp=0,
3177 exceed_action_type=0,
3178 exceed_dscp=0,
3179 violate_action_type=0,
3180 violate_dscp=0):
3181 return self.api(self.papi.policer_add_del,
3182 {'name': name,
3183 'cir': cir,
3184 'eir': eir,
3185 'cb': cb,
3186 'eb': eb,
3187 'is_add': is_add,
3188 'rate_type': rate_type,
3189 'round_type': round_type,
3190 'type': ptype,
3191 'color_aware': color_aware,
3192 'conform_action_type': conform_action_type,
3193 'conform_dscp': conform_dscp,
3194 'exceed_action_type': exceed_action_type,
3195 'exceed_dscp': exceed_dscp,
3196 'violate_action_type': violate_action_type,
3197 'violate_dscp': violate_dscp})
3198
3199 def ip_punt_police(self,
3200 policer_index,
3201 is_ip6=0,
3202 is_add=1):
3203 return self.api(self.papi.ip_punt_police,
3204 {'policer_index': policer_index,
3205 'is_add': is_add,
3206 'is_ip6': is_ip6})
3207
3208 def ip_punt_redirect(self,
3209 rx_sw_if_index,
3210 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003211 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003212 is_add=1):
3213 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003214 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3215 'tx_sw_if_index': tx_sw_if_index,
3216 'nh': address},
3217 'is_add': is_add})
3218
3219 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3220 return self.api(self.papi.ip_punt_redirect_dump,
3221 {'sw_if_index': sw_if_index,
3222 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003223
3224 def bier_table_add_del(self,
3225 bti,
3226 mpls_label,
3227 is_add=1):
3228 """ BIER Table add/del """
3229 return self.api(
3230 self.papi.bier_table_add_del,
3231 {'bt_tbl_id': {"bt_set": bti.set_id,
3232 "bt_sub_domain": bti.sub_domain_id,
3233 "bt_hdr_len_id": bti.hdr_len_id},
3234 'bt_label': mpls_label,
3235 'bt_is_add': is_add})
3236
3237 def bier_table_dump(self):
3238 return self.api(self.papi.bier_table_dump, {})
3239
3240 def bier_route_add_del(self,
3241 bti,
3242 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003243 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003244 is_add=1,
3245 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003246 """ BIER Route add/del """
3247 return self.api(
3248 self.papi.bier_route_add_del,
3249 {'br_tbl_id': {"bt_set": bti.set_id,
3250 "bt_sub_domain": bti.sub_domain_id,
3251 "bt_hdr_len_id": bti.hdr_len_id},
3252 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003253 'br_n_paths': len(paths),
3254 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003255 'br_is_add': is_add,
3256 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003257
3258 def bier_route_dump(self, bti):
3259 return self.api(
3260 self.papi.bier_route_dump,
3261 {'br_tbl_id': {"bt_set": bti.set_id,
3262 "bt_sub_domain": bti.sub_domain_id,
3263 "bt_hdr_len_id": bti.hdr_len_id}})
3264
3265 def bier_imp_add(self,
3266 bti,
3267 src,
3268 ibytes,
3269 is_add=1):
3270 """ BIER Imposition Add """
3271 return self.api(
3272 self.papi.bier_imp_add,
3273 {'bi_tbl_id': {"bt_set": bti.set_id,
3274 "bt_sub_domain": bti.sub_domain_id,
3275 "bt_hdr_len_id": bti.hdr_len_id},
3276 'bi_src': src,
3277 'bi_n_bytes': len(ibytes),
3278 'bi_bytes': ibytes})
3279
3280 def bier_imp_del(self, bi_index):
3281 """ BIER Imposition del """
3282 return self.api(
3283 self.papi.bier_imp_del,
3284 {'bi_index': bi_index})
3285
3286 def bier_imp_dump(self):
3287 return self.api(self.papi.bier_imp_dump, {})
3288
3289 def bier_disp_table_add_del(self,
3290 bdti,
3291 is_add=1):
3292 """ BIER Disposition Table add/del """
3293 return self.api(
3294 self.papi.bier_disp_table_add_del,
3295 {'bdt_tbl_id': bdti,
3296 'bdt_is_add': is_add})
3297
3298 def bier_disp_table_dump(self):
3299 return self.api(self.papi.bier_disp_table_dump, {})
3300
3301 def bier_disp_entry_add_del(self,
3302 bdti,
3303 bp,
3304 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003305 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003306 next_hop,
3307 next_hop_tbl_id=0,
3308 next_hop_rpf_id=~0,
3309 next_hop_is_ip4=1,
3310 is_add=1):
3311 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003312 lstack = []
3313 while (len(lstack) < 16):
3314 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003315 return self.api(
3316 self.papi.bier_disp_entry_add_del,
3317 {'bde_tbl_id': bdti,
3318 'bde_bp': bp,
3319 'bde_payload_proto': payload_proto,
3320 'bde_n_paths': 1,
3321 'bde_paths': [{'next_hop': next_hop,
3322 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003323 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003324 'rpf_id': next_hop_rpf_id,
3325 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003326 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003327 'bde_is_add': is_add})
3328
3329 def bier_disp_entry_dump(self, bdti):
3330 return self.api(
3331 self.papi.bier_disp_entry_dump,
3332 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003333
3334 def add_node_next(self, node_name, next_name):
3335 """ Set the next node for a given node request
3336
3337 :param node_name:
3338 :param next_name:
3339 """
3340 return self.api(self.papi.add_node_next,
3341 {'node_name': node_name,
3342 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003343
3344 def session_enable_disable(self, is_enabled):
3345 return self.api(
3346 self.papi.session_enable_disable,
3347 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003348
3349 def ipsec_spd_add_del(self, spd_id, is_add=1):
3350 """ SPD add/del - Wrapper to add or del ipsec SPD
3351 Sample CLI : 'ipsec spd add 1'
3352
3353 :param spd_id - SPD ID to be created in the vpp . mandatory
3354 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3355 optional
3356 :returns: reply from the API
3357 """
3358 return self.api(
3359 self.papi.ipsec_spd_add_del, {
3360 'spd_id': spd_id, 'is_add': is_add})
3361
3362 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3363 """ IPSEC interface SPD add/del - \
3364 Wrapper to associate/disassociate SPD to interface in VPP
3365 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3366
3367 :param spd_id - SPD ID to associate with the interface . mandatory
3368 :param sw_if_index - Interface Index which needs to ipsec \
3369 association mandatory
3370 :param is_add - add(1) or del(0) association with interface \
3371 (Default 1 - add) . optional
3372 :returns: reply from the API
3373 """
3374 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003375 self.papi.ipsec_interface_add_del_spd,
3376 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003377
3378 def ipsec_sad_add_del_entry(self,
3379 sad_id,
3380 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003381 integrity_algorithm,
3382 integrity_key,
3383 crypto_algorithm,
3384 crypto_key,
3385 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003386 tunnel_src_address='',
3387 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003388 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003389 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003390 is_add=1,
Neale Rannsde847272018-11-28 01:38:34 -08003391 udp_encap=0,
3392 use_anti_replay=0,
3393 use_extended_sequence_number=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003394 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003395 :param sad_id: security association ID
3396 :param spi: security param index of the SA in decimal
3397 :param integrity_algorithm:
3398 :param integrity_key:
3399 :param crypto_algorithm:
3400 :param crypto_key:
3401 :param protocol: AH(0) or ESP(1) protocol
3402 :param tunnel_src_address: tunnel mode outer src address
3403 :param tunnel_dst_address: tunnel mode outer dst address
3404 :param is_add:
3405 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003406 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3407 crypto and ipsec algorithms
3408 """
3409 return self.api(
3410 self.papi.ipsec_sad_add_del_entry,
3411 {'sad_id': sad_id,
3412 'spi': spi,
3413 'tunnel_src_address': tunnel_src_address,
3414 'tunnel_dst_address': tunnel_dst_address,
3415 'protocol': protocol,
3416 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003417 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003418 'integrity_key': integrity_key,
3419 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003420 'crypto_key_length': len(crypto_key) if crypto_key is not None
3421 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003422 'crypto_key': crypto_key,
3423 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003424 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003425 'is_tunnel_ipv6': is_tunnel_ipv6,
Neale Rannsde847272018-11-28 01:38:34 -08003426 'udp_encap': udp_encap,
3427 'use_extended_sequence_number': use_extended_sequence_number,
3428 'use_anti_replay': use_anti_replay})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003429
3430 def ipsec_spd_add_del_entry(self,
3431 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003432 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003433 local_address_start,
3434 local_address_stop,
3435 remote_address_start,
3436 remote_address_stop,
3437 local_port_start=0,
3438 local_port_stop=65535,
3439 remote_port_start=0,
3440 remote_port_stop=65535,
3441 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003442 policy=0,
3443 priority=100,
3444 is_outbound=1,
3445 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003446 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003447 is_ip_any=0):
3448 """ IPSEC policy SPD add/del -
3449 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003450 :param spd_id: SPD ID for the policy
3451 :param local_address_start: local-ip-range start address
3452 :param local_address_stop : local-ip-range stop address
3453 :param remote_address_start: remote-ip-range start address
3454 :param remote_address_stop : remote-ip-range stop address
3455 :param local_port_start: (Default value = 0)
3456 :param local_port_stop: (Default value = 65535)
3457 :param remote_port_start: (Default value = 0)
3458 :param remote_port_stop: (Default value = 65535)
3459 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3460 :param sa_id: Security Association ID for mapping it to SPD
3461 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3462 (Default value = 0)
3463 :param priority: value for the spd action (Default value = 100)
3464 :param is_outbound: flag for inbound(0) or outbound(1)
3465 (Default value = 1)
3466 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003467 """
3468 return self.api(
3469 self.papi.ipsec_spd_add_del_entry,
3470 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003471 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003472 'local_address_start': local_address_start,
3473 'local_address_stop': local_address_stop,
3474 'remote_address_start': remote_address_start,
3475 'remote_address_stop': remote_address_stop,
3476 'local_port_start': local_port_start,
3477 'local_port_stop': local_port_stop,
3478 'remote_port_start': remote_port_start,
3479 'remote_port_stop': remote_port_stop,
3480 'is_add': is_add,
3481 'protocol': protocol,
3482 'policy': policy,
3483 'priority': priority,
3484 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003485 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003486 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003487
Klement Sekera31da2e32018-06-24 22:49:55 +02003488 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3489 remote_spi, crypto_alg, local_crypto_key,
3490 remote_crypto_key, integ_alg, local_integ_key,
3491 remote_integ_key, is_add=1, esn=0,
3492 anti_replay=1, renumber=0, show_instance=0):
3493 return self.api(
3494 self.papi.ipsec_tunnel_if_add_del,
3495 {'local_ip': local_ip, 'remote_ip': remote_ip,
3496 'local_spi': local_spi, 'remote_spi': remote_spi,
3497 'crypto_alg': crypto_alg,
3498 'local_crypto_key_len': len(local_crypto_key),
3499 'local_crypto_key': local_crypto_key,
3500 'remote_crypto_key_len': len(remote_crypto_key),
3501 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3502 'local_integ_key_len': len(local_integ_key),
3503 'local_integ_key': local_integ_key,
3504 'remote_integ_key_len': len(remote_integ_key),
3505 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3506 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3507 'show_instance': show_instance
3508 })
3509
Klement Sekerab4d30532018-11-08 13:00:02 +01003510 def ipsec_select_backend(self, protocol, index):
3511 return self.api(self.papi.ipsec_select_backend,
3512 {'protocol': protocol, 'index': index})
3513
3514 def ipsec_backend_dump(self):
3515 return self.api(self.papi.ipsec_backend_dump, {})
3516
Florin Corasb795bd02017-12-14 11:30:48 -08003517 def app_namespace_add(self,
3518 namespace_id,
3519 ip4_fib_id=0,
3520 ip6_fib_id=0,
3521 sw_if_index=0xFFFFFFFF,
3522 secret=0):
3523 return self.api(
3524 self.papi.app_namespace_add_del,
3525 {'secret': secret,
3526 'sw_if_index': sw_if_index,
3527 'ip4_fib_id': ip4_fib_id,
3528 'ip6_fib_id': ip6_fib_id,
3529 'namespace_id': namespace_id,
3530 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003531
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003532 def punt_socket_register(self, port, pathname, protocol=0x11,
3533 header_version=1, is_ip4=1):
3534 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02003535 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003536 {'header_version': header_version,
3537 'punt': {'ipv': is_ip4,
3538 'l4_protocol': protocol,
3539 'l4_port': port},
3540 'pathname': pathname})
3541
3542 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
3543 """ Unregister punt socket """
3544 return self.api(self.papi.punt_socket_deregister,
3545 {'punt': {'ipv': is_ip4,
3546 'l4_protocol': protocol,
3547 'l4_port': port}})
3548
3549 def punt_socket_dump(self, is_ip6=1):
3550 """ Dump punt socket"""
3551 return self.api(self.papi.punt_socket_dump,
3552 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02003553
3554 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3555 expire_walk_interval_ms, is_ip6=0):
3556 """ Set IP reassembly parameters """
3557 return self.api(self.papi.ip_reassembly_set,
3558 {'is_ip6': is_ip6,
3559 'timeout_ms': timeout_ms,
3560 'expire_walk_interval_ms': expire_walk_interval_ms,
3561 'max_reassemblies': max_reassemblies})
3562
3563 def ip_reassembly_get(self, is_ip6=0):
3564 """ Get IP reassembly parameters """
3565 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003566
Klement Sekera4c533132018-02-22 11:41:12 +01003567 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3568 enable_ip6=False):
3569 """ Enable/disable IP reassembly """
3570 return self.api(self.papi.ip_reassembly_enable_disable,
3571 {'sw_if_index': sw_if_index,
3572 'enable_ip4': 1 if enable_ip4 else 0,
3573 'enable_ip6': 1 if enable_ip6 else 0,
3574 })
3575
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003576 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3577 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003578 """ GBP endpoint Add """
3579 return self.api(self.papi.gbp_endpoint_add,
3580 {'endpoint': {
3581 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003582 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003583 'ips': ips,
3584 'n_ips': len(ips),
3585 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003586 'epg_id': epg,
3587 'flags': flags,
3588 'tun': {
3589 'src': tun_src,
3590 'dst': tun_dst,
3591 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003592
3593 def gbp_endpoint_del(self, handle):
3594 """ GBP endpoint Del """
3595 return self.api(self.papi.gbp_endpoint_del,
3596 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003597
3598 def gbp_endpoint_dump(self):
3599 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003600 return self.api(self.papi.gbp_endpoint_dump,
3601 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003602
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003603 def gbp_endpoint_group_add(self, epg, bd,
3604 rd, uplink_sw_if_index):
3605 """ GBP endpoint group Add """
3606 return self.api(self.papi.gbp_endpoint_group_add,
3607 {'epg':
3608 {
Neale Ranns25b04942018-04-04 09:34:50 -07003609 'uplink_sw_if_index': uplink_sw_if_index,
3610 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003611 'rd_id': rd,
3612 'epg_id': epg
3613 }})
3614
3615 def gbp_endpoint_group_del(self, epg):
3616 """ GBP endpoint group Del """
3617 return self.api(self.papi.gbp_endpoint_group_del,
3618 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003619
3620 def gbp_endpoint_group_dump(self):
3621 """ GBP endpoint group Dump """
3622 return self.api(self.papi.gbp_endpoint_group_dump, {})
3623
Neale Rannsc29c0af2018-11-07 04:21:12 -08003624 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003625 bvi_sw_if_index,
3626 uu_fwd_sw_if_index):
3627 """ GBP bridge-domain Add """
3628 return self.api(self.papi.gbp_bridge_domain_add,
3629 {'bd':
3630 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003631 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003632 'bvi_sw_if_index': bvi_sw_if_index,
3633 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3634 'bd_id': bd_id
3635 }})
3636
3637 def gbp_bridge_domain_del(self, bd_id):
3638 """ GBP bridge-domain Del """
3639 return self.api(self.papi.gbp_bridge_domain_del,
3640 {'bd_id': bd_id})
3641
3642 def gbp_bridge_domain_dump(self):
3643 """ GBP Bridge Domain Dump """
3644 return self.api(self.papi.gbp_bridge_domain_dump, {})
3645
3646 def gbp_route_domain_add(self, rd_id,
3647 ip4_table_id,
3648 ip6_table_id,
3649 ip4_uu_sw_if_index,
3650 ip6_uu_sw_if_index):
3651 """ GBP route-domain Add """
3652 return self.api(self.papi.gbp_route_domain_add,
3653 {'rd':
3654 {
3655 'ip4_table_id': ip4_table_id,
3656 'ip6_table_id': ip6_table_id,
3657 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3658 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3659 'rd_id': rd_id
3660 }})
3661
3662 def gbp_route_domain_del(self, rd_id):
3663 """ GBP route-domain Del """
3664 return self.api(self.papi.gbp_route_domain_del,
3665 {'rd_id': rd_id})
3666
3667 def gbp_route_domain_dump(self):
3668 """ GBP Route Domain Dump """
3669 return self.api(self.papi.gbp_route_domain_dump, {})
3670
Neale Ranns25b04942018-04-04 09:34:50 -07003671 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3672 """ GBP recirc Add/Del """
3673 return self.api(self.papi.gbp_recirc_add_del,
3674 {'is_add': is_add,
3675 'recirc': {
3676 'is_ext': is_ext,
3677 'sw_if_index': sw_if_index,
3678 'epg_id': epg}})
3679
3680 def gbp_recirc_dump(self):
3681 """ GBP recirc Dump """
3682 return self.api(self.papi.gbp_recirc_dump, {})
3683
Neale Rannsb6a47952018-11-21 05:44:35 -08003684 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3685 """ GBP recirc Add/Del """
3686 return self.api(self.papi.gbp_ext_itf_add_del,
3687 {'is_add': is_add,
3688 'ext_itf': {
3689 'sw_if_index': sw_if_index,
3690 'bd_id': bd_id,
3691 'rd_id': rd_id}})
3692
3693 def gbp_ext_itf_dump(self):
3694 """ GBP recirc Dump """
3695 return self.api(self.papi.gbp_ext_itf_dump, {})
3696
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003697 def gbp_subnet_add_del(self, is_add, rd_id,
3698 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003699 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003700 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003701 """ GBP Subnet Add/Del """
3702 return self.api(self.papi.gbp_subnet_add_del,
3703 {'is_add': is_add,
3704 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003705 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003706 'sw_if_index': sw_if_index,
3707 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003708 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003709 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003710
3711 def gbp_subnet_dump(self):
3712 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003713 return self.api(self.papi.gbp_subnet_dump,
3714 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07003715
Neale Ranns13a08cc2018-11-07 09:25:54 -08003716 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003717 """ GBP contract Add/Del """
3718 return self.api(self.papi.gbp_contract_add_del,
3719 {'is_add': is_add,
3720 'contract': {
3721 'acl_index': acl_index,
3722 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003723 'dst_epg': dst_epg,
3724 'n_rules': len(rules),
3725 'rules': rules}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003726
3727 def gbp_contract_dump(self):
3728 """ GBP contract Dump """
3729 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003730
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003731 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3732 """ GBP set inactive threshold """
3733 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3734 {'threshold': threshold})
3735
3736 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3737 """ GBP VXLAN tunnel add """
3738 return self.api(self.papi.gbp_vxlan_tunnel_add,
3739 {
3740 'tunnel': {
3741 'vni': vni,
3742 'mode': mode,
3743 'bd_rd_id': bd_rd_id
3744 }
3745 })
3746
3747 def gbp_vxlan_tunnel_del(self, vni):
3748 """ GBP VXLAN tunnel del """
3749 return self.api(self.papi.gbp_vxlan_tunnel_del,
3750 {
3751 'vni': vni,
3752 })
3753
3754 def gbp_vxlan_tunnel_dump(self):
3755 """ GBP VXLAN tunnel add/del """
3756 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3757
Neale Ranns61502112018-08-22 00:21:14 -07003758 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3759 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003760 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003761 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003762 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003763 {'ip4_table_id': ip4_table_id,
3764 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003765 'ip6_prefix': ip6_prefix,
3766 'ip6_prefix_len': ip6_prefix_len,
3767 'ip4_prefix': ip4_prefix,
3768 'ip4_prefix_len': ip4_prefix_len,
3769 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003770 'security_check': security_check})
3771
Ole Troan298c6952018-03-08 12:30:43 +01003772 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003773 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003774 return self.api(self.papi.ipip_6rd_del_tunnel,
3775 {'sw_if_index': sw_if_index})
3776
3777 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003778 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003779 """ IPIP tunnel Add/Del """
3780 return self.api(self.papi.ipip_add_tunnel,
3781 {'is_ipv6': is_ipv6,
3782 'instance': instance,
3783 'src_address': src_address,
3784 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003785 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003786 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003787
3788 def ipip_del_tunnel(self, sw_if_index):
3789 """ IPIP tunnel Delete """
3790 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003791 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003792
3793 def qos_egress_map_update(self, id, outputs):
3794 """ QOS egress map update """
3795 return self.api(self.papi.qos_egress_map_update,
3796 {'map_id': id,
3797 'rows': outputs})
3798
3799 def qos_egress_map_delete(self, id):
3800 """ QOS egress map delete """
3801 return self.api(self.papi.qos_egress_map_delete,
3802 {'map_id': id})
3803
3804 def qos_mark_enable_disable(self, sw_if_index,
3805 output_source,
3806 map_id,
3807 enable):
3808 """ QOS Mark Enable/Disable """
3809 return self.api(self.papi.qos_mark_enable_disable,
3810 {'map_id': map_id,
3811 'sw_if_index': sw_if_index,
3812 'output_source': output_source,
3813 'enable': enable})
3814
3815 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3816 """ IP QoS recording Enble/Disable """
3817 return self.api(self.papi.qos_record_enable_disable,
3818 {'sw_if_index': sw_if_index,
3819 'input_source': input_source,
3820 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003821
Neale Ranns947ea622018-06-07 23:48:20 -07003822 def igmp_enable_disable(self, sw_if_index, enable, host):
3823 """ Enable/disable IGMP on a given interface """
3824 return self.api(self.papi.igmp_enable_disable,
3825 {'enable': enable,
3826 'mode': host,
3827 'sw_if_index': sw_if_index})
3828
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003829 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3830 """ Add/del IGMP proxy device """
3831 return self.api(self.papi.igmp_proxy_device_add_del,
3832 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3833 'add': add})
3834
3835 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3836 """ Add/del interface to/from IGMP proxy device """
3837 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3838 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3839 'add': add})
3840
Neale Ranns947ea622018-06-07 23:48:20 -07003841 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003842 """ Listen for new (S,G) on specified interface
3843
3844 :param enable: add/del
3845 :param sw_if_index: interface sw index
3846 :param saddr: source ip4 addr
3847 :param gaddr: group ip4 addr
3848 """
3849 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003850 {
3851 'group':
3852 {
3853 'filter': filter,
3854 'sw_if_index': sw_if_index,
3855 'n_srcs': len(saddrs),
3856 'saddrs': saddrs,
Ole Troan8c8acc02018-11-27 10:05:23 +01003857 'gaddr': gaddr
Neale Ranns947ea622018-06-07 23:48:20 -07003858 }
3859 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003860
3861 def igmp_dump(self, sw_if_index=None):
3862 """ Dump all (S,G) interface configurations """
3863 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003864 sw_if_index = 0xffffffff
3865 return self.api(self.papi.igmp_dump,
3866 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003867
3868 def igmp_clear_interface(self, sw_if_index):
3869 """ Remove all (S,G)s from specified interface
3870 doesn't send IGMP report!
3871 """
3872 return self.api(
3873 self.papi.igmp_clear_interface, {
3874 'sw_if_index': sw_if_index})
3875
3876 def want_igmp_events(self, enable=1):
3877 return self.api(self.papi.want_igmp_events, {'enable': enable,
3878 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003879
3880 def bond_create(
3881 self,
3882 mode,
3883 lb,
3884 use_custom_mac,
3885 mac_address=''):
3886 """
3887 :param mode: mode
3888 :param lb: load balance
3889 :param use_custom_mac: use custom mac
3890 :param mac_address: mac address
3891 """
3892 return self.api(
3893 self.papi.bond_create,
3894 {'mode': mode,
3895 'lb': lb,
3896 'use_custom_mac': use_custom_mac,
3897 'mac_address': mac_address
3898 })
3899
3900 def bond_delete(
3901 self,
3902 sw_if_index):
3903 """
3904 :param sw_if_index: interface the operation is applied to
3905 """
3906 return self.api(self.papi.bond_delete,
3907 {'sw_if_index': sw_if_index})
3908
3909 def bond_enslave(
3910 self,
3911 sw_if_index,
3912 bond_sw_if_index,
3913 is_passive,
3914 is_long_timeout):
3915 """
3916 :param sw_if_index: slave sw_if_index
3917 :param bond_sw_if_index: bond sw_if_index
3918 :param is_passive: is passive lacp speaker
3919 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3920 """
3921 return self.api(
3922 self.papi.bond_enslave,
3923 {'sw_if_index': sw_if_index,
3924 'bond_sw_if_index': bond_sw_if_index,
3925 'is_passive': is_passive,
3926 'is_long_timeout': is_long_timeout
3927 })
3928
3929 def bond_detach_slave(
3930 self,
3931 sw_if_index):
3932 """
3933 :param sw_if_index: slave interface the operation is applied to
3934 """
3935 return self.api(self.papi.bond_detach_slave,
3936 {'sw_if_index': sw_if_index})
3937
3938 def sw_interface_slave_dump(
3939 self,
3940 sw_if_index):
3941 """
3942 :param sw_if_index: bond sw_if_index
3943 """
3944 return self.api(self.papi.sw_interface_slave_dump,
3945 {'sw_if_index': sw_if_index})
3946
3947 def sw_interface_bond_dump(
3948 self):
3949 """
3950
3951 """
3952 return self.api(self.papi.sw_interface_bond_dump,
3953 {})
Stevene8fa6202017-08-30 14:36:45 -07003954
3955 def create_vhost_user_if(
3956 self,
3957 is_server,
3958 sock_filename,
3959 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003960 disable_mrg_rxbuf,
3961 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003962 custom_dev_instance,
3963 use_custom_mac,
3964 mac_address,
3965 tag=''):
3966 """
3967 :param is_server: is server
3968 :param sock_filename: socket name
3969 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003970 :param disable_mrg_rxbuf: disable mergable rx buffers
3971 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003972 :param custom_dev_instance: custom dev instance
3973 :param use_custom_mac: use custom mac
3974 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003975 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003976 """
3977 return self.api(
3978 self.papi.create_vhost_user_if,
3979 {'is_server': is_server,
3980 'sock_filename': sock_filename,
3981 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003982 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3983 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003984 'custom_dev_instance': custom_dev_instance,
3985 'use_custom_mac': use_custom_mac,
3986 'mac_address': mac_address,
3987 'tag': tag
3988 })
3989
3990 def delete_vhost_user_if(
3991 self,
3992 sw_if_index):
3993 """
3994 :param sw_if_index: interface the operation is applied to
3995 """
3996 return self.api(self.papi.delete_vhost_user_if,
3997 {'sw_if_index': sw_if_index, })
3998
3999 def sw_interface_vhost_user_dump(
4000 self):
4001 """
4002
4003 """
4004 return self.api(self.papi.sw_interface_vhost_user_dump,
4005 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01004006
4007 def abf_policy_add_del(self, is_add, policy):
4008 return self.api(
4009 self.papi.abf_policy_add_del,
4010 {'is_add': is_add,
4011 'policy': policy})
4012
4013 def abf_itf_attach_add_del(self, is_add, attach):
4014 return self.api(
4015 self.papi.abf_itf_attach_add_del,
4016 {'is_add': is_add,
4017 'attach': attach})
4018
4019 def abf_policy_dump(self):
4020 return self.api(
4021 self.papi.abf_policy_dump, {})
4022
4023 def abf_itf_attach_dump(self):
4024 return self.api(
4025 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07004026
4027 def pipe_create(self, is_specified, user_instance):
4028 return self.api(self.papi.pipe_create,
4029 {'is_specified': is_specified,
4030 'user_instance': user_instance})
4031
4032 def pipe_delete(self, parent_sw_if_index):
4033 return self.api(self.papi.pipe_delete,
4034 {'parent_sw_if_index': parent_sw_if_index})
4035
4036 def pipe_dump(self):
4037 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02004038
4039 def memif_create(
4040 self,
4041 role,
4042 mode,
4043 rx_queues=None,
4044 tx_queues=None,
4045 _id=None,
4046 socket_id=None,
4047 secret=None,
4048 ring_size=None,
4049 buffer_size=None,
4050 hw_addr=None):
4051 return self.api(self.papi.memif_create,
4052 {'role': role,
4053 'mode': mode,
4054 'rx_queues': rx_queues,
4055 'tx_queues': tx_queues,
4056 'id': _id,
4057 'socket_id': socket_id,
4058 'secret': secret,
4059 'ring_size': ring_size,
4060 'buffer_size': buffer_size,
4061 'hw_addr': hw_addr})
4062
4063 def memif_delete(self, sw_if_index):
4064 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4065
4066 def memif_dump(self):
4067 return self.api(self.papi.memif_dump, {})
4068
4069 def memif_socket_filename_add_del(
4070 self, is_add, socket_id, socket_filename):
4071 return self.api(
4072 self.papi.memif_socket_filename_add_del,
4073 {'is_add': is_add,
4074 'socket_id': socket_id,
4075 'socket_filename': socket_filename})
4076
4077 def memif_socket_filename_dump(self):
4078 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004079
4080 def svs_table_add_del(self, af, table_id, is_add=1):
4081 return self.api(self.papi.svs_table_add_del,
4082 {
4083 'table_id': table_id,
4084 'is_add': is_add,
4085 'af': af,
4086 })
4087
4088 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4089 return self.api(self.papi.svs_route_add_del,
4090 {
4091 'table_id': table_id,
4092 'source_table_id': src_table_id,
4093 'prefix': prefix,
4094 'is_add': is_add,
4095 })
4096
4097 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4098 return self.api(self.papi.svs_enable_disable,
4099 {
4100 'af': af,
4101 'table_id': table_id,
4102 'sw_if_index': sw_if_index,
4103 'is_enable': is_enable,
4104 })
4105
4106 def svs_dump(self):
4107 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004108
4109 def syslog_set_sender(
4110 self,
4111 collector,
4112 src,
4113 collector_port=514,
4114 vrf_id=0,
4115 max_msg_size=480):
4116 """Set syslog sender configuration
4117
4118 :param collector: colector IP address
4119 :param src: source IP address
4120 :param collector_port: collector UDP port (Default value = 514)
4121 :param vrf_id: VRF id (Default value = 0)
4122 :param max_msg_size: maximum message length (Default value = 480)
4123 """
4124 return self.api(self.papi.syslog_set_sender,
Ole Troan8c8acc02018-11-27 10:05:23 +01004125 {'collector_address': collector,
4126 'src_address': src,
Matus Fabianb4515b42018-11-19 04:25:32 -08004127 'collector_port': collector_port,
4128 'vrf_id': vrf_id,
4129 'max_msg_size': max_msg_size})
4130
4131 def syslog_get_sender(self):
4132 """Return syslog sender configuration"""
4133 return self.api(self.papi.syslog_get_sender, {})
4134
4135 def syslog_set_filter(self, severity):
4136 """Set syslog filter parameters
4137
4138 :param severity: severity filter (specified severity and greater match)
4139 """
4140 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4141
4142 def syslog_get_filter(self):
4143 """Return syslog filter parameters"""
4144 return self.api(self.papi.syslog_get_filter, {})