blob: f8d0e6ca0f9428d430dd83e85b32b7b680e29676 [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import os
2import fnmatch
3import time
Klement Sekeraf62ae122016-10-11 11:47:09 +02004from hook import Hook
Klement Sekerae4504c62016-12-08 10:16:41 +01005from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02006
Klement Sekera0e3c0de2016-09-29 14:43:44 +02007# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +01008# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
9# the vpp_papi_provider.py file to be importable without having to build
10# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020011do_import = True
12try:
13 no_vpp_papi = os.getenv("NO_VPP_PAPI")
14 if no_vpp_papi == "1":
15 do_import = False
16except:
17 pass
18
19if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010020 from vpp_papi import VPP
Neale Ranns93cc3ee2018-10-10 07:22:51 -070021 from vpp_l2 import L2_PORT_TYPE
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030029 L2_DISABLED = 0
30 L2_PUSH_1 = 1
31 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000032 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030033 L2_POP_2 = 4
34 L2_TRANSLATE_1_1 = 5
35 L2_TRANSLATE_1_2 = 6
36 L2_TRANSLATE_2_1 = 7
37 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000038
Klement Sekera0e3c0de2016-09-29 14:43:44 +020039
Neale Ranns039cbfe2018-02-27 03:45:38 -080040class QOS_SOURCE:
41 EXT = 0
42 VLAN = 1
43 MPLS = 2
44 IP = 3
45
46
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 Sekera0e3c0de2016-09-29 14:43:44 +020080 install_dir = os.getenv('VPP_TEST_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" % \
187 (reply.retval, repr(reply))
188 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,
194 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 Troan7e3a8752016-12-05 10:27:09 +0100213 r = self.papi.cli_inband(length=len(cli), 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 Troan7e3a8752016-12-05 10:27:09 +0100216 return r.reply.decode().rstrip('\x00')
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
Jan4af521d2016-11-15 17:05:00 +0100226 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200227 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100228
Klement Sekeraf62ae122016-10-11 11:47:09 +0200229 def show_version(self):
230 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100231 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200232
233 def pg_create_interface(self, pg_index):
234 """
235
236 :param pg_index:
237
238 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100239 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200240 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200241
242 def sw_interface_dump(self, filter=None):
243 """
244
245 :param filter: (Default value = None)
246
247 """
248 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200249 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200250 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100251 args = {}
252 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200253
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000254 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100255 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000256
257 :param sw_if_index:
258 :param is_ipv6:
259 :param table_id:
260
261 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100262 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200263 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
264 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000265
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700266 def sw_interface_get_table(self, sw_if_index, is_ipv6):
267 """ Get the IPvX Table-id for the Interface
268
269 :param sw_if_index:
270 :param is_ipv6:
271 :return table_id
272
273 """
274 return self.api(self.papi.sw_interface_get_table,
275 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
276
Klement Sekeraf62ae122016-10-11 11:47:09 +0200277 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
278 is_ipv6=0, is_add=1, del_all=0):
279 """
280
281 :param addr: param is_ipv6: (Default value = 0)
282 :param sw_if_index:
283 :param addr_len:
284 :param is_ipv6: (Default value = 0)
285 :param is_add: (Default value = 1)
286 :param del_all: (Default value = 0)
287
288 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100289 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200290 {'sw_if_index': sw_if_index,
291 'is_add': is_add,
292 'is_ipv6': is_ipv6,
293 'del_all': del_all,
294 'address_length': addr_len,
295 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700297 def ip_address_dump(self, sw_if_index, is_ipv6=0):
298 return self.api(self.papi.ip_address_dump,
299 {'sw_if_index': sw_if_index,
300 'is_ipv6': is_ipv6})
301
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800302 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
303 is_add=1):
304 """ Set the Interface to be unnumbered
305
306 :param is_add: (Default value = 1)
307 :param sw_if_index - interface That will be unnumbered
308 :param ip_sw_if_index - interface with an IP addres
309
310 """
311 return self.api(self.papi.sw_interface_set_unnumbered,
312 {'sw_if_index': ip_sw_if_index,
313 'unnumbered_sw_if_index': sw_if_index,
314 'is_add': is_add})
315
Neale Ranns404d88e2018-08-08 06:37:33 -0700316 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
317 return self.api(self.papi.ip_unnumbered_dump,
318 {'sw_if_index': sw_if_index})
319
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000320 def sw_interface_enable_disable_mpls(self, sw_if_index,
321 is_enable=1):
322 """
323 Enable/Disable MPLS on the interface
324 :param sw_if_index:
325 :param is_enable: (Default value = 1)
326
327 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100328 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200329 {'sw_if_index': sw_if_index,
330 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000331
Jan Gelety057bb8c2016-12-20 17:32:45 +0100332 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100333 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100334 {'sw_if_index': sw_if_index,
335 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200336
Neale Ranns227038a2017-04-21 01:07:59 -0700337 def set_ip_flow_hash(self,
338 table_id,
339 src=1,
340 dst=1,
341 sport=1,
342 dport=1,
343 proto=1,
344 reverse=0,
345 is_ip6=0):
346 return self.api(self.papi.set_ip_flow_hash,
347 {'vrf_id': table_id,
348 'src': src,
349 'dst': dst,
350 'dport': dport,
351 'sport': sport,
352 'proto': proto,
353 'reverse': reverse,
354 'is_ipv6': is_ip6})
355
Neale Ranns3f844d02017-02-18 00:03:54 -0800356 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
357 return self.api(self.papi.ip6nd_proxy_add_del,
358 {'address': address,
359 'sw_if_index': sw_if_index,
360 'is_del': is_del})
361
Neale Ranns75152282017-01-09 01:00:45 -0800362 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000363 no,
Neale Ranns75152282017-01-09 01:00:45 -0800364 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000365 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800366 return self.api(self.papi.sw_interface_ip6nd_ra_config,
367 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000368 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100369 'suppress': suppress,
370 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800371
Neale Ranns87df12d2017-02-18 08:16:41 -0800372 def ip6_sw_interface_ra_prefix(self,
373 sw_if_index,
374 address,
375 address_length,
376 use_default=0,
377 no_advertise=0,
378 off_link=0,
379 no_autoconfig=0,
380 no_onlink=0,
381 is_no=0,
382 val_lifetime=0xffffffff,
383 pref_lifetime=0xffffffff):
384 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
385 {'sw_if_index': sw_if_index,
386 'address': address,
387 'address_length': address_length,
388 'use_default': use_default,
389 'no_advertise': no_advertise,
390 'off_link': off_link,
391 'no_autoconfig': no_autoconfig,
392 'no_onlink': no_onlink,
393 'is_no': is_no,
394 'val_lifetime': val_lifetime,
395 'pref_lifetime': pref_lifetime})
396
Neale Ranns75152282017-01-09 01:00:45 -0800397 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
398 """
399 Enable/Disable An interface for IPv6
400 """
401 return self.api(self.papi.sw_interface_ip6_enable_disable,
402 {'sw_if_index': sw_if_index,
403 'enable': enable})
404
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405 def vxlan_add_del_tunnel(
406 self,
407 src_addr,
408 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200409 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200410 is_add=1,
411 is_ipv6=0,
412 encap_vrf_id=0,
413 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600414 vni=0,
415 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200416 """
417
418 :param dst_addr:
419 :param src_addr:
420 :param is_add: (Default value = 1)
421 :param is_ipv6: (Default value = 0)
422 :param encap_vrf_id: (Default value = 0)
423 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200424 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200425 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600426 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200427
428 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100429 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200430 {'is_add': is_add,
431 'is_ipv6': is_ipv6,
432 'src_address': src_addr,
433 'dst_address': dst_addr,
434 'mcast_sw_if_index': mcast_sw_if_index,
435 'encap_vrf_id': encap_vrf_id,
436 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600437 'vni': vni,
438 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200439
Marco Varleseb598f1d2017-09-19 14:25:28 +0200440 def geneve_add_del_tunnel(
441 self,
442 local_addr,
443 remote_addr,
444 mcast_sw_if_index=0xFFFFFFFF,
445 is_add=1,
446 is_ipv6=0,
447 encap_vrf_id=0,
448 decap_next_index=0xFFFFFFFF,
449 vni=0):
450 """
451
452 :param remote_addr:
453 :param local_addr:
454 :param is_add: (Default value = 1)
455 :param is_ipv6: (Default value = 0)
456 :param encap_vrf_id: (Default value = 0)
457 :param decap_next_index: (Default value = 0xFFFFFFFF)
458 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
459 :param vni: (Default value = 0)
460
461 """
462 return self.api(self.papi.geneve_add_del_tunnel,
463 {'is_add': is_add,
464 'is_ipv6': is_ipv6,
465 'local_address': local_addr,
466 'remote_address': remote_addr,
467 'mcast_sw_if_index': mcast_sw_if_index,
468 'encap_vrf_id': encap_vrf_id,
469 'decap_next_index': decap_next_index,
470 'vni': vni})
471
Jan4af521d2016-11-15 17:05:00 +0100472 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
473 learn=1, arp_term=0, is_add=1):
474 """Create/delete bridge domain.
475
476 :param int bd_id: Bridge domain index.
477 :param int flood: Enable/disable bcast/mcast flooding in the BD.
478 (Default value = 1)
479 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
480 (Default value = 1)
481 :param int forward: Enable/disable forwarding on all interfaces in
482 the BD. (Default value = 1)
483 :param int learn: Enable/disable learning on all interfaces in the BD.
484 (Default value = 1)
485 :param int arp_term: Enable/disable arp termination in the BD.
486 (Default value = 1)
487 :param int is_add: Add or delete flag. (Default value = 1)
488 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100489 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200490 {'bd_id': bd_id,
491 'flood': flood,
492 'uu_flood': uu_flood,
493 'forward': forward,
494 'learn': learn,
495 'arp_term': arp_term,
496 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100497
Eyal Baric86e5922017-07-02 18:33:16 +0300498 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
499 return self.api(self.papi.bd_ip_mac_add_del,
500 {'bd_id': bd_id,
501 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700502 'ip': ip,
503 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300504
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700505 def bd_ip_mac_dump(self, bd_id):
506 return self.api(self.papi.bd_ip_mac_dump,
507 {'bd_id': bd_id})
508
Eyal Bari20197482017-09-13 12:29:08 +0300509 def want_ip4_arp_events(self, enable_disable=1, address=0):
510 return self.api(self.papi.want_ip4_arp_events,
511 {'enable_disable': enable_disable,
512 'address': address,
513 'pid': os.getpid(), })
514
Eyal Baric125ecc2017-09-20 11:29:17 +0300515 def want_ip6_nd_events(self, enable_disable=1, address=0):
516 return self.api(self.papi.want_ip6_nd_events,
517 {'enable_disable': enable_disable,
518 'address': address,
519 'pid': os.getpid(), })
520
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100521 def want_ip6_ra_events(self, enable_disable=1):
522 return self.api(self.papi.want_ip6_ra_events,
523 {'enable_disable': enable_disable,
524 'pid': os.getpid(), })
525
526 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
527 mrc=0, mrd=0):
528 return self.api(self.papi.ip6nd_send_router_solicitation,
529 {'irt': irt,
530 'mrt': mrt,
531 'mrc': mrc,
532 'mrd': mrd,
533 'sw_if_index': sw_if_index})
534
Juraj Slobodac0374232018-02-01 15:18:49 +0100535 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
536 install_default_routes):
537 return self.api(self.papi.ip6_nd_address_autoconfig,
538 {'sw_if_index': sw_if_index,
539 'enable': enable,
540 'install_default_routes': install_default_routes})
541
Juraj Slobodab3f90502018-10-04 15:15:16 +0200542 def want_interface_events(self, enable_disable=1):
543 return self.api(self.papi.want_interface_events,
544 {'enable_disable': enable_disable,
545 'pid': os.getpid(), })
546
Eyal Bari24db0ec2017-09-27 21:43:51 +0300547 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
548 max_macs_in_event=0, learn_limit=0):
549 return self.api(self.papi.want_l2_macs_events,
550 {'enable_disable': enable_disable,
551 'scan_delay': scan_delay,
552 'max_macs_in_event': max_macs_in_event,
553 'learn_limit': learn_limit,
554 'pid': os.getpid(), })
555
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200556 def want_dhcp6_reply_events(self, enable_disable=1):
557 return self.api(self.papi.want_dhcp6_reply_events,
558 {'enable_disable': enable_disable,
559 'pid': os.getpid()})
560
Juraj Sloboda81119e82018-05-25 14:02:20 +0200561 def want_dhcp6_pd_reply_events(self, enable_disable=1):
562 return self.api(self.papi.want_dhcp6_pd_reply_events,
563 {'enable_disable': enable_disable,
564 'pid': os.getpid()})
565
566 def dhcp6_clients_enable_disable(self, enable=1):
567 return self.api(self.papi.dhcp6_clients_enable_disable,
568 {'enable': enable})
569
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200570 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
571 addresses, server_index=0xFFFFFFFF,
572 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
573 ):
574 return self.api(self.papi.dhcp6_send_client_message,
575 {'sw_if_index': sw_if_index,
576 'server_index': server_index,
577 'irt': irt,
578 'mrt': mrt,
579 'mrc': mrc,
580 'mrd': mrd,
581 'stop': stop,
582 'msg_type': msg_type,
583 'T1': T1,
584 'T2': T2,
585 'n_addresses': len(addresses),
586 'addresses': addresses})
587
Juraj Sloboda81119e82018-05-25 14:02:20 +0200588 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
589 prefixes, server_index=0xFFFFFFFF,
590 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
591 ):
592 return self.api(self.papi.dhcp6_pd_send_client_message,
593 {'sw_if_index': sw_if_index,
594 'server_index': server_index,
595 'irt': irt,
596 'mrt': mrt,
597 'mrc': mrc,
598 'mrd': mrd,
599 'stop': stop,
600 'msg_type': msg_type,
601 'T1': T1,
602 'T2': T2,
603 'n_prefixes': len(prefixes),
604 'prefixes': prefixes})
605
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200606 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
607 enable=1):
608 return self.api(self.papi.dhcp6_client_enable_disable,
609 {'sw_if_index': sw_if_index,
610 'enable': enable})
611
Juraj Sloboda81119e82018-05-25 14:02:20 +0200612 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
613 enable=1):
614 return self.api(self.papi.dhcp6_pd_client_enable_disable,
615 {'sw_if_index': sw_if_index,
616 'prefix_group': prefix_group,
617 'enable': enable})
618
619 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
620 prefix_length, prefix_group,
621 is_add=1):
622 return self.api(self.papi.ip6_add_del_address_using_prefix,
623 {'sw_if_index': sw_if_index,
624 'prefix_group': prefix_group,
625 'address': address,
626 'prefix_length': prefix_length,
627 'is_add': is_add})
628
Jan4af521d2016-11-15 17:05:00 +0100629 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
630 filter_mac=0, bvi_mac=0):
631 """Create/delete L2 FIB entry.
632
633 :param str mac: MAC address to create FIB entry for.
634 :param int bd_id: Bridge domain index.
635 :param int sw_if_index: Software interface index of the interface.
636 :param int is_add: Add or delete flag. (Default value = 1)
637 :param int static_mac: Set to 1 to create static MAC entry.
638 (Default value = 0)
639 :param int filter_mac: Set to 1 to drop packet that's source or
640 destination MAC address contains defined MAC address.
641 (Default value = 0)
642 :param int bvi_mac: Set to 1 to create entry that points to BVI
643 interface. (Default value = 0)
644 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100645 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200646 {'mac': self._convert_mac(mac),
647 'bd_id': bd_id,
648 'sw_if_index': sw_if_index,
649 'is_add': is_add,
650 'static_mac': static_mac,
651 'filter_mac': filter_mac,
652 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100653
Eyal Bari93b503e2017-05-15 10:13:15 +0300654 def l2fib_flush_int(self, sw_if_index):
655 """Flush L2 FIB entries for sw_if_index.
656
657 :param int sw_if_index: Software interface index of the interface.
658 """
659 return self.api(self.papi.l2fib_flush_int,
660 {'sw_if_index': sw_if_index})
661
662 def l2fib_flush_bd(self, bd_id):
663 """Flush L2 FIB entries for bd_id.
664
665 :param int sw_if_index: Bridge Domain id.
666 """
667 return self.api(self.papi.l2fib_flush_bd,
668 {'bd_id': bd_id})
669
670 def l2fib_flush_all(self):
671 """Flush all L2 FIB.
672 """
673 return self.api(self.papi.l2fib_flush_all, {})
674
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700675 def l2_fib_table_dump(self, bd_id):
676 """ Dump the L2 FIB """
677 return self.api(self.papi.l2_fib_table_dump,
678 {'bd_id': bd_id})
679
Klement Sekeraf62ae122016-10-11 11:47:09 +0200680 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700681 shg=0, port_type=L2_PORT_TYPE.NORMAL,
682 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100683 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200684
Jan4af521d2016-11-15 17:05:00 +0100685 :param int sw_if_index: Software interface index of the interface.
686 :param int bd_id: Bridge domain index.
687 :param int shg: Split-horizon group index. (Default value = 0)
688 :param int bvi: Set interface as a bridge group virtual interface.
689 (Default value = 0)
690 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200691 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100692 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200693 {'rx_sw_if_index': sw_if_index,
694 'bd_id': bd_id,
695 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700696 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200697 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200698
Jan00dad122016-11-29 10:04:53 +0100699 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400700 """Enable/disable required feature of the bridge domain with defined
701 ID.
Jan00dad122016-11-29 10:04:53 +0100702
703 :param int bd_id: Bridge domain ID.
704 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700705 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100706 - learn (1 << 0),
707 - forward (1 << 1),
708 - flood (1 << 2),
709 - uu-flood (1 << 3) or
710 - arp-term (1 << 4).
711 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100712 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200713 {'bd_id': bd_id,
714 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700715 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100716
717 def bridge_domain_dump(self, bd_id=0):
718 """
719
720 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
721 existing bridge domains returned)
722 :return: Dictionary of bridge domain(s) data.
723 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100724 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200725 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100726
Klement Sekeraf62ae122016-10-11 11:47:09 +0200727 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
728 enable):
729 """Create or delete unidirectional cross-connect from Tx interface to
730 Rx interface.
731
Jan4af521d2016-11-15 17:05:00 +0100732 :param int rx_sw_if_index: Software interface index of Rx interface.
733 :param int tx_sw_if_index: Software interface index of Tx interface.
734 :param int enable: Create cross-connect if equal to 1, delete
735 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200736
737 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100738 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200739 {'rx_sw_if_index': rx_sw_if_index,
740 'tx_sw_if_index': tx_sw_if_index,
741 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200742
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200743 def sw_interface_set_l2_tag_rewrite(
744 self,
745 sw_if_index,
746 vtr_oper,
747 push=0,
748 tag1=0,
749 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000750 """L2 interface vlan tag rewrite configure request
751 :param client_index - opaque cookie to identify the sender
752 :param context - sender context, to match reply w/ request
753 :param sw_if_index - interface the operation is applied to
754 :param vtr_op - Choose from l2_vtr_op_t enum values
755 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
756 :param tag1 - Needed for any push or translate vtr op
757 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
758
759 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100760 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200761 {'sw_if_index': sw_if_index,
762 'vtr_op': vtr_oper,
763 'push_dot1q': push,
764 'tag1': tag1,
765 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000766
Neale Ranns55d03782017-10-21 06:34:22 -0700767 def sw_interface_set_l2_emulation(
768 self,
769 sw_if_index,
770 enable=1):
771 """L2 Emulation
772 :param sw_if_index - interface the operation is applied to
773
774 """
775 return self.api(self.papi.l2_emulation,
776 {'sw_if_index': sw_if_index,
777 'enable': enable})
778
Neale Ranns1855b8e2018-07-11 10:31:26 -0700779 def sw_interface_set_ip_directed_broadcast(
780 self,
781 sw_if_index,
782 enable=1):
783 """IP Directed broadcast
784 :param sw_if_index - interface the operation is applied to
785
786 """
787 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
788 {'sw_if_index': sw_if_index,
789 'enable': enable})
790
Neale Rannsa07bd702017-08-07 07:53:49 -0700791 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200792 """
793
794 :param admin_up_down:
795 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200796
797 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100798 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200799 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700800 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200801
Ole Troand7231612018-06-07 10:17:57 +0200802 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800803 """
804 :param sw_if_index:
805 :param mtu:
806
807 """
808 return self.api(self.papi.sw_interface_set_mtu,
809 {'sw_if_index': sw_if_index,
810 'mtu': mtu})
811
Neale Ranns25b04942018-04-04 09:34:50 -0700812 def sw_interface_set_promiscuous(self, sw_if_index, enable):
813 """
814 :param sw_if_index:
815 :param enable:
816
817 """
818 return self.api(self.papi.sw_interface_set_promiscuous,
819 {'sw_if_index': sw_if_index,
820 'enable': enable})
821
Neale Rannsc819fc62018-02-16 02:44:05 -0800822 def sw_interface_set_mac_address(self, sw_if_index, mac):
823 return self.api(self.papi.sw_interface_set_mac_address,
824 {'sw_if_index': sw_if_index,
825 'mac_address': mac})
826
Klement Sekeraf62ae122016-10-11 11:47:09 +0200827 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
828 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
829 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
830 """Create subinterface
831 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
832
833 :param sub_id: param inner_vlan:
834 :param sw_if_index:
835 :param outer_vlan:
836 :param inner_vlan:
837 :param no_tags: (Default value = 0)
838 :param one_tag: (Default value = 0)
839 :param two_tags: (Default value = 0)
840 :param dot1ad: (Default value = 0)
841 :param exact_match: (Default value = 0)
842 :param default_sub: (Default value = 0)
843 :param outer_vlan_id_any: (Default value = 0)
844 :param inner_vlan_id_any: (Default value = 0)
845
846 """
847 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100848 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200849 {'sw_if_index': sw_if_index,
850 'sub_id': sub_id,
851 'no_tags': no_tags,
852 'one_tag': one_tag,
853 'two_tags': two_tags,
854 'dot1ad': dot1ad,
855 'exact_match': exact_match,
856 'default_sub': default_sub,
857 'outer_vlan_id_any': outer_vlan_id_any,
858 'inner_vlan_id_any': inner_vlan_id_any,
859 'outer_vlan_id': outer_vlan,
860 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200861
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200862 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
863 """Create p2p ethernet subinterface
864
865 :param sw_if_index: main (parent) interface
866 :param remote_mac: client (remote) mac address
867
868 """
869 return self.api(
870 self.papi.p2p_ethernet_add,
871 {'parent_if_index': sw_if_index,
872 'remote_mac': remote_mac,
873 'subif_id': subif_id})
874
Neale Ranns177bbdc2016-11-15 09:46:51 +0000875 def delete_subif(self, sw_if_index):
876 """Delete subinterface
877
878 :param sw_if_index:
879 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100880 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200881 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000882
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200883 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
884 """Delete p2p ethernet subinterface
885
886 :param sw_if_index: main (parent) interface
887 :param remote_mac: client (remote) mac address
888
889 """
890 return self.api(
891 self.papi.p2p_ethernet_del,
892 {'parent_if_index': sw_if_index,
893 'remote_mac': remote_mac})
894
Klement Sekeraf62ae122016-10-11 11:47:09 +0200895 def create_vlan_subif(self, sw_if_index, vlan):
896 """
897
898 :param vlan:
899 :param sw_if_index:
900
901 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100902 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200903 {'sw_if_index': sw_if_index,
904 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200905
Matej Klotton0178d522016-11-04 11:11:44 +0100906 def create_loopback(self, mac=''):
907 """
908
909 :param mac: (Optional)
910 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100911 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200912 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100913
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100914 def delete_loopback(self, sw_if_index):
915 return self.api(self.papi.delete_loopback,
916 {'sw_if_index': sw_if_index, })
917
Neale Ranns15002542017-09-10 04:39:11 -0700918 def ip_table_add_del(self,
919 table_id,
920 is_add=1,
921 is_ipv6=0):
922 """
923
924 :param table_id
925 :param is_add: (Default value = 1)
926 :param is_ipv6: (Default value = 0)
927
928 """
929
930 return self.api(
931 self.papi.ip_table_add_del,
932 {'table_id': table_id,
933 'is_add': is_add,
934 'is_ipv6': is_ipv6})
935
Klement Sekeraf62ae122016-10-11 11:47:09 +0200936 def ip_add_del_route(
937 self,
938 dst_address,
939 dst_address_length,
940 next_hop_address,
941 next_hop_sw_if_index=0xFFFFFFFF,
942 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200943 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000944 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200945 next_hop_n_out_labels=0,
946 next_hop_out_label_stack=[],
947 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800948 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000949 is_resolve_host=0,
950 is_resolve_attached=0,
951 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200952 is_add=1,
953 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200954 is_unreach=0,
955 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200956 is_ipv6=0,
957 is_local=0,
958 is_classify=0,
959 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800960 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800961 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200962 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200963 """
964
965 :param dst_address_length:
966 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
967 :param dst_address:
968 :param next_hop_address:
969 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
970 :param vrf_id: (Default value = 0)
971 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200972 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200973 :param is_add: (Default value = 1)
974 :param is_drop: (Default value = 0)
975 :param is_ipv6: (Default value = 0)
976 :param is_local: (Default value = 0)
977 :param is_classify: (Default value = 0)
978 :param is_multipath: (Default value = 0)
979 :param is_resolve_host: (Default value = 0)
980 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800981 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700982 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200983 :param next_hop_weight: (Default value = 1)
984
985 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000986
Klement Sekeraf62ae122016-10-11 11:47:09 +0200987 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100988 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200989 {'next_hop_sw_if_index': next_hop_sw_if_index,
990 'table_id': table_id,
991 'classify_table_index': classify_table_index,
992 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200993 'is_add': is_add,
994 'is_drop': is_drop,
995 'is_unreach': is_unreach,
996 'is_prohibit': is_prohibit,
997 'is_ipv6': is_ipv6,
998 'is_local': is_local,
999 'is_classify': is_classify,
1000 'is_multipath': is_multipath,
1001 'is_resolve_host': is_resolve_host,
1002 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -08001003 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -07001004 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -08001005 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001006 'next_hop_weight': next_hop_weight,
1007 'dst_address_length': dst_address_length,
1008 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -08001009 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001010 'next_hop_address': next_hop_address,
1011 'next_hop_n_out_labels': next_hop_n_out_labels,
1012 'next_hop_via_label': next_hop_via_label,
1013 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +01001014
Matej Klotton16a14cd2016-12-07 15:09:13 +01001015 def ip_fib_dump(self):
1016 return self.api(self.papi.ip_fib_dump, {})
1017
Jan Gelety057bb8c2016-12-20 17:32:45 +01001018 def ip6_fib_dump(self):
1019 return self.api(self.papi.ip6_fib_dump, {})
1020
Matej Klotton0178d522016-11-04 11:11:44 +01001021 def ip_neighbor_add_del(self,
1022 sw_if_index,
1023 mac_address,
1024 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001025 is_add=1,
1026 is_ipv6=0,
1027 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001028 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +01001029 ):
1030 """ Add neighbor MAC to IPv4 or IPv6 address.
1031
1032 :param sw_if_index:
1033 :param mac_address:
1034 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001035 :param is_add: (Default value = 1)
1036 :param is_ipv6: (Default value = 0)
1037 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001038 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001039 """
1040
1041 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001042 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001043 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001044 'is_add': is_add,
1045 'is_ipv6': is_ipv6,
1046 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001047 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001048 'mac_address': mac_address,
1049 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001050 }
Matej Klotton0178d522016-11-04 11:11:44 +01001051 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001052
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001053 def ip_neighbor_dump(self,
1054 sw_if_index,
1055 is_ipv6=0):
1056 """ Return IP neighbor dump.
1057
1058 :param sw_if_index:
1059 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1060 """
1061
1062 return self.api(
1063 self.papi.ip_neighbor_dump,
1064 {'is_ipv6': is_ipv6,
1065 'sw_if_index': sw_if_index
1066 }
1067 )
1068
1069 def proxy_arp_add_del(self,
1070 low_address,
1071 hi_address,
1072 vrf_id=0,
1073 is_add=1):
1074 """ Config Proxy Arp Range.
1075
1076 :param low_address: Start address in the rnage to Proxy for
1077 :param hi_address: End address in the rnage to Proxy for
1078 :param vrf_id: The VRF/table in which to proxy
1079 """
1080
1081 return self.api(
1082 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001083 {'proxy':
1084 {
1085 'vrf_id': vrf_id,
1086 'low_address': low_address,
1087 'hi_address': hi_address,
1088 },
1089 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001090
1091 def proxy_arp_intfc_enable_disable(self,
1092 sw_if_index,
1093 is_enable=1):
1094 """ Enable/Disable an interface for proxy ARP requests
1095
1096 :param sw_if_index: Interface
1097 :param enable_disable: Enable/Disable
1098 """
1099
1100 return self.api(
1101 self.papi.proxy_arp_intfc_enable_disable,
1102 {'sw_if_index': sw_if_index,
1103 'enable_disable': is_enable
1104 }
1105 )
1106
Jane546d3b2016-12-08 13:10:03 +01001107 def reset_vrf(self,
1108 vrf_id,
1109 is_ipv6=0,
1110 ):
1111 """ Reset VRF (remove all routes etc.) request.
1112
1113 :param int vrf_id: ID of the FIB table / VRF to reset.
1114 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1115 """
1116
1117 return self.api(
1118 self.papi.reset_vrf,
1119 {'vrf_id': vrf_id,
1120 'is_ipv6': is_ipv6,
1121 }
1122 )
1123
1124 def reset_fib(self,
1125 vrf_id,
1126 is_ipv6=0,
1127 ):
1128 """ Reset VRF (remove all routes etc.) request.
1129
1130 :param int vrf_id: ID of the FIB table / VRF to reset.
1131 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1132 """
1133
1134 return self.api(
1135 self.papi.reset_fib,
1136 {'vrf_id': vrf_id,
1137 'is_ipv6': is_ipv6,
1138 }
1139 )
1140
1141 def ip_dump(self,
1142 is_ipv6=0,
1143 ):
1144 """ Return IP dump.
1145
1146 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1147 """
1148
1149 return self.api(
1150 self.papi.ip_dump,
1151 {'is_ipv6': is_ipv6,
1152 }
1153 )
1154
Klement Sekera7bb873a2016-11-18 07:38:42 +01001155 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001156 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001157 """
1158
1159 :param sw_if_index_from:
1160 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001161 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001162 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001163 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001164 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001165 {'sw_if_index_from': sw_if_index_from,
1166 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001167 'state': state,
1168 'is_l2': is_l2,
1169 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001170
1171 def gre_tunnel_add_del(self,
1172 src_address,
1173 dst_address,
1174 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001175 tunnel_type=0,
1176 instance=0xFFFFFFFF,
1177 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001178 is_add=1,
1179 is_ip6=0):
1180 """ Add a GRE tunnel
1181
1182 :param src_address:
1183 :param dst_address:
1184 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001185 :param tunnel_type: (Default value = 0)
1186 :param instance: (Default value = 0xFFFFFFFF)
1187 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001188 :param is_add: (Default value = 1)
1189 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001190 """
1191
1192 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001193 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001194 {'is_add': is_add,
1195 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001196 'tunnel_type': tunnel_type,
1197 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001198 'src_address': src_address,
1199 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001200 'outer_fib_id': outer_fib_id,
1201 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001202 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001203
Neale Rannsd0df49f2018-08-08 01:06:40 -07001204 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001205 src_ip,
1206 dst_ip,
1207 src_port,
1208 dst_port,
1209 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001210 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001211 :param src_ip:
1212 :param dst_ip:
1213 :param src_port:
1214 :param dst_port:
1215 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001216 """
1217
1218 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001219 self.papi.udp_encap_add,
1220 {
1221 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001222 'src_ip': src_ip,
1223 'dst_ip': dst_ip,
1224 'src_port': src_port,
1225 'dst_port': dst_port,
1226 'table_id': table_id
1227 }
1228 })
1229
1230 def udp_encap_del(self, id):
1231 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001232
1233 def udp_encap_dump(self):
1234 return self.api(self.papi.udp_encap_dump, {})
1235
Neale Ranns43b1f442018-03-20 01:47:35 -07001236 def want_udp_encap_stats(self, enable=1):
1237 return self.api(self.papi.want_udp_encap_stats,
1238 {'enable': enable,
1239 'pid': os.getpid()})
1240
Neale Ranns5a8123b2017-01-26 01:18:23 -08001241 def mpls_fib_dump(self):
1242 return self.api(self.papi.mpls_fib_dump, {})
1243
Neale Ranns15002542017-09-10 04:39:11 -07001244 def mpls_table_add_del(
1245 self,
1246 table_id,
1247 is_add=1):
1248 """
1249
1250 :param table_id
1251 :param is_add: (Default value = 1)
1252
1253 """
1254
1255 return self.api(
1256 self.papi.mpls_table_add_del,
1257 {'mt_table_id': table_id,
1258 'mt_is_add': is_add})
1259
Neale Rannsad422ed2016-11-02 14:20:04 +00001260 def mpls_route_add_del(
1261 self,
1262 label,
1263 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001264 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001265 next_hop_address,
1266 next_hop_sw_if_index=0xFFFFFFFF,
1267 table_id=0,
1268 next_hop_table_id=0,
1269 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001270 next_hop_n_out_labels=0,
1271 next_hop_out_label_stack=[],
1272 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001273 is_resolve_host=0,
1274 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001275 is_interface_rx=0,
1276 is_rpf_id=0,
1277 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001278 is_add=1,
1279 is_drop=0,
1280 is_multipath=0,
1281 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001282 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001283 """
1284
1285 :param dst_address_length:
1286 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1287 :param dst_address:
1288 :param next_hop_address:
1289 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1290 :param vrf_id: (Default value = 0)
1291 :param lookup_in_vrf: (Default value = 0)
1292 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001293 :param is_add: (Default value = 1)
1294 :param is_drop: (Default value = 0)
1295 :param is_ipv6: (Default value = 0)
1296 :param is_local: (Default value = 0)
1297 :param is_classify: (Default value = 0)
1298 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001299 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001300 :param is_resolve_host: (Default value = 0)
1301 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001302 :param next_hop_weight: (Default value = 1)
1303
1304 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001305 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001306 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001307 {'mr_label': label,
1308 'mr_eos': eos,
1309 'mr_table_id': table_id,
1310 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001311 'mr_is_add': is_add,
1312 'mr_is_classify': is_classify,
1313 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001314 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001315 'mr_is_resolve_host': is_resolve_host,
1316 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001317 'mr_is_interface_rx': is_interface_rx,
1318 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001319 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001320 'mr_next_hop_weight': next_hop_weight,
1321 'mr_next_hop': next_hop_address,
1322 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1323 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1324 'mr_next_hop_table_id': next_hop_table_id,
1325 'mr_next_hop_via_label': next_hop_via_label,
1326 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001327
1328 def mpls_ip_bind_unbind(
1329 self,
1330 label,
1331 dst_address,
1332 dst_address_length,
1333 table_id=0,
1334 ip_table_id=0,
1335 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001336 is_bind=1):
1337 """
1338 """
1339 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001340 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001341 {'mb_mpls_table_id': table_id,
1342 'mb_label': label,
1343 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001344 'mb_is_bind': is_bind,
1345 'mb_is_ip4': is_ip4,
1346 'mb_address_length': dst_address_length,
1347 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001348
1349 def mpls_tunnel_add_del(
1350 self,
1351 tun_sw_if_index,
1352 next_hop_proto_is_ip4,
1353 next_hop_address,
1354 next_hop_sw_if_index=0xFFFFFFFF,
1355 next_hop_table_id=0,
1356 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001357 next_hop_n_out_labels=0,
1358 next_hop_out_label_stack=[],
1359 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001360 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001361 l2_only=0,
1362 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001363 """
1364
1365 :param dst_address_length:
1366 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1367 :param dst_address:
1368 :param next_hop_address:
1369 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1370 :param vrf_id: (Default value = 0)
1371 :param lookup_in_vrf: (Default value = 0)
1372 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001373 :param is_add: (Default value = 1)
1374 :param is_drop: (Default value = 0)
1375 :param is_ipv6: (Default value = 0)
1376 :param is_local: (Default value = 0)
1377 :param is_classify: (Default value = 0)
1378 :param is_multipath: (Default value = 0)
1379 :param is_resolve_host: (Default value = 0)
1380 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001381 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001382 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001383
1384 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001385 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001386 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001387 {'mt_sw_if_index': tun_sw_if_index,
1388 'mt_is_add': is_add,
1389 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001390 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001391 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1392 'mt_next_hop_weight': next_hop_weight,
1393 'mt_next_hop': next_hop_address,
1394 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1395 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1396 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001397 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001398 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001399
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001400 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1401 return self.api(self.papi.mpls_tunnel_dump,
1402 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001403
Matus Fabian2ba92e32017-08-21 07:05:03 -07001404 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001405 self,
1406 sw_if_index,
1407 is_inside=1,
1408 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001409 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001410
1411 :param sw_if_index: Software index of the interface
1412 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1413 :param is_add: 1 if add, 0 if delete (Default value = 1)
1414 """
1415 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001416 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001417 {'is_add': is_add,
1418 'is_inside': is_inside,
1419 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001420
Matus Fabian2ba92e32017-08-21 07:05:03 -07001421 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001422 self,
1423 sw_if_index,
1424 is_inside=1,
1425 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001426 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001427
1428 :param sw_if_index: Software index of the interface
1429 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1430 :param is_add: 1 if add, 0 if delete (Default value = 1)
1431 """
1432 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001433 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001434 {'is_add': is_add,
1435 'is_inside': is_inside,
1436 'sw_if_index': sw_if_index})
1437
Matus Fabian2ba92e32017-08-21 07:05:03 -07001438 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001439 self,
1440 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001441 external_ip=0,
1442 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001443 local_port=0,
1444 external_port=0,
1445 addr_only=1,
1446 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001447 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001448 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001449 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001450 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001451 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001452 is_add=1):
1453 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001454
1455 :param local_ip: Local IP address
1456 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001457 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001458 :param local_port: Local port number (Default value = 0)
1459 :param external_port: External port number (Default value = 0)
1460 :param addr_only: 1 if address only mapping, 0 if address and port
1461 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001462 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001463 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001464 :param self_twice_nat: 1 if translate external host address and port
1465 whenever external host address equals
1466 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001467 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001468 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001469 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001470 """
1471 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001472 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001473 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001474 'addr_only': addr_only,
1475 'local_ip_address': local_ip,
1476 'external_ip_address': external_ip,
1477 'local_port': local_port,
1478 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001479 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001480 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001481 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001482 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001483 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001484 'out2in_only': out2in_only,
1485 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001486
Matus Fabianab7a8052017-11-28 04:29:41 -08001487 def nat44_add_del_identity_mapping(
1488 self,
1489 ip='0',
1490 sw_if_index=0xFFFFFFFF,
1491 port=0,
1492 addr_only=1,
1493 vrf_id=0,
1494 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001495 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001496 is_add=1):
1497 """Add/delete NAT44 identity mapping
1498
1499 :param ip: IP address (Default value = 0)
1500 :param sw_if_index: Interface instead of IP address
1501 :param port: Port number (Default value = 0)
1502 :param addr_only: 1 if address only mapping, 0 if address and port
1503 :param vrf_id: VRF ID
1504 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001505 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001506 :param is_add: 1 if add, 0 if delete (Default value = 1)
1507 """
1508 return self.api(
1509 self.papi.nat44_add_del_identity_mapping,
1510 {'is_add': is_add,
1511 'addr_only': addr_only,
1512 'ip_address': ip,
1513 'port': port,
1514 'sw_if_index': sw_if_index,
1515 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001516 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001517 'protocol': protocol})
1518
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001520 self,
1521 first_ip_address,
1522 last_ip_address,
1523 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001524 vrf_id=0xFFFFFFFF,
1525 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001526 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001527
1528 :param first_ip_address: First IP address
1529 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001530 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001531 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001532 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001533 """
1534 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001535 self.papi.nat44_add_del_address_range,
1536 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001537 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001538 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001539 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001540 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat44_address_dump(self):
1543 """Dump NAT44 addresses
1544 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001545 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001546 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001547
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 def nat44_interface_dump(self):
1549 """Dump interfaces with NAT44 feature
1550 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001551 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001552 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001553
Matus Fabian2ba92e32017-08-21 07:05:03 -07001554 def nat44_interface_output_feature_dump(self):
1555 """Dump interfaces with NAT44 output feature
1556 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001557 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001558 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001559
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 def nat44_static_mapping_dump(self):
1561 """Dump NAT44 static mappings
1562 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001563 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001564 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001565
Matus Fabianab7a8052017-11-28 04:29:41 -08001566 def nat44_identity_mapping_dump(self):
1567 """Dump NAT44 identity mappings
1568 :return: Dictionary of NAT44 identity mappings
1569 """
1570 return self.api(self.papi.nat44_identity_mapping_dump, {})
1571
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 def nat_show_config(self):
1573 """Show NAT plugin config
1574 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001575 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001577
Matus Fabian2ba92e32017-08-21 07:05:03 -07001578 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001579 self,
1580 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001581 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001582 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001583 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001584
1585 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001586 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001587 :param is_add: 1 if add, 0 if delete (Default value = 1)
1588 """
Matus Fabianb932d262017-12-18 05:38:24 -08001589 return self.api(
1590 self.papi.nat44_add_del_interface_addr,
1591 {'is_add': is_add,
1592 'sw_if_index': sw_if_index,
1593 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001594
Matus Fabian2ba92e32017-08-21 07:05:03 -07001595 def nat44_interface_addr_dump(self):
1596 """Dump NAT44 addresses interfaces
1597 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001598 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001599 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001600
Matus Fabian2ba92e32017-08-21 07:05:03 -07001601 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001602 self,
1603 domain_id=1,
1604 src_port=4739,
1605 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001606 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001607
1608 :param domain_id: Observation domain ID (Default value = 1)
1609 :param src_port: Source port number (Default value = 4739)
1610 :param enable: 1 if enable, 0 if disable (Default value = 1)
1611 """
1612 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001613 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001614 {'domain_id': domain_id,
1615 'src_port': src_port,
1616 'enable': enable})
1617
Matus Fabian2ba92e32017-08-21 07:05:03 -07001618 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001619 self,
1620 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001621 vrf_id):
1622 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001623
1624 :param ip_address: ip adress of the user to be dumped
1625 :param cpu_index: cpu_index on which the user is
1626 :param vrf_id: VRF ID
1627 :return: Dictionary of S-NAT sessions
1628 """
1629 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001630 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001631 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001632 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001633
Matus Fabian2ba92e32017-08-21 07:05:03 -07001634 def nat44_user_dump(self):
1635 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001636
Matus Fabian2ba92e32017-08-21 07:05:03 -07001637 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001638 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001639 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001640
Matus Fabian704018c2017-09-04 02:17:18 -07001641 def nat44_add_del_lb_static_mapping(
1642 self,
1643 external_addr,
1644 external_port,
1645 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001646 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001647 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001648 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001649 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001650 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001651 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001652 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001653 is_add=1):
1654 """Add/delete NAT44 load balancing static mapping
1655
Matus Fabianb932d262017-12-18 05:38:24 -08001656 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001657 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001658 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001659 :param is_add - 1 if add, 0 if delete
1660 """
1661 return self.api(
1662 self.papi.nat44_add_del_lb_static_mapping,
1663 {'is_add': is_add,
1664 'external_addr': external_addr,
1665 'external_port': external_port,
1666 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001667 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001668 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001669 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001670 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001671 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001672 'local_num': local_num,
1673 'locals': locals})
1674
1675 def nat44_lb_static_mapping_dump(self):
1676 """Dump NAT44 load balancing static mappings
1677
1678 :return: Dictionary of NAT44 load balancing static mapping
1679 """
1680 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1681
Matus Fabian5ba86f72017-10-26 03:37:38 -07001682 def nat44_del_session(
1683 self,
1684 addr,
1685 port,
1686 protocol,
1687 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001688 is_in=1,
1689 ext_host_address=None,
1690 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001691 """Delete NAT44 session
1692
1693 :param addr: IPv4 address
1694 :param por: port number
1695 :param protocol: IP protocol number
1696 :param vrf_id: VRF ID
1697 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001698 :param ext_host_address: external host IPv4 address
1699 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001700 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001701 if ext_host_address is None:
1702 return self.api(
1703 self.papi.nat44_del_session,
1704 {'address': addr,
1705 'port': port,
1706 'protocol': protocol,
1707 'vrf_id': vrf_id,
1708 'is_in': is_in})
1709 else:
1710 return self.api(
1711 self.papi.nat44_del_session,
1712 {'address': addr,
1713 'port': port,
1714 'protocol': protocol,
1715 'vrf_id': vrf_id,
1716 'is_in': is_in,
1717 'ext_host_valid': 1,
1718 'ext_host_address': ext_host_address,
1719 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001720
Juraj Sloboda7b929792017-11-23 13:20:48 +01001721 def nat44_forwarding_enable_disable(
1722 self,
1723 enable):
1724 """Enable/disable forwarding for NAT44
1725
1726 :param enable: 1 for enable, 0 for disable
1727 """
1728 return self.api(
1729 self.papi.nat44_forwarding_enable_disable,
1730 {'enable': enable})
1731
Matus Fabianefcd1e92017-08-15 06:59:19 -07001732 def nat_set_reass(
1733 self,
1734 timeout=2,
1735 max_reass=1024,
1736 max_frag=5,
1737 drop_frag=0,
1738 is_ip6=0):
1739 """Set NAT virtual fragmentation reassembly
1740
1741 :param timeout: reassembly timeout (Default 2sec)
1742 :param max_reass: maximum concurrent reassemblies (Default 1024)
1743 :param max_frag: maximum fragmets per reassembly (Default 5)
1744 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1745 :param is_ip6: 1 if IPv6, 0 if IPv4
1746 """
1747 return self.api(
1748 self.papi.nat_set_reass,
1749 {'timeout': timeout,
1750 'max_reass': max_reass,
1751 'max_frag': max_frag,
1752 'drop_frag': drop_frag,
1753 'is_ip6': is_ip6})
1754
1755 def nat_get_reass(self):
1756 """Get NAT virtual fragmentation reassembly configuration
1757
1758 :return: NAT virtual fragmentation reassembly configuration
1759 """
1760 return self.api(self.papi.nat_get_reass, {})
1761
1762 def nat_reass_dump(self):
1763 """Dump NAT virtual fragmentation reassemblies
1764
1765 :return: Dictionary of NAT virtual fragmentation reassemblies
1766 """
1767 return self.api(self.papi.nat_reass_dump, {})
1768
Matus Fabian2ba92e32017-08-21 07:05:03 -07001769 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001770 self,
1771 in_addr,
1772 in_plen,
1773 out_addr,
1774 out_plen,
1775 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001776 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001777
1778 :param is_add - 1 if add, 0 if delete
1779 :param in_addr - inside IP address
1780 :param in_plen - inside IP address prefix length
1781 :param out_addr - outside IP address
1782 :param out_plen - outside IP address prefix length
1783 """
1784 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001785 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001786 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001787 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001788 'in_addr': in_addr,
1789 'in_plen': in_plen,
1790 'out_addr': out_addr,
1791 'out_plen': out_plen})
1792
Matus Fabian2ba92e32017-08-21 07:05:03 -07001793 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001794 self,
1795 in_addr):
1796 """Get outside address and port range from inside address
1797
1798 :param in_addr - inside IP address
1799 """
1800 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001801 self.papi.nat_det_forward,
1802 {'in_addr': in_addr,
1803 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001804
Matus Fabian2ba92e32017-08-21 07:05:03 -07001805 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001806 self,
1807 out_addr,
1808 out_port):
1809 """Get inside address from outside address and port
1810
1811 :param out_addr - outside IP address
1812 :param out_port - outside port
1813 """
1814 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001815 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001816 {'out_addr': out_addr,
1817 'out_port': out_port})
1818
Matus Fabian2ba92e32017-08-21 07:05:03 -07001819 def nat_det_map_dump(self):
1820 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001821
Matus Fabian2ba92e32017-08-21 07:05:03 -07001822 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001823 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001824 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001825
Matus Fabian878c6462018-08-23 00:33:35 -07001826 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001827 self,
1828 udp=300,
1829 tcp_established=7440,
1830 tcp_transitory=240,
1831 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001832 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001833
1834 :param udp - UDP timeout (Default value = 300)
1835 :param tcp_established - TCP established timeout (Default value = 7440)
1836 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1837 :param icmp - ICMP timeout (Default value = 60)
1838 """
1839 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001840 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001841 {'udp': udp,
1842 'tcp_established': tcp_established,
1843 'tcp_transitory': tcp_transitory,
1844 'icmp': icmp})
1845
Matus Fabian878c6462018-08-23 00:33:35 -07001846 def nat_get_timeouts(self):
1847 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001848
Matus Fabian878c6462018-08-23 00:33:35 -07001849 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001850 """
Matus Fabian878c6462018-08-23 00:33:35 -07001851 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001852
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001853 def nat_set_addr_and_port_alloc_alg(
1854 self,
1855 alg=0,
1856 psid_offset=0,
1857 psid_length=0,
1858 psid=0,
1859 start_port=0,
1860 end_port=0):
1861 """Set address and port assignment algorithm
1862
1863 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1864 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1865 :param psid_length: length of PSID (valid only for MAP-E alg)
1866 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1867 :param start_port: beginning of the port range
1868 :param end_port: end of the port range
1869 """
1870 return self.api(
1871 self.papi.nat_set_addr_and_port_alloc_alg,
1872 {'alg': alg,
1873 'psid_offset': psid_offset,
1874 'psid_length': psid_length,
1875 'psid': psid,
1876 'start_port': start_port,
1877 'end_port': end_port})
1878
1879 def nat_get_addr_and_port_alloc_alg(self):
1880 """Get address and port assignment algorithm"""
1881 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1882
Matus Fabianbb4e0222018-09-13 02:36:25 -07001883 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1884 """Set TCP MSS rewriting configuration
1885
1886 :param enable: disable(0)/enable(1) MSS rewriting feature
1887 :param mss_value: MSS value to be used for MSS rewriting
1888 """
1889 return self.api(
1890 self.papi.nat_set_mss_clamping,
1891 {'enable': enable, 'mss_value': mss_value})
1892
1893 def nat_get_mss_clamping(self):
1894 """Get TCP MSS rewriting configuration"""
1895 return self.api(self.papi.nat_get_mss_clamping, {})
1896
Matus Fabian2ba92e32017-08-21 07:05:03 -07001897 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001898 self,
1899 out_addr,
1900 out_port,
1901 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001902 ext_port):
1903 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001904
1905 :param out_addr - outside IP address
1906 :param out_port - outside port
1907 :param ext_addr - external host IP address
1908 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001909 """
1910 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001911 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001912 {'out_addr': out_addr,
1913 'out_port': out_port,
1914 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001915 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001916
Matus Fabian2ba92e32017-08-21 07:05:03 -07001917 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001918 self,
1919 in_addr,
1920 in_port,
1921 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001922 ext_port):
1923 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001924
1925 :param in_addr - inside IP address
1926 :param in_port - inside port
1927 :param ext_addr - external host IP address
1928 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001929 """
1930 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001931 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001932 {'in_addr': in_addr,
1933 'in_port': in_port,
1934 'ext_addr': ext_addr,
1935 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001936 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001937
Matus Fabian2ba92e32017-08-21 07:05:03 -07001938 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001939 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001940 user_addr):
1941 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001942
1943 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001944 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001945 """
1946 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001947 self.papi.nat_det_session_dump,
1948 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001949 'user_addr': user_addr})
1950
Matus Fabian06596c52017-06-06 04:53:28 -07001951 def nat64_add_del_pool_addr_range(
1952 self,
1953 start_addr,
1954 end_addr,
1955 vrf_id=0xFFFFFFFF,
1956 is_add=1):
1957 """Add/del address range to NAT64 pool
1958
1959 :param start_addr: First IP address
1960 :param end_addr: Last IP address
1961 :param vrf_id: VRF id for the address range
1962 :param is_add: 1 if add, 0 if delete (Default value = 1)
1963 """
1964 return self.api(
1965 self.papi.nat64_add_del_pool_addr_range,
1966 {'start_addr': start_addr,
1967 'end_addr': end_addr,
1968 'vrf_id': vrf_id,
1969 'is_add': is_add})
1970
1971 def nat64_pool_addr_dump(self):
1972 """Dump NAT64 pool addresses
1973 :return: Dictionary of NAT64 pool addresses
1974 """
1975 return self.api(self.papi.nat64_pool_addr_dump, {})
1976
1977 def nat64_add_del_interface(
1978 self,
1979 sw_if_index,
1980 is_inside=1,
1981 is_add=1):
1982 """Enable/disable NAT64 feature on the interface
1983 :param sw_if_index: Index of the interface
1984 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1985 :param is_add: 1 if add, 0 if delete (Default value = 1)
1986 """
1987 return self.api(
1988 self.papi.nat64_add_del_interface,
1989 {'sw_if_index': sw_if_index,
1990 'is_inside': is_inside,
1991 'is_add': is_add})
1992
1993 def nat64_interface_dump(self):
1994 """Dump interfaces with NAT64 feature
1995 :return: Dictionary of interfaces with NAT64 feature
1996 """
1997 return self.api(self.papi.nat64_interface_dump, {})
1998
1999 def nat64_add_del_static_bib(
2000 self,
2001 in_ip,
2002 out_ip,
2003 in_port,
2004 out_port,
2005 protocol,
2006 vrf_id=0,
2007 is_add=1):
2008 """Add/delete S-NAT static BIB entry
2009
2010 :param in_ip: Inside IPv6 address
2011 :param out_ip: Outside IPv4 address
2012 :param in_port: Inside port number
2013 :param out_port: Outside port number
2014 :param protocol: IP protocol
2015 :param vrf_id: VRF ID (Default value = 0)
2016 :param is_add: 1 if add, 0 if delete (Default value = 1)
2017 """
2018 return self.api(
2019 self.papi.nat64_add_del_static_bib,
2020 {'i_addr': in_ip,
2021 'o_addr': out_ip,
2022 'i_port': in_port,
2023 'o_port': out_port,
2024 'vrf_id': vrf_id,
2025 'proto': protocol,
2026 'is_add': is_add})
2027
Matus Fabianab9a59c2017-08-16 05:37:36 -07002028 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002029 """Dump NAT64 BIB
2030
Matus Fabianab9a59c2017-08-16 05:37:36 -07002031 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002032 :returns: Dictionary of NAT64 BIB entries
2033 """
2034 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2035
2036 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2037 tcp_incoming_syn=6):
2038 """Set values of timeouts for NAT64 (in seconds)
2039
Matus Fabian428dc912017-06-21 06:15:18 -07002040 :param udpi: UDP timeout (Default value = 300)
2041 :param icmp: ICMP timeout (Default value = 60)
2042 :param tcp_trans: TCP transitory timeout (Default value = 240)
2043 :param tcp_est: TCP established timeout (Default value = 7440)
2044 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002045 """
2046 return self.api(
2047 self.papi.nat64_set_timeouts,
2048 {'udp': udp,
2049 'icmp': icmp,
2050 'tcp_trans': tcp_trans,
2051 'tcp_est': tcp_est,
2052 'tcp_incoming_syn': tcp_incoming_syn})
2053
2054 def nat64_get_timeouts(self):
2055 """Get values of timeouts for NAT64
2056
2057 :return: Timeouts for NAT64 (in seconds)
2058 """
2059 return self.api(self.papi.nat64_get_timeouts, {})
2060
Matus Fabianab9a59c2017-08-16 05:37:36 -07002061 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002062 """Dump NAT64 session table
2063
Matus Fabianab9a59c2017-08-16 05:37:36 -07002064 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002065 :returns: Dictionary of NAT64 sesstion table entries
2066 """
2067 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2068
Matus Fabian428dc912017-06-21 06:15:18 -07002069 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2070 """Add/del NAT64 prefix
2071
2072 :param prefix: NAT64 prefix
2073 :param plen: NAT64 prefix length
2074 :param vrf_id: VRF id of tenant (Default 0)
2075 :param is_add: 1 if add, 0 if delete (Default value = 1)
2076 """
2077 return self.api(
2078 self.papi.nat64_add_del_prefix,
2079 {'prefix': prefix,
2080 'prefix_len': plen,
2081 'vrf_id': vrf_id,
2082 'is_add': is_add})
2083
2084 def nat64_prefix_dump(self):
2085 """Dump NAT64 prefix
2086
2087 :returns: Dictionary of NAT64 prefixes
2088 """
2089 return self.api(self.papi.nat64_prefix_dump, {})
2090
Matus Fabian0938dcf2017-11-08 01:59:38 -08002091 def nat64_add_interface_addr(
2092 self,
2093 sw_if_index,
2094 is_add=1):
2095 """Add/del NAT64 address from interface
2096
2097 :param sw_if_index: Software index of the interface
2098 :param is_add: 1 if add, 0 if delete (Default value = 1)
2099 """
2100 return self.api(self.papi.nat64_add_del_interface_addr,
2101 {'is_add': is_add, 'sw_if_index': sw_if_index})
2102
Matus Fabian8ebe6252017-11-06 05:04:53 -08002103 def dslite_set_aftr_addr(self, ip6, ip4):
2104 """Set DS-Lite AFTR addresses
2105
2106 :param ip4: IPv4 address
2107 :param ip6: IPv6 address
2108 """
2109 return self.api(
2110 self.papi.dslite_set_aftr_addr,
2111 {'ip4_addr': ip4,
2112 'ip6_addr': ip6})
2113
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002114 def dslite_set_b4_addr(self, ip6, ip4):
2115 """Set DS-Lite B4 IPv6 address
2116
2117 :param ip4: IPv4 address
2118 :param ip6: IPv6 address
2119 """
2120 return self.api(
2121 self.papi.dslite_set_b4_addr,
2122 {'ip4_addr': ip4,
2123 'ip6_addr': ip6})
2124
Matus Fabian8ebe6252017-11-06 05:04:53 -08002125 def dslite_add_del_pool_addr_range(
2126 self,
2127 start_addr,
2128 end_addr,
2129 is_add=1):
2130 """Add/del address range to DS-Lite pool
2131
2132 :param start_addr: First IP address
2133 :param end_addr: Last IP address
2134 :param is_add: 1 if add, 0 if delete (Default value = 1)
2135 """
2136 return self.api(
2137 self.papi.dslite_add_del_pool_addr_range,
2138 {'start_addr': start_addr,
2139 'end_addr': end_addr,
2140 'is_add': is_add})
2141
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002142 def nat66_add_del_interface(
2143 self,
2144 sw_if_index,
2145 is_inside=1,
2146 is_add=1):
2147 """Enable/disable NAT66 feature on the interface
2148 :param sw_if_index: Index of the interface
2149 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2150 :param is_add: 1 if add, 0 if delete (Default value = 1)
2151 """
2152 return self.api(
2153 self.papi.nat66_add_del_interface,
2154 {'sw_if_index': sw_if_index,
2155 'is_inside': is_inside,
2156 'is_add': is_add})
2157
2158 def nat66_add_del_static_mapping(
2159 self,
2160 in_ip,
2161 out_ip,
2162 vrf_id=0,
2163 is_add=1):
2164 """Add/delete NAT66 static mapping
2165
2166 :param in_ip: Inside IPv6 address
2167 :param out_ip: Outside IPv6 address
2168 :param vrf_id: VRF ID (Default value = 0)
2169 :param is_add: 1 if add, 0 if delete (Default value = 1)
2170 """
2171 return self.api(
2172 self.papi.nat66_add_del_static_mapping,
2173 {'local_ip_address': in_ip,
2174 'external_ip_address': out_ip,
2175 'vrf_id': vrf_id,
2176 'is_add': is_add})
2177
2178 def nat66_interface_dump(self):
2179 """Dump interfaces with NAT66 feature
2180 :return: Dictionary of interfaces with NAT66 feature
2181 """
2182 return self.api(self.papi.nat66_interface_dump, {})
2183
2184 def nat66_static_mapping_dump(self):
2185 """Dump NAT66 static mappings
2186 :return: Dictionary of NAT66 static mappings
2187 """
2188 return self.api(self.papi.nat66_static_mapping_dump, {})
2189
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002190 def control_ping(self):
2191 self.api(self.papi.control_ping)
2192
2193 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002194 detect_mult, local_addr, peer_addr, is_ipv6=0,
2195 bfd_key_id=None, conf_key_id=None):
2196 if bfd_key_id is None:
2197 return self.api(self.papi.bfd_udp_add,
2198 {
2199 'sw_if_index': sw_if_index,
2200 'desired_min_tx': desired_min_tx,
2201 'required_min_rx': required_min_rx,
2202 'local_addr': local_addr,
2203 'peer_addr': peer_addr,
2204 'is_ipv6': is_ipv6,
2205 'detect_mult': detect_mult,
2206 })
2207 else:
2208 return self.api(self.papi.bfd_udp_add,
2209 {
2210 'sw_if_index': sw_if_index,
2211 'desired_min_tx': desired_min_tx,
2212 'required_min_rx': required_min_rx,
2213 'local_addr': local_addr,
2214 'peer_addr': peer_addr,
2215 'is_ipv6': is_ipv6,
2216 'detect_mult': detect_mult,
2217 'is_authenticated': 1,
2218 'bfd_key_id': bfd_key_id,
2219 'conf_key_id': conf_key_id,
2220 })
2221
Klement Sekeraa57a9702017-02-02 06:58:07 +01002222 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2223 detect_mult, local_addr, peer_addr, is_ipv6=0):
2224 return self.api(self.papi.bfd_udp_mod,
2225 {
2226 'sw_if_index': sw_if_index,
2227 'desired_min_tx': desired_min_tx,
2228 'required_min_rx': required_min_rx,
2229 'local_addr': local_addr,
2230 'peer_addr': peer_addr,
2231 'is_ipv6': is_ipv6,
2232 'detect_mult': detect_mult,
2233 })
2234
Klement Sekerab17dd962017-01-09 07:43:48 +01002235 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2236 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2237 is_delayed=False):
2238 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002239 {
2240 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002241 'local_addr': local_addr,
2242 'peer_addr': peer_addr,
2243 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002244 'is_delayed': 1 if is_delayed else 0,
2245 'bfd_key_id': bfd_key_id,
2246 'conf_key_id': conf_key_id,
2247 })
2248
2249 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2250 is_ipv6=0, is_delayed=False):
2251 return self.api(self.papi.bfd_udp_auth_deactivate,
2252 {
2253 'sw_if_index': sw_if_index,
2254 'local_addr': local_addr,
2255 'peer_addr': peer_addr,
2256 'is_ipv6': is_ipv6,
2257 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002258 })
2259
2260 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2261 return self.api(self.papi.bfd_udp_del,
2262 {
2263 'sw_if_index': sw_if_index,
2264 'local_addr': local_addr,
2265 'peer_addr': peer_addr,
2266 'is_ipv6': is_ipv6,
2267 })
2268
2269 def bfd_udp_session_dump(self):
2270 return self.api(self.papi.bfd_udp_session_dump, {})
2271
Klement Sekerab17dd962017-01-09 07:43:48 +01002272 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2273 peer_addr, is_ipv6=0):
2274 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002275 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002276 'sw_if_index': sw_if_index,
2277 'local_addr': local_addr,
2278 'peer_addr': peer_addr,
2279 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002280 })
2281
2282 def want_bfd_events(self, enable_disable=1):
2283 return self.api(self.papi.want_bfd_events, {
2284 'enable_disable': enable_disable,
2285 'pid': os.getpid(),
2286 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002287
Klement Sekerab17dd962017-01-09 07:43:48 +01002288 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2289 return self.api(self.papi.bfd_auth_set_key, {
2290 'conf_key_id': conf_key_id,
2291 'auth_type': auth_type,
2292 'key': key,
2293 'key_len': len(key),
2294 })
2295
2296 def bfd_auth_del_key(self, conf_key_id):
2297 return self.api(self.papi.bfd_auth_del_key, {
2298 'conf_key_id': conf_key_id,
2299 })
2300
2301 def bfd_auth_keys_dump(self):
2302 return self.api(self.papi.bfd_auth_keys_dump, {})
2303
Klement Sekera239790f2017-02-16 10:53:53 +01002304 def bfd_udp_set_echo_source(self, sw_if_index):
2305 return self.api(self.papi.bfd_udp_set_echo_source,
2306 {'sw_if_index': sw_if_index})
2307
Klement Sekera73884482017-02-23 09:26:30 +01002308 def bfd_udp_del_echo_source(self):
2309 return self.api(self.papi.bfd_udp_del_echo_source, {})
2310
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002311 def bfd_udp_get_echo_source(self):
2312 return self.api(self.papi.bfd_udp_get_echo_source, {})
2313
Steve Shin7957d6e2016-12-19 09:24:50 -08002314 def classify_add_del_table(
2315 self,
2316 is_add,
2317 mask,
2318 match_n_vectors=1,
2319 table_index=0xFFFFFFFF,
2320 nbuckets=2,
2321 memory_size=2097152,
2322 skip_n_vectors=0,
2323 next_table_index=0xFFFFFFFF,
2324 miss_next_index=0xFFFFFFFF,
2325 current_data_flag=0,
2326 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002327 """
2328 :param is_add:
2329 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002330 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002331 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002332 :param nbuckets: (Default value = 2)
2333 :param memory_size: (Default value = 2097152)
2334 :param skip_n_vectors: (Default value = 0)
2335 :param next_table_index: (Default value = 0xFFFFFFFF)
2336 :param miss_next_index: (Default value = 0xFFFFFFFF)
2337 :param current_data_flag: (Default value = 0)
2338 :param current_data_offset: (Default value = 0)
2339 """
2340
Juraj Sloboda75282452018-06-12 14:20:49 +02002341 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2342 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002343 return self.api(
2344 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002345 {'is_add': is_add,
2346 'table_index': table_index,
2347 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002348 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002349 'skip_n_vectors': skip_n_vectors,
2350 'match_n_vectors': match_n_vectors,
2351 'next_table_index': next_table_index,
2352 'miss_next_index': miss_next_index,
2353 'current_data_flag': current_data_flag,
2354 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002355 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002356 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002357
2358 def classify_add_del_session(
2359 self,
2360 is_add,
2361 table_index,
2362 match,
2363 opaque_index=0xFFFFFFFF,
2364 hit_next_index=0xFFFFFFFF,
2365 advance=0,
2366 action=0,
2367 metadata=0):
2368 """
2369 :param is_add:
2370 :param table_index:
2371 :param match:
2372 :param opaque_index: (Default value = 0xFFFFFFFF)
2373 :param hit_next_index: (Default value = 0xFFFFFFFF)
2374 :param advance: (Default value = 0)
2375 :param action: (Default value = 0)
2376 :param metadata: (Default value = 0)
2377 """
2378
Juraj Sloboda75282452018-06-12 14:20:49 +02002379 match_len = ((len(match) - 1) / 16 + 1) * 16
2380 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002381 return self.api(
2382 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002383 {'is_add': is_add,
2384 'table_index': table_index,
2385 'hit_next_index': hit_next_index,
2386 'opaque_index': opaque_index,
2387 'advance': advance,
2388 'action': action,
2389 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002390 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002391 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002392
2393 def input_acl_set_interface(
2394 self,
2395 is_add,
2396 sw_if_index,
2397 ip4_table_index=0xFFFFFFFF,
2398 ip6_table_index=0xFFFFFFFF,
2399 l2_table_index=0xFFFFFFFF):
2400 """
2401 :param is_add:
2402 :param sw_if_index:
2403 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2404 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2405 :param l2_table_index: (Default value = 0xFFFFFFFF)
2406 """
2407
2408 return self.api(
2409 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002410 {'sw_if_index': sw_if_index,
2411 'ip4_table_index': ip4_table_index,
2412 'ip6_table_index': ip6_table_index,
2413 'l2_table_index': l2_table_index,
2414 'is_add': is_add})
2415
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002416 def output_acl_set_interface(
2417 self,
2418 is_add,
2419 sw_if_index,
2420 ip4_table_index=0xFFFFFFFF,
2421 ip6_table_index=0xFFFFFFFF,
2422 l2_table_index=0xFFFFFFFF):
2423 """
2424 :param is_add:
2425 :param sw_if_index:
2426 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2427 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2428 :param l2_table_index: (Default value = 0xFFFFFFFF)
2429 """
2430
2431 return self.api(
2432 self.papi.output_acl_set_interface,
2433 {'sw_if_index': sw_if_index,
2434 'ip4_table_index': ip4_table_index,
2435 'ip6_table_index': ip6_table_index,
2436 'l2_table_index': l2_table_index,
2437 'is_add': is_add})
2438
Klement Sekera77fabdb2017-01-02 07:46:14 +01002439 def set_ipfix_exporter(
2440 self,
2441 collector_address,
2442 src_address,
2443 path_mtu,
2444 template_interval,
2445 vrf_id=0,
2446 collector_port=4739,
2447 udp_checksum=0):
2448 return self.api(
2449 self.papi.set_ipfix_exporter,
2450 {
2451 'collector_address': collector_address,
2452 'collector_port': collector_port,
2453 'src_address': src_address,
2454 'vrf_id': vrf_id,
2455 'path_mtu': path_mtu,
2456 'template_interval': template_interval,
2457 'udp_checksum': udp_checksum,
2458 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002459
2460 def dhcp_proxy_config(self,
2461 dhcp_server,
2462 dhcp_src_address,
2463 rx_table_id=0,
2464 server_table_id=0,
2465 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002466 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002467 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002468 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002469 {
2470 'rx_vrf_id': rx_table_id,
2471 'server_vrf_id': server_table_id,
2472 'is_ipv6': is_ipv6,
2473 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002474 'dhcp_server': dhcp_server,
2475 'dhcp_src_address': dhcp_src_address,
2476 })
2477
2478 def dhcp_proxy_set_vss(self,
2479 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002480 vss_type=255,
2481 vpn_ascii_id="",
2482 oui=0,
2483 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002484 is_add=1,
2485 is_ip6=0):
2486 return self.api(
2487 self.papi.dhcp_proxy_set_vss,
2488 {
2489 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002490 'vss_type': vss_type,
2491 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002492 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002493 'vpn_index': vpn_index,
2494 'is_add': is_add,
2495 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002496 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002497
Neale Rannsdaff1782018-05-16 04:12:18 -07002498 def dhcp_client_dump(self):
2499 return self.api(self.papi.dhcp_client_dump, {})
2500
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002501 def dhcp_client(self,
2502 sw_if_index,
2503 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002504 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002505 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002506 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002507 want_dhcp_events=0):
2508 return self.api(
2509 self.papi.dhcp_client_config,
2510 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002511 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002512 'client': {
2513 'sw_if_index': sw_if_index,
2514 'hostname': hostname,
2515 'id': client_id,
2516 'want_dhcp_event': want_dhcp_events,
2517 'set_broadcast_flag': set_broadcast_flag,
2518 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002519 })
2520
Neale Ranns32e1c012016-11-22 17:07:28 +00002521 def ip_mroute_add_del(self,
2522 src_address,
2523 grp_address,
2524 grp_address_length,
2525 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002526 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002527 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002528 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002529 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002530 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002531 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002532 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002533 is_add=1,
2534 is_ipv6=0,
2535 is_local=0):
2536 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002537 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002538 """
2539 return self.api(
2540 self.papi.ip_mroute_add_del,
2541 {'next_hop_sw_if_index': next_hop_sw_if_index,
2542 'entry_flags': e_flags,
2543 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002544 'table_id': table_id,
2545 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002546 'is_add': is_add,
2547 'is_ipv6': is_ipv6,
2548 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002549 'bier_imp': bier_imp,
2550 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002551 'grp_address_length': grp_address_length,
2552 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002553 'src_address': src_address,
2554 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002555
2556 def mfib_signal_dump(self):
2557 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002558
2559 def ip_mfib_dump(self):
2560 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002561
Neale Rannsd792d9c2017-10-21 10:53:20 -07002562 def ip6_mfib_dump(self):
2563 return self.api(self.papi.ip6_mfib_dump, {})
2564
Filip Tehlar770e89e2017-01-31 10:39:16 +01002565 def lisp_enable_disable(self, is_enabled):
2566 return self.api(
2567 self.papi.lisp_enable_disable,
2568 {
2569 'is_en': is_enabled,
2570 })
2571
2572 def lisp_locator_set(self,
2573 ls_name,
2574 is_add=1):
2575 return self.api(
2576 self.papi.lisp_add_del_locator_set,
2577 {
2578 'is_add': is_add,
2579 'locator_set_name': ls_name
2580 })
2581
2582 def lisp_locator_set_dump(self):
2583 return self.api(self.papi.lisp_locator_set_dump, {})
2584
2585 def lisp_locator(self,
2586 ls_name,
2587 sw_if_index,
2588 priority=1,
2589 weight=1,
2590 is_add=1):
2591 return self.api(
2592 self.papi.lisp_add_del_locator,
2593 {
2594 'is_add': is_add,
2595 'locator_set_name': ls_name,
2596 'sw_if_index': sw_if_index,
2597 'priority': priority,
2598 'weight': weight
2599 })
2600
2601 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2602 return self.api(
2603 self.papi.lisp_locator_dump,
2604 {
2605 'is_index_set': is_index_set,
2606 'ls_name': ls_name,
2607 'ls_index': ls_index,
2608 })
2609
2610 def lisp_local_mapping(self,
2611 ls_name,
2612 eid_type,
2613 eid,
2614 prefix_len,
2615 vni=0,
2616 key_id=0,
2617 key="",
2618 is_add=1):
2619 return self.api(
2620 self.papi.lisp_add_del_local_eid,
2621 {
2622 'locator_set_name': ls_name,
2623 'is_add': is_add,
2624 'eid_type': eid_type,
2625 'eid': eid,
2626 'prefix_len': prefix_len,
2627 'vni': vni,
2628 'key_id': key_id,
2629 'key': key
2630 })
2631
2632 def lisp_eid_table_dump(self,
2633 eid_set=0,
2634 prefix_length=0,
2635 vni=0,
2636 eid_type=0,
2637 eid=None,
2638 filter_opt=0):
2639 return self.api(
2640 self.papi.lisp_eid_table_dump,
2641 {
2642 'eid_set': eid_set,
2643 'prefix_length': prefix_length,
2644 'vni': vni,
2645 'eid_type': eid_type,
2646 'eid': eid,
2647 'filter': filter_opt,
2648 })
2649
2650 def lisp_remote_mapping(self,
2651 eid_type,
2652 eid,
2653 eid_prefix_len=0,
2654 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002655 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002656 rlocs_num=0,
2657 is_src_dst=0,
2658 is_add=1):
2659 return self.api(
2660 self.papi.lisp_add_del_remote_mapping,
2661 {
2662 'is_add': is_add,
2663 'eid_type': eid_type,
2664 'eid': eid,
2665 'eid_len': eid_prefix_len,
2666 'rloc_num': rlocs_num,
2667 'rlocs': rlocs,
2668 'vni': vni,
2669 'is_src_dst': is_src_dst,
2670 })
2671
2672 def lisp_adjacency(self,
2673 leid,
2674 reid,
2675 leid_len,
2676 reid_len,
2677 eid_type,
2678 is_add=1,
2679 vni=0):
2680 return self.api(
2681 self.papi.lisp_add_del_adjacency,
2682 {
2683 'is_add': is_add,
2684 'vni': vni,
2685 'eid_type': eid_type,
2686 'leid': leid,
2687 'reid': reid,
2688 'leid_len': leid_len,
2689 'reid_len': reid_len,
2690 })
2691
2692 def lisp_adjacencies_get(self, vni=0):
2693 return self.api(
2694 self.papi.lisp_adjacencies_get,
2695 {
2696 'vni': vni
2697 })
Neale Ranns80823802017-02-20 18:23:41 -08002698
2699 def map_add_domain(self,
2700 ip6_prefix,
2701 ip6_prefix_len,
2702 ip6_src,
2703 ip6_src_prefix_len,
2704 ip4_prefix,
2705 ip4_prefix_len,
2706 ea_bits_len=0,
2707 psid_offset=0,
2708 psid_length=0,
2709 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002710 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002711 mtu=1280):
2712 return self.api(
2713 self.papi.map_add_domain,
2714 {
2715 'ip6_prefix': ip6_prefix,
2716 'ip6_prefix_len': ip6_prefix_len,
2717 'ip4_prefix': ip4_prefix,
2718 'ip4_prefix_len': ip4_prefix_len,
2719 'ip6_src': ip6_src,
2720 'ip6_src_prefix_len': ip6_src_prefix_len,
2721 'ea_bits_len': ea_bits_len,
2722 'psid_offset': psid_offset,
2723 'psid_length': psid_length,
2724 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002725 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002726 'mtu': mtu
2727 })
Hongjun Nief486b12017-04-12 19:21:16 +08002728
2729 def gtpu_add_del_tunnel(
2730 self,
2731 src_addr,
2732 dst_addr,
2733 is_add=1,
2734 is_ipv6=0,
2735 mcast_sw_if_index=0xFFFFFFFF,
2736 encap_vrf_id=0,
2737 decap_next_index=0xFFFFFFFF,
2738 teid=0):
2739 """
2740
2741 :param is_add: (Default value = 1)
2742 :param is_ipv6: (Default value = 0)
2743 :param src_addr:
2744 :param dst_addr:
2745 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2746 :param encap_vrf_id: (Default value = 0)
2747 :param decap_next_index: (Default value = 0xFFFFFFFF)
2748 :param teid: (Default value = 0)
2749
2750 """
2751 return self.api(self.papi.gtpu_add_del_tunnel,
2752 {'is_add': is_add,
2753 'is_ipv6': is_ipv6,
2754 'src_address': src_addr,
2755 'dst_address': dst_addr,
2756 'mcast_sw_if_index': mcast_sw_if_index,
2757 'encap_vrf_id': encap_vrf_id,
2758 'decap_next_index': decap_next_index,
2759 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002760
2761 def vxlan_gpe_add_del_tunnel(
2762 self,
2763 src_addr,
2764 dst_addr,
2765 mcast_sw_if_index=0xFFFFFFFF,
2766 is_add=1,
2767 is_ipv6=0,
2768 encap_vrf_id=0,
2769 decap_vrf_id=0,
2770 protocol=3,
2771 vni=0):
2772 """
2773
2774 :param local:
2775 :param remote:
2776 :param is_add: (Default value = 1)
2777 :param is_ipv6: (Default value = 0)
2778 :param encap_vrf_id: (Default value = 0)
2779 :param decap_vrf_id: (Default value = 0)
2780 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2781 :param protocol: (Default value = 3)
2782 :param vni: (Default value = 0)
2783
2784 """
2785 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2786 {'is_add': is_add,
2787 'is_ipv6': is_ipv6,
2788 'local': src_addr,
2789 'remote': dst_addr,
2790 'mcast_sw_if_index': mcast_sw_if_index,
2791 'encap_vrf_id': encap_vrf_id,
2792 'decap_vrf_id': decap_vrf_id,
2793 'protocol': protocol,
2794 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002795
Neale Ranns79a05f52018-09-11 07:39:43 -07002796 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002797 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002798 src,
2799 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002800 mcast_sw_if_index=0xFFFFFFFF,
2801 is_add=1,
2802 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002803 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002804 vni=0,
2805 instance=0xFFFFFFFF):
2806 """
2807
2808 :param dst_addr:
2809 :param src_addr:
2810 :param is_add: (Default value = 1)
2811 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002812 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002813 :param decap_next_index: (Default value = 0xFFFFFFFF)
2814 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2815 :param vni: (Default value = 0)
2816 :param instance: (Default value = 0xFFFFFFFF)
2817
2818 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002819 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002820 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002821 'tunnel': {
2822 'src': src,
2823 'dst': dst,
2824 'mcast_sw_if_index': mcast_sw_if_index,
2825 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002826 'vni': vni,
2827 'instance': instance}})
2828
2829 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2830 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2831 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002832
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002833 def pppoe_add_del_session(
2834 self,
2835 client_ip,
2836 client_mac,
2837 session_id=0,
2838 is_add=1,
2839 is_ipv6=0,
2840 decap_vrf_id=0):
2841 """
2842
2843 :param is_add: (Default value = 1)
2844 :param is_ipv6: (Default value = 0)
2845 :param client_ip:
2846 :param session_id: (Default value = 0)
2847 :param client_mac:
2848 :param decap_vrf_id: (Default value = 0)
2849
2850 """
2851 return self.api(self.papi.pppoe_add_del_session,
2852 {'is_add': is_add,
2853 'is_ipv6': is_ipv6,
2854 'session_id': session_id,
2855 'client_ip': client_ip,
2856 'decap_vrf_id': decap_vrf_id,
2857 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002858
Neale Ranns7c922dc2018-08-30 06:12:27 -07002859 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2860 return self.api(self.papi.sr_mpls_policy_add,
2861 {'bsid': bsid,
2862 'weight': weight,
2863 'type': type,
2864 'n_segments': len(segments),
2865 'segments': segments})
2866
2867 def sr_mpls_policy_del(self, bsid):
2868 return self.api(self.papi.sr_mpls_policy_del,
2869 {'bsid': bsid})
2870
Kris Michielsen91074432017-06-22 13:00:20 +02002871 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002872 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002873 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002874 nh_addr4,
2875 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002876 is_del=0,
2877 end_psp=0,
2878 sw_if_index=0xFFFFFFFF,
2879 vlan_index=0,
2880 fib_table=0,
2881 ):
2882 """ Add/del IPv6 SR local-SID.
2883
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002884 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002885 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2886 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002887 :param nh_addr4:
2888 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002889 :param is_del: (Default value = 0)
2890 :param end_psp: (Default value = 0)
2891 :param sw_if_index: (Default value = 0xFFFFFFFF)
2892 :param vlan_index: (Default value = 0)
2893 :param fib_table: (Default value = 0)
2894 """
2895 return self.api(
2896 self.papi.sr_localsid_add_del,
2897 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002898 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002899 'end_psp': end_psp,
2900 'behavior': behavior,
2901 'sw_if_index': sw_if_index,
2902 'vlan_index': vlan_index,
2903 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002904 'nh_addr4': nh_addr4,
2905 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002906 }
2907 )
2908
2909 def sr_policy_add(
2910 self,
2911 bsid_addr,
2912 weight=1,
2913 is_encap=1,
2914 type=0,
2915 fib_table=0,
2916 n_segments=0,
2917 segments=[]):
2918 """
2919 :param bsid_addr: bindingSID of the SR Policy
2920 :param weight: weight of the sid list. optional. (default: 1)
2921 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2922 (default: Encap)
2923 :param type: type/behavior of the SR policy. (default or spray) \
2924 (default: default)
2925 :param fib_table: VRF where to install the FIB entry for the BSID \
2926 (default: 0)
2927 :param n_segments: number of segments \
2928 (default: 0)
2929 :param segments: a vector of IPv6 address composing the segment list \
2930 (default: [])
2931 """
2932 return self.api(
2933 self.papi.sr_policy_add,
2934 {'bsid_addr': bsid_addr,
2935 'weight': weight,
2936 'is_encap': is_encap,
2937 'type': type,
2938 'fib_table': fib_table,
2939 'n_segments': n_segments,
2940 'segments': segments
2941 }
2942 )
2943
2944 def sr_policy_del(
2945 self,
2946 bsid_addr,
2947 sr_policy_index=0):
2948 """
2949 :param bsid: bindingSID of the SR Policy
2950 :param sr_policy_index: index of the sr policy (default: 0)
2951 """
2952 return self.api(
2953 self.papi.sr_policy_del,
2954 {'bsid_addr': bsid_addr,
2955 'sr_policy_index': sr_policy_index
2956 })
2957
2958 def sr_steering_add_del(
2959 self,
2960 is_del,
2961 bsid_addr,
2962 sr_policy_index,
2963 table_id,
2964 prefix_addr,
2965 mask_width,
2966 sw_if_index,
2967 traffic_type):
2968 """
2969 Steer traffic L2 and L3 traffic through a given SR policy
2970
2971 :param is_del: delete or add
2972 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2973 :param sr_policy: is the index of the SR Policy (alt to bsid)
2974 :param table_id: is the VRF where to install the FIB entry for the BSID
2975 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2976 :param mask_width: is the mask for L3 traffic type
2977 :param sw_if_index: is the incoming interface for L2 traffic
2978 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2979 """
2980 return self.api(
2981 self.papi.sr_steering_add_del,
2982 {'is_del': is_del,
2983 'bsid_addr': bsid_addr,
2984 'sr_policy_index': sr_policy_index,
2985 'table_id': table_id,
2986 'prefix_addr': prefix_addr,
2987 'mask_width': mask_width,
2988 'sw_if_index': sw_if_index,
2989 'traffic_type': traffic_type
2990 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002991
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002992 def acl_add_replace(self, acl_index, r, tag='',
2993 expected_retval=0):
2994 """Add/replace an ACL
2995 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2996 :param acl_rule r: ACL rules array.
2997 :param str tag: symbolic tag (description) for this ACL.
2998 :param int count: number of rules.
2999 """
3000 return self.api(self.papi.acl_add_replace,
3001 {'acl_index': acl_index,
3002 'r': r,
3003 'count': len(r),
3004 'tag': tag},
3005 expected_retval=expected_retval)
3006
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003007 def acl_del(self, acl_index, expected_retval=0):
3008 """
3009
3010 :param acl_index:
3011 :return:
3012 """
3013 return self.api(self.papi.acl_del,
3014 {'acl_index': acl_index},
3015 expected_retval=expected_retval)
3016
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003017 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3018 expected_retval=0):
3019 return self.api(self.papi.acl_interface_set_acl_list,
3020 {'sw_if_index': sw_if_index,
3021 'count': len(acls),
3022 'n_input': n_input,
3023 'acls': acls},
3024 expected_retval=expected_retval)
3025
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003026 def acl_interface_set_etype_whitelist(self, sw_if_index,
3027 n_input, whitelist,
3028 expected_retval=0):
3029 return self.api(self.papi.acl_interface_set_etype_whitelist,
3030 {'sw_if_index': sw_if_index,
3031 'count': len(whitelist),
3032 'n_input': n_input,
3033 'whitelist': whitelist},
3034 expected_retval=expected_retval)
3035
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003036 def acl_interface_add_del(self,
3037 sw_if_index,
3038 acl_index,
3039 is_add=1):
3040 """ Add/Delete ACL to/from interface
3041
3042 :param sw_if_index:
3043 :param acl_index:
3044 :param is_add: (Default value = 1)
3045 """
3046
3047 return self.api(self.papi.acl_interface_add_del,
3048 {'is_add': is_add,
3049 'is_input': 1,
3050 'sw_if_index': sw_if_index,
3051 'acl_index': acl_index})
3052
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003053 def acl_dump(self, acl_index, expected_retval=0):
3054 return self.api(self.papi.acl_dump,
3055 {'acl_index': acl_index},
3056 expected_retval=expected_retval)
3057
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003058 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3059 expected_retval=0):
3060 return self.api(self.papi.acl_interface_list_dump,
3061 {'sw_if_index': sw_if_index},
3062 expected_retval=expected_retval)
3063
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003064 def macip_acl_add(self, rules, tag=""):
3065 """ Add MACIP acl
3066
3067 :param rules: list of rules for given acl
3068 :param tag: acl tag
3069 """
3070
3071 return self.api(self.papi.macip_acl_add,
3072 {'r': rules,
3073 'count': len(rules),
3074 'tag': tag})
3075
Pavel Kotucek932f7412017-09-07 14:44:52 +02003076 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3077 """ Add MACIP acl
3078
3079 :param rules: list of rules for given acl
3080 :param tag: acl tag
3081 """
3082
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003083 return self.api(self.papi.macip_acl_add_replace,
3084 {'acl_index': acl_index,
3085 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003086 'count': len(rules),
3087 'tag': tag})
3088
3089 def macip_acl_del(self, acl_index):
3090 """
3091
3092 :param acl_index:
3093 :return:
3094 """
3095 return self.api(self.papi.macip_acl_del,
3096 {'acl_index': acl_index})
3097
3098 def macip_acl_interface_add_del(self,
3099 sw_if_index,
3100 acl_index,
3101 is_add=1):
3102 """ Add MACIP acl to interface
3103
3104 :param sw_if_index:
3105 :param acl_index:
3106 :param is_add: (Default value = 1)
3107 """
3108
3109 return self.api(self.papi.macip_acl_interface_add_del,
3110 {'is_add': is_add,
3111 'sw_if_index': sw_if_index,
3112 'acl_index': acl_index})
3113
3114 def macip_acl_interface_get(self):
3115 """ Return interface acls dump
3116 """
3117 return self.api(
3118 self.papi.macip_acl_interface_get, {})
3119
3120 def macip_acl_dump(self, acl_index=4294967295):
3121 """ Return MACIP acl dump
3122 """
3123
3124 return self.api(
3125 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003126
3127 def policer_add_del(self,
3128 name,
3129 cir,
3130 eir,
3131 cb,
3132 eb,
3133 is_add=1,
3134 rate_type=0,
3135 round_type=0,
3136 ptype=0,
3137 color_aware=0,
3138 conform_action_type=1,
3139 conform_dscp=0,
3140 exceed_action_type=0,
3141 exceed_dscp=0,
3142 violate_action_type=0,
3143 violate_dscp=0):
3144 return self.api(self.papi.policer_add_del,
3145 {'name': name,
3146 'cir': cir,
3147 'eir': eir,
3148 'cb': cb,
3149 'eb': eb,
3150 'is_add': is_add,
3151 'rate_type': rate_type,
3152 'round_type': round_type,
3153 'type': ptype,
3154 'color_aware': color_aware,
3155 'conform_action_type': conform_action_type,
3156 'conform_dscp': conform_dscp,
3157 'exceed_action_type': exceed_action_type,
3158 'exceed_dscp': exceed_dscp,
3159 'violate_action_type': violate_action_type,
3160 'violate_dscp': violate_dscp})
3161
3162 def ip_punt_police(self,
3163 policer_index,
3164 is_ip6=0,
3165 is_add=1):
3166 return self.api(self.papi.ip_punt_police,
3167 {'policer_index': policer_index,
3168 'is_add': is_add,
3169 'is_ip6': is_ip6})
3170
3171 def ip_punt_redirect(self,
3172 rx_sw_if_index,
3173 tx_sw_if_index,
3174 nh,
3175 is_ip6=0,
3176 is_add=1):
3177 return self.api(self.papi.ip_punt_redirect,
3178 {'rx_sw_if_index': rx_sw_if_index,
3179 'tx_sw_if_index': tx_sw_if_index,
3180 'nh': nh,
3181 'is_add': is_add,
3182 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003183
3184 def bier_table_add_del(self,
3185 bti,
3186 mpls_label,
3187 is_add=1):
3188 """ BIER Table add/del """
3189 return self.api(
3190 self.papi.bier_table_add_del,
3191 {'bt_tbl_id': {"bt_set": bti.set_id,
3192 "bt_sub_domain": bti.sub_domain_id,
3193 "bt_hdr_len_id": bti.hdr_len_id},
3194 'bt_label': mpls_label,
3195 'bt_is_add': is_add})
3196
3197 def bier_table_dump(self):
3198 return self.api(self.papi.bier_table_dump, {})
3199
3200 def bier_route_add_del(self,
3201 bti,
3202 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003203 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003204 is_add=1,
3205 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003206 """ BIER Route add/del """
3207 return self.api(
3208 self.papi.bier_route_add_del,
3209 {'br_tbl_id': {"bt_set": bti.set_id,
3210 "bt_sub_domain": bti.sub_domain_id,
3211 "bt_hdr_len_id": bti.hdr_len_id},
3212 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003213 'br_n_paths': len(paths),
3214 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003215 'br_is_add': is_add,
3216 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003217
3218 def bier_route_dump(self, bti):
3219 return self.api(
3220 self.papi.bier_route_dump,
3221 {'br_tbl_id': {"bt_set": bti.set_id,
3222 "bt_sub_domain": bti.sub_domain_id,
3223 "bt_hdr_len_id": bti.hdr_len_id}})
3224
3225 def bier_imp_add(self,
3226 bti,
3227 src,
3228 ibytes,
3229 is_add=1):
3230 """ BIER Imposition Add """
3231 return self.api(
3232 self.papi.bier_imp_add,
3233 {'bi_tbl_id': {"bt_set": bti.set_id,
3234 "bt_sub_domain": bti.sub_domain_id,
3235 "bt_hdr_len_id": bti.hdr_len_id},
3236 'bi_src': src,
3237 'bi_n_bytes': len(ibytes),
3238 'bi_bytes': ibytes})
3239
3240 def bier_imp_del(self, bi_index):
3241 """ BIER Imposition del """
3242 return self.api(
3243 self.papi.bier_imp_del,
3244 {'bi_index': bi_index})
3245
3246 def bier_imp_dump(self):
3247 return self.api(self.papi.bier_imp_dump, {})
3248
3249 def bier_disp_table_add_del(self,
3250 bdti,
3251 is_add=1):
3252 """ BIER Disposition Table add/del """
3253 return self.api(
3254 self.papi.bier_disp_table_add_del,
3255 {'bdt_tbl_id': bdti,
3256 'bdt_is_add': is_add})
3257
3258 def bier_disp_table_dump(self):
3259 return self.api(self.papi.bier_disp_table_dump, {})
3260
3261 def bier_disp_entry_add_del(self,
3262 bdti,
3263 bp,
3264 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003265 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003266 next_hop,
3267 next_hop_tbl_id=0,
3268 next_hop_rpf_id=~0,
3269 next_hop_is_ip4=1,
3270 is_add=1):
3271 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003272 lstack = []
3273 while (len(lstack) < 16):
3274 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003275 return self.api(
3276 self.papi.bier_disp_entry_add_del,
3277 {'bde_tbl_id': bdti,
3278 'bde_bp': bp,
3279 'bde_payload_proto': payload_proto,
3280 'bde_n_paths': 1,
3281 'bde_paths': [{'next_hop': next_hop,
3282 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003283 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003284 'rpf_id': next_hop_rpf_id,
3285 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003286 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003287 'bde_is_add': is_add})
3288
3289 def bier_disp_entry_dump(self, bdti):
3290 return self.api(
3291 self.papi.bier_disp_entry_dump,
3292 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003293
3294 def add_node_next(self, node_name, next_name):
3295 """ Set the next node for a given node request
3296
3297 :param node_name:
3298 :param next_name:
3299 """
3300 return self.api(self.papi.add_node_next,
3301 {'node_name': node_name,
3302 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003303
3304 def session_enable_disable(self, is_enabled):
3305 return self.api(
3306 self.papi.session_enable_disable,
3307 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003308
3309 def ipsec_spd_add_del(self, spd_id, is_add=1):
3310 """ SPD add/del - Wrapper to add or del ipsec SPD
3311 Sample CLI : 'ipsec spd add 1'
3312
3313 :param spd_id - SPD ID to be created in the vpp . mandatory
3314 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3315 optional
3316 :returns: reply from the API
3317 """
3318 return self.api(
3319 self.papi.ipsec_spd_add_del, {
3320 'spd_id': spd_id, 'is_add': is_add})
3321
3322 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3323 """ IPSEC interface SPD add/del - \
3324 Wrapper to associate/disassociate SPD to interface in VPP
3325 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3326
3327 :param spd_id - SPD ID to associate with the interface . mandatory
3328 :param sw_if_index - Interface Index which needs to ipsec \
3329 association mandatory
3330 :param is_add - add(1) or del(0) association with interface \
3331 (Default 1 - add) . optional
3332 :returns: reply from the API
3333 """
3334 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003335 self.papi.ipsec_interface_add_del_spd,
3336 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003337
3338 def ipsec_sad_add_del_entry(self,
3339 sad_id,
3340 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003341 integrity_algorithm,
3342 integrity_key,
3343 crypto_algorithm,
3344 crypto_key,
3345 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003346 tunnel_src_address='',
3347 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003348 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003349 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003350 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003351 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003352 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003353 :param sad_id: security association ID
3354 :param spi: security param index of the SA in decimal
3355 :param integrity_algorithm:
3356 :param integrity_key:
3357 :param crypto_algorithm:
3358 :param crypto_key:
3359 :param protocol: AH(0) or ESP(1) protocol
3360 :param tunnel_src_address: tunnel mode outer src address
3361 :param tunnel_dst_address: tunnel mode outer dst address
3362 :param is_add:
3363 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003364 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3365 crypto and ipsec algorithms
3366 """
3367 return self.api(
3368 self.papi.ipsec_sad_add_del_entry,
3369 {'sad_id': sad_id,
3370 'spi': spi,
3371 'tunnel_src_address': tunnel_src_address,
3372 'tunnel_dst_address': tunnel_dst_address,
3373 'protocol': protocol,
3374 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003375 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003376 'integrity_key': integrity_key,
3377 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003378 'crypto_key_length': len(crypto_key) if crypto_key is not None
3379 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003380 'crypto_key': crypto_key,
3381 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003382 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003383 'is_tunnel_ipv6': is_tunnel_ipv6,
Klement Sekera4b089f22018-04-17 18:04:57 +02003384 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003385
3386 def ipsec_spd_add_del_entry(self,
3387 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003388 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003389 local_address_start,
3390 local_address_stop,
3391 remote_address_start,
3392 remote_address_stop,
3393 local_port_start=0,
3394 local_port_stop=65535,
3395 remote_port_start=0,
3396 remote_port_stop=65535,
3397 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003398 policy=0,
3399 priority=100,
3400 is_outbound=1,
3401 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003402 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003403 is_ip_any=0):
3404 """ IPSEC policy SPD add/del -
3405 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003406 :param spd_id: SPD ID for the policy
3407 :param local_address_start: local-ip-range start address
3408 :param local_address_stop : local-ip-range stop address
3409 :param remote_address_start: remote-ip-range start address
3410 :param remote_address_stop : remote-ip-range stop address
3411 :param local_port_start: (Default value = 0)
3412 :param local_port_stop: (Default value = 65535)
3413 :param remote_port_start: (Default value = 0)
3414 :param remote_port_stop: (Default value = 65535)
3415 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3416 :param sa_id: Security Association ID for mapping it to SPD
3417 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3418 (Default value = 0)
3419 :param priority: value for the spd action (Default value = 100)
3420 :param is_outbound: flag for inbound(0) or outbound(1)
3421 (Default value = 1)
3422 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003423 """
3424 return self.api(
3425 self.papi.ipsec_spd_add_del_entry,
3426 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003427 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003428 'local_address_start': local_address_start,
3429 'local_address_stop': local_address_stop,
3430 'remote_address_start': remote_address_start,
3431 'remote_address_stop': remote_address_stop,
3432 'local_port_start': local_port_start,
3433 'local_port_stop': local_port_stop,
3434 'remote_port_start': remote_port_start,
3435 'remote_port_stop': remote_port_stop,
3436 'is_add': is_add,
3437 'protocol': protocol,
3438 'policy': policy,
3439 'priority': priority,
3440 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003441 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003442 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003443
Klement Sekera31da2e32018-06-24 22:49:55 +02003444 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3445 remote_spi, crypto_alg, local_crypto_key,
3446 remote_crypto_key, integ_alg, local_integ_key,
3447 remote_integ_key, is_add=1, esn=0,
3448 anti_replay=1, renumber=0, show_instance=0):
3449 return self.api(
3450 self.papi.ipsec_tunnel_if_add_del,
3451 {'local_ip': local_ip, 'remote_ip': remote_ip,
3452 'local_spi': local_spi, 'remote_spi': remote_spi,
3453 'crypto_alg': crypto_alg,
3454 'local_crypto_key_len': len(local_crypto_key),
3455 'local_crypto_key': local_crypto_key,
3456 'remote_crypto_key_len': len(remote_crypto_key),
3457 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3458 'local_integ_key_len': len(local_integ_key),
3459 'local_integ_key': local_integ_key,
3460 'remote_integ_key_len': len(remote_integ_key),
3461 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3462 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3463 'show_instance': show_instance
3464 })
3465
Klement Sekerab4d30532018-11-08 13:00:02 +01003466 def ipsec_select_backend(self, protocol, index):
3467 return self.api(self.papi.ipsec_select_backend,
3468 {'protocol': protocol, 'index': index})
3469
3470 def ipsec_backend_dump(self):
3471 return self.api(self.papi.ipsec_backend_dump, {})
3472
Florin Corasb795bd02017-12-14 11:30:48 -08003473 def app_namespace_add(self,
3474 namespace_id,
3475 ip4_fib_id=0,
3476 ip6_fib_id=0,
3477 sw_if_index=0xFFFFFFFF,
3478 secret=0):
3479 return self.api(
3480 self.papi.app_namespace_add_del,
3481 {'secret': secret,
3482 'sw_if_index': sw_if_index,
3483 'ip4_fib_id': ip4_fib_id,
3484 'ip6_fib_id': ip6_fib_id,
3485 'namespace_id': namespace_id,
3486 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003487
3488 def punt_socket_register(self, l4_port, pathname, header_version=1,
3489 is_ip4=1, l4_protocol=0x11):
3490 """ Punt to socket """
3491 return self.api(self.papi.punt_socket_register,
3492 {'is_ip4': is_ip4,
3493 'l4_protocol': l4_protocol,
3494 'l4_port': l4_port,
3495 'pathname': pathname,
3496 'header_version': header_version})
3497
3498 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3499 expire_walk_interval_ms, is_ip6=0):
3500 """ Set IP reassembly parameters """
3501 return self.api(self.papi.ip_reassembly_set,
3502 {'is_ip6': is_ip6,
3503 'timeout_ms': timeout_ms,
3504 'expire_walk_interval_ms': expire_walk_interval_ms,
3505 'max_reassemblies': max_reassemblies})
3506
3507 def ip_reassembly_get(self, is_ip6=0):
3508 """ Get IP reassembly parameters """
3509 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003510
Klement Sekera4c533132018-02-22 11:41:12 +01003511 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3512 enable_ip6=False):
3513 """ Enable/disable IP reassembly """
3514 return self.api(self.papi.ip_reassembly_enable_disable,
3515 {'sw_if_index': sw_if_index,
3516 'enable_ip4': 1 if enable_ip4 else 0,
3517 'enable_ip6': 1 if enable_ip6 else 0,
3518 })
3519
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003520 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3521 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003522 """ GBP endpoint Add """
3523 return self.api(self.papi.gbp_endpoint_add,
3524 {'endpoint': {
3525 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003526 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003527 'ips': ips,
3528 'n_ips': len(ips),
3529 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003530 'epg_id': epg,
3531 'flags': flags,
3532 'tun': {
3533 'src': tun_src,
3534 'dst': tun_dst,
3535 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003536
3537 def gbp_endpoint_del(self, handle):
3538 """ GBP endpoint Del """
3539 return self.api(self.papi.gbp_endpoint_del,
3540 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003541
3542 def gbp_endpoint_dump(self):
3543 """ GBP endpoint Dump """
3544 return self.api(self.papi.gbp_endpoint_dump, {})
3545
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003546 def gbp_endpoint_group_add(self, epg, bd,
3547 rd, uplink_sw_if_index):
3548 """ GBP endpoint group Add """
3549 return self.api(self.papi.gbp_endpoint_group_add,
3550 {'epg':
3551 {
Neale Ranns25b04942018-04-04 09:34:50 -07003552 'uplink_sw_if_index': uplink_sw_if_index,
3553 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003554 'rd_id': rd,
3555 'epg_id': epg
3556 }})
3557
3558 def gbp_endpoint_group_del(self, epg):
3559 """ GBP endpoint group Del """
3560 return self.api(self.papi.gbp_endpoint_group_del,
3561 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003562
3563 def gbp_endpoint_group_dump(self):
3564 """ GBP endpoint group Dump """
3565 return self.api(self.papi.gbp_endpoint_group_dump, {})
3566
Neale Rannsc29c0af2018-11-07 04:21:12 -08003567 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003568 bvi_sw_if_index,
3569 uu_fwd_sw_if_index):
3570 """ GBP bridge-domain Add """
3571 return self.api(self.papi.gbp_bridge_domain_add,
3572 {'bd':
3573 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003574 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003575 'bvi_sw_if_index': bvi_sw_if_index,
3576 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3577 'bd_id': bd_id
3578 }})
3579
3580 def gbp_bridge_domain_del(self, bd_id):
3581 """ GBP bridge-domain Del """
3582 return self.api(self.papi.gbp_bridge_domain_del,
3583 {'bd_id': bd_id})
3584
3585 def gbp_bridge_domain_dump(self):
3586 """ GBP Bridge Domain Dump """
3587 return self.api(self.papi.gbp_bridge_domain_dump, {})
3588
3589 def gbp_route_domain_add(self, rd_id,
3590 ip4_table_id,
3591 ip6_table_id,
3592 ip4_uu_sw_if_index,
3593 ip6_uu_sw_if_index):
3594 """ GBP route-domain Add """
3595 return self.api(self.papi.gbp_route_domain_add,
3596 {'rd':
3597 {
3598 'ip4_table_id': ip4_table_id,
3599 'ip6_table_id': ip6_table_id,
3600 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3601 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3602 'rd_id': rd_id
3603 }})
3604
3605 def gbp_route_domain_del(self, rd_id):
3606 """ GBP route-domain Del """
3607 return self.api(self.papi.gbp_route_domain_del,
3608 {'rd_id': rd_id})
3609
3610 def gbp_route_domain_dump(self):
3611 """ GBP Route Domain Dump """
3612 return self.api(self.papi.gbp_route_domain_dump, {})
3613
Neale Ranns25b04942018-04-04 09:34:50 -07003614 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3615 """ GBP recirc Add/Del """
3616 return self.api(self.papi.gbp_recirc_add_del,
3617 {'is_add': is_add,
3618 'recirc': {
3619 'is_ext': is_ext,
3620 'sw_if_index': sw_if_index,
3621 'epg_id': epg}})
3622
3623 def gbp_recirc_dump(self):
3624 """ GBP recirc Dump """
3625 return self.api(self.papi.gbp_recirc_dump, {})
3626
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003627 def gbp_subnet_add_del(self, is_add, rd_id,
3628 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003629 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003630 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003631 """ GBP Subnet Add/Del """
3632 return self.api(self.papi.gbp_subnet_add_del,
3633 {'is_add': is_add,
3634 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003635 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003636 'sw_if_index': sw_if_index,
3637 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003638 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003639 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003640
3641 def gbp_subnet_dump(self):
3642 """ GBP Subnet Dump """
3643 return self.api(self.papi.gbp_subnet_dump, {})
3644
Neale Ranns13a08cc2018-11-07 09:25:54 -08003645 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003646 """ GBP contract Add/Del """
3647 return self.api(self.papi.gbp_contract_add_del,
3648 {'is_add': is_add,
3649 'contract': {
3650 'acl_index': acl_index,
3651 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003652 'dst_epg': dst_epg,
3653 'n_rules': len(rules),
3654 'rules': rules}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003655
3656 def gbp_contract_dump(self):
3657 """ GBP contract Dump """
3658 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003659
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003660 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3661 """ GBP set inactive threshold """
3662 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3663 {'threshold': threshold})
3664
3665 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3666 """ GBP VXLAN tunnel add """
3667 return self.api(self.papi.gbp_vxlan_tunnel_add,
3668 {
3669 'tunnel': {
3670 'vni': vni,
3671 'mode': mode,
3672 'bd_rd_id': bd_rd_id
3673 }
3674 })
3675
3676 def gbp_vxlan_tunnel_del(self, vni):
3677 """ GBP VXLAN tunnel del """
3678 return self.api(self.papi.gbp_vxlan_tunnel_del,
3679 {
3680 'vni': vni,
3681 })
3682
3683 def gbp_vxlan_tunnel_dump(self):
3684 """ GBP VXLAN tunnel add/del """
3685 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3686
Neale Ranns61502112018-08-22 00:21:14 -07003687 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3688 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003689 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003690 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003691 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003692 {'ip4_table_id': ip4_table_id,
3693 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003694 'ip6_prefix': ip6_prefix,
3695 'ip6_prefix_len': ip6_prefix_len,
3696 'ip4_prefix': ip4_prefix,
3697 'ip4_prefix_len': ip4_prefix_len,
3698 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003699 'security_check': security_check})
3700
Ole Troan298c6952018-03-08 12:30:43 +01003701 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003702 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003703 return self.api(self.papi.ipip_6rd_del_tunnel,
3704 {'sw_if_index': sw_if_index})
3705
3706 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003707 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003708 """ IPIP tunnel Add/Del """
3709 return self.api(self.papi.ipip_add_tunnel,
3710 {'is_ipv6': is_ipv6,
3711 'instance': instance,
3712 'src_address': src_address,
3713 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003714 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003715 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003716
3717 def ipip_del_tunnel(self, sw_if_index):
3718 """ IPIP tunnel Delete """
3719 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003720 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003721
3722 def qos_egress_map_update(self, id, outputs):
3723 """ QOS egress map update """
3724 return self.api(self.papi.qos_egress_map_update,
3725 {'map_id': id,
3726 'rows': outputs})
3727
3728 def qos_egress_map_delete(self, id):
3729 """ QOS egress map delete """
3730 return self.api(self.papi.qos_egress_map_delete,
3731 {'map_id': id})
3732
3733 def qos_mark_enable_disable(self, sw_if_index,
3734 output_source,
3735 map_id,
3736 enable):
3737 """ QOS Mark Enable/Disable """
3738 return self.api(self.papi.qos_mark_enable_disable,
3739 {'map_id': map_id,
3740 'sw_if_index': sw_if_index,
3741 'output_source': output_source,
3742 'enable': enable})
3743
3744 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3745 """ IP QoS recording Enble/Disable """
3746 return self.api(self.papi.qos_record_enable_disable,
3747 {'sw_if_index': sw_if_index,
3748 'input_source': input_source,
3749 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003750
Neale Ranns947ea622018-06-07 23:48:20 -07003751 def igmp_enable_disable(self, sw_if_index, enable, host):
3752 """ Enable/disable IGMP on a given interface """
3753 return self.api(self.papi.igmp_enable_disable,
3754 {'enable': enable,
3755 'mode': host,
3756 'sw_if_index': sw_if_index})
3757
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003758 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3759 """ Add/del IGMP proxy device """
3760 return self.api(self.papi.igmp_proxy_device_add_del,
3761 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3762 'add': add})
3763
3764 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3765 """ Add/del interface to/from IGMP proxy device """
3766 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3767 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3768 'add': add})
3769
Neale Ranns947ea622018-06-07 23:48:20 -07003770 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003771 """ Listen for new (S,G) on specified interface
3772
3773 :param enable: add/del
3774 :param sw_if_index: interface sw index
3775 :param saddr: source ip4 addr
3776 :param gaddr: group ip4 addr
3777 """
3778 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003779 {
3780 'group':
3781 {
3782 'filter': filter,
3783 'sw_if_index': sw_if_index,
3784 'n_srcs': len(saddrs),
3785 'saddrs': saddrs,
3786 'gaddr':
3787 {
3788 'address': gaddr
3789 }
3790 }
3791 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003792
3793 def igmp_dump(self, sw_if_index=None):
3794 """ Dump all (S,G) interface configurations """
3795 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003796 sw_if_index = 0xffffffff
3797 return self.api(self.papi.igmp_dump,
3798 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003799
3800 def igmp_clear_interface(self, sw_if_index):
3801 """ Remove all (S,G)s from specified interface
3802 doesn't send IGMP report!
3803 """
3804 return self.api(
3805 self.papi.igmp_clear_interface, {
3806 'sw_if_index': sw_if_index})
3807
3808 def want_igmp_events(self, enable=1):
3809 return self.api(self.papi.want_igmp_events, {'enable': enable,
3810 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003811
3812 def bond_create(
3813 self,
3814 mode,
3815 lb,
3816 use_custom_mac,
3817 mac_address=''):
3818 """
3819 :param mode: mode
3820 :param lb: load balance
3821 :param use_custom_mac: use custom mac
3822 :param mac_address: mac address
3823 """
3824 return self.api(
3825 self.papi.bond_create,
3826 {'mode': mode,
3827 'lb': lb,
3828 'use_custom_mac': use_custom_mac,
3829 'mac_address': mac_address
3830 })
3831
3832 def bond_delete(
3833 self,
3834 sw_if_index):
3835 """
3836 :param sw_if_index: interface the operation is applied to
3837 """
3838 return self.api(self.papi.bond_delete,
3839 {'sw_if_index': sw_if_index})
3840
3841 def bond_enslave(
3842 self,
3843 sw_if_index,
3844 bond_sw_if_index,
3845 is_passive,
3846 is_long_timeout):
3847 """
3848 :param sw_if_index: slave sw_if_index
3849 :param bond_sw_if_index: bond sw_if_index
3850 :param is_passive: is passive lacp speaker
3851 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3852 """
3853 return self.api(
3854 self.papi.bond_enslave,
3855 {'sw_if_index': sw_if_index,
3856 'bond_sw_if_index': bond_sw_if_index,
3857 'is_passive': is_passive,
3858 'is_long_timeout': is_long_timeout
3859 })
3860
3861 def bond_detach_slave(
3862 self,
3863 sw_if_index):
3864 """
3865 :param sw_if_index: slave interface the operation is applied to
3866 """
3867 return self.api(self.papi.bond_detach_slave,
3868 {'sw_if_index': sw_if_index})
3869
3870 def sw_interface_slave_dump(
3871 self,
3872 sw_if_index):
3873 """
3874 :param sw_if_index: bond sw_if_index
3875 """
3876 return self.api(self.papi.sw_interface_slave_dump,
3877 {'sw_if_index': sw_if_index})
3878
3879 def sw_interface_bond_dump(
3880 self):
3881 """
3882
3883 """
3884 return self.api(self.papi.sw_interface_bond_dump,
3885 {})
Stevene8fa6202017-08-30 14:36:45 -07003886
3887 def create_vhost_user_if(
3888 self,
3889 is_server,
3890 sock_filename,
3891 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003892 disable_mrg_rxbuf,
3893 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003894 custom_dev_instance,
3895 use_custom_mac,
3896 mac_address,
3897 tag=''):
3898 """
3899 :param is_server: is server
3900 :param sock_filename: socket name
3901 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003902 :param disable_mrg_rxbuf: disable mergable rx buffers
3903 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003904 :param custom_dev_instance: custom dev instance
3905 :param use_custom_mac: use custom mac
3906 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003907 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003908 """
3909 return self.api(
3910 self.papi.create_vhost_user_if,
3911 {'is_server': is_server,
3912 'sock_filename': sock_filename,
3913 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003914 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3915 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003916 'custom_dev_instance': custom_dev_instance,
3917 'use_custom_mac': use_custom_mac,
3918 'mac_address': mac_address,
3919 'tag': tag
3920 })
3921
3922 def delete_vhost_user_if(
3923 self,
3924 sw_if_index):
3925 """
3926 :param sw_if_index: interface the operation is applied to
3927 """
3928 return self.api(self.papi.delete_vhost_user_if,
3929 {'sw_if_index': sw_if_index, })
3930
3931 def sw_interface_vhost_user_dump(
3932 self):
3933 """
3934
3935 """
3936 return self.api(self.papi.sw_interface_vhost_user_dump,
3937 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003938
3939 def abf_policy_add_del(self, is_add, policy):
3940 return self.api(
3941 self.papi.abf_policy_add_del,
3942 {'is_add': is_add,
3943 'policy': policy})
3944
3945 def abf_itf_attach_add_del(self, is_add, attach):
3946 return self.api(
3947 self.papi.abf_itf_attach_add_del,
3948 {'is_add': is_add,
3949 'attach': attach})
3950
3951 def abf_policy_dump(self):
3952 return self.api(
3953 self.papi.abf_policy_dump, {})
3954
3955 def abf_itf_attach_dump(self):
3956 return self.api(
3957 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003958
3959 def pipe_create(self, is_specified, user_instance):
3960 return self.api(self.papi.pipe_create,
3961 {'is_specified': is_specified,
3962 'user_instance': user_instance})
3963
3964 def pipe_delete(self, parent_sw_if_index):
3965 return self.api(self.papi.pipe_delete,
3966 {'parent_sw_if_index': parent_sw_if_index})
3967
3968 def pipe_dump(self):
3969 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003970
3971 def memif_create(
3972 self,
3973 role,
3974 mode,
3975 rx_queues=None,
3976 tx_queues=None,
3977 _id=None,
3978 socket_id=None,
3979 secret=None,
3980 ring_size=None,
3981 buffer_size=None,
3982 hw_addr=None):
3983 return self.api(self.papi.memif_create,
3984 {'role': role,
3985 'mode': mode,
3986 'rx_queues': rx_queues,
3987 'tx_queues': tx_queues,
3988 'id': _id,
3989 'socket_id': socket_id,
3990 'secret': secret,
3991 'ring_size': ring_size,
3992 'buffer_size': buffer_size,
3993 'hw_addr': hw_addr})
3994
3995 def memif_delete(self, sw_if_index):
3996 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
3997
3998 def memif_dump(self):
3999 return self.api(self.papi.memif_dump, {})
4000
4001 def memif_socket_filename_add_del(
4002 self, is_add, socket_id, socket_filename):
4003 return self.api(
4004 self.papi.memif_socket_filename_add_del,
4005 {'is_add': is_add,
4006 'socket_id': socket_id,
4007 'socket_filename': socket_filename})
4008
4009 def memif_socket_filename_dump(self):
4010 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004011
4012 def svs_table_add_del(self, af, table_id, is_add=1):
4013 return self.api(self.papi.svs_table_add_del,
4014 {
4015 'table_id': table_id,
4016 'is_add': is_add,
4017 'af': af,
4018 })
4019
4020 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4021 return self.api(self.papi.svs_route_add_del,
4022 {
4023 'table_id': table_id,
4024 'source_table_id': src_table_id,
4025 'prefix': prefix,
4026 'is_add': is_add,
4027 })
4028
4029 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4030 return self.api(self.papi.svs_enable_disable,
4031 {
4032 'af': af,
4033 'table_id': table_id,
4034 'sw_if_index': sw_if_index,
4035 'is_enable': is_enable,
4036 })
4037
4038 def svs_dump(self):
4039 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004040
4041 def syslog_set_sender(
4042 self,
4043 collector,
4044 src,
4045 collector_port=514,
4046 vrf_id=0,
4047 max_msg_size=480):
4048 """Set syslog sender configuration
4049
4050 :param collector: colector IP address
4051 :param src: source IP address
4052 :param collector_port: collector UDP port (Default value = 514)
4053 :param vrf_id: VRF id (Default value = 0)
4054 :param max_msg_size: maximum message length (Default value = 480)
4055 """
4056 return self.api(self.papi.syslog_set_sender,
4057 {'collector_address': {
4058 'address': collector},
4059 'src_address': {
4060 'address': src},
4061 'collector_port': collector_port,
4062 'vrf_id': vrf_id,
4063 'max_msg_size': max_msg_size})
4064
4065 def syslog_get_sender(self):
4066 """Return syslog sender configuration"""
4067 return self.api(self.papi.syslog_get_sender, {})
4068
4069 def syslog_set_filter(self, severity):
4070 """Set syslog filter parameters
4071
4072 :param severity: severity filter (specified severity and greater match)
4073 """
4074 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4075
4076 def syslog_get_filter(self):
4077 """Return syslog filter parameters"""
4078 return self.api(self.papi.syslog_get_filter, {})