blob: f9ac7694bf6d769cd834a7ab77bc1ccda052ce6f [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
Klement Sekera73884482017-02-23 09:26:30 +010046class UnexpectedApiReturnValueError(Exception):
47 """ exception raised when the API return value is unexpected """
48 pass
49
50
Klement Sekeraf62ae122016-10-11 11:47:09 +020051class VppPapiProvider(object):
52 """VPP-api provider using vpp-papi
53
54 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +020055 """
56
Klement Sekerae0545ef2017-01-25 08:00:40 +010057 _zero, _negative = range(2)
58
Klement Sekera7bb873a2016-11-18 07:38:42 +010059 def __init__(self, name, shm_prefix, test_class):
Klement Sekera277b89c2016-10-28 13:20:27 +020060 self.hook = Hook("vpp-papi-provider")
Klement Sekeraf62ae122016-10-11 11:47:09 +020061 self.name = name
62 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +010063 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +010064 self._expect_api_retval = self._zero
65 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +010066 jsonfiles = []
67
Klement Sekera0e3c0de2016-09-29 14:43:44 +020068 install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +010069 for root, dirnames, filenames in os.walk(install_dir):
70 for filename in fnmatch.filter(filenames, '*.api.json'):
71 jsonfiles.append(os.path.join(root, filename))
72
Ole Troana7564e82018-06-12 21:06:44 +020073 self.vpp = VPP(jsonfiles, logger=test_class.logger, read_timeout=5)
Klement Sekerae4504c62016-12-08 10:16:41 +010074 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +020075
Klement Sekerae0545ef2017-01-25 08:00:40 +010076 def __enter__(self):
77 return self
78
79 def expect_negative_api_retval(self):
80 """ Expect API failure """
81 self._expect_stack.append(self._expect_api_retval)
82 self._expect_api_retval = self._negative
83 return self
84
85 def expect_zero_api_retval(self):
86 """ Expect API success """
87 self._expect_stack.append(self._expect_api_retval)
88 self._expect_api_retval = self._zero
89 return self
90
91 def __exit__(self, exc_type, exc_value, traceback):
92 self._expect_api_retval = self._expect_stack.pop()
93
Klement Sekeraf62ae122016-10-11 11:47:09 +020094 def register_hook(self, hook):
95 """Replace hook registration with new hook
96
97 :param hook:
98
99 """
100 self.hook = hook
101
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200102 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100103 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200104 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100105 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200106 return e
107
108 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100109 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100110 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100111 self.test_class.logger.debug("Expecting event '%s' within %ss",
112 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300113 else:
114 self.test_class.logger.debug("Expecting event within %ss",
115 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100116 if self._events:
117 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200118 limit = time.time() + timeout
119 while time.time() < limit:
120 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100121 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200122 if name and type(e).__name__ != name:
123 raise Exception(
124 "Unexpected event received: %s, expected: %s" %
125 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100126 self.test_class.logger.debug("Returning event %s:%s" %
127 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200128 return e
129 time.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200130 raise Exception("Event did not occur within timeout")
131
132 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100133 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200134 # FIXME use the name instead of relying on type(e).__name__ ?
135 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100136 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200137 self._events.append(event)
138
Klement Sekeraf62ae122016-10-11 11:47:09 +0200139 def connect(self):
140 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100141 self.vpp.connect(self.name, self.shm_prefix)
142 self.papi = self.vpp.api
143 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144
145 def disconnect(self):
146 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100147 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200148
149 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100150 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200151 Call the appropriate hooks before and after the API call
152
153 :param api_fn: API function to call
154 :param api_args: tuple of API function arguments
155 :param expected_retval: Expected return value (Default value = 0)
156 :returns: reply from the API
157
158 """
159 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100160 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100161 if self._expect_api_retval == self._negative:
162 if hasattr(reply, 'retval') and reply.retval >= 0:
163 msg = "API call passed unexpectedly: expected negative "\
164 "return value instead of %d in %s" % \
165 (reply.retval, repr(reply))
166 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100167 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100168 elif self._expect_api_retval == self._zero:
169 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Neale Ranns88fc83e2017-04-05 08:11:14 -0700170 msg = "API call failed, expected %d return value instead "\
171 "of %d in %s" % (expected_retval, reply.retval,
172 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100173 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100174 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 else:
176 raise Exception("Internal error, unexpected value for "
177 "self._expect_api_retval %s" %
178 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200179 self.hook.after_api(api_fn.__name__, api_args)
180 return reply
181
182 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100183 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200184
185 :param cli: CLI to execute
186 :returns: CLI output
187
188 """
189 self.hook.before_cli(cli)
190 cli += '\n'
Ole Troan7e3a8752016-12-05 10:27:09 +0100191 r = self.papi.cli_inband(length=len(cli), cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200192 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200193 if hasattr(r, 'reply'):
Ole Troan7e3a8752016-12-05 10:27:09 +0100194 return r.reply.decode().rstrip('\x00')
Klement Sekeraf62ae122016-10-11 11:47:09 +0200195
Jan49c0fca2016-10-26 15:44:27 +0200196 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100197 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200198
199 :param cli: CLI to execute
200 :returns: CLI output
201 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600202 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200203
Jan4af521d2016-11-15 17:05:00 +0100204 def _convert_mac(self, mac):
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200205 return mac.replace(':', '').decode('hex')
Jan4af521d2016-11-15 17:05:00 +0100206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207 def show_version(self):
208 """ """
Klement Sekera7112c542017-03-01 09:53:19 +0100209 return self.api(self.papi.show_version, {})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210
211 def pg_create_interface(self, pg_index):
212 """
213
214 :param pg_index:
215
216 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100217 return self.api(self.papi.pg_create_interface,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200218 {"interface_id": pg_index})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200219
220 def sw_interface_dump(self, filter=None):
221 """
222
223 :param filter: (Default value = None)
224
225 """
226 if filter is not None:
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200227 args = {"name_filter_valid": 1, "name_filter": filter}
Klement Sekeraf62ae122016-10-11 11:47:09 +0200228 else:
Ole Troan7e3a8752016-12-05 10:27:09 +0100229 args = {}
230 return self.api(self.papi.sw_interface_dump, args)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200231
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000232 def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
Klement Sekerae4504c62016-12-08 10:16:41 +0100233 """ Set the IPvX Table-id for the Interface
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000234
235 :param sw_if_index:
236 :param is_ipv6:
237 :param table_id:
238
239 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100240 return self.api(self.papi.sw_interface_set_table,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200241 {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
242 'vrf_id': table_id})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000243
Klement Sekeraf62ae122016-10-11 11:47:09 +0200244 def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
245 is_ipv6=0, is_add=1, del_all=0):
246 """
247
248 :param addr: param is_ipv6: (Default value = 0)
249 :param sw_if_index:
250 :param addr_len:
251 :param is_ipv6: (Default value = 0)
252 :param is_add: (Default value = 1)
253 :param del_all: (Default value = 0)
254
255 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100256 return self.api(self.papi.sw_interface_add_del_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200257 {'sw_if_index': sw_if_index,
258 'is_add': is_add,
259 'is_ipv6': is_ipv6,
260 'del_all': del_all,
261 'address_length': addr_len,
262 'address': addr})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200263
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800264 def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
265 is_add=1):
266 """ Set the Interface to be unnumbered
267
268 :param is_add: (Default value = 1)
269 :param sw_if_index - interface That will be unnumbered
270 :param ip_sw_if_index - interface with an IP addres
271
272 """
273 return self.api(self.papi.sw_interface_set_unnumbered,
274 {'sw_if_index': ip_sw_if_index,
275 'unnumbered_sw_if_index': sw_if_index,
276 'is_add': is_add})
277
Neale Ranns404d88e2018-08-08 06:37:33 -0700278 def ip_unnumbered_dump(self, sw_if_index=0xffffffff):
279 return self.api(self.papi.ip_unnumbered_dump,
280 {'sw_if_index': sw_if_index})
281
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000282 def sw_interface_enable_disable_mpls(self, sw_if_index,
283 is_enable=1):
284 """
285 Enable/Disable MPLS on the interface
286 :param sw_if_index:
287 :param is_enable: (Default value = 1)
288
289 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100290 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200291 {'sw_if_index': sw_if_index,
292 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000293
Jan Gelety057bb8c2016-12-20 17:32:45 +0100294 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100295 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100296 {'sw_if_index': sw_if_index,
297 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200298
Neale Ranns227038a2017-04-21 01:07:59 -0700299 def set_ip_flow_hash(self,
300 table_id,
301 src=1,
302 dst=1,
303 sport=1,
304 dport=1,
305 proto=1,
306 reverse=0,
307 is_ip6=0):
308 return self.api(self.papi.set_ip_flow_hash,
309 {'vrf_id': table_id,
310 'src': src,
311 'dst': dst,
312 'dport': dport,
313 'sport': sport,
314 'proto': proto,
315 'reverse': reverse,
316 'is_ipv6': is_ip6})
317
Neale Ranns3f844d02017-02-18 00:03:54 -0800318 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
319 return self.api(self.papi.ip6nd_proxy_add_del,
320 {'address': address,
321 'sw_if_index': sw_if_index,
322 'is_del': is_del})
323
Neale Ranns75152282017-01-09 01:00:45 -0800324 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000325 no,
Neale Ranns75152282017-01-09 01:00:45 -0800326 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000327 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800328 return self.api(self.papi.sw_interface_ip6nd_ra_config,
329 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000330 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100331 'suppress': suppress,
332 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800333
Neale Ranns87df12d2017-02-18 08:16:41 -0800334 def ip6_sw_interface_ra_prefix(self,
335 sw_if_index,
336 address,
337 address_length,
338 use_default=0,
339 no_advertise=0,
340 off_link=0,
341 no_autoconfig=0,
342 no_onlink=0,
343 is_no=0,
344 val_lifetime=0xffffffff,
345 pref_lifetime=0xffffffff):
346 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
347 {'sw_if_index': sw_if_index,
348 'address': address,
349 'address_length': address_length,
350 'use_default': use_default,
351 'no_advertise': no_advertise,
352 'off_link': off_link,
353 'no_autoconfig': no_autoconfig,
354 'no_onlink': no_onlink,
355 'is_no': is_no,
356 'val_lifetime': val_lifetime,
357 'pref_lifetime': pref_lifetime})
358
Neale Ranns75152282017-01-09 01:00:45 -0800359 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
360 """
361 Enable/Disable An interface for IPv6
362 """
363 return self.api(self.papi.sw_interface_ip6_enable_disable,
364 {'sw_if_index': sw_if_index,
365 'enable': enable})
366
Klement Sekeraf62ae122016-10-11 11:47:09 +0200367 def vxlan_add_del_tunnel(
368 self,
369 src_addr,
370 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200371 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200372 is_add=1,
373 is_ipv6=0,
374 encap_vrf_id=0,
375 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600376 vni=0,
377 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200378 """
379
380 :param dst_addr:
381 :param src_addr:
382 :param is_add: (Default value = 1)
383 :param is_ipv6: (Default value = 0)
384 :param encap_vrf_id: (Default value = 0)
385 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200386 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200387 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600388 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200389
390 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100391 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200392 {'is_add': is_add,
393 'is_ipv6': is_ipv6,
394 'src_address': src_addr,
395 'dst_address': dst_addr,
396 'mcast_sw_if_index': mcast_sw_if_index,
397 'encap_vrf_id': encap_vrf_id,
398 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600399 'vni': vni,
400 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200401
Marco Varleseb598f1d2017-09-19 14:25:28 +0200402 def geneve_add_del_tunnel(
403 self,
404 local_addr,
405 remote_addr,
406 mcast_sw_if_index=0xFFFFFFFF,
407 is_add=1,
408 is_ipv6=0,
409 encap_vrf_id=0,
410 decap_next_index=0xFFFFFFFF,
411 vni=0):
412 """
413
414 :param remote_addr:
415 :param local_addr:
416 :param is_add: (Default value = 1)
417 :param is_ipv6: (Default value = 0)
418 :param encap_vrf_id: (Default value = 0)
419 :param decap_next_index: (Default value = 0xFFFFFFFF)
420 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
421 :param vni: (Default value = 0)
422
423 """
424 return self.api(self.papi.geneve_add_del_tunnel,
425 {'is_add': is_add,
426 'is_ipv6': is_ipv6,
427 'local_address': local_addr,
428 'remote_address': remote_addr,
429 'mcast_sw_if_index': mcast_sw_if_index,
430 'encap_vrf_id': encap_vrf_id,
431 'decap_next_index': decap_next_index,
432 'vni': vni})
433
Jan4af521d2016-11-15 17:05:00 +0100434 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
435 learn=1, arp_term=0, is_add=1):
436 """Create/delete bridge domain.
437
438 :param int bd_id: Bridge domain index.
439 :param int flood: Enable/disable bcast/mcast flooding in the BD.
440 (Default value = 1)
441 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
442 (Default value = 1)
443 :param int forward: Enable/disable forwarding on all interfaces in
444 the BD. (Default value = 1)
445 :param int learn: Enable/disable learning on all interfaces in the BD.
446 (Default value = 1)
447 :param int arp_term: Enable/disable arp termination in the BD.
448 (Default value = 1)
449 :param int is_add: Add or delete flag. (Default value = 1)
450 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100451 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200452 {'bd_id': bd_id,
453 'flood': flood,
454 'uu_flood': uu_flood,
455 'forward': forward,
456 'learn': learn,
457 'arp_term': arp_term,
458 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100459
Eyal Baric86e5922017-07-02 18:33:16 +0300460 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
461 return self.api(self.papi.bd_ip_mac_add_del,
462 {'bd_id': bd_id,
463 'is_add': is_add,
464 'is_ipv6': is_ipv6,
465 'ip_address': ip,
466 'mac_address': mac})
467
Eyal Bari20197482017-09-13 12:29:08 +0300468 def want_ip4_arp_events(self, enable_disable=1, address=0):
469 return self.api(self.papi.want_ip4_arp_events,
470 {'enable_disable': enable_disable,
471 'address': address,
472 'pid': os.getpid(), })
473
Eyal Baric125ecc2017-09-20 11:29:17 +0300474 def want_ip6_nd_events(self, enable_disable=1, address=0):
475 return self.api(self.papi.want_ip6_nd_events,
476 {'enable_disable': enable_disable,
477 'address': address,
478 'pid': os.getpid(), })
479
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100480 def want_ip6_ra_events(self, enable_disable=1):
481 return self.api(self.papi.want_ip6_ra_events,
482 {'enable_disable': enable_disable,
483 'pid': os.getpid(), })
484
485 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
486 mrc=0, mrd=0):
487 return self.api(self.papi.ip6nd_send_router_solicitation,
488 {'irt': irt,
489 'mrt': mrt,
490 'mrc': mrc,
491 'mrd': mrd,
492 'sw_if_index': sw_if_index})
493
Juraj Slobodac0374232018-02-01 15:18:49 +0100494 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
495 install_default_routes):
496 return self.api(self.papi.ip6_nd_address_autoconfig,
497 {'sw_if_index': sw_if_index,
498 'enable': enable,
499 'install_default_routes': install_default_routes})
500
Eyal Bari24db0ec2017-09-27 21:43:51 +0300501 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
502 max_macs_in_event=0, learn_limit=0):
503 return self.api(self.papi.want_l2_macs_events,
504 {'enable_disable': enable_disable,
505 'scan_delay': scan_delay,
506 'max_macs_in_event': max_macs_in_event,
507 'learn_limit': learn_limit,
508 'pid': os.getpid(), })
509
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200510 def want_dhcp6_reply_events(self, enable_disable=1):
511 return self.api(self.papi.want_dhcp6_reply_events,
512 {'enable_disable': enable_disable,
513 'pid': os.getpid()})
514
Juraj Sloboda81119e82018-05-25 14:02:20 +0200515 def want_dhcp6_pd_reply_events(self, enable_disable=1):
516 return self.api(self.papi.want_dhcp6_pd_reply_events,
517 {'enable_disable': enable_disable,
518 'pid': os.getpid()})
519
520 def dhcp6_clients_enable_disable(self, enable=1):
521 return self.api(self.papi.dhcp6_clients_enable_disable,
522 {'enable': enable})
523
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200524 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
525 addresses, server_index=0xFFFFFFFF,
526 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
527 ):
528 return self.api(self.papi.dhcp6_send_client_message,
529 {'sw_if_index': sw_if_index,
530 'server_index': server_index,
531 'irt': irt,
532 'mrt': mrt,
533 'mrc': mrc,
534 'mrd': mrd,
535 'stop': stop,
536 'msg_type': msg_type,
537 'T1': T1,
538 'T2': T2,
539 'n_addresses': len(addresses),
540 'addresses': addresses})
541
Juraj Sloboda81119e82018-05-25 14:02:20 +0200542 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
543 prefixes, server_index=0xFFFFFFFF,
544 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
545 ):
546 return self.api(self.papi.dhcp6_pd_send_client_message,
547 {'sw_if_index': sw_if_index,
548 'server_index': server_index,
549 'irt': irt,
550 'mrt': mrt,
551 'mrc': mrc,
552 'mrd': mrd,
553 'stop': stop,
554 'msg_type': msg_type,
555 'T1': T1,
556 'T2': T2,
557 'n_prefixes': len(prefixes),
558 'prefixes': prefixes})
559
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200560 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
561 enable=1):
562 return self.api(self.papi.dhcp6_client_enable_disable,
563 {'sw_if_index': sw_if_index,
564 'enable': enable})
565
Juraj Sloboda81119e82018-05-25 14:02:20 +0200566 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
567 enable=1):
568 return self.api(self.papi.dhcp6_pd_client_enable_disable,
569 {'sw_if_index': sw_if_index,
570 'prefix_group': prefix_group,
571 'enable': enable})
572
573 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
574 prefix_length, prefix_group,
575 is_add=1):
576 return self.api(self.papi.ip6_add_del_address_using_prefix,
577 {'sw_if_index': sw_if_index,
578 'prefix_group': prefix_group,
579 'address': address,
580 'prefix_length': prefix_length,
581 'is_add': is_add})
582
Jan4af521d2016-11-15 17:05:00 +0100583 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
584 filter_mac=0, bvi_mac=0):
585 """Create/delete L2 FIB entry.
586
587 :param str mac: MAC address to create FIB entry for.
588 :param int bd_id: Bridge domain index.
589 :param int sw_if_index: Software interface index of the interface.
590 :param int is_add: Add or delete flag. (Default value = 1)
591 :param int static_mac: Set to 1 to create static MAC entry.
592 (Default value = 0)
593 :param int filter_mac: Set to 1 to drop packet that's source or
594 destination MAC address contains defined MAC address.
595 (Default value = 0)
596 :param int bvi_mac: Set to 1 to create entry that points to BVI
597 interface. (Default value = 0)
598 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100599 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200600 {'mac': self._convert_mac(mac),
601 'bd_id': bd_id,
602 'sw_if_index': sw_if_index,
603 'is_add': is_add,
604 'static_mac': static_mac,
605 'filter_mac': filter_mac,
606 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100607
Eyal Bari93b503e2017-05-15 10:13:15 +0300608 def l2fib_flush_int(self, sw_if_index):
609 """Flush L2 FIB entries for sw_if_index.
610
611 :param int sw_if_index: Software interface index of the interface.
612 """
613 return self.api(self.papi.l2fib_flush_int,
614 {'sw_if_index': sw_if_index})
615
616 def l2fib_flush_bd(self, bd_id):
617 """Flush L2 FIB entries for bd_id.
618
619 :param int sw_if_index: Bridge Domain id.
620 """
621 return self.api(self.papi.l2fib_flush_bd,
622 {'bd_id': bd_id})
623
624 def l2fib_flush_all(self):
625 """Flush all L2 FIB.
626 """
627 return self.api(self.papi.l2fib_flush_all, {})
628
Klement Sekeraf62ae122016-10-11 11:47:09 +0200629 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
630 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100631 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200632
Jan4af521d2016-11-15 17:05:00 +0100633 :param int sw_if_index: Software interface index of the interface.
634 :param int bd_id: Bridge domain index.
635 :param int shg: Split-horizon group index. (Default value = 0)
636 :param int bvi: Set interface as a bridge group virtual interface.
637 (Default value = 0)
638 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200639 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100640 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200641 {'rx_sw_if_index': sw_if_index,
642 'bd_id': bd_id,
643 'shg': shg,
644 'bvi': bvi,
645 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200646
Jan00dad122016-11-29 10:04:53 +0100647 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400648 """Enable/disable required feature of the bridge domain with defined
649 ID.
Jan00dad122016-11-29 10:04:53 +0100650
651 :param int bd_id: Bridge domain ID.
652 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
653 :param int feature_bitmap: Bitmap value of the feature to be set:
654 - learn (1 << 0),
655 - forward (1 << 1),
656 - flood (1 << 2),
657 - uu-flood (1 << 3) or
658 - arp-term (1 << 4).
659 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100660 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200661 {'bd_id': bd_id,
662 'is_set': is_set,
663 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100664
665 def bridge_domain_dump(self, bd_id=0):
666 """
667
668 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
669 existing bridge domains returned)
670 :return: Dictionary of bridge domain(s) data.
671 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100672 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200673 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100674
Klement Sekeraf62ae122016-10-11 11:47:09 +0200675 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
676 enable):
677 """Create or delete unidirectional cross-connect from Tx interface to
678 Rx interface.
679
Jan4af521d2016-11-15 17:05:00 +0100680 :param int rx_sw_if_index: Software interface index of Rx interface.
681 :param int tx_sw_if_index: Software interface index of Tx interface.
682 :param int enable: Create cross-connect if equal to 1, delete
683 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200684
685 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100686 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200687 {'rx_sw_if_index': rx_sw_if_index,
688 'tx_sw_if_index': tx_sw_if_index,
689 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200690
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200691 def sw_interface_set_l2_tag_rewrite(
692 self,
693 sw_if_index,
694 vtr_oper,
695 push=0,
696 tag1=0,
697 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000698 """L2 interface vlan tag rewrite configure request
699 :param client_index - opaque cookie to identify the sender
700 :param context - sender context, to match reply w/ request
701 :param sw_if_index - interface the operation is applied to
702 :param vtr_op - Choose from l2_vtr_op_t enum values
703 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
704 :param tag1 - Needed for any push or translate vtr op
705 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
706
707 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100708 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200709 {'sw_if_index': sw_if_index,
710 'vtr_op': vtr_oper,
711 'push_dot1q': push,
712 'tag1': tag1,
713 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000714
Neale Ranns55d03782017-10-21 06:34:22 -0700715 def sw_interface_set_l2_emulation(
716 self,
717 sw_if_index,
718 enable=1):
719 """L2 Emulation
720 :param sw_if_index - interface the operation is applied to
721
722 """
723 return self.api(self.papi.l2_emulation,
724 {'sw_if_index': sw_if_index,
725 'enable': enable})
726
Neale Ranns1855b8e2018-07-11 10:31:26 -0700727 def sw_interface_set_ip_directed_broadcast(
728 self,
729 sw_if_index,
730 enable=1):
731 """IP Directed broadcast
732 :param sw_if_index - interface the operation is applied to
733
734 """
735 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
736 {'sw_if_index': sw_if_index,
737 'enable': enable})
738
Neale Rannsa07bd702017-08-07 07:53:49 -0700739 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200740 """
741
742 :param admin_up_down:
743 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200744
745 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100746 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200747 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700748 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200749
Ole Troand7231612018-06-07 10:17:57 +0200750 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800751 """
752 :param sw_if_index:
753 :param mtu:
754
755 """
756 return self.api(self.papi.sw_interface_set_mtu,
757 {'sw_if_index': sw_if_index,
758 'mtu': mtu})
759
Neale Ranns25b04942018-04-04 09:34:50 -0700760 def sw_interface_set_promiscuous(self, sw_if_index, enable):
761 """
762 :param sw_if_index:
763 :param enable:
764
765 """
766 return self.api(self.papi.sw_interface_set_promiscuous,
767 {'sw_if_index': sw_if_index,
768 'enable': enable})
769
Neale Rannsc819fc62018-02-16 02:44:05 -0800770 def sw_interface_set_mac_address(self, sw_if_index, mac):
771 return self.api(self.papi.sw_interface_set_mac_address,
772 {'sw_if_index': sw_if_index,
773 'mac_address': mac})
774
Klement Sekeraf62ae122016-10-11 11:47:09 +0200775 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
776 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
777 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
778 """Create subinterface
779 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
780
781 :param sub_id: param inner_vlan:
782 :param sw_if_index:
783 :param outer_vlan:
784 :param inner_vlan:
785 :param no_tags: (Default value = 0)
786 :param one_tag: (Default value = 0)
787 :param two_tags: (Default value = 0)
788 :param dot1ad: (Default value = 0)
789 :param exact_match: (Default value = 0)
790 :param default_sub: (Default value = 0)
791 :param outer_vlan_id_any: (Default value = 0)
792 :param inner_vlan_id_any: (Default value = 0)
793
794 """
795 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100796 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200797 {'sw_if_index': sw_if_index,
798 'sub_id': sub_id,
799 'no_tags': no_tags,
800 'one_tag': one_tag,
801 'two_tags': two_tags,
802 'dot1ad': dot1ad,
803 'exact_match': exact_match,
804 'default_sub': default_sub,
805 'outer_vlan_id_any': outer_vlan_id_any,
806 'inner_vlan_id_any': inner_vlan_id_any,
807 'outer_vlan_id': outer_vlan,
808 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200809
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200810 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
811 """Create p2p ethernet subinterface
812
813 :param sw_if_index: main (parent) interface
814 :param remote_mac: client (remote) mac address
815
816 """
817 return self.api(
818 self.papi.p2p_ethernet_add,
819 {'parent_if_index': sw_if_index,
820 'remote_mac': remote_mac,
821 'subif_id': subif_id})
822
Neale Ranns177bbdc2016-11-15 09:46:51 +0000823 def delete_subif(self, sw_if_index):
824 """Delete subinterface
825
826 :param sw_if_index:
827 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100828 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200829 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000830
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200831 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
832 """Delete p2p ethernet subinterface
833
834 :param sw_if_index: main (parent) interface
835 :param remote_mac: client (remote) mac address
836
837 """
838 return self.api(
839 self.papi.p2p_ethernet_del,
840 {'parent_if_index': sw_if_index,
841 'remote_mac': remote_mac})
842
Klement Sekeraf62ae122016-10-11 11:47:09 +0200843 def create_vlan_subif(self, sw_if_index, vlan):
844 """
845
846 :param vlan:
847 :param sw_if_index:
848
849 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100850 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200851 {'sw_if_index': sw_if_index,
852 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200853
Matej Klotton0178d522016-11-04 11:11:44 +0100854 def create_loopback(self, mac=''):
855 """
856
857 :param mac: (Optional)
858 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100859 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200860 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100861
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100862 def delete_loopback(self, sw_if_index):
863 return self.api(self.papi.delete_loopback,
864 {'sw_if_index': sw_if_index, })
865
Neale Ranns15002542017-09-10 04:39:11 -0700866 def ip_table_add_del(self,
867 table_id,
868 is_add=1,
869 is_ipv6=0):
870 """
871
872 :param table_id
873 :param is_add: (Default value = 1)
874 :param is_ipv6: (Default value = 0)
875
876 """
877
878 return self.api(
879 self.papi.ip_table_add_del,
880 {'table_id': table_id,
881 'is_add': is_add,
882 'is_ipv6': is_ipv6})
883
Klement Sekeraf62ae122016-10-11 11:47:09 +0200884 def ip_add_del_route(
885 self,
886 dst_address,
887 dst_address_length,
888 next_hop_address,
889 next_hop_sw_if_index=0xFFFFFFFF,
890 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200891 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000892 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200893 next_hop_n_out_labels=0,
894 next_hop_out_label_stack=[],
895 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800896 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000897 is_resolve_host=0,
898 is_resolve_attached=0,
899 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200900 is_add=1,
901 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200902 is_unreach=0,
903 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200904 is_ipv6=0,
905 is_local=0,
906 is_classify=0,
907 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800908 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800909 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200910 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200911 """
912
913 :param dst_address_length:
914 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
915 :param dst_address:
916 :param next_hop_address:
917 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
918 :param vrf_id: (Default value = 0)
919 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200920 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200921 :param is_add: (Default value = 1)
922 :param is_drop: (Default value = 0)
923 :param is_ipv6: (Default value = 0)
924 :param is_local: (Default value = 0)
925 :param is_classify: (Default value = 0)
926 :param is_multipath: (Default value = 0)
927 :param is_resolve_host: (Default value = 0)
928 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800929 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700930 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200931 :param next_hop_weight: (Default value = 1)
932
933 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000934
Klement Sekeraf62ae122016-10-11 11:47:09 +0200935 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100936 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200937 {'next_hop_sw_if_index': next_hop_sw_if_index,
938 'table_id': table_id,
939 'classify_table_index': classify_table_index,
940 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200941 'is_add': is_add,
942 'is_drop': is_drop,
943 'is_unreach': is_unreach,
944 'is_prohibit': is_prohibit,
945 'is_ipv6': is_ipv6,
946 'is_local': is_local,
947 'is_classify': is_classify,
948 'is_multipath': is_multipath,
949 'is_resolve_host': is_resolve_host,
950 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800951 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700952 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800953 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200954 'next_hop_weight': next_hop_weight,
955 'dst_address_length': dst_address_length,
956 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800957 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200958 'next_hop_address': next_hop_address,
959 'next_hop_n_out_labels': next_hop_n_out_labels,
960 'next_hop_via_label': next_hop_via_label,
961 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100962
Matej Klotton16a14cd2016-12-07 15:09:13 +0100963 def ip_fib_dump(self):
964 return self.api(self.papi.ip_fib_dump, {})
965
Jan Gelety057bb8c2016-12-20 17:32:45 +0100966 def ip6_fib_dump(self):
967 return self.api(self.papi.ip6_fib_dump, {})
968
Matej Klotton0178d522016-11-04 11:11:44 +0100969 def ip_neighbor_add_del(self,
970 sw_if_index,
971 mac_address,
972 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100973 is_add=1,
974 is_ipv6=0,
975 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800976 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100977 ):
978 """ Add neighbor MAC to IPv4 or IPv6 address.
979
980 :param sw_if_index:
981 :param mac_address:
982 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100983 :param is_add: (Default value = 1)
984 :param is_ipv6: (Default value = 0)
985 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800986 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100987 """
988
989 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100990 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800991 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 'is_add': is_add,
993 'is_ipv6': is_ipv6,
994 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800995 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200996 'mac_address': mac_address,
997 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100998 }
Matej Klotton0178d522016-11-04 11:11:44 +0100999 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001000
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001001 def ip_neighbor_dump(self,
1002 sw_if_index,
1003 is_ipv6=0):
1004 """ Return IP neighbor dump.
1005
1006 :param sw_if_index:
1007 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1008 """
1009
1010 return self.api(
1011 self.papi.ip_neighbor_dump,
1012 {'is_ipv6': is_ipv6,
1013 'sw_if_index': sw_if_index
1014 }
1015 )
1016
1017 def proxy_arp_add_del(self,
1018 low_address,
1019 hi_address,
1020 vrf_id=0,
1021 is_add=1):
1022 """ Config Proxy Arp Range.
1023
1024 :param low_address: Start address in the rnage to Proxy for
1025 :param hi_address: End address in the rnage to Proxy for
1026 :param vrf_id: The VRF/table in which to proxy
1027 """
1028
1029 return self.api(
1030 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001031 {'proxy':
1032 {
1033 'vrf_id': vrf_id,
1034 'low_address': low_address,
1035 'hi_address': hi_address,
1036 },
1037 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001038
1039 def proxy_arp_intfc_enable_disable(self,
1040 sw_if_index,
1041 is_enable=1):
1042 """ Enable/Disable an interface for proxy ARP requests
1043
1044 :param sw_if_index: Interface
1045 :param enable_disable: Enable/Disable
1046 """
1047
1048 return self.api(
1049 self.papi.proxy_arp_intfc_enable_disable,
1050 {'sw_if_index': sw_if_index,
1051 'enable_disable': is_enable
1052 }
1053 )
1054
Jane546d3b2016-12-08 13:10:03 +01001055 def reset_vrf(self,
1056 vrf_id,
1057 is_ipv6=0,
1058 ):
1059 """ Reset VRF (remove all routes etc.) request.
1060
1061 :param int vrf_id: ID of the FIB table / VRF to reset.
1062 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1063 """
1064
1065 return self.api(
1066 self.papi.reset_vrf,
1067 {'vrf_id': vrf_id,
1068 'is_ipv6': is_ipv6,
1069 }
1070 )
1071
1072 def reset_fib(self,
1073 vrf_id,
1074 is_ipv6=0,
1075 ):
1076 """ Reset VRF (remove all routes etc.) request.
1077
1078 :param int vrf_id: ID of the FIB table / VRF to reset.
1079 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1080 """
1081
1082 return self.api(
1083 self.papi.reset_fib,
1084 {'vrf_id': vrf_id,
1085 'is_ipv6': is_ipv6,
1086 }
1087 )
1088
1089 def ip_dump(self,
1090 is_ipv6=0,
1091 ):
1092 """ Return IP dump.
1093
1094 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1095 """
1096
1097 return self.api(
1098 self.papi.ip_dump,
1099 {'is_ipv6': is_ipv6,
1100 }
1101 )
1102
Klement Sekera7bb873a2016-11-18 07:38:42 +01001103 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001104 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001105 """
1106
1107 :param sw_if_index_from:
1108 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001109 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001110 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001111 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001112 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001113 {'sw_if_index_from': sw_if_index_from,
1114 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001115 'state': state,
1116 'is_l2': is_l2,
1117 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001118
1119 def gre_tunnel_add_del(self,
1120 src_address,
1121 dst_address,
1122 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001123 tunnel_type=0,
1124 instance=0xFFFFFFFF,
1125 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001126 is_add=1,
1127 is_ip6=0):
1128 """ Add a GRE tunnel
1129
1130 :param src_address:
1131 :param dst_address:
1132 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001133 :param tunnel_type: (Default value = 0)
1134 :param instance: (Default value = 0xFFFFFFFF)
1135 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001136 :param is_add: (Default value = 1)
1137 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001138 """
1139
1140 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001141 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001142 {'is_add': is_add,
1143 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001144 'tunnel_type': tunnel_type,
1145 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001146 'src_address': src_address,
1147 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001148 'outer_fib_id': outer_fib_id,
1149 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001150 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001151
Neale Rannsd0df49f2018-08-08 01:06:40 -07001152 def udp_encap_add(self,
1153 id,
1154 src_ip,
1155 dst_ip,
1156 src_port,
1157 dst_port,
1158 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -08001159 """ Add a GRE tunnel
1160 :param id: user provided ID
1161 :param src_ip:
1162 :param dst_ip:
1163 :param src_port:
1164 :param dst_port:
1165 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -08001166 """
1167
1168 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -07001169 self.papi.udp_encap_add,
1170 {
1171 'udp_encap': {
1172 'id': id,
1173 'src_ip': src_ip,
1174 'dst_ip': dst_ip,
1175 'src_port': src_port,
1176 'dst_port': dst_port,
1177 'table_id': table_id
1178 }
1179 })
1180
1181 def udp_encap_del(self, id):
1182 return self.api(self.papi.udp_encap_del, {'id': id})
Neale Ranns810086d2017-11-05 16:26:46 -08001183
1184 def udp_encap_dump(self):
1185 return self.api(self.papi.udp_encap_dump, {})
1186
Neale Ranns43b1f442018-03-20 01:47:35 -07001187 def want_udp_encap_stats(self, enable=1):
1188 return self.api(self.papi.want_udp_encap_stats,
1189 {'enable': enable,
1190 'pid': os.getpid()})
1191
Neale Ranns5a8123b2017-01-26 01:18:23 -08001192 def mpls_fib_dump(self):
1193 return self.api(self.papi.mpls_fib_dump, {})
1194
Neale Ranns15002542017-09-10 04:39:11 -07001195 def mpls_table_add_del(
1196 self,
1197 table_id,
1198 is_add=1):
1199 """
1200
1201 :param table_id
1202 :param is_add: (Default value = 1)
1203
1204 """
1205
1206 return self.api(
1207 self.papi.mpls_table_add_del,
1208 {'mt_table_id': table_id,
1209 'mt_is_add': is_add})
1210
Neale Rannsad422ed2016-11-02 14:20:04 +00001211 def mpls_route_add_del(
1212 self,
1213 label,
1214 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001215 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001216 next_hop_address,
1217 next_hop_sw_if_index=0xFFFFFFFF,
1218 table_id=0,
1219 next_hop_table_id=0,
1220 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001221 next_hop_n_out_labels=0,
1222 next_hop_out_label_stack=[],
1223 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001224 is_resolve_host=0,
1225 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001226 is_interface_rx=0,
1227 is_rpf_id=0,
1228 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001229 is_add=1,
1230 is_drop=0,
1231 is_multipath=0,
1232 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001233 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001234 """
1235
1236 :param dst_address_length:
1237 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1238 :param dst_address:
1239 :param next_hop_address:
1240 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1241 :param vrf_id: (Default value = 0)
1242 :param lookup_in_vrf: (Default value = 0)
1243 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001244 :param is_add: (Default value = 1)
1245 :param is_drop: (Default value = 0)
1246 :param is_ipv6: (Default value = 0)
1247 :param is_local: (Default value = 0)
1248 :param is_classify: (Default value = 0)
1249 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001250 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001251 :param is_resolve_host: (Default value = 0)
1252 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001253 :param next_hop_weight: (Default value = 1)
1254
1255 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001256 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001257 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001258 {'mr_label': label,
1259 'mr_eos': eos,
1260 'mr_table_id': table_id,
1261 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001262 'mr_is_add': is_add,
1263 'mr_is_classify': is_classify,
1264 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001265 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001266 'mr_is_resolve_host': is_resolve_host,
1267 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001268 'mr_is_interface_rx': is_interface_rx,
1269 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001270 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001271 'mr_next_hop_weight': next_hop_weight,
1272 'mr_next_hop': next_hop_address,
1273 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1274 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1275 'mr_next_hop_table_id': next_hop_table_id,
1276 'mr_next_hop_via_label': next_hop_via_label,
1277 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001278
1279 def mpls_ip_bind_unbind(
1280 self,
1281 label,
1282 dst_address,
1283 dst_address_length,
1284 table_id=0,
1285 ip_table_id=0,
1286 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001287 is_bind=1):
1288 """
1289 """
1290 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001291 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001292 {'mb_mpls_table_id': table_id,
1293 'mb_label': label,
1294 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001295 'mb_is_bind': is_bind,
1296 'mb_is_ip4': is_ip4,
1297 'mb_address_length': dst_address_length,
1298 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001299
1300 def mpls_tunnel_add_del(
1301 self,
1302 tun_sw_if_index,
1303 next_hop_proto_is_ip4,
1304 next_hop_address,
1305 next_hop_sw_if_index=0xFFFFFFFF,
1306 next_hop_table_id=0,
1307 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001308 next_hop_n_out_labels=0,
1309 next_hop_out_label_stack=[],
1310 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001311 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001312 l2_only=0,
1313 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001314 """
1315
1316 :param dst_address_length:
1317 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1318 :param dst_address:
1319 :param next_hop_address:
1320 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1321 :param vrf_id: (Default value = 0)
1322 :param lookup_in_vrf: (Default value = 0)
1323 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001324 :param is_add: (Default value = 1)
1325 :param is_drop: (Default value = 0)
1326 :param is_ipv6: (Default value = 0)
1327 :param is_local: (Default value = 0)
1328 :param is_classify: (Default value = 0)
1329 :param is_multipath: (Default value = 0)
1330 :param is_resolve_host: (Default value = 0)
1331 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001332 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001333 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001334
1335 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001336 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001337 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001338 {'mt_sw_if_index': tun_sw_if_index,
1339 'mt_is_add': is_add,
1340 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001341 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001342 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1343 'mt_next_hop_weight': next_hop_weight,
1344 'mt_next_hop': next_hop_address,
1345 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1346 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1347 'mt_next_hop_table_id': next_hop_table_id,
1348 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001349
Matus Fabian2ba92e32017-08-21 07:05:03 -07001350 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001351 self,
1352 sw_if_index,
1353 is_inside=1,
1354 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001355 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001356
1357 :param sw_if_index: Software index of the interface
1358 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1359 :param is_add: 1 if add, 0 if delete (Default value = 1)
1360 """
1361 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001362 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001363 {'is_add': is_add,
1364 'is_inside': is_inside,
1365 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001366
Matus Fabian2ba92e32017-08-21 07:05:03 -07001367 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001368 self,
1369 sw_if_index,
1370 is_inside=1,
1371 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001372 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001373
1374 :param sw_if_index: Software index of the interface
1375 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1376 :param is_add: 1 if add, 0 if delete (Default value = 1)
1377 """
1378 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001379 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001380 {'is_add': is_add,
1381 'is_inside': is_inside,
1382 'sw_if_index': sw_if_index})
1383
Matus Fabian2ba92e32017-08-21 07:05:03 -07001384 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001385 self,
1386 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001387 external_ip=0,
1388 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001389 local_port=0,
1390 external_port=0,
1391 addr_only=1,
1392 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001393 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001394 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001395 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001396 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001397 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001398 is_add=1):
1399 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001400
1401 :param local_ip: Local IP address
1402 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001403 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001404 :param local_port: Local port number (Default value = 0)
1405 :param external_port: External port number (Default value = 0)
1406 :param addr_only: 1 if address only mapping, 0 if address and port
1407 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001408 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001409 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001410 :param self_twice_nat: 1 if translate external host address and port
1411 whenever external host address equals
1412 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001413 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001414 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001415 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001416 """
1417 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001418 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001419 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001420 'addr_only': addr_only,
1421 'local_ip_address': local_ip,
1422 'external_ip_address': external_ip,
1423 'local_port': local_port,
1424 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001425 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001426 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001427 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001428 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001429 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001430 'out2in_only': out2in_only,
1431 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001432
Matus Fabianab7a8052017-11-28 04:29:41 -08001433 def nat44_add_del_identity_mapping(
1434 self,
1435 ip='0',
1436 sw_if_index=0xFFFFFFFF,
1437 port=0,
1438 addr_only=1,
1439 vrf_id=0,
1440 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001441 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001442 is_add=1):
1443 """Add/delete NAT44 identity mapping
1444
1445 :param ip: IP address (Default value = 0)
1446 :param sw_if_index: Interface instead of IP address
1447 :param port: Port number (Default value = 0)
1448 :param addr_only: 1 if address only mapping, 0 if address and port
1449 :param vrf_id: VRF ID
1450 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001451 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001452 :param is_add: 1 if add, 0 if delete (Default value = 1)
1453 """
1454 return self.api(
1455 self.papi.nat44_add_del_identity_mapping,
1456 {'is_add': is_add,
1457 'addr_only': addr_only,
1458 'ip_address': ip,
1459 'port': port,
1460 'sw_if_index': sw_if_index,
1461 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001462 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001463 'protocol': protocol})
1464
Matus Fabian2ba92e32017-08-21 07:05:03 -07001465 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001466 self,
1467 first_ip_address,
1468 last_ip_address,
1469 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001470 vrf_id=0xFFFFFFFF,
1471 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001472 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001473
1474 :param first_ip_address: First IP address
1475 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001476 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001477 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001478 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001479 """
1480 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001481 self.papi.nat44_add_del_address_range,
1482 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001483 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001484 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001485 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001486 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001487
Matus Fabian2ba92e32017-08-21 07:05:03 -07001488 def nat44_address_dump(self):
1489 """Dump NAT44 addresses
1490 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001491 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001492 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001493
Matus Fabian2ba92e32017-08-21 07:05:03 -07001494 def nat44_interface_dump(self):
1495 """Dump interfaces with NAT44 feature
1496 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001497 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001498 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001499
Matus Fabian2ba92e32017-08-21 07:05:03 -07001500 def nat44_interface_output_feature_dump(self):
1501 """Dump interfaces with NAT44 output feature
1502 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001503 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001504 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001505
Matus Fabian2ba92e32017-08-21 07:05:03 -07001506 def nat44_static_mapping_dump(self):
1507 """Dump NAT44 static mappings
1508 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001509 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001510 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001511
Matus Fabianab7a8052017-11-28 04:29:41 -08001512 def nat44_identity_mapping_dump(self):
1513 """Dump NAT44 identity mappings
1514 :return: Dictionary of NAT44 identity mappings
1515 """
1516 return self.api(self.papi.nat44_identity_mapping_dump, {})
1517
Matus Fabian2ba92e32017-08-21 07:05:03 -07001518 def nat_show_config(self):
1519 """Show NAT plugin config
1520 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001521 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001523
Matus Fabian2ba92e32017-08-21 07:05:03 -07001524 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001525 self,
1526 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001527 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001528 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001529 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001530
1531 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001532 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001533 :param is_add: 1 if add, 0 if delete (Default value = 1)
1534 """
Matus Fabianb932d262017-12-18 05:38:24 -08001535 return self.api(
1536 self.papi.nat44_add_del_interface_addr,
1537 {'is_add': is_add,
1538 'sw_if_index': sw_if_index,
1539 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001540
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 def nat44_interface_addr_dump(self):
1542 """Dump NAT44 addresses interfaces
1543 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001544 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001545 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001546
Matus Fabian2ba92e32017-08-21 07:05:03 -07001547 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001548 self,
1549 domain_id=1,
1550 src_port=4739,
1551 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001552 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001553
1554 :param domain_id: Observation domain ID (Default value = 1)
1555 :param src_port: Source port number (Default value = 4739)
1556 :param enable: 1 if enable, 0 if disable (Default value = 1)
1557 """
1558 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001559 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001560 {'domain_id': domain_id,
1561 'src_port': src_port,
1562 'enable': enable})
1563
Matus Fabian2ba92e32017-08-21 07:05:03 -07001564 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001565 self,
1566 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001567 vrf_id):
1568 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001569
1570 :param ip_address: ip adress of the user to be dumped
1571 :param cpu_index: cpu_index on which the user is
1572 :param vrf_id: VRF ID
1573 :return: Dictionary of S-NAT sessions
1574 """
1575 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001577 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001578 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001579
Matus Fabian2ba92e32017-08-21 07:05:03 -07001580 def nat44_user_dump(self):
1581 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001582
Matus Fabian2ba92e32017-08-21 07:05:03 -07001583 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001584 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001585 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001586
Matus Fabian704018c2017-09-04 02:17:18 -07001587 def nat44_add_del_lb_static_mapping(
1588 self,
1589 external_addr,
1590 external_port,
1591 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001592 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001593 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001594 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001595 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001596 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001597 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001598 is_add=1):
1599 """Add/delete NAT44 load balancing static mapping
1600
Matus Fabianb932d262017-12-18 05:38:24 -08001601 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001602 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001603 :param is_add - 1 if add, 0 if delete
1604 """
1605 return self.api(
1606 self.papi.nat44_add_del_lb_static_mapping,
1607 {'is_add': is_add,
1608 'external_addr': external_addr,
1609 'external_port': external_port,
1610 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001611 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001612 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001613 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001614 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001615 'local_num': local_num,
1616 'locals': locals})
1617
1618 def nat44_lb_static_mapping_dump(self):
1619 """Dump NAT44 load balancing static mappings
1620
1621 :return: Dictionary of NAT44 load balancing static mapping
1622 """
1623 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1624
Matus Fabian5ba86f72017-10-26 03:37:38 -07001625 def nat44_del_session(
1626 self,
1627 addr,
1628 port,
1629 protocol,
1630 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001631 is_in=1,
1632 ext_host_address=None,
1633 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001634 """Delete NAT44 session
1635
1636 :param addr: IPv4 address
1637 :param por: port number
1638 :param protocol: IP protocol number
1639 :param vrf_id: VRF ID
1640 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001641 :param ext_host_address: external host IPv4 address
1642 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001643 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001644 if ext_host_address is None:
1645 return self.api(
1646 self.papi.nat44_del_session,
1647 {'address': addr,
1648 'port': port,
1649 'protocol': protocol,
1650 'vrf_id': vrf_id,
1651 'is_in': is_in})
1652 else:
1653 return self.api(
1654 self.papi.nat44_del_session,
1655 {'address': addr,
1656 'port': port,
1657 'protocol': protocol,
1658 'vrf_id': vrf_id,
1659 'is_in': is_in,
1660 'ext_host_valid': 1,
1661 'ext_host_address': ext_host_address,
1662 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001663
Juraj Sloboda7b929792017-11-23 13:20:48 +01001664 def nat44_forwarding_enable_disable(
1665 self,
1666 enable):
1667 """Enable/disable forwarding for NAT44
1668
1669 :param enable: 1 for enable, 0 for disable
1670 """
1671 return self.api(
1672 self.papi.nat44_forwarding_enable_disable,
1673 {'enable': enable})
1674
Matus Fabianefcd1e92017-08-15 06:59:19 -07001675 def nat_set_reass(
1676 self,
1677 timeout=2,
1678 max_reass=1024,
1679 max_frag=5,
1680 drop_frag=0,
1681 is_ip6=0):
1682 """Set NAT virtual fragmentation reassembly
1683
1684 :param timeout: reassembly timeout (Default 2sec)
1685 :param max_reass: maximum concurrent reassemblies (Default 1024)
1686 :param max_frag: maximum fragmets per reassembly (Default 5)
1687 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1688 :param is_ip6: 1 if IPv6, 0 if IPv4
1689 """
1690 return self.api(
1691 self.papi.nat_set_reass,
1692 {'timeout': timeout,
1693 'max_reass': max_reass,
1694 'max_frag': max_frag,
1695 'drop_frag': drop_frag,
1696 'is_ip6': is_ip6})
1697
1698 def nat_get_reass(self):
1699 """Get NAT virtual fragmentation reassembly configuration
1700
1701 :return: NAT virtual fragmentation reassembly configuration
1702 """
1703 return self.api(self.papi.nat_get_reass, {})
1704
1705 def nat_reass_dump(self):
1706 """Dump NAT virtual fragmentation reassemblies
1707
1708 :return: Dictionary of NAT virtual fragmentation reassemblies
1709 """
1710 return self.api(self.papi.nat_reass_dump, {})
1711
Matus Fabian2ba92e32017-08-21 07:05:03 -07001712 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001713 self,
1714 in_addr,
1715 in_plen,
1716 out_addr,
1717 out_plen,
1718 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001719 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001720
1721 :param is_add - 1 if add, 0 if delete
1722 :param in_addr - inside IP address
1723 :param in_plen - inside IP address prefix length
1724 :param out_addr - outside IP address
1725 :param out_plen - outside IP address prefix length
1726 """
1727 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001728 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001729 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001730 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001731 'in_addr': in_addr,
1732 'in_plen': in_plen,
1733 'out_addr': out_addr,
1734 'out_plen': out_plen})
1735
Matus Fabian2ba92e32017-08-21 07:05:03 -07001736 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001737 self,
1738 in_addr):
1739 """Get outside address and port range from inside address
1740
1741 :param in_addr - inside IP address
1742 """
1743 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001744 self.papi.nat_det_forward,
1745 {'in_addr': in_addr,
1746 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001747
Matus Fabian2ba92e32017-08-21 07:05:03 -07001748 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001749 self,
1750 out_addr,
1751 out_port):
1752 """Get inside address from outside address and port
1753
1754 :param out_addr - outside IP address
1755 :param out_port - outside port
1756 """
1757 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001758 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001759 {'out_addr': out_addr,
1760 'out_port': out_port})
1761
Matus Fabian2ba92e32017-08-21 07:05:03 -07001762 def nat_det_map_dump(self):
1763 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001764
Matus Fabian2ba92e32017-08-21 07:05:03 -07001765 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001766 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001767 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001768
Matus Fabian2ba92e32017-08-21 07:05:03 -07001769 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001770 self,
1771 udp=300,
1772 tcp_established=7440,
1773 tcp_transitory=240,
1774 icmp=60):
1775 """Set values of timeouts for deterministic NAT (in seconds)
1776
1777 :param udp - UDP timeout (Default value = 300)
1778 :param tcp_established - TCP established timeout (Default value = 7440)
1779 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1780 :param icmp - ICMP timeout (Default value = 60)
1781 """
1782 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001783 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001784 {'udp': udp,
1785 'tcp_established': tcp_established,
1786 'tcp_transitory': tcp_transitory,
1787 'icmp': icmp})
1788
Matus Fabian2ba92e32017-08-21 07:05:03 -07001789 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001790 """Get values of timeouts for deterministic NAT
1791
1792 :return: Timeouts for deterministic NAT (in seconds)
1793 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001794 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001795
Matus Fabian2ba92e32017-08-21 07:05:03 -07001796 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001797 self,
1798 out_addr,
1799 out_port,
1800 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001801 ext_port):
1802 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001803
1804 :param out_addr - outside IP address
1805 :param out_port - outside port
1806 :param ext_addr - external host IP address
1807 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001808 """
1809 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001810 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001811 {'out_addr': out_addr,
1812 'out_port': out_port,
1813 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001814 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001815
Matus Fabian2ba92e32017-08-21 07:05:03 -07001816 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001817 self,
1818 in_addr,
1819 in_port,
1820 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001821 ext_port):
1822 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001823
1824 :param in_addr - inside IP address
1825 :param in_port - inside port
1826 :param ext_addr - external host IP address
1827 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001828 """
1829 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001830 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001831 {'in_addr': in_addr,
1832 'in_port': in_port,
1833 'ext_addr': ext_addr,
1834 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001835 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001836
Matus Fabian2ba92e32017-08-21 07:05:03 -07001837 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001838 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001839 user_addr):
1840 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001841
1842 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001843 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001844 """
1845 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001846 self.papi.nat_det_session_dump,
1847 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001848 'user_addr': user_addr})
1849
Matus Fabian06596c52017-06-06 04:53:28 -07001850 def nat64_add_del_pool_addr_range(
1851 self,
1852 start_addr,
1853 end_addr,
1854 vrf_id=0xFFFFFFFF,
1855 is_add=1):
1856 """Add/del address range to NAT64 pool
1857
1858 :param start_addr: First IP address
1859 :param end_addr: Last IP address
1860 :param vrf_id: VRF id for the address range
1861 :param is_add: 1 if add, 0 if delete (Default value = 1)
1862 """
1863 return self.api(
1864 self.papi.nat64_add_del_pool_addr_range,
1865 {'start_addr': start_addr,
1866 'end_addr': end_addr,
1867 'vrf_id': vrf_id,
1868 'is_add': is_add})
1869
1870 def nat64_pool_addr_dump(self):
1871 """Dump NAT64 pool addresses
1872 :return: Dictionary of NAT64 pool addresses
1873 """
1874 return self.api(self.papi.nat64_pool_addr_dump, {})
1875
1876 def nat64_add_del_interface(
1877 self,
1878 sw_if_index,
1879 is_inside=1,
1880 is_add=1):
1881 """Enable/disable NAT64 feature on the interface
1882 :param sw_if_index: Index of the interface
1883 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1884 :param is_add: 1 if add, 0 if delete (Default value = 1)
1885 """
1886 return self.api(
1887 self.papi.nat64_add_del_interface,
1888 {'sw_if_index': sw_if_index,
1889 'is_inside': is_inside,
1890 'is_add': is_add})
1891
1892 def nat64_interface_dump(self):
1893 """Dump interfaces with NAT64 feature
1894 :return: Dictionary of interfaces with NAT64 feature
1895 """
1896 return self.api(self.papi.nat64_interface_dump, {})
1897
1898 def nat64_add_del_static_bib(
1899 self,
1900 in_ip,
1901 out_ip,
1902 in_port,
1903 out_port,
1904 protocol,
1905 vrf_id=0,
1906 is_add=1):
1907 """Add/delete S-NAT static BIB entry
1908
1909 :param in_ip: Inside IPv6 address
1910 :param out_ip: Outside IPv4 address
1911 :param in_port: Inside port number
1912 :param out_port: Outside port number
1913 :param protocol: IP protocol
1914 :param vrf_id: VRF ID (Default value = 0)
1915 :param is_add: 1 if add, 0 if delete (Default value = 1)
1916 """
1917 return self.api(
1918 self.papi.nat64_add_del_static_bib,
1919 {'i_addr': in_ip,
1920 'o_addr': out_ip,
1921 'i_port': in_port,
1922 'o_port': out_port,
1923 'vrf_id': vrf_id,
1924 'proto': protocol,
1925 'is_add': is_add})
1926
Matus Fabianab9a59c2017-08-16 05:37:36 -07001927 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001928 """Dump NAT64 BIB
1929
Matus Fabianab9a59c2017-08-16 05:37:36 -07001930 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001931 :returns: Dictionary of NAT64 BIB entries
1932 """
1933 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1934
1935 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1936 tcp_incoming_syn=6):
1937 """Set values of timeouts for NAT64 (in seconds)
1938
Matus Fabian428dc912017-06-21 06:15:18 -07001939 :param udpi: UDP timeout (Default value = 300)
1940 :param icmp: ICMP timeout (Default value = 60)
1941 :param tcp_trans: TCP transitory timeout (Default value = 240)
1942 :param tcp_est: TCP established timeout (Default value = 7440)
1943 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001944 """
1945 return self.api(
1946 self.papi.nat64_set_timeouts,
1947 {'udp': udp,
1948 'icmp': icmp,
1949 'tcp_trans': tcp_trans,
1950 'tcp_est': tcp_est,
1951 'tcp_incoming_syn': tcp_incoming_syn})
1952
1953 def nat64_get_timeouts(self):
1954 """Get values of timeouts for NAT64
1955
1956 :return: Timeouts for NAT64 (in seconds)
1957 """
1958 return self.api(self.papi.nat64_get_timeouts, {})
1959
Matus Fabianab9a59c2017-08-16 05:37:36 -07001960 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001961 """Dump NAT64 session table
1962
Matus Fabianab9a59c2017-08-16 05:37:36 -07001963 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001964 :returns: Dictionary of NAT64 sesstion table entries
1965 """
1966 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1967
Matus Fabian428dc912017-06-21 06:15:18 -07001968 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1969 """Add/del NAT64 prefix
1970
1971 :param prefix: NAT64 prefix
1972 :param plen: NAT64 prefix length
1973 :param vrf_id: VRF id of tenant (Default 0)
1974 :param is_add: 1 if add, 0 if delete (Default value = 1)
1975 """
1976 return self.api(
1977 self.papi.nat64_add_del_prefix,
1978 {'prefix': prefix,
1979 'prefix_len': plen,
1980 'vrf_id': vrf_id,
1981 'is_add': is_add})
1982
1983 def nat64_prefix_dump(self):
1984 """Dump NAT64 prefix
1985
1986 :returns: Dictionary of NAT64 prefixes
1987 """
1988 return self.api(self.papi.nat64_prefix_dump, {})
1989
Matus Fabian0938dcf2017-11-08 01:59:38 -08001990 def nat64_add_interface_addr(
1991 self,
1992 sw_if_index,
1993 is_add=1):
1994 """Add/del NAT64 address from interface
1995
1996 :param sw_if_index: Software index of the interface
1997 :param is_add: 1 if add, 0 if delete (Default value = 1)
1998 """
1999 return self.api(self.papi.nat64_add_del_interface_addr,
2000 {'is_add': is_add, 'sw_if_index': sw_if_index})
2001
Matus Fabian8ebe6252017-11-06 05:04:53 -08002002 def dslite_set_aftr_addr(self, ip6, ip4):
2003 """Set DS-Lite AFTR addresses
2004
2005 :param ip4: IPv4 address
2006 :param ip6: IPv6 address
2007 """
2008 return self.api(
2009 self.papi.dslite_set_aftr_addr,
2010 {'ip4_addr': ip4,
2011 'ip6_addr': ip6})
2012
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002013 def dslite_set_b4_addr(self, ip6, ip4):
2014 """Set DS-Lite B4 IPv6 address
2015
2016 :param ip4: IPv4 address
2017 :param ip6: IPv6 address
2018 """
2019 return self.api(
2020 self.papi.dslite_set_b4_addr,
2021 {'ip4_addr': ip4,
2022 'ip6_addr': ip6})
2023
Matus Fabian8ebe6252017-11-06 05:04:53 -08002024 def dslite_add_del_pool_addr_range(
2025 self,
2026 start_addr,
2027 end_addr,
2028 is_add=1):
2029 """Add/del address range to DS-Lite pool
2030
2031 :param start_addr: First IP address
2032 :param end_addr: Last IP address
2033 :param is_add: 1 if add, 0 if delete (Default value = 1)
2034 """
2035 return self.api(
2036 self.papi.dslite_add_del_pool_addr_range,
2037 {'start_addr': start_addr,
2038 'end_addr': end_addr,
2039 'is_add': is_add})
2040
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002041 def nat66_add_del_interface(
2042 self,
2043 sw_if_index,
2044 is_inside=1,
2045 is_add=1):
2046 """Enable/disable NAT66 feature on the interface
2047 :param sw_if_index: Index of the interface
2048 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2049 :param is_add: 1 if add, 0 if delete (Default value = 1)
2050 """
2051 return self.api(
2052 self.papi.nat66_add_del_interface,
2053 {'sw_if_index': sw_if_index,
2054 'is_inside': is_inside,
2055 'is_add': is_add})
2056
2057 def nat66_add_del_static_mapping(
2058 self,
2059 in_ip,
2060 out_ip,
2061 vrf_id=0,
2062 is_add=1):
2063 """Add/delete NAT66 static mapping
2064
2065 :param in_ip: Inside IPv6 address
2066 :param out_ip: Outside IPv6 address
2067 :param vrf_id: VRF ID (Default value = 0)
2068 :param is_add: 1 if add, 0 if delete (Default value = 1)
2069 """
2070 return self.api(
2071 self.papi.nat66_add_del_static_mapping,
2072 {'local_ip_address': in_ip,
2073 'external_ip_address': out_ip,
2074 'vrf_id': vrf_id,
2075 'is_add': is_add})
2076
2077 def nat66_interface_dump(self):
2078 """Dump interfaces with NAT66 feature
2079 :return: Dictionary of interfaces with NAT66 feature
2080 """
2081 return self.api(self.papi.nat66_interface_dump, {})
2082
2083 def nat66_static_mapping_dump(self):
2084 """Dump NAT66 static mappings
2085 :return: Dictionary of NAT66 static mappings
2086 """
2087 return self.api(self.papi.nat66_static_mapping_dump, {})
2088
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002089 def control_ping(self):
2090 self.api(self.papi.control_ping)
2091
2092 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002093 detect_mult, local_addr, peer_addr, is_ipv6=0,
2094 bfd_key_id=None, conf_key_id=None):
2095 if bfd_key_id is None:
2096 return self.api(self.papi.bfd_udp_add,
2097 {
2098 'sw_if_index': sw_if_index,
2099 'desired_min_tx': desired_min_tx,
2100 'required_min_rx': required_min_rx,
2101 'local_addr': local_addr,
2102 'peer_addr': peer_addr,
2103 'is_ipv6': is_ipv6,
2104 'detect_mult': detect_mult,
2105 })
2106 else:
2107 return self.api(self.papi.bfd_udp_add,
2108 {
2109 'sw_if_index': sw_if_index,
2110 'desired_min_tx': desired_min_tx,
2111 'required_min_rx': required_min_rx,
2112 'local_addr': local_addr,
2113 'peer_addr': peer_addr,
2114 'is_ipv6': is_ipv6,
2115 'detect_mult': detect_mult,
2116 'is_authenticated': 1,
2117 'bfd_key_id': bfd_key_id,
2118 'conf_key_id': conf_key_id,
2119 })
2120
Klement Sekeraa57a9702017-02-02 06:58:07 +01002121 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2122 detect_mult, local_addr, peer_addr, is_ipv6=0):
2123 return self.api(self.papi.bfd_udp_mod,
2124 {
2125 'sw_if_index': sw_if_index,
2126 'desired_min_tx': desired_min_tx,
2127 'required_min_rx': required_min_rx,
2128 'local_addr': local_addr,
2129 'peer_addr': peer_addr,
2130 'is_ipv6': is_ipv6,
2131 'detect_mult': detect_mult,
2132 })
2133
Klement Sekerab17dd962017-01-09 07:43:48 +01002134 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2135 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2136 is_delayed=False):
2137 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002138 {
2139 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002140 'local_addr': local_addr,
2141 'peer_addr': peer_addr,
2142 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002143 'is_delayed': 1 if is_delayed else 0,
2144 'bfd_key_id': bfd_key_id,
2145 'conf_key_id': conf_key_id,
2146 })
2147
2148 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2149 is_ipv6=0, is_delayed=False):
2150 return self.api(self.papi.bfd_udp_auth_deactivate,
2151 {
2152 'sw_if_index': sw_if_index,
2153 'local_addr': local_addr,
2154 'peer_addr': peer_addr,
2155 'is_ipv6': is_ipv6,
2156 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002157 })
2158
2159 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2160 return self.api(self.papi.bfd_udp_del,
2161 {
2162 'sw_if_index': sw_if_index,
2163 'local_addr': local_addr,
2164 'peer_addr': peer_addr,
2165 'is_ipv6': is_ipv6,
2166 })
2167
2168 def bfd_udp_session_dump(self):
2169 return self.api(self.papi.bfd_udp_session_dump, {})
2170
Klement Sekerab17dd962017-01-09 07:43:48 +01002171 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2172 peer_addr, is_ipv6=0):
2173 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002174 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002175 'sw_if_index': sw_if_index,
2176 'local_addr': local_addr,
2177 'peer_addr': peer_addr,
2178 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002179 })
2180
2181 def want_bfd_events(self, enable_disable=1):
2182 return self.api(self.papi.want_bfd_events, {
2183 'enable_disable': enable_disable,
2184 'pid': os.getpid(),
2185 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002186
Klement Sekerab17dd962017-01-09 07:43:48 +01002187 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2188 return self.api(self.papi.bfd_auth_set_key, {
2189 'conf_key_id': conf_key_id,
2190 'auth_type': auth_type,
2191 'key': key,
2192 'key_len': len(key),
2193 })
2194
2195 def bfd_auth_del_key(self, conf_key_id):
2196 return self.api(self.papi.bfd_auth_del_key, {
2197 'conf_key_id': conf_key_id,
2198 })
2199
2200 def bfd_auth_keys_dump(self):
2201 return self.api(self.papi.bfd_auth_keys_dump, {})
2202
Klement Sekera239790f2017-02-16 10:53:53 +01002203 def bfd_udp_set_echo_source(self, sw_if_index):
2204 return self.api(self.papi.bfd_udp_set_echo_source,
2205 {'sw_if_index': sw_if_index})
2206
Klement Sekera73884482017-02-23 09:26:30 +01002207 def bfd_udp_del_echo_source(self):
2208 return self.api(self.papi.bfd_udp_del_echo_source, {})
2209
Steve Shin7957d6e2016-12-19 09:24:50 -08002210 def classify_add_del_table(
2211 self,
2212 is_add,
2213 mask,
2214 match_n_vectors=1,
2215 table_index=0xFFFFFFFF,
2216 nbuckets=2,
2217 memory_size=2097152,
2218 skip_n_vectors=0,
2219 next_table_index=0xFFFFFFFF,
2220 miss_next_index=0xFFFFFFFF,
2221 current_data_flag=0,
2222 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002223 """
2224 :param is_add:
2225 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002226 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002227 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002228 :param nbuckets: (Default value = 2)
2229 :param memory_size: (Default value = 2097152)
2230 :param skip_n_vectors: (Default value = 0)
2231 :param next_table_index: (Default value = 0xFFFFFFFF)
2232 :param miss_next_index: (Default value = 0xFFFFFFFF)
2233 :param current_data_flag: (Default value = 0)
2234 :param current_data_offset: (Default value = 0)
2235 """
2236
Juraj Sloboda75282452018-06-12 14:20:49 +02002237 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2238 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002239 return self.api(
2240 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002241 {'is_add': is_add,
2242 'table_index': table_index,
2243 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002244 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002245 'skip_n_vectors': skip_n_vectors,
2246 'match_n_vectors': match_n_vectors,
2247 'next_table_index': next_table_index,
2248 'miss_next_index': miss_next_index,
2249 'current_data_flag': current_data_flag,
2250 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002251 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002252 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002253
2254 def classify_add_del_session(
2255 self,
2256 is_add,
2257 table_index,
2258 match,
2259 opaque_index=0xFFFFFFFF,
2260 hit_next_index=0xFFFFFFFF,
2261 advance=0,
2262 action=0,
2263 metadata=0):
2264 """
2265 :param is_add:
2266 :param table_index:
2267 :param match:
2268 :param opaque_index: (Default value = 0xFFFFFFFF)
2269 :param hit_next_index: (Default value = 0xFFFFFFFF)
2270 :param advance: (Default value = 0)
2271 :param action: (Default value = 0)
2272 :param metadata: (Default value = 0)
2273 """
2274
Juraj Sloboda75282452018-06-12 14:20:49 +02002275 match_len = ((len(match) - 1) / 16 + 1) * 16
2276 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002277 return self.api(
2278 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002279 {'is_add': is_add,
2280 'table_index': table_index,
2281 'hit_next_index': hit_next_index,
2282 'opaque_index': opaque_index,
2283 'advance': advance,
2284 'action': action,
2285 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002286 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002287 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002288
2289 def input_acl_set_interface(
2290 self,
2291 is_add,
2292 sw_if_index,
2293 ip4_table_index=0xFFFFFFFF,
2294 ip6_table_index=0xFFFFFFFF,
2295 l2_table_index=0xFFFFFFFF):
2296 """
2297 :param is_add:
2298 :param sw_if_index:
2299 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2300 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2301 :param l2_table_index: (Default value = 0xFFFFFFFF)
2302 """
2303
2304 return self.api(
2305 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002306 {'sw_if_index': sw_if_index,
2307 'ip4_table_index': ip4_table_index,
2308 'ip6_table_index': ip6_table_index,
2309 'l2_table_index': l2_table_index,
2310 'is_add': is_add})
2311
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002312 def output_acl_set_interface(
2313 self,
2314 is_add,
2315 sw_if_index,
2316 ip4_table_index=0xFFFFFFFF,
2317 ip6_table_index=0xFFFFFFFF,
2318 l2_table_index=0xFFFFFFFF):
2319 """
2320 :param is_add:
2321 :param sw_if_index:
2322 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2323 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2324 :param l2_table_index: (Default value = 0xFFFFFFFF)
2325 """
2326
2327 return self.api(
2328 self.papi.output_acl_set_interface,
2329 {'sw_if_index': sw_if_index,
2330 'ip4_table_index': ip4_table_index,
2331 'ip6_table_index': ip6_table_index,
2332 'l2_table_index': l2_table_index,
2333 'is_add': is_add})
2334
Klement Sekera77fabdb2017-01-02 07:46:14 +01002335 def set_ipfix_exporter(
2336 self,
2337 collector_address,
2338 src_address,
2339 path_mtu,
2340 template_interval,
2341 vrf_id=0,
2342 collector_port=4739,
2343 udp_checksum=0):
2344 return self.api(
2345 self.papi.set_ipfix_exporter,
2346 {
2347 'collector_address': collector_address,
2348 'collector_port': collector_port,
2349 'src_address': src_address,
2350 'vrf_id': vrf_id,
2351 'path_mtu': path_mtu,
2352 'template_interval': template_interval,
2353 'udp_checksum': udp_checksum,
2354 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002355
2356 def dhcp_proxy_config(self,
2357 dhcp_server,
2358 dhcp_src_address,
2359 rx_table_id=0,
2360 server_table_id=0,
2361 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002362 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002363 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002364 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002365 {
2366 'rx_vrf_id': rx_table_id,
2367 'server_vrf_id': server_table_id,
2368 'is_ipv6': is_ipv6,
2369 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002370 'dhcp_server': dhcp_server,
2371 'dhcp_src_address': dhcp_src_address,
2372 })
2373
2374 def dhcp_proxy_set_vss(self,
2375 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002376 vss_type=255,
2377 vpn_ascii_id="",
2378 oui=0,
2379 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002380 is_add=1,
2381 is_ip6=0):
2382 return self.api(
2383 self.papi.dhcp_proxy_set_vss,
2384 {
2385 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002386 'vss_type': vss_type,
2387 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002388 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002389 'vpn_index': vpn_index,
2390 'is_add': is_add,
2391 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002392 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002393
Neale Rannsdaff1782018-05-16 04:12:18 -07002394 def dhcp_client_dump(self):
2395 return self.api(self.papi.dhcp_client_dump, {})
2396
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002397 def dhcp_client(self,
2398 sw_if_index,
2399 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002400 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002401 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002402 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002403 want_dhcp_events=0):
2404 return self.api(
2405 self.papi.dhcp_client_config,
2406 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002407 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002408 'client': {
2409 'sw_if_index': sw_if_index,
2410 'hostname': hostname,
2411 'id': client_id,
2412 'want_dhcp_event': want_dhcp_events,
2413 'set_broadcast_flag': set_broadcast_flag,
2414 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002415 })
2416
Neale Ranns32e1c012016-11-22 17:07:28 +00002417 def ip_mroute_add_del(self,
2418 src_address,
2419 grp_address,
2420 grp_address_length,
2421 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002422 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002423 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002424 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002425 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002426 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002427 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002428 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002429 is_add=1,
2430 is_ipv6=0,
2431 is_local=0):
2432 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002433 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002434 """
2435 return self.api(
2436 self.papi.ip_mroute_add_del,
2437 {'next_hop_sw_if_index': next_hop_sw_if_index,
2438 'entry_flags': e_flags,
2439 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002440 'table_id': table_id,
2441 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002442 'is_add': is_add,
2443 'is_ipv6': is_ipv6,
2444 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002445 'bier_imp': bier_imp,
2446 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002447 'grp_address_length': grp_address_length,
2448 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002449 'src_address': src_address,
2450 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002451
2452 def mfib_signal_dump(self):
2453 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002454
2455 def ip_mfib_dump(self):
2456 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002457
Neale Rannsd792d9c2017-10-21 10:53:20 -07002458 def ip6_mfib_dump(self):
2459 return self.api(self.papi.ip6_mfib_dump, {})
2460
Filip Tehlar770e89e2017-01-31 10:39:16 +01002461 def lisp_enable_disable(self, is_enabled):
2462 return self.api(
2463 self.papi.lisp_enable_disable,
2464 {
2465 'is_en': is_enabled,
2466 })
2467
2468 def lisp_locator_set(self,
2469 ls_name,
2470 is_add=1):
2471 return self.api(
2472 self.papi.lisp_add_del_locator_set,
2473 {
2474 'is_add': is_add,
2475 'locator_set_name': ls_name
2476 })
2477
2478 def lisp_locator_set_dump(self):
2479 return self.api(self.papi.lisp_locator_set_dump, {})
2480
2481 def lisp_locator(self,
2482 ls_name,
2483 sw_if_index,
2484 priority=1,
2485 weight=1,
2486 is_add=1):
2487 return self.api(
2488 self.papi.lisp_add_del_locator,
2489 {
2490 'is_add': is_add,
2491 'locator_set_name': ls_name,
2492 'sw_if_index': sw_if_index,
2493 'priority': priority,
2494 'weight': weight
2495 })
2496
2497 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2498 return self.api(
2499 self.papi.lisp_locator_dump,
2500 {
2501 'is_index_set': is_index_set,
2502 'ls_name': ls_name,
2503 'ls_index': ls_index,
2504 })
2505
2506 def lisp_local_mapping(self,
2507 ls_name,
2508 eid_type,
2509 eid,
2510 prefix_len,
2511 vni=0,
2512 key_id=0,
2513 key="",
2514 is_add=1):
2515 return self.api(
2516 self.papi.lisp_add_del_local_eid,
2517 {
2518 'locator_set_name': ls_name,
2519 'is_add': is_add,
2520 'eid_type': eid_type,
2521 'eid': eid,
2522 'prefix_len': prefix_len,
2523 'vni': vni,
2524 'key_id': key_id,
2525 'key': key
2526 })
2527
2528 def lisp_eid_table_dump(self,
2529 eid_set=0,
2530 prefix_length=0,
2531 vni=0,
2532 eid_type=0,
2533 eid=None,
2534 filter_opt=0):
2535 return self.api(
2536 self.papi.lisp_eid_table_dump,
2537 {
2538 'eid_set': eid_set,
2539 'prefix_length': prefix_length,
2540 'vni': vni,
2541 'eid_type': eid_type,
2542 'eid': eid,
2543 'filter': filter_opt,
2544 })
2545
2546 def lisp_remote_mapping(self,
2547 eid_type,
2548 eid,
2549 eid_prefix_len=0,
2550 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002551 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002552 rlocs_num=0,
2553 is_src_dst=0,
2554 is_add=1):
2555 return self.api(
2556 self.papi.lisp_add_del_remote_mapping,
2557 {
2558 'is_add': is_add,
2559 'eid_type': eid_type,
2560 'eid': eid,
2561 'eid_len': eid_prefix_len,
2562 'rloc_num': rlocs_num,
2563 'rlocs': rlocs,
2564 'vni': vni,
2565 'is_src_dst': is_src_dst,
2566 })
2567
2568 def lisp_adjacency(self,
2569 leid,
2570 reid,
2571 leid_len,
2572 reid_len,
2573 eid_type,
2574 is_add=1,
2575 vni=0):
2576 return self.api(
2577 self.papi.lisp_add_del_adjacency,
2578 {
2579 'is_add': is_add,
2580 'vni': vni,
2581 'eid_type': eid_type,
2582 'leid': leid,
2583 'reid': reid,
2584 'leid_len': leid_len,
2585 'reid_len': reid_len,
2586 })
2587
2588 def lisp_adjacencies_get(self, vni=0):
2589 return self.api(
2590 self.papi.lisp_adjacencies_get,
2591 {
2592 'vni': vni
2593 })
Neale Ranns80823802017-02-20 18:23:41 -08002594
2595 def map_add_domain(self,
2596 ip6_prefix,
2597 ip6_prefix_len,
2598 ip6_src,
2599 ip6_src_prefix_len,
2600 ip4_prefix,
2601 ip4_prefix_len,
2602 ea_bits_len=0,
2603 psid_offset=0,
2604 psid_length=0,
2605 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002606 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002607 mtu=1280):
2608 return self.api(
2609 self.papi.map_add_domain,
2610 {
2611 'ip6_prefix': ip6_prefix,
2612 'ip6_prefix_len': ip6_prefix_len,
2613 'ip4_prefix': ip4_prefix,
2614 'ip4_prefix_len': ip4_prefix_len,
2615 'ip6_src': ip6_src,
2616 'ip6_src_prefix_len': ip6_src_prefix_len,
2617 'ea_bits_len': ea_bits_len,
2618 'psid_offset': psid_offset,
2619 'psid_length': psid_length,
2620 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002621 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002622 'mtu': mtu
2623 })
Hongjun Nief486b12017-04-12 19:21:16 +08002624
2625 def gtpu_add_del_tunnel(
2626 self,
2627 src_addr,
2628 dst_addr,
2629 is_add=1,
2630 is_ipv6=0,
2631 mcast_sw_if_index=0xFFFFFFFF,
2632 encap_vrf_id=0,
2633 decap_next_index=0xFFFFFFFF,
2634 teid=0):
2635 """
2636
2637 :param is_add: (Default value = 1)
2638 :param is_ipv6: (Default value = 0)
2639 :param src_addr:
2640 :param dst_addr:
2641 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2642 :param encap_vrf_id: (Default value = 0)
2643 :param decap_next_index: (Default value = 0xFFFFFFFF)
2644 :param teid: (Default value = 0)
2645
2646 """
2647 return self.api(self.papi.gtpu_add_del_tunnel,
2648 {'is_add': is_add,
2649 'is_ipv6': is_ipv6,
2650 'src_address': src_addr,
2651 'dst_address': dst_addr,
2652 'mcast_sw_if_index': mcast_sw_if_index,
2653 'encap_vrf_id': encap_vrf_id,
2654 'decap_next_index': decap_next_index,
2655 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002656
2657 def vxlan_gpe_add_del_tunnel(
2658 self,
2659 src_addr,
2660 dst_addr,
2661 mcast_sw_if_index=0xFFFFFFFF,
2662 is_add=1,
2663 is_ipv6=0,
2664 encap_vrf_id=0,
2665 decap_vrf_id=0,
2666 protocol=3,
2667 vni=0):
2668 """
2669
2670 :param local:
2671 :param remote:
2672 :param is_add: (Default value = 1)
2673 :param is_ipv6: (Default value = 0)
2674 :param encap_vrf_id: (Default value = 0)
2675 :param decap_vrf_id: (Default value = 0)
2676 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2677 :param protocol: (Default value = 3)
2678 :param vni: (Default value = 0)
2679
2680 """
2681 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2682 {'is_add': is_add,
2683 'is_ipv6': is_ipv6,
2684 'local': src_addr,
2685 'remote': dst_addr,
2686 'mcast_sw_if_index': mcast_sw_if_index,
2687 'encap_vrf_id': encap_vrf_id,
2688 'decap_vrf_id': decap_vrf_id,
2689 'protocol': protocol,
2690 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002691
2692 def pppoe_add_del_session(
2693 self,
2694 client_ip,
2695 client_mac,
2696 session_id=0,
2697 is_add=1,
2698 is_ipv6=0,
2699 decap_vrf_id=0):
2700 """
2701
2702 :param is_add: (Default value = 1)
2703 :param is_ipv6: (Default value = 0)
2704 :param client_ip:
2705 :param session_id: (Default value = 0)
2706 :param client_mac:
2707 :param decap_vrf_id: (Default value = 0)
2708
2709 """
2710 return self.api(self.papi.pppoe_add_del_session,
2711 {'is_add': is_add,
2712 'is_ipv6': is_ipv6,
2713 'session_id': session_id,
2714 'client_ip': client_ip,
2715 'decap_vrf_id': decap_vrf_id,
2716 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002717
2718 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002719 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002720 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002721 nh_addr4,
2722 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002723 is_del=0,
2724 end_psp=0,
2725 sw_if_index=0xFFFFFFFF,
2726 vlan_index=0,
2727 fib_table=0,
2728 ):
2729 """ Add/del IPv6 SR local-SID.
2730
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002731 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002732 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2733 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002734 :param nh_addr4:
2735 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002736 :param is_del: (Default value = 0)
2737 :param end_psp: (Default value = 0)
2738 :param sw_if_index: (Default value = 0xFFFFFFFF)
2739 :param vlan_index: (Default value = 0)
2740 :param fib_table: (Default value = 0)
2741 """
2742 return self.api(
2743 self.papi.sr_localsid_add_del,
2744 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002745 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002746 'end_psp': end_psp,
2747 'behavior': behavior,
2748 'sw_if_index': sw_if_index,
2749 'vlan_index': vlan_index,
2750 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002751 'nh_addr4': nh_addr4,
2752 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002753 }
2754 )
2755
2756 def sr_policy_add(
2757 self,
2758 bsid_addr,
2759 weight=1,
2760 is_encap=1,
2761 type=0,
2762 fib_table=0,
2763 n_segments=0,
2764 segments=[]):
2765 """
2766 :param bsid_addr: bindingSID of the SR Policy
2767 :param weight: weight of the sid list. optional. (default: 1)
2768 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2769 (default: Encap)
2770 :param type: type/behavior of the SR policy. (default or spray) \
2771 (default: default)
2772 :param fib_table: VRF where to install the FIB entry for the BSID \
2773 (default: 0)
2774 :param n_segments: number of segments \
2775 (default: 0)
2776 :param segments: a vector of IPv6 address composing the segment list \
2777 (default: [])
2778 """
2779 return self.api(
2780 self.papi.sr_policy_add,
2781 {'bsid_addr': bsid_addr,
2782 'weight': weight,
2783 'is_encap': is_encap,
2784 'type': type,
2785 'fib_table': fib_table,
2786 'n_segments': n_segments,
2787 'segments': segments
2788 }
2789 )
2790
2791 def sr_policy_del(
2792 self,
2793 bsid_addr,
2794 sr_policy_index=0):
2795 """
2796 :param bsid: bindingSID of the SR Policy
2797 :param sr_policy_index: index of the sr policy (default: 0)
2798 """
2799 return self.api(
2800 self.papi.sr_policy_del,
2801 {'bsid_addr': bsid_addr,
2802 'sr_policy_index': sr_policy_index
2803 })
2804
2805 def sr_steering_add_del(
2806 self,
2807 is_del,
2808 bsid_addr,
2809 sr_policy_index,
2810 table_id,
2811 prefix_addr,
2812 mask_width,
2813 sw_if_index,
2814 traffic_type):
2815 """
2816 Steer traffic L2 and L3 traffic through a given SR policy
2817
2818 :param is_del: delete or add
2819 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2820 :param sr_policy: is the index of the SR Policy (alt to bsid)
2821 :param table_id: is the VRF where to install the FIB entry for the BSID
2822 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2823 :param mask_width: is the mask for L3 traffic type
2824 :param sw_if_index: is the incoming interface for L2 traffic
2825 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2826 """
2827 return self.api(
2828 self.papi.sr_steering_add_del,
2829 {'is_del': is_del,
2830 'bsid_addr': bsid_addr,
2831 'sr_policy_index': sr_policy_index,
2832 'table_id': table_id,
2833 'prefix_addr': prefix_addr,
2834 'mask_width': mask_width,
2835 'sw_if_index': sw_if_index,
2836 'traffic_type': traffic_type
2837 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002838
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002839 def acl_add_replace(self, acl_index, r, tag='',
2840 expected_retval=0):
2841 """Add/replace an ACL
2842 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2843 :param acl_rule r: ACL rules array.
2844 :param str tag: symbolic tag (description) for this ACL.
2845 :param int count: number of rules.
2846 """
2847 return self.api(self.papi.acl_add_replace,
2848 {'acl_index': acl_index,
2849 'r': r,
2850 'count': len(r),
2851 'tag': tag},
2852 expected_retval=expected_retval)
2853
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002854 def acl_del(self, acl_index, expected_retval=0):
2855 """
2856
2857 :param acl_index:
2858 :return:
2859 """
2860 return self.api(self.papi.acl_del,
2861 {'acl_index': acl_index},
2862 expected_retval=expected_retval)
2863
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002864 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2865 expected_retval=0):
2866 return self.api(self.papi.acl_interface_set_acl_list,
2867 {'sw_if_index': sw_if_index,
2868 'count': len(acls),
2869 'n_input': n_input,
2870 'acls': acls},
2871 expected_retval=expected_retval)
2872
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002873 def acl_interface_set_etype_whitelist(self, sw_if_index,
2874 n_input, whitelist,
2875 expected_retval=0):
2876 return self.api(self.papi.acl_interface_set_etype_whitelist,
2877 {'sw_if_index': sw_if_index,
2878 'count': len(whitelist),
2879 'n_input': n_input,
2880 'whitelist': whitelist},
2881 expected_retval=expected_retval)
2882
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002883 def acl_interface_add_del(self,
2884 sw_if_index,
2885 acl_index,
2886 is_add=1):
2887 """ Add/Delete ACL to/from interface
2888
2889 :param sw_if_index:
2890 :param acl_index:
2891 :param is_add: (Default value = 1)
2892 """
2893
2894 return self.api(self.papi.acl_interface_add_del,
2895 {'is_add': is_add,
2896 'is_input': 1,
2897 'sw_if_index': sw_if_index,
2898 'acl_index': acl_index})
2899
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002900 def acl_dump(self, acl_index, expected_retval=0):
2901 return self.api(self.papi.acl_dump,
2902 {'acl_index': acl_index},
2903 expected_retval=expected_retval)
2904
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002905 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2906 expected_retval=0):
2907 return self.api(self.papi.acl_interface_list_dump,
2908 {'sw_if_index': sw_if_index},
2909 expected_retval=expected_retval)
2910
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002911 def macip_acl_add(self, rules, tag=""):
2912 """ Add MACIP acl
2913
2914 :param rules: list of rules for given acl
2915 :param tag: acl tag
2916 """
2917
2918 return self.api(self.papi.macip_acl_add,
2919 {'r': rules,
2920 'count': len(rules),
2921 'tag': tag})
2922
Pavel Kotucek932f7412017-09-07 14:44:52 +02002923 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2924 """ Add MACIP acl
2925
2926 :param rules: list of rules for given acl
2927 :param tag: acl tag
2928 """
2929
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002930 return self.api(self.papi.macip_acl_add_replace,
2931 {'acl_index': acl_index,
2932 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002933 'count': len(rules),
2934 'tag': tag})
2935
2936 def macip_acl_del(self, acl_index):
2937 """
2938
2939 :param acl_index:
2940 :return:
2941 """
2942 return self.api(self.papi.macip_acl_del,
2943 {'acl_index': acl_index})
2944
2945 def macip_acl_interface_add_del(self,
2946 sw_if_index,
2947 acl_index,
2948 is_add=1):
2949 """ Add MACIP acl to interface
2950
2951 :param sw_if_index:
2952 :param acl_index:
2953 :param is_add: (Default value = 1)
2954 """
2955
2956 return self.api(self.papi.macip_acl_interface_add_del,
2957 {'is_add': is_add,
2958 'sw_if_index': sw_if_index,
2959 'acl_index': acl_index})
2960
2961 def macip_acl_interface_get(self):
2962 """ Return interface acls dump
2963 """
2964 return self.api(
2965 self.papi.macip_acl_interface_get, {})
2966
2967 def macip_acl_dump(self, acl_index=4294967295):
2968 """ Return MACIP acl dump
2969 """
2970
2971 return self.api(
2972 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002973
2974 def policer_add_del(self,
2975 name,
2976 cir,
2977 eir,
2978 cb,
2979 eb,
2980 is_add=1,
2981 rate_type=0,
2982 round_type=0,
2983 ptype=0,
2984 color_aware=0,
2985 conform_action_type=1,
2986 conform_dscp=0,
2987 exceed_action_type=0,
2988 exceed_dscp=0,
2989 violate_action_type=0,
2990 violate_dscp=0):
2991 return self.api(self.papi.policer_add_del,
2992 {'name': name,
2993 'cir': cir,
2994 'eir': eir,
2995 'cb': cb,
2996 'eb': eb,
2997 'is_add': is_add,
2998 'rate_type': rate_type,
2999 'round_type': round_type,
3000 'type': ptype,
3001 'color_aware': color_aware,
3002 'conform_action_type': conform_action_type,
3003 'conform_dscp': conform_dscp,
3004 'exceed_action_type': exceed_action_type,
3005 'exceed_dscp': exceed_dscp,
3006 'violate_action_type': violate_action_type,
3007 'violate_dscp': violate_dscp})
3008
3009 def ip_punt_police(self,
3010 policer_index,
3011 is_ip6=0,
3012 is_add=1):
3013 return self.api(self.papi.ip_punt_police,
3014 {'policer_index': policer_index,
3015 'is_add': is_add,
3016 'is_ip6': is_ip6})
3017
3018 def ip_punt_redirect(self,
3019 rx_sw_if_index,
3020 tx_sw_if_index,
3021 nh,
3022 is_ip6=0,
3023 is_add=1):
3024 return self.api(self.papi.ip_punt_redirect,
3025 {'rx_sw_if_index': rx_sw_if_index,
3026 'tx_sw_if_index': tx_sw_if_index,
3027 'nh': nh,
3028 'is_add': is_add,
3029 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003030
3031 def bier_table_add_del(self,
3032 bti,
3033 mpls_label,
3034 is_add=1):
3035 """ BIER Table add/del """
3036 return self.api(
3037 self.papi.bier_table_add_del,
3038 {'bt_tbl_id': {"bt_set": bti.set_id,
3039 "bt_sub_domain": bti.sub_domain_id,
3040 "bt_hdr_len_id": bti.hdr_len_id},
3041 'bt_label': mpls_label,
3042 'bt_is_add': is_add})
3043
3044 def bier_table_dump(self):
3045 return self.api(self.papi.bier_table_dump, {})
3046
3047 def bier_route_add_del(self,
3048 bti,
3049 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003050 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003051 is_add=1):
3052 """ BIER Route add/del """
3053 return self.api(
3054 self.papi.bier_route_add_del,
3055 {'br_tbl_id': {"bt_set": bti.set_id,
3056 "bt_sub_domain": bti.sub_domain_id,
3057 "bt_hdr_len_id": bti.hdr_len_id},
3058 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003059 'br_n_paths': len(paths),
3060 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003061 'br_is_add': is_add})
3062
3063 def bier_route_dump(self, bti):
3064 return self.api(
3065 self.papi.bier_route_dump,
3066 {'br_tbl_id': {"bt_set": bti.set_id,
3067 "bt_sub_domain": bti.sub_domain_id,
3068 "bt_hdr_len_id": bti.hdr_len_id}})
3069
3070 def bier_imp_add(self,
3071 bti,
3072 src,
3073 ibytes,
3074 is_add=1):
3075 """ BIER Imposition Add """
3076 return self.api(
3077 self.papi.bier_imp_add,
3078 {'bi_tbl_id': {"bt_set": bti.set_id,
3079 "bt_sub_domain": bti.sub_domain_id,
3080 "bt_hdr_len_id": bti.hdr_len_id},
3081 'bi_src': src,
3082 'bi_n_bytes': len(ibytes),
3083 'bi_bytes': ibytes})
3084
3085 def bier_imp_del(self, bi_index):
3086 """ BIER Imposition del """
3087 return self.api(
3088 self.papi.bier_imp_del,
3089 {'bi_index': bi_index})
3090
3091 def bier_imp_dump(self):
3092 return self.api(self.papi.bier_imp_dump, {})
3093
3094 def bier_disp_table_add_del(self,
3095 bdti,
3096 is_add=1):
3097 """ BIER Disposition Table add/del """
3098 return self.api(
3099 self.papi.bier_disp_table_add_del,
3100 {'bdt_tbl_id': bdti,
3101 'bdt_is_add': is_add})
3102
3103 def bier_disp_table_dump(self):
3104 return self.api(self.papi.bier_disp_table_dump, {})
3105
3106 def bier_disp_entry_add_del(self,
3107 bdti,
3108 bp,
3109 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003110 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003111 next_hop,
3112 next_hop_tbl_id=0,
3113 next_hop_rpf_id=~0,
3114 next_hop_is_ip4=1,
3115 is_add=1):
3116 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003117 lstack = []
3118 while (len(lstack) < 16):
3119 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003120 return self.api(
3121 self.papi.bier_disp_entry_add_del,
3122 {'bde_tbl_id': bdti,
3123 'bde_bp': bp,
3124 'bde_payload_proto': payload_proto,
3125 'bde_n_paths': 1,
3126 'bde_paths': [{'next_hop': next_hop,
3127 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003128 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003129 'rpf_id': next_hop_rpf_id,
3130 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003131 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003132 'bde_is_add': is_add})
3133
3134 def bier_disp_entry_dump(self, bdti):
3135 return self.api(
3136 self.papi.bier_disp_entry_dump,
3137 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003138
3139 def add_node_next(self, node_name, next_name):
3140 """ Set the next node for a given node request
3141
3142 :param node_name:
3143 :param next_name:
3144 """
3145 return self.api(self.papi.add_node_next,
3146 {'node_name': node_name,
3147 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003148
3149 def session_enable_disable(self, is_enabled):
3150 return self.api(
3151 self.papi.session_enable_disable,
3152 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003153
3154 def ipsec_spd_add_del(self, spd_id, is_add=1):
3155 """ SPD add/del - Wrapper to add or del ipsec SPD
3156 Sample CLI : 'ipsec spd add 1'
3157
3158 :param spd_id - SPD ID to be created in the vpp . mandatory
3159 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3160 optional
3161 :returns: reply from the API
3162 """
3163 return self.api(
3164 self.papi.ipsec_spd_add_del, {
3165 'spd_id': spd_id, 'is_add': is_add})
3166
3167 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3168 """ IPSEC interface SPD add/del - \
3169 Wrapper to associate/disassociate SPD to interface in VPP
3170 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3171
3172 :param spd_id - SPD ID to associate with the interface . mandatory
3173 :param sw_if_index - Interface Index which needs to ipsec \
3174 association mandatory
3175 :param is_add - add(1) or del(0) association with interface \
3176 (Default 1 - add) . optional
3177 :returns: reply from the API
3178 """
3179 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003180 self.papi.ipsec_interface_add_del_spd,
3181 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003182
3183 def ipsec_sad_add_del_entry(self,
3184 sad_id,
3185 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003186 integrity_algorithm,
3187 integrity_key,
3188 crypto_algorithm,
3189 crypto_key,
3190 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003191 tunnel_src_address='',
3192 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003193 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003194 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003195 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003196 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003197 :param sad_id: security association ID
3198 :param spi: security param index of the SA in decimal
3199 :param integrity_algorithm:
3200 :param integrity_key:
3201 :param crypto_algorithm:
3202 :param crypto_key:
3203 :param protocol: AH(0) or ESP(1) protocol
3204 :param tunnel_src_address: tunnel mode outer src address
3205 :param tunnel_dst_address: tunnel mode outer dst address
3206 :param is_add:
3207 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003208 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3209 crypto and ipsec algorithms
3210 """
3211 return self.api(
3212 self.papi.ipsec_sad_add_del_entry,
3213 {'sad_id': sad_id,
3214 'spi': spi,
3215 'tunnel_src_address': tunnel_src_address,
3216 'tunnel_dst_address': tunnel_dst_address,
3217 'protocol': protocol,
3218 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003219 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003220 'integrity_key': integrity_key,
3221 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003222 'crypto_key_length': len(crypto_key) if crypto_key is not None
3223 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003224 'crypto_key': crypto_key,
3225 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003226 'is_tunnel': is_tunnel,
3227 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003228
3229 def ipsec_spd_add_del_entry(self,
3230 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003231 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003232 local_address_start,
3233 local_address_stop,
3234 remote_address_start,
3235 remote_address_stop,
3236 local_port_start=0,
3237 local_port_stop=65535,
3238 remote_port_start=0,
3239 remote_port_stop=65535,
3240 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003241 policy=0,
3242 priority=100,
3243 is_outbound=1,
3244 is_add=1,
3245 is_ip_any=0):
3246 """ IPSEC policy SPD add/del -
3247 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003248 :param spd_id: SPD ID for the policy
3249 :param local_address_start: local-ip-range start address
3250 :param local_address_stop : local-ip-range stop address
3251 :param remote_address_start: remote-ip-range start address
3252 :param remote_address_stop : remote-ip-range stop address
3253 :param local_port_start: (Default value = 0)
3254 :param local_port_stop: (Default value = 65535)
3255 :param remote_port_start: (Default value = 0)
3256 :param remote_port_stop: (Default value = 65535)
3257 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3258 :param sa_id: Security Association ID for mapping it to SPD
3259 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3260 (Default value = 0)
3261 :param priority: value for the spd action (Default value = 100)
3262 :param is_outbound: flag for inbound(0) or outbound(1)
3263 (Default value = 1)
3264 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003265 """
3266 return self.api(
3267 self.papi.ipsec_spd_add_del_entry,
3268 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003269 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003270 'local_address_start': local_address_start,
3271 'local_address_stop': local_address_stop,
3272 'remote_address_start': remote_address_start,
3273 'remote_address_stop': remote_address_stop,
3274 'local_port_start': local_port_start,
3275 'local_port_stop': local_port_stop,
3276 'remote_port_start': remote_port_start,
3277 'remote_port_stop': remote_port_stop,
3278 'is_add': is_add,
3279 'protocol': protocol,
3280 'policy': policy,
3281 'priority': priority,
3282 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003283 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003284
Klement Sekera31da2e32018-06-24 22:49:55 +02003285 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3286 remote_spi, crypto_alg, local_crypto_key,
3287 remote_crypto_key, integ_alg, local_integ_key,
3288 remote_integ_key, is_add=1, esn=0,
3289 anti_replay=1, renumber=0, show_instance=0):
3290 return self.api(
3291 self.papi.ipsec_tunnel_if_add_del,
3292 {'local_ip': local_ip, 'remote_ip': remote_ip,
3293 'local_spi': local_spi, 'remote_spi': remote_spi,
3294 'crypto_alg': crypto_alg,
3295 'local_crypto_key_len': len(local_crypto_key),
3296 'local_crypto_key': local_crypto_key,
3297 'remote_crypto_key_len': len(remote_crypto_key),
3298 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3299 'local_integ_key_len': len(local_integ_key),
3300 'local_integ_key': local_integ_key,
3301 'remote_integ_key_len': len(remote_integ_key),
3302 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3303 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3304 'show_instance': show_instance
3305 })
3306
Florin Corasb795bd02017-12-14 11:30:48 -08003307 def app_namespace_add(self,
3308 namespace_id,
3309 ip4_fib_id=0,
3310 ip6_fib_id=0,
3311 sw_if_index=0xFFFFFFFF,
3312 secret=0):
3313 return self.api(
3314 self.papi.app_namespace_add_del,
3315 {'secret': secret,
3316 'sw_if_index': sw_if_index,
3317 'ip4_fib_id': ip4_fib_id,
3318 'ip6_fib_id': ip6_fib_id,
3319 'namespace_id': namespace_id,
3320 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003321
3322 def punt_socket_register(self, l4_port, pathname, header_version=1,
3323 is_ip4=1, l4_protocol=0x11):
3324 """ Punt to socket """
3325 return self.api(self.papi.punt_socket_register,
3326 {'is_ip4': is_ip4,
3327 'l4_protocol': l4_protocol,
3328 'l4_port': l4_port,
3329 'pathname': pathname,
3330 'header_version': header_version})
3331
3332 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3333 expire_walk_interval_ms, is_ip6=0):
3334 """ Set IP reassembly parameters """
3335 return self.api(self.papi.ip_reassembly_set,
3336 {'is_ip6': is_ip6,
3337 'timeout_ms': timeout_ms,
3338 'expire_walk_interval_ms': expire_walk_interval_ms,
3339 'max_reassemblies': max_reassemblies})
3340
3341 def ip_reassembly_get(self, is_ip6=0):
3342 """ Get IP reassembly parameters """
3343 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003344
Klement Sekera4c533132018-02-22 11:41:12 +01003345 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3346 enable_ip6=False):
3347 """ Enable/disable IP reassembly """
3348 return self.api(self.papi.ip_reassembly_enable_disable,
3349 {'sw_if_index': sw_if_index,
3350 'enable_ip4': 1 if enable_ip4 else 0,
3351 'enable_ip6': 1 if enable_ip6 else 0,
3352 })
3353
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003354 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3355 """ GBP endpoint Add/Del """
3356 return self.api(self.papi.gbp_endpoint_add_del,
3357 {'is_add': is_add,
3358 'endpoint': {
3359 'is_ip6': is_ip6,
3360 'sw_if_index': sw_if_index,
3361 'address': addr,
3362 'epg_id': epg}})
3363
3364 def gbp_endpoint_dump(self):
3365 """ GBP endpoint Dump """
3366 return self.api(self.papi.gbp_endpoint_dump, {})
3367
Neale Ranns25b04942018-04-04 09:34:50 -07003368 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3369 ip4_rd,
3370 ip6_rd,
3371 uplink_sw_if_index):
3372 """ GBP endpoint group Add/Del """
3373 return self.api(self.papi.gbp_endpoint_group_add_del,
3374 {'is_add': is_add,
3375 'epg': {
3376 'uplink_sw_if_index': uplink_sw_if_index,
3377 'bd_id': bd,
3378 'ip4_table_id': ip4_rd,
3379 'ip6_table_id': ip6_rd,
3380 'epg_id': epg}})
3381
3382 def gbp_endpoint_group_dump(self):
3383 """ GBP endpoint group Dump """
3384 return self.api(self.papi.gbp_endpoint_group_dump, {})
3385
3386 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3387 """ GBP recirc Add/Del """
3388 return self.api(self.papi.gbp_recirc_add_del,
3389 {'is_add': is_add,
3390 'recirc': {
3391 'is_ext': is_ext,
3392 'sw_if_index': sw_if_index,
3393 'epg_id': epg}})
3394
3395 def gbp_recirc_dump(self):
3396 """ GBP recirc Dump """
3397 return self.api(self.papi.gbp_recirc_dump, {})
3398
3399 def gbp_subnet_add_del(self, is_add, table_id,
3400 is_internal,
3401 addr, addr_len,
3402 sw_if_index=0xffffffff,
3403 epg_id=0xffffffff,
3404 is_ip6=False):
3405 """ GBP Subnet Add/Del """
3406 return self.api(self.papi.gbp_subnet_add_del,
3407 {'is_add': is_add,
3408 'subnet': {
3409 'is_internal': is_internal,
3410 'is_ip6': is_ip6,
3411 'sw_if_index': sw_if_index,
3412 'epg_id': epg_id,
3413 'address': addr,
3414 'address_length': addr_len,
3415 'table_id': table_id}})
3416
3417 def gbp_subnet_dump(self):
3418 """ GBP Subnet Dump """
3419 return self.api(self.papi.gbp_subnet_dump, {})
3420
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003421 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3422 """ GBP contract Add/Del """
3423 return self.api(self.papi.gbp_contract_add_del,
3424 {'is_add': is_add,
3425 'contract': {
3426 'acl_index': acl_index,
3427 'src_epg': src_epg,
3428 'dst_epg': dst_epg}})
3429
3430 def gbp_contract_dump(self):
3431 """ GBP contract Dump """
3432 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003433
Ole Troan298c6952018-03-08 12:30:43 +01003434 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3435 ip4_prefix, ip4_prefix_len, ip4_src,
3436 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003437 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003438 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003439 {'fib_index': fib_index,
3440 'ip6_prefix': ip6_prefix,
3441 'ip6_prefix_len': ip6_prefix_len,
3442 'ip4_prefix': ip4_prefix,
3443 'ip4_prefix_len': ip4_prefix_len,
3444 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003445 'security_check': security_check})
3446
Ole Troan298c6952018-03-08 12:30:43 +01003447 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003448 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003449 return self.api(self.papi.ipip_6rd_del_tunnel,
3450 {'sw_if_index': sw_if_index})
3451
3452 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Ole Troand57f6362018-05-24 13:21:43 +02003453 instance=0xFFFFFFFF, fib_index=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003454 """ IPIP tunnel Add/Del """
3455 return self.api(self.papi.ipip_add_tunnel,
3456 {'is_ipv6': is_ipv6,
3457 'instance': instance,
3458 'src_address': src_address,
3459 'dst_address': dst_address,
Ole Troand57f6362018-05-24 13:21:43 +02003460 'fib_index': fib_index,
3461 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003462
3463 def ipip_del_tunnel(self, sw_if_index):
3464 """ IPIP tunnel Delete """
3465 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003466 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003467
3468 def qos_egress_map_update(self, id, outputs):
3469 """ QOS egress map update """
3470 return self.api(self.papi.qos_egress_map_update,
3471 {'map_id': id,
3472 'rows': outputs})
3473
3474 def qos_egress_map_delete(self, id):
3475 """ QOS egress map delete """
3476 return self.api(self.papi.qos_egress_map_delete,
3477 {'map_id': id})
3478
3479 def qos_mark_enable_disable(self, sw_if_index,
3480 output_source,
3481 map_id,
3482 enable):
3483 """ QOS Mark Enable/Disable """
3484 return self.api(self.papi.qos_mark_enable_disable,
3485 {'map_id': map_id,
3486 'sw_if_index': sw_if_index,
3487 'output_source': output_source,
3488 'enable': enable})
3489
3490 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3491 """ IP QoS recording Enble/Disable """
3492 return self.api(self.papi.qos_record_enable_disable,
3493 {'sw_if_index': sw_if_index,
3494 'input_source': input_source,
3495 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003496
Neale Ranns947ea622018-06-07 23:48:20 -07003497 def igmp_enable_disable(self, sw_if_index, enable, host):
3498 """ Enable/disable IGMP on a given interface """
3499 return self.api(self.papi.igmp_enable_disable,
3500 {'enable': enable,
3501 'mode': host,
3502 'sw_if_index': sw_if_index})
3503
3504 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003505 """ Listen for new (S,G) on specified interface
3506
3507 :param enable: add/del
3508 :param sw_if_index: interface sw index
3509 :param saddr: source ip4 addr
3510 :param gaddr: group ip4 addr
3511 """
3512 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003513 {
3514 'group':
3515 {
3516 'filter': filter,
3517 'sw_if_index': sw_if_index,
3518 'n_srcs': len(saddrs),
3519 'saddrs': saddrs,
3520 'gaddr':
3521 {
3522 'address': gaddr
3523 }
3524 }
3525 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003526
3527 def igmp_dump(self, sw_if_index=None):
3528 """ Dump all (S,G) interface configurations """
3529 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003530 sw_if_index = 0xffffffff
3531 return self.api(self.papi.igmp_dump,
3532 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003533
3534 def igmp_clear_interface(self, sw_if_index):
3535 """ Remove all (S,G)s from specified interface
3536 doesn't send IGMP report!
3537 """
3538 return self.api(
3539 self.papi.igmp_clear_interface, {
3540 'sw_if_index': sw_if_index})
3541
3542 def want_igmp_events(self, enable=1):
3543 return self.api(self.papi.want_igmp_events, {'enable': enable,
3544 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003545
3546 def bond_create(
3547 self,
3548 mode,
3549 lb,
3550 use_custom_mac,
3551 mac_address=''):
3552 """
3553 :param mode: mode
3554 :param lb: load balance
3555 :param use_custom_mac: use custom mac
3556 :param mac_address: mac address
3557 """
3558 return self.api(
3559 self.papi.bond_create,
3560 {'mode': mode,
3561 'lb': lb,
3562 'use_custom_mac': use_custom_mac,
3563 'mac_address': mac_address
3564 })
3565
3566 def bond_delete(
3567 self,
3568 sw_if_index):
3569 """
3570 :param sw_if_index: interface the operation is applied to
3571 """
3572 return self.api(self.papi.bond_delete,
3573 {'sw_if_index': sw_if_index})
3574
3575 def bond_enslave(
3576 self,
3577 sw_if_index,
3578 bond_sw_if_index,
3579 is_passive,
3580 is_long_timeout):
3581 """
3582 :param sw_if_index: slave sw_if_index
3583 :param bond_sw_if_index: bond sw_if_index
3584 :param is_passive: is passive lacp speaker
3585 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3586 """
3587 return self.api(
3588 self.papi.bond_enslave,
3589 {'sw_if_index': sw_if_index,
3590 'bond_sw_if_index': bond_sw_if_index,
3591 'is_passive': is_passive,
3592 'is_long_timeout': is_long_timeout
3593 })
3594
3595 def bond_detach_slave(
3596 self,
3597 sw_if_index):
3598 """
3599 :param sw_if_index: slave interface the operation is applied to
3600 """
3601 return self.api(self.papi.bond_detach_slave,
3602 {'sw_if_index': sw_if_index})
3603
3604 def sw_interface_slave_dump(
3605 self,
3606 sw_if_index):
3607 """
3608 :param sw_if_index: bond sw_if_index
3609 """
3610 return self.api(self.papi.sw_interface_slave_dump,
3611 {'sw_if_index': sw_if_index})
3612
3613 def sw_interface_bond_dump(
3614 self):
3615 """
3616
3617 """
3618 return self.api(self.papi.sw_interface_bond_dump,
3619 {})
Stevene8fa6202017-08-30 14:36:45 -07003620
3621 def create_vhost_user_if(
3622 self,
3623 is_server,
3624 sock_filename,
3625 renumber,
3626 custom_dev_instance,
3627 use_custom_mac,
3628 mac_address,
3629 tag=''):
3630 """
3631 :param is_server: is server
3632 :param sock_filename: socket name
3633 :param renumber: renumber
3634 :param custom_dev_instance: custom dev instance
3635 :param use_custom_mac: use custom mac
3636 :param mac_address: mac address
3637 :param tag: tag (default ''
3638 """
3639 return self.api(
3640 self.papi.create_vhost_user_if,
3641 {'is_server': is_server,
3642 'sock_filename': sock_filename,
3643 'renumber': renumber,
3644 'custom_dev_instance': custom_dev_instance,
3645 'use_custom_mac': use_custom_mac,
3646 'mac_address': mac_address,
3647 'tag': tag
3648 })
3649
3650 def delete_vhost_user_if(
3651 self,
3652 sw_if_index):
3653 """
3654 :param sw_if_index: interface the operation is applied to
3655 """
3656 return self.api(self.papi.delete_vhost_user_if,
3657 {'sw_if_index': sw_if_index, })
3658
3659 def sw_interface_vhost_user_dump(
3660 self):
3661 """
3662
3663 """
3664 return self.api(self.papi.sw_interface_vhost_user_dump,
3665 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003666
3667 def abf_policy_add_del(self, is_add, policy):
3668 return self.api(
3669 self.papi.abf_policy_add_del,
3670 {'is_add': is_add,
3671 'policy': policy})
3672
3673 def abf_itf_attach_add_del(self, is_add, attach):
3674 return self.api(
3675 self.papi.abf_itf_attach_add_del,
3676 {'is_add': is_add,
3677 'attach': attach})
3678
3679 def abf_policy_dump(self):
3680 return self.api(
3681 self.papi.abf_policy_dump, {})
3682
3683 def abf_itf_attach_dump(self):
3684 return self.api(
3685 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003686
3687 def pipe_create(self, is_specified, user_instance):
3688 return self.api(self.papi.pipe_create,
3689 {'is_specified': is_specified,
3690 'user_instance': user_instance})
3691
3692 def pipe_delete(self, parent_sw_if_index):
3693 return self.api(self.papi.pipe_delete,
3694 {'parent_sw_if_index': parent_sw_if_index})
3695
3696 def pipe_dump(self):
3697 return self.api(self.papi.pipe_dump, {})