blob: 4e7809f6960c7246ba7dec6748a473ca0aadc1f9 [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
Klement Sekera277b89c2016-10-28 13:20:27 +020021
Klement Sekeraf62ae122016-10-11 11:47:09 +020022# from vnet/vnet/mpls/mpls_types.h
23MPLS_IETF_MAX_LABEL = 0xfffff
24MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
25
Klement Sekera0e3c0de2016-09-29 14:43:44 +020026
Neale Ranns177bbdc2016-11-15 09:46:51 +000027class L2_VTR_OP:
Eyal Bari284293a2017-06-06 14:18:55 +030028 L2_DISABLED = 0
29 L2_PUSH_1 = 1
30 L2_PUSH_2 = 2
Neale Ranns177bbdc2016-11-15 09:46:51 +000031 L2_POP_1 = 3
Eyal Bari284293a2017-06-06 14:18:55 +030032 L2_POP_2 = 4
33 L2_TRANSLATE_1_1 = 5
34 L2_TRANSLATE_1_2 = 6
35 L2_TRANSLATE_2_1 = 7
36 L2_TRANSLATE_2_2 = 8
Neale Ranns177bbdc2016-11-15 09:46:51 +000037
Klement Sekera0e3c0de2016-09-29 14:43:44 +020038
Neale Ranns039cbfe2018-02-27 03:45:38 -080039class QOS_SOURCE:
40 EXT = 0
41 VLAN = 1
42 MPLS = 2
43 IP = 3
44
45
Neale Rannsb4743802018-09-05 09:13:57 -070046class L2_PORT_TYPE:
47 NORMAL = 0
48 BVI = 1
49 UU_FWD = 2
50
51
52class BRIDGE_FLAGS:
53 NONE = 0
54 LEARN = 1
55 FWD = 2
56 FLOOD = 4
57 UU_FLOOD = 8
58 ARP_TERM = 16
59
60
Klement Sekera73884482017-02-23 09:26:30 +010061class UnexpectedApiReturnValueError(Exception):
62 """ exception raised when the API return value is unexpected """
63 pass
64
65
Klement Sekeraf62ae122016-10-11 11:47:09 +020066class VppPapiProvider(object):
67 """VPP-api provider using vpp-papi
68
69 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020070 """
71
Klement Sekerae0545ef2017-01-25 08:00:40 +010072 _zero, _negative = range(2)
73
Klement Sekera611864f2018-09-26 11:19:00 +020074 def __init__(self, name, shm_prefix, test_class, read_timeout):
Klement Sekera277b89c2016-10-28 13:20:27 +020075 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020076 self.name = name
77 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010078 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010079 self._expect_api_retval = self._zero
80 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010081 jsonfiles = []
82
Klement Sekera0e3c0de2016-09-29 14:43:44 +020083 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010084 for root, dirnames, filenames in os.walk(install_dir):
85 for filename in fnmatch.filter(filenames, '*.api.json'):
86 jsonfiles.append(os.path.join(root, filename))
87
Klement Sekera611864f2018-09-26 11:19:00 +020088 self.vpp = VPP(jsonfiles, logger=test_class.logger,
89 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +010090 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020091
Klement Sekerae0545ef2017-01-25 08:00:40 +010092 def __enter__(self):
93 return self
94
95 def expect_negative_api_retval(self):
96 """ Expect API failure """
97 self._expect_stack.append(self._expect_api_retval)
98 self._expect_api_retval = self._negative
99 return self
100
101 def expect_zero_api_retval(self):
102 """ Expect API success """
103 self._expect_stack.append(self._expect_api_retval)
104 self._expect_api_retval = self._zero
105 return self
106
107 def __exit__(self, exc_type, exc_value, traceback):
108 self._expect_api_retval = self._expect_stack.pop()
109
Klement Sekeraf62ae122016-10-11 11:47:09 +0200110 def register_hook(self, hook):
111 """Replace hook registration with new hook
112
113 :param hook:
114
115 """
116 self.hook = hook
117
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200118 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100119 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200120 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100121 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122 return e
123
124 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100125 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100126 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100127 self.test_class.logger.debug("Expecting event '%s' within %ss",
128 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300129 else:
130 self.test_class.logger.debug("Expecting event within %ss",
131 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100132 if self._events:
133 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200134 limit = time.time() + timeout
135 while time.time() < limit:
136 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100137 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200138 if name and type(e).__name__ != name:
139 raise Exception(
140 "Unexpected event received: %s, expected: %s" %
141 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100142 self.test_class.logger.debug("Returning event %s:%s" %
143 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200144 return e
145 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200146 raise Exception("Event did not occur within timeout")
147
148 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100149 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200150 # FIXME use the name instead of relying on type(e).__name__ ?
151 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100152 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200153 self._events.append(event)
154
Klement Sekeraf62ae122016-10-11 11:47:09 +0200155 def connect(self):
156 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100157 self.vpp.connect(self.name, self.shm_prefix)
158 self.papi = self.vpp.api
159 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200160
161 def disconnect(self):
162 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100163 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200164
165 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100166 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200167 Call the appropriate hooks before and after the API call
168
169 :param api_fn: API function to call
170 :param api_args: tuple of API function arguments
171 :param expected_retval: Expected return value (Default value = 0)
172 :returns: reply from the API
173
174 """
175 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100176 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100177 if self._expect_api_retval == self._negative:
178 if hasattr(reply, 'retval') and reply.retval >= 0:
179 msg = "API call passed unexpectedly: expected negative "\
180 "return value instead of %d in %s" % \
181 (reply.retval, repr(reply))
182 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100183 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100184 elif self._expect_api_retval == self._zero:
185 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700186 msg = "API call failed, expected %d return value instead "\
187 "of %d in %s" % (expected_retval, reply.retval,
188 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100189 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100190 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100191 else:
192 raise Exception("Internal error, unexpected value for "
193 "self._expect_api_retval %s" %
194 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195 self.hook.after_api(api_fn.__name__, api_args)
196 return reply
197
198 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100199 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200200
201 :param cli: CLI to execute
202 :returns: CLI output
203
204 """
205 self.hook.before_cli(cli)
206 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100207 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200208 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200209 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100210 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211
Jan49c0fca2016-10-26 15:44:27 +0200212 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100213 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200214
215 :param cli: CLI to execute
216 :returns: CLI output
217 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600218 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200219
Jan4af521d2016-11-15 17:05:00 +0100220 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200221 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100222
Klement Sekeraf62ae122016-10-11 11:47:09 +0200223 def show_version(self):
224 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100225 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200226
227 def pg_create_interface(self, pg_index):
228 """
229
230 :param pg_index:
231
232 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100233 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200235
236 def sw_interface_dump(self, filter=None):
237 """
238
239 :param filter: (Default value = None)
240
241 """
242 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200243 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200244 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100245 args = {}
246 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200247
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000248 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100249 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000250
251 :param sw_if_index:
252 :param is_ipv6:
253 :param table_id:
254
255 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100256 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200257 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
258 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000259
Klement Sekeraf62ae122016-10-11 11:47:09 +0200260 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
261 is_ipv6=0, is_add=1, del_all=0):
262 """
263
264 :param addr: param is_ipv6: (Default value = 0)
265 :param sw_if_index:
266 :param addr_len:
267 :param is_ipv6: (Default value = 0)
268 :param is_add: (Default value = 1)
269 :param del_all: (Default value = 0)
270
271 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100272 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200273 {'sw_if_index': sw_if_index,
274 'is_add': is_add,
275 'is_ipv6': is_ipv6,
276 'del_all': del_all,
277 'address_length': addr_len,
278 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200279
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800280 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
281 is_add=1):
282 """ Set the Interface to be unnumbered
283
284 :param is_add: (Default value = 1)
285 :param sw_if_index - interface That will be unnumbered
286 :param ip_sw_if_index - interface with an IP addres
287
288 """
289 return self.api(self.papi.sw_interface_set_unnumbered,
290 {'sw_if_index': ip_sw_if_index,
291 'unnumbered_sw_if_index': sw_if_index,
292 'is_add': is_add})
293
Neale Ranns404d88e2018-08-08 06:37:33 -0700294 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
295 return self.api(self.papi.ip_unnumbered_dump,
296 {'sw_if_index': sw_if_index})
297
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000298 def sw_interface_enable_disable_mpls(self, sw_if_index,
299 is_enable=1):
300 """
301 Enable/Disable MPLS on the interface
302 :param sw_if_index:
303 :param is_enable: (Default value = 1)
304
305 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100306 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200307 {'sw_if_index': sw_if_index,
308 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000309
Jan Gelety057bb8c2016-12-20 17:32:45 +0100310 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100311 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100312 {'sw_if_index': sw_if_index,
313 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200314
Neale Ranns227038a2017-04-21 01:07:59 -0700315 def set_ip_flow_hash(self,
316 table_id,
317 src=1,
318 dst=1,
319 sport=1,
320 dport=1,
321 proto=1,
322 reverse=0,
323 is_ip6=0):
324 return self.api(self.papi.set_ip_flow_hash,
325 {'vrf_id': table_id,
326 'src': src,
327 'dst': dst,
328 'dport': dport,
329 'sport': sport,
330 'proto': proto,
331 'reverse': reverse,
332 'is_ipv6': is_ip6})
333
Neale Ranns3f844d02017-02-18 00:03:54 -0800334 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
335 return self.api(self.papi.ip6nd_proxy_add_del,
336 {'address': address,
337 'sw_if_index': sw_if_index,
338 'is_del': is_del})
339
Neale Ranns75152282017-01-09 01:00:45 -0800340 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000341 no,
Neale Ranns75152282017-01-09 01:00:45 -0800342 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000343 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800344 return self.api(self.papi.sw_interface_ip6nd_ra_config,
345 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000346 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100347 'suppress': suppress,
348 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800349
Neale Ranns87df12d2017-02-18 08:16:41 -0800350 def ip6_sw_interface_ra_prefix(self,
351 sw_if_index,
352 address,
353 address_length,
354 use_default=0,
355 no_advertise=0,
356 off_link=0,
357 no_autoconfig=0,
358 no_onlink=0,
359 is_no=0,
360 val_lifetime=0xffffffff,
361 pref_lifetime=0xffffffff):
362 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
363 {'sw_if_index': sw_if_index,
364 'address': address,
365 'address_length': address_length,
366 'use_default': use_default,
367 'no_advertise': no_advertise,
368 'off_link': off_link,
369 'no_autoconfig': no_autoconfig,
370 'no_onlink': no_onlink,
371 'is_no': is_no,
372 'val_lifetime': val_lifetime,
373 'pref_lifetime': pref_lifetime})
374
Neale Ranns75152282017-01-09 01:00:45 -0800375 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
376 """
377 Enable/Disable An interface for IPv6
378 """
379 return self.api(self.papi.sw_interface_ip6_enable_disable,
380 {'sw_if_index': sw_if_index,
381 'enable': enable})
382
Klement Sekeraf62ae122016-10-11 11:47:09 +0200383 def vxlan_add_del_tunnel(
384 self,
385 src_addr,
386 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200387 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200388 is_add=1,
389 is_ipv6=0,
390 encap_vrf_id=0,
391 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600392 vni=0,
393 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200394 """
395
396 :param dst_addr:
397 :param src_addr:
398 :param is_add: (Default value = 1)
399 :param is_ipv6: (Default value = 0)
400 :param encap_vrf_id: (Default value = 0)
401 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200402 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200403 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600404 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200405
406 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100407 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200408 {'is_add': is_add,
409 'is_ipv6': is_ipv6,
410 'src_address': src_addr,
411 'dst_address': dst_addr,
412 'mcast_sw_if_index': mcast_sw_if_index,
413 'encap_vrf_id': encap_vrf_id,
414 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600415 'vni': vni,
416 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200417
Marco Varleseb598f1d2017-09-19 14:25:28 +0200418 def geneve_add_del_tunnel(
419 self,
420 local_addr,
421 remote_addr,
422 mcast_sw_if_index=0xFFFFFFFF,
423 is_add=1,
424 is_ipv6=0,
425 encap_vrf_id=0,
426 decap_next_index=0xFFFFFFFF,
427 vni=0):
428 """
429
430 :param remote_addr:
431 :param local_addr:
432 :param is_add: (Default value = 1)
433 :param is_ipv6: (Default value = 0)
434 :param encap_vrf_id: (Default value = 0)
435 :param decap_next_index: (Default value = 0xFFFFFFFF)
436 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
437 :param vni: (Default value = 0)
438
439 """
440 return self.api(self.papi.geneve_add_del_tunnel,
441 {'is_add': is_add,
442 'is_ipv6': is_ipv6,
443 'local_address': local_addr,
444 'remote_address': remote_addr,
445 'mcast_sw_if_index': mcast_sw_if_index,
446 'encap_vrf_id': encap_vrf_id,
447 'decap_next_index': decap_next_index,
448 'vni': vni})
449
Jan4af521d2016-11-15 17:05:00 +0100450 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
451 learn=1, arp_term=0, is_add=1):
452 """Create/delete bridge domain.
453
454 :param int bd_id: Bridge domain index.
455 :param int flood: Enable/disable bcast/mcast flooding in the BD.
456 (Default value = 1)
457 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
458 (Default value = 1)
459 :param int forward: Enable/disable forwarding on all interfaces in
460 the BD. (Default value = 1)
461 :param int learn: Enable/disable learning on all interfaces in the BD.
462 (Default value = 1)
463 :param int arp_term: Enable/disable arp termination in the BD.
464 (Default value = 1)
465 :param int is_add: Add or delete flag. (Default value = 1)
466 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100467 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200468 {'bd_id': bd_id,
469 'flood': flood,
470 'uu_flood': uu_flood,
471 'forward': forward,
472 'learn': learn,
473 'arp_term': arp_term,
474 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100475
Eyal Baric86e5922017-07-02 18:33:16 +0300476 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
477 return self.api(self.papi.bd_ip_mac_add_del,
478 {'bd_id': bd_id,
479 'is_add': is_add,
480 'is_ipv6': is_ipv6,
481 'ip_address': ip,
482 'mac_address': mac})
483
Eyal Bari20197482017-09-13 12:29:08 +0300484 def want_ip4_arp_events(self, enable_disable=1, address=0):
485 return self.api(self.papi.want_ip4_arp_events,
486 {'enable_disable': enable_disable,
487 'address': address,
488 'pid': os.getpid(), })
489
Eyal Baric125ecc2017-09-20 11:29:17 +0300490 def want_ip6_nd_events(self, enable_disable=1, address=0):
491 return self.api(self.papi.want_ip6_nd_events,
492 {'enable_disable': enable_disable,
493 'address': address,
494 'pid': os.getpid(), })
495
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100496 def want_ip6_ra_events(self, enable_disable=1):
497 return self.api(self.papi.want_ip6_ra_events,
498 {'enable_disable': enable_disable,
499 'pid': os.getpid(), })
500
501 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
502 mrc=0, mrd=0):
503 return self.api(self.papi.ip6nd_send_router_solicitation,
504 {'irt': irt,
505 'mrt': mrt,
506 'mrc': mrc,
507 'mrd': mrd,
508 'sw_if_index': sw_if_index})
509
Juraj Slobodac0374232018-02-01 15:18:49 +0100510 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
511 install_default_routes):
512 return self.api(self.papi.ip6_nd_address_autoconfig,
513 {'sw_if_index': sw_if_index,
514 'enable': enable,
515 'install_default_routes': install_default_routes})
516
Juraj Slobodab3f90502018-10-04 15:15:16 +0200517 def want_interface_events(self, enable_disable=1):
518 return self.api(self.papi.want_interface_events,
519 {'enable_disable': enable_disable,
520 'pid': os.getpid(), })
521
Eyal Bari24db0ec2017-09-27 21:43:51 +0300522 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
523 max_macs_in_event=0, learn_limit=0):
524 return self.api(self.papi.want_l2_macs_events,
525 {'enable_disable': enable_disable,
526 'scan_delay': scan_delay,
527 'max_macs_in_event': max_macs_in_event,
528 'learn_limit': learn_limit,
529 'pid': os.getpid(), })
530
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200531 def want_dhcp6_reply_events(self, enable_disable=1):
532 return self.api(self.papi.want_dhcp6_reply_events,
533 {'enable_disable': enable_disable,
534 'pid': os.getpid()})
535
Juraj Sloboda81119e82018-05-25 14:02:20 +0200536 def want_dhcp6_pd_reply_events(self, enable_disable=1):
537 return self.api(self.papi.want_dhcp6_pd_reply_events,
538 {'enable_disable': enable_disable,
539 'pid': os.getpid()})
540
541 def dhcp6_clients_enable_disable(self, enable=1):
542 return self.api(self.papi.dhcp6_clients_enable_disable,
543 {'enable': enable})
544
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200545 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
546 addresses, server_index=0xFFFFFFFF,
547 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
548 ):
549 return self.api(self.papi.dhcp6_send_client_message,
550 {'sw_if_index': sw_if_index,
551 'server_index': server_index,
552 'irt': irt,
553 'mrt': mrt,
554 'mrc': mrc,
555 'mrd': mrd,
556 'stop': stop,
557 'msg_type': msg_type,
558 'T1': T1,
559 'T2': T2,
560 'n_addresses': len(addresses),
561 'addresses': addresses})
562
Juraj Sloboda81119e82018-05-25 14:02:20 +0200563 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
564 prefixes, server_index=0xFFFFFFFF,
565 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
566 ):
567 return self.api(self.papi.dhcp6_pd_send_client_message,
568 {'sw_if_index': sw_if_index,
569 'server_index': server_index,
570 'irt': irt,
571 'mrt': mrt,
572 'mrc': mrc,
573 'mrd': mrd,
574 'stop': stop,
575 'msg_type': msg_type,
576 'T1': T1,
577 'T2': T2,
578 'n_prefixes': len(prefixes),
579 'prefixes': prefixes})
580
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200581 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
582 enable=1):
583 return self.api(self.papi.dhcp6_client_enable_disable,
584 {'sw_if_index': sw_if_index,
585 'enable': enable})
586
Juraj Sloboda81119e82018-05-25 14:02:20 +0200587 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
588 enable=1):
589 return self.api(self.papi.dhcp6_pd_client_enable_disable,
590 {'sw_if_index': sw_if_index,
591 'prefix_group': prefix_group,
592 'enable': enable})
593
594 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
595 prefix_length, prefix_group,
596 is_add=1):
597 return self.api(self.papi.ip6_add_del_address_using_prefix,
598 {'sw_if_index': sw_if_index,
599 'prefix_group': prefix_group,
600 'address': address,
601 'prefix_length': prefix_length,
602 'is_add': is_add})
603
Jan4af521d2016-11-15 17:05:00 +0100604 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
605 filter_mac=0, bvi_mac=0):
606 """Create/delete L2 FIB entry.
607
608 :param str mac: MAC address to create FIB entry for.
609 :param int bd_id: Bridge domain index.
610 :param int sw_if_index: Software interface index of the interface.
611 :param int is_add: Add or delete flag. (Default value = 1)
612 :param int static_mac: Set to 1 to create static MAC entry.
613 (Default value = 0)
614 :param int filter_mac: Set to 1 to drop packet that's source or
615 destination MAC address contains defined MAC address.
616 (Default value = 0)
617 :param int bvi_mac: Set to 1 to create entry that points to BVI
618 interface. (Default value = 0)
619 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100620 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200621 {'mac': self._convert_mac(mac),
622 'bd_id': bd_id,
623 'sw_if_index': sw_if_index,
624 'is_add': is_add,
625 'static_mac': static_mac,
626 'filter_mac': filter_mac,
627 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100628
Eyal Bari93b503e2017-05-15 10:13:15 +0300629 def l2fib_flush_int(self, sw_if_index):
630 """Flush L2 FIB entries for sw_if_index.
631
632 :param int sw_if_index: Software interface index of the interface.
633 """
634 return self.api(self.papi.l2fib_flush_int,
635 {'sw_if_index': sw_if_index})
636
637 def l2fib_flush_bd(self, bd_id):
638 """Flush L2 FIB entries for bd_id.
639
640 :param int sw_if_index: Bridge Domain id.
641 """
642 return self.api(self.papi.l2fib_flush_bd,
643 {'bd_id': bd_id})
644
645 def l2fib_flush_all(self):
646 """Flush all L2 FIB.
647 """
648 return self.api(self.papi.l2fib_flush_all, {})
649
Klement Sekeraf62ae122016-10-11 11:47:09 +0200650 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
Neale Rannsb4743802018-09-05 09:13:57 -0700651 shg=0, port_type=L2_PORT_TYPE.NORMAL,
652 enable=1):
Jan4af521d2016-11-15 17:05:00 +0100653 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200654
Jan4af521d2016-11-15 17:05:00 +0100655 :param int sw_if_index: Software interface index of the interface.
656 :param int bd_id: Bridge domain index.
657 :param int shg: Split-horizon group index. (Default value = 0)
658 :param int bvi: Set interface as a bridge group virtual interface.
659 (Default value = 0)
660 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200661 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100662 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200663 {'rx_sw_if_index': sw_if_index,
664 'bd_id': bd_id,
665 'shg': shg,
Neale Rannsb4743802018-09-05 09:13:57 -0700666 'port_type': port_type,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200667 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200668
Jan00dad122016-11-29 10:04:53 +0100669 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400670 """Enable/disable required feature of the bridge domain with defined
671 ID.
Jan00dad122016-11-29 10:04:53 +0100672
673 :param int bd_id: Bridge domain ID.
674 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
Neale Rannsb4743802018-09-05 09:13:57 -0700675 :param int flags: Bitmap value of the feature to be set:
Jan00dad122016-11-29 10:04:53 +0100676 - learn (1 << 0),
677 - forward (1 << 1),
678 - flood (1 << 2),
679 - uu-flood (1 << 3) or
680 - arp-term (1 << 4).
681 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100682 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200683 {'bd_id': bd_id,
684 'is_set': is_set,
Neale Rannsb4743802018-09-05 09:13:57 -0700685 'flags': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100686
687 def bridge_domain_dump(self, bd_id=0):
688 """
689
690 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
691 existing bridge domains returned)
692 :return: Dictionary of bridge domain(s) data.
693 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100694 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200695 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100696
Klement Sekeraf62ae122016-10-11 11:47:09 +0200697 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
698 enable):
699 """Create or delete unidirectional cross-connect from Tx interface to
700 Rx interface.
701
Jan4af521d2016-11-15 17:05:00 +0100702 :param int rx_sw_if_index: Software interface index of Rx interface.
703 :param int tx_sw_if_index: Software interface index of Tx interface.
704 :param int enable: Create cross-connect if equal to 1, delete
705 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200706
707 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100708 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200709 {'rx_sw_if_index': rx_sw_if_index,
710 'tx_sw_if_index': tx_sw_if_index,
711 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200712
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200713 def sw_interface_set_l2_tag_rewrite(
714 self,
715 sw_if_index,
716 vtr_oper,
717 push=0,
718 tag1=0,
719 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000720 """L2 interface vlan tag rewrite configure request
721 :param client_index - opaque cookie to identify the sender
722 :param context - sender context, to match reply w/ request
723 :param sw_if_index - interface the operation is applied to
724 :param vtr_op - Choose from l2_vtr_op_t enum values
725 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
726 :param tag1 - Needed for any push or translate vtr op
727 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
728
729 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100730 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200731 {'sw_if_index': sw_if_index,
732 'vtr_op': vtr_oper,
733 'push_dot1q': push,
734 'tag1': tag1,
735 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000736
Neale Ranns55d03782017-10-21 06:34:22 -0700737 def sw_interface_set_l2_emulation(
738 self,
739 sw_if_index,
740 enable=1):
741 """L2 Emulation
742 :param sw_if_index - interface the operation is applied to
743
744 """
745 return self.api(self.papi.l2_emulation,
746 {'sw_if_index': sw_if_index,
747 'enable': enable})
748
Neale Ranns1855b8e2018-07-11 10:31:26 -0700749 def sw_interface_set_ip_directed_broadcast(
750 self,
751 sw_if_index,
752 enable=1):
753 """IP Directed broadcast
754 :param sw_if_index - interface the operation is applied to
755
756 """
757 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
758 {'sw_if_index': sw_if_index,
759 'enable': enable})
760
Neale Rannsa07bd702017-08-07 07:53:49 -0700761 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200762 """
763
764 :param admin_up_down:
765 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200766
767 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100768 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200769 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700770 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200771
Ole Troand7231612018-06-07 10:17:57 +0200772 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800773 """
774 :param sw_if_index:
775 :param mtu:
776
777 """
778 return self.api(self.papi.sw_interface_set_mtu,
779 {'sw_if_index': sw_if_index,
780 'mtu': mtu})
781
Neale Ranns25b04942018-04-04 09:34:50 -0700782 def sw_interface_set_promiscuous(self, sw_if_index, enable):
783 """
784 :param sw_if_index:
785 :param enable:
786
787 """
788 return self.api(self.papi.sw_interface_set_promiscuous,
789 {'sw_if_index': sw_if_index,
790 'enable': enable})
791
Neale Rannsc819fc62018-02-16 02:44:05 -0800792 def sw_interface_set_mac_address(self, sw_if_index, mac):
793 return self.api(self.papi.sw_interface_set_mac_address,
794 {'sw_if_index': sw_if_index,
795 'mac_address': mac})
796
Klement Sekeraf62ae122016-10-11 11:47:09 +0200797 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
798 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
799 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
800 """Create subinterface
801 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
802
803 :param sub_id: param inner_vlan:
804 :param sw_if_index:
805 :param outer_vlan:
806 :param inner_vlan:
807 :param no_tags: (Default value = 0)
808 :param one_tag: (Default value = 0)
809 :param two_tags: (Default value = 0)
810 :param dot1ad: (Default value = 0)
811 :param exact_match: (Default value = 0)
812 :param default_sub: (Default value = 0)
813 :param outer_vlan_id_any: (Default value = 0)
814 :param inner_vlan_id_any: (Default value = 0)
815
816 """
817 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100818 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200819 {'sw_if_index': sw_if_index,
820 'sub_id': sub_id,
821 'no_tags': no_tags,
822 'one_tag': one_tag,
823 'two_tags': two_tags,
824 'dot1ad': dot1ad,
825 'exact_match': exact_match,
826 'default_sub': default_sub,
827 'outer_vlan_id_any': outer_vlan_id_any,
828 'inner_vlan_id_any': inner_vlan_id_any,
829 'outer_vlan_id': outer_vlan,
830 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200831
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200832 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
833 """Create p2p ethernet subinterface
834
835 :param sw_if_index: main (parent) interface
836 :param remote_mac: client (remote) mac address
837
838 """
839 return self.api(
840 self.papi.p2p_ethernet_add,
841 {'parent_if_index': sw_if_index,
842 'remote_mac': remote_mac,
843 'subif_id': subif_id})
844
Neale Ranns177bbdc2016-11-15 09:46:51 +0000845 def delete_subif(self, sw_if_index):
846 """Delete subinterface
847
848 :param sw_if_index:
849 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100850 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200851 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000852
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200853 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
854 """Delete p2p ethernet subinterface
855
856 :param sw_if_index: main (parent) interface
857 :param remote_mac: client (remote) mac address
858
859 """
860 return self.api(
861 self.papi.p2p_ethernet_del,
862 {'parent_if_index': sw_if_index,
863 'remote_mac': remote_mac})
864
Klement Sekeraf62ae122016-10-11 11:47:09 +0200865 def create_vlan_subif(self, sw_if_index, vlan):
866 """
867
868 :param vlan:
869 :param sw_if_index:
870
871 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100872 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200873 {'sw_if_index': sw_if_index,
874 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200875
Matej Klotton0178d522016-11-04 11:11:44 +0100876 def create_loopback(self, mac=''):
877 """
878
879 :param mac: (Optional)
880 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100881 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200882 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100883
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100884 def delete_loopback(self, sw_if_index):
885 return self.api(self.papi.delete_loopback,
886 {'sw_if_index': sw_if_index, })
887
Neale Ranns15002542017-09-10 04:39:11 -0700888 def ip_table_add_del(self,
889 table_id,
890 is_add=1,
891 is_ipv6=0):
892 """
893
894 :param table_id
895 :param is_add: (Default value = 1)
896 :param is_ipv6: (Default value = 0)
897
898 """
899
900 return self.api(
901 self.papi.ip_table_add_del,
902 {'table_id': table_id,
903 'is_add': is_add,
904 'is_ipv6': is_ipv6})
905
Klement Sekeraf62ae122016-10-11 11:47:09 +0200906 def ip_add_del_route(
907 self,
908 dst_address,
909 dst_address_length,
910 next_hop_address,
911 next_hop_sw_if_index=0xFFFFFFFF,
912 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200913 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000914 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200915 next_hop_n_out_labels=0,
916 next_hop_out_label_stack=[],
917 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800918 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000919 is_resolve_host=0,
920 is_resolve_attached=0,
921 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200922 is_add=1,
923 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200924 is_unreach=0,
925 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200926 is_ipv6=0,
927 is_local=0,
928 is_classify=0,
929 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800930 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800931 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200932 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200933 """
934
935 :param dst_address_length:
936 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
937 :param dst_address:
938 :param next_hop_address:
939 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
940 :param vrf_id: (Default value = 0)
941 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200942 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200943 :param is_add: (Default value = 1)
944 :param is_drop: (Default value = 0)
945 :param is_ipv6: (Default value = 0)
946 :param is_local: (Default value = 0)
947 :param is_classify: (Default value = 0)
948 :param is_multipath: (Default value = 0)
949 :param is_resolve_host: (Default value = 0)
950 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800951 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700952 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200953 :param next_hop_weight: (Default value = 1)
954
955 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000956
Klement Sekeraf62ae122016-10-11 11:47:09 +0200957 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100958 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200959 {'next_hop_sw_if_index': next_hop_sw_if_index,
960 'table_id': table_id,
961 'classify_table_index': classify_table_index,
962 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200963 'is_add': is_add,
964 'is_drop': is_drop,
965 'is_unreach': is_unreach,
966 'is_prohibit': is_prohibit,
967 'is_ipv6': is_ipv6,
968 'is_local': is_local,
969 'is_classify': is_classify,
970 'is_multipath': is_multipath,
971 'is_resolve_host': is_resolve_host,
972 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800973 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700974 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800975 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200976 'next_hop_weight': next_hop_weight,
977 'dst_address_length': dst_address_length,
978 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800979 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200980 'next_hop_address': next_hop_address,
981 'next_hop_n_out_labels': next_hop_n_out_labels,
982 'next_hop_via_label': next_hop_via_label,
983 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100984
Matej Klotton16a14cd2016-12-07 15:09:13 +0100985 def ip_fib_dump(self):
986 return self.api(self.papi.ip_fib_dump, {})
987
Jan Gelety057bb8c2016-12-20 17:32:45 +0100988 def ip6_fib_dump(self):
989 return self.api(self.papi.ip6_fib_dump, {})
990
Matej Klotton0178d522016-11-04 11:11:44 +0100991 def ip_neighbor_add_del(self,
992 sw_if_index,
993 mac_address,
994 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100995 is_add=1,
996 is_ipv6=0,
997 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800998 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100999 ):
1000 """ Add neighbor MAC to IPv4 or IPv6 address.
1001
1002 :param sw_if_index:
1003 :param mac_address:
1004 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +01001005 :param is_add: (Default value = 1)
1006 :param is_ipv6: (Default value = 0)
1007 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -08001008 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +01001009 """
1010
1011 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001012 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -08001013 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001014 'is_add': is_add,
1015 'is_ipv6': is_ipv6,
1016 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -08001017 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001018 'mac_address': mac_address,
1019 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +01001020 }
Matej Klotton0178d522016-11-04 11:11:44 +01001021 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001022
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001023 def ip_neighbor_dump(self,
1024 sw_if_index,
1025 is_ipv6=0):
1026 """ Return IP neighbor dump.
1027
1028 :param sw_if_index:
1029 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1030 """
1031
1032 return self.api(
1033 self.papi.ip_neighbor_dump,
1034 {'is_ipv6': is_ipv6,
1035 'sw_if_index': sw_if_index
1036 }
1037 )
1038
1039 def proxy_arp_add_del(self,
1040 low_address,
1041 hi_address,
1042 vrf_id=0,
1043 is_add=1):
1044 """ Config Proxy Arp Range.
1045
1046 :param low_address: Start address in the rnage to Proxy for
1047 :param hi_address: End address in the rnage to Proxy for
1048 :param vrf_id: The VRF/table in which to proxy
1049 """
1050
1051 return self.api(
1052 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001053 {'proxy':
1054 {
1055 'vrf_id': vrf_id,
1056 'low_address': low_address,
1057 'hi_address': hi_address,
1058 },
1059 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001060
1061 def proxy_arp_intfc_enable_disable(self,
1062 sw_if_index,
1063 is_enable=1):
1064 """ Enable/Disable an interface for proxy ARP requests
1065
1066 :param sw_if_index: Interface
1067 :param enable_disable: Enable/Disable
1068 """
1069
1070 return self.api(
1071 self.papi.proxy_arp_intfc_enable_disable,
1072 {'sw_if_index': sw_if_index,
1073 'enable_disable': is_enable
1074 }
1075 )
1076
Jane546d3b2016-12-08 13:10:03 +01001077 def reset_vrf(self,
1078 vrf_id,
1079 is_ipv6=0,
1080 ):
1081 """ Reset VRF (remove all routes etc.) request.
1082
1083 :param int vrf_id: ID of the FIB table / VRF to reset.
1084 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1085 """
1086
1087 return self.api(
1088 self.papi.reset_vrf,
1089 {'vrf_id': vrf_id,
1090 'is_ipv6': is_ipv6,
1091 }
1092 )
1093
1094 def reset_fib(self,
1095 vrf_id,
1096 is_ipv6=0,
1097 ):
1098 """ Reset VRF (remove all routes etc.) request.
1099
1100 :param int vrf_id: ID of the FIB table / VRF to reset.
1101 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1102 """
1103
1104 return self.api(
1105 self.papi.reset_fib,
1106 {'vrf_id': vrf_id,
1107 'is_ipv6': is_ipv6,
1108 }
1109 )
1110
1111 def ip_dump(self,
1112 is_ipv6=0,
1113 ):
1114 """ Return IP dump.
1115
1116 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1117 """
1118
1119 return self.api(
1120 self.papi.ip_dump,
1121 {'is_ipv6': is_ipv6,
1122 }
1123 )
1124
Klement Sekera7bb873a2016-11-18 07:38:42 +01001125 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001126 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001127 """
1128
1129 :param sw_if_index_from:
1130 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001131 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001132 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001133 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001134 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001135 {'sw_if_index_from': sw_if_index_from,
1136 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001137 'state': state,
1138 'is_l2': is_l2,
1139 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001140
1141 def gre_tunnel_add_del(self,
1142 src_address,
1143 dst_address,
1144 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001145 tunnel_type=0,
1146 instance=0xFFFFFFFF,
1147 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001148 is_add=1,
1149 is_ip6=0):
1150 """ Add a GRE tunnel
1151
1152 :param src_address:
1153 :param dst_address:
1154 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001155 :param tunnel_type: (Default value = 0)
1156 :param instance: (Default value = 0xFFFFFFFF)
1157 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001158 :param is_add: (Default value = 1)
1159 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001160 """
1161
1162 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001163 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001164 {'is_add': is_add,
1165 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001166 'tunnel_type': tunnel_type,
1167 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001168 'src_address': src_address,
1169 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001170 'outer_fib_id': outer_fib_id,
1171 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001172 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001173
Neale Rannsd0df49f2018-08-08 01:06:40 -07001174 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -07001175 src_ip,
1176 dst_ip,
1177 src_port,
1178 dst_port,
1179 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001180 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -08001181 :param src_ip:
1182 :param dst_ip:
1183 :param src_port:
1184 :param dst_port:
1185 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001186 """
1187
1188 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001189 self.papi.udp_encap_add,
1190 {
1191 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -07001192 'src_ip': src_ip,
1193 'dst_ip': dst_ip,
1194 'src_port': src_port,
1195 'dst_port': dst_port,
1196 'table_id': table_id
1197 }
1198 })
1199
1200 def udp_encap_del(self, id):
1201 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001202
1203 def udp_encap_dump(self):
1204 return self.api(self.papi.udp_encap_dump, {})
1205
Neale Ranns43b1f442018-03-20 01:47:35 -07001206 def want_udp_encap_stats(self, enable=1):
1207 return self.api(self.papi.want_udp_encap_stats,
1208 {'enable': enable,
1209 'pid': os.getpid()})
1210
Neale Ranns5a8123b2017-01-26 01:18:23 -08001211 def mpls_fib_dump(self):
1212 return self.api(self.papi.mpls_fib_dump, {})
1213
Neale Ranns15002542017-09-10 04:39:11 -07001214 def mpls_table_add_del(
1215 self,
1216 table_id,
1217 is_add=1):
1218 """
1219
1220 :param table_id
1221 :param is_add: (Default value = 1)
1222
1223 """
1224
1225 return self.api(
1226 self.papi.mpls_table_add_del,
1227 {'mt_table_id': table_id,
1228 'mt_is_add': is_add})
1229
Neale Rannsad422ed2016-11-02 14:20:04 +00001230 def mpls_route_add_del(
1231 self,
1232 label,
1233 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001234 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001235 next_hop_address,
1236 next_hop_sw_if_index=0xFFFFFFFF,
1237 table_id=0,
1238 next_hop_table_id=0,
1239 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001240 next_hop_n_out_labels=0,
1241 next_hop_out_label_stack=[],
1242 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001243 is_resolve_host=0,
1244 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001245 is_interface_rx=0,
1246 is_rpf_id=0,
1247 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001248 is_add=1,
1249 is_drop=0,
1250 is_multipath=0,
1251 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001252 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001253 """
1254
1255 :param dst_address_length:
1256 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1257 :param dst_address:
1258 :param next_hop_address:
1259 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1260 :param vrf_id: (Default value = 0)
1261 :param lookup_in_vrf: (Default value = 0)
1262 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001263 :param is_add: (Default value = 1)
1264 :param is_drop: (Default value = 0)
1265 :param is_ipv6: (Default value = 0)
1266 :param is_local: (Default value = 0)
1267 :param is_classify: (Default value = 0)
1268 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001269 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001270 :param is_resolve_host: (Default value = 0)
1271 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001272 :param next_hop_weight: (Default value = 1)
1273
1274 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001275 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001276 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001277 {'mr_label': label,
1278 'mr_eos': eos,
1279 'mr_table_id': table_id,
1280 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001281 'mr_is_add': is_add,
1282 'mr_is_classify': is_classify,
1283 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001284 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001285 'mr_is_resolve_host': is_resolve_host,
1286 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001287 'mr_is_interface_rx': is_interface_rx,
1288 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001289 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001290 'mr_next_hop_weight': next_hop_weight,
1291 'mr_next_hop': next_hop_address,
1292 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1293 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1294 'mr_next_hop_table_id': next_hop_table_id,
1295 'mr_next_hop_via_label': next_hop_via_label,
1296 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001297
1298 def mpls_ip_bind_unbind(
1299 self,
1300 label,
1301 dst_address,
1302 dst_address_length,
1303 table_id=0,
1304 ip_table_id=0,
1305 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001306 is_bind=1):
1307 """
1308 """
1309 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001310 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001311 {'mb_mpls_table_id': table_id,
1312 'mb_label': label,
1313 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001314 'mb_is_bind': is_bind,
1315 'mb_is_ip4': is_ip4,
1316 'mb_address_length': dst_address_length,
1317 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001318
1319 def mpls_tunnel_add_del(
1320 self,
1321 tun_sw_if_index,
1322 next_hop_proto_is_ip4,
1323 next_hop_address,
1324 next_hop_sw_if_index=0xFFFFFFFF,
1325 next_hop_table_id=0,
1326 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001327 next_hop_n_out_labels=0,
1328 next_hop_out_label_stack=[],
1329 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001330 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001331 l2_only=0,
1332 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001333 """
1334
1335 :param dst_address_length:
1336 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1337 :param dst_address:
1338 :param next_hop_address:
1339 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1340 :param vrf_id: (Default value = 0)
1341 :param lookup_in_vrf: (Default value = 0)
1342 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001343 :param is_add: (Default value = 1)
1344 :param is_drop: (Default value = 0)
1345 :param is_ipv6: (Default value = 0)
1346 :param is_local: (Default value = 0)
1347 :param is_classify: (Default value = 0)
1348 :param is_multipath: (Default value = 0)
1349 :param is_resolve_host: (Default value = 0)
1350 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001351 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001352 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001353
1354 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001355 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001356 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001357 {'mt_sw_if_index': tun_sw_if_index,
1358 'mt_is_add': is_add,
1359 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001360 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001361 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1362 'mt_next_hop_weight': next_hop_weight,
1363 'mt_next_hop': next_hop_address,
1364 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1365 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1366 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001367 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001368 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001369
Neale Rannsf5fa5ae2018-09-26 05:07:25 -07001370 def mpls_tunnel_dump(self, sw_if_index=0xffffffff):
1371 return self.api(self.papi.mpls_tunnel_dump,
1372 {'sw_if_index': sw_if_index})
Neale Ranns6a30b5f2018-09-25 07:22:36 -07001373
Matus Fabian2ba92e32017-08-21 07:05:03 -07001374 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001375 self,
1376 sw_if_index,
1377 is_inside=1,
1378 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001379 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001380
1381 :param sw_if_index: Software index of the interface
1382 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1383 :param is_add: 1 if add, 0 if delete (Default value = 1)
1384 """
1385 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001387 {'is_add': is_add,
1388 'is_inside': is_inside,
1389 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001390
Matus Fabian2ba92e32017-08-21 07:05:03 -07001391 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001392 self,
1393 sw_if_index,
1394 is_inside=1,
1395 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001396 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001397
1398 :param sw_if_index: Software index of the interface
1399 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1400 :param is_add: 1 if add, 0 if delete (Default value = 1)
1401 """
1402 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001403 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001404 {'is_add': is_add,
1405 'is_inside': is_inside,
1406 'sw_if_index': sw_if_index})
1407
Matus Fabian2ba92e32017-08-21 07:05:03 -07001408 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001409 self,
1410 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001411 external_ip=0,
1412 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001413 local_port=0,
1414 external_port=0,
1415 addr_only=1,
1416 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001417 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001418 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001419 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001420 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001421 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001422 is_add=1):
1423 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001424
1425 :param local_ip: Local IP address
1426 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001427 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001428 :param local_port: Local port number (Default value = 0)
1429 :param external_port: External port number (Default value = 0)
1430 :param addr_only: 1 if address only mapping, 0 if address and port
1431 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001432 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001433 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001434 :param self_twice_nat: 1 if translate external host address and port
1435 whenever external host address equals
1436 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001437 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001438 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001439 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001440 """
1441 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001442 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001443 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001444 'addr_only': addr_only,
1445 'local_ip_address': local_ip,
1446 'external_ip_address': external_ip,
1447 'local_port': local_port,
1448 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001449 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001450 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001451 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001452 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001453 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001454 'out2in_only': out2in_only,
1455 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001456
Matus Fabianab7a8052017-11-28 04:29:41 -08001457 def nat44_add_del_identity_mapping(
1458 self,
1459 ip='0',
1460 sw_if_index=0xFFFFFFFF,
1461 port=0,
1462 addr_only=1,
1463 vrf_id=0,
1464 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001465 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001466 is_add=1):
1467 """Add/delete NAT44 identity mapping
1468
1469 :param ip: IP address (Default value = 0)
1470 :param sw_if_index: Interface instead of IP address
1471 :param port: Port number (Default value = 0)
1472 :param addr_only: 1 if address only mapping, 0 if address and port
1473 :param vrf_id: VRF ID
1474 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001475 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001476 :param is_add: 1 if add, 0 if delete (Default value = 1)
1477 """
1478 return self.api(
1479 self.papi.nat44_add_del_identity_mapping,
1480 {'is_add': is_add,
1481 'addr_only': addr_only,
1482 'ip_address': ip,
1483 'port': port,
1484 'sw_if_index': sw_if_index,
1485 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001486 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001487 'protocol': protocol})
1488
Matus Fabian2ba92e32017-08-21 07:05:03 -07001489 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001490 self,
1491 first_ip_address,
1492 last_ip_address,
1493 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001494 vrf_id=0xFFFFFFFF,
1495 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001496 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001497
1498 :param first_ip_address: First IP address
1499 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001500 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001501 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001502 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001503 """
1504 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001505 self.papi.nat44_add_del_address_range,
1506 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001507 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001508 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001509 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001510 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001511
Matus Fabian2ba92e32017-08-21 07:05:03 -07001512 def nat44_address_dump(self):
1513 """Dump NAT44 addresses
1514 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001515 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001516 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001517
Matus Fabian2ba92e32017-08-21 07:05:03 -07001518 def nat44_interface_dump(self):
1519 """Dump interfaces with NAT44 feature
1520 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001521 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001523
Matus Fabian2ba92e32017-08-21 07:05:03 -07001524 def nat44_interface_output_feature_dump(self):
1525 """Dump interfaces with NAT44 output feature
1526 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001527 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001528 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001529
Matus Fabian2ba92e32017-08-21 07:05:03 -07001530 def nat44_static_mapping_dump(self):
1531 """Dump NAT44 static mappings
1532 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001533 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001534 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001535
Matus Fabianab7a8052017-11-28 04:29:41 -08001536 def nat44_identity_mapping_dump(self):
1537 """Dump NAT44 identity mappings
1538 :return: Dictionary of NAT44 identity mappings
1539 """
1540 return self.api(self.papi.nat44_identity_mapping_dump, {})
1541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat_show_config(self):
1543 """Show NAT plugin config
1544 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001545 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001546 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001547
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001549 self,
1550 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001551 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001552 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001554
1555 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001556 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001557 :param is_add: 1 if add, 0 if delete (Default value = 1)
1558 """
Matus Fabianb932d262017-12-18 05:38:24 -08001559 return self.api(
1560 self.papi.nat44_add_del_interface_addr,
1561 {'is_add': is_add,
1562 'sw_if_index': sw_if_index,
1563 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001564
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 def nat44_interface_addr_dump(self):
1566 """Dump NAT44 addresses interfaces
1567 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001568 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001569 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001570
Matus Fabian2ba92e32017-08-21 07:05:03 -07001571 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001572 self,
1573 domain_id=1,
1574 src_port=4739,
1575 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001577
1578 :param domain_id: Observation domain ID (Default value = 1)
1579 :param src_port: Source port number (Default value = 4739)
1580 :param enable: 1 if enable, 0 if disable (Default value = 1)
1581 """
1582 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001583 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001584 {'domain_id': domain_id,
1585 'src_port': src_port,
1586 'enable': enable})
1587
Matus Fabian2ba92e32017-08-21 07:05:03 -07001588 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001589 self,
1590 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001591 vrf_id):
1592 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001593
1594 :param ip_address: ip adress of the user to be dumped
1595 :param cpu_index: cpu_index on which the user is
1596 :param vrf_id: VRF ID
1597 :return: Dictionary of S-NAT sessions
1598 """
1599 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001600 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001601 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001602 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001603
Matus Fabian2ba92e32017-08-21 07:05:03 -07001604 def nat44_user_dump(self):
1605 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001606
Matus Fabian2ba92e32017-08-21 07:05:03 -07001607 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001608 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001609 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001610
Matus Fabian704018c2017-09-04 02:17:18 -07001611 def nat44_add_del_lb_static_mapping(
1612 self,
1613 external_addr,
1614 external_port,
1615 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001616 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001617 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001618 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001619 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001620 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001621 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001622 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001623 is_add=1):
1624 """Add/delete NAT44 load balancing static mapping
1625
Matus Fabianb932d262017-12-18 05:38:24 -08001626 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001627 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001628 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001629 :param is_add - 1 if add, 0 if delete
1630 """
1631 return self.api(
1632 self.papi.nat44_add_del_lb_static_mapping,
1633 {'is_add': is_add,
1634 'external_addr': external_addr,
1635 'external_port': external_port,
1636 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001637 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001638 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001639 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001640 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001641 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001642 'local_num': local_num,
1643 'locals': locals})
1644
1645 def nat44_lb_static_mapping_dump(self):
1646 """Dump NAT44 load balancing static mappings
1647
1648 :return: Dictionary of NAT44 load balancing static mapping
1649 """
1650 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1651
Matus Fabian5ba86f72017-10-26 03:37:38 -07001652 def nat44_del_session(
1653 self,
1654 addr,
1655 port,
1656 protocol,
1657 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001658 is_in=1,
1659 ext_host_address=None,
1660 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001661 """Delete NAT44 session
1662
1663 :param addr: IPv4 address
1664 :param por: port number
1665 :param protocol: IP protocol number
1666 :param vrf_id: VRF ID
1667 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001668 :param ext_host_address: external host IPv4 address
1669 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001670 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001671 if ext_host_address is None:
1672 return self.api(
1673 self.papi.nat44_del_session,
1674 {'address': addr,
1675 'port': port,
1676 'protocol': protocol,
1677 'vrf_id': vrf_id,
1678 'is_in': is_in})
1679 else:
1680 return self.api(
1681 self.papi.nat44_del_session,
1682 {'address': addr,
1683 'port': port,
1684 'protocol': protocol,
1685 'vrf_id': vrf_id,
1686 'is_in': is_in,
1687 'ext_host_valid': 1,
1688 'ext_host_address': ext_host_address,
1689 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001690
Juraj Sloboda7b929792017-11-23 13:20:48 +01001691 def nat44_forwarding_enable_disable(
1692 self,
1693 enable):
1694 """Enable/disable forwarding for NAT44
1695
1696 :param enable: 1 for enable, 0 for disable
1697 """
1698 return self.api(
1699 self.papi.nat44_forwarding_enable_disable,
1700 {'enable': enable})
1701
Matus Fabianefcd1e92017-08-15 06:59:19 -07001702 def nat_set_reass(
1703 self,
1704 timeout=2,
1705 max_reass=1024,
1706 max_frag=5,
1707 drop_frag=0,
1708 is_ip6=0):
1709 """Set NAT virtual fragmentation reassembly
1710
1711 :param timeout: reassembly timeout (Default 2sec)
1712 :param max_reass: maximum concurrent reassemblies (Default 1024)
1713 :param max_frag: maximum fragmets per reassembly (Default 5)
1714 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1715 :param is_ip6: 1 if IPv6, 0 if IPv4
1716 """
1717 return self.api(
1718 self.papi.nat_set_reass,
1719 {'timeout': timeout,
1720 'max_reass': max_reass,
1721 'max_frag': max_frag,
1722 'drop_frag': drop_frag,
1723 'is_ip6': is_ip6})
1724
1725 def nat_get_reass(self):
1726 """Get NAT virtual fragmentation reassembly configuration
1727
1728 :return: NAT virtual fragmentation reassembly configuration
1729 """
1730 return self.api(self.papi.nat_get_reass, {})
1731
1732 def nat_reass_dump(self):
1733 """Dump NAT virtual fragmentation reassemblies
1734
1735 :return: Dictionary of NAT virtual fragmentation reassemblies
1736 """
1737 return self.api(self.papi.nat_reass_dump, {})
1738
Matus Fabian2ba92e32017-08-21 07:05:03 -07001739 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001740 self,
1741 in_addr,
1742 in_plen,
1743 out_addr,
1744 out_plen,
1745 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001746 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001747
1748 :param is_add - 1 if add, 0 if delete
1749 :param in_addr - inside IP address
1750 :param in_plen - inside IP address prefix length
1751 :param out_addr - outside IP address
1752 :param out_plen - outside IP address prefix length
1753 """
1754 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001755 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001756 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001757 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001758 'in_addr': in_addr,
1759 'in_plen': in_plen,
1760 'out_addr': out_addr,
1761 'out_plen': out_plen})
1762
Matus Fabian2ba92e32017-08-21 07:05:03 -07001763 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001764 self,
1765 in_addr):
1766 """Get outside address and port range from inside address
1767
1768 :param in_addr - inside IP address
1769 """
1770 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001771 self.papi.nat_det_forward,
1772 {'in_addr': in_addr,
1773 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001774
Matus Fabian2ba92e32017-08-21 07:05:03 -07001775 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001776 self,
1777 out_addr,
1778 out_port):
1779 """Get inside address from outside address and port
1780
1781 :param out_addr - outside IP address
1782 :param out_port - outside port
1783 """
1784 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001785 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001786 {'out_addr': out_addr,
1787 'out_port': out_port})
1788
Matus Fabian2ba92e32017-08-21 07:05:03 -07001789 def nat_det_map_dump(self):
1790 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001791
Matus Fabian2ba92e32017-08-21 07:05:03 -07001792 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001793 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001794 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001795
Matus Fabian878c6462018-08-23 00:33:35 -07001796 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001797 self,
1798 udp=300,
1799 tcp_established=7440,
1800 tcp_transitory=240,
1801 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001802 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001803
1804 :param udp - UDP timeout (Default value = 300)
1805 :param tcp_established - TCP established timeout (Default value = 7440)
1806 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1807 :param icmp - ICMP timeout (Default value = 60)
1808 """
1809 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001810 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001811 {'udp': udp,
1812 'tcp_established': tcp_established,
1813 'tcp_transitory': tcp_transitory,
1814 'icmp': icmp})
1815
Matus Fabian878c6462018-08-23 00:33:35 -07001816 def nat_get_timeouts(self):
1817 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001818
Matus Fabian878c6462018-08-23 00:33:35 -07001819 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001820 """
Matus Fabian878c6462018-08-23 00:33:35 -07001821 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001822
Matus Fabian5d28c7a2018-09-04 03:55:45 -07001823 def nat_set_addr_and_port_alloc_alg(
1824 self,
1825 alg=0,
1826 psid_offset=0,
1827 psid_length=0,
1828 psid=0,
1829 start_port=0,
1830 end_port=0):
1831 """Set address and port assignment algorithm
1832
1833 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1834 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1835 :param psid_length: length of PSID (valid only for MAP-E alg)
1836 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1837 :param start_port: beginning of the port range
1838 :param end_port: end of the port range
1839 """
1840 return self.api(
1841 self.papi.nat_set_addr_and_port_alloc_alg,
1842 {'alg': alg,
1843 'psid_offset': psid_offset,
1844 'psid_length': psid_length,
1845 'psid': psid,
1846 'start_port': start_port,
1847 'end_port': end_port})
1848
1849 def nat_get_addr_and_port_alloc_alg(self):
1850 """Get address and port assignment algorithm"""
1851 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1852
Matus Fabianbb4e0222018-09-13 02:36:25 -07001853 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1854 """Set TCP MSS rewriting configuration
1855
1856 :param enable: disable(0)/enable(1) MSS rewriting feature
1857 :param mss_value: MSS value to be used for MSS rewriting
1858 """
1859 return self.api(
1860 self.papi.nat_set_mss_clamping,
1861 {'enable': enable, 'mss_value': mss_value})
1862
1863 def nat_get_mss_clamping(self):
1864 """Get TCP MSS rewriting configuration"""
1865 return self.api(self.papi.nat_get_mss_clamping, {})
1866
Matus Fabian2ba92e32017-08-21 07:05:03 -07001867 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001868 self,
1869 out_addr,
1870 out_port,
1871 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001872 ext_port):
1873 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001874
1875 :param out_addr - outside IP address
1876 :param out_port - outside port
1877 :param ext_addr - external host IP address
1878 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001879 """
1880 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001881 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001882 {'out_addr': out_addr,
1883 'out_port': out_port,
1884 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001885 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001886
Matus Fabian2ba92e32017-08-21 07:05:03 -07001887 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001888 self,
1889 in_addr,
1890 in_port,
1891 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001892 ext_port):
1893 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001894
1895 :param in_addr - inside IP address
1896 :param in_port - inside port
1897 :param ext_addr - external host IP address
1898 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001899 """
1900 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001901 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001902 {'in_addr': in_addr,
1903 'in_port': in_port,
1904 'ext_addr': ext_addr,
1905 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001906 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001907
Matus Fabian2ba92e32017-08-21 07:05:03 -07001908 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001909 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001910 user_addr):
1911 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001912
1913 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001914 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001915 """
1916 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001917 self.papi.nat_det_session_dump,
1918 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001919 'user_addr': user_addr})
1920
Matus Fabian06596c52017-06-06 04:53:28 -07001921 def nat64_add_del_pool_addr_range(
1922 self,
1923 start_addr,
1924 end_addr,
1925 vrf_id=0xFFFFFFFF,
1926 is_add=1):
1927 """Add/del address range to NAT64 pool
1928
1929 :param start_addr: First IP address
1930 :param end_addr: Last IP address
1931 :param vrf_id: VRF id for the address range
1932 :param is_add: 1 if add, 0 if delete (Default value = 1)
1933 """
1934 return self.api(
1935 self.papi.nat64_add_del_pool_addr_range,
1936 {'start_addr': start_addr,
1937 'end_addr': end_addr,
1938 'vrf_id': vrf_id,
1939 'is_add': is_add})
1940
1941 def nat64_pool_addr_dump(self):
1942 """Dump NAT64 pool addresses
1943 :return: Dictionary of NAT64 pool addresses
1944 """
1945 return self.api(self.papi.nat64_pool_addr_dump, {})
1946
1947 def nat64_add_del_interface(
1948 self,
1949 sw_if_index,
1950 is_inside=1,
1951 is_add=1):
1952 """Enable/disable NAT64 feature on the interface
1953 :param sw_if_index: Index of the interface
1954 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1955 :param is_add: 1 if add, 0 if delete (Default value = 1)
1956 """
1957 return self.api(
1958 self.papi.nat64_add_del_interface,
1959 {'sw_if_index': sw_if_index,
1960 'is_inside': is_inside,
1961 'is_add': is_add})
1962
1963 def nat64_interface_dump(self):
1964 """Dump interfaces with NAT64 feature
1965 :return: Dictionary of interfaces with NAT64 feature
1966 """
1967 return self.api(self.papi.nat64_interface_dump, {})
1968
1969 def nat64_add_del_static_bib(
1970 self,
1971 in_ip,
1972 out_ip,
1973 in_port,
1974 out_port,
1975 protocol,
1976 vrf_id=0,
1977 is_add=1):
1978 """Add/delete S-NAT static BIB entry
1979
1980 :param in_ip: Inside IPv6 address
1981 :param out_ip: Outside IPv4 address
1982 :param in_port: Inside port number
1983 :param out_port: Outside port number
1984 :param protocol: IP protocol
1985 :param vrf_id: VRF ID (Default value = 0)
1986 :param is_add: 1 if add, 0 if delete (Default value = 1)
1987 """
1988 return self.api(
1989 self.papi.nat64_add_del_static_bib,
1990 {'i_addr': in_ip,
1991 'o_addr': out_ip,
1992 'i_port': in_port,
1993 'o_port': out_port,
1994 'vrf_id': vrf_id,
1995 'proto': protocol,
1996 'is_add': is_add})
1997
Matus Fabianab9a59c2017-08-16 05:37:36 -07001998 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001999 """Dump NAT64 BIB
2000
Matus Fabianab9a59c2017-08-16 05:37:36 -07002001 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07002002 :returns: Dictionary of NAT64 BIB entries
2003 """
2004 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
2005
2006 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
2007 tcp_incoming_syn=6):
2008 """Set values of timeouts for NAT64 (in seconds)
2009
Matus Fabian428dc912017-06-21 06:15:18 -07002010 :param udpi: UDP timeout (Default value = 300)
2011 :param icmp: ICMP timeout (Default value = 60)
2012 :param tcp_trans: TCP transitory timeout (Default value = 240)
2013 :param tcp_est: TCP established timeout (Default value = 7440)
2014 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07002015 """
2016 return self.api(
2017 self.papi.nat64_set_timeouts,
2018 {'udp': udp,
2019 'icmp': icmp,
2020 'tcp_trans': tcp_trans,
2021 'tcp_est': tcp_est,
2022 'tcp_incoming_syn': tcp_incoming_syn})
2023
2024 def nat64_get_timeouts(self):
2025 """Get values of timeouts for NAT64
2026
2027 :return: Timeouts for NAT64 (in seconds)
2028 """
2029 return self.api(self.papi.nat64_get_timeouts, {})
2030
Matus Fabianab9a59c2017-08-16 05:37:36 -07002031 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07002032 """Dump NAT64 session table
2033
Matus Fabianab9a59c2017-08-16 05:37:36 -07002034 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07002035 :returns: Dictionary of NAT64 sesstion table entries
2036 """
2037 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2038
Matus Fabian428dc912017-06-21 06:15:18 -07002039 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2040 """Add/del NAT64 prefix
2041
2042 :param prefix: NAT64 prefix
2043 :param plen: NAT64 prefix length
2044 :param vrf_id: VRF id of tenant (Default 0)
2045 :param is_add: 1 if add, 0 if delete (Default value = 1)
2046 """
2047 return self.api(
2048 self.papi.nat64_add_del_prefix,
2049 {'prefix': prefix,
2050 'prefix_len': plen,
2051 'vrf_id': vrf_id,
2052 'is_add': is_add})
2053
2054 def nat64_prefix_dump(self):
2055 """Dump NAT64 prefix
2056
2057 :returns: Dictionary of NAT64 prefixes
2058 """
2059 return self.api(self.papi.nat64_prefix_dump, {})
2060
Matus Fabian0938dcf2017-11-08 01:59:38 -08002061 def nat64_add_interface_addr(
2062 self,
2063 sw_if_index,
2064 is_add=1):
2065 """Add/del NAT64 address from interface
2066
2067 :param sw_if_index: Software index of the interface
2068 :param is_add: 1 if add, 0 if delete (Default value = 1)
2069 """
2070 return self.api(self.papi.nat64_add_del_interface_addr,
2071 {'is_add': is_add, 'sw_if_index': sw_if_index})
2072
Matus Fabian8ebe6252017-11-06 05:04:53 -08002073 def dslite_set_aftr_addr(self, ip6, ip4):
2074 """Set DS-Lite AFTR addresses
2075
2076 :param ip4: IPv4 address
2077 :param ip6: IPv6 address
2078 """
2079 return self.api(
2080 self.papi.dslite_set_aftr_addr,
2081 {'ip4_addr': ip4,
2082 'ip6_addr': ip6})
2083
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002084 def dslite_set_b4_addr(self, ip6, ip4):
2085 """Set DS-Lite B4 IPv6 address
2086
2087 :param ip4: IPv4 address
2088 :param ip6: IPv6 address
2089 """
2090 return self.api(
2091 self.papi.dslite_set_b4_addr,
2092 {'ip4_addr': ip4,
2093 'ip6_addr': ip6})
2094
Matus Fabian8ebe6252017-11-06 05:04:53 -08002095 def dslite_add_del_pool_addr_range(
2096 self,
2097 start_addr,
2098 end_addr,
2099 is_add=1):
2100 """Add/del address range to DS-Lite pool
2101
2102 :param start_addr: First IP address
2103 :param end_addr: Last IP address
2104 :param is_add: 1 if add, 0 if delete (Default value = 1)
2105 """
2106 return self.api(
2107 self.papi.dslite_add_del_pool_addr_range,
2108 {'start_addr': start_addr,
2109 'end_addr': end_addr,
2110 'is_add': is_add})
2111
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002112 def nat66_add_del_interface(
2113 self,
2114 sw_if_index,
2115 is_inside=1,
2116 is_add=1):
2117 """Enable/disable NAT66 feature on the interface
2118 :param sw_if_index: Index of the interface
2119 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2120 :param is_add: 1 if add, 0 if delete (Default value = 1)
2121 """
2122 return self.api(
2123 self.papi.nat66_add_del_interface,
2124 {'sw_if_index': sw_if_index,
2125 'is_inside': is_inside,
2126 'is_add': is_add})
2127
2128 def nat66_add_del_static_mapping(
2129 self,
2130 in_ip,
2131 out_ip,
2132 vrf_id=0,
2133 is_add=1):
2134 """Add/delete NAT66 static mapping
2135
2136 :param in_ip: Inside IPv6 address
2137 :param out_ip: Outside IPv6 address
2138 :param vrf_id: VRF ID (Default value = 0)
2139 :param is_add: 1 if add, 0 if delete (Default value = 1)
2140 """
2141 return self.api(
2142 self.papi.nat66_add_del_static_mapping,
2143 {'local_ip_address': in_ip,
2144 'external_ip_address': out_ip,
2145 'vrf_id': vrf_id,
2146 'is_add': is_add})
2147
2148 def nat66_interface_dump(self):
2149 """Dump interfaces with NAT66 feature
2150 :return: Dictionary of interfaces with NAT66 feature
2151 """
2152 return self.api(self.papi.nat66_interface_dump, {})
2153
2154 def nat66_static_mapping_dump(self):
2155 """Dump NAT66 static mappings
2156 :return: Dictionary of NAT66 static mappings
2157 """
2158 return self.api(self.papi.nat66_static_mapping_dump, {})
2159
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002160 def control_ping(self):
2161 self.api(self.papi.control_ping)
2162
2163 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002164 detect_mult, local_addr, peer_addr, is_ipv6=0,
2165 bfd_key_id=None, conf_key_id=None):
2166 if bfd_key_id is None:
2167 return self.api(self.papi.bfd_udp_add,
2168 {
2169 'sw_if_index': sw_if_index,
2170 'desired_min_tx': desired_min_tx,
2171 'required_min_rx': required_min_rx,
2172 'local_addr': local_addr,
2173 'peer_addr': peer_addr,
2174 'is_ipv6': is_ipv6,
2175 'detect_mult': detect_mult,
2176 })
2177 else:
2178 return self.api(self.papi.bfd_udp_add,
2179 {
2180 'sw_if_index': sw_if_index,
2181 'desired_min_tx': desired_min_tx,
2182 'required_min_rx': required_min_rx,
2183 'local_addr': local_addr,
2184 'peer_addr': peer_addr,
2185 'is_ipv6': is_ipv6,
2186 'detect_mult': detect_mult,
2187 'is_authenticated': 1,
2188 'bfd_key_id': bfd_key_id,
2189 'conf_key_id': conf_key_id,
2190 })
2191
Klement Sekeraa57a9702017-02-02 06:58:07 +01002192 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2193 detect_mult, local_addr, peer_addr, is_ipv6=0):
2194 return self.api(self.papi.bfd_udp_mod,
2195 {
2196 'sw_if_index': sw_if_index,
2197 'desired_min_tx': desired_min_tx,
2198 'required_min_rx': required_min_rx,
2199 'local_addr': local_addr,
2200 'peer_addr': peer_addr,
2201 'is_ipv6': is_ipv6,
2202 'detect_mult': detect_mult,
2203 })
2204
Klement Sekerab17dd962017-01-09 07:43:48 +01002205 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2206 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2207 is_delayed=False):
2208 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002209 {
2210 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002211 'local_addr': local_addr,
2212 'peer_addr': peer_addr,
2213 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002214 'is_delayed': 1 if is_delayed else 0,
2215 'bfd_key_id': bfd_key_id,
2216 'conf_key_id': conf_key_id,
2217 })
2218
2219 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2220 is_ipv6=0, is_delayed=False):
2221 return self.api(self.papi.bfd_udp_auth_deactivate,
2222 {
2223 'sw_if_index': sw_if_index,
2224 'local_addr': local_addr,
2225 'peer_addr': peer_addr,
2226 'is_ipv6': is_ipv6,
2227 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002228 })
2229
2230 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2231 return self.api(self.papi.bfd_udp_del,
2232 {
2233 'sw_if_index': sw_if_index,
2234 'local_addr': local_addr,
2235 'peer_addr': peer_addr,
2236 'is_ipv6': is_ipv6,
2237 })
2238
2239 def bfd_udp_session_dump(self):
2240 return self.api(self.papi.bfd_udp_session_dump, {})
2241
Klement Sekerab17dd962017-01-09 07:43:48 +01002242 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2243 peer_addr, is_ipv6=0):
2244 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002245 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002246 'sw_if_index': sw_if_index,
2247 'local_addr': local_addr,
2248 'peer_addr': peer_addr,
2249 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002250 })
2251
2252 def want_bfd_events(self, enable_disable=1):
2253 return self.api(self.papi.want_bfd_events, {
2254 'enable_disable': enable_disable,
2255 'pid': os.getpid(),
2256 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002257
Klement Sekerab17dd962017-01-09 07:43:48 +01002258 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2259 return self.api(self.papi.bfd_auth_set_key, {
2260 'conf_key_id': conf_key_id,
2261 'auth_type': auth_type,
2262 'key': key,
2263 'key_len': len(key),
2264 })
2265
2266 def bfd_auth_del_key(self, conf_key_id):
2267 return self.api(self.papi.bfd_auth_del_key, {
2268 'conf_key_id': conf_key_id,
2269 })
2270
2271 def bfd_auth_keys_dump(self):
2272 return self.api(self.papi.bfd_auth_keys_dump, {})
2273
Klement Sekera239790f2017-02-16 10:53:53 +01002274 def bfd_udp_set_echo_source(self, sw_if_index):
2275 return self.api(self.papi.bfd_udp_set_echo_source,
2276 {'sw_if_index': sw_if_index})
2277
Klement Sekera73884482017-02-23 09:26:30 +01002278 def bfd_udp_del_echo_source(self):
2279 return self.api(self.papi.bfd_udp_del_echo_source, {})
2280
Matus Fabian2d3c7b92018-10-02 03:22:18 -07002281 def bfd_udp_get_echo_source(self):
2282 return self.api(self.papi.bfd_udp_get_echo_source, {})
2283
Steve Shin7957d6e2016-12-19 09:24:50 -08002284 def classify_add_del_table(
2285 self,
2286 is_add,
2287 mask,
2288 match_n_vectors=1,
2289 table_index=0xFFFFFFFF,
2290 nbuckets=2,
2291 memory_size=2097152,
2292 skip_n_vectors=0,
2293 next_table_index=0xFFFFFFFF,
2294 miss_next_index=0xFFFFFFFF,
2295 current_data_flag=0,
2296 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002297 """
2298 :param is_add:
2299 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002300 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002301 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002302 :param nbuckets: (Default value = 2)
2303 :param memory_size: (Default value = 2097152)
2304 :param skip_n_vectors: (Default value = 0)
2305 :param next_table_index: (Default value = 0xFFFFFFFF)
2306 :param miss_next_index: (Default value = 0xFFFFFFFF)
2307 :param current_data_flag: (Default value = 0)
2308 :param current_data_offset: (Default value = 0)
2309 """
2310
Juraj Sloboda75282452018-06-12 14:20:49 +02002311 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2312 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002313 return self.api(
2314 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002315 {'is_add': is_add,
2316 'table_index': table_index,
2317 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002318 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002319 'skip_n_vectors': skip_n_vectors,
2320 'match_n_vectors': match_n_vectors,
2321 'next_table_index': next_table_index,
2322 'miss_next_index': miss_next_index,
2323 'current_data_flag': current_data_flag,
2324 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002325 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002326 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002327
2328 def classify_add_del_session(
2329 self,
2330 is_add,
2331 table_index,
2332 match,
2333 opaque_index=0xFFFFFFFF,
2334 hit_next_index=0xFFFFFFFF,
2335 advance=0,
2336 action=0,
2337 metadata=0):
2338 """
2339 :param is_add:
2340 :param table_index:
2341 :param match:
2342 :param opaque_index: (Default value = 0xFFFFFFFF)
2343 :param hit_next_index: (Default value = 0xFFFFFFFF)
2344 :param advance: (Default value = 0)
2345 :param action: (Default value = 0)
2346 :param metadata: (Default value = 0)
2347 """
2348
Juraj Sloboda75282452018-06-12 14:20:49 +02002349 match_len = ((len(match) - 1) / 16 + 1) * 16
2350 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002351 return self.api(
2352 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002353 {'is_add': is_add,
2354 'table_index': table_index,
2355 'hit_next_index': hit_next_index,
2356 'opaque_index': opaque_index,
2357 'advance': advance,
2358 'action': action,
2359 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002360 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002361 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002362
2363 def input_acl_set_interface(
2364 self,
2365 is_add,
2366 sw_if_index,
2367 ip4_table_index=0xFFFFFFFF,
2368 ip6_table_index=0xFFFFFFFF,
2369 l2_table_index=0xFFFFFFFF):
2370 """
2371 :param is_add:
2372 :param sw_if_index:
2373 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2374 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2375 :param l2_table_index: (Default value = 0xFFFFFFFF)
2376 """
2377
2378 return self.api(
2379 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002380 {'sw_if_index': sw_if_index,
2381 'ip4_table_index': ip4_table_index,
2382 'ip6_table_index': ip6_table_index,
2383 'l2_table_index': l2_table_index,
2384 'is_add': is_add})
2385
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002386 def output_acl_set_interface(
2387 self,
2388 is_add,
2389 sw_if_index,
2390 ip4_table_index=0xFFFFFFFF,
2391 ip6_table_index=0xFFFFFFFF,
2392 l2_table_index=0xFFFFFFFF):
2393 """
2394 :param is_add:
2395 :param sw_if_index:
2396 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2397 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2398 :param l2_table_index: (Default value = 0xFFFFFFFF)
2399 """
2400
2401 return self.api(
2402 self.papi.output_acl_set_interface,
2403 {'sw_if_index': sw_if_index,
2404 'ip4_table_index': ip4_table_index,
2405 'ip6_table_index': ip6_table_index,
2406 'l2_table_index': l2_table_index,
2407 'is_add': is_add})
2408
Klement Sekera77fabdb2017-01-02 07:46:14 +01002409 def set_ipfix_exporter(
2410 self,
2411 collector_address,
2412 src_address,
2413 path_mtu,
2414 template_interval,
2415 vrf_id=0,
2416 collector_port=4739,
2417 udp_checksum=0):
2418 return self.api(
2419 self.papi.set_ipfix_exporter,
2420 {
2421 'collector_address': collector_address,
2422 'collector_port': collector_port,
2423 'src_address': src_address,
2424 'vrf_id': vrf_id,
2425 'path_mtu': path_mtu,
2426 'template_interval': template_interval,
2427 'udp_checksum': udp_checksum,
2428 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002429
2430 def dhcp_proxy_config(self,
2431 dhcp_server,
2432 dhcp_src_address,
2433 rx_table_id=0,
2434 server_table_id=0,
2435 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002436 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002437 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002438 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002439 {
2440 'rx_vrf_id': rx_table_id,
2441 'server_vrf_id': server_table_id,
2442 'is_ipv6': is_ipv6,
2443 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002444 'dhcp_server': dhcp_server,
2445 'dhcp_src_address': dhcp_src_address,
2446 })
2447
2448 def dhcp_proxy_set_vss(self,
2449 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002450 vss_type=255,
2451 vpn_ascii_id="",
2452 oui=0,
2453 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002454 is_add=1,
2455 is_ip6=0):
2456 return self.api(
2457 self.papi.dhcp_proxy_set_vss,
2458 {
2459 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002460 'vss_type': vss_type,
2461 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002462 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002463 'vpn_index': vpn_index,
2464 'is_add': is_add,
2465 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002466 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002467
Neale Rannsdaff1782018-05-16 04:12:18 -07002468 def dhcp_client_dump(self):
2469 return self.api(self.papi.dhcp_client_dump, {})
2470
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002471 def dhcp_client(self,
2472 sw_if_index,
2473 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002474 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002475 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002476 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002477 want_dhcp_events=0):
2478 return self.api(
2479 self.papi.dhcp_client_config,
2480 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002481 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002482 'client': {
2483 'sw_if_index': sw_if_index,
2484 'hostname': hostname,
2485 'id': client_id,
2486 'want_dhcp_event': want_dhcp_events,
2487 'set_broadcast_flag': set_broadcast_flag,
2488 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002489 })
2490
Neale Ranns32e1c012016-11-22 17:07:28 +00002491 def ip_mroute_add_del(self,
2492 src_address,
2493 grp_address,
2494 grp_address_length,
2495 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002496 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002497 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002498 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002499 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002500 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002501 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002502 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002503 is_add=1,
2504 is_ipv6=0,
2505 is_local=0):
2506 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002507 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002508 """
2509 return self.api(
2510 self.papi.ip_mroute_add_del,
2511 {'next_hop_sw_if_index': next_hop_sw_if_index,
2512 'entry_flags': e_flags,
2513 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002514 'table_id': table_id,
2515 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002516 'is_add': is_add,
2517 'is_ipv6': is_ipv6,
2518 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002519 'bier_imp': bier_imp,
2520 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002521 'grp_address_length': grp_address_length,
2522 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002523 'src_address': src_address,
2524 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002525
2526 def mfib_signal_dump(self):
2527 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002528
2529 def ip_mfib_dump(self):
2530 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002531
Neale Rannsd792d9c2017-10-21 10:53:20 -07002532 def ip6_mfib_dump(self):
2533 return self.api(self.papi.ip6_mfib_dump, {})
2534
Filip Tehlar770e89e2017-01-31 10:39:16 +01002535 def lisp_enable_disable(self, is_enabled):
2536 return self.api(
2537 self.papi.lisp_enable_disable,
2538 {
2539 'is_en': is_enabled,
2540 })
2541
2542 def lisp_locator_set(self,
2543 ls_name,
2544 is_add=1):
2545 return self.api(
2546 self.papi.lisp_add_del_locator_set,
2547 {
2548 'is_add': is_add,
2549 'locator_set_name': ls_name
2550 })
2551
2552 def lisp_locator_set_dump(self):
2553 return self.api(self.papi.lisp_locator_set_dump, {})
2554
2555 def lisp_locator(self,
2556 ls_name,
2557 sw_if_index,
2558 priority=1,
2559 weight=1,
2560 is_add=1):
2561 return self.api(
2562 self.papi.lisp_add_del_locator,
2563 {
2564 'is_add': is_add,
2565 'locator_set_name': ls_name,
2566 'sw_if_index': sw_if_index,
2567 'priority': priority,
2568 'weight': weight
2569 })
2570
2571 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2572 return self.api(
2573 self.papi.lisp_locator_dump,
2574 {
2575 'is_index_set': is_index_set,
2576 'ls_name': ls_name,
2577 'ls_index': ls_index,
2578 })
2579
2580 def lisp_local_mapping(self,
2581 ls_name,
2582 eid_type,
2583 eid,
2584 prefix_len,
2585 vni=0,
2586 key_id=0,
2587 key="",
2588 is_add=1):
2589 return self.api(
2590 self.papi.lisp_add_del_local_eid,
2591 {
2592 'locator_set_name': ls_name,
2593 'is_add': is_add,
2594 'eid_type': eid_type,
2595 'eid': eid,
2596 'prefix_len': prefix_len,
2597 'vni': vni,
2598 'key_id': key_id,
2599 'key': key
2600 })
2601
2602 def lisp_eid_table_dump(self,
2603 eid_set=0,
2604 prefix_length=0,
2605 vni=0,
2606 eid_type=0,
2607 eid=None,
2608 filter_opt=0):
2609 return self.api(
2610 self.papi.lisp_eid_table_dump,
2611 {
2612 'eid_set': eid_set,
2613 'prefix_length': prefix_length,
2614 'vni': vni,
2615 'eid_type': eid_type,
2616 'eid': eid,
2617 'filter': filter_opt,
2618 })
2619
2620 def lisp_remote_mapping(self,
2621 eid_type,
2622 eid,
2623 eid_prefix_len=0,
2624 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002625 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002626 rlocs_num=0,
2627 is_src_dst=0,
2628 is_add=1):
2629 return self.api(
2630 self.papi.lisp_add_del_remote_mapping,
2631 {
2632 'is_add': is_add,
2633 'eid_type': eid_type,
2634 'eid': eid,
2635 'eid_len': eid_prefix_len,
2636 'rloc_num': rlocs_num,
2637 'rlocs': rlocs,
2638 'vni': vni,
2639 'is_src_dst': is_src_dst,
2640 })
2641
2642 def lisp_adjacency(self,
2643 leid,
2644 reid,
2645 leid_len,
2646 reid_len,
2647 eid_type,
2648 is_add=1,
2649 vni=0):
2650 return self.api(
2651 self.papi.lisp_add_del_adjacency,
2652 {
2653 'is_add': is_add,
2654 'vni': vni,
2655 'eid_type': eid_type,
2656 'leid': leid,
2657 'reid': reid,
2658 'leid_len': leid_len,
2659 'reid_len': reid_len,
2660 })
2661
2662 def lisp_adjacencies_get(self, vni=0):
2663 return self.api(
2664 self.papi.lisp_adjacencies_get,
2665 {
2666 'vni': vni
2667 })
Neale Ranns80823802017-02-20 18:23:41 -08002668
2669 def map_add_domain(self,
2670 ip6_prefix,
2671 ip6_prefix_len,
2672 ip6_src,
2673 ip6_src_prefix_len,
2674 ip4_prefix,
2675 ip4_prefix_len,
2676 ea_bits_len=0,
2677 psid_offset=0,
2678 psid_length=0,
2679 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002680 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002681 mtu=1280):
2682 return self.api(
2683 self.papi.map_add_domain,
2684 {
2685 'ip6_prefix': ip6_prefix,
2686 'ip6_prefix_len': ip6_prefix_len,
2687 'ip4_prefix': ip4_prefix,
2688 'ip4_prefix_len': ip4_prefix_len,
2689 'ip6_src': ip6_src,
2690 'ip6_src_prefix_len': ip6_src_prefix_len,
2691 'ea_bits_len': ea_bits_len,
2692 'psid_offset': psid_offset,
2693 'psid_length': psid_length,
2694 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002695 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002696 'mtu': mtu
2697 })
Hongjun Nief486b12017-04-12 19:21:16 +08002698
2699 def gtpu_add_del_tunnel(
2700 self,
2701 src_addr,
2702 dst_addr,
2703 is_add=1,
2704 is_ipv6=0,
2705 mcast_sw_if_index=0xFFFFFFFF,
2706 encap_vrf_id=0,
2707 decap_next_index=0xFFFFFFFF,
2708 teid=0):
2709 """
2710
2711 :param is_add: (Default value = 1)
2712 :param is_ipv6: (Default value = 0)
2713 :param src_addr:
2714 :param dst_addr:
2715 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2716 :param encap_vrf_id: (Default value = 0)
2717 :param decap_next_index: (Default value = 0xFFFFFFFF)
2718 :param teid: (Default value = 0)
2719
2720 """
2721 return self.api(self.papi.gtpu_add_del_tunnel,
2722 {'is_add': is_add,
2723 'is_ipv6': is_ipv6,
2724 'src_address': src_addr,
2725 'dst_address': dst_addr,
2726 'mcast_sw_if_index': mcast_sw_if_index,
2727 'encap_vrf_id': encap_vrf_id,
2728 'decap_next_index': decap_next_index,
2729 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002730
2731 def vxlan_gpe_add_del_tunnel(
2732 self,
2733 src_addr,
2734 dst_addr,
2735 mcast_sw_if_index=0xFFFFFFFF,
2736 is_add=1,
2737 is_ipv6=0,
2738 encap_vrf_id=0,
2739 decap_vrf_id=0,
2740 protocol=3,
2741 vni=0):
2742 """
2743
2744 :param local:
2745 :param remote:
2746 :param is_add: (Default value = 1)
2747 :param is_ipv6: (Default value = 0)
2748 :param encap_vrf_id: (Default value = 0)
2749 :param decap_vrf_id: (Default value = 0)
2750 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2751 :param protocol: (Default value = 3)
2752 :param vni: (Default value = 0)
2753
2754 """
2755 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2756 {'is_add': is_add,
2757 'is_ipv6': is_ipv6,
2758 'local': src_addr,
2759 'remote': dst_addr,
2760 'mcast_sw_if_index': mcast_sw_if_index,
2761 'encap_vrf_id': encap_vrf_id,
2762 'decap_vrf_id': decap_vrf_id,
2763 'protocol': protocol,
2764 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002765
Neale Ranns79a05f52018-09-11 07:39:43 -07002766 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002767 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07002768 src,
2769 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002770 mcast_sw_if_index=0xFFFFFFFF,
2771 is_add=1,
2772 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07002773 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002774 decap_next_index=0xFFFFFFFF,
2775 vni=0,
2776 instance=0xFFFFFFFF):
2777 """
2778
2779 :param dst_addr:
2780 :param src_addr:
2781 :param is_add: (Default value = 1)
2782 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07002783 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002784 :param decap_next_index: (Default value = 0xFFFFFFFF)
2785 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2786 :param vni: (Default value = 0)
2787 :param instance: (Default value = 0xFFFFFFFF)
2788
2789 """
Neale Ranns79a05f52018-09-11 07:39:43 -07002790 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002791 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07002792 'tunnel': {
2793 'src': src,
2794 'dst': dst,
2795 'mcast_sw_if_index': mcast_sw_if_index,
2796 'encap_table_id': encap_table_id,
2797 'decap_next_index': decap_next_index,
2798 'vni': vni,
2799 'instance': instance}})
2800
2801 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
2802 return self.api(self.papi.vxlan_gbp_tunnel_dump,
2803 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02002804
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002805 def pppoe_add_del_session(
2806 self,
2807 client_ip,
2808 client_mac,
2809 session_id=0,
2810 is_add=1,
2811 is_ipv6=0,
2812 decap_vrf_id=0):
2813 """
2814
2815 :param is_add: (Default value = 1)
2816 :param is_ipv6: (Default value = 0)
2817 :param client_ip:
2818 :param session_id: (Default value = 0)
2819 :param client_mac:
2820 :param decap_vrf_id: (Default value = 0)
2821
2822 """
2823 return self.api(self.papi.pppoe_add_del_session,
2824 {'is_add': is_add,
2825 'is_ipv6': is_ipv6,
2826 'session_id': session_id,
2827 'client_ip': client_ip,
2828 'decap_vrf_id': decap_vrf_id,
2829 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002830
Neale Ranns7c922dc2018-08-30 06:12:27 -07002831 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2832 return self.api(self.papi.sr_mpls_policy_add,
2833 {'bsid': bsid,
2834 'weight': weight,
2835 'type': type,
2836 'n_segments': len(segments),
2837 'segments': segments})
2838
2839 def sr_mpls_policy_del(self, bsid):
2840 return self.api(self.papi.sr_mpls_policy_del,
2841 {'bsid': bsid})
2842
Kris Michielsen91074432017-06-22 13:00:20 +02002843 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002844 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002845 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002846 nh_addr4,
2847 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002848 is_del=0,
2849 end_psp=0,
2850 sw_if_index=0xFFFFFFFF,
2851 vlan_index=0,
2852 fib_table=0,
2853 ):
2854 """ Add/del IPv6 SR local-SID.
2855
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002856 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002857 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2858 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002859 :param nh_addr4:
2860 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002861 :param is_del: (Default value = 0)
2862 :param end_psp: (Default value = 0)
2863 :param sw_if_index: (Default value = 0xFFFFFFFF)
2864 :param vlan_index: (Default value = 0)
2865 :param fib_table: (Default value = 0)
2866 """
2867 return self.api(
2868 self.papi.sr_localsid_add_del,
2869 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002870 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002871 'end_psp': end_psp,
2872 'behavior': behavior,
2873 'sw_if_index': sw_if_index,
2874 'vlan_index': vlan_index,
2875 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002876 'nh_addr4': nh_addr4,
2877 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002878 }
2879 )
2880
2881 def sr_policy_add(
2882 self,
2883 bsid_addr,
2884 weight=1,
2885 is_encap=1,
2886 type=0,
2887 fib_table=0,
2888 n_segments=0,
2889 segments=[]):
2890 """
2891 :param bsid_addr: bindingSID of the SR Policy
2892 :param weight: weight of the sid list. optional. (default: 1)
2893 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2894 (default: Encap)
2895 :param type: type/behavior of the SR policy. (default or spray) \
2896 (default: default)
2897 :param fib_table: VRF where to install the FIB entry for the BSID \
2898 (default: 0)
2899 :param n_segments: number of segments \
2900 (default: 0)
2901 :param segments: a vector of IPv6 address composing the segment list \
2902 (default: [])
2903 """
2904 return self.api(
2905 self.papi.sr_policy_add,
2906 {'bsid_addr': bsid_addr,
2907 'weight': weight,
2908 'is_encap': is_encap,
2909 'type': type,
2910 'fib_table': fib_table,
2911 'n_segments': n_segments,
2912 'segments': segments
2913 }
2914 )
2915
2916 def sr_policy_del(
2917 self,
2918 bsid_addr,
2919 sr_policy_index=0):
2920 """
2921 :param bsid: bindingSID of the SR Policy
2922 :param sr_policy_index: index of the sr policy (default: 0)
2923 """
2924 return self.api(
2925 self.papi.sr_policy_del,
2926 {'bsid_addr': bsid_addr,
2927 'sr_policy_index': sr_policy_index
2928 })
2929
2930 def sr_steering_add_del(
2931 self,
2932 is_del,
2933 bsid_addr,
2934 sr_policy_index,
2935 table_id,
2936 prefix_addr,
2937 mask_width,
2938 sw_if_index,
2939 traffic_type):
2940 """
2941 Steer traffic L2 and L3 traffic through a given SR policy
2942
2943 :param is_del: delete or add
2944 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2945 :param sr_policy: is the index of the SR Policy (alt to bsid)
2946 :param table_id: is the VRF where to install the FIB entry for the BSID
2947 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2948 :param mask_width: is the mask for L3 traffic type
2949 :param sw_if_index: is the incoming interface for L2 traffic
2950 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2951 """
2952 return self.api(
2953 self.papi.sr_steering_add_del,
2954 {'is_del': is_del,
2955 'bsid_addr': bsid_addr,
2956 'sr_policy_index': sr_policy_index,
2957 'table_id': table_id,
2958 'prefix_addr': prefix_addr,
2959 'mask_width': mask_width,
2960 'sw_if_index': sw_if_index,
2961 'traffic_type': traffic_type
2962 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002963
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002964 def acl_add_replace(self, acl_index, r, tag='',
2965 expected_retval=0):
2966 """Add/replace an ACL
2967 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2968 :param acl_rule r: ACL rules array.
2969 :param str tag: symbolic tag (description) for this ACL.
2970 :param int count: number of rules.
2971 """
2972 return self.api(self.papi.acl_add_replace,
2973 {'acl_index': acl_index,
2974 'r': r,
2975 'count': len(r),
2976 'tag': tag},
2977 expected_retval=expected_retval)
2978
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002979 def acl_del(self, acl_index, expected_retval=0):
2980 """
2981
2982 :param acl_index:
2983 :return:
2984 """
2985 return self.api(self.papi.acl_del,
2986 {'acl_index': acl_index},
2987 expected_retval=expected_retval)
2988
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002989 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2990 expected_retval=0):
2991 return self.api(self.papi.acl_interface_set_acl_list,
2992 {'sw_if_index': sw_if_index,
2993 'count': len(acls),
2994 'n_input': n_input,
2995 'acls': acls},
2996 expected_retval=expected_retval)
2997
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002998 def acl_interface_set_etype_whitelist(self, sw_if_index,
2999 n_input, whitelist,
3000 expected_retval=0):
3001 return self.api(self.papi.acl_interface_set_etype_whitelist,
3002 {'sw_if_index': sw_if_index,
3003 'count': len(whitelist),
3004 'n_input': n_input,
3005 'whitelist': whitelist},
3006 expected_retval=expected_retval)
3007
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02003008 def acl_interface_add_del(self,
3009 sw_if_index,
3010 acl_index,
3011 is_add=1):
3012 """ Add/Delete ACL to/from interface
3013
3014 :param sw_if_index:
3015 :param acl_index:
3016 :param is_add: (Default value = 1)
3017 """
3018
3019 return self.api(self.papi.acl_interface_add_del,
3020 {'is_add': is_add,
3021 'is_input': 1,
3022 'sw_if_index': sw_if_index,
3023 'acl_index': acl_index})
3024
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02003025 def acl_dump(self, acl_index, expected_retval=0):
3026 return self.api(self.papi.acl_dump,
3027 {'acl_index': acl_index},
3028 expected_retval=expected_retval)
3029
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01003030 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
3031 expected_retval=0):
3032 return self.api(self.papi.acl_interface_list_dump,
3033 {'sw_if_index': sw_if_index},
3034 expected_retval=expected_retval)
3035
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003036 def macip_acl_add(self, rules, tag=""):
3037 """ Add MACIP acl
3038
3039 :param rules: list of rules for given acl
3040 :param tag: acl tag
3041 """
3042
3043 return self.api(self.papi.macip_acl_add,
3044 {'r': rules,
3045 'count': len(rules),
3046 'tag': tag})
3047
Pavel Kotucek932f7412017-09-07 14:44:52 +02003048 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
3049 """ Add MACIP acl
3050
3051 :param rules: list of rules for given acl
3052 :param tag: acl tag
3053 """
3054
Pavel Kotucekc29940c2017-09-07 08:17:31 +02003055 return self.api(self.papi.macip_acl_add_replace,
3056 {'acl_index': acl_index,
3057 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02003058 'count': len(rules),
3059 'tag': tag})
3060
3061 def macip_acl_del(self, acl_index):
3062 """
3063
3064 :param acl_index:
3065 :return:
3066 """
3067 return self.api(self.papi.macip_acl_del,
3068 {'acl_index': acl_index})
3069
3070 def macip_acl_interface_add_del(self,
3071 sw_if_index,
3072 acl_index,
3073 is_add=1):
3074 """ Add MACIP acl to interface
3075
3076 :param sw_if_index:
3077 :param acl_index:
3078 :param is_add: (Default value = 1)
3079 """
3080
3081 return self.api(self.papi.macip_acl_interface_add_del,
3082 {'is_add': is_add,
3083 'sw_if_index': sw_if_index,
3084 'acl_index': acl_index})
3085
3086 def macip_acl_interface_get(self):
3087 """ Return interface acls dump
3088 """
3089 return self.api(
3090 self.papi.macip_acl_interface_get, {})
3091
3092 def macip_acl_dump(self, acl_index=4294967295):
3093 """ Return MACIP acl dump
3094 """
3095
3096 return self.api(
3097 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003098
3099 def policer_add_del(self,
3100 name,
3101 cir,
3102 eir,
3103 cb,
3104 eb,
3105 is_add=1,
3106 rate_type=0,
3107 round_type=0,
3108 ptype=0,
3109 color_aware=0,
3110 conform_action_type=1,
3111 conform_dscp=0,
3112 exceed_action_type=0,
3113 exceed_dscp=0,
3114 violate_action_type=0,
3115 violate_dscp=0):
3116 return self.api(self.papi.policer_add_del,
3117 {'name': name,
3118 'cir': cir,
3119 'eir': eir,
3120 'cb': cb,
3121 'eb': eb,
3122 'is_add': is_add,
3123 'rate_type': rate_type,
3124 'round_type': round_type,
3125 'type': ptype,
3126 'color_aware': color_aware,
3127 'conform_action_type': conform_action_type,
3128 'conform_dscp': conform_dscp,
3129 'exceed_action_type': exceed_action_type,
3130 'exceed_dscp': exceed_dscp,
3131 'violate_action_type': violate_action_type,
3132 'violate_dscp': violate_dscp})
3133
3134 def ip_punt_police(self,
3135 policer_index,
3136 is_ip6=0,
3137 is_add=1):
3138 return self.api(self.papi.ip_punt_police,
3139 {'policer_index': policer_index,
3140 'is_add': is_add,
3141 'is_ip6': is_ip6})
3142
3143 def ip_punt_redirect(self,
3144 rx_sw_if_index,
3145 tx_sw_if_index,
3146 nh,
3147 is_ip6=0,
3148 is_add=1):
3149 return self.api(self.papi.ip_punt_redirect,
3150 {'rx_sw_if_index': rx_sw_if_index,
3151 'tx_sw_if_index': tx_sw_if_index,
3152 'nh': nh,
3153 'is_add': is_add,
3154 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003155
3156 def bier_table_add_del(self,
3157 bti,
3158 mpls_label,
3159 is_add=1):
3160 """ BIER Table add/del """
3161 return self.api(
3162 self.papi.bier_table_add_del,
3163 {'bt_tbl_id': {"bt_set": bti.set_id,
3164 "bt_sub_domain": bti.sub_domain_id,
3165 "bt_hdr_len_id": bti.hdr_len_id},
3166 'bt_label': mpls_label,
3167 'bt_is_add': is_add})
3168
3169 def bier_table_dump(self):
3170 return self.api(self.papi.bier_table_dump, {})
3171
3172 def bier_route_add_del(self,
3173 bti,
3174 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003175 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003176 is_add=1,
3177 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07003178 """ BIER Route add/del """
3179 return self.api(
3180 self.papi.bier_route_add_del,
3181 {'br_tbl_id': {"bt_set": bti.set_id,
3182 "bt_sub_domain": bti.sub_domain_id,
3183 "bt_hdr_len_id": bti.hdr_len_id},
3184 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003185 'br_n_paths': len(paths),
3186 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07003187 'br_is_add': is_add,
3188 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003189
3190 def bier_route_dump(self, bti):
3191 return self.api(
3192 self.papi.bier_route_dump,
3193 {'br_tbl_id': {"bt_set": bti.set_id,
3194 "bt_sub_domain": bti.sub_domain_id,
3195 "bt_hdr_len_id": bti.hdr_len_id}})
3196
3197 def bier_imp_add(self,
3198 bti,
3199 src,
3200 ibytes,
3201 is_add=1):
3202 """ BIER Imposition Add """
3203 return self.api(
3204 self.papi.bier_imp_add,
3205 {'bi_tbl_id': {"bt_set": bti.set_id,
3206 "bt_sub_domain": bti.sub_domain_id,
3207 "bt_hdr_len_id": bti.hdr_len_id},
3208 'bi_src': src,
3209 'bi_n_bytes': len(ibytes),
3210 'bi_bytes': ibytes})
3211
3212 def bier_imp_del(self, bi_index):
3213 """ BIER Imposition del """
3214 return self.api(
3215 self.papi.bier_imp_del,
3216 {'bi_index': bi_index})
3217
3218 def bier_imp_dump(self):
3219 return self.api(self.papi.bier_imp_dump, {})
3220
3221 def bier_disp_table_add_del(self,
3222 bdti,
3223 is_add=1):
3224 """ BIER Disposition Table add/del """
3225 return self.api(
3226 self.papi.bier_disp_table_add_del,
3227 {'bdt_tbl_id': bdti,
3228 'bdt_is_add': is_add})
3229
3230 def bier_disp_table_dump(self):
3231 return self.api(self.papi.bier_disp_table_dump, {})
3232
3233 def bier_disp_entry_add_del(self,
3234 bdti,
3235 bp,
3236 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003237 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003238 next_hop,
3239 next_hop_tbl_id=0,
3240 next_hop_rpf_id=~0,
3241 next_hop_is_ip4=1,
3242 is_add=1):
3243 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003244 lstack = []
3245 while (len(lstack) < 16):
3246 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003247 return self.api(
3248 self.papi.bier_disp_entry_add_del,
3249 {'bde_tbl_id': bdti,
3250 'bde_bp': bp,
3251 'bde_payload_proto': payload_proto,
3252 'bde_n_paths': 1,
3253 'bde_paths': [{'next_hop': next_hop,
3254 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003255 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003256 'rpf_id': next_hop_rpf_id,
3257 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003258 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003259 'bde_is_add': is_add})
3260
3261 def bier_disp_entry_dump(self, bdti):
3262 return self.api(
3263 self.papi.bier_disp_entry_dump,
3264 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003265
3266 def add_node_next(self, node_name, next_name):
3267 """ Set the next node for a given node request
3268
3269 :param node_name:
3270 :param next_name:
3271 """
3272 return self.api(self.papi.add_node_next,
3273 {'node_name': node_name,
3274 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003275
3276 def session_enable_disable(self, is_enabled):
3277 return self.api(
3278 self.papi.session_enable_disable,
3279 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003280
3281 def ipsec_spd_add_del(self, spd_id, is_add=1):
3282 """ SPD add/del - Wrapper to add or del ipsec SPD
3283 Sample CLI : 'ipsec spd add 1'
3284
3285 :param spd_id - SPD ID to be created in the vpp . mandatory
3286 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3287 optional
3288 :returns: reply from the API
3289 """
3290 return self.api(
3291 self.papi.ipsec_spd_add_del, {
3292 'spd_id': spd_id, 'is_add': is_add})
3293
3294 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3295 """ IPSEC interface SPD add/del - \
3296 Wrapper to associate/disassociate SPD to interface in VPP
3297 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3298
3299 :param spd_id - SPD ID to associate with the interface . mandatory
3300 :param sw_if_index - Interface Index which needs to ipsec \
3301 association mandatory
3302 :param is_add - add(1) or del(0) association with interface \
3303 (Default 1 - add) . optional
3304 :returns: reply from the API
3305 """
3306 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003307 self.papi.ipsec_interface_add_del_spd,
3308 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003309
3310 def ipsec_sad_add_del_entry(self,
3311 sad_id,
3312 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003313 integrity_algorithm,
3314 integrity_key,
3315 crypto_algorithm,
3316 crypto_key,
3317 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003318 tunnel_src_address='',
3319 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003320 is_tunnel=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003321 is_tunnel_ipv6=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02003322 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003323 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003324 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003325 :param sad_id: security association ID
3326 :param spi: security param index of the SA in decimal
3327 :param integrity_algorithm:
3328 :param integrity_key:
3329 :param crypto_algorithm:
3330 :param crypto_key:
3331 :param protocol: AH(0) or ESP(1) protocol
3332 :param tunnel_src_address: tunnel mode outer src address
3333 :param tunnel_dst_address: tunnel mode outer dst address
3334 :param is_add:
3335 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003336 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3337 crypto and ipsec algorithms
3338 """
3339 return self.api(
3340 self.papi.ipsec_sad_add_del_entry,
3341 {'sad_id': sad_id,
3342 'spi': spi,
3343 'tunnel_src_address': tunnel_src_address,
3344 'tunnel_dst_address': tunnel_dst_address,
3345 'protocol': protocol,
3346 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003347 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003348 'integrity_key': integrity_key,
3349 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003350 'crypto_key_length': len(crypto_key) if crypto_key is not None
3351 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003352 'crypto_key': crypto_key,
3353 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003354 'is_tunnel': is_tunnel,
Klement Sekera611864f2018-09-26 11:19:00 +02003355 'is_tunnel_ipv6': is_tunnel_ipv6,
Klement Sekera4b089f22018-04-17 18:04:57 +02003356 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003357
3358 def ipsec_spd_add_del_entry(self,
3359 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003360 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003361 local_address_start,
3362 local_address_stop,
3363 remote_address_start,
3364 remote_address_stop,
3365 local_port_start=0,
3366 local_port_stop=65535,
3367 remote_port_start=0,
3368 remote_port_stop=65535,
3369 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003370 policy=0,
3371 priority=100,
3372 is_outbound=1,
3373 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02003374 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003375 is_ip_any=0):
3376 """ IPSEC policy SPD add/del -
3377 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003378 :param spd_id: SPD ID for the policy
3379 :param local_address_start: local-ip-range start address
3380 :param local_address_stop : local-ip-range stop address
3381 :param remote_address_start: remote-ip-range start address
3382 :param remote_address_stop : remote-ip-range stop address
3383 :param local_port_start: (Default value = 0)
3384 :param local_port_stop: (Default value = 65535)
3385 :param remote_port_start: (Default value = 0)
3386 :param remote_port_stop: (Default value = 65535)
3387 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3388 :param sa_id: Security Association ID for mapping it to SPD
3389 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3390 (Default value = 0)
3391 :param priority: value for the spd action (Default value = 100)
3392 :param is_outbound: flag for inbound(0) or outbound(1)
3393 (Default value = 1)
3394 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003395 """
3396 return self.api(
3397 self.papi.ipsec_spd_add_del_entry,
3398 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003399 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003400 'local_address_start': local_address_start,
3401 'local_address_stop': local_address_stop,
3402 'remote_address_start': remote_address_start,
3403 'remote_address_stop': remote_address_stop,
3404 'local_port_start': local_port_start,
3405 'local_port_stop': local_port_stop,
3406 'remote_port_start': remote_port_start,
3407 'remote_port_stop': remote_port_stop,
3408 'is_add': is_add,
3409 'protocol': protocol,
3410 'policy': policy,
3411 'priority': priority,
3412 'is_outbound': is_outbound,
Klement Sekera611864f2018-09-26 11:19:00 +02003413 'is_ipv6': is_ipv6,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003414 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003415
Klement Sekera31da2e32018-06-24 22:49:55 +02003416 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3417 remote_spi, crypto_alg, local_crypto_key,
3418 remote_crypto_key, integ_alg, local_integ_key,
3419 remote_integ_key, is_add=1, esn=0,
3420 anti_replay=1, renumber=0, show_instance=0):
3421 return self.api(
3422 self.papi.ipsec_tunnel_if_add_del,
3423 {'local_ip': local_ip, 'remote_ip': remote_ip,
3424 'local_spi': local_spi, 'remote_spi': remote_spi,
3425 'crypto_alg': crypto_alg,
3426 'local_crypto_key_len': len(local_crypto_key),
3427 'local_crypto_key': local_crypto_key,
3428 'remote_crypto_key_len': len(remote_crypto_key),
3429 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3430 'local_integ_key_len': len(local_integ_key),
3431 'local_integ_key': local_integ_key,
3432 'remote_integ_key_len': len(remote_integ_key),
3433 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3434 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3435 'show_instance': show_instance
3436 })
3437
Florin Corasb795bd02017-12-14 11:30:48 -08003438 def app_namespace_add(self,
3439 namespace_id,
3440 ip4_fib_id=0,
3441 ip6_fib_id=0,
3442 sw_if_index=0xFFFFFFFF,
3443 secret=0):
3444 return self.api(
3445 self.papi.app_namespace_add_del,
3446 {'secret': secret,
3447 'sw_if_index': sw_if_index,
3448 'ip4_fib_id': ip4_fib_id,
3449 'ip6_fib_id': ip6_fib_id,
3450 'namespace_id': namespace_id,
3451 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003452
3453 def punt_socket_register(self, l4_port, pathname, header_version=1,
3454 is_ip4=1, l4_protocol=0x11):
3455 """ Punt to socket """
3456 return self.api(self.papi.punt_socket_register,
3457 {'is_ip4': is_ip4,
3458 'l4_protocol': l4_protocol,
3459 'l4_port': l4_port,
3460 'pathname': pathname,
3461 'header_version': header_version})
3462
3463 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3464 expire_walk_interval_ms, is_ip6=0):
3465 """ Set IP reassembly parameters """
3466 return self.api(self.papi.ip_reassembly_set,
3467 {'is_ip6': is_ip6,
3468 'timeout_ms': timeout_ms,
3469 'expire_walk_interval_ms': expire_walk_interval_ms,
3470 'max_reassemblies': max_reassemblies})
3471
3472 def ip_reassembly_get(self, is_ip6=0):
3473 """ Get IP reassembly parameters """
3474 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003475
Klement Sekera4c533132018-02-22 11:41:12 +01003476 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3477 enable_ip6=False):
3478 """ Enable/disable IP reassembly """
3479 return self.api(self.papi.ip_reassembly_enable_disable,
3480 {'sw_if_index': sw_if_index,
3481 'enable_ip4': 1 if enable_ip4 else 0,
3482 'enable_ip6': 1 if enable_ip6 else 0,
3483 })
3484
Neale Rannsc0a93142018-09-05 15:42:26 -07003485 def gbp_endpoint_add(self, sw_if_index, ips, mac, epg):
3486 """ GBP endpoint Add """
3487 return self.api(self.papi.gbp_endpoint_add,
3488 {'endpoint': {
3489 'sw_if_index': sw_if_index,
3490 'ips': ips,
3491 'n_ips': len(ips),
3492 'mac': mac,
3493 'epg_id': epg}})
3494
3495 def gbp_endpoint_del(self, handle):
3496 """ GBP endpoint Del """
3497 return self.api(self.papi.gbp_endpoint_del,
3498 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003499
3500 def gbp_endpoint_dump(self):
3501 """ GBP endpoint Dump """
3502 return self.api(self.papi.gbp_endpoint_dump, {})
3503
Neale Ranns25b04942018-04-04 09:34:50 -07003504 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3505 ip4_rd,
3506 ip6_rd,
3507 uplink_sw_if_index):
3508 """ GBP endpoint group Add/Del """
3509 return self.api(self.papi.gbp_endpoint_group_add_del,
3510 {'is_add': is_add,
3511 'epg': {
3512 'uplink_sw_if_index': uplink_sw_if_index,
3513 'bd_id': bd,
3514 'ip4_table_id': ip4_rd,
3515 'ip6_table_id': ip6_rd,
3516 'epg_id': epg}})
3517
3518 def gbp_endpoint_group_dump(self):
3519 """ GBP endpoint group Dump """
3520 return self.api(self.papi.gbp_endpoint_group_dump, {})
3521
3522 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3523 """ GBP recirc Add/Del """
3524 return self.api(self.papi.gbp_recirc_add_del,
3525 {'is_add': is_add,
3526 'recirc': {
3527 'is_ext': is_ext,
3528 'sw_if_index': sw_if_index,
3529 'epg_id': epg}})
3530
3531 def gbp_recirc_dump(self):
3532 """ GBP recirc Dump """
3533 return self.api(self.papi.gbp_recirc_dump, {})
3534
3535 def gbp_subnet_add_del(self, is_add, table_id,
3536 is_internal,
Neale Rannsc0a93142018-09-05 15:42:26 -07003537 prefix,
Neale Ranns25b04942018-04-04 09:34:50 -07003538 sw_if_index=0xffffffff,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02003539 epg_id=0xffff,
Neale Ranns25b04942018-04-04 09:34:50 -07003540 is_ip6=False):
3541 """ GBP Subnet Add/Del """
3542 return self.api(self.papi.gbp_subnet_add_del,
3543 {'is_add': is_add,
3544 'subnet': {
3545 'is_internal': is_internal,
3546 'is_ip6': is_ip6,
3547 'sw_if_index': sw_if_index,
3548 'epg_id': epg_id,
Neale Rannsc0a93142018-09-05 15:42:26 -07003549 'prefix': prefix,
Neale Ranns25b04942018-04-04 09:34:50 -07003550 'table_id': table_id}})
3551
3552 def gbp_subnet_dump(self):
3553 """ GBP Subnet Dump """
3554 return self.api(self.papi.gbp_subnet_dump, {})
3555
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003556 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3557 """ GBP contract Add/Del """
3558 return self.api(self.papi.gbp_contract_add_del,
3559 {'is_add': is_add,
3560 'contract': {
3561 'acl_index': acl_index,
3562 'src_epg': src_epg,
3563 'dst_epg': dst_epg}})
3564
3565 def gbp_contract_dump(self):
3566 """ GBP contract Dump """
3567 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003568
Neale Ranns61502112018-08-22 00:21:14 -07003569 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3570 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003571 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003572 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003573 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003574 {'ip4_table_id': ip4_table_id,
3575 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003576 'ip6_prefix': ip6_prefix,
3577 'ip6_prefix_len': ip6_prefix_len,
3578 'ip4_prefix': ip4_prefix,
3579 'ip4_prefix_len': ip4_prefix_len,
3580 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003581 'security_check': security_check})
3582
Ole Troan298c6952018-03-08 12:30:43 +01003583 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003584 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003585 return self.api(self.papi.ipip_6rd_del_tunnel,
3586 {'sw_if_index': sw_if_index})
3587
3588 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003589 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003590 """ IPIP tunnel Add/Del """
3591 return self.api(self.papi.ipip_add_tunnel,
3592 {'is_ipv6': is_ipv6,
3593 'instance': instance,
3594 'src_address': src_address,
3595 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003596 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003597 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003598
3599 def ipip_del_tunnel(self, sw_if_index):
3600 """ IPIP tunnel Delete """
3601 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003602 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003603
3604 def qos_egress_map_update(self, id, outputs):
3605 """ QOS egress map update """
3606 return self.api(self.papi.qos_egress_map_update,
3607 {'map_id': id,
3608 'rows': outputs})
3609
3610 def qos_egress_map_delete(self, id):
3611 """ QOS egress map delete """
3612 return self.api(self.papi.qos_egress_map_delete,
3613 {'map_id': id})
3614
3615 def qos_mark_enable_disable(self, sw_if_index,
3616 output_source,
3617 map_id,
3618 enable):
3619 """ QOS Mark Enable/Disable """
3620 return self.api(self.papi.qos_mark_enable_disable,
3621 {'map_id': map_id,
3622 'sw_if_index': sw_if_index,
3623 'output_source': output_source,
3624 'enable': enable})
3625
3626 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3627 """ IP QoS recording Enble/Disable """
3628 return self.api(self.papi.qos_record_enable_disable,
3629 {'sw_if_index': sw_if_index,
3630 'input_source': input_source,
3631 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003632
Neale Ranns947ea622018-06-07 23:48:20 -07003633 def igmp_enable_disable(self, sw_if_index, enable, host):
3634 """ Enable/disable IGMP on a given interface """
3635 return self.api(self.papi.igmp_enable_disable,
3636 {'enable': enable,
3637 'mode': host,
3638 'sw_if_index': sw_if_index})
3639
Jakub Grajciar97748ca2018-10-04 11:05:35 +02003640 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
3641 """ Add/del IGMP proxy device """
3642 return self.api(self.papi.igmp_proxy_device_add_del,
3643 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3644 'add': add})
3645
3646 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
3647 """ Add/del interface to/from IGMP proxy device """
3648 return self.api(self.papi.igmp_proxy_device_add_del_interface,
3649 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
3650 'add': add})
3651
Neale Ranns947ea622018-06-07 23:48:20 -07003652 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003653 """ Listen for new (S,G) on specified interface
3654
3655 :param enable: add/del
3656 :param sw_if_index: interface sw index
3657 :param saddr: source ip4 addr
3658 :param gaddr: group ip4 addr
3659 """
3660 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003661 {
3662 'group':
3663 {
3664 'filter': filter,
3665 'sw_if_index': sw_if_index,
3666 'n_srcs': len(saddrs),
3667 'saddrs': saddrs,
3668 'gaddr':
3669 {
3670 'address': gaddr
3671 }
3672 }
3673 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003674
3675 def igmp_dump(self, sw_if_index=None):
3676 """ Dump all (S,G) interface configurations """
3677 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003678 sw_if_index = 0xffffffff
3679 return self.api(self.papi.igmp_dump,
3680 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003681
3682 def igmp_clear_interface(self, sw_if_index):
3683 """ Remove all (S,G)s from specified interface
3684 doesn't send IGMP report!
3685 """
3686 return self.api(
3687 self.papi.igmp_clear_interface, {
3688 'sw_if_index': sw_if_index})
3689
3690 def want_igmp_events(self, enable=1):
3691 return self.api(self.papi.want_igmp_events, {'enable': enable,
3692 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003693
3694 def bond_create(
3695 self,
3696 mode,
3697 lb,
3698 use_custom_mac,
3699 mac_address=''):
3700 """
3701 :param mode: mode
3702 :param lb: load balance
3703 :param use_custom_mac: use custom mac
3704 :param mac_address: mac address
3705 """
3706 return self.api(
3707 self.papi.bond_create,
3708 {'mode': mode,
3709 'lb': lb,
3710 'use_custom_mac': use_custom_mac,
3711 'mac_address': mac_address
3712 })
3713
3714 def bond_delete(
3715 self,
3716 sw_if_index):
3717 """
3718 :param sw_if_index: interface the operation is applied to
3719 """
3720 return self.api(self.papi.bond_delete,
3721 {'sw_if_index': sw_if_index})
3722
3723 def bond_enslave(
3724 self,
3725 sw_if_index,
3726 bond_sw_if_index,
3727 is_passive,
3728 is_long_timeout):
3729 """
3730 :param sw_if_index: slave sw_if_index
3731 :param bond_sw_if_index: bond sw_if_index
3732 :param is_passive: is passive lacp speaker
3733 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3734 """
3735 return self.api(
3736 self.papi.bond_enslave,
3737 {'sw_if_index': sw_if_index,
3738 'bond_sw_if_index': bond_sw_if_index,
3739 'is_passive': is_passive,
3740 'is_long_timeout': is_long_timeout
3741 })
3742
3743 def bond_detach_slave(
3744 self,
3745 sw_if_index):
3746 """
3747 :param sw_if_index: slave interface the operation is applied to
3748 """
3749 return self.api(self.papi.bond_detach_slave,
3750 {'sw_if_index': sw_if_index})
3751
3752 def sw_interface_slave_dump(
3753 self,
3754 sw_if_index):
3755 """
3756 :param sw_if_index: bond sw_if_index
3757 """
3758 return self.api(self.papi.sw_interface_slave_dump,
3759 {'sw_if_index': sw_if_index})
3760
3761 def sw_interface_bond_dump(
3762 self):
3763 """
3764
3765 """
3766 return self.api(self.papi.sw_interface_bond_dump,
3767 {})
Stevene8fa6202017-08-30 14:36:45 -07003768
3769 def create_vhost_user_if(
3770 self,
3771 is_server,
3772 sock_filename,
3773 renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003774 disable_mrg_rxbuf,
3775 disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003776 custom_dev_instance,
3777 use_custom_mac,
3778 mac_address,
3779 tag=''):
3780 """
3781 :param is_server: is server
3782 :param sock_filename: socket name
3783 :param renumber: renumber
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003784 :param disable_mrg_rxbuf: disable mergable rx buffers
3785 :param disable_indirect_desc: disable indirect descriptors
Stevene8fa6202017-08-30 14:36:45 -07003786 :param custom_dev_instance: custom dev instance
3787 :param use_custom_mac: use custom mac
3788 :param mac_address: mac address
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003789 :param tag: tag (default '')
Stevene8fa6202017-08-30 14:36:45 -07003790 """
3791 return self.api(
3792 self.papi.create_vhost_user_if,
3793 {'is_server': is_server,
3794 'sock_filename': sock_filename,
3795 'renumber': renumber,
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +02003796 'disable_mrg_rxbuf': disable_mrg_rxbuf,
3797 'disable_indirect_desc': disable_indirect_desc,
Stevene8fa6202017-08-30 14:36:45 -07003798 'custom_dev_instance': custom_dev_instance,
3799 'use_custom_mac': use_custom_mac,
3800 'mac_address': mac_address,
3801 'tag': tag
3802 })
3803
3804 def delete_vhost_user_if(
3805 self,
3806 sw_if_index):
3807 """
3808 :param sw_if_index: interface the operation is applied to
3809 """
3810 return self.api(self.papi.delete_vhost_user_if,
3811 {'sw_if_index': sw_if_index, })
3812
3813 def sw_interface_vhost_user_dump(
3814 self):
3815 """
3816
3817 """
3818 return self.api(self.papi.sw_interface_vhost_user_dump,
3819 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003820
3821 def abf_policy_add_del(self, is_add, policy):
3822 return self.api(
3823 self.papi.abf_policy_add_del,
3824 {'is_add': is_add,
3825 'policy': policy})
3826
3827 def abf_itf_attach_add_del(self, is_add, attach):
3828 return self.api(
3829 self.papi.abf_itf_attach_add_del,
3830 {'is_add': is_add,
3831 'attach': attach})
3832
3833 def abf_policy_dump(self):
3834 return self.api(
3835 self.papi.abf_policy_dump, {})
3836
3837 def abf_itf_attach_dump(self):
3838 return self.api(
3839 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003840
3841 def pipe_create(self, is_specified, user_instance):
3842 return self.api(self.papi.pipe_create,
3843 {'is_specified': is_specified,
3844 'user_instance': user_instance})
3845
3846 def pipe_delete(self, parent_sw_if_index):
3847 return self.api(self.papi.pipe_delete,
3848 {'parent_sw_if_index': parent_sw_if_index})
3849
3850 def pipe_dump(self):
3851 return self.api(self.papi.pipe_dump, {})
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02003852
3853 def memif_create(
3854 self,
3855 role,
3856 mode,
3857 rx_queues=None,
3858 tx_queues=None,
3859 _id=None,
3860 socket_id=None,
3861 secret=None,
3862 ring_size=None,
3863 buffer_size=None,
3864 hw_addr=None):
3865 return self.api(self.papi.memif_create,
3866 {'role': role,
3867 'mode': mode,
3868 'rx_queues': rx_queues,
3869 'tx_queues': tx_queues,
3870 'id': _id,
3871 'socket_id': socket_id,
3872 'secret': secret,
3873 'ring_size': ring_size,
3874 'buffer_size': buffer_size,
3875 'hw_addr': hw_addr})
3876
3877 def memif_delete(self, sw_if_index):
3878 return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index})
3879
3880 def memif_dump(self):
3881 return self.api(self.papi.memif_dump, {})
3882
3883 def memif_socket_filename_add_del(
3884 self, is_add, socket_id, socket_filename):
3885 return self.api(
3886 self.papi.memif_socket_filename_add_del,
3887 {'is_add': is_add,
3888 'socket_id': socket_id,
3889 'socket_filename': socket_filename})
3890
3891 def memif_socket_filename_dump(self):
3892 return self.api(self.papi.memif_socket_filename_dump, {})
Neale Rannsd1e68ab2018-10-01 01:42:13 -07003893
3894 def svs_table_add_del(self, af, table_id, is_add=1):
3895 return self.api(self.papi.svs_table_add_del,
3896 {
3897 'table_id': table_id,
3898 'is_add': is_add,
3899 'af': af,
3900 })
3901
3902 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
3903 return self.api(self.papi.svs_route_add_del,
3904 {
3905 'table_id': table_id,
3906 'source_table_id': src_table_id,
3907 'prefix': prefix,
3908 'is_add': is_add,
3909 })
3910
3911 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
3912 return self.api(self.papi.svs_enable_disable,
3913 {
3914 'af': af,
3915 'table_id': table_id,
3916 'sw_if_index': sw_if_index,
3917 'is_enable': is_enable,
3918 })
3919
3920 def svs_dump(self):
3921 return self.api(self.papi.svs_dump, {})