blob: 320ea12c6dcfe4b1076a738ec43c69feab47e9a4 [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import fnmatch
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08002import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02003import time
Klement Sekerae4504c62016-12-08 10:16:41 +01004from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02005
Paul Vinciguerra6c746172018-11-26 09:57:21 -08006from six import moves
Ole Troan7f991832018-12-06 17:35:12 +01007from vpp_mac import mactobinary
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008from hook import Hook
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -08009from vpp_l2 import L2_PORT_TYPE
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080010
Klement Sekera0e3c0de2016-09-29 14:43:44 +020011# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +010012# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
13# the vpp_papi_provider.py file to be importable without having to build
14# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020015
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -080016try:
Ole Troan7e3a8752016-12-05 10:27:09 +010017 from vpp_papi import VPP
Paul Vinciguerraf0cbcea2018-12-06 09:32:45 -080018except ImportError:
19 if not os.getenv("NO_VPP_PAPI") == 1:
20 raise
21 pass
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030029 L2_DISABLED = 0
30 L2_PUSH_1 = 1
31 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000032 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030033 L2_POP_2 = 4
34 L2_TRANSLATE_1_1 = 5
35 L2_TRANSLATE_1_2 = 6
36 L2_TRANSLATE_2_1 = 7
37 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000038
Klement Sekera0e3c0de2016-09-29 14:43:44 +020039
Neale Ranns039cbfe2018-02-27 03:45:38 -080040class QOS_SOURCE:
41 EXT = 0
42 VLAN = 1
43 MPLS = 2
44 IP = 3
45
46
Matus Fabianb4515b42018-11-19 04:25:32 -080047class SYSLOG_SEVERITY:
48 EMERG = 0
49 ALERT = 1
50 CRIT = 2
51 ERR = 3
52 WARN = 4
53 NOTICE = 5
54 INFO = 6
55 DBG = 7
56
57
Klement Sekera73884482017-02-23 09:26:30 +010058class UnexpectedApiReturnValueError(Exception):
59 """ exception raised when the API return value is unexpected """
60 pass
61
62
Klement Sekeraf62ae122016-10-11 11:47:09 +020063class VppPapiProvider(object):
64 """VPP-api provider using vpp-papi
65
66 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020067 """
68
Klement Sekerae0545ef2017-01-25 08:00:40 +010069 _zero, _negative = range(2)
70
Klement Sekera611864f2018-09-26 11:19:00 +020071 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020072 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020073 self.name = name
74 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010075 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010076 self._expect_api_retval = self._zero
77 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010078 jsonfiles = []
79
Klement Sekerab8c72a42018-11-08 11:21:39 +010080 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010081 for root, dirnames, filenames in os.walk(install_dir):
82 for filename in fnmatch.filter(filenames, '*.api.json'):
83 jsonfiles.append(os.path.join(root, filename))
84
Klement Sekera611864f2018-09-26 11:19:00 +020085 self.vpp = VPP(jsonfiles, logger=test_class.logger,
86 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010087 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020088
Klement Sekerae0545ef2017-01-25 08:00:40 +010089 def __enter__(self):
90 return self
91
Klement Sekera7d6afb32018-11-08 11:52:04 +010092 def assert_negative_api_retval(self):
93 """ Expect API failure - used with with, e.g.:
94 with self.vapi.assert_negative_api_retval():
95 self.vapi.<api call expected to fail>
96 """
Klement Sekerae0545ef2017-01-25 08:00:40 +010097 self._expect_stack.append(self._expect_api_retval)
98 self._expect_api_retval = self._negative
99 return self
100
Klement Sekera7d6afb32018-11-08 11:52:04 +0100101 def assert_zero_api_retval(self):
102 """ Expect API success - used with with, e.g.:
103 with self.vapi.assert_negative_api_retval():
104 self.vapi.<api call expected to succeed>
105
106 note: this is useful only inside another with block
107 as success is the default expected value
108 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100109 self._expect_stack.append(self._expect_api_retval)
110 self._expect_api_retval = self._zero
111 return self
112
113 def __exit__(self, exc_type, exc_value, traceback):
114 self._expect_api_retval = self._expect_stack.pop()
115
Klement Sekeraf62ae122016-10-11 11:47:09 +0200116 def register_hook(self, hook):
117 """Replace hook registration with new hook
118
119 :param hook:
120
121 """
122 self.hook = hook
123
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200124 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100125 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200126 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100127 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 return e
129
130 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100131 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100132 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100133 self.test_class.logger.debug("Expecting event '%s' within %ss",
134 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300135 else:
136 self.test_class.logger.debug("Expecting event within %ss",
137 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100138 if self._events:
139 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200140 limit = time.time() + timeout
141 while time.time() < limit:
142 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100143 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200144 if name and type(e).__name__ != name:
145 raise Exception(
146 "Unexpected event received: %s, expected: %s" %
147 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100148 self.test_class.logger.debug("Returning event %s:%s" %
149 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200150 return e
151 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200152 raise Exception("Event did not occur within timeout")
153
154 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100155 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200156 # FIXME use the name instead of relying on type(e).__name__ ?
157 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100158 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200159 self._events.append(event)
160
Klement Sekeraf62ae122016-10-11 11:47:09 +0200161 def connect(self):
162 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100163 self.vpp.connect(self.name, self.shm_prefix)
164 self.papi = self.vpp.api
165 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166
167 def disconnect(self):
168 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100169 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200170
171 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100172 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200173 Call the appropriate hooks before and after the API call
174
175 :param api_fn: API function to call
176 :param api_args: tuple of API function arguments
177 :param expected_retval: Expected return value (Default value = 0)
178 :returns: reply from the API
179
180 """
181 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100182 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100183 if self._expect_api_retval == self._negative:
184 if hasattr(reply, 'retval') and reply.retval >= 0:
185 msg = "API call passed unexpectedly: expected negative "\
186 "return value instead of %d in %s" % \
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800187 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100188 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100189 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100190 elif self._expect_api_retval == self._zero:
191 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700192 msg = "API call failed, expected %d return value instead "\
193 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra6c746172018-11-26 09:57:21 -0800194 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100195 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100196 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100197 else:
198 raise Exception("Internal error, unexpected value for "
199 "self._expect_api_retval %s" %
200 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200201 self.hook.after_api(api_fn.__name__, api_args)
202 return reply
203
204 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100205 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206
207 :param cli: CLI to execute
208 :returns: CLI output
209
210 """
211 self.hook.before_cli(cli)
212 cli += '\n'
Ole Troan7f991832018-12-06 17:35:12 +0100213 r = self.papi.cli_inband(length=len(cli), cmd=str(cli).encode('utf8'))
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):
Ole Troan7f991832018-12-06 17:35:12 +0100227 return mactobinary(mac)
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 """
Matej Klotton0178d522016-11-04 11:11:44 +01001040 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001041 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001042 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001043 'is_add': is_add,
1044 'is_ipv6': is_ipv6,
1045 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001046 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001047 'mac_address': mac_address,
1048 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001049 }
Matej Klotton0178d522016-11-04 11:11:44 +01001050 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001051
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001052 def ip_neighbor_dump(self,
1053 sw_if_index,
1054 is_ipv6=0):
1055 """ Return IP neighbor dump.
1056
1057 :param sw_if_index:
1058 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1059 """
1060
1061 return self.api(
1062 self.papi.ip_neighbor_dump,
1063 {'is_ipv6': is_ipv6,
1064 'sw_if_index': sw_if_index
1065 }
1066 )
1067
1068 def proxy_arp_add_del(self,
1069 low_address,
1070 hi_address,
1071 vrf_id=0,
1072 is_add=1):
1073 """ Config Proxy Arp Range.
1074
1075 :param low_address: Start address in the rnage to Proxy for
1076 :param hi_address: End address in the rnage to Proxy for
1077 :param vrf_id: The VRF/table in which to proxy
1078 """
1079
1080 return self.api(
1081 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001082 {'proxy':
1083 {
1084 'vrf_id': vrf_id,
1085 'low_address': low_address,
1086 'hi_address': hi_address,
1087 },
1088 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001089
1090 def proxy_arp_intfc_enable_disable(self,
1091 sw_if_index,
1092 is_enable=1):
1093 """ Enable/Disable an interface for proxy ARP requests
1094
1095 :param sw_if_index: Interface
1096 :param enable_disable: Enable/Disable
1097 """
1098
1099 return self.api(
1100 self.papi.proxy_arp_intfc_enable_disable,
1101 {'sw_if_index': sw_if_index,
1102 'enable_disable': is_enable
1103 }
1104 )
1105
Jane546d3b2016-12-08 13:10:03 +01001106 def reset_vrf(self,
1107 vrf_id,
1108 is_ipv6=0,
1109 ):
1110 """ Reset VRF (remove all routes etc.) request.
1111
1112 :param int vrf_id: ID of the FIB table / VRF to reset.
1113 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1114 """
1115
1116 return self.api(
1117 self.papi.reset_vrf,
1118 {'vrf_id': vrf_id,
1119 'is_ipv6': is_ipv6,
1120 }
1121 )
1122
1123 def reset_fib(self,
1124 vrf_id,
1125 is_ipv6=0,
1126 ):
1127 """ Reset VRF (remove all routes etc.) request.
1128
1129 :param int vrf_id: ID of the FIB table / VRF to reset.
1130 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1131 """
1132
1133 return self.api(
1134 self.papi.reset_fib,
1135 {'vrf_id': vrf_id,
1136 'is_ipv6': is_ipv6,
1137 }
1138 )
1139
1140 def ip_dump(self,
1141 is_ipv6=0,
1142 ):
1143 """ Return IP dump.
1144
1145 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1146 """
1147
1148 return self.api(
1149 self.papi.ip_dump,
1150 {'is_ipv6': is_ipv6,
1151 }
1152 )
1153
Klement Sekera7bb873a2016-11-18 07:38:42 +01001154 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001155 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001156 """
1157
1158 :param sw_if_index_from:
1159 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001160 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001161 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001162 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001163 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001164 {'sw_if_index_from': sw_if_index_from,
1165 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001166 'state': state,
1167 'is_l2': is_l2,
1168 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001169
1170 def gre_tunnel_add_del(self,
1171 src_address,
1172 dst_address,
1173 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001174 tunnel_type=0,
1175 instance=0xFFFFFFFF,
1176 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001177 is_add=1,
1178 is_ip6=0):
1179 """ Add a GRE tunnel
1180
1181 :param src_address:
1182 :param dst_address:
1183 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001184 :param tunnel_type: (Default value = 0)
1185 :param instance: (Default value = 0xFFFFFFFF)
1186 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001187 :param is_add: (Default value = 1)
1188 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001189 """
1190
1191 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001192 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001193 {'is_add': is_add,
1194 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001195 'tunnel_type': tunnel_type,
1196 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001197 'src_address': src_address,
1198 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001199 'outer_fib_id': outer_fib_id,
1200 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001201 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001202
Neale Rannsd0df49f2018-08-08 01:06:40 -07001203 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001204 src_ip,
1205 dst_ip,
1206 src_port,
1207 dst_port,
1208 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001209 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001210 :param src_ip:
1211 :param dst_ip:
1212 :param src_port:
1213 :param dst_port:
1214 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001215 """
1216
1217 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001218 self.papi.udp_encap_add,
1219 {
1220 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001221 'src_ip': src_ip,
1222 'dst_ip': dst_ip,
1223 'src_port': src_port,
1224 'dst_port': dst_port,
1225 'table_id': table_id
1226 }
1227 })
1228
1229 def udp_encap_del(self, id):
1230 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001231
1232 def udp_encap_dump(self):
1233 return self.api(self.papi.udp_encap_dump, {})
1234
Neale Ranns43b1f442018-03-20 01:47:35 -07001235 def want_udp_encap_stats(self, enable=1):
1236 return self.api(self.papi.want_udp_encap_stats,
1237 {'enable': enable,
1238 'pid': os.getpid()})
1239
Neale Ranns5a8123b2017-01-26 01:18:23 -08001240 def mpls_fib_dump(self):
1241 return self.api(self.papi.mpls_fib_dump, {})
1242
Neale Ranns15002542017-09-10 04:39:11 -07001243 def mpls_table_add_del(
1244 self,
1245 table_id,
1246 is_add=1):
1247 """
1248
1249 :param table_id
1250 :param is_add: (Default value = 1)
1251
1252 """
1253
1254 return self.api(
1255 self.papi.mpls_table_add_del,
1256 {'mt_table_id': table_id,
1257 'mt_is_add': is_add})
1258
Neale Rannsad422ed2016-11-02 14:20:04 +00001259 def mpls_route_add_del(
1260 self,
1261 label,
1262 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001263 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001264 next_hop_address,
1265 next_hop_sw_if_index=0xFFFFFFFF,
1266 table_id=0,
1267 next_hop_table_id=0,
1268 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001269 next_hop_n_out_labels=0,
1270 next_hop_out_label_stack=[],
1271 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001272 is_resolve_host=0,
1273 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001274 is_interface_rx=0,
1275 is_rpf_id=0,
1276 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001277 is_add=1,
1278 is_drop=0,
1279 is_multipath=0,
1280 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001281 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001282 """
1283
1284 :param dst_address_length:
1285 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1286 :param dst_address:
1287 :param next_hop_address:
1288 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1289 :param vrf_id: (Default value = 0)
1290 :param lookup_in_vrf: (Default value = 0)
1291 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001292 :param is_add: (Default value = 1)
1293 :param is_drop: (Default value = 0)
1294 :param is_ipv6: (Default value = 0)
1295 :param is_local: (Default value = 0)
1296 :param is_classify: (Default value = 0)
1297 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001298 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001299 :param is_resolve_host: (Default value = 0)
1300 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001301 :param next_hop_weight: (Default value = 1)
1302
1303 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001304 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001305 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001306 {'mr_label': label,
1307 'mr_eos': eos,
1308 'mr_table_id': table_id,
1309 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001310 'mr_is_add': is_add,
1311 'mr_is_classify': is_classify,
1312 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001313 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001314 'mr_is_resolve_host': is_resolve_host,
1315 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001316 'mr_is_interface_rx': is_interface_rx,
1317 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001318 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001319 'mr_next_hop_weight': next_hop_weight,
1320 'mr_next_hop': next_hop_address,
1321 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1322 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1323 'mr_next_hop_table_id': next_hop_table_id,
1324 'mr_next_hop_via_label': next_hop_via_label,
1325 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001326
1327 def mpls_ip_bind_unbind(
1328 self,
1329 label,
1330 dst_address,
1331 dst_address_length,
1332 table_id=0,
1333 ip_table_id=0,
1334 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001335 is_bind=1):
1336 """
1337 """
1338 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001339 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001340 {'mb_mpls_table_id': table_id,
1341 'mb_label': label,
1342 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001343 'mb_is_bind': is_bind,
1344 'mb_is_ip4': is_ip4,
1345 'mb_address_length': dst_address_length,
1346 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001347
1348 def mpls_tunnel_add_del(
1349 self,
1350 tun_sw_if_index,
1351 next_hop_proto_is_ip4,
1352 next_hop_address,
1353 next_hop_sw_if_index=0xFFFFFFFF,
1354 next_hop_table_id=0,
1355 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001356 next_hop_n_out_labels=0,
1357 next_hop_out_label_stack=[],
1358 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001359 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001360 l2_only=0,
1361 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001362 """
1363
1364 :param dst_address_length:
1365 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1366 :param dst_address:
1367 :param next_hop_address:
1368 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1369 :param vrf_id: (Default value = 0)
1370 :param lookup_in_vrf: (Default value = 0)
1371 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001372 :param is_add: (Default value = 1)
1373 :param is_drop: (Default value = 0)
1374 :param is_ipv6: (Default value = 0)
1375 :param is_local: (Default value = 0)
1376 :param is_classify: (Default value = 0)
1377 :param is_multipath: (Default value = 0)
1378 :param is_resolve_host: (Default value = 0)
1379 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001380 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001381 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001382
1383 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001384 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001385 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001386 {'mt_sw_if_index': tun_sw_if_index,
1387 'mt_is_add': is_add,
1388 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001389 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001390 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1391 'mt_next_hop_weight': next_hop_weight,
1392 'mt_next_hop': next_hop_address,
1393 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1394 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1395 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001396 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001397 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001398
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001399 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1400 return self.api(self.papi.mpls_tunnel_dump,
1401 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001402
Matus Fabian2ba92e32017-08-21 07:05:03 -07001403 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001404 self,
1405 sw_if_index,
1406 is_inside=1,
1407 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001408 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001409
1410 :param sw_if_index: Software index of the interface
1411 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1412 :param is_add: 1 if add, 0 if delete (Default value = 1)
1413 """
1414 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001415 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001416 {'is_add': is_add,
1417 'is_inside': is_inside,
1418 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001419
Matus Fabian2ba92e32017-08-21 07:05:03 -07001420 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001421 self,
1422 sw_if_index,
1423 is_inside=1,
1424 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001425 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001426
1427 :param sw_if_index: Software index of the interface
1428 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1429 :param is_add: 1 if add, 0 if delete (Default value = 1)
1430 """
1431 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001432 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001433 {'is_add': is_add,
1434 'is_inside': is_inside,
1435 'sw_if_index': sw_if_index})
1436
Matus Fabian2ba92e32017-08-21 07:05:03 -07001437 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001438 self,
1439 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001440 external_ip=0,
1441 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001442 local_port=0,
1443 external_port=0,
1444 addr_only=1,
1445 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001446 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001447 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001448 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001449 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001450 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001451 is_add=1):
1452 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001453
1454 :param local_ip: Local IP address
1455 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001456 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001457 :param local_port: Local port number (Default value = 0)
1458 :param external_port: External port number (Default value = 0)
1459 :param addr_only: 1 if address only mapping, 0 if address and port
1460 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001461 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001462 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001463 :param self_twice_nat: 1 if translate external host address and port
1464 whenever external host address equals
1465 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001466 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001467 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001468 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001469 """
1470 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001471 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001472 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001473 'addr_only': addr_only,
1474 'local_ip_address': local_ip,
1475 'external_ip_address': external_ip,
1476 'local_port': local_port,
1477 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001478 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001479 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001480 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001481 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001482 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001483 'out2in_only': out2in_only,
1484 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001485
Matus Fabianab7a8052017-11-28 04:29:41 -08001486 def nat44_add_del_identity_mapping(
1487 self,
1488 ip='0',
1489 sw_if_index=0xFFFFFFFF,
1490 port=0,
1491 addr_only=1,
1492 vrf_id=0,
1493 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001494 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001495 is_add=1):
1496 """Add/delete NAT44 identity mapping
1497
1498 :param ip: IP address (Default value = 0)
1499 :param sw_if_index: Interface instead of IP address
1500 :param port: Port number (Default value = 0)
1501 :param addr_only: 1 if address only mapping, 0 if address and port
1502 :param vrf_id: VRF ID
1503 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001504 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001505 :param is_add: 1 if add, 0 if delete (Default value = 1)
1506 """
1507 return self.api(
1508 self.papi.nat44_add_del_identity_mapping,
1509 {'is_add': is_add,
1510 'addr_only': addr_only,
1511 'ip_address': ip,
1512 'port': port,
1513 'sw_if_index': sw_if_index,
1514 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001515 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001516 'protocol': protocol})
1517
Matus Fabian2ba92e32017-08-21 07:05:03 -07001518 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001519 self,
1520 first_ip_address,
1521 last_ip_address,
1522 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001523 vrf_id=0xFFFFFFFF,
1524 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001525 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001526
1527 :param first_ip_address: First IP address
1528 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001529 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001530 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001531 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001532 """
1533 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001534 self.papi.nat44_add_del_address_range,
1535 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001536 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001537 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001538 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001539 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001540
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 def nat44_address_dump(self):
1542 """Dump NAT44 addresses
1543 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001544 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001545 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001546
Matus Fabian2ba92e32017-08-21 07:05:03 -07001547 def nat44_interface_dump(self):
1548 """Dump interfaces with NAT44 feature
1549 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001550 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001551 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001552
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 def nat44_interface_output_feature_dump(self):
1554 """Dump interfaces with NAT44 output feature
1555 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001556 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001557 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001558
Matus Fabian2ba92e32017-08-21 07:05:03 -07001559 def nat44_static_mapping_dump(self):
1560 """Dump NAT44 static mappings
1561 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001562 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001563 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001564
Matus Fabianab7a8052017-11-28 04:29:41 -08001565 def nat44_identity_mapping_dump(self):
1566 """Dump NAT44 identity mappings
1567 :return: Dictionary of NAT44 identity mappings
1568 """
1569 return self.api(self.papi.nat44_identity_mapping_dump, {})
1570
Matus Fabian2ba92e32017-08-21 07:05:03 -07001571 def nat_show_config(self):
1572 """Show NAT plugin config
1573 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001574 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001575 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001576
Matus Fabian2ba92e32017-08-21 07:05:03 -07001577 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001578 self,
1579 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001580 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001581 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001582 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001583
1584 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001585 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001586 :param is_add: 1 if add, 0 if delete (Default value = 1)
1587 """
Matus Fabianb932d262017-12-18 05:38:24 -08001588 return self.api(
1589 self.papi.nat44_add_del_interface_addr,
1590 {'is_add': is_add,
1591 'sw_if_index': sw_if_index,
1592 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001593
Matus Fabian2ba92e32017-08-21 07:05:03 -07001594 def nat44_interface_addr_dump(self):
1595 """Dump NAT44 addresses interfaces
1596 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001597 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001598 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001599
Matus Fabian2ba92e32017-08-21 07:05:03 -07001600 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001601 self,
1602 domain_id=1,
1603 src_port=4739,
1604 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001605 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001606
1607 :param domain_id: Observation domain ID (Default value = 1)
1608 :param src_port: Source port number (Default value = 4739)
1609 :param enable: 1 if enable, 0 if disable (Default value = 1)
1610 """
1611 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001612 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001613 {'domain_id': domain_id,
1614 'src_port': src_port,
1615 'enable': enable})
1616
Matus Fabian2ba92e32017-08-21 07:05:03 -07001617 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001618 self,
1619 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001620 vrf_id):
1621 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001622
1623 :param ip_address: ip adress of the user to be dumped
1624 :param cpu_index: cpu_index on which the user is
1625 :param vrf_id: VRF ID
1626 :return: Dictionary of S-NAT sessions
1627 """
1628 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001629 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001630 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001631 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001632
Matus Fabian2ba92e32017-08-21 07:05:03 -07001633 def nat44_user_dump(self):
1634 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001635
Matus Fabian2ba92e32017-08-21 07:05:03 -07001636 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001637 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001638 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001639
Matus Fabian704018c2017-09-04 02:17:18 -07001640 def nat44_add_del_lb_static_mapping(
1641 self,
1642 external_addr,
1643 external_port,
1644 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001645 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001646 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001647 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001648 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001649 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001650 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001651 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001652 is_add=1):
1653 """Add/delete NAT44 load balancing static mapping
1654
Matus Fabianb932d262017-12-18 05:38:24 -08001655 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001656 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001657 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001658 :param is_add - 1 if add, 0 if delete
1659 """
1660 return self.api(
1661 self.papi.nat44_add_del_lb_static_mapping,
1662 {'is_add': is_add,
1663 'external_addr': external_addr,
1664 'external_port': external_port,
1665 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001666 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001667 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001668 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001669 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001670 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001671 'local_num': local_num,
1672 'locals': locals})
1673
1674 def nat44_lb_static_mapping_dump(self):
1675 """Dump NAT44 load balancing static mappings
1676
1677 :return: Dictionary of NAT44 load balancing static mapping
1678 """
1679 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1680
Matus Fabian5ba86f72017-10-26 03:37:38 -07001681 def nat44_del_session(
1682 self,
1683 addr,
1684 port,
1685 protocol,
1686 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001687 is_in=1,
1688 ext_host_address=None,
1689 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001690 """Delete NAT44 session
1691
1692 :param addr: IPv4 address
1693 :param por: port number
1694 :param protocol: IP protocol number
1695 :param vrf_id: VRF ID
1696 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001697 :param ext_host_address: external host IPv4 address
1698 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001699 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001700 if ext_host_address is None:
1701 return self.api(
1702 self.papi.nat44_del_session,
1703 {'address': addr,
1704 'port': port,
1705 'protocol': protocol,
1706 'vrf_id': vrf_id,
1707 'is_in': is_in})
1708 else:
1709 return self.api(
1710 self.papi.nat44_del_session,
1711 {'address': addr,
1712 'port': port,
1713 'protocol': protocol,
1714 'vrf_id': vrf_id,
1715 'is_in': is_in,
1716 'ext_host_valid': 1,
1717 'ext_host_address': ext_host_address,
1718 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001719
Juraj Sloboda7b929792017-11-23 13:20:48 +01001720 def nat44_forwarding_enable_disable(
1721 self,
1722 enable):
1723 """Enable/disable forwarding for NAT44
1724
1725 :param enable: 1 for enable, 0 for disable
1726 """
1727 return self.api(
1728 self.papi.nat44_forwarding_enable_disable,
1729 {'enable': enable})
1730
Matus Fabianefcd1e92017-08-15 06:59:19 -07001731 def nat_set_reass(
1732 self,
1733 timeout=2,
1734 max_reass=1024,
1735 max_frag=5,
1736 drop_frag=0,
1737 is_ip6=0):
1738 """Set NAT virtual fragmentation reassembly
1739
1740 :param timeout: reassembly timeout (Default 2sec)
1741 :param max_reass: maximum concurrent reassemblies (Default 1024)
1742 :param max_frag: maximum fragmets per reassembly (Default 5)
1743 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1744 :param is_ip6: 1 if IPv6, 0 if IPv4
1745 """
1746 return self.api(
1747 self.papi.nat_set_reass,
1748 {'timeout': timeout,
1749 'max_reass': max_reass,
1750 'max_frag': max_frag,
1751 'drop_frag': drop_frag,
1752 'is_ip6': is_ip6})
1753
1754 def nat_get_reass(self):
1755 """Get NAT virtual fragmentation reassembly configuration
1756
1757 :return: NAT virtual fragmentation reassembly configuration
1758 """
1759 return self.api(self.papi.nat_get_reass, {})
1760
1761 def nat_reass_dump(self):
1762 """Dump NAT virtual fragmentation reassemblies
1763
1764 :return: Dictionary of NAT virtual fragmentation reassemblies
1765 """
1766 return self.api(self.papi.nat_reass_dump, {})
1767
Matus Fabian2ba92e32017-08-21 07:05:03 -07001768 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001769 self,
1770 in_addr,
1771 in_plen,
1772 out_addr,
1773 out_plen,
1774 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001775 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001776
1777 :param is_add - 1 if add, 0 if delete
1778 :param in_addr - inside IP address
1779 :param in_plen - inside IP address prefix length
1780 :param out_addr - outside IP address
1781 :param out_plen - outside IP address prefix length
1782 """
1783 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001784 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001785 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001786 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001787 'in_addr': in_addr,
1788 'in_plen': in_plen,
1789 'out_addr': out_addr,
1790 'out_plen': out_plen})
1791
Matus Fabian2ba92e32017-08-21 07:05:03 -07001792 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001793 self,
1794 in_addr):
1795 """Get outside address and port range from inside address
1796
1797 :param in_addr - inside IP address
1798 """
1799 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001800 self.papi.nat_det_forward,
1801 {'in_addr': in_addr,
1802 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001803
Matus Fabian2ba92e32017-08-21 07:05:03 -07001804 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001805 self,
1806 out_addr,
1807 out_port):
1808 """Get inside address from outside address and port
1809
1810 :param out_addr - outside IP address
1811 :param out_port - outside port
1812 """
1813 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001814 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001815 {'out_addr': out_addr,
1816 'out_port': out_port})
1817
Matus Fabian2ba92e32017-08-21 07:05:03 -07001818 def nat_det_map_dump(self):
1819 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001820
Matus Fabian2ba92e32017-08-21 07:05:03 -07001821 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001822 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001823 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001824
Matus Fabian878c6462018-08-23 00:33:35 -07001825 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001826 self,
1827 udp=300,
1828 tcp_established=7440,
1829 tcp_transitory=240,
1830 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001831 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001832
1833 :param udp - UDP timeout (Default value = 300)
1834 :param tcp_established - TCP established timeout (Default value = 7440)
1835 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1836 :param icmp - ICMP timeout (Default value = 60)
1837 """
1838 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001839 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001840 {'udp': udp,
1841 'tcp_established': tcp_established,
1842 'tcp_transitory': tcp_transitory,
1843 'icmp': icmp})
1844
Matus Fabian878c6462018-08-23 00:33:35 -07001845 def nat_get_timeouts(self):
1846 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001847
Matus Fabian878c6462018-08-23 00:33:35 -07001848 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001849 """
Matus Fabian878c6462018-08-23 00:33:35 -07001850 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001851
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001852 def nat_set_addr_and_port_alloc_alg(
1853 self,
1854 alg=0,
1855 psid_offset=0,
1856 psid_length=0,
1857 psid=0,
1858 start_port=0,
1859 end_port=0):
1860 """Set address and port assignment algorithm
1861
1862 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1863 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1864 :param psid_length: length of PSID (valid only for MAP-E alg)
1865 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1866 :param start_port: beginning of the port range
1867 :param end_port: end of the port range
1868 """
1869 return self.api(
1870 self.papi.nat_set_addr_and_port_alloc_alg,
1871 {'alg': alg,
1872 'psid_offset': psid_offset,
1873 'psid_length': psid_length,
1874 'psid': psid,
1875 'start_port': start_port,
1876 'end_port': end_port})
1877
1878 def nat_get_addr_and_port_alloc_alg(self):
1879 """Get address and port assignment algorithm"""
1880 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1881
Matus Fabianbb4e0222018-09-13 02:36:25 -07001882 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1883 """Set TCP MSS rewriting configuration
1884
1885 :param enable: disable(0)/enable(1) MSS rewriting feature
1886 :param mss_value: MSS value to be used for MSS rewriting
1887 """
1888 return self.api(
1889 self.papi.nat_set_mss_clamping,
1890 {'enable': enable, 'mss_value': mss_value})
1891
1892 def nat_get_mss_clamping(self):
1893 """Get TCP MSS rewriting configuration"""
1894 return self.api(self.papi.nat_get_mss_clamping, {})
1895
Matus Fabian2ba92e32017-08-21 07:05:03 -07001896 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001897 self,
1898 out_addr,
1899 out_port,
1900 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001901 ext_port):
1902 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001903
1904 :param out_addr - outside IP address
1905 :param out_port - outside port
1906 :param ext_addr - external host IP address
1907 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001908 """
1909 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001910 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001911 {'out_addr': out_addr,
1912 'out_port': out_port,
1913 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001914 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001915
Matus Fabian2ba92e32017-08-21 07:05:03 -07001916 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001917 self,
1918 in_addr,
1919 in_port,
1920 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001921 ext_port):
1922 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001923
1924 :param in_addr - inside IP address
1925 :param in_port - inside port
1926 :param ext_addr - external host IP address
1927 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001928 """
1929 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001930 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001931 {'in_addr': in_addr,
1932 'in_port': in_port,
1933 'ext_addr': ext_addr,
1934 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001935 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001936
Matus Fabian2ba92e32017-08-21 07:05:03 -07001937 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001938 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001939 user_addr):
1940 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001941
1942 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001943 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001944 """
1945 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001946 self.papi.nat_det_session_dump,
1947 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001948 'user_addr': user_addr})
1949
Matus Fabian06596c52017-06-06 04:53:28 -07001950 def nat64_add_del_pool_addr_range(
1951 self,
1952 start_addr,
1953 end_addr,
1954 vrf_id=0xFFFFFFFF,
1955 is_add=1):
1956 """Add/del address range to NAT64 pool
1957
1958 :param start_addr: First IP address
1959 :param end_addr: Last IP address
1960 :param vrf_id: VRF id for the address range
1961 :param is_add: 1 if add, 0 if delete (Default value = 1)
1962 """
1963 return self.api(
1964 self.papi.nat64_add_del_pool_addr_range,
1965 {'start_addr': start_addr,
1966 'end_addr': end_addr,
1967 'vrf_id': vrf_id,
1968 'is_add': is_add})
1969
1970 def nat64_pool_addr_dump(self):
1971 """Dump NAT64 pool addresses
1972 :return: Dictionary of NAT64 pool addresses
1973 """
1974 return self.api(self.papi.nat64_pool_addr_dump, {})
1975
1976 def nat64_add_del_interface(
1977 self,
1978 sw_if_index,
1979 is_inside=1,
1980 is_add=1):
1981 """Enable/disable NAT64 feature on the interface
1982 :param sw_if_index: Index of the interface
1983 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1984 :param is_add: 1 if add, 0 if delete (Default value = 1)
1985 """
1986 return self.api(
1987 self.papi.nat64_add_del_interface,
1988 {'sw_if_index': sw_if_index,
1989 'is_inside': is_inside,
1990 'is_add': is_add})
1991
1992 def nat64_interface_dump(self):
1993 """Dump interfaces with NAT64 feature
1994 :return: Dictionary of interfaces with NAT64 feature
1995 """
1996 return self.api(self.papi.nat64_interface_dump, {})
1997
1998 def nat64_add_del_static_bib(
1999 self,
2000 in_ip,
2001 out_ip,
2002 in_port,
2003 out_port,
2004 protocol,
2005 vrf_id=0,
2006 is_add=1):
2007 """Add/delete S-NAT static BIB entry
2008
2009 :param in_ip: Inside IPv6 address
2010 :param out_ip: Outside IPv4 address
2011 :param in_port: Inside port number
2012 :param out_port: Outside port number
2013 :param protocol: IP protocol
2014 :param vrf_id: VRF ID (Default value = 0)
2015 :param is_add: 1 if add, 0 if delete (Default value = 1)
2016 """
2017 return self.api(
2018 self.papi.nat64_add_del_static_bib,
2019 {'i_addr': in_ip,
2020 'o_addr': out_ip,
2021 'i_port': in_port,
2022 'o_port': out_port,
2023 'vrf_id': vrf_id,
2024 'proto': protocol,
2025 'is_add': is_add})
2026
Matus Fabianab9a59c2017-08-16 05:37:36 -07002027 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002028 """Dump NAT64 BIB
2029
Matus Fabianab9a59c2017-08-16 05:37:36 -07002030 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002031 :returns: Dictionary of NAT64 BIB entries
2032 """
2033 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2034
2035 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2036 tcp_incoming_syn=6):
2037 """Set values of timeouts for NAT64 (in seconds)
2038
Matus Fabian428dc912017-06-21 06:15:18 -07002039 :param udpi: UDP timeout (Default value = 300)
2040 :param icmp: ICMP timeout (Default value = 60)
2041 :param tcp_trans: TCP transitory timeout (Default value = 240)
2042 :param tcp_est: TCP established timeout (Default value = 7440)
2043 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002044 """
2045 return self.api(
2046 self.papi.nat64_set_timeouts,
2047 {'udp': udp,
2048 'icmp': icmp,
2049 'tcp_trans': tcp_trans,
2050 'tcp_est': tcp_est,
2051 'tcp_incoming_syn': tcp_incoming_syn})
2052
2053 def nat64_get_timeouts(self):
2054 """Get values of timeouts for NAT64
2055
2056 :return: Timeouts for NAT64 (in seconds)
2057 """
2058 return self.api(self.papi.nat64_get_timeouts, {})
2059
Matus Fabianab9a59c2017-08-16 05:37:36 -07002060 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002061 """Dump NAT64 session table
2062
Matus Fabianab9a59c2017-08-16 05:37:36 -07002063 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002064 :returns: Dictionary of NAT64 sesstion table entries
2065 """
2066 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2067
Matus Fabian428dc912017-06-21 06:15:18 -07002068 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2069 """Add/del NAT64 prefix
2070
2071 :param prefix: NAT64 prefix
2072 :param plen: NAT64 prefix length
2073 :param vrf_id: VRF id of tenant (Default 0)
2074 :param is_add: 1 if add, 0 if delete (Default value = 1)
2075 """
2076 return self.api(
2077 self.papi.nat64_add_del_prefix,
2078 {'prefix': prefix,
2079 'prefix_len': plen,
2080 'vrf_id': vrf_id,
2081 'is_add': is_add})
2082
2083 def nat64_prefix_dump(self):
2084 """Dump NAT64 prefix
2085
2086 :returns: Dictionary of NAT64 prefixes
2087 """
2088 return self.api(self.papi.nat64_prefix_dump, {})
2089
Matus Fabian0938dcf2017-11-08 01:59:38 -08002090 def nat64_add_interface_addr(
2091 self,
2092 sw_if_index,
2093 is_add=1):
2094 """Add/del NAT64 address from interface
2095
2096 :param sw_if_index: Software index of the interface
2097 :param is_add: 1 if add, 0 if delete (Default value = 1)
2098 """
2099 return self.api(self.papi.nat64_add_del_interface_addr,
2100 {'is_add': is_add, 'sw_if_index': sw_if_index})
2101
Matus Fabian8ebe6252017-11-06 05:04:53 -08002102 def dslite_set_aftr_addr(self, ip6, ip4):
2103 """Set DS-Lite AFTR addresses
2104
2105 :param ip4: IPv4 address
2106 :param ip6: IPv6 address
2107 """
2108 return self.api(
2109 self.papi.dslite_set_aftr_addr,
2110 {'ip4_addr': ip4,
2111 'ip6_addr': ip6})
2112
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002113 def dslite_set_b4_addr(self, ip6, ip4):
2114 """Set DS-Lite B4 IPv6 address
2115
2116 :param ip4: IPv4 address
2117 :param ip6: IPv6 address
2118 """
2119 return self.api(
2120 self.papi.dslite_set_b4_addr,
2121 {'ip4_addr': ip4,
2122 'ip6_addr': ip6})
2123
Matus Fabian8ebe6252017-11-06 05:04:53 -08002124 def dslite_add_del_pool_addr_range(
2125 self,
2126 start_addr,
2127 end_addr,
2128 is_add=1):
2129 """Add/del address range to DS-Lite pool
2130
2131 :param start_addr: First IP address
2132 :param end_addr: Last IP address
2133 :param is_add: 1 if add, 0 if delete (Default value = 1)
2134 """
2135 return self.api(
2136 self.papi.dslite_add_del_pool_addr_range,
2137 {'start_addr': start_addr,
2138 'end_addr': end_addr,
2139 'is_add': is_add})
2140
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002141 def nat66_add_del_interface(
2142 self,
2143 sw_if_index,
2144 is_inside=1,
2145 is_add=1):
2146 """Enable/disable NAT66 feature on the interface
2147 :param sw_if_index: Index of the interface
2148 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2149 :param is_add: 1 if add, 0 if delete (Default value = 1)
2150 """
2151 return self.api(
2152 self.papi.nat66_add_del_interface,
2153 {'sw_if_index': sw_if_index,
2154 'is_inside': is_inside,
2155 'is_add': is_add})
2156
2157 def nat66_add_del_static_mapping(
2158 self,
2159 in_ip,
2160 out_ip,
2161 vrf_id=0,
2162 is_add=1):
2163 """Add/delete NAT66 static mapping
2164
2165 :param in_ip: Inside IPv6 address
2166 :param out_ip: Outside IPv6 address
2167 :param vrf_id: VRF ID (Default value = 0)
2168 :param is_add: 1 if add, 0 if delete (Default value = 1)
2169 """
2170 return self.api(
2171 self.papi.nat66_add_del_static_mapping,
2172 {'local_ip_address': in_ip,
2173 'external_ip_address': out_ip,
2174 'vrf_id': vrf_id,
2175 'is_add': is_add})
2176
2177 def nat66_interface_dump(self):
2178 """Dump interfaces with NAT66 feature
2179 :return: Dictionary of interfaces with NAT66 feature
2180 """
2181 return self.api(self.papi.nat66_interface_dump, {})
2182
2183 def nat66_static_mapping_dump(self):
2184 """Dump NAT66 static mappings
2185 :return: Dictionary of NAT66 static mappings
2186 """
2187 return self.api(self.papi.nat66_static_mapping_dump, {})
2188
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002189 def control_ping(self):
2190 self.api(self.papi.control_ping)
2191
2192 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002193 detect_mult, local_addr, peer_addr, is_ipv6=0,
2194 bfd_key_id=None, conf_key_id=None):
2195 if bfd_key_id is None:
2196 return self.api(self.papi.bfd_udp_add,
2197 {
2198 'sw_if_index': sw_if_index,
2199 'desired_min_tx': desired_min_tx,
2200 'required_min_rx': required_min_rx,
2201 'local_addr': local_addr,
2202 'peer_addr': peer_addr,
2203 'is_ipv6': is_ipv6,
2204 'detect_mult': detect_mult,
2205 })
2206 else:
2207 return self.api(self.papi.bfd_udp_add,
2208 {
2209 'sw_if_index': sw_if_index,
2210 'desired_min_tx': desired_min_tx,
2211 'required_min_rx': required_min_rx,
2212 'local_addr': local_addr,
2213 'peer_addr': peer_addr,
2214 'is_ipv6': is_ipv6,
2215 'detect_mult': detect_mult,
2216 'is_authenticated': 1,
2217 'bfd_key_id': bfd_key_id,
2218 'conf_key_id': conf_key_id,
2219 })
2220
Klement Sekeraa57a9702017-02-02 06:58:07 +01002221 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2222 detect_mult, local_addr, peer_addr, is_ipv6=0):
2223 return self.api(self.papi.bfd_udp_mod,
2224 {
2225 'sw_if_index': sw_if_index,
2226 'desired_min_tx': desired_min_tx,
2227 'required_min_rx': required_min_rx,
2228 'local_addr': local_addr,
2229 'peer_addr': peer_addr,
2230 'is_ipv6': is_ipv6,
2231 'detect_mult': detect_mult,
2232 })
2233
Klement Sekerab17dd962017-01-09 07:43:48 +01002234 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2235 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2236 is_delayed=False):
2237 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002238 {
2239 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002240 'local_addr': local_addr,
2241 'peer_addr': peer_addr,
2242 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002243 'is_delayed': 1 if is_delayed else 0,
2244 'bfd_key_id': bfd_key_id,
2245 'conf_key_id': conf_key_id,
2246 })
2247
2248 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2249 is_ipv6=0, is_delayed=False):
2250 return self.api(self.papi.bfd_udp_auth_deactivate,
2251 {
2252 'sw_if_index': sw_if_index,
2253 'local_addr': local_addr,
2254 'peer_addr': peer_addr,
2255 'is_ipv6': is_ipv6,
2256 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002257 })
2258
2259 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2260 return self.api(self.papi.bfd_udp_del,
2261 {
2262 'sw_if_index': sw_if_index,
2263 'local_addr': local_addr,
2264 'peer_addr': peer_addr,
2265 'is_ipv6': is_ipv6,
2266 })
2267
2268 def bfd_udp_session_dump(self):
2269 return self.api(self.papi.bfd_udp_session_dump, {})
2270
Klement Sekerab17dd962017-01-09 07:43:48 +01002271 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2272 peer_addr, is_ipv6=0):
2273 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002274 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002275 'sw_if_index': sw_if_index,
2276 'local_addr': local_addr,
2277 'peer_addr': peer_addr,
2278 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002279 })
2280
2281 def want_bfd_events(self, enable_disable=1):
2282 return self.api(self.papi.want_bfd_events, {
2283 'enable_disable': enable_disable,
2284 'pid': os.getpid(),
2285 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002286
Klement Sekerab17dd962017-01-09 07:43:48 +01002287 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2288 return self.api(self.papi.bfd_auth_set_key, {
2289 'conf_key_id': conf_key_id,
2290 'auth_type': auth_type,
2291 'key': key,
2292 'key_len': len(key),
2293 })
2294
2295 def bfd_auth_del_key(self, conf_key_id):
2296 return self.api(self.papi.bfd_auth_del_key, {
2297 'conf_key_id': conf_key_id,
2298 })
2299
2300 def bfd_auth_keys_dump(self):
2301 return self.api(self.papi.bfd_auth_keys_dump, {})
2302
Klement Sekera239790f2017-02-16 10:53:53 +01002303 def bfd_udp_set_echo_source(self, sw_if_index):
2304 return self.api(self.papi.bfd_udp_set_echo_source,
2305 {'sw_if_index': sw_if_index})
2306
Klement Sekera73884482017-02-23 09:26:30 +01002307 def bfd_udp_del_echo_source(self):
2308 return self.api(self.papi.bfd_udp_del_echo_source, {})
2309
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002310 def bfd_udp_get_echo_source(self):
2311 return self.api(self.papi.bfd_udp_get_echo_source, {})
2312
Steve Shin7957d6e2016-12-19 09:24:50 -08002313 def classify_add_del_table(
2314 self,
2315 is_add,
2316 mask,
2317 match_n_vectors=1,
2318 table_index=0xFFFFFFFF,
2319 nbuckets=2,
2320 memory_size=2097152,
2321 skip_n_vectors=0,
2322 next_table_index=0xFFFFFFFF,
2323 miss_next_index=0xFFFFFFFF,
2324 current_data_flag=0,
2325 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002326 """
2327 :param is_add:
2328 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002329 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002330 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002331 :param nbuckets: (Default value = 2)
2332 :param memory_size: (Default value = 2097152)
2333 :param skip_n_vectors: (Default value = 0)
2334 :param next_table_index: (Default value = 0xFFFFFFFF)
2335 :param miss_next_index: (Default value = 0xFFFFFFFF)
2336 :param current_data_flag: (Default value = 0)
2337 :param current_data_offset: (Default value = 0)
2338 """
2339
Juraj Sloboda75282452018-06-12 14:20:49 +02002340 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2341 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002342 return self.api(
2343 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002344 {'is_add': is_add,
2345 'table_index': table_index,
2346 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002347 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002348 'skip_n_vectors': skip_n_vectors,
2349 'match_n_vectors': match_n_vectors,
2350 'next_table_index': next_table_index,
2351 'miss_next_index': miss_next_index,
2352 'current_data_flag': current_data_flag,
2353 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002354 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002355 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002356
2357 def classify_add_del_session(
2358 self,
2359 is_add,
2360 table_index,
2361 match,
2362 opaque_index=0xFFFFFFFF,
2363 hit_next_index=0xFFFFFFFF,
2364 advance=0,
2365 action=0,
2366 metadata=0):
2367 """
2368 :param is_add:
2369 :param table_index:
2370 :param match:
2371 :param opaque_index: (Default value = 0xFFFFFFFF)
2372 :param hit_next_index: (Default value = 0xFFFFFFFF)
2373 :param advance: (Default value = 0)
2374 :param action: (Default value = 0)
2375 :param metadata: (Default value = 0)
2376 """
2377
Juraj Sloboda75282452018-06-12 14:20:49 +02002378 match_len = ((len(match) - 1) / 16 + 1) * 16
2379 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002380 return self.api(
2381 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002382 {'is_add': is_add,
2383 'table_index': table_index,
2384 'hit_next_index': hit_next_index,
2385 'opaque_index': opaque_index,
2386 'advance': advance,
2387 'action': action,
2388 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002389 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002390 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002391
2392 def input_acl_set_interface(
2393 self,
2394 is_add,
2395 sw_if_index,
2396 ip4_table_index=0xFFFFFFFF,
2397 ip6_table_index=0xFFFFFFFF,
2398 l2_table_index=0xFFFFFFFF):
2399 """
2400 :param is_add:
2401 :param sw_if_index:
2402 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2403 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2404 :param l2_table_index: (Default value = 0xFFFFFFFF)
2405 """
2406
2407 return self.api(
2408 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002409 {'sw_if_index': sw_if_index,
2410 'ip4_table_index': ip4_table_index,
2411 'ip6_table_index': ip6_table_index,
2412 'l2_table_index': l2_table_index,
2413 'is_add': is_add})
2414
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002415 def output_acl_set_interface(
2416 self,
2417 is_add,
2418 sw_if_index,
2419 ip4_table_index=0xFFFFFFFF,
2420 ip6_table_index=0xFFFFFFFF,
2421 l2_table_index=0xFFFFFFFF):
2422 """
2423 :param is_add:
2424 :param sw_if_index:
2425 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2426 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2427 :param l2_table_index: (Default value = 0xFFFFFFFF)
2428 """
2429
2430 return self.api(
2431 self.papi.output_acl_set_interface,
2432 {'sw_if_index': sw_if_index,
2433 'ip4_table_index': ip4_table_index,
2434 'ip6_table_index': ip6_table_index,
2435 'l2_table_index': l2_table_index,
2436 'is_add': is_add})
2437
Klement Sekera77fabdb2017-01-02 07:46:14 +01002438 def set_ipfix_exporter(
2439 self,
2440 collector_address,
2441 src_address,
2442 path_mtu,
2443 template_interval,
2444 vrf_id=0,
2445 collector_port=4739,
2446 udp_checksum=0):
2447 return self.api(
2448 self.papi.set_ipfix_exporter,
2449 {
2450 'collector_address': collector_address,
2451 'collector_port': collector_port,
2452 'src_address': src_address,
2453 'vrf_id': vrf_id,
2454 'path_mtu': path_mtu,
2455 'template_interval': template_interval,
2456 'udp_checksum': udp_checksum,
2457 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002458
2459 def dhcp_proxy_config(self,
2460 dhcp_server,
2461 dhcp_src_address,
2462 rx_table_id=0,
2463 server_table_id=0,
2464 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002465 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002466 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002467 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002468 {
2469 'rx_vrf_id': rx_table_id,
2470 'server_vrf_id': server_table_id,
2471 'is_ipv6': is_ipv6,
2472 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002473 'dhcp_server': dhcp_server,
2474 'dhcp_src_address': dhcp_src_address,
2475 })
2476
2477 def dhcp_proxy_set_vss(self,
2478 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002479 vss_type=255,
2480 vpn_ascii_id="",
2481 oui=0,
2482 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002483 is_add=1,
2484 is_ip6=0):
2485 return self.api(
2486 self.papi.dhcp_proxy_set_vss,
2487 {
2488 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002489 'vss_type': vss_type,
2490 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002491 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002492 'vpn_index': vpn_index,
2493 'is_add': is_add,
2494 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002495 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002496
Neale Rannsdaff1782018-05-16 04:12:18 -07002497 def dhcp_client_dump(self):
2498 return self.api(self.papi.dhcp_client_dump, {})
2499
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002500 def dhcp_client(self,
2501 sw_if_index,
2502 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002503 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002504 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002505 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002506 want_dhcp_events=0):
2507 return self.api(
2508 self.papi.dhcp_client_config,
2509 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002510 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002511 'client': {
2512 'sw_if_index': sw_if_index,
2513 'hostname': hostname,
2514 'id': client_id,
2515 'want_dhcp_event': want_dhcp_events,
2516 'set_broadcast_flag': set_broadcast_flag,
2517 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002518 })
2519
Neale Ranns32e1c012016-11-22 17:07:28 +00002520 def ip_mroute_add_del(self,
2521 src_address,
2522 grp_address,
2523 grp_address_length,
2524 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002525 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002526 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002527 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002528 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002529 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002530 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002531 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002532 is_add=1,
2533 is_ipv6=0,
2534 is_local=0):
2535 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002536 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002537 """
2538 return self.api(
2539 self.papi.ip_mroute_add_del,
2540 {'next_hop_sw_if_index': next_hop_sw_if_index,
2541 'entry_flags': e_flags,
2542 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002543 'table_id': table_id,
2544 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002545 'is_add': is_add,
2546 'is_ipv6': is_ipv6,
2547 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002548 'bier_imp': bier_imp,
2549 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002550 'grp_address_length': grp_address_length,
2551 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002552 'src_address': src_address,
2553 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002554
2555 def mfib_signal_dump(self):
2556 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002557
2558 def ip_mfib_dump(self):
2559 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002560
Neale Rannsd792d9c2017-10-21 10:53:20 -07002561 def ip6_mfib_dump(self):
2562 return self.api(self.papi.ip6_mfib_dump, {})
2563
Filip Tehlar770e89e2017-01-31 10:39:16 +01002564 def lisp_enable_disable(self, is_enabled):
2565 return self.api(
2566 self.papi.lisp_enable_disable,
2567 {
2568 'is_en': is_enabled,
2569 })
2570
2571 def lisp_locator_set(self,
2572 ls_name,
2573 is_add=1):
2574 return self.api(
2575 self.papi.lisp_add_del_locator_set,
2576 {
2577 'is_add': is_add,
2578 'locator_set_name': ls_name
2579 })
2580
2581 def lisp_locator_set_dump(self):
2582 return self.api(self.papi.lisp_locator_set_dump, {})
2583
2584 def lisp_locator(self,
2585 ls_name,
2586 sw_if_index,
2587 priority=1,
2588 weight=1,
2589 is_add=1):
2590 return self.api(
2591 self.papi.lisp_add_del_locator,
2592 {
2593 'is_add': is_add,
2594 'locator_set_name': ls_name,
2595 'sw_if_index': sw_if_index,
2596 'priority': priority,
2597 'weight': weight
2598 })
2599
2600 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2601 return self.api(
2602 self.papi.lisp_locator_dump,
2603 {
2604 'is_index_set': is_index_set,
2605 'ls_name': ls_name,
2606 'ls_index': ls_index,
2607 })
2608
2609 def lisp_local_mapping(self,
2610 ls_name,
2611 eid_type,
2612 eid,
2613 prefix_len,
2614 vni=0,
2615 key_id=0,
2616 key="",
2617 is_add=1):
2618 return self.api(
2619 self.papi.lisp_add_del_local_eid,
2620 {
2621 'locator_set_name': ls_name,
2622 'is_add': is_add,
2623 'eid_type': eid_type,
2624 'eid': eid,
2625 'prefix_len': prefix_len,
2626 'vni': vni,
2627 'key_id': key_id,
2628 'key': key
2629 })
2630
2631 def lisp_eid_table_dump(self,
2632 eid_set=0,
2633 prefix_length=0,
2634 vni=0,
2635 eid_type=0,
2636 eid=None,
2637 filter_opt=0):
2638 return self.api(
2639 self.papi.lisp_eid_table_dump,
2640 {
2641 'eid_set': eid_set,
2642 'prefix_length': prefix_length,
2643 'vni': vni,
2644 'eid_type': eid_type,
2645 'eid': eid,
2646 'filter': filter_opt,
2647 })
2648
2649 def lisp_remote_mapping(self,
2650 eid_type,
2651 eid,
2652 eid_prefix_len=0,
2653 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002654 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002655 rlocs_num=0,
2656 is_src_dst=0,
2657 is_add=1):
2658 return self.api(
2659 self.papi.lisp_add_del_remote_mapping,
2660 {
2661 'is_add': is_add,
2662 'eid_type': eid_type,
2663 'eid': eid,
2664 'eid_len': eid_prefix_len,
2665 'rloc_num': rlocs_num,
2666 'rlocs': rlocs,
2667 'vni': vni,
2668 'is_src_dst': is_src_dst,
2669 })
2670
2671 def lisp_adjacency(self,
2672 leid,
2673 reid,
2674 leid_len,
2675 reid_len,
2676 eid_type,
2677 is_add=1,
2678 vni=0):
2679 return self.api(
2680 self.papi.lisp_add_del_adjacency,
2681 {
2682 'is_add': is_add,
2683 'vni': vni,
2684 'eid_type': eid_type,
2685 'leid': leid,
2686 'reid': reid,
2687 'leid_len': leid_len,
2688 'reid_len': reid_len,
2689 })
2690
2691 def lisp_adjacencies_get(self, vni=0):
2692 return self.api(
2693 self.papi.lisp_adjacencies_get,
2694 {
2695 'vni': vni
2696 })
Neale Ranns80823802017-02-20 18:23:41 -08002697
2698 def map_add_domain(self,
2699 ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002700 ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002701 ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002702 ea_bits_len=0,
2703 psid_offset=0,
2704 psid_length=0,
2705 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002706 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002707 mtu=1280):
2708 return self.api(
2709 self.papi.map_add_domain,
2710 {
2711 'ip6_prefix': ip6_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002712 'ip4_prefix': ip4_prefix,
Neale Ranns80823802017-02-20 18:23:41 -08002713 'ip6_src': ip6_src,
Neale Ranns80823802017-02-20 18:23:41 -08002714 'ea_bits_len': ea_bits_len,
2715 'psid_offset': psid_offset,
2716 'psid_length': psid_length,
2717 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002718 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002719 'mtu': mtu
2720 })
Hongjun Nief486b12017-04-12 19:21:16 +08002721
2722 def gtpu_add_del_tunnel(
2723 self,
2724 src_addr,
2725 dst_addr,
2726 is_add=1,
2727 is_ipv6=0,
2728 mcast_sw_if_index=0xFFFFFFFF,
2729 encap_vrf_id=0,
2730 decap_next_index=0xFFFFFFFF,
2731 teid=0):
2732 """
2733
2734 :param is_add: (Default value = 1)
2735 :param is_ipv6: (Default value = 0)
2736 :param src_addr:
2737 :param dst_addr:
2738 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2739 :param encap_vrf_id: (Default value = 0)
2740 :param decap_next_index: (Default value = 0xFFFFFFFF)
2741 :param teid: (Default value = 0)
2742
2743 """
2744 return self.api(self.papi.gtpu_add_del_tunnel,
2745 {'is_add': is_add,
2746 'is_ipv6': is_ipv6,
2747 'src_address': src_addr,
2748 'dst_address': dst_addr,
2749 'mcast_sw_if_index': mcast_sw_if_index,
2750 'encap_vrf_id': encap_vrf_id,
2751 'decap_next_index': decap_next_index,
2752 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002753
2754 def vxlan_gpe_add_del_tunnel(
2755 self,
2756 src_addr,
2757 dst_addr,
2758 mcast_sw_if_index=0xFFFFFFFF,
2759 is_add=1,
2760 is_ipv6=0,
2761 encap_vrf_id=0,
2762 decap_vrf_id=0,
2763 protocol=3,
2764 vni=0):
2765 """
2766
2767 :param local:
2768 :param remote:
2769 :param is_add: (Default value = 1)
2770 :param is_ipv6: (Default value = 0)
2771 :param encap_vrf_id: (Default value = 0)
2772 :param decap_vrf_id: (Default value = 0)
2773 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2774 :param protocol: (Default value = 3)
2775 :param vni: (Default value = 0)
2776
2777 """
2778 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2779 {'is_add': is_add,
2780 'is_ipv6': is_ipv6,
2781 'local': src_addr,
2782 'remote': dst_addr,
2783 'mcast_sw_if_index': mcast_sw_if_index,
2784 'encap_vrf_id': encap_vrf_id,
2785 'decap_vrf_id': decap_vrf_id,
2786 'protocol': protocol,
2787 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002788
Neale Ranns79a05f52018-09-11 07:39:43 -07002789 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002790 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002791 src,
2792 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002793 mcast_sw_if_index=0xFFFFFFFF,
2794 is_add=1,
2795 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002796 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002797 vni=0,
2798 instance=0xFFFFFFFF):
2799 """
2800
2801 :param dst_addr:
2802 :param src_addr:
2803 :param is_add: (Default value = 1)
2804 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002805 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002806 :param decap_next_index: (Default value = 0xFFFFFFFF)
2807 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2808 :param vni: (Default value = 0)
2809 :param instance: (Default value = 0xFFFFFFFF)
2810
2811 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002812 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002813 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002814 'tunnel': {
2815 'src': src,
2816 'dst': dst,
2817 'mcast_sw_if_index': mcast_sw_if_index,
2818 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002819 'vni': vni,
2820 'instance': instance}})
2821
2822 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2823 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01002824 {'sw_if_index': sw_if_index,
2825 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002826
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002827 def pppoe_add_del_session(
2828 self,
2829 client_ip,
2830 client_mac,
2831 session_id=0,
2832 is_add=1,
2833 is_ipv6=0,
2834 decap_vrf_id=0):
2835 """
2836
2837 :param is_add: (Default value = 1)
2838 :param is_ipv6: (Default value = 0)
2839 :param client_ip:
2840 :param session_id: (Default value = 0)
2841 :param client_mac:
2842 :param decap_vrf_id: (Default value = 0)
2843
2844 """
2845 return self.api(self.papi.pppoe_add_del_session,
2846 {'is_add': is_add,
2847 'is_ipv6': is_ipv6,
2848 'session_id': session_id,
2849 'client_ip': client_ip,
2850 'decap_vrf_id': decap_vrf_id,
2851 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002852
Neale Ranns7c922dc2018-08-30 06:12:27 -07002853 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2854 return self.api(self.papi.sr_mpls_policy_add,
2855 {'bsid': bsid,
2856 'weight': weight,
2857 'type': type,
2858 'n_segments': len(segments),
2859 'segments': segments})
2860
2861 def sr_mpls_policy_del(self, bsid):
2862 return self.api(self.papi.sr_mpls_policy_del,
2863 {'bsid': bsid})
2864
Kris Michielsen91074432017-06-22 13:00:20 +02002865 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002866 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002867 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002868 nh_addr4,
2869 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002870 is_del=0,
2871 end_psp=0,
2872 sw_if_index=0xFFFFFFFF,
2873 vlan_index=0,
2874 fib_table=0,
2875 ):
2876 """ Add/del IPv6 SR local-SID.
2877
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002878 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002879 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2880 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002881 :param nh_addr4:
2882 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002883 :param is_del: (Default value = 0)
2884 :param end_psp: (Default value = 0)
2885 :param sw_if_index: (Default value = 0xFFFFFFFF)
2886 :param vlan_index: (Default value = 0)
2887 :param fib_table: (Default value = 0)
2888 """
2889 return self.api(
2890 self.papi.sr_localsid_add_del,
2891 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002892 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002893 'end_psp': end_psp,
2894 'behavior': behavior,
2895 'sw_if_index': sw_if_index,
2896 'vlan_index': vlan_index,
2897 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002898 'nh_addr4': nh_addr4,
2899 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002900 }
2901 )
2902
2903 def sr_policy_add(
2904 self,
2905 bsid_addr,
2906 weight=1,
2907 is_encap=1,
2908 type=0,
2909 fib_table=0,
2910 n_segments=0,
2911 segments=[]):
2912 """
2913 :param bsid_addr: bindingSID of the SR Policy
2914 :param weight: weight of the sid list. optional. (default: 1)
2915 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2916 (default: Encap)
2917 :param type: type/behavior of the SR policy. (default or spray) \
2918 (default: default)
2919 :param fib_table: VRF where to install the FIB entry for the BSID \
2920 (default: 0)
2921 :param n_segments: number of segments \
2922 (default: 0)
2923 :param segments: a vector of IPv6 address composing the segment list \
2924 (default: [])
2925 """
2926 return self.api(
2927 self.papi.sr_policy_add,
2928 {'bsid_addr': bsid_addr,
2929 'weight': weight,
2930 'is_encap': is_encap,
2931 'type': type,
2932 'fib_table': fib_table,
2933 'n_segments': n_segments,
2934 'segments': segments
2935 }
2936 )
2937
2938 def sr_policy_del(
2939 self,
2940 bsid_addr,
2941 sr_policy_index=0):
2942 """
2943 :param bsid: bindingSID of the SR Policy
2944 :param sr_policy_index: index of the sr policy (default: 0)
2945 """
2946 return self.api(
2947 self.papi.sr_policy_del,
2948 {'bsid_addr': bsid_addr,
2949 'sr_policy_index': sr_policy_index
2950 })
2951
2952 def sr_steering_add_del(
2953 self,
2954 is_del,
2955 bsid_addr,
2956 sr_policy_index,
2957 table_id,
2958 prefix_addr,
2959 mask_width,
2960 sw_if_index,
2961 traffic_type):
2962 """
2963 Steer traffic L2 and L3 traffic through a given SR policy
2964
2965 :param is_del: delete or add
2966 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2967 :param sr_policy: is the index of the SR Policy (alt to bsid)
2968 :param table_id: is the VRF where to install the FIB entry for the BSID
2969 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2970 :param mask_width: is the mask for L3 traffic type
2971 :param sw_if_index: is the incoming interface for L2 traffic
2972 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2973 """
2974 return self.api(
2975 self.papi.sr_steering_add_del,
2976 {'is_del': is_del,
2977 'bsid_addr': bsid_addr,
2978 'sr_policy_index': sr_policy_index,
2979 'table_id': table_id,
2980 'prefix_addr': prefix_addr,
2981 'mask_width': mask_width,
2982 'sw_if_index': sw_if_index,
2983 'traffic_type': traffic_type
2984 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002985
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002986 def acl_add_replace(self, acl_index, r, tag='',
2987 expected_retval=0):
2988 """Add/replace an ACL
2989 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2990 :param acl_rule r: ACL rules array.
2991 :param str tag: symbolic tag (description) for this ACL.
2992 :param int count: number of rules.
2993 """
2994 return self.api(self.papi.acl_add_replace,
2995 {'acl_index': acl_index,
2996 'r': r,
2997 'count': len(r),
2998 'tag': tag},
2999 expected_retval=expected_retval)
3000
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02003001 def acl_del(self, acl_index, expected_retval=0):
3002 """
3003
3004 :param acl_index:
3005 :return:
3006 """
3007 return self.api(self.papi.acl_del,
3008 {'acl_index': acl_index},
3009 expected_retval=expected_retval)
3010
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003011 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
3012 expected_retval=0):
3013 return self.api(self.papi.acl_interface_set_acl_list,
3014 {'sw_if_index': sw_if_index,
3015 'count': len(acls),
3016 'n_input': n_input,
3017 'acls': acls},
3018 expected_retval=expected_retval)
3019
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003020 def acl_interface_set_etype_whitelist(self, sw_if_index,
3021 n_input, whitelist,
3022 expected_retval=0):
3023 return self.api(self.papi.acl_interface_set_etype_whitelist,
3024 {'sw_if_index': sw_if_index,
3025 'count': len(whitelist),
3026 'n_input': n_input,
3027 'whitelist': whitelist},
3028 expected_retval=expected_retval)
3029
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003030 def acl_interface_add_del(self,
3031 sw_if_index,
3032 acl_index,
3033 is_add=1):
3034 """ Add/Delete ACL to/from interface
3035
3036 :param sw_if_index:
3037 :param acl_index:
3038 :param is_add: (Default value = 1)
3039 """
3040
3041 return self.api(self.papi.acl_interface_add_del,
3042 {'is_add': is_add,
3043 'is_input': 1,
3044 'sw_if_index': sw_if_index,
3045 'acl_index': acl_index})
3046
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003047 def acl_dump(self, acl_index, expected_retval=0):
3048 return self.api(self.papi.acl_dump,
3049 {'acl_index': acl_index},
3050 expected_retval=expected_retval)
3051
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003052 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3053 expected_retval=0):
3054 return self.api(self.papi.acl_interface_list_dump,
3055 {'sw_if_index': sw_if_index},
3056 expected_retval=expected_retval)
3057
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003058 def macip_acl_add(self, rules, tag=""):
3059 """ Add MACIP acl
3060
3061 :param rules: list of rules for given acl
3062 :param tag: acl tag
3063 """
3064
3065 return self.api(self.papi.macip_acl_add,
3066 {'r': rules,
3067 'count': len(rules),
3068 'tag': tag})
3069
Pavel Kotucek932f7412017-09-07 14:44:52 +02003070 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3071 """ Add MACIP acl
3072
3073 :param rules: list of rules for given acl
3074 :param tag: acl tag
3075 """
3076
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003077 return self.api(self.papi.macip_acl_add_replace,
3078 {'acl_index': acl_index,
3079 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003080 'count': len(rules),
3081 'tag': tag})
3082
3083 def macip_acl_del(self, acl_index):
3084 """
3085
3086 :param acl_index:
3087 :return:
3088 """
3089 return self.api(self.papi.macip_acl_del,
3090 {'acl_index': acl_index})
3091
3092 def macip_acl_interface_add_del(self,
3093 sw_if_index,
3094 acl_index,
3095 is_add=1):
3096 """ Add MACIP acl to interface
3097
3098 :param sw_if_index:
3099 :param acl_index:
3100 :param is_add: (Default value = 1)
3101 """
3102
3103 return self.api(self.papi.macip_acl_interface_add_del,
3104 {'is_add': is_add,
3105 'sw_if_index': sw_if_index,
3106 'acl_index': acl_index})
3107
3108 def macip_acl_interface_get(self):
3109 """ Return interface acls dump
3110 """
3111 return self.api(
3112 self.papi.macip_acl_interface_get, {})
3113
3114 def macip_acl_dump(self, acl_index=4294967295):
3115 """ Return MACIP acl dump
3116 """
3117
3118 return self.api(
3119 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003120
3121 def policer_add_del(self,
3122 name,
3123 cir,
3124 eir,
3125 cb,
3126 eb,
3127 is_add=1,
3128 rate_type=0,
3129 round_type=0,
3130 ptype=0,
3131 color_aware=0,
3132 conform_action_type=1,
3133 conform_dscp=0,
3134 exceed_action_type=0,
3135 exceed_dscp=0,
3136 violate_action_type=0,
3137 violate_dscp=0):
3138 return self.api(self.papi.policer_add_del,
3139 {'name': name,
3140 'cir': cir,
3141 'eir': eir,
3142 'cb': cb,
3143 'eb': eb,
3144 'is_add': is_add,
3145 'rate_type': rate_type,
3146 'round_type': round_type,
3147 'type': ptype,
3148 'color_aware': color_aware,
3149 'conform_action_type': conform_action_type,
3150 'conform_dscp': conform_dscp,
3151 'exceed_action_type': exceed_action_type,
3152 'exceed_dscp': exceed_dscp,
3153 'violate_action_type': violate_action_type,
3154 'violate_dscp': violate_dscp})
3155
3156 def ip_punt_police(self,
3157 policer_index,
3158 is_ip6=0,
3159 is_add=1):
3160 return self.api(self.papi.ip_punt_police,
3161 {'policer_index': policer_index,
3162 'is_add': is_add,
3163 'is_ip6': is_ip6})
3164
3165 def ip_punt_redirect(self,
3166 rx_sw_if_index,
3167 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003168 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07003169 is_add=1):
3170 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01003171 {'punt': {'rx_sw_if_index': rx_sw_if_index,
3172 'tx_sw_if_index': tx_sw_if_index,
3173 'nh': address},
3174 'is_add': is_add})
3175
3176 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
3177 return self.api(self.papi.ip_punt_redirect_dump,
3178 {'sw_if_index': sw_if_index,
3179 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003180
3181 def bier_table_add_del(self,
3182 bti,
3183 mpls_label,
3184 is_add=1):
3185 """ BIER Table add/del """
3186 return self.api(
3187 self.papi.bier_table_add_del,
3188 {'bt_tbl_id': {"bt_set": bti.set_id,
3189 "bt_sub_domain": bti.sub_domain_id,
3190 "bt_hdr_len_id": bti.hdr_len_id},
3191 'bt_label': mpls_label,
3192 'bt_is_add': is_add})
3193
3194 def bier_table_dump(self):
3195 return self.api(self.papi.bier_table_dump, {})
3196
3197 def bier_route_add_del(self,
3198 bti,
3199 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003200 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003201 is_add=1,
3202 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003203 """ BIER Route add/del """
3204 return self.api(
3205 self.papi.bier_route_add_del,
3206 {'br_tbl_id': {"bt_set": bti.set_id,
3207 "bt_sub_domain": bti.sub_domain_id,
3208 "bt_hdr_len_id": bti.hdr_len_id},
3209 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003210 'br_n_paths': len(paths),
3211 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003212 'br_is_add': is_add,
3213 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003214
3215 def bier_route_dump(self, bti):
3216 return self.api(
3217 self.papi.bier_route_dump,
3218 {'br_tbl_id': {"bt_set": bti.set_id,
3219 "bt_sub_domain": bti.sub_domain_id,
3220 "bt_hdr_len_id": bti.hdr_len_id}})
3221
3222 def bier_imp_add(self,
3223 bti,
3224 src,
3225 ibytes,
3226 is_add=1):
3227 """ BIER Imposition Add """
3228 return self.api(
3229 self.papi.bier_imp_add,
3230 {'bi_tbl_id': {"bt_set": bti.set_id,
3231 "bt_sub_domain": bti.sub_domain_id,
3232 "bt_hdr_len_id": bti.hdr_len_id},
3233 'bi_src': src,
3234 'bi_n_bytes': len(ibytes),
3235 'bi_bytes': ibytes})
3236
3237 def bier_imp_del(self, bi_index):
3238 """ BIER Imposition del """
3239 return self.api(
3240 self.papi.bier_imp_del,
3241 {'bi_index': bi_index})
3242
3243 def bier_imp_dump(self):
3244 return self.api(self.papi.bier_imp_dump, {})
3245
3246 def bier_disp_table_add_del(self,
3247 bdti,
3248 is_add=1):
3249 """ BIER Disposition Table add/del """
3250 return self.api(
3251 self.papi.bier_disp_table_add_del,
3252 {'bdt_tbl_id': bdti,
3253 'bdt_is_add': is_add})
3254
3255 def bier_disp_table_dump(self):
3256 return self.api(self.papi.bier_disp_table_dump, {})
3257
3258 def bier_disp_entry_add_del(self,
3259 bdti,
3260 bp,
3261 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003262 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003263 next_hop,
3264 next_hop_tbl_id=0,
3265 next_hop_rpf_id=~0,
3266 next_hop_is_ip4=1,
3267 is_add=1):
3268 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003269 lstack = []
3270 while (len(lstack) < 16):
3271 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003272 return self.api(
3273 self.papi.bier_disp_entry_add_del,
3274 {'bde_tbl_id': bdti,
3275 'bde_bp': bp,
3276 'bde_payload_proto': payload_proto,
3277 'bde_n_paths': 1,
3278 'bde_paths': [{'next_hop': next_hop,
3279 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003280 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003281 'rpf_id': next_hop_rpf_id,
3282 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003283 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003284 'bde_is_add': is_add})
3285
3286 def bier_disp_entry_dump(self, bdti):
3287 return self.api(
3288 self.papi.bier_disp_entry_dump,
3289 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003290
3291 def add_node_next(self, node_name, next_name):
3292 """ Set the next node for a given node request
3293
3294 :param node_name:
3295 :param next_name:
3296 """
3297 return self.api(self.papi.add_node_next,
3298 {'node_name': node_name,
3299 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003300
3301 def session_enable_disable(self, is_enabled):
3302 return self.api(
3303 self.papi.session_enable_disable,
3304 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003305
3306 def ipsec_spd_add_del(self, spd_id, is_add=1):
3307 """ SPD add/del - Wrapper to add or del ipsec SPD
3308 Sample CLI : 'ipsec spd add 1'
3309
3310 :param spd_id - SPD ID to be created in the vpp . mandatory
3311 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3312 optional
3313 :returns: reply from the API
3314 """
3315 return self.api(
3316 self.papi.ipsec_spd_add_del, {
3317 'spd_id': spd_id, 'is_add': is_add})
3318
3319 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3320 """ IPSEC interface SPD add/del - \
3321 Wrapper to associate/disassociate SPD to interface in VPP
3322 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3323
3324 :param spd_id - SPD ID to associate with the interface . mandatory
3325 :param sw_if_index - Interface Index which needs to ipsec \
3326 association mandatory
3327 :param is_add - add(1) or del(0) association with interface \
3328 (Default 1 - add) . optional
3329 :returns: reply from the API
3330 """
3331 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003332 self.papi.ipsec_interface_add_del_spd,
3333 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003334
3335 def ipsec_sad_add_del_entry(self,
3336 sad_id,
3337 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003338 integrity_algorithm,
3339 integrity_key,
3340 crypto_algorithm,
3341 crypto_key,
3342 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003343 tunnel_src_address='',
3344 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003345 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003346 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003347 is_add=1,
Neale Rannsde847272018-11-28 01:38:34 -08003348 udp_encap=0,
3349 use_anti_replay=0,
3350 use_extended_sequence_number=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003351 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003352 :param sad_id: security association ID
3353 :param spi: security param index of the SA in decimal
3354 :param integrity_algorithm:
3355 :param integrity_key:
3356 :param crypto_algorithm:
3357 :param crypto_key:
3358 :param protocol: AH(0) or ESP(1) protocol
3359 :param tunnel_src_address: tunnel mode outer src address
3360 :param tunnel_dst_address: tunnel mode outer dst address
3361 :param is_add:
3362 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003363 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3364 crypto and ipsec algorithms
3365 """
3366 return self.api(
3367 self.papi.ipsec_sad_add_del_entry,
3368 {'sad_id': sad_id,
3369 'spi': spi,
3370 'tunnel_src_address': tunnel_src_address,
3371 'tunnel_dst_address': tunnel_dst_address,
3372 'protocol': protocol,
3373 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003374 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003375 'integrity_key': integrity_key,
3376 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003377 'crypto_key_length': len(crypto_key) if crypto_key is not None
3378 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003379 'crypto_key': crypto_key,
3380 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003381 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003382 'is_tunnel_ipv6': is_tunnel_ipv6,
Neale Rannsde847272018-11-28 01:38:34 -08003383 'udp_encap': udp_encap,
3384 'use_extended_sequence_number': use_extended_sequence_number,
3385 'use_anti_replay': use_anti_replay})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003386
3387 def ipsec_spd_add_del_entry(self,
3388 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003389 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003390 local_address_start,
3391 local_address_stop,
3392 remote_address_start,
3393 remote_address_stop,
3394 local_port_start=0,
3395 local_port_stop=65535,
3396 remote_port_start=0,
3397 remote_port_stop=65535,
3398 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003399 policy=0,
3400 priority=100,
3401 is_outbound=1,
3402 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003403 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003404 is_ip_any=0):
3405 """ IPSEC policy SPD add/del -
3406 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003407 :param spd_id: SPD ID for the policy
3408 :param local_address_start: local-ip-range start address
3409 :param local_address_stop : local-ip-range stop address
3410 :param remote_address_start: remote-ip-range start address
3411 :param remote_address_stop : remote-ip-range stop address
3412 :param local_port_start: (Default value = 0)
3413 :param local_port_stop: (Default value = 65535)
3414 :param remote_port_start: (Default value = 0)
3415 :param remote_port_stop: (Default value = 65535)
3416 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3417 :param sa_id: Security Association ID for mapping it to SPD
3418 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3419 (Default value = 0)
3420 :param priority: value for the spd action (Default value = 100)
3421 :param is_outbound: flag for inbound(0) or outbound(1)
3422 (Default value = 1)
3423 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003424 """
3425 return self.api(
3426 self.papi.ipsec_spd_add_del_entry,
3427 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003428 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003429 'local_address_start': local_address_start,
3430 'local_address_stop': local_address_stop,
3431 'remote_address_start': remote_address_start,
3432 'remote_address_stop': remote_address_stop,
3433 'local_port_start': local_port_start,
3434 'local_port_stop': local_port_stop,
3435 'remote_port_start': remote_port_start,
3436 'remote_port_stop': remote_port_stop,
3437 'is_add': is_add,
3438 'protocol': protocol,
3439 'policy': policy,
3440 'priority': priority,
3441 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003442 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003443 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003444
Klement Sekera31da2e32018-06-24 22:49:55 +02003445 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3446 remote_spi, crypto_alg, local_crypto_key,
3447 remote_crypto_key, integ_alg, local_integ_key,
3448 remote_integ_key, is_add=1, esn=0,
3449 anti_replay=1, renumber=0, show_instance=0):
3450 return self.api(
3451 self.papi.ipsec_tunnel_if_add_del,
3452 {'local_ip': local_ip, 'remote_ip': remote_ip,
3453 'local_spi': local_spi, 'remote_spi': remote_spi,
3454 'crypto_alg': crypto_alg,
3455 'local_crypto_key_len': len(local_crypto_key),
3456 'local_crypto_key': local_crypto_key,
3457 'remote_crypto_key_len': len(remote_crypto_key),
3458 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3459 'local_integ_key_len': len(local_integ_key),
3460 'local_integ_key': local_integ_key,
3461 'remote_integ_key_len': len(remote_integ_key),
3462 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3463 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3464 'show_instance': show_instance
3465 })
3466
Klement Sekerab4d30532018-11-08 13:00:02 +01003467 def ipsec_select_backend(self, protocol, index):
3468 return self.api(self.papi.ipsec_select_backend,
3469 {'protocol': protocol, 'index': index})
3470
3471 def ipsec_backend_dump(self):
3472 return self.api(self.papi.ipsec_backend_dump, {})
3473
Florin Corasb795bd02017-12-14 11:30:48 -08003474 def app_namespace_add(self,
3475 namespace_id,
3476 ip4_fib_id=0,
3477 ip6_fib_id=0,
3478 sw_if_index=0xFFFFFFFF,
3479 secret=0):
3480 return self.api(
3481 self.papi.app_namespace_add_del,
3482 {'secret': secret,
3483 'sw_if_index': sw_if_index,
3484 'ip4_fib_id': ip4_fib_id,
3485 'ip6_fib_id': ip6_fib_id,
3486 'namespace_id': namespace_id,
3487 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003488
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003489 def punt_socket_register(self, port, pathname, protocol=0x11,
3490 header_version=1, is_ip4=1):
3491 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02003492 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01003493 {'header_version': header_version,
3494 'punt': {'ipv': is_ip4,
3495 'l4_protocol': protocol,
3496 'l4_port': port},
3497 'pathname': pathname})
3498
3499 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
3500 """ Unregister punt socket """
3501 return self.api(self.papi.punt_socket_deregister,
3502 {'punt': {'ipv': is_ip4,
3503 'l4_protocol': protocol,
3504 'l4_port': port}})
3505
3506 def punt_socket_dump(self, is_ip6=1):
3507 """ Dump punt socket"""
3508 return self.api(self.papi.punt_socket_dump,
3509 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02003510
3511 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3512 expire_walk_interval_ms, is_ip6=0):
3513 """ Set IP reassembly parameters """
3514 return self.api(self.papi.ip_reassembly_set,
3515 {'is_ip6': is_ip6,
3516 'timeout_ms': timeout_ms,
3517 'expire_walk_interval_ms': expire_walk_interval_ms,
3518 'max_reassemblies': max_reassemblies})
3519
3520 def ip_reassembly_get(self, is_ip6=0):
3521 """ Get IP reassembly parameters """
3522 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003523
Klement Sekera4c533132018-02-22 11:41:12 +01003524 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3525 enable_ip6=False):
3526 """ Enable/disable IP reassembly """
3527 return self.api(self.papi.ip_reassembly_enable_disable,
3528 {'sw_if_index': sw_if_index,
3529 'enable_ip4': 1 if enable_ip4 else 0,
3530 'enable_ip6': 1 if enable_ip6 else 0,
3531 })
3532
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003533 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3534 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003535 """ GBP endpoint Add """
3536 return self.api(self.papi.gbp_endpoint_add,
3537 {'endpoint': {
3538 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003539 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003540 'ips': ips,
3541 'n_ips': len(ips),
3542 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003543 'epg_id': epg,
3544 'flags': flags,
3545 'tun': {
3546 'src': tun_src,
3547 'dst': tun_dst,
3548 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003549
3550 def gbp_endpoint_del(self, handle):
3551 """ GBP endpoint Del """
3552 return self.api(self.papi.gbp_endpoint_del,
3553 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003554
3555 def gbp_endpoint_dump(self):
3556 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003557 return self.api(self.papi.gbp_endpoint_dump,
3558 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003559
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003560 def gbp_endpoint_group_add(self, epg, bd,
3561 rd, uplink_sw_if_index):
3562 """ GBP endpoint group Add """
3563 return self.api(self.papi.gbp_endpoint_group_add,
3564 {'epg':
3565 {
Neale Ranns25b04942018-04-04 09:34:50 -07003566 'uplink_sw_if_index': uplink_sw_if_index,
3567 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003568 'rd_id': rd,
3569 'epg_id': epg
3570 }})
3571
3572 def gbp_endpoint_group_del(self, epg):
3573 """ GBP endpoint group Del """
3574 return self.api(self.papi.gbp_endpoint_group_del,
3575 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003576
3577 def gbp_endpoint_group_dump(self):
3578 """ GBP endpoint group Dump """
3579 return self.api(self.papi.gbp_endpoint_group_dump, {})
3580
Neale Rannsc29c0af2018-11-07 04:21:12 -08003581 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003582 bvi_sw_if_index,
3583 uu_fwd_sw_if_index):
3584 """ GBP bridge-domain Add """
3585 return self.api(self.papi.gbp_bridge_domain_add,
3586 {'bd':
3587 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003588 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003589 'bvi_sw_if_index': bvi_sw_if_index,
3590 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3591 'bd_id': bd_id
3592 }})
3593
3594 def gbp_bridge_domain_del(self, bd_id):
3595 """ GBP bridge-domain Del """
3596 return self.api(self.papi.gbp_bridge_domain_del,
3597 {'bd_id': bd_id})
3598
3599 def gbp_bridge_domain_dump(self):
3600 """ GBP Bridge Domain Dump """
3601 return self.api(self.papi.gbp_bridge_domain_dump, {})
3602
3603 def gbp_route_domain_add(self, rd_id,
3604 ip4_table_id,
3605 ip6_table_id,
3606 ip4_uu_sw_if_index,
3607 ip6_uu_sw_if_index):
3608 """ GBP route-domain Add """
3609 return self.api(self.papi.gbp_route_domain_add,
3610 {'rd':
3611 {
3612 'ip4_table_id': ip4_table_id,
3613 'ip6_table_id': ip6_table_id,
3614 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3615 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3616 'rd_id': rd_id
3617 }})
3618
3619 def gbp_route_domain_del(self, rd_id):
3620 """ GBP route-domain Del """
3621 return self.api(self.papi.gbp_route_domain_del,
3622 {'rd_id': rd_id})
3623
3624 def gbp_route_domain_dump(self):
3625 """ GBP Route Domain Dump """
3626 return self.api(self.papi.gbp_route_domain_dump, {})
3627
Neale Ranns25b04942018-04-04 09:34:50 -07003628 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3629 """ GBP recirc Add/Del """
3630 return self.api(self.papi.gbp_recirc_add_del,
3631 {'is_add': is_add,
3632 'recirc': {
3633 'is_ext': is_ext,
3634 'sw_if_index': sw_if_index,
3635 'epg_id': epg}})
3636
3637 def gbp_recirc_dump(self):
3638 """ GBP recirc Dump """
3639 return self.api(self.papi.gbp_recirc_dump, {})
3640
Neale Rannsb6a47952018-11-21 05:44:35 -08003641 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
3642 """ GBP recirc Add/Del """
3643 return self.api(self.papi.gbp_ext_itf_add_del,
3644 {'is_add': is_add,
3645 'ext_itf': {
3646 'sw_if_index': sw_if_index,
3647 'bd_id': bd_id,
3648 'rd_id': rd_id}})
3649
3650 def gbp_ext_itf_dump(self):
3651 """ GBP recirc Dump """
3652 return self.api(self.papi.gbp_ext_itf_dump, {})
3653
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003654 def gbp_subnet_add_del(self, is_add, rd_id,
3655 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003656 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003657 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003658 """ GBP Subnet Add/Del """
3659 return self.api(self.papi.gbp_subnet_add_del,
3660 {'is_add': is_add,
3661 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003662 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003663 'sw_if_index': sw_if_index,
3664 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003665 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003666 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003667
3668 def gbp_subnet_dump(self):
3669 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01003670 return self.api(self.papi.gbp_subnet_dump,
3671 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07003672
Neale Ranns13a08cc2018-11-07 09:25:54 -08003673 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003674 """ GBP contract Add/Del """
3675 return self.api(self.papi.gbp_contract_add_del,
3676 {'is_add': is_add,
3677 'contract': {
3678 'acl_index': acl_index,
3679 'src_epg': src_epg,
Neale Ranns13a08cc2018-11-07 09:25:54 -08003680 'dst_epg': dst_epg,
3681 'n_rules': len(rules),
3682 'rules': rules}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003683
3684 def gbp_contract_dump(self):
3685 """ GBP contract Dump """
3686 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003687
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003688 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3689 """ GBP set inactive threshold """
3690 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3691 {'threshold': threshold})
3692
3693 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3694 """ GBP VXLAN tunnel add """
3695 return self.api(self.papi.gbp_vxlan_tunnel_add,
3696 {
3697 'tunnel': {
3698 'vni': vni,
3699 'mode': mode,
3700 'bd_rd_id': bd_rd_id
3701 }
3702 })
3703
3704 def gbp_vxlan_tunnel_del(self, vni):
3705 """ GBP VXLAN tunnel del """
3706 return self.api(self.papi.gbp_vxlan_tunnel_del,
3707 {
3708 'vni': vni,
3709 })
3710
3711 def gbp_vxlan_tunnel_dump(self):
3712 """ GBP VXLAN tunnel add/del """
3713 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3714
Neale Ranns61502112018-08-22 00:21:14 -07003715 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3716 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003717 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003718 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003719 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003720 {'ip4_table_id': ip4_table_id,
3721 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003722 'ip6_prefix': ip6_prefix,
3723 'ip6_prefix_len': ip6_prefix_len,
3724 'ip4_prefix': ip4_prefix,
3725 'ip4_prefix_len': ip4_prefix_len,
3726 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003727 'security_check': security_check})
3728
Ole Troan298c6952018-03-08 12:30:43 +01003729 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003730 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003731 return self.api(self.papi.ipip_6rd_del_tunnel,
3732 {'sw_if_index': sw_if_index})
3733
3734 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003735 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003736 """ IPIP tunnel Add/Del """
3737 return self.api(self.papi.ipip_add_tunnel,
3738 {'is_ipv6': is_ipv6,
3739 'instance': instance,
3740 'src_address': src_address,
3741 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003742 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003743 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003744
3745 def ipip_del_tunnel(self, sw_if_index):
3746 """ IPIP tunnel Delete """
3747 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003748 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003749
3750 def qos_egress_map_update(self, id, outputs):
3751 """ QOS egress map update """
3752 return self.api(self.papi.qos_egress_map_update,
3753 {'map_id': id,
3754 'rows': outputs})
3755
3756 def qos_egress_map_delete(self, id):
3757 """ QOS egress map delete """
3758 return self.api(self.papi.qos_egress_map_delete,
3759 {'map_id': id})
3760
3761 def qos_mark_enable_disable(self, sw_if_index,
3762 output_source,
3763 map_id,
3764 enable):
3765 """ QOS Mark Enable/Disable """
3766 return self.api(self.papi.qos_mark_enable_disable,
3767 {'map_id': map_id,
3768 'sw_if_index': sw_if_index,
3769 'output_source': output_source,
3770 'enable': enable})
3771
3772 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3773 """ IP QoS recording Enble/Disable """
3774 return self.api(self.papi.qos_record_enable_disable,
3775 {'sw_if_index': sw_if_index,
3776 'input_source': input_source,
3777 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003778
Neale Ranns947ea622018-06-07 23:48:20 -07003779 def igmp_enable_disable(self, sw_if_index, enable, host):
3780 """ Enable/disable IGMP on a given interface """
3781 return self.api(self.papi.igmp_enable_disable,
3782 {'enable': enable,
3783 'mode': host,
3784 'sw_if_index': sw_if_index})
3785
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003786 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3787 """ Add/del IGMP proxy device """
3788 return self.api(self.papi.igmp_proxy_device_add_del,
3789 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3790 'add': add})
3791
3792 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3793 """ Add/del interface to/from IGMP proxy device """
3794 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3795 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3796 'add': add})
3797
Neale Ranns947ea622018-06-07 23:48:20 -07003798 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003799 """ Listen for new (S,G) on specified interface
3800
3801 :param enable: add/del
3802 :param sw_if_index: interface sw index
3803 :param saddr: source ip4 addr
3804 :param gaddr: group ip4 addr
3805 """
3806 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003807 {
3808 'group':
3809 {
3810 'filter': filter,
3811 'sw_if_index': sw_if_index,
3812 'n_srcs': len(saddrs),
3813 'saddrs': saddrs,
Ole Troan8c8acc02018-11-27 10:05:23 +01003814 'gaddr': gaddr
Neale Ranns947ea622018-06-07 23:48:20 -07003815 }
3816 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003817
3818 def igmp_dump(self, sw_if_index=None):
3819 """ Dump all (S,G) interface configurations """
3820 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003821 sw_if_index = 0xffffffff
3822 return self.api(self.papi.igmp_dump,
3823 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003824
3825 def igmp_clear_interface(self, sw_if_index):
3826 """ Remove all (S,G)s from specified interface
3827 doesn't send IGMP report!
3828 """
3829 return self.api(
3830 self.papi.igmp_clear_interface, {
3831 'sw_if_index': sw_if_index})
3832
3833 def want_igmp_events(self, enable=1):
3834 return self.api(self.papi.want_igmp_events, {'enable': enable,
3835 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003836
3837 def bond_create(
3838 self,
3839 mode,
3840 lb,
3841 use_custom_mac,
3842 mac_address=''):
3843 """
3844 :param mode: mode
3845 :param lb: load balance
3846 :param use_custom_mac: use custom mac
3847 :param mac_address: mac address
3848 """
3849 return self.api(
3850 self.papi.bond_create,
3851 {'mode': mode,
3852 'lb': lb,
3853 'use_custom_mac': use_custom_mac,
3854 'mac_address': mac_address
3855 })
3856
3857 def bond_delete(
3858 self,
3859 sw_if_index):
3860 """
3861 :param sw_if_index: interface the operation is applied to
3862 """
3863 return self.api(self.papi.bond_delete,
3864 {'sw_if_index': sw_if_index})
3865
3866 def bond_enslave(
3867 self,
3868 sw_if_index,
3869 bond_sw_if_index,
3870 is_passive,
3871 is_long_timeout):
3872 """
3873 :param sw_if_index: slave sw_if_index
3874 :param bond_sw_if_index: bond sw_if_index
3875 :param is_passive: is passive lacp speaker
3876 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3877 """
3878 return self.api(
3879 self.papi.bond_enslave,
3880 {'sw_if_index': sw_if_index,
3881 'bond_sw_if_index': bond_sw_if_index,
3882 'is_passive': is_passive,
3883 'is_long_timeout': is_long_timeout
3884 })
3885
3886 def bond_detach_slave(
3887 self,
3888 sw_if_index):
3889 """
3890 :param sw_if_index: slave interface the operation is applied to
3891 """
3892 return self.api(self.papi.bond_detach_slave,
3893 {'sw_if_index': sw_if_index})
3894
3895 def sw_interface_slave_dump(
3896 self,
3897 sw_if_index):
3898 """
3899 :param sw_if_index: bond sw_if_index
3900 """
3901 return self.api(self.papi.sw_interface_slave_dump,
3902 {'sw_if_index': sw_if_index})
3903
3904 def sw_interface_bond_dump(
3905 self):
3906 """
3907
3908 """
3909 return self.api(self.papi.sw_interface_bond_dump,
3910 {})
Stevene8fa6202017-08-30 14:36:45 -07003911
3912 def create_vhost_user_if(
3913 self,
3914 is_server,
3915 sock_filename,
3916 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003917 disable_mrg_rxbuf,
3918 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003919 custom_dev_instance,
3920 use_custom_mac,
3921 mac_address,
3922 tag=''):
3923 """
3924 :param is_server: is server
3925 :param sock_filename: socket name
3926 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003927 :param disable_mrg_rxbuf: disable mergable rx buffers
3928 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003929 :param custom_dev_instance: custom dev instance
3930 :param use_custom_mac: use custom mac
3931 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003932 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003933 """
3934 return self.api(
3935 self.papi.create_vhost_user_if,
3936 {'is_server': is_server,
3937 'sock_filename': sock_filename,
3938 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003939 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3940 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003941 'custom_dev_instance': custom_dev_instance,
3942 'use_custom_mac': use_custom_mac,
3943 'mac_address': mac_address,
3944 'tag': tag
3945 })
3946
3947 def delete_vhost_user_if(
3948 self,
3949 sw_if_index):
3950 """
3951 :param sw_if_index: interface the operation is applied to
3952 """
3953 return self.api(self.papi.delete_vhost_user_if,
3954 {'sw_if_index': sw_if_index, })
3955
3956 def sw_interface_vhost_user_dump(
3957 self):
3958 """
3959
3960 """
3961 return self.api(self.papi.sw_interface_vhost_user_dump,
3962 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003963
3964 def abf_policy_add_del(self, is_add, policy):
3965 return self.api(
3966 self.papi.abf_policy_add_del,
3967 {'is_add': is_add,
3968 'policy': policy})
3969
3970 def abf_itf_attach_add_del(self, is_add, attach):
3971 return self.api(
3972 self.papi.abf_itf_attach_add_del,
3973 {'is_add': is_add,
3974 'attach': attach})
3975
3976 def abf_policy_dump(self):
3977 return self.api(
3978 self.papi.abf_policy_dump, {})
3979
3980 def abf_itf_attach_dump(self):
3981 return self.api(
3982 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003983
3984 def pipe_create(self, is_specified, user_instance):
3985 return self.api(self.papi.pipe_create,
3986 {'is_specified': is_specified,
3987 'user_instance': user_instance})
3988
3989 def pipe_delete(self, parent_sw_if_index):
3990 return self.api(self.papi.pipe_delete,
3991 {'parent_sw_if_index': parent_sw_if_index})
3992
3993 def pipe_dump(self):
3994 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003995
3996 def memif_create(
3997 self,
3998 role,
3999 mode,
4000 rx_queues=None,
4001 tx_queues=None,
4002 _id=None,
4003 socket_id=None,
4004 secret=None,
4005 ring_size=None,
4006 buffer_size=None,
4007 hw_addr=None):
4008 return self.api(self.papi.memif_create,
4009 {'role': role,
4010 'mode': mode,
4011 'rx_queues': rx_queues,
4012 'tx_queues': tx_queues,
4013 'id': _id,
4014 'socket_id': socket_id,
4015 'secret': secret,
4016 'ring_size': ring_size,
4017 'buffer_size': buffer_size,
4018 'hw_addr': hw_addr})
4019
4020 def memif_delete(self, sw_if_index):
4021 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
4022
4023 def memif_dump(self):
4024 return self.api(self.papi.memif_dump, {})
4025
4026 def memif_socket_filename_add_del(
4027 self, is_add, socket_id, socket_filename):
4028 return self.api(
4029 self.papi.memif_socket_filename_add_del,
4030 {'is_add': is_add,
4031 'socket_id': socket_id,
4032 'socket_filename': socket_filename})
4033
4034 def memif_socket_filename_dump(self):
4035 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07004036
4037 def svs_table_add_del(self, af, table_id, is_add=1):
4038 return self.api(self.papi.svs_table_add_del,
4039 {
4040 'table_id': table_id,
4041 'is_add': is_add,
4042 'af': af,
4043 })
4044
4045 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
4046 return self.api(self.papi.svs_route_add_del,
4047 {
4048 'table_id': table_id,
4049 'source_table_id': src_table_id,
4050 'prefix': prefix,
4051 'is_add': is_add,
4052 })
4053
4054 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4055 return self.api(self.papi.svs_enable_disable,
4056 {
4057 'af': af,
4058 'table_id': table_id,
4059 'sw_if_index': sw_if_index,
4060 'is_enable': is_enable,
4061 })
4062
4063 def svs_dump(self):
4064 return self.api(self.papi.svs_dump, {})
Matus Fabianb4515b42018-11-19 04:25:32 -08004065
4066 def syslog_set_sender(
4067 self,
4068 collector,
4069 src,
4070 collector_port=514,
4071 vrf_id=0,
4072 max_msg_size=480):
4073 """Set syslog sender configuration
4074
4075 :param collector: colector IP address
4076 :param src: source IP address
4077 :param collector_port: collector UDP port (Default value = 514)
4078 :param vrf_id: VRF id (Default value = 0)
4079 :param max_msg_size: maximum message length (Default value = 480)
4080 """
4081 return self.api(self.papi.syslog_set_sender,
Ole Troan8c8acc02018-11-27 10:05:23 +01004082 {'collector_address': collector,
4083 'src_address': src,
Matus Fabianb4515b42018-11-19 04:25:32 -08004084 'collector_port': collector_port,
4085 'vrf_id': vrf_id,
4086 'max_msg_size': max_msg_size})
4087
4088 def syslog_get_sender(self):
4089 """Return syslog sender configuration"""
4090 return self.api(self.papi.syslog_get_sender, {})
4091
4092 def syslog_set_filter(self, severity):
4093 """Set syslog filter parameters
4094
4095 :param severity: severity filter (specified severity and greater match)
4096 """
4097 return self.api(self.papi.syslog_set_filter, {'severity': severity})
4098
4099 def syslog_get_filter(self):
4100 """Return syslog filter parameters"""
4101 return self.api(self.papi.syslog_get_filter, {})