blob: 9f7968bbbb791a800258b067b64ee15bb71a7f50 [file] [log] [blame]
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001import os
2import fnmatch
3import time
Klement Sekeraf62ae122016-10-11 11:47:09 +02004from hook import Hook
Klement Sekerae4504c62016-12-08 10:16:41 +01005from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +02006
Klement Sekera0e3c0de2016-09-29 14:43:44 +02007# Sphinx creates auto-generated documentation by importing the python source
Klement Sekerada505f62017-01-04 12:58:53 +01008# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
9# the vpp_papi_provider.py file to be importable without having to build
10# the whole vpp api if the user only wishes to generate the test documentation.
Klement Sekera277b89c2016-10-28 13:20:27 +020011do_import = True
12try:
13 no_vpp_papi = os.getenv("NO_VPP_PAPI")
14 if no_vpp_papi == "1":
15 do_import = False
16except:
17 pass
18
19if do_import:
Ole Troan7e3a8752016-12-05 10:27:09 +010020 from vpp_papi import VPP
Neale Ranns93cc3ee2018-10-10 07:22:51 -070021 from vpp_l2 import L2_PORT_TYPE
Klement Sekera277b89c2016-10-28 13:20:27 +020022
Klement Sekeraf62ae122016-10-11 11:47:09 +020023# from vnet/vnet/mpls/mpls_types.h
24MPLS_IETF_MAX_LABEL = 0xfffff
25MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
26
Klement Sekera0e3c0de2016-09-29 14:43:44 +020027
Neale Ranns177bbdc2016-11-15 09:46:51 +000028class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030029 L2_DISABLED = 0
30 L2_PUSH_1 = 1
31 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000032 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030033 L2_POP_2 = 4
34 L2_TRANSLATE_1_1 = 5
35 L2_TRANSLATE_1_2 = 6
36 L2_TRANSLATE_2_1 = 7
37 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000038
Klement Sekera0e3c0de2016-09-29 14:43:44 +020039
Neale Ranns039cbfe2018-02-27 03:45:38 -080040class QOS_SOURCE:
41 EXT = 0
42 VLAN = 1
43 MPLS = 2
44 IP = 3
45
46
Klement Sekera73884482017-02-23 09:26:30 +010047class UnexpectedApiReturnValueError(Exception):
48 """ exception raised when the API return value is unexpected """
49 pass
50
51
Klement Sekeraf62ae122016-10-11 11:47:09 +020052class VppPapiProvider(object):
53 """VPP-api provider using vpp-papi
54
55 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020056 """
57
Klement Sekerae0545ef2017-01-25 08:00:40 +010058 _zero, _negative = range(2)
59
Klement Sekera611864f2018-09-26 11:19:00 +020060 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020061 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020062 self.name = name
63 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010064 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010065 self._expect_api_retval = self._zero
66 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010067 jsonfiles = []
68
Klement Sekera0e3c0de2016-09-29 14:43:44 +020069 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010070 for root, dirnames, filenames in os.walk(install_dir):
71 for filename in fnmatch.filter(filenames, '*.api.json'):
72 jsonfiles.append(os.path.join(root, filename))
73
Klement Sekera611864f2018-09-26 11:19:00 +020074 self.vpp = VPP(jsonfiles, logger=test_class.logger,
75 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010076 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020077
Klement Sekerae0545ef2017-01-25 08:00:40 +010078 def __enter__(self):
79 return self
80
81 def expect_negative_api_retval(self):
82 """ Expect API failure """
83 self._expect_stack.append(self._expect_api_retval)
84 self._expect_api_retval = self._negative
85 return self
86
87 def expect_zero_api_retval(self):
88 """ Expect API success """
89 self._expect_stack.append(self._expect_api_retval)
90 self._expect_api_retval = self._zero
91 return self
92
93 def __exit__(self, exc_type, exc_value, traceback):
94 self._expect_api_retval = self._expect_stack.pop()
95
Klement Sekeraf62ae122016-10-11 11:47:09 +020096 def register_hook(self, hook):
97 """Replace hook registration with new hook
98
99 :param hook:
100
101 """
102 self.hook = hook
103
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200104 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100105 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200106 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100107 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200108 return e
109
110 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100111 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100112 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100113 self.test_class.logger.debug("Expecting event '%s' within %ss",
114 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300115 else:
116 self.test_class.logger.debug("Expecting event within %ss",
117 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100118 if self._events:
119 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200120 limit = time.time() + timeout
121 while time.time() < limit:
122 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100123 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200124 if name and type(e).__name__ != name:
125 raise Exception(
126 "Unexpected event received: %s, expected: %s" %
127 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100128 self.test_class.logger.debug("Returning event %s:%s" %
129 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 return e
131 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200132 raise Exception("Event did not occur within timeout")
133
134 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100135 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200136 # FIXME use the name instead of relying on type(e).__name__ ?
137 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100138 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200139 self._events.append(event)
140
Klement Sekeraf62ae122016-10-11 11:47:09 +0200141 def connect(self):
142 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100143 self.vpp.connect(self.name, self.shm_prefix)
144 self.papi = self.vpp.api
145 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200146
147 def disconnect(self):
148 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100149 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200150
151 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100152 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200153 Call the appropriate hooks before and after the API call
154
155 :param api_fn: API function to call
156 :param api_args: tuple of API function arguments
157 :param expected_retval: Expected return value (Default value = 0)
158 :returns: reply from the API
159
160 """
161 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100162 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100163 if self._expect_api_retval == self._negative:
164 if hasattr(reply, 'retval') and reply.retval >= 0:
165 msg = "API call passed unexpectedly: expected negative "\
166 "return value instead of %d in %s" % \
167 (reply.retval, repr(reply))
168 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100169 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100170 elif self._expect_api_retval == self._zero:
171 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700172 msg = "API call failed, expected %d return value instead "\
173 "of %d in %s" % (expected_retval, reply.retval,
174 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100176 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100177 else:
178 raise Exception("Internal error, unexpected value for "
179 "self._expect_api_retval %s" %
180 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200181 self.hook.after_api(api_fn.__name__, api_args)
182 return reply
183
184 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100185 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200186
187 :param cli: CLI to execute
188 :returns: CLI output
189
190 """
191 self.hook.before_cli(cli)
192 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100193 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200195 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100196 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200197
Jan49c0fca2016-10-26 15:44:27 +0200198 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100199 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200200
201 :param cli: CLI to execute
202 :returns: CLI output
203 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600204 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200205
Jan4af521d2016-11-15 17:05:00 +0100206 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200207 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100208
Klement Sekeraf62ae122016-10-11 11:47:09 +0200209 def show_version(self):
210 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100211 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212
213 def pg_create_interface(self, pg_index):
214 """
215
216 :param pg_index:
217
218 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100219 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200221
222 def sw_interface_dump(self, filter=None):
223 """
224
225 :param filter: (Default value = None)
226
227 """
228 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200229 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200230 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100231 args = {}
232 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200233
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000234 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100235 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000236
237 :param sw_if_index:
238 :param is_ipv6:
239 :param table_id:
240
241 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100242 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200243 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
244 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000245
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700246 def sw_interface_get_table(self, sw_if_index, is_ipv6):
247 """ Get the IPvX Table-id for the Interface
248
249 :param sw_if_index:
250 :param is_ipv6:
251 :return table_id
252
253 """
254 return self.api(self.papi.sw_interface_get_table,
255 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6})
256
Klement Sekeraf62ae122016-10-11 11:47:09 +0200257 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
258 is_ipv6=0, is_add=1, del_all=0):
259 """
260
261 :param addr: param is_ipv6: (Default value = 0)
262 :param sw_if_index:
263 :param addr_len:
264 :param is_ipv6: (Default value = 0)
265 :param is_add: (Default value = 1)
266 :param del_all: (Default value = 0)
267
268 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100269 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200270 {'sw_if_index': sw_if_index,
271 'is_add': is_add,
272 'is_ipv6': is_ipv6,
273 'del_all': del_all,
274 'address_length': addr_len,
275 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700277 def ip_address_dump(self, sw_if_index, is_ipv6=0):
278 return self.api(self.papi.ip_address_dump,
279 {'sw_if_index': sw_if_index,
280 'is_ipv6': is_ipv6})
281
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800282 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
283 is_add=1):
284 """ Set the Interface to be unnumbered
285
286 :param is_add: (Default value = 1)
287 :param sw_if_index - interface That will be unnumbered
288 :param ip_sw_if_index - interface with an IP addres
289
290 """
291 return self.api(self.papi.sw_interface_set_unnumbered,
292 {'sw_if_index': ip_sw_if_index,
293 'unnumbered_sw_if_index': sw_if_index,
294 'is_add': is_add})
295
Neale Ranns404d88e2018-08-08 06:37:33 -0700296 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
297 return self.api(self.papi.ip_unnumbered_dump,
298 {'sw_if_index': sw_if_index})
299
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000300 def sw_interface_enable_disable_mpls(self, sw_if_index,
301 is_enable=1):
302 """
303 Enable/Disable MPLS on the interface
304 :param sw_if_index:
305 :param is_enable: (Default value = 1)
306
307 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100308 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200309 {'sw_if_index': sw_if_index,
310 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000311
Jan Gelety057bb8c2016-12-20 17:32:45 +0100312 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100313 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100314 {'sw_if_index': sw_if_index,
315 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200316
Neale Ranns227038a2017-04-21 01:07:59 -0700317 def set_ip_flow_hash(self,
318 table_id,
319 src=1,
320 dst=1,
321 sport=1,
322 dport=1,
323 proto=1,
324 reverse=0,
325 is_ip6=0):
326 return self.api(self.papi.set_ip_flow_hash,
327 {'vrf_id': table_id,
328 'src': src,
329 'dst': dst,
330 'dport': dport,
331 'sport': sport,
332 'proto': proto,
333 'reverse': reverse,
334 'is_ipv6': is_ip6})
335
Neale Ranns3f844d02017-02-18 00:03:54 -0800336 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
337 return self.api(self.papi.ip6nd_proxy_add_del,
338 {'address': address,
339 'sw_if_index': sw_if_index,
340 'is_del': is_del})
341
Neale Ranns75152282017-01-09 01:00:45 -0800342 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000343 no,
Neale Ranns75152282017-01-09 01:00:45 -0800344 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000345 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800346 return self.api(self.papi.sw_interface_ip6nd_ra_config,
347 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000348 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100349 'suppress': suppress,
350 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800351
Neale Ranns87df12d2017-02-18 08:16:41 -0800352 def ip6_sw_interface_ra_prefix(self,
353 sw_if_index,
354 address,
355 address_length,
356 use_default=0,
357 no_advertise=0,
358 off_link=0,
359 no_autoconfig=0,
360 no_onlink=0,
361 is_no=0,
362 val_lifetime=0xffffffff,
363 pref_lifetime=0xffffffff):
364 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
365 {'sw_if_index': sw_if_index,
366 'address': address,
367 'address_length': address_length,
368 'use_default': use_default,
369 'no_advertise': no_advertise,
370 'off_link': off_link,
371 'no_autoconfig': no_autoconfig,
372 'no_onlink': no_onlink,
373 'is_no': is_no,
374 'val_lifetime': val_lifetime,
375 'pref_lifetime': pref_lifetime})
376
Neale Ranns75152282017-01-09 01:00:45 -0800377 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
378 """
379 Enable/Disable An interface for IPv6
380 """
381 return self.api(self.papi.sw_interface_ip6_enable_disable,
382 {'sw_if_index': sw_if_index,
383 'enable': enable})
384
Klement Sekeraf62ae122016-10-11 11:47:09 +0200385 def vxlan_add_del_tunnel(
386 self,
387 src_addr,
388 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200389 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200390 is_add=1,
391 is_ipv6=0,
392 encap_vrf_id=0,
393 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600394 vni=0,
395 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200396 """
397
398 :param dst_addr:
399 :param src_addr:
400 :param is_add: (Default value = 1)
401 :param is_ipv6: (Default value = 0)
402 :param encap_vrf_id: (Default value = 0)
403 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200404 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600406 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200407
408 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100409 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200410 {'is_add': is_add,
411 'is_ipv6': is_ipv6,
412 'src_address': src_addr,
413 'dst_address': dst_addr,
414 'mcast_sw_if_index': mcast_sw_if_index,
415 'encap_vrf_id': encap_vrf_id,
416 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600417 'vni': vni,
418 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200419
Marco Varleseb598f1d2017-09-19 14:25:28 +0200420 def geneve_add_del_tunnel(
421 self,
422 local_addr,
423 remote_addr,
424 mcast_sw_if_index=0xFFFFFFFF,
425 is_add=1,
426 is_ipv6=0,
427 encap_vrf_id=0,
428 decap_next_index=0xFFFFFFFF,
429 vni=0):
430 """
431
432 :param remote_addr:
433 :param local_addr:
434 :param is_add: (Default value = 1)
435 :param is_ipv6: (Default value = 0)
436 :param encap_vrf_id: (Default value = 0)
437 :param decap_next_index: (Default value = 0xFFFFFFFF)
438 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
439 :param vni: (Default value = 0)
440
441 """
442 return self.api(self.papi.geneve_add_del_tunnel,
443 {'is_add': is_add,
444 'is_ipv6': is_ipv6,
445 'local_address': local_addr,
446 'remote_address': remote_addr,
447 'mcast_sw_if_index': mcast_sw_if_index,
448 'encap_vrf_id': encap_vrf_id,
449 'decap_next_index': decap_next_index,
450 'vni': vni})
451
Jan4af521d2016-11-15 17:05:00 +0100452 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
453 learn=1, arp_term=0, is_add=1):
454 """Create/delete bridge domain.
455
456 :param int bd_id: Bridge domain index.
457 :param int flood: Enable/disable bcast/mcast flooding in the BD.
458 (Default value = 1)
459 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
460 (Default value = 1)
461 :param int forward: Enable/disable forwarding on all interfaces in
462 the BD. (Default value = 1)
463 :param int learn: Enable/disable learning on all interfaces in the BD.
464 (Default value = 1)
465 :param int arp_term: Enable/disable arp termination in the BD.
466 (Default value = 1)
467 :param int is_add: Add or delete flag. (Default value = 1)
468 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100469 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200470 {'bd_id': bd_id,
471 'flood': flood,
472 'uu_flood': uu_flood,
473 'forward': forward,
474 'learn': learn,
475 'arp_term': arp_term,
476 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100477
Eyal Baric86e5922017-07-02 18:33:16 +0300478 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
479 return self.api(self.papi.bd_ip_mac_add_del,
480 {'bd_id': bd_id,
481 'is_add': is_add,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700482 'ip': ip,
483 'mac': mac})
Eyal Baric86e5922017-07-02 18:33:16 +0300484
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700485 def bd_ip_mac_dump(self, bd_id):
486 return self.api(self.papi.bd_ip_mac_dump,
487 {'bd_id': bd_id})
488
Eyal Bari20197482017-09-13 12:29:08 +0300489 def want_ip4_arp_events(self, enable_disable=1, address=0):
490 return self.api(self.papi.want_ip4_arp_events,
491 {'enable_disable': enable_disable,
492 'address': address,
493 'pid': os.getpid(), })
494
Eyal Baric125ecc2017-09-20 11:29:17 +0300495 def want_ip6_nd_events(self, enable_disable=1, address=0):
496 return self.api(self.papi.want_ip6_nd_events,
497 {'enable_disable': enable_disable,
498 'address': address,
499 'pid': os.getpid(), })
500
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100501 def want_ip6_ra_events(self, enable_disable=1):
502 return self.api(self.papi.want_ip6_ra_events,
503 {'enable_disable': enable_disable,
504 'pid': os.getpid(), })
505
506 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
507 mrc=0, mrd=0):
508 return self.api(self.papi.ip6nd_send_router_solicitation,
509 {'irt': irt,
510 'mrt': mrt,
511 'mrc': mrc,
512 'mrd': mrd,
513 'sw_if_index': sw_if_index})
514
Juraj Slobodac0374232018-02-01 15:18:49 +0100515 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
516 install_default_routes):
517 return self.api(self.papi.ip6_nd_address_autoconfig,
518 {'sw_if_index': sw_if_index,
519 'enable': enable,
520 'install_default_routes': install_default_routes})
521
Juraj Slobodab3f90502018-10-04 15:15:16 +0200522 def want_interface_events(self, enable_disable=1):
523 return self.api(self.papi.want_interface_events,
524 {'enable_disable': enable_disable,
525 'pid': os.getpid(), })
526
Eyal Bari24db0ec2017-09-27 21:43:51 +0300527 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
528 max_macs_in_event=0, learn_limit=0):
529 return self.api(self.papi.want_l2_macs_events,
530 {'enable_disable': enable_disable,
531 'scan_delay': scan_delay,
532 'max_macs_in_event': max_macs_in_event,
533 'learn_limit': learn_limit,
534 'pid': os.getpid(), })
535
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200536 def want_dhcp6_reply_events(self, enable_disable=1):
537 return self.api(self.papi.want_dhcp6_reply_events,
538 {'enable_disable': enable_disable,
539 'pid': os.getpid()})
540
Juraj Sloboda81119e82018-05-25 14:02:20 +0200541 def want_dhcp6_pd_reply_events(self, enable_disable=1):
542 return self.api(self.papi.want_dhcp6_pd_reply_events,
543 {'enable_disable': enable_disable,
544 'pid': os.getpid()})
545
546 def dhcp6_clients_enable_disable(self, enable=1):
547 return self.api(self.papi.dhcp6_clients_enable_disable,
548 {'enable': enable})
549
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200550 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
551 addresses, server_index=0xFFFFFFFF,
552 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
553 ):
554 return self.api(self.papi.dhcp6_send_client_message,
555 {'sw_if_index': sw_if_index,
556 'server_index': server_index,
557 'irt': irt,
558 'mrt': mrt,
559 'mrc': mrc,
560 'mrd': mrd,
561 'stop': stop,
562 'msg_type': msg_type,
563 'T1': T1,
564 'T2': T2,
565 'n_addresses': len(addresses),
566 'addresses': addresses})
567
Juraj Sloboda81119e82018-05-25 14:02:20 +0200568 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
569 prefixes, server_index=0xFFFFFFFF,
570 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
571 ):
572 return self.api(self.papi.dhcp6_pd_send_client_message,
573 {'sw_if_index': sw_if_index,
574 'server_index': server_index,
575 'irt': irt,
576 'mrt': mrt,
577 'mrc': mrc,
578 'mrd': mrd,
579 'stop': stop,
580 'msg_type': msg_type,
581 'T1': T1,
582 'T2': T2,
583 'n_prefixes': len(prefixes),
584 'prefixes': prefixes})
585
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200586 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
587 enable=1):
588 return self.api(self.papi.dhcp6_client_enable_disable,
589 {'sw_if_index': sw_if_index,
590 'enable': enable})
591
Juraj Sloboda81119e82018-05-25 14:02:20 +0200592 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
593 enable=1):
594 return self.api(self.papi.dhcp6_pd_client_enable_disable,
595 {'sw_if_index': sw_if_index,
596 'prefix_group': prefix_group,
597 'enable': enable})
598
599 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
600 prefix_length, prefix_group,
601 is_add=1):
602 return self.api(self.papi.ip6_add_del_address_using_prefix,
603 {'sw_if_index': sw_if_index,
604 'prefix_group': prefix_group,
605 'address': address,
606 'prefix_length': prefix_length,
607 'is_add': is_add})
608
Jan4af521d2016-11-15 17:05:00 +0100609 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
610 filter_mac=0, bvi_mac=0):
611 """Create/delete L2 FIB entry.
612
613 :param str mac: MAC address to create FIB entry for.
614 :param int bd_id: Bridge domain index.
615 :param int sw_if_index: Software interface index of the interface.
616 :param int is_add: Add or delete flag. (Default value = 1)
617 :param int static_mac: Set to 1 to create static MAC entry.
618 (Default value = 0)
619 :param int filter_mac: Set to 1 to drop packet that's source or
620 destination MAC address contains defined MAC address.
621 (Default value = 0)
622 :param int bvi_mac: Set to 1 to create entry that points to BVI
623 interface. (Default value = 0)
624 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100625 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200626 {'mac': self._convert_mac(mac),
627 'bd_id': bd_id,
628 'sw_if_index': sw_if_index,
629 'is_add': is_add,
630 'static_mac': static_mac,
631 'filter_mac': filter_mac,
632 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100633
Eyal Bari93b503e2017-05-15 10:13:15 +0300634 def l2fib_flush_int(self, sw_if_index):
635 """Flush L2 FIB entries for sw_if_index.
636
637 :param int sw_if_index: Software interface index of the interface.
638 """
639 return self.api(self.papi.l2fib_flush_int,
640 {'sw_if_index': sw_if_index})
641
642 def l2fib_flush_bd(self, bd_id):
643 """Flush L2 FIB entries for bd_id.
644
645 :param int sw_if_index: Bridge Domain id.
646 """
647 return self.api(self.papi.l2fib_flush_bd,
648 {'bd_id': bd_id})
649
650 def l2fib_flush_all(self):
651 """Flush all L2 FIB.
652 """
653 return self.api(self.papi.l2fib_flush_all, {})
654
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700655 def l2_fib_table_dump(self, bd_id):
656 """ Dump the L2 FIB """
657 return self.api(self.papi.l2_fib_table_dump,
658 {'bd_id': bd_id})
659
Klement Sekeraf62ae122016-10-11 11:47:09 +0200660 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700661 shg=0, port_type=L2_PORT_TYPE.NORMAL,
662 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100663 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200664
Jan4af521d2016-11-15 17:05:00 +0100665 :param int sw_if_index: Software interface index of the interface.
666 :param int bd_id: Bridge domain index.
667 :param int shg: Split-horizon group index. (Default value = 0)
668 :param int bvi: Set interface as a bridge group virtual interface.
669 (Default value = 0)
670 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200671 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100672 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200673 {'rx_sw_if_index': sw_if_index,
674 'bd_id': bd_id,
675 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700676 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200677 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200678
Jan00dad122016-11-29 10:04:53 +0100679 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400680 """Enable/disable required feature of the bridge domain with defined
681 ID.
Jan00dad122016-11-29 10:04:53 +0100682
683 :param int bd_id: Bridge domain ID.
684 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700685 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100686 - learn (1 << 0),
687 - forward (1 << 1),
688 - flood (1 << 2),
689 - uu-flood (1 << 3) or
690 - arp-term (1 << 4).
691 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100692 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200693 {'bd_id': bd_id,
694 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700695 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100696
697 def bridge_domain_dump(self, bd_id=0):
698 """
699
700 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
701 existing bridge domains returned)
702 :return: Dictionary of bridge domain(s) data.
703 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100704 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200705 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100706
Klement Sekeraf62ae122016-10-11 11:47:09 +0200707 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
708 enable):
709 """Create or delete unidirectional cross-connect from Tx interface to
710 Rx interface.
711
Jan4af521d2016-11-15 17:05:00 +0100712 :param int rx_sw_if_index: Software interface index of Rx interface.
713 :param int tx_sw_if_index: Software interface index of Tx interface.
714 :param int enable: Create cross-connect if equal to 1, delete
715 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200716
717 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100718 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200719 {'rx_sw_if_index': rx_sw_if_index,
720 'tx_sw_if_index': tx_sw_if_index,
721 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200722
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200723 def sw_interface_set_l2_tag_rewrite(
724 self,
725 sw_if_index,
726 vtr_oper,
727 push=0,
728 tag1=0,
729 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000730 """L2 interface vlan tag rewrite configure request
731 :param client_index - opaque cookie to identify the sender
732 :param context - sender context, to match reply w/ request
733 :param sw_if_index - interface the operation is applied to
734 :param vtr_op - Choose from l2_vtr_op_t enum values
735 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
736 :param tag1 - Needed for any push or translate vtr op
737 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
738
739 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100740 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200741 {'sw_if_index': sw_if_index,
742 'vtr_op': vtr_oper,
743 'push_dot1q': push,
744 'tag1': tag1,
745 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000746
Neale Ranns55d03782017-10-21 06:34:22 -0700747 def sw_interface_set_l2_emulation(
748 self,
749 sw_if_index,
750 enable=1):
751 """L2 Emulation
752 :param sw_if_index - interface the operation is applied to
753
754 """
755 return self.api(self.papi.l2_emulation,
756 {'sw_if_index': sw_if_index,
757 'enable': enable})
758
Neale Ranns1855b8e2018-07-11 10:31:26 -0700759 def sw_interface_set_ip_directed_broadcast(
760 self,
761 sw_if_index,
762 enable=1):
763 """IP Directed broadcast
764 :param sw_if_index - interface the operation is applied to
765
766 """
767 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
768 {'sw_if_index': sw_if_index,
769 'enable': enable})
770
Neale Rannsa07bd702017-08-07 07:53:49 -0700771 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200772 """
773
774 :param admin_up_down:
775 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200776
777 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100778 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200779 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700780 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200781
Ole Troand7231612018-06-07 10:17:57 +0200782 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800783 """
784 :param sw_if_index:
785 :param mtu:
786
787 """
788 return self.api(self.papi.sw_interface_set_mtu,
789 {'sw_if_index': sw_if_index,
790 'mtu': mtu})
791
Neale Ranns25b04942018-04-04 09:34:50 -0700792 def sw_interface_set_promiscuous(self, sw_if_index, enable):
793 """
794 :param sw_if_index:
795 :param enable:
796
797 """
798 return self.api(self.papi.sw_interface_set_promiscuous,
799 {'sw_if_index': sw_if_index,
800 'enable': enable})
801
Neale Rannsc819fc62018-02-16 02:44:05 -0800802 def sw_interface_set_mac_address(self, sw_if_index, mac):
803 return self.api(self.papi.sw_interface_set_mac_address,
804 {'sw_if_index': sw_if_index,
805 'mac_address': mac})
806
Klement Sekeraf62ae122016-10-11 11:47:09 +0200807 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
808 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
809 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
810 """Create subinterface
811 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
812
813 :param sub_id: param inner_vlan:
814 :param sw_if_index:
815 :param outer_vlan:
816 :param inner_vlan:
817 :param no_tags: (Default value = 0)
818 :param one_tag: (Default value = 0)
819 :param two_tags: (Default value = 0)
820 :param dot1ad: (Default value = 0)
821 :param exact_match: (Default value = 0)
822 :param default_sub: (Default value = 0)
823 :param outer_vlan_id_any: (Default value = 0)
824 :param inner_vlan_id_any: (Default value = 0)
825
826 """
827 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100828 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200829 {'sw_if_index': sw_if_index,
830 'sub_id': sub_id,
831 'no_tags': no_tags,
832 'one_tag': one_tag,
833 'two_tags': two_tags,
834 'dot1ad': dot1ad,
835 'exact_match': exact_match,
836 'default_sub': default_sub,
837 'outer_vlan_id_any': outer_vlan_id_any,
838 'inner_vlan_id_any': inner_vlan_id_any,
839 'outer_vlan_id': outer_vlan,
840 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200841
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200842 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
843 """Create p2p ethernet subinterface
844
845 :param sw_if_index: main (parent) interface
846 :param remote_mac: client (remote) mac address
847
848 """
849 return self.api(
850 self.papi.p2p_ethernet_add,
851 {'parent_if_index': sw_if_index,
852 'remote_mac': remote_mac,
853 'subif_id': subif_id})
854
Neale Ranns177bbdc2016-11-15 09:46:51 +0000855 def delete_subif(self, sw_if_index):
856 """Delete subinterface
857
858 :param sw_if_index:
859 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100860 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200861 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000862
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200863 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
864 """Delete p2p ethernet subinterface
865
866 :param sw_if_index: main (parent) interface
867 :param remote_mac: client (remote) mac address
868
869 """
870 return self.api(
871 self.papi.p2p_ethernet_del,
872 {'parent_if_index': sw_if_index,
873 'remote_mac': remote_mac})
874
Klement Sekeraf62ae122016-10-11 11:47:09 +0200875 def create_vlan_subif(self, sw_if_index, vlan):
876 """
877
878 :param vlan:
879 :param sw_if_index:
880
881 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100882 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200883 {'sw_if_index': sw_if_index,
884 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200885
Matej Klotton0178d522016-11-04 11:11:44 +0100886 def create_loopback(self, mac=''):
887 """
888
889 :param mac: (Optional)
890 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100891 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200892 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100893
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100894 def delete_loopback(self, sw_if_index):
895 return self.api(self.papi.delete_loopback,
896 {'sw_if_index': sw_if_index, })
897
Neale Ranns15002542017-09-10 04:39:11 -0700898 def ip_table_add_del(self,
899 table_id,
900 is_add=1,
901 is_ipv6=0):
902 """
903
904 :param table_id
905 :param is_add: (Default value = 1)
906 :param is_ipv6: (Default value = 0)
907
908 """
909
910 return self.api(
911 self.papi.ip_table_add_del,
912 {'table_id': table_id,
913 'is_add': is_add,
914 'is_ipv6': is_ipv6})
915
Klement Sekeraf62ae122016-10-11 11:47:09 +0200916 def ip_add_del_route(
917 self,
918 dst_address,
919 dst_address_length,
920 next_hop_address,
921 next_hop_sw_if_index=0xFFFFFFFF,
922 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200923 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000924 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200925 next_hop_n_out_labels=0,
926 next_hop_out_label_stack=[],
927 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800928 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000929 is_resolve_host=0,
930 is_resolve_attached=0,
931 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200932 is_add=1,
933 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200934 is_unreach=0,
935 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200936 is_ipv6=0,
937 is_local=0,
938 is_classify=0,
939 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800940 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800941 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200942 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200943 """
944
945 :param dst_address_length:
946 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
947 :param dst_address:
948 :param next_hop_address:
949 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
950 :param vrf_id: (Default value = 0)
951 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200952 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200953 :param is_add: (Default value = 1)
954 :param is_drop: (Default value = 0)
955 :param is_ipv6: (Default value = 0)
956 :param is_local: (Default value = 0)
957 :param is_classify: (Default value = 0)
958 :param is_multipath: (Default value = 0)
959 :param is_resolve_host: (Default value = 0)
960 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800961 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700962 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200963 :param next_hop_weight: (Default value = 1)
964
965 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000966
Klement Sekeraf62ae122016-10-11 11:47:09 +0200967 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100968 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200969 {'next_hop_sw_if_index': next_hop_sw_if_index,
970 'table_id': table_id,
971 'classify_table_index': classify_table_index,
972 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200973 'is_add': is_add,
974 'is_drop': is_drop,
975 'is_unreach': is_unreach,
976 'is_prohibit': is_prohibit,
977 'is_ipv6': is_ipv6,
978 'is_local': is_local,
979 'is_classify': is_classify,
980 'is_multipath': is_multipath,
981 'is_resolve_host': is_resolve_host,
982 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800983 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700984 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800985 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200986 'next_hop_weight': next_hop_weight,
987 'dst_address_length': dst_address_length,
988 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800989 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200990 'next_hop_address': next_hop_address,
991 'next_hop_n_out_labels': next_hop_n_out_labels,
992 'next_hop_via_label': next_hop_via_label,
993 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100994
Matej Klotton16a14cd2016-12-07 15:09:13 +0100995 def ip_fib_dump(self):
996 return self.api(self.papi.ip_fib_dump, {})
997
Jan Gelety057bb8c2016-12-20 17:32:45 +0100998 def ip6_fib_dump(self):
999 return self.api(self.papi.ip6_fib_dump, {})
1000
Matej Klotton0178d522016-11-04 11:11:44 +01001001 def ip_neighbor_add_del(self,
1002 sw_if_index,
1003 mac_address,
1004 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +01001005 is_add=1,
1006 is_ipv6=0,
1007 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001008 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +01001009 ):
1010 """ Add neighbor MAC to IPv4 or IPv6 address.
1011
1012 :param sw_if_index:
1013 :param mac_address:
1014 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001015 :param is_add: (Default value = 1)
1016 :param is_ipv6: (Default value = 0)
1017 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001018 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001019 """
1020
1021 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001022 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001023 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001024 'is_add': is_add,
1025 'is_ipv6': is_ipv6,
1026 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001027 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001028 'mac_address': mac_address,
1029 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001030 }
Matej Klotton0178d522016-11-04 11:11:44 +01001031 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001032
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001033 def ip_neighbor_dump(self,
1034 sw_if_index,
1035 is_ipv6=0):
1036 """ Return IP neighbor dump.
1037
1038 :param sw_if_index:
1039 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1040 """
1041
1042 return self.api(
1043 self.papi.ip_neighbor_dump,
1044 {'is_ipv6': is_ipv6,
1045 'sw_if_index': sw_if_index
1046 }
1047 )
1048
1049 def proxy_arp_add_del(self,
1050 low_address,
1051 hi_address,
1052 vrf_id=0,
1053 is_add=1):
1054 """ Config Proxy Arp Range.
1055
1056 :param low_address: Start address in the rnage to Proxy for
1057 :param hi_address: End address in the rnage to Proxy for
1058 :param vrf_id: The VRF/table in which to proxy
1059 """
1060
1061 return self.api(
1062 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001063 {'proxy':
1064 {
1065 'vrf_id': vrf_id,
1066 'low_address': low_address,
1067 'hi_address': hi_address,
1068 },
1069 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001070
1071 def proxy_arp_intfc_enable_disable(self,
1072 sw_if_index,
1073 is_enable=1):
1074 """ Enable/Disable an interface for proxy ARP requests
1075
1076 :param sw_if_index: Interface
1077 :param enable_disable: Enable/Disable
1078 """
1079
1080 return self.api(
1081 self.papi.proxy_arp_intfc_enable_disable,
1082 {'sw_if_index': sw_if_index,
1083 'enable_disable': is_enable
1084 }
1085 )
1086
Jane546d3b2016-12-08 13:10:03 +01001087 def reset_vrf(self,
1088 vrf_id,
1089 is_ipv6=0,
1090 ):
1091 """ Reset VRF (remove all routes etc.) request.
1092
1093 :param int vrf_id: ID of the FIB table / VRF to reset.
1094 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1095 """
1096
1097 return self.api(
1098 self.papi.reset_vrf,
1099 {'vrf_id': vrf_id,
1100 'is_ipv6': is_ipv6,
1101 }
1102 )
1103
1104 def reset_fib(self,
1105 vrf_id,
1106 is_ipv6=0,
1107 ):
1108 """ Reset VRF (remove all routes etc.) request.
1109
1110 :param int vrf_id: ID of the FIB table / VRF to reset.
1111 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1112 """
1113
1114 return self.api(
1115 self.papi.reset_fib,
1116 {'vrf_id': vrf_id,
1117 'is_ipv6': is_ipv6,
1118 }
1119 )
1120
1121 def ip_dump(self,
1122 is_ipv6=0,
1123 ):
1124 """ Return IP dump.
1125
1126 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1127 """
1128
1129 return self.api(
1130 self.papi.ip_dump,
1131 {'is_ipv6': is_ipv6,
1132 }
1133 )
1134
Klement Sekera7bb873a2016-11-18 07:38:42 +01001135 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001136 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001137 """
1138
1139 :param sw_if_index_from:
1140 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001141 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001142 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001143 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001144 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001145 {'sw_if_index_from': sw_if_index_from,
1146 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001147 'state': state,
1148 'is_l2': is_l2,
1149 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001150
1151 def gre_tunnel_add_del(self,
1152 src_address,
1153 dst_address,
1154 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001155 tunnel_type=0,
1156 instance=0xFFFFFFFF,
1157 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001158 is_add=1,
1159 is_ip6=0):
1160 """ Add a GRE tunnel
1161
1162 :param src_address:
1163 :param dst_address:
1164 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001165 :param tunnel_type: (Default value = 0)
1166 :param instance: (Default value = 0xFFFFFFFF)
1167 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001168 :param is_add: (Default value = 1)
1169 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001170 """
1171
1172 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001173 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001174 {'is_add': is_add,
1175 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001176 'tunnel_type': tunnel_type,
1177 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001178 'src_address': src_address,
1179 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001180 'outer_fib_id': outer_fib_id,
1181 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001182 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001183
Neale Rannsd0df49f2018-08-08 01:06:40 -07001184 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001185 src_ip,
1186 dst_ip,
1187 src_port,
1188 dst_port,
1189 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001190 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001191 :param src_ip:
1192 :param dst_ip:
1193 :param src_port:
1194 :param dst_port:
1195 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001196 """
1197
1198 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001199 self.papi.udp_encap_add,
1200 {
1201 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001202 'src_ip': src_ip,
1203 'dst_ip': dst_ip,
1204 'src_port': src_port,
1205 'dst_port': dst_port,
1206 'table_id': table_id
1207 }
1208 })
1209
1210 def udp_encap_del(self, id):
1211 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001212
1213 def udp_encap_dump(self):
1214 return self.api(self.papi.udp_encap_dump, {})
1215
Neale Ranns43b1f442018-03-20 01:47:35 -07001216 def want_udp_encap_stats(self, enable=1):
1217 return self.api(self.papi.want_udp_encap_stats,
1218 {'enable': enable,
1219 'pid': os.getpid()})
1220
Neale Ranns5a8123b2017-01-26 01:18:23 -08001221 def mpls_fib_dump(self):
1222 return self.api(self.papi.mpls_fib_dump, {})
1223
Neale Ranns15002542017-09-10 04:39:11 -07001224 def mpls_table_add_del(
1225 self,
1226 table_id,
1227 is_add=1):
1228 """
1229
1230 :param table_id
1231 :param is_add: (Default value = 1)
1232
1233 """
1234
1235 return self.api(
1236 self.papi.mpls_table_add_del,
1237 {'mt_table_id': table_id,
1238 'mt_is_add': is_add})
1239
Neale Rannsad422ed2016-11-02 14:20:04 +00001240 def mpls_route_add_del(
1241 self,
1242 label,
1243 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001244 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001245 next_hop_address,
1246 next_hop_sw_if_index=0xFFFFFFFF,
1247 table_id=0,
1248 next_hop_table_id=0,
1249 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001250 next_hop_n_out_labels=0,
1251 next_hop_out_label_stack=[],
1252 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001253 is_resolve_host=0,
1254 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001255 is_interface_rx=0,
1256 is_rpf_id=0,
1257 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001258 is_add=1,
1259 is_drop=0,
1260 is_multipath=0,
1261 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001262 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001263 """
1264
1265 :param dst_address_length:
1266 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1267 :param dst_address:
1268 :param next_hop_address:
1269 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1270 :param vrf_id: (Default value = 0)
1271 :param lookup_in_vrf: (Default value = 0)
1272 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001273 :param is_add: (Default value = 1)
1274 :param is_drop: (Default value = 0)
1275 :param is_ipv6: (Default value = 0)
1276 :param is_local: (Default value = 0)
1277 :param is_classify: (Default value = 0)
1278 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001279 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001280 :param is_resolve_host: (Default value = 0)
1281 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001282 :param next_hop_weight: (Default value = 1)
1283
1284 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001285 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001286 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001287 {'mr_label': label,
1288 'mr_eos': eos,
1289 'mr_table_id': table_id,
1290 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001291 'mr_is_add': is_add,
1292 'mr_is_classify': is_classify,
1293 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001294 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001295 'mr_is_resolve_host': is_resolve_host,
1296 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001297 'mr_is_interface_rx': is_interface_rx,
1298 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001299 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001300 'mr_next_hop_weight': next_hop_weight,
1301 'mr_next_hop': next_hop_address,
1302 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1303 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1304 'mr_next_hop_table_id': next_hop_table_id,
1305 'mr_next_hop_via_label': next_hop_via_label,
1306 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001307
1308 def mpls_ip_bind_unbind(
1309 self,
1310 label,
1311 dst_address,
1312 dst_address_length,
1313 table_id=0,
1314 ip_table_id=0,
1315 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001316 is_bind=1):
1317 """
1318 """
1319 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001320 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001321 {'mb_mpls_table_id': table_id,
1322 'mb_label': label,
1323 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001324 'mb_is_bind': is_bind,
1325 'mb_is_ip4': is_ip4,
1326 'mb_address_length': dst_address_length,
1327 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001328
1329 def mpls_tunnel_add_del(
1330 self,
1331 tun_sw_if_index,
1332 next_hop_proto_is_ip4,
1333 next_hop_address,
1334 next_hop_sw_if_index=0xFFFFFFFF,
1335 next_hop_table_id=0,
1336 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001337 next_hop_n_out_labels=0,
1338 next_hop_out_label_stack=[],
1339 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001340 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001341 l2_only=0,
1342 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001343 """
1344
1345 :param dst_address_length:
1346 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1347 :param dst_address:
1348 :param next_hop_address:
1349 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1350 :param vrf_id: (Default value = 0)
1351 :param lookup_in_vrf: (Default value = 0)
1352 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001353 :param is_add: (Default value = 1)
1354 :param is_drop: (Default value = 0)
1355 :param is_ipv6: (Default value = 0)
1356 :param is_local: (Default value = 0)
1357 :param is_classify: (Default value = 0)
1358 :param is_multipath: (Default value = 0)
1359 :param is_resolve_host: (Default value = 0)
1360 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001361 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001362 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001363
1364 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001365 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001366 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001367 {'mt_sw_if_index': tun_sw_if_index,
1368 'mt_is_add': is_add,
1369 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001370 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001371 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1372 'mt_next_hop_weight': next_hop_weight,
1373 'mt_next_hop': next_hop_address,
1374 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1375 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1376 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001377 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001378 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001379
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001380 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1381 return self.api(self.papi.mpls_tunnel_dump,
1382 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001383
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001385 self,
1386 sw_if_index,
1387 is_inside=1,
1388 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001389 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001390
1391 :param sw_if_index: Software index of the interface
1392 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1393 :param is_add: 1 if add, 0 if delete (Default value = 1)
1394 """
1395 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001396 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001397 {'is_add': is_add,
1398 'is_inside': is_inside,
1399 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001400
Matus Fabian2ba92e32017-08-21 07:05:03 -07001401 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001402 self,
1403 sw_if_index,
1404 is_inside=1,
1405 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001406 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001407
1408 :param sw_if_index: Software index of the interface
1409 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1410 :param is_add: 1 if add, 0 if delete (Default value = 1)
1411 """
1412 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001413 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001414 {'is_add': is_add,
1415 'is_inside': is_inside,
1416 'sw_if_index': sw_if_index})
1417
Matus Fabian2ba92e32017-08-21 07:05:03 -07001418 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001419 self,
1420 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001421 external_ip=0,
1422 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001423 local_port=0,
1424 external_port=0,
1425 addr_only=1,
1426 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001427 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001428 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001429 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001430 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001431 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001432 is_add=1):
1433 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001434
1435 :param local_ip: Local IP address
1436 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001437 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001438 :param local_port: Local port number (Default value = 0)
1439 :param external_port: External port number (Default value = 0)
1440 :param addr_only: 1 if address only mapping, 0 if address and port
1441 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001442 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001443 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001444 :param self_twice_nat: 1 if translate external host address and port
1445 whenever external host address equals
1446 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001447 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001448 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001449 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001450 """
1451 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001452 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001453 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001454 'addr_only': addr_only,
1455 'local_ip_address': local_ip,
1456 'external_ip_address': external_ip,
1457 'local_port': local_port,
1458 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001459 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001460 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001461 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001462 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001463 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001464 'out2in_only': out2in_only,
1465 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001466
Matus Fabianab7a8052017-11-28 04:29:41 -08001467 def nat44_add_del_identity_mapping(
1468 self,
1469 ip='0',
1470 sw_if_index=0xFFFFFFFF,
1471 port=0,
1472 addr_only=1,
1473 vrf_id=0,
1474 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001475 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001476 is_add=1):
1477 """Add/delete NAT44 identity mapping
1478
1479 :param ip: IP address (Default value = 0)
1480 :param sw_if_index: Interface instead of IP address
1481 :param port: Port number (Default value = 0)
1482 :param addr_only: 1 if address only mapping, 0 if address and port
1483 :param vrf_id: VRF ID
1484 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001485 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001486 :param is_add: 1 if add, 0 if delete (Default value = 1)
1487 """
1488 return self.api(
1489 self.papi.nat44_add_del_identity_mapping,
1490 {'is_add': is_add,
1491 'addr_only': addr_only,
1492 'ip_address': ip,
1493 'port': port,
1494 'sw_if_index': sw_if_index,
1495 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001496 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001497 'protocol': protocol})
1498
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001500 self,
1501 first_ip_address,
1502 last_ip_address,
1503 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001504 vrf_id=0xFFFFFFFF,
1505 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001506 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001507
1508 :param first_ip_address: First IP address
1509 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001510 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001511 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001512 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001513 """
1514 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001515 self.papi.nat44_add_del_address_range,
1516 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001517 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001518 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001519 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001520 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001521
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 def nat44_address_dump(self):
1523 """Dump NAT44 addresses
1524 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001525 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001526 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001527
Matus Fabian2ba92e32017-08-21 07:05:03 -07001528 def nat44_interface_dump(self):
1529 """Dump interfaces with NAT44 feature
1530 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001531 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001532 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001533
Matus Fabian2ba92e32017-08-21 07:05:03 -07001534 def nat44_interface_output_feature_dump(self):
1535 """Dump interfaces with NAT44 output feature
1536 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001537 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001538 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001539
Matus Fabian2ba92e32017-08-21 07:05:03 -07001540 def nat44_static_mapping_dump(self):
1541 """Dump NAT44 static mappings
1542 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001543 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001544 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001545
Matus Fabianab7a8052017-11-28 04:29:41 -08001546 def nat44_identity_mapping_dump(self):
1547 """Dump NAT44 identity mappings
1548 :return: Dictionary of NAT44 identity mappings
1549 """
1550 return self.api(self.papi.nat44_identity_mapping_dump, {})
1551
Matus Fabian2ba92e32017-08-21 07:05:03 -07001552 def nat_show_config(self):
1553 """Show NAT plugin config
1554 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001555 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001556 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001557
Matus Fabian2ba92e32017-08-21 07:05:03 -07001558 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001559 self,
1560 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001561 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001562 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001563 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001564
1565 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001566 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001567 :param is_add: 1 if add, 0 if delete (Default value = 1)
1568 """
Matus Fabianb932d262017-12-18 05:38:24 -08001569 return self.api(
1570 self.papi.nat44_add_del_interface_addr,
1571 {'is_add': is_add,
1572 'sw_if_index': sw_if_index,
1573 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001574
Matus Fabian2ba92e32017-08-21 07:05:03 -07001575 def nat44_interface_addr_dump(self):
1576 """Dump NAT44 addresses interfaces
1577 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001578 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001580
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001582 self,
1583 domain_id=1,
1584 src_port=4739,
1585 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001586 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001587
1588 :param domain_id: Observation domain ID (Default value = 1)
1589 :param src_port: Source port number (Default value = 4739)
1590 :param enable: 1 if enable, 0 if disable (Default value = 1)
1591 """
1592 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001593 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001594 {'domain_id': domain_id,
1595 'src_port': src_port,
1596 'enable': enable})
1597
Matus Fabian2ba92e32017-08-21 07:05:03 -07001598 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001599 self,
1600 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001601 vrf_id):
1602 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001603
1604 :param ip_address: ip adress of the user to be dumped
1605 :param cpu_index: cpu_index on which the user is
1606 :param vrf_id: VRF ID
1607 :return: Dictionary of S-NAT sessions
1608 """
1609 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001610 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001611 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001612 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001613
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 def nat44_user_dump(self):
1615 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001616
Matus Fabian2ba92e32017-08-21 07:05:03 -07001617 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001618 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001619 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001620
Matus Fabian704018c2017-09-04 02:17:18 -07001621 def nat44_add_del_lb_static_mapping(
1622 self,
1623 external_addr,
1624 external_port,
1625 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001626 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001627 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001628 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001629 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001630 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001631 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001632 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001633 is_add=1):
1634 """Add/delete NAT44 load balancing static mapping
1635
Matus Fabianb932d262017-12-18 05:38:24 -08001636 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001637 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001638 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001639 :param is_add - 1 if add, 0 if delete
1640 """
1641 return self.api(
1642 self.papi.nat44_add_del_lb_static_mapping,
1643 {'is_add': is_add,
1644 'external_addr': external_addr,
1645 'external_port': external_port,
1646 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001647 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001648 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001649 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001650 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001651 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001652 'local_num': local_num,
1653 'locals': locals})
1654
1655 def nat44_lb_static_mapping_dump(self):
1656 """Dump NAT44 load balancing static mappings
1657
1658 :return: Dictionary of NAT44 load balancing static mapping
1659 """
1660 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1661
Matus Fabian5ba86f72017-10-26 03:37:38 -07001662 def nat44_del_session(
1663 self,
1664 addr,
1665 port,
1666 protocol,
1667 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001668 is_in=1,
1669 ext_host_address=None,
1670 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001671 """Delete NAT44 session
1672
1673 :param addr: IPv4 address
1674 :param por: port number
1675 :param protocol: IP protocol number
1676 :param vrf_id: VRF ID
1677 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001678 :param ext_host_address: external host IPv4 address
1679 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001680 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001681 if ext_host_address is None:
1682 return self.api(
1683 self.papi.nat44_del_session,
1684 {'address': addr,
1685 'port': port,
1686 'protocol': protocol,
1687 'vrf_id': vrf_id,
1688 'is_in': is_in})
1689 else:
1690 return self.api(
1691 self.papi.nat44_del_session,
1692 {'address': addr,
1693 'port': port,
1694 'protocol': protocol,
1695 'vrf_id': vrf_id,
1696 'is_in': is_in,
1697 'ext_host_valid': 1,
1698 'ext_host_address': ext_host_address,
1699 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001700
Juraj Sloboda7b929792017-11-23 13:20:48 +01001701 def nat44_forwarding_enable_disable(
1702 self,
1703 enable):
1704 """Enable/disable forwarding for NAT44
1705
1706 :param enable: 1 for enable, 0 for disable
1707 """
1708 return self.api(
1709 self.papi.nat44_forwarding_enable_disable,
1710 {'enable': enable})
1711
Matus Fabianefcd1e92017-08-15 06:59:19 -07001712 def nat_set_reass(
1713 self,
1714 timeout=2,
1715 max_reass=1024,
1716 max_frag=5,
1717 drop_frag=0,
1718 is_ip6=0):
1719 """Set NAT virtual fragmentation reassembly
1720
1721 :param timeout: reassembly timeout (Default 2sec)
1722 :param max_reass: maximum concurrent reassemblies (Default 1024)
1723 :param max_frag: maximum fragmets per reassembly (Default 5)
1724 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1725 :param is_ip6: 1 if IPv6, 0 if IPv4
1726 """
1727 return self.api(
1728 self.papi.nat_set_reass,
1729 {'timeout': timeout,
1730 'max_reass': max_reass,
1731 'max_frag': max_frag,
1732 'drop_frag': drop_frag,
1733 'is_ip6': is_ip6})
1734
1735 def nat_get_reass(self):
1736 """Get NAT virtual fragmentation reassembly configuration
1737
1738 :return: NAT virtual fragmentation reassembly configuration
1739 """
1740 return self.api(self.papi.nat_get_reass, {})
1741
1742 def nat_reass_dump(self):
1743 """Dump NAT virtual fragmentation reassemblies
1744
1745 :return: Dictionary of NAT virtual fragmentation reassemblies
1746 """
1747 return self.api(self.papi.nat_reass_dump, {})
1748
Matus Fabian2ba92e32017-08-21 07:05:03 -07001749 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001750 self,
1751 in_addr,
1752 in_plen,
1753 out_addr,
1754 out_plen,
1755 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001756 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001757
1758 :param is_add - 1 if add, 0 if delete
1759 :param in_addr - inside IP address
1760 :param in_plen - inside IP address prefix length
1761 :param out_addr - outside IP address
1762 :param out_plen - outside IP address prefix length
1763 """
1764 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001765 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001766 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001767 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001768 'in_addr': in_addr,
1769 'in_plen': in_plen,
1770 'out_addr': out_addr,
1771 'out_plen': out_plen})
1772
Matus Fabian2ba92e32017-08-21 07:05:03 -07001773 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001774 self,
1775 in_addr):
1776 """Get outside address and port range from inside address
1777
1778 :param in_addr - inside IP address
1779 """
1780 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001781 self.papi.nat_det_forward,
1782 {'in_addr': in_addr,
1783 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001784
Matus Fabian2ba92e32017-08-21 07:05:03 -07001785 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001786 self,
1787 out_addr,
1788 out_port):
1789 """Get inside address from outside address and port
1790
1791 :param out_addr - outside IP address
1792 :param out_port - outside port
1793 """
1794 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001795 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001796 {'out_addr': out_addr,
1797 'out_port': out_port})
1798
Matus Fabian2ba92e32017-08-21 07:05:03 -07001799 def nat_det_map_dump(self):
1800 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001801
Matus Fabian2ba92e32017-08-21 07:05:03 -07001802 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001803 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001804 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001805
Matus Fabian878c6462018-08-23 00:33:35 -07001806 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001807 self,
1808 udp=300,
1809 tcp_established=7440,
1810 tcp_transitory=240,
1811 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001812 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001813
1814 :param udp - UDP timeout (Default value = 300)
1815 :param tcp_established - TCP established timeout (Default value = 7440)
1816 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1817 :param icmp - ICMP timeout (Default value = 60)
1818 """
1819 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001820 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001821 {'udp': udp,
1822 'tcp_established': tcp_established,
1823 'tcp_transitory': tcp_transitory,
1824 'icmp': icmp})
1825
Matus Fabian878c6462018-08-23 00:33:35 -07001826 def nat_get_timeouts(self):
1827 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001828
Matus Fabian878c6462018-08-23 00:33:35 -07001829 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001830 """
Matus Fabian878c6462018-08-23 00:33:35 -07001831 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001832
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001833 def nat_set_addr_and_port_alloc_alg(
1834 self,
1835 alg=0,
1836 psid_offset=0,
1837 psid_length=0,
1838 psid=0,
1839 start_port=0,
1840 end_port=0):
1841 """Set address and port assignment algorithm
1842
1843 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1844 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1845 :param psid_length: length of PSID (valid only for MAP-E alg)
1846 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1847 :param start_port: beginning of the port range
1848 :param end_port: end of the port range
1849 """
1850 return self.api(
1851 self.papi.nat_set_addr_and_port_alloc_alg,
1852 {'alg': alg,
1853 'psid_offset': psid_offset,
1854 'psid_length': psid_length,
1855 'psid': psid,
1856 'start_port': start_port,
1857 'end_port': end_port})
1858
1859 def nat_get_addr_and_port_alloc_alg(self):
1860 """Get address and port assignment algorithm"""
1861 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1862
Matus Fabianbb4e0222018-09-13 02:36:25 -07001863 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1864 """Set TCP MSS rewriting configuration
1865
1866 :param enable: disable(0)/enable(1) MSS rewriting feature
1867 :param mss_value: MSS value to be used for MSS rewriting
1868 """
1869 return self.api(
1870 self.papi.nat_set_mss_clamping,
1871 {'enable': enable, 'mss_value': mss_value})
1872
1873 def nat_get_mss_clamping(self):
1874 """Get TCP MSS rewriting configuration"""
1875 return self.api(self.papi.nat_get_mss_clamping, {})
1876
Matus Fabian2ba92e32017-08-21 07:05:03 -07001877 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001878 self,
1879 out_addr,
1880 out_port,
1881 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001882 ext_port):
1883 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001884
1885 :param out_addr - outside IP address
1886 :param out_port - outside port
1887 :param ext_addr - external host IP address
1888 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001889 """
1890 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001891 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001892 {'out_addr': out_addr,
1893 'out_port': out_port,
1894 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001895 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001896
Matus Fabian2ba92e32017-08-21 07:05:03 -07001897 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001898 self,
1899 in_addr,
1900 in_port,
1901 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001902 ext_port):
1903 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001904
1905 :param in_addr - inside IP address
1906 :param in_port - inside port
1907 :param ext_addr - external host IP address
1908 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001909 """
1910 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001911 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001912 {'in_addr': in_addr,
1913 'in_port': in_port,
1914 'ext_addr': ext_addr,
1915 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001916 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001917
Matus Fabian2ba92e32017-08-21 07:05:03 -07001918 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001919 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001920 user_addr):
1921 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001922
1923 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001924 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001925 """
1926 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001927 self.papi.nat_det_session_dump,
1928 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001929 'user_addr': user_addr})
1930
Matus Fabian06596c52017-06-06 04:53:28 -07001931 def nat64_add_del_pool_addr_range(
1932 self,
1933 start_addr,
1934 end_addr,
1935 vrf_id=0xFFFFFFFF,
1936 is_add=1):
1937 """Add/del address range to NAT64 pool
1938
1939 :param start_addr: First IP address
1940 :param end_addr: Last IP address
1941 :param vrf_id: VRF id for the address range
1942 :param is_add: 1 if add, 0 if delete (Default value = 1)
1943 """
1944 return self.api(
1945 self.papi.nat64_add_del_pool_addr_range,
1946 {'start_addr': start_addr,
1947 'end_addr': end_addr,
1948 'vrf_id': vrf_id,
1949 'is_add': is_add})
1950
1951 def nat64_pool_addr_dump(self):
1952 """Dump NAT64 pool addresses
1953 :return: Dictionary of NAT64 pool addresses
1954 """
1955 return self.api(self.papi.nat64_pool_addr_dump, {})
1956
1957 def nat64_add_del_interface(
1958 self,
1959 sw_if_index,
1960 is_inside=1,
1961 is_add=1):
1962 """Enable/disable NAT64 feature on the interface
1963 :param sw_if_index: Index of the interface
1964 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1965 :param is_add: 1 if add, 0 if delete (Default value = 1)
1966 """
1967 return self.api(
1968 self.papi.nat64_add_del_interface,
1969 {'sw_if_index': sw_if_index,
1970 'is_inside': is_inside,
1971 'is_add': is_add})
1972
1973 def nat64_interface_dump(self):
1974 """Dump interfaces with NAT64 feature
1975 :return: Dictionary of interfaces with NAT64 feature
1976 """
1977 return self.api(self.papi.nat64_interface_dump, {})
1978
1979 def nat64_add_del_static_bib(
1980 self,
1981 in_ip,
1982 out_ip,
1983 in_port,
1984 out_port,
1985 protocol,
1986 vrf_id=0,
1987 is_add=1):
1988 """Add/delete S-NAT static BIB entry
1989
1990 :param in_ip: Inside IPv6 address
1991 :param out_ip: Outside IPv4 address
1992 :param in_port: Inside port number
1993 :param out_port: Outside port number
1994 :param protocol: IP protocol
1995 :param vrf_id: VRF ID (Default value = 0)
1996 :param is_add: 1 if add, 0 if delete (Default value = 1)
1997 """
1998 return self.api(
1999 self.papi.nat64_add_del_static_bib,
2000 {'i_addr': in_ip,
2001 'o_addr': out_ip,
2002 'i_port': in_port,
2003 'o_port': out_port,
2004 'vrf_id': vrf_id,
2005 'proto': protocol,
2006 'is_add': is_add})
2007
Matus Fabianab9a59c2017-08-16 05:37:36 -07002008 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002009 """Dump NAT64 BIB
2010
Matus Fabianab9a59c2017-08-16 05:37:36 -07002011 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002012 :returns: Dictionary of NAT64 BIB entries
2013 """
2014 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2015
2016 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2017 tcp_incoming_syn=6):
2018 """Set values of timeouts for NAT64 (in seconds)
2019
Matus Fabian428dc912017-06-21 06:15:18 -07002020 :param udpi: UDP timeout (Default value = 300)
2021 :param icmp: ICMP timeout (Default value = 60)
2022 :param tcp_trans: TCP transitory timeout (Default value = 240)
2023 :param tcp_est: TCP established timeout (Default value = 7440)
2024 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002025 """
2026 return self.api(
2027 self.papi.nat64_set_timeouts,
2028 {'udp': udp,
2029 'icmp': icmp,
2030 'tcp_trans': tcp_trans,
2031 'tcp_est': tcp_est,
2032 'tcp_incoming_syn': tcp_incoming_syn})
2033
2034 def nat64_get_timeouts(self):
2035 """Get values of timeouts for NAT64
2036
2037 :return: Timeouts for NAT64 (in seconds)
2038 """
2039 return self.api(self.papi.nat64_get_timeouts, {})
2040
Matus Fabianab9a59c2017-08-16 05:37:36 -07002041 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002042 """Dump NAT64 session table
2043
Matus Fabianab9a59c2017-08-16 05:37:36 -07002044 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002045 :returns: Dictionary of NAT64 sesstion table entries
2046 """
2047 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2048
Matus Fabian428dc912017-06-21 06:15:18 -07002049 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2050 """Add/del NAT64 prefix
2051
2052 :param prefix: NAT64 prefix
2053 :param plen: NAT64 prefix length
2054 :param vrf_id: VRF id of tenant (Default 0)
2055 :param is_add: 1 if add, 0 if delete (Default value = 1)
2056 """
2057 return self.api(
2058 self.papi.nat64_add_del_prefix,
2059 {'prefix': prefix,
2060 'prefix_len': plen,
2061 'vrf_id': vrf_id,
2062 'is_add': is_add})
2063
2064 def nat64_prefix_dump(self):
2065 """Dump NAT64 prefix
2066
2067 :returns: Dictionary of NAT64 prefixes
2068 """
2069 return self.api(self.papi.nat64_prefix_dump, {})
2070
Matus Fabian0938dcf2017-11-08 01:59:38 -08002071 def nat64_add_interface_addr(
2072 self,
2073 sw_if_index,
2074 is_add=1):
2075 """Add/del NAT64 address from interface
2076
2077 :param sw_if_index: Software index of the interface
2078 :param is_add: 1 if add, 0 if delete (Default value = 1)
2079 """
2080 return self.api(self.papi.nat64_add_del_interface_addr,
2081 {'is_add': is_add, 'sw_if_index': sw_if_index})
2082
Matus Fabian8ebe6252017-11-06 05:04:53 -08002083 def dslite_set_aftr_addr(self, ip6, ip4):
2084 """Set DS-Lite AFTR addresses
2085
2086 :param ip4: IPv4 address
2087 :param ip6: IPv6 address
2088 """
2089 return self.api(
2090 self.papi.dslite_set_aftr_addr,
2091 {'ip4_addr': ip4,
2092 'ip6_addr': ip6})
2093
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002094 def dslite_set_b4_addr(self, ip6, ip4):
2095 """Set DS-Lite B4 IPv6 address
2096
2097 :param ip4: IPv4 address
2098 :param ip6: IPv6 address
2099 """
2100 return self.api(
2101 self.papi.dslite_set_b4_addr,
2102 {'ip4_addr': ip4,
2103 'ip6_addr': ip6})
2104
Matus Fabian8ebe6252017-11-06 05:04:53 -08002105 def dslite_add_del_pool_addr_range(
2106 self,
2107 start_addr,
2108 end_addr,
2109 is_add=1):
2110 """Add/del address range to DS-Lite pool
2111
2112 :param start_addr: First IP address
2113 :param end_addr: Last IP address
2114 :param is_add: 1 if add, 0 if delete (Default value = 1)
2115 """
2116 return self.api(
2117 self.papi.dslite_add_del_pool_addr_range,
2118 {'start_addr': start_addr,
2119 'end_addr': end_addr,
2120 'is_add': is_add})
2121
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002122 def nat66_add_del_interface(
2123 self,
2124 sw_if_index,
2125 is_inside=1,
2126 is_add=1):
2127 """Enable/disable NAT66 feature on the interface
2128 :param sw_if_index: Index of the interface
2129 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2130 :param is_add: 1 if add, 0 if delete (Default value = 1)
2131 """
2132 return self.api(
2133 self.papi.nat66_add_del_interface,
2134 {'sw_if_index': sw_if_index,
2135 'is_inside': is_inside,
2136 'is_add': is_add})
2137
2138 def nat66_add_del_static_mapping(
2139 self,
2140 in_ip,
2141 out_ip,
2142 vrf_id=0,
2143 is_add=1):
2144 """Add/delete NAT66 static mapping
2145
2146 :param in_ip: Inside IPv6 address
2147 :param out_ip: Outside IPv6 address
2148 :param vrf_id: VRF ID (Default value = 0)
2149 :param is_add: 1 if add, 0 if delete (Default value = 1)
2150 """
2151 return self.api(
2152 self.papi.nat66_add_del_static_mapping,
2153 {'local_ip_address': in_ip,
2154 'external_ip_address': out_ip,
2155 'vrf_id': vrf_id,
2156 'is_add': is_add})
2157
2158 def nat66_interface_dump(self):
2159 """Dump interfaces with NAT66 feature
2160 :return: Dictionary of interfaces with NAT66 feature
2161 """
2162 return self.api(self.papi.nat66_interface_dump, {})
2163
2164 def nat66_static_mapping_dump(self):
2165 """Dump NAT66 static mappings
2166 :return: Dictionary of NAT66 static mappings
2167 """
2168 return self.api(self.papi.nat66_static_mapping_dump, {})
2169
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002170 def control_ping(self):
2171 self.api(self.papi.control_ping)
2172
2173 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002174 detect_mult, local_addr, peer_addr, is_ipv6=0,
2175 bfd_key_id=None, conf_key_id=None):
2176 if bfd_key_id is None:
2177 return self.api(self.papi.bfd_udp_add,
2178 {
2179 'sw_if_index': sw_if_index,
2180 'desired_min_tx': desired_min_tx,
2181 'required_min_rx': required_min_rx,
2182 'local_addr': local_addr,
2183 'peer_addr': peer_addr,
2184 'is_ipv6': is_ipv6,
2185 'detect_mult': detect_mult,
2186 })
2187 else:
2188 return self.api(self.papi.bfd_udp_add,
2189 {
2190 'sw_if_index': sw_if_index,
2191 'desired_min_tx': desired_min_tx,
2192 'required_min_rx': required_min_rx,
2193 'local_addr': local_addr,
2194 'peer_addr': peer_addr,
2195 'is_ipv6': is_ipv6,
2196 'detect_mult': detect_mult,
2197 'is_authenticated': 1,
2198 'bfd_key_id': bfd_key_id,
2199 'conf_key_id': conf_key_id,
2200 })
2201
Klement Sekeraa57a9702017-02-02 06:58:07 +01002202 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2203 detect_mult, local_addr, peer_addr, is_ipv6=0):
2204 return self.api(self.papi.bfd_udp_mod,
2205 {
2206 'sw_if_index': sw_if_index,
2207 'desired_min_tx': desired_min_tx,
2208 'required_min_rx': required_min_rx,
2209 'local_addr': local_addr,
2210 'peer_addr': peer_addr,
2211 'is_ipv6': is_ipv6,
2212 'detect_mult': detect_mult,
2213 })
2214
Klement Sekerab17dd962017-01-09 07:43:48 +01002215 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2216 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2217 is_delayed=False):
2218 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002219 {
2220 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002221 'local_addr': local_addr,
2222 'peer_addr': peer_addr,
2223 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002224 'is_delayed': 1 if is_delayed else 0,
2225 'bfd_key_id': bfd_key_id,
2226 'conf_key_id': conf_key_id,
2227 })
2228
2229 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2230 is_ipv6=0, is_delayed=False):
2231 return self.api(self.papi.bfd_udp_auth_deactivate,
2232 {
2233 'sw_if_index': sw_if_index,
2234 'local_addr': local_addr,
2235 'peer_addr': peer_addr,
2236 'is_ipv6': is_ipv6,
2237 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002238 })
2239
2240 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2241 return self.api(self.papi.bfd_udp_del,
2242 {
2243 'sw_if_index': sw_if_index,
2244 'local_addr': local_addr,
2245 'peer_addr': peer_addr,
2246 'is_ipv6': is_ipv6,
2247 })
2248
2249 def bfd_udp_session_dump(self):
2250 return self.api(self.papi.bfd_udp_session_dump, {})
2251
Klement Sekerab17dd962017-01-09 07:43:48 +01002252 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2253 peer_addr, is_ipv6=0):
2254 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002255 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002256 'sw_if_index': sw_if_index,
2257 'local_addr': local_addr,
2258 'peer_addr': peer_addr,
2259 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002260 })
2261
2262 def want_bfd_events(self, enable_disable=1):
2263 return self.api(self.papi.want_bfd_events, {
2264 'enable_disable': enable_disable,
2265 'pid': os.getpid(),
2266 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002267
Klement Sekerab17dd962017-01-09 07:43:48 +01002268 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2269 return self.api(self.papi.bfd_auth_set_key, {
2270 'conf_key_id': conf_key_id,
2271 'auth_type': auth_type,
2272 'key': key,
2273 'key_len': len(key),
2274 })
2275
2276 def bfd_auth_del_key(self, conf_key_id):
2277 return self.api(self.papi.bfd_auth_del_key, {
2278 'conf_key_id': conf_key_id,
2279 })
2280
2281 def bfd_auth_keys_dump(self):
2282 return self.api(self.papi.bfd_auth_keys_dump, {})
2283
Klement Sekera239790f2017-02-16 10:53:53 +01002284 def bfd_udp_set_echo_source(self, sw_if_index):
2285 return self.api(self.papi.bfd_udp_set_echo_source,
2286 {'sw_if_index': sw_if_index})
2287
Klement Sekera73884482017-02-23 09:26:30 +01002288 def bfd_udp_del_echo_source(self):
2289 return self.api(self.papi.bfd_udp_del_echo_source, {})
2290
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002291 def bfd_udp_get_echo_source(self):
2292 return self.api(self.papi.bfd_udp_get_echo_source, {})
2293
Steve Shin7957d6e2016-12-19 09:24:50 -08002294 def classify_add_del_table(
2295 self,
2296 is_add,
2297 mask,
2298 match_n_vectors=1,
2299 table_index=0xFFFFFFFF,
2300 nbuckets=2,
2301 memory_size=2097152,
2302 skip_n_vectors=0,
2303 next_table_index=0xFFFFFFFF,
2304 miss_next_index=0xFFFFFFFF,
2305 current_data_flag=0,
2306 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002307 """
2308 :param is_add:
2309 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002310 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002311 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002312 :param nbuckets: (Default value = 2)
2313 :param memory_size: (Default value = 2097152)
2314 :param skip_n_vectors: (Default value = 0)
2315 :param next_table_index: (Default value = 0xFFFFFFFF)
2316 :param miss_next_index: (Default value = 0xFFFFFFFF)
2317 :param current_data_flag: (Default value = 0)
2318 :param current_data_offset: (Default value = 0)
2319 """
2320
Juraj Sloboda75282452018-06-12 14:20:49 +02002321 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2322 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002323 return self.api(
2324 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002325 {'is_add': is_add,
2326 'table_index': table_index,
2327 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002328 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002329 'skip_n_vectors': skip_n_vectors,
2330 'match_n_vectors': match_n_vectors,
2331 'next_table_index': next_table_index,
2332 'miss_next_index': miss_next_index,
2333 'current_data_flag': current_data_flag,
2334 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002335 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002336 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002337
2338 def classify_add_del_session(
2339 self,
2340 is_add,
2341 table_index,
2342 match,
2343 opaque_index=0xFFFFFFFF,
2344 hit_next_index=0xFFFFFFFF,
2345 advance=0,
2346 action=0,
2347 metadata=0):
2348 """
2349 :param is_add:
2350 :param table_index:
2351 :param match:
2352 :param opaque_index: (Default value = 0xFFFFFFFF)
2353 :param hit_next_index: (Default value = 0xFFFFFFFF)
2354 :param advance: (Default value = 0)
2355 :param action: (Default value = 0)
2356 :param metadata: (Default value = 0)
2357 """
2358
Juraj Sloboda75282452018-06-12 14:20:49 +02002359 match_len = ((len(match) - 1) / 16 + 1) * 16
2360 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002361 return self.api(
2362 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002363 {'is_add': is_add,
2364 'table_index': table_index,
2365 'hit_next_index': hit_next_index,
2366 'opaque_index': opaque_index,
2367 'advance': advance,
2368 'action': action,
2369 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002370 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002371 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002372
2373 def input_acl_set_interface(
2374 self,
2375 is_add,
2376 sw_if_index,
2377 ip4_table_index=0xFFFFFFFF,
2378 ip6_table_index=0xFFFFFFFF,
2379 l2_table_index=0xFFFFFFFF):
2380 """
2381 :param is_add:
2382 :param sw_if_index:
2383 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2384 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2385 :param l2_table_index: (Default value = 0xFFFFFFFF)
2386 """
2387
2388 return self.api(
2389 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002390 {'sw_if_index': sw_if_index,
2391 'ip4_table_index': ip4_table_index,
2392 'ip6_table_index': ip6_table_index,
2393 'l2_table_index': l2_table_index,
2394 'is_add': is_add})
2395
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002396 def output_acl_set_interface(
2397 self,
2398 is_add,
2399 sw_if_index,
2400 ip4_table_index=0xFFFFFFFF,
2401 ip6_table_index=0xFFFFFFFF,
2402 l2_table_index=0xFFFFFFFF):
2403 """
2404 :param is_add:
2405 :param sw_if_index:
2406 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2407 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2408 :param l2_table_index: (Default value = 0xFFFFFFFF)
2409 """
2410
2411 return self.api(
2412 self.papi.output_acl_set_interface,
2413 {'sw_if_index': sw_if_index,
2414 'ip4_table_index': ip4_table_index,
2415 'ip6_table_index': ip6_table_index,
2416 'l2_table_index': l2_table_index,
2417 'is_add': is_add})
2418
Klement Sekera77fabdb2017-01-02 07:46:14 +01002419 def set_ipfix_exporter(
2420 self,
2421 collector_address,
2422 src_address,
2423 path_mtu,
2424 template_interval,
2425 vrf_id=0,
2426 collector_port=4739,
2427 udp_checksum=0):
2428 return self.api(
2429 self.papi.set_ipfix_exporter,
2430 {
2431 'collector_address': collector_address,
2432 'collector_port': collector_port,
2433 'src_address': src_address,
2434 'vrf_id': vrf_id,
2435 'path_mtu': path_mtu,
2436 'template_interval': template_interval,
2437 'udp_checksum': udp_checksum,
2438 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002439
2440 def dhcp_proxy_config(self,
2441 dhcp_server,
2442 dhcp_src_address,
2443 rx_table_id=0,
2444 server_table_id=0,
2445 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002446 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002447 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002448 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002449 {
2450 'rx_vrf_id': rx_table_id,
2451 'server_vrf_id': server_table_id,
2452 'is_ipv6': is_ipv6,
2453 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002454 'dhcp_server': dhcp_server,
2455 'dhcp_src_address': dhcp_src_address,
2456 })
2457
2458 def dhcp_proxy_set_vss(self,
2459 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002460 vss_type=255,
2461 vpn_ascii_id="",
2462 oui=0,
2463 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002464 is_add=1,
2465 is_ip6=0):
2466 return self.api(
2467 self.papi.dhcp_proxy_set_vss,
2468 {
2469 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002470 'vss_type': vss_type,
2471 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002472 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002473 'vpn_index': vpn_index,
2474 'is_add': is_add,
2475 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002476 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002477
Neale Rannsdaff1782018-05-16 04:12:18 -07002478 def dhcp_client_dump(self):
2479 return self.api(self.papi.dhcp_client_dump, {})
2480
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002481 def dhcp_client(self,
2482 sw_if_index,
2483 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002484 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002485 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002486 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002487 want_dhcp_events=0):
2488 return self.api(
2489 self.papi.dhcp_client_config,
2490 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002491 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002492 'client': {
2493 'sw_if_index': sw_if_index,
2494 'hostname': hostname,
2495 'id': client_id,
2496 'want_dhcp_event': want_dhcp_events,
2497 'set_broadcast_flag': set_broadcast_flag,
2498 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002499 })
2500
Neale Ranns32e1c012016-11-22 17:07:28 +00002501 def ip_mroute_add_del(self,
2502 src_address,
2503 grp_address,
2504 grp_address_length,
2505 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002506 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002507 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002508 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002509 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002510 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002511 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002512 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002513 is_add=1,
2514 is_ipv6=0,
2515 is_local=0):
2516 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002517 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002518 """
2519 return self.api(
2520 self.papi.ip_mroute_add_del,
2521 {'next_hop_sw_if_index': next_hop_sw_if_index,
2522 'entry_flags': e_flags,
2523 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002524 'table_id': table_id,
2525 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002526 'is_add': is_add,
2527 'is_ipv6': is_ipv6,
2528 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002529 'bier_imp': bier_imp,
2530 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002531 'grp_address_length': grp_address_length,
2532 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002533 'src_address': src_address,
2534 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002535
2536 def mfib_signal_dump(self):
2537 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002538
2539 def ip_mfib_dump(self):
2540 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002541
Neale Rannsd792d9c2017-10-21 10:53:20 -07002542 def ip6_mfib_dump(self):
2543 return self.api(self.papi.ip6_mfib_dump, {})
2544
Filip Tehlar770e89e2017-01-31 10:39:16 +01002545 def lisp_enable_disable(self, is_enabled):
2546 return self.api(
2547 self.papi.lisp_enable_disable,
2548 {
2549 'is_en': is_enabled,
2550 })
2551
2552 def lisp_locator_set(self,
2553 ls_name,
2554 is_add=1):
2555 return self.api(
2556 self.papi.lisp_add_del_locator_set,
2557 {
2558 'is_add': is_add,
2559 'locator_set_name': ls_name
2560 })
2561
2562 def lisp_locator_set_dump(self):
2563 return self.api(self.papi.lisp_locator_set_dump, {})
2564
2565 def lisp_locator(self,
2566 ls_name,
2567 sw_if_index,
2568 priority=1,
2569 weight=1,
2570 is_add=1):
2571 return self.api(
2572 self.papi.lisp_add_del_locator,
2573 {
2574 'is_add': is_add,
2575 'locator_set_name': ls_name,
2576 'sw_if_index': sw_if_index,
2577 'priority': priority,
2578 'weight': weight
2579 })
2580
2581 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2582 return self.api(
2583 self.papi.lisp_locator_dump,
2584 {
2585 'is_index_set': is_index_set,
2586 'ls_name': ls_name,
2587 'ls_index': ls_index,
2588 })
2589
2590 def lisp_local_mapping(self,
2591 ls_name,
2592 eid_type,
2593 eid,
2594 prefix_len,
2595 vni=0,
2596 key_id=0,
2597 key="",
2598 is_add=1):
2599 return self.api(
2600 self.papi.lisp_add_del_local_eid,
2601 {
2602 'locator_set_name': ls_name,
2603 'is_add': is_add,
2604 'eid_type': eid_type,
2605 'eid': eid,
2606 'prefix_len': prefix_len,
2607 'vni': vni,
2608 'key_id': key_id,
2609 'key': key
2610 })
2611
2612 def lisp_eid_table_dump(self,
2613 eid_set=0,
2614 prefix_length=0,
2615 vni=0,
2616 eid_type=0,
2617 eid=None,
2618 filter_opt=0):
2619 return self.api(
2620 self.papi.lisp_eid_table_dump,
2621 {
2622 'eid_set': eid_set,
2623 'prefix_length': prefix_length,
2624 'vni': vni,
2625 'eid_type': eid_type,
2626 'eid': eid,
2627 'filter': filter_opt,
2628 })
2629
2630 def lisp_remote_mapping(self,
2631 eid_type,
2632 eid,
2633 eid_prefix_len=0,
2634 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002635 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002636 rlocs_num=0,
2637 is_src_dst=0,
2638 is_add=1):
2639 return self.api(
2640 self.papi.lisp_add_del_remote_mapping,
2641 {
2642 'is_add': is_add,
2643 'eid_type': eid_type,
2644 'eid': eid,
2645 'eid_len': eid_prefix_len,
2646 'rloc_num': rlocs_num,
2647 'rlocs': rlocs,
2648 'vni': vni,
2649 'is_src_dst': is_src_dst,
2650 })
2651
2652 def lisp_adjacency(self,
2653 leid,
2654 reid,
2655 leid_len,
2656 reid_len,
2657 eid_type,
2658 is_add=1,
2659 vni=0):
2660 return self.api(
2661 self.papi.lisp_add_del_adjacency,
2662 {
2663 'is_add': is_add,
2664 'vni': vni,
2665 'eid_type': eid_type,
2666 'leid': leid,
2667 'reid': reid,
2668 'leid_len': leid_len,
2669 'reid_len': reid_len,
2670 })
2671
2672 def lisp_adjacencies_get(self, vni=0):
2673 return self.api(
2674 self.papi.lisp_adjacencies_get,
2675 {
2676 'vni': vni
2677 })
Neale Ranns80823802017-02-20 18:23:41 -08002678
2679 def map_add_domain(self,
2680 ip6_prefix,
2681 ip6_prefix_len,
2682 ip6_src,
2683 ip6_src_prefix_len,
2684 ip4_prefix,
2685 ip4_prefix_len,
2686 ea_bits_len=0,
2687 psid_offset=0,
2688 psid_length=0,
2689 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002690 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002691 mtu=1280):
2692 return self.api(
2693 self.papi.map_add_domain,
2694 {
2695 'ip6_prefix': ip6_prefix,
2696 'ip6_prefix_len': ip6_prefix_len,
2697 'ip4_prefix': ip4_prefix,
2698 'ip4_prefix_len': ip4_prefix_len,
2699 'ip6_src': ip6_src,
2700 'ip6_src_prefix_len': ip6_src_prefix_len,
2701 'ea_bits_len': ea_bits_len,
2702 'psid_offset': psid_offset,
2703 'psid_length': psid_length,
2704 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002705 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002706 'mtu': mtu
2707 })
Hongjun Nief486b12017-04-12 19:21:16 +08002708
2709 def gtpu_add_del_tunnel(
2710 self,
2711 src_addr,
2712 dst_addr,
2713 is_add=1,
2714 is_ipv6=0,
2715 mcast_sw_if_index=0xFFFFFFFF,
2716 encap_vrf_id=0,
2717 decap_next_index=0xFFFFFFFF,
2718 teid=0):
2719 """
2720
2721 :param is_add: (Default value = 1)
2722 :param is_ipv6: (Default value = 0)
2723 :param src_addr:
2724 :param dst_addr:
2725 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2726 :param encap_vrf_id: (Default value = 0)
2727 :param decap_next_index: (Default value = 0xFFFFFFFF)
2728 :param teid: (Default value = 0)
2729
2730 """
2731 return self.api(self.papi.gtpu_add_del_tunnel,
2732 {'is_add': is_add,
2733 'is_ipv6': is_ipv6,
2734 'src_address': src_addr,
2735 'dst_address': dst_addr,
2736 'mcast_sw_if_index': mcast_sw_if_index,
2737 'encap_vrf_id': encap_vrf_id,
2738 'decap_next_index': decap_next_index,
2739 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002740
2741 def vxlan_gpe_add_del_tunnel(
2742 self,
2743 src_addr,
2744 dst_addr,
2745 mcast_sw_if_index=0xFFFFFFFF,
2746 is_add=1,
2747 is_ipv6=0,
2748 encap_vrf_id=0,
2749 decap_vrf_id=0,
2750 protocol=3,
2751 vni=0):
2752 """
2753
2754 :param local:
2755 :param remote:
2756 :param is_add: (Default value = 1)
2757 :param is_ipv6: (Default value = 0)
2758 :param encap_vrf_id: (Default value = 0)
2759 :param decap_vrf_id: (Default value = 0)
2760 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2761 :param protocol: (Default value = 3)
2762 :param vni: (Default value = 0)
2763
2764 """
2765 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2766 {'is_add': is_add,
2767 'is_ipv6': is_ipv6,
2768 'local': src_addr,
2769 'remote': dst_addr,
2770 'mcast_sw_if_index': mcast_sw_if_index,
2771 'encap_vrf_id': encap_vrf_id,
2772 'decap_vrf_id': decap_vrf_id,
2773 'protocol': protocol,
2774 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002775
Neale Ranns79a05f52018-09-11 07:39:43 -07002776 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002777 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002778 src,
2779 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002780 mcast_sw_if_index=0xFFFFFFFF,
2781 is_add=1,
2782 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002783 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002784 vni=0,
2785 instance=0xFFFFFFFF):
2786 """
2787
2788 :param dst_addr:
2789 :param src_addr:
2790 :param is_add: (Default value = 1)
2791 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002792 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002793 :param decap_next_index: (Default value = 0xFFFFFFFF)
2794 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2795 :param vni: (Default value = 0)
2796 :param instance: (Default value = 0xFFFFFFFF)
2797
2798 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002799 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002800 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002801 'tunnel': {
2802 'src': src,
2803 'dst': dst,
2804 'mcast_sw_if_index': mcast_sw_if_index,
2805 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07002806 'vni': vni,
2807 'instance': instance}})
2808
2809 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2810 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2811 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002812
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002813 def pppoe_add_del_session(
2814 self,
2815 client_ip,
2816 client_mac,
2817 session_id=0,
2818 is_add=1,
2819 is_ipv6=0,
2820 decap_vrf_id=0):
2821 """
2822
2823 :param is_add: (Default value = 1)
2824 :param is_ipv6: (Default value = 0)
2825 :param client_ip:
2826 :param session_id: (Default value = 0)
2827 :param client_mac:
2828 :param decap_vrf_id: (Default value = 0)
2829
2830 """
2831 return self.api(self.papi.pppoe_add_del_session,
2832 {'is_add': is_add,
2833 'is_ipv6': is_ipv6,
2834 'session_id': session_id,
2835 'client_ip': client_ip,
2836 'decap_vrf_id': decap_vrf_id,
2837 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002838
Neale Ranns7c922dc2018-08-30 06:12:27 -07002839 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2840 return self.api(self.papi.sr_mpls_policy_add,
2841 {'bsid': bsid,
2842 'weight': weight,
2843 'type': type,
2844 'n_segments': len(segments),
2845 'segments': segments})
2846
2847 def sr_mpls_policy_del(self, bsid):
2848 return self.api(self.papi.sr_mpls_policy_del,
2849 {'bsid': bsid})
2850
Kris Michielsen91074432017-06-22 13:00:20 +02002851 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002852 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002853 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002854 nh_addr4,
2855 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002856 is_del=0,
2857 end_psp=0,
2858 sw_if_index=0xFFFFFFFF,
2859 vlan_index=0,
2860 fib_table=0,
2861 ):
2862 """ Add/del IPv6 SR local-SID.
2863
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002864 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002865 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2866 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002867 :param nh_addr4:
2868 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002869 :param is_del: (Default value = 0)
2870 :param end_psp: (Default value = 0)
2871 :param sw_if_index: (Default value = 0xFFFFFFFF)
2872 :param vlan_index: (Default value = 0)
2873 :param fib_table: (Default value = 0)
2874 """
2875 return self.api(
2876 self.papi.sr_localsid_add_del,
2877 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002878 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002879 'end_psp': end_psp,
2880 'behavior': behavior,
2881 'sw_if_index': sw_if_index,
2882 'vlan_index': vlan_index,
2883 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002884 'nh_addr4': nh_addr4,
2885 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002886 }
2887 )
2888
2889 def sr_policy_add(
2890 self,
2891 bsid_addr,
2892 weight=1,
2893 is_encap=1,
2894 type=0,
2895 fib_table=0,
2896 n_segments=0,
2897 segments=[]):
2898 """
2899 :param bsid_addr: bindingSID of the SR Policy
2900 :param weight: weight of the sid list. optional. (default: 1)
2901 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2902 (default: Encap)
2903 :param type: type/behavior of the SR policy. (default or spray) \
2904 (default: default)
2905 :param fib_table: VRF where to install the FIB entry for the BSID \
2906 (default: 0)
2907 :param n_segments: number of segments \
2908 (default: 0)
2909 :param segments: a vector of IPv6 address composing the segment list \
2910 (default: [])
2911 """
2912 return self.api(
2913 self.papi.sr_policy_add,
2914 {'bsid_addr': bsid_addr,
2915 'weight': weight,
2916 'is_encap': is_encap,
2917 'type': type,
2918 'fib_table': fib_table,
2919 'n_segments': n_segments,
2920 'segments': segments
2921 }
2922 )
2923
2924 def sr_policy_del(
2925 self,
2926 bsid_addr,
2927 sr_policy_index=0):
2928 """
2929 :param bsid: bindingSID of the SR Policy
2930 :param sr_policy_index: index of the sr policy (default: 0)
2931 """
2932 return self.api(
2933 self.papi.sr_policy_del,
2934 {'bsid_addr': bsid_addr,
2935 'sr_policy_index': sr_policy_index
2936 })
2937
2938 def sr_steering_add_del(
2939 self,
2940 is_del,
2941 bsid_addr,
2942 sr_policy_index,
2943 table_id,
2944 prefix_addr,
2945 mask_width,
2946 sw_if_index,
2947 traffic_type):
2948 """
2949 Steer traffic L2 and L3 traffic through a given SR policy
2950
2951 :param is_del: delete or add
2952 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2953 :param sr_policy: is the index of the SR Policy (alt to bsid)
2954 :param table_id: is the VRF where to install the FIB entry for the BSID
2955 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2956 :param mask_width: is the mask for L3 traffic type
2957 :param sw_if_index: is the incoming interface for L2 traffic
2958 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2959 """
2960 return self.api(
2961 self.papi.sr_steering_add_del,
2962 {'is_del': is_del,
2963 'bsid_addr': bsid_addr,
2964 'sr_policy_index': sr_policy_index,
2965 'table_id': table_id,
2966 'prefix_addr': prefix_addr,
2967 'mask_width': mask_width,
2968 'sw_if_index': sw_if_index,
2969 'traffic_type': traffic_type
2970 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002971
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002972 def acl_add_replace(self, acl_index, r, tag='',
2973 expected_retval=0):
2974 """Add/replace an ACL
2975 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2976 :param acl_rule r: ACL rules array.
2977 :param str tag: symbolic tag (description) for this ACL.
2978 :param int count: number of rules.
2979 """
2980 return self.api(self.papi.acl_add_replace,
2981 {'acl_index': acl_index,
2982 'r': r,
2983 'count': len(r),
2984 'tag': tag},
2985 expected_retval=expected_retval)
2986
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002987 def acl_del(self, acl_index, expected_retval=0):
2988 """
2989
2990 :param acl_index:
2991 :return:
2992 """
2993 return self.api(self.papi.acl_del,
2994 {'acl_index': acl_index},
2995 expected_retval=expected_retval)
2996
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002997 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2998 expected_retval=0):
2999 return self.api(self.papi.acl_interface_set_acl_list,
3000 {'sw_if_index': sw_if_index,
3001 'count': len(acls),
3002 'n_input': n_input,
3003 'acls': acls},
3004 expected_retval=expected_retval)
3005
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01003006 def acl_interface_set_etype_whitelist(self, sw_if_index,
3007 n_input, whitelist,
3008 expected_retval=0):
3009 return self.api(self.papi.acl_interface_set_etype_whitelist,
3010 {'sw_if_index': sw_if_index,
3011 'count': len(whitelist),
3012 'n_input': n_input,
3013 'whitelist': whitelist},
3014 expected_retval=expected_retval)
3015
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003016 def acl_interface_add_del(self,
3017 sw_if_index,
3018 acl_index,
3019 is_add=1):
3020 """ Add/Delete ACL to/from interface
3021
3022 :param sw_if_index:
3023 :param acl_index:
3024 :param is_add: (Default value = 1)
3025 """
3026
3027 return self.api(self.papi.acl_interface_add_del,
3028 {'is_add': is_add,
3029 'is_input': 1,
3030 'sw_if_index': sw_if_index,
3031 'acl_index': acl_index})
3032
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003033 def acl_dump(self, acl_index, expected_retval=0):
3034 return self.api(self.papi.acl_dump,
3035 {'acl_index': acl_index},
3036 expected_retval=expected_retval)
3037
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003038 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3039 expected_retval=0):
3040 return self.api(self.papi.acl_interface_list_dump,
3041 {'sw_if_index': sw_if_index},
3042 expected_retval=expected_retval)
3043
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003044 def macip_acl_add(self, rules, tag=""):
3045 """ Add MACIP acl
3046
3047 :param rules: list of rules for given acl
3048 :param tag: acl tag
3049 """
3050
3051 return self.api(self.papi.macip_acl_add,
3052 {'r': rules,
3053 'count': len(rules),
3054 'tag': tag})
3055
Pavel Kotucek932f7412017-09-07 14:44:52 +02003056 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3057 """ Add MACIP acl
3058
3059 :param rules: list of rules for given acl
3060 :param tag: acl tag
3061 """
3062
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003063 return self.api(self.papi.macip_acl_add_replace,
3064 {'acl_index': acl_index,
3065 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003066 'count': len(rules),
3067 'tag': tag})
3068
3069 def macip_acl_del(self, acl_index):
3070 """
3071
3072 :param acl_index:
3073 :return:
3074 """
3075 return self.api(self.papi.macip_acl_del,
3076 {'acl_index': acl_index})
3077
3078 def macip_acl_interface_add_del(self,
3079 sw_if_index,
3080 acl_index,
3081 is_add=1):
3082 """ Add MACIP acl to interface
3083
3084 :param sw_if_index:
3085 :param acl_index:
3086 :param is_add: (Default value = 1)
3087 """
3088
3089 return self.api(self.papi.macip_acl_interface_add_del,
3090 {'is_add': is_add,
3091 'sw_if_index': sw_if_index,
3092 'acl_index': acl_index})
3093
3094 def macip_acl_interface_get(self):
3095 """ Return interface acls dump
3096 """
3097 return self.api(
3098 self.papi.macip_acl_interface_get, {})
3099
3100 def macip_acl_dump(self, acl_index=4294967295):
3101 """ Return MACIP acl dump
3102 """
3103
3104 return self.api(
3105 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003106
3107 def policer_add_del(self,
3108 name,
3109 cir,
3110 eir,
3111 cb,
3112 eb,
3113 is_add=1,
3114 rate_type=0,
3115 round_type=0,
3116 ptype=0,
3117 color_aware=0,
3118 conform_action_type=1,
3119 conform_dscp=0,
3120 exceed_action_type=0,
3121 exceed_dscp=0,
3122 violate_action_type=0,
3123 violate_dscp=0):
3124 return self.api(self.papi.policer_add_del,
3125 {'name': name,
3126 'cir': cir,
3127 'eir': eir,
3128 'cb': cb,
3129 'eb': eb,
3130 'is_add': is_add,
3131 'rate_type': rate_type,
3132 'round_type': round_type,
3133 'type': ptype,
3134 'color_aware': color_aware,
3135 'conform_action_type': conform_action_type,
3136 'conform_dscp': conform_dscp,
3137 'exceed_action_type': exceed_action_type,
3138 'exceed_dscp': exceed_dscp,
3139 'violate_action_type': violate_action_type,
3140 'violate_dscp': violate_dscp})
3141
3142 def ip_punt_police(self,
3143 policer_index,
3144 is_ip6=0,
3145 is_add=1):
3146 return self.api(self.papi.ip_punt_police,
3147 {'policer_index': policer_index,
3148 'is_add': is_add,
3149 'is_ip6': is_ip6})
3150
3151 def ip_punt_redirect(self,
3152 rx_sw_if_index,
3153 tx_sw_if_index,
3154 nh,
3155 is_ip6=0,
3156 is_add=1):
3157 return self.api(self.papi.ip_punt_redirect,
3158 {'rx_sw_if_index': rx_sw_if_index,
3159 'tx_sw_if_index': tx_sw_if_index,
3160 'nh': nh,
3161 'is_add': is_add,
3162 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003163
3164 def bier_table_add_del(self,
3165 bti,
3166 mpls_label,
3167 is_add=1):
3168 """ BIER Table add/del """
3169 return self.api(
3170 self.papi.bier_table_add_del,
3171 {'bt_tbl_id': {"bt_set": bti.set_id,
3172 "bt_sub_domain": bti.sub_domain_id,
3173 "bt_hdr_len_id": bti.hdr_len_id},
3174 'bt_label': mpls_label,
3175 'bt_is_add': is_add})
3176
3177 def bier_table_dump(self):
3178 return self.api(self.papi.bier_table_dump, {})
3179
3180 def bier_route_add_del(self,
3181 bti,
3182 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003183 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003184 is_add=1,
3185 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003186 """ BIER Route add/del """
3187 return self.api(
3188 self.papi.bier_route_add_del,
3189 {'br_tbl_id': {"bt_set": bti.set_id,
3190 "bt_sub_domain": bti.sub_domain_id,
3191 "bt_hdr_len_id": bti.hdr_len_id},
3192 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003193 'br_n_paths': len(paths),
3194 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003195 'br_is_add': is_add,
3196 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003197
3198 def bier_route_dump(self, bti):
3199 return self.api(
3200 self.papi.bier_route_dump,
3201 {'br_tbl_id': {"bt_set": bti.set_id,
3202 "bt_sub_domain": bti.sub_domain_id,
3203 "bt_hdr_len_id": bti.hdr_len_id}})
3204
3205 def bier_imp_add(self,
3206 bti,
3207 src,
3208 ibytes,
3209 is_add=1):
3210 """ BIER Imposition Add """
3211 return self.api(
3212 self.papi.bier_imp_add,
3213 {'bi_tbl_id': {"bt_set": bti.set_id,
3214 "bt_sub_domain": bti.sub_domain_id,
3215 "bt_hdr_len_id": bti.hdr_len_id},
3216 'bi_src': src,
3217 'bi_n_bytes': len(ibytes),
3218 'bi_bytes': ibytes})
3219
3220 def bier_imp_del(self, bi_index):
3221 """ BIER Imposition del """
3222 return self.api(
3223 self.papi.bier_imp_del,
3224 {'bi_index': bi_index})
3225
3226 def bier_imp_dump(self):
3227 return self.api(self.papi.bier_imp_dump, {})
3228
3229 def bier_disp_table_add_del(self,
3230 bdti,
3231 is_add=1):
3232 """ BIER Disposition Table add/del """
3233 return self.api(
3234 self.papi.bier_disp_table_add_del,
3235 {'bdt_tbl_id': bdti,
3236 'bdt_is_add': is_add})
3237
3238 def bier_disp_table_dump(self):
3239 return self.api(self.papi.bier_disp_table_dump, {})
3240
3241 def bier_disp_entry_add_del(self,
3242 bdti,
3243 bp,
3244 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003245 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003246 next_hop,
3247 next_hop_tbl_id=0,
3248 next_hop_rpf_id=~0,
3249 next_hop_is_ip4=1,
3250 is_add=1):
3251 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003252 lstack = []
3253 while (len(lstack) < 16):
3254 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003255 return self.api(
3256 self.papi.bier_disp_entry_add_del,
3257 {'bde_tbl_id': bdti,
3258 'bde_bp': bp,
3259 'bde_payload_proto': payload_proto,
3260 'bde_n_paths': 1,
3261 'bde_paths': [{'next_hop': next_hop,
3262 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003263 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003264 'rpf_id': next_hop_rpf_id,
3265 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003266 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003267 'bde_is_add': is_add})
3268
3269 def bier_disp_entry_dump(self, bdti):
3270 return self.api(
3271 self.papi.bier_disp_entry_dump,
3272 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003273
3274 def add_node_next(self, node_name, next_name):
3275 """ Set the next node for a given node request
3276
3277 :param node_name:
3278 :param next_name:
3279 """
3280 return self.api(self.papi.add_node_next,
3281 {'node_name': node_name,
3282 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003283
3284 def session_enable_disable(self, is_enabled):
3285 return self.api(
3286 self.papi.session_enable_disable,
3287 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003288
3289 def ipsec_spd_add_del(self, spd_id, is_add=1):
3290 """ SPD add/del - Wrapper to add or del ipsec SPD
3291 Sample CLI : 'ipsec spd add 1'
3292
3293 :param spd_id - SPD ID to be created in the vpp . mandatory
3294 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3295 optional
3296 :returns: reply from the API
3297 """
3298 return self.api(
3299 self.papi.ipsec_spd_add_del, {
3300 'spd_id': spd_id, 'is_add': is_add})
3301
3302 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3303 """ IPSEC interface SPD add/del - \
3304 Wrapper to associate/disassociate SPD to interface in VPP
3305 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3306
3307 :param spd_id - SPD ID to associate with the interface . mandatory
3308 :param sw_if_index - Interface Index which needs to ipsec \
3309 association mandatory
3310 :param is_add - add(1) or del(0) association with interface \
3311 (Default 1 - add) . optional
3312 :returns: reply from the API
3313 """
3314 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003315 self.papi.ipsec_interface_add_del_spd,
3316 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003317
3318 def ipsec_sad_add_del_entry(self,
3319 sad_id,
3320 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003321 integrity_algorithm,
3322 integrity_key,
3323 crypto_algorithm,
3324 crypto_key,
3325 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003326 tunnel_src_address='',
3327 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003328 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003329 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003330 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003331 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003332 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003333 :param sad_id: security association ID
3334 :param spi: security param index of the SA in decimal
3335 :param integrity_algorithm:
3336 :param integrity_key:
3337 :param crypto_algorithm:
3338 :param crypto_key:
3339 :param protocol: AH(0) or ESP(1) protocol
3340 :param tunnel_src_address: tunnel mode outer src address
3341 :param tunnel_dst_address: tunnel mode outer dst address
3342 :param is_add:
3343 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003344 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3345 crypto and ipsec algorithms
3346 """
3347 return self.api(
3348 self.papi.ipsec_sad_add_del_entry,
3349 {'sad_id': sad_id,
3350 'spi': spi,
3351 'tunnel_src_address': tunnel_src_address,
3352 'tunnel_dst_address': tunnel_dst_address,
3353 'protocol': protocol,
3354 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003355 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003356 'integrity_key': integrity_key,
3357 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003358 'crypto_key_length': len(crypto_key) if crypto_key is not None
3359 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003360 'crypto_key': crypto_key,
3361 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003362 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003363 'is_tunnel_ipv6': is_tunnel_ipv6,
Klement Sekera4b089f22018-04-17 18:04:57 +02003364 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003365
3366 def ipsec_spd_add_del_entry(self,
3367 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003368 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003369 local_address_start,
3370 local_address_stop,
3371 remote_address_start,
3372 remote_address_stop,
3373 local_port_start=0,
3374 local_port_stop=65535,
3375 remote_port_start=0,
3376 remote_port_stop=65535,
3377 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003378 policy=0,
3379 priority=100,
3380 is_outbound=1,
3381 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003382 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003383 is_ip_any=0):
3384 """ IPSEC policy SPD add/del -
3385 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003386 :param spd_id: SPD ID for the policy
3387 :param local_address_start: local-ip-range start address
3388 :param local_address_stop : local-ip-range stop address
3389 :param remote_address_start: remote-ip-range start address
3390 :param remote_address_stop : remote-ip-range stop address
3391 :param local_port_start: (Default value = 0)
3392 :param local_port_stop: (Default value = 65535)
3393 :param remote_port_start: (Default value = 0)
3394 :param remote_port_stop: (Default value = 65535)
3395 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3396 :param sa_id: Security Association ID for mapping it to SPD
3397 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3398 (Default value = 0)
3399 :param priority: value for the spd action (Default value = 100)
3400 :param is_outbound: flag for inbound(0) or outbound(1)
3401 (Default value = 1)
3402 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003403 """
3404 return self.api(
3405 self.papi.ipsec_spd_add_del_entry,
3406 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003407 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003408 'local_address_start': local_address_start,
3409 'local_address_stop': local_address_stop,
3410 'remote_address_start': remote_address_start,
3411 'remote_address_stop': remote_address_stop,
3412 'local_port_start': local_port_start,
3413 'local_port_stop': local_port_stop,
3414 'remote_port_start': remote_port_start,
3415 'remote_port_stop': remote_port_stop,
3416 'is_add': is_add,
3417 'protocol': protocol,
3418 'policy': policy,
3419 'priority': priority,
3420 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003421 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003422 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003423
Klement Sekera31da2e32018-06-24 22:49:55 +02003424 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3425 remote_spi, crypto_alg, local_crypto_key,
3426 remote_crypto_key, integ_alg, local_integ_key,
3427 remote_integ_key, is_add=1, esn=0,
3428 anti_replay=1, renumber=0, show_instance=0):
3429 return self.api(
3430 self.papi.ipsec_tunnel_if_add_del,
3431 {'local_ip': local_ip, 'remote_ip': remote_ip,
3432 'local_spi': local_spi, 'remote_spi': remote_spi,
3433 'crypto_alg': crypto_alg,
3434 'local_crypto_key_len': len(local_crypto_key),
3435 'local_crypto_key': local_crypto_key,
3436 'remote_crypto_key_len': len(remote_crypto_key),
3437 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3438 'local_integ_key_len': len(local_integ_key),
3439 'local_integ_key': local_integ_key,
3440 'remote_integ_key_len': len(remote_integ_key),
3441 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3442 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3443 'show_instance': show_instance
3444 })
3445
Florin Corasb795bd02017-12-14 11:30:48 -08003446 def app_namespace_add(self,
3447 namespace_id,
3448 ip4_fib_id=0,
3449 ip6_fib_id=0,
3450 sw_if_index=0xFFFFFFFF,
3451 secret=0):
3452 return self.api(
3453 self.papi.app_namespace_add_del,
3454 {'secret': secret,
3455 'sw_if_index': sw_if_index,
3456 'ip4_fib_id': ip4_fib_id,
3457 'ip6_fib_id': ip6_fib_id,
3458 'namespace_id': namespace_id,
3459 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003460
3461 def punt_socket_register(self, l4_port, pathname, header_version=1,
3462 is_ip4=1, l4_protocol=0x11):
3463 """ Punt to socket """
3464 return self.api(self.papi.punt_socket_register,
3465 {'is_ip4': is_ip4,
3466 'l4_protocol': l4_protocol,
3467 'l4_port': l4_port,
3468 'pathname': pathname,
3469 'header_version': header_version})
3470
3471 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3472 expire_walk_interval_ms, is_ip6=0):
3473 """ Set IP reassembly parameters """
3474 return self.api(self.papi.ip_reassembly_set,
3475 {'is_ip6': is_ip6,
3476 'timeout_ms': timeout_ms,
3477 'expire_walk_interval_ms': expire_walk_interval_ms,
3478 'max_reassemblies': max_reassemblies})
3479
3480 def ip_reassembly_get(self, is_ip6=0):
3481 """ Get IP reassembly parameters """
3482 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003483
Klement Sekera4c533132018-02-22 11:41:12 +01003484 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3485 enable_ip6=False):
3486 """ Enable/disable IP reassembly """
3487 return self.api(self.papi.ip_reassembly_enable_disable,
3488 {'sw_if_index': sw_if_index,
3489 'enable_ip4': 1 if enable_ip4 else 0,
3490 'enable_ip6': 1 if enable_ip6 else 0,
3491 })
3492
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003493 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags,
3494 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07003495 """ GBP endpoint Add """
3496 return self.api(self.papi.gbp_endpoint_add,
3497 {'endpoint': {
3498 'sw_if_index': sw_if_index,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003499 'flags': 0,
Neale Rannsc0a93142018-09-05 15:42:26 -07003500 'ips': ips,
3501 'n_ips': len(ips),
3502 'mac': mac,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003503 'epg_id': epg,
3504 'flags': flags,
3505 'tun': {
3506 'src': tun_src,
3507 'dst': tun_dst,
3508 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07003509
3510 def gbp_endpoint_del(self, handle):
3511 """ GBP endpoint Del """
3512 return self.api(self.papi.gbp_endpoint_del,
3513 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003514
3515 def gbp_endpoint_dump(self):
3516 """ GBP endpoint Dump """
3517 return self.api(self.papi.gbp_endpoint_dump, {})
3518
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003519 def gbp_endpoint_group_add(self, epg, bd,
3520 rd, uplink_sw_if_index):
3521 """ GBP endpoint group Add """
3522 return self.api(self.papi.gbp_endpoint_group_add,
3523 {'epg':
3524 {
Neale Ranns25b04942018-04-04 09:34:50 -07003525 'uplink_sw_if_index': uplink_sw_if_index,
3526 'bd_id': bd,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003527 'rd_id': rd,
3528 'epg_id': epg
3529 }})
3530
3531 def gbp_endpoint_group_del(self, epg):
3532 """ GBP endpoint group Del """
3533 return self.api(self.papi.gbp_endpoint_group_del,
3534 {'epg_id': epg})
Neale Ranns25b04942018-04-04 09:34:50 -07003535
3536 def gbp_endpoint_group_dump(self):
3537 """ GBP endpoint group Dump """
3538 return self.api(self.papi.gbp_endpoint_group_dump, {})
3539
Neale Rannsc29c0af2018-11-07 04:21:12 -08003540 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003541 bvi_sw_if_index,
3542 uu_fwd_sw_if_index):
3543 """ GBP bridge-domain Add """
3544 return self.api(self.papi.gbp_bridge_domain_add,
3545 {'bd':
3546 {
Neale Rannsc29c0af2018-11-07 04:21:12 -08003547 'flags': flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003548 'bvi_sw_if_index': bvi_sw_if_index,
3549 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
3550 'bd_id': bd_id
3551 }})
3552
3553 def gbp_bridge_domain_del(self, bd_id):
3554 """ GBP bridge-domain Del """
3555 return self.api(self.papi.gbp_bridge_domain_del,
3556 {'bd_id': bd_id})
3557
3558 def gbp_bridge_domain_dump(self):
3559 """ GBP Bridge Domain Dump """
3560 return self.api(self.papi.gbp_bridge_domain_dump, {})
3561
3562 def gbp_route_domain_add(self, rd_id,
3563 ip4_table_id,
3564 ip6_table_id,
3565 ip4_uu_sw_if_index,
3566 ip6_uu_sw_if_index):
3567 """ GBP route-domain Add """
3568 return self.api(self.papi.gbp_route_domain_add,
3569 {'rd':
3570 {
3571 'ip4_table_id': ip4_table_id,
3572 'ip6_table_id': ip6_table_id,
3573 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
3574 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
3575 'rd_id': rd_id
3576 }})
3577
3578 def gbp_route_domain_del(self, rd_id):
3579 """ GBP route-domain Del """
3580 return self.api(self.papi.gbp_route_domain_del,
3581 {'rd_id': rd_id})
3582
3583 def gbp_route_domain_dump(self):
3584 """ GBP Route Domain Dump """
3585 return self.api(self.papi.gbp_route_domain_dump, {})
3586
Neale Ranns25b04942018-04-04 09:34:50 -07003587 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3588 """ GBP recirc Add/Del """
3589 return self.api(self.papi.gbp_recirc_add_del,
3590 {'is_add': is_add,
3591 'recirc': {
3592 'is_ext': is_ext,
3593 'sw_if_index': sw_if_index,
3594 'epg_id': epg}})
3595
3596 def gbp_recirc_dump(self):
3597 """ GBP recirc Dump """
3598 return self.api(self.papi.gbp_recirc_dump, {})
3599
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003600 def gbp_subnet_add_del(self, is_add, rd_id,
3601 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07003602 sw_if_index=0xffffffff,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003603 epg_id=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07003604 """ GBP Subnet Add/Del """
3605 return self.api(self.papi.gbp_subnet_add_del,
3606 {'is_add': is_add,
3607 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003608 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07003609 'sw_if_index': sw_if_index,
3610 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003611 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003612 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07003613
3614 def gbp_subnet_dump(self):
3615 """ GBP Subnet Dump """
3616 return self.api(self.papi.gbp_subnet_dump, {})
3617
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003618 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3619 """ GBP contract Add/Del """
3620 return self.api(self.papi.gbp_contract_add_del,
3621 {'is_add': is_add,
3622 'contract': {
3623 'acl_index': acl_index,
3624 'src_epg': src_epg,
3625 'dst_epg': dst_epg}})
3626
3627 def gbp_contract_dump(self):
3628 """ GBP contract Dump """
3629 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003630
Neale Ranns93cc3ee2018-10-10 07:22:51 -07003631 def gbp_endpoint_learn_set_inactive_threshold(self, threshold):
3632 """ GBP set inactive threshold """
3633 return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold,
3634 {'threshold': threshold})
3635
3636 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode):
3637 """ GBP VXLAN tunnel add """
3638 return self.api(self.papi.gbp_vxlan_tunnel_add,
3639 {
3640 'tunnel': {
3641 'vni': vni,
3642 'mode': mode,
3643 'bd_rd_id': bd_rd_id
3644 }
3645 })
3646
3647 def gbp_vxlan_tunnel_del(self, vni):
3648 """ GBP VXLAN tunnel del """
3649 return self.api(self.papi.gbp_vxlan_tunnel_del,
3650 {
3651 'vni': vni,
3652 })
3653
3654 def gbp_vxlan_tunnel_dump(self):
3655 """ GBP VXLAN tunnel add/del """
3656 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
3657
Neale Ranns61502112018-08-22 00:21:14 -07003658 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3659 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003660 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003661 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003662 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003663 {'ip4_table_id': ip4_table_id,
3664 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003665 'ip6_prefix': ip6_prefix,
3666 'ip6_prefix_len': ip6_prefix_len,
3667 'ip4_prefix': ip4_prefix,
3668 'ip4_prefix_len': ip4_prefix_len,
3669 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003670 'security_check': security_check})
3671
Ole Troan298c6952018-03-08 12:30:43 +01003672 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003673 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003674 return self.api(self.papi.ipip_6rd_del_tunnel,
3675 {'sw_if_index': sw_if_index})
3676
3677 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003678 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003679 """ IPIP tunnel Add/Del """
3680 return self.api(self.papi.ipip_add_tunnel,
3681 {'is_ipv6': is_ipv6,
3682 'instance': instance,
3683 'src_address': src_address,
3684 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003685 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003686 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003687
3688 def ipip_del_tunnel(self, sw_if_index):
3689 """ IPIP tunnel Delete """
3690 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003691 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003692
3693 def qos_egress_map_update(self, id, outputs):
3694 """ QOS egress map update """
3695 return self.api(self.papi.qos_egress_map_update,
3696 {'map_id': id,
3697 'rows': outputs})
3698
3699 def qos_egress_map_delete(self, id):
3700 """ QOS egress map delete """
3701 return self.api(self.papi.qos_egress_map_delete,
3702 {'map_id': id})
3703
3704 def qos_mark_enable_disable(self, sw_if_index,
3705 output_source,
3706 map_id,
3707 enable):
3708 """ QOS Mark Enable/Disable """
3709 return self.api(self.papi.qos_mark_enable_disable,
3710 {'map_id': map_id,
3711 'sw_if_index': sw_if_index,
3712 'output_source': output_source,
3713 'enable': enable})
3714
3715 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3716 """ IP QoS recording Enble/Disable """
3717 return self.api(self.papi.qos_record_enable_disable,
3718 {'sw_if_index': sw_if_index,
3719 'input_source': input_source,
3720 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003721
Neale Ranns947ea622018-06-07 23:48:20 -07003722 def igmp_enable_disable(self, sw_if_index, enable, host):
3723 """ Enable/disable IGMP on a given interface """
3724 return self.api(self.papi.igmp_enable_disable,
3725 {'enable': enable,
3726 'mode': host,
3727 'sw_if_index': sw_if_index})
3728
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003729 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3730 """ Add/del IGMP proxy device """
3731 return self.api(self.papi.igmp_proxy_device_add_del,
3732 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3733 'add': add})
3734
3735 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3736 """ Add/del interface to/from IGMP proxy device """
3737 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3738 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3739 'add': add})
3740
Neale Ranns947ea622018-06-07 23:48:20 -07003741 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003742 """ Listen for new (S,G) on specified interface
3743
3744 :param enable: add/del
3745 :param sw_if_index: interface sw index
3746 :param saddr: source ip4 addr
3747 :param gaddr: group ip4 addr
3748 """
3749 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003750 {
3751 'group':
3752 {
3753 'filter': filter,
3754 'sw_if_index': sw_if_index,
3755 'n_srcs': len(saddrs),
3756 'saddrs': saddrs,
3757 'gaddr':
3758 {
3759 'address': gaddr
3760 }
3761 }
3762 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003763
3764 def igmp_dump(self, sw_if_index=None):
3765 """ Dump all (S,G) interface configurations """
3766 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003767 sw_if_index = 0xffffffff
3768 return self.api(self.papi.igmp_dump,
3769 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003770
3771 def igmp_clear_interface(self, sw_if_index):
3772 """ Remove all (S,G)s from specified interface
3773 doesn't send IGMP report!
3774 """
3775 return self.api(
3776 self.papi.igmp_clear_interface, {
3777 'sw_if_index': sw_if_index})
3778
3779 def want_igmp_events(self, enable=1):
3780 return self.api(self.papi.want_igmp_events, {'enable': enable,
3781 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003782
3783 def bond_create(
3784 self,
3785 mode,
3786 lb,
3787 use_custom_mac,
3788 mac_address=''):
3789 """
3790 :param mode: mode
3791 :param lb: load balance
3792 :param use_custom_mac: use custom mac
3793 :param mac_address: mac address
3794 """
3795 return self.api(
3796 self.papi.bond_create,
3797 {'mode': mode,
3798 'lb': lb,
3799 'use_custom_mac': use_custom_mac,
3800 'mac_address': mac_address
3801 })
3802
3803 def bond_delete(
3804 self,
3805 sw_if_index):
3806 """
3807 :param sw_if_index: interface the operation is applied to
3808 """
3809 return self.api(self.papi.bond_delete,
3810 {'sw_if_index': sw_if_index})
3811
3812 def bond_enslave(
3813 self,
3814 sw_if_index,
3815 bond_sw_if_index,
3816 is_passive,
3817 is_long_timeout):
3818 """
3819 :param sw_if_index: slave sw_if_index
3820 :param bond_sw_if_index: bond sw_if_index
3821 :param is_passive: is passive lacp speaker
3822 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3823 """
3824 return self.api(
3825 self.papi.bond_enslave,
3826 {'sw_if_index': sw_if_index,
3827 'bond_sw_if_index': bond_sw_if_index,
3828 'is_passive': is_passive,
3829 'is_long_timeout': is_long_timeout
3830 })
3831
3832 def bond_detach_slave(
3833 self,
3834 sw_if_index):
3835 """
3836 :param sw_if_index: slave interface the operation is applied to
3837 """
3838 return self.api(self.papi.bond_detach_slave,
3839 {'sw_if_index': sw_if_index})
3840
3841 def sw_interface_slave_dump(
3842 self,
3843 sw_if_index):
3844 """
3845 :param sw_if_index: bond sw_if_index
3846 """
3847 return self.api(self.papi.sw_interface_slave_dump,
3848 {'sw_if_index': sw_if_index})
3849
3850 def sw_interface_bond_dump(
3851 self):
3852 """
3853
3854 """
3855 return self.api(self.papi.sw_interface_bond_dump,
3856 {})
Stevene8fa6202017-08-30 14:36:45 -07003857
3858 def create_vhost_user_if(
3859 self,
3860 is_server,
3861 sock_filename,
3862 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003863 disable_mrg_rxbuf,
3864 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003865 custom_dev_instance,
3866 use_custom_mac,
3867 mac_address,
3868 tag=''):
3869 """
3870 :param is_server: is server
3871 :param sock_filename: socket name
3872 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003873 :param disable_mrg_rxbuf: disable mergable rx buffers
3874 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003875 :param custom_dev_instance: custom dev instance
3876 :param use_custom_mac: use custom mac
3877 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003878 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003879 """
3880 return self.api(
3881 self.papi.create_vhost_user_if,
3882 {'is_server': is_server,
3883 'sock_filename': sock_filename,
3884 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003885 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3886 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003887 'custom_dev_instance': custom_dev_instance,
3888 'use_custom_mac': use_custom_mac,
3889 'mac_address': mac_address,
3890 'tag': tag
3891 })
3892
3893 def delete_vhost_user_if(
3894 self,
3895 sw_if_index):
3896 """
3897 :param sw_if_index: interface the operation is applied to
3898 """
3899 return self.api(self.papi.delete_vhost_user_if,
3900 {'sw_if_index': sw_if_index, })
3901
3902 def sw_interface_vhost_user_dump(
3903 self):
3904 """
3905
3906 """
3907 return self.api(self.papi.sw_interface_vhost_user_dump,
3908 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003909
3910 def abf_policy_add_del(self, is_add, policy):
3911 return self.api(
3912 self.papi.abf_policy_add_del,
3913 {'is_add': is_add,
3914 'policy': policy})
3915
3916 def abf_itf_attach_add_del(self, is_add, attach):
3917 return self.api(
3918 self.papi.abf_itf_attach_add_del,
3919 {'is_add': is_add,
3920 'attach': attach})
3921
3922 def abf_policy_dump(self):
3923 return self.api(
3924 self.papi.abf_policy_dump, {})
3925
3926 def abf_itf_attach_dump(self):
3927 return self.api(
3928 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003929
3930 def pipe_create(self, is_specified, user_instance):
3931 return self.api(self.papi.pipe_create,
3932 {'is_specified': is_specified,
3933 'user_instance': user_instance})
3934
3935 def pipe_delete(self, parent_sw_if_index):
3936 return self.api(self.papi.pipe_delete,
3937 {'parent_sw_if_index': parent_sw_if_index})
3938
3939 def pipe_dump(self):
3940 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003941
3942 def memif_create(
3943 self,
3944 role,
3945 mode,
3946 rx_queues=None,
3947 tx_queues=None,
3948 _id=None,
3949 socket_id=None,
3950 secret=None,
3951 ring_size=None,
3952 buffer_size=None,
3953 hw_addr=None):
3954 return self.api(self.papi.memif_create,
3955 {'role': role,
3956 'mode': mode,
3957 'rx_queues': rx_queues,
3958 'tx_queues': tx_queues,
3959 'id': _id,
3960 'socket_id': socket_id,
3961 'secret': secret,
3962 'ring_size': ring_size,
3963 'buffer_size': buffer_size,
3964 'hw_addr': hw_addr})
3965
3966 def memif_delete(self, sw_if_index):
3967 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
3968
3969 def memif_dump(self):
3970 return self.api(self.papi.memif_dump, {})
3971
3972 def memif_socket_filename_add_del(
3973 self, is_add, socket_id, socket_filename):
3974 return self.api(
3975 self.papi.memif_socket_filename_add_del,
3976 {'is_add': is_add,
3977 'socket_id': socket_id,
3978 'socket_filename': socket_filename})
3979
3980 def memif_socket_filename_dump(self):
3981 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07003982
3983 def svs_table_add_del(self, af, table_id, is_add=1):
3984 return self.api(self.papi.svs_table_add_del,
3985 {
3986 'table_id': table_id,
3987 'is_add': is_add,
3988 'af': af,
3989 })
3990
3991 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
3992 return self.api(self.papi.svs_route_add_del,
3993 {
3994 'table_id': table_id,
3995 'source_table_id': src_table_id,
3996 'prefix': prefix,
3997 'is_add': is_add,
3998 })
3999
4000 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
4001 return self.api(self.papi.svs_enable_disable,
4002 {
4003 'af': af,
4004 'table_id': table_id,
4005 'sw_if_index': sw_if_index,
4006 'is_enable': is_enable,
4007 })
4008
4009 def svs_dump(self):
4010 return self.api(self.papi.svs_dump, {})