blob: e0d55c16cee7cd14bd21d475de84c9bd18b21cc1 [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,
Neale Ranns7c922dc2018-08-30 06:12:27 -07001348 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001349 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001350
Matus Fabian2ba92e32017-08-21 07:05:03 -07001351 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001352 self,
1353 sw_if_index,
1354 is_inside=1,
1355 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001356 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001357
1358 :param sw_if_index: Software index of the interface
1359 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1360 :param is_add: 1 if add, 0 if delete (Default value = 1)
1361 """
1362 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001363 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001364 {'is_add': is_add,
1365 'is_inside': is_inside,
1366 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001367
Matus Fabian2ba92e32017-08-21 07:05:03 -07001368 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001369 self,
1370 sw_if_index,
1371 is_inside=1,
1372 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001373 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001374
1375 :param sw_if_index: Software index of the interface
1376 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1377 :param is_add: 1 if add, 0 if delete (Default value = 1)
1378 """
1379 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001380 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001381 {'is_add': is_add,
1382 'is_inside': is_inside,
1383 'sw_if_index': sw_if_index})
1384
Matus Fabian2ba92e32017-08-21 07:05:03 -07001385 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001386 self,
1387 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001388 external_ip=0,
1389 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001390 local_port=0,
1391 external_port=0,
1392 addr_only=1,
1393 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001394 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001395 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001396 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001397 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001398 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001399 is_add=1):
1400 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001401
1402 :param local_ip: Local IP address
1403 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001404 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001405 :param local_port: Local port number (Default value = 0)
1406 :param external_port: External port number (Default value = 0)
1407 :param addr_only: 1 if address only mapping, 0 if address and port
1408 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001409 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001410 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001411 :param self_twice_nat: 1 if translate external host address and port
1412 whenever external host address equals
1413 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001414 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001415 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001416 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001417 """
1418 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001419 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001420 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001421 'addr_only': addr_only,
1422 'local_ip_address': local_ip,
1423 'external_ip_address': external_ip,
1424 'local_port': local_port,
1425 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001426 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001427 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001428 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001429 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001430 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001431 'out2in_only': out2in_only,
1432 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001433
Matus Fabianab7a8052017-11-28 04:29:41 -08001434 def nat44_add_del_identity_mapping(
1435 self,
1436 ip='0',
1437 sw_if_index=0xFFFFFFFF,
1438 port=0,
1439 addr_only=1,
1440 vrf_id=0,
1441 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001442 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001443 is_add=1):
1444 """Add/delete NAT44 identity mapping
1445
1446 :param ip: IP address (Default value = 0)
1447 :param sw_if_index: Interface instead of IP address
1448 :param port: Port number (Default value = 0)
1449 :param addr_only: 1 if address only mapping, 0 if address and port
1450 :param vrf_id: VRF ID
1451 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001452 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001453 :param is_add: 1 if add, 0 if delete (Default value = 1)
1454 """
1455 return self.api(
1456 self.papi.nat44_add_del_identity_mapping,
1457 {'is_add': is_add,
1458 'addr_only': addr_only,
1459 'ip_address': ip,
1460 'port': port,
1461 'sw_if_index': sw_if_index,
1462 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001463 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001464 'protocol': protocol})
1465
Matus Fabian2ba92e32017-08-21 07:05:03 -07001466 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001467 self,
1468 first_ip_address,
1469 last_ip_address,
1470 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001471 vrf_id=0xFFFFFFFF,
1472 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001473 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001474
1475 :param first_ip_address: First IP address
1476 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001477 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001478 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001479 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001480 """
1481 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001482 self.papi.nat44_add_del_address_range,
1483 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001484 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001485 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001486 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001487 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001488
Matus Fabian2ba92e32017-08-21 07:05:03 -07001489 def nat44_address_dump(self):
1490 """Dump NAT44 addresses
1491 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001492 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001493 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001494
Matus Fabian2ba92e32017-08-21 07:05:03 -07001495 def nat44_interface_dump(self):
1496 """Dump interfaces with NAT44 feature
1497 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001498 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001499 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001500
Matus Fabian2ba92e32017-08-21 07:05:03 -07001501 def nat44_interface_output_feature_dump(self):
1502 """Dump interfaces with NAT44 output feature
1503 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001504 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001505 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001506
Matus Fabian2ba92e32017-08-21 07:05:03 -07001507 def nat44_static_mapping_dump(self):
1508 """Dump NAT44 static mappings
1509 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001510 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001511 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001512
Matus Fabianab7a8052017-11-28 04:29:41 -08001513 def nat44_identity_mapping_dump(self):
1514 """Dump NAT44 identity mappings
1515 :return: Dictionary of NAT44 identity mappings
1516 """
1517 return self.api(self.papi.nat44_identity_mapping_dump, {})
1518
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 def nat_show_config(self):
1520 """Show NAT plugin config
1521 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001522 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001523 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001524
Matus Fabian2ba92e32017-08-21 07:05:03 -07001525 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001526 self,
1527 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001528 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001529 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001530 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001531
1532 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001533 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001534 :param is_add: 1 if add, 0 if delete (Default value = 1)
1535 """
Matus Fabianb932d262017-12-18 05:38:24 -08001536 return self.api(
1537 self.papi.nat44_add_del_interface_addr,
1538 {'is_add': is_add,
1539 'sw_if_index': sw_if_index,
1540 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001541
Matus Fabian2ba92e32017-08-21 07:05:03 -07001542 def nat44_interface_addr_dump(self):
1543 """Dump NAT44 addresses interfaces
1544 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001545 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001546 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001547
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001549 self,
1550 domain_id=1,
1551 src_port=4739,
1552 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001553 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001554
1555 :param domain_id: Observation domain ID (Default value = 1)
1556 :param src_port: Source port number (Default value = 4739)
1557 :param enable: 1 if enable, 0 if disable (Default value = 1)
1558 """
1559 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001561 {'domain_id': domain_id,
1562 'src_port': src_port,
1563 'enable': enable})
1564
Matus Fabian2ba92e32017-08-21 07:05:03 -07001565 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001566 self,
1567 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001568 vrf_id):
1569 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001570
1571 :param ip_address: ip adress of the user to be dumped
1572 :param cpu_index: cpu_index on which the user is
1573 :param vrf_id: VRF ID
1574 :return: Dictionary of S-NAT sessions
1575 """
1576 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001577 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001578 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001580
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 def nat44_user_dump(self):
1582 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001583
Matus Fabian2ba92e32017-08-21 07:05:03 -07001584 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001585 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001586 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001587
Matus Fabian704018c2017-09-04 02:17:18 -07001588 def nat44_add_del_lb_static_mapping(
1589 self,
1590 external_addr,
1591 external_port,
1592 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001593 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001594 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001595 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001596 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -07001597 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -07001598 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001599 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001600 is_add=1):
1601 """Add/delete NAT44 load balancing static mapping
1602
Matus Fabianb932d262017-12-18 05:38:24 -08001603 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001604 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -07001605 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -07001606 :param is_add - 1 if add, 0 if delete
1607 """
1608 return self.api(
1609 self.papi.nat44_add_del_lb_static_mapping,
1610 {'is_add': is_add,
1611 'external_addr': external_addr,
1612 'external_port': external_port,
1613 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -08001614 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001615 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001616 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001617 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -07001618 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -07001619 'local_num': local_num,
1620 'locals': locals})
1621
1622 def nat44_lb_static_mapping_dump(self):
1623 """Dump NAT44 load balancing static mappings
1624
1625 :return: Dictionary of NAT44 load balancing static mapping
1626 """
1627 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1628
Matus Fabian5ba86f72017-10-26 03:37:38 -07001629 def nat44_del_session(
1630 self,
1631 addr,
1632 port,
1633 protocol,
1634 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001635 is_in=1,
1636 ext_host_address=None,
1637 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001638 """Delete NAT44 session
1639
1640 :param addr: IPv4 address
1641 :param por: port number
1642 :param protocol: IP protocol number
1643 :param vrf_id: VRF ID
1644 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001645 :param ext_host_address: external host IPv4 address
1646 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001647 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001648 if ext_host_address is None:
1649 return self.api(
1650 self.papi.nat44_del_session,
1651 {'address': addr,
1652 'port': port,
1653 'protocol': protocol,
1654 'vrf_id': vrf_id,
1655 'is_in': is_in})
1656 else:
1657 return self.api(
1658 self.papi.nat44_del_session,
1659 {'address': addr,
1660 'port': port,
1661 'protocol': protocol,
1662 'vrf_id': vrf_id,
1663 'is_in': is_in,
1664 'ext_host_valid': 1,
1665 'ext_host_address': ext_host_address,
1666 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001667
Juraj Sloboda7b929792017-11-23 13:20:48 +01001668 def nat44_forwarding_enable_disable(
1669 self,
1670 enable):
1671 """Enable/disable forwarding for NAT44
1672
1673 :param enable: 1 for enable, 0 for disable
1674 """
1675 return self.api(
1676 self.papi.nat44_forwarding_enable_disable,
1677 {'enable': enable})
1678
Matus Fabianefcd1e92017-08-15 06:59:19 -07001679 def nat_set_reass(
1680 self,
1681 timeout=2,
1682 max_reass=1024,
1683 max_frag=5,
1684 drop_frag=0,
1685 is_ip6=0):
1686 """Set NAT virtual fragmentation reassembly
1687
1688 :param timeout: reassembly timeout (Default 2sec)
1689 :param max_reass: maximum concurrent reassemblies (Default 1024)
1690 :param max_frag: maximum fragmets per reassembly (Default 5)
1691 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1692 :param is_ip6: 1 if IPv6, 0 if IPv4
1693 """
1694 return self.api(
1695 self.papi.nat_set_reass,
1696 {'timeout': timeout,
1697 'max_reass': max_reass,
1698 'max_frag': max_frag,
1699 'drop_frag': drop_frag,
1700 'is_ip6': is_ip6})
1701
1702 def nat_get_reass(self):
1703 """Get NAT virtual fragmentation reassembly configuration
1704
1705 :return: NAT virtual fragmentation reassembly configuration
1706 """
1707 return self.api(self.papi.nat_get_reass, {})
1708
1709 def nat_reass_dump(self):
1710 """Dump NAT virtual fragmentation reassemblies
1711
1712 :return: Dictionary of NAT virtual fragmentation reassemblies
1713 """
1714 return self.api(self.papi.nat_reass_dump, {})
1715
Matus Fabian2ba92e32017-08-21 07:05:03 -07001716 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001717 self,
1718 in_addr,
1719 in_plen,
1720 out_addr,
1721 out_plen,
1722 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001723 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001724
1725 :param is_add - 1 if add, 0 if delete
1726 :param in_addr - inside IP address
1727 :param in_plen - inside IP address prefix length
1728 :param out_addr - outside IP address
1729 :param out_plen - outside IP address prefix length
1730 """
1731 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001732 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001733 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001734 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001735 'in_addr': in_addr,
1736 'in_plen': in_plen,
1737 'out_addr': out_addr,
1738 'out_plen': out_plen})
1739
Matus Fabian2ba92e32017-08-21 07:05:03 -07001740 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001741 self,
1742 in_addr):
1743 """Get outside address and port range from inside address
1744
1745 :param in_addr - inside IP address
1746 """
1747 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001748 self.papi.nat_det_forward,
1749 {'in_addr': in_addr,
1750 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001751
Matus Fabian2ba92e32017-08-21 07:05:03 -07001752 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001753 self,
1754 out_addr,
1755 out_port):
1756 """Get inside address from outside address and port
1757
1758 :param out_addr - outside IP address
1759 :param out_port - outside port
1760 """
1761 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001762 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001763 {'out_addr': out_addr,
1764 'out_port': out_port})
1765
Matus Fabian2ba92e32017-08-21 07:05:03 -07001766 def nat_det_map_dump(self):
1767 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001768
Matus Fabian2ba92e32017-08-21 07:05:03 -07001769 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001770 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001771 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001772
Matus Fabian878c6462018-08-23 00:33:35 -07001773 def nat_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001774 self,
1775 udp=300,
1776 tcp_established=7440,
1777 tcp_transitory=240,
1778 icmp=60):
Matus Fabian878c6462018-08-23 00:33:35 -07001779 """Set values of timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001780
1781 :param udp - UDP timeout (Default value = 300)
1782 :param tcp_established - TCP established timeout (Default value = 7440)
1783 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1784 :param icmp - ICMP timeout (Default value = 60)
1785 """
1786 return self.api(
Matus Fabian878c6462018-08-23 00:33:35 -07001787 self.papi.nat_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001788 {'udp': udp,
1789 'tcp_established': tcp_established,
1790 'tcp_transitory': tcp_transitory,
1791 'icmp': icmp})
1792
Matus Fabian878c6462018-08-23 00:33:35 -07001793 def nat_get_timeouts(self):
1794 """Get values of timeouts for NAT sessions
Matus Fabian6a0946f2017-04-12 03:36:13 -07001795
Matus Fabian878c6462018-08-23 00:33:35 -07001796 :return: Timeouts for NAT sessions (in seconds)
Matus Fabian6a0946f2017-04-12 03:36:13 -07001797 """
Matus Fabian878c6462018-08-23 00:33:35 -07001798 return self.api(self.papi.nat_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001799
Matus Fabian2ba92e32017-08-21 07:05:03 -07001800 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001801 self,
1802 out_addr,
1803 out_port,
1804 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001805 ext_port):
1806 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001807
1808 :param out_addr - outside IP address
1809 :param out_port - outside port
1810 :param ext_addr - external host IP address
1811 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001812 """
1813 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001814 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001815 {'out_addr': out_addr,
1816 'out_port': out_port,
1817 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001818 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001819
Matus Fabian2ba92e32017-08-21 07:05:03 -07001820 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001821 self,
1822 in_addr,
1823 in_port,
1824 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001825 ext_port):
1826 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001827
1828 :param in_addr - inside IP address
1829 :param in_port - inside port
1830 :param ext_addr - external host IP address
1831 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001832 """
1833 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001834 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001835 {'in_addr': in_addr,
1836 'in_port': in_port,
1837 'ext_addr': ext_addr,
1838 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001839 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001840
Matus Fabian2ba92e32017-08-21 07:05:03 -07001841 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001842 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001843 user_addr):
1844 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001845
1846 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001847 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001848 """
1849 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001850 self.papi.nat_det_session_dump,
1851 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001852 'user_addr': user_addr})
1853
Matus Fabian06596c52017-06-06 04:53:28 -07001854 def nat64_add_del_pool_addr_range(
1855 self,
1856 start_addr,
1857 end_addr,
1858 vrf_id=0xFFFFFFFF,
1859 is_add=1):
1860 """Add/del address range to NAT64 pool
1861
1862 :param start_addr: First IP address
1863 :param end_addr: Last IP address
1864 :param vrf_id: VRF id for the address range
1865 :param is_add: 1 if add, 0 if delete (Default value = 1)
1866 """
1867 return self.api(
1868 self.papi.nat64_add_del_pool_addr_range,
1869 {'start_addr': start_addr,
1870 'end_addr': end_addr,
1871 'vrf_id': vrf_id,
1872 'is_add': is_add})
1873
1874 def nat64_pool_addr_dump(self):
1875 """Dump NAT64 pool addresses
1876 :return: Dictionary of NAT64 pool addresses
1877 """
1878 return self.api(self.papi.nat64_pool_addr_dump, {})
1879
1880 def nat64_add_del_interface(
1881 self,
1882 sw_if_index,
1883 is_inside=1,
1884 is_add=1):
1885 """Enable/disable NAT64 feature on the interface
1886 :param sw_if_index: Index of the interface
1887 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1888 :param is_add: 1 if add, 0 if delete (Default value = 1)
1889 """
1890 return self.api(
1891 self.papi.nat64_add_del_interface,
1892 {'sw_if_index': sw_if_index,
1893 'is_inside': is_inside,
1894 'is_add': is_add})
1895
1896 def nat64_interface_dump(self):
1897 """Dump interfaces with NAT64 feature
1898 :return: Dictionary of interfaces with NAT64 feature
1899 """
1900 return self.api(self.papi.nat64_interface_dump, {})
1901
1902 def nat64_add_del_static_bib(
1903 self,
1904 in_ip,
1905 out_ip,
1906 in_port,
1907 out_port,
1908 protocol,
1909 vrf_id=0,
1910 is_add=1):
1911 """Add/delete S-NAT static BIB entry
1912
1913 :param in_ip: Inside IPv6 address
1914 :param out_ip: Outside IPv4 address
1915 :param in_port: Inside port number
1916 :param out_port: Outside port number
1917 :param protocol: IP protocol
1918 :param vrf_id: VRF ID (Default value = 0)
1919 :param is_add: 1 if add, 0 if delete (Default value = 1)
1920 """
1921 return self.api(
1922 self.papi.nat64_add_del_static_bib,
1923 {'i_addr': in_ip,
1924 'o_addr': out_ip,
1925 'i_port': in_port,
1926 'o_port': out_port,
1927 'vrf_id': vrf_id,
1928 'proto': protocol,
1929 'is_add': is_add})
1930
Matus Fabianab9a59c2017-08-16 05:37:36 -07001931 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001932 """Dump NAT64 BIB
1933
Matus Fabianab9a59c2017-08-16 05:37:36 -07001934 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001935 :returns: Dictionary of NAT64 BIB entries
1936 """
1937 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1938
1939 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1940 tcp_incoming_syn=6):
1941 """Set values of timeouts for NAT64 (in seconds)
1942
Matus Fabian428dc912017-06-21 06:15:18 -07001943 :param udpi: UDP timeout (Default value = 300)
1944 :param icmp: ICMP timeout (Default value = 60)
1945 :param tcp_trans: TCP transitory timeout (Default value = 240)
1946 :param tcp_est: TCP established timeout (Default value = 7440)
1947 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001948 """
1949 return self.api(
1950 self.papi.nat64_set_timeouts,
1951 {'udp': udp,
1952 'icmp': icmp,
1953 'tcp_trans': tcp_trans,
1954 'tcp_est': tcp_est,
1955 'tcp_incoming_syn': tcp_incoming_syn})
1956
1957 def nat64_get_timeouts(self):
1958 """Get values of timeouts for NAT64
1959
1960 :return: Timeouts for NAT64 (in seconds)
1961 """
1962 return self.api(self.papi.nat64_get_timeouts, {})
1963
Matus Fabianab9a59c2017-08-16 05:37:36 -07001964 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001965 """Dump NAT64 session table
1966
Matus Fabianab9a59c2017-08-16 05:37:36 -07001967 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001968 :returns: Dictionary of NAT64 sesstion table entries
1969 """
1970 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1971
Matus Fabian428dc912017-06-21 06:15:18 -07001972 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1973 """Add/del NAT64 prefix
1974
1975 :param prefix: NAT64 prefix
1976 :param plen: NAT64 prefix length
1977 :param vrf_id: VRF id of tenant (Default 0)
1978 :param is_add: 1 if add, 0 if delete (Default value = 1)
1979 """
1980 return self.api(
1981 self.papi.nat64_add_del_prefix,
1982 {'prefix': prefix,
1983 'prefix_len': plen,
1984 'vrf_id': vrf_id,
1985 'is_add': is_add})
1986
1987 def nat64_prefix_dump(self):
1988 """Dump NAT64 prefix
1989
1990 :returns: Dictionary of NAT64 prefixes
1991 """
1992 return self.api(self.papi.nat64_prefix_dump, {})
1993
Matus Fabian0938dcf2017-11-08 01:59:38 -08001994 def nat64_add_interface_addr(
1995 self,
1996 sw_if_index,
1997 is_add=1):
1998 """Add/del NAT64 address from interface
1999
2000 :param sw_if_index: Software index of the interface
2001 :param is_add: 1 if add, 0 if delete (Default value = 1)
2002 """
2003 return self.api(self.papi.nat64_add_del_interface_addr,
2004 {'is_add': is_add, 'sw_if_index': sw_if_index})
2005
Matus Fabian8ebe6252017-11-06 05:04:53 -08002006 def dslite_set_aftr_addr(self, ip6, ip4):
2007 """Set DS-Lite AFTR addresses
2008
2009 :param ip4: IPv4 address
2010 :param ip6: IPv6 address
2011 """
2012 return self.api(
2013 self.papi.dslite_set_aftr_addr,
2014 {'ip4_addr': ip4,
2015 'ip6_addr': ip6})
2016
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002017 def dslite_set_b4_addr(self, ip6, ip4):
2018 """Set DS-Lite B4 IPv6 address
2019
2020 :param ip4: IPv4 address
2021 :param ip6: IPv6 address
2022 """
2023 return self.api(
2024 self.papi.dslite_set_b4_addr,
2025 {'ip4_addr': ip4,
2026 'ip6_addr': ip6})
2027
Matus Fabian8ebe6252017-11-06 05:04:53 -08002028 def dslite_add_del_pool_addr_range(
2029 self,
2030 start_addr,
2031 end_addr,
2032 is_add=1):
2033 """Add/del address range to DS-Lite pool
2034
2035 :param start_addr: First IP address
2036 :param end_addr: Last IP address
2037 :param is_add: 1 if add, 0 if delete (Default value = 1)
2038 """
2039 return self.api(
2040 self.papi.dslite_add_del_pool_addr_range,
2041 {'start_addr': start_addr,
2042 'end_addr': end_addr,
2043 'is_add': is_add})
2044
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002045 def nat66_add_del_interface(
2046 self,
2047 sw_if_index,
2048 is_inside=1,
2049 is_add=1):
2050 """Enable/disable NAT66 feature on the interface
2051 :param sw_if_index: Index of the interface
2052 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2053 :param is_add: 1 if add, 0 if delete (Default value = 1)
2054 """
2055 return self.api(
2056 self.papi.nat66_add_del_interface,
2057 {'sw_if_index': sw_if_index,
2058 'is_inside': is_inside,
2059 'is_add': is_add})
2060
2061 def nat66_add_del_static_mapping(
2062 self,
2063 in_ip,
2064 out_ip,
2065 vrf_id=0,
2066 is_add=1):
2067 """Add/delete NAT66 static mapping
2068
2069 :param in_ip: Inside IPv6 address
2070 :param out_ip: Outside IPv6 address
2071 :param vrf_id: VRF ID (Default value = 0)
2072 :param is_add: 1 if add, 0 if delete (Default value = 1)
2073 """
2074 return self.api(
2075 self.papi.nat66_add_del_static_mapping,
2076 {'local_ip_address': in_ip,
2077 'external_ip_address': out_ip,
2078 'vrf_id': vrf_id,
2079 'is_add': is_add})
2080
2081 def nat66_interface_dump(self):
2082 """Dump interfaces with NAT66 feature
2083 :return: Dictionary of interfaces with NAT66 feature
2084 """
2085 return self.api(self.papi.nat66_interface_dump, {})
2086
2087 def nat66_static_mapping_dump(self):
2088 """Dump NAT66 static mappings
2089 :return: Dictionary of NAT66 static mappings
2090 """
2091 return self.api(self.papi.nat66_static_mapping_dump, {})
2092
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002093 def control_ping(self):
2094 self.api(self.papi.control_ping)
2095
2096 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002097 detect_mult, local_addr, peer_addr, is_ipv6=0,
2098 bfd_key_id=None, conf_key_id=None):
2099 if bfd_key_id is None:
2100 return self.api(self.papi.bfd_udp_add,
2101 {
2102 'sw_if_index': sw_if_index,
2103 'desired_min_tx': desired_min_tx,
2104 'required_min_rx': required_min_rx,
2105 'local_addr': local_addr,
2106 'peer_addr': peer_addr,
2107 'is_ipv6': is_ipv6,
2108 'detect_mult': detect_mult,
2109 })
2110 else:
2111 return self.api(self.papi.bfd_udp_add,
2112 {
2113 'sw_if_index': sw_if_index,
2114 'desired_min_tx': desired_min_tx,
2115 'required_min_rx': required_min_rx,
2116 'local_addr': local_addr,
2117 'peer_addr': peer_addr,
2118 'is_ipv6': is_ipv6,
2119 'detect_mult': detect_mult,
2120 'is_authenticated': 1,
2121 'bfd_key_id': bfd_key_id,
2122 'conf_key_id': conf_key_id,
2123 })
2124
Klement Sekeraa57a9702017-02-02 06:58:07 +01002125 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2126 detect_mult, local_addr, peer_addr, is_ipv6=0):
2127 return self.api(self.papi.bfd_udp_mod,
2128 {
2129 'sw_if_index': sw_if_index,
2130 'desired_min_tx': desired_min_tx,
2131 'required_min_rx': required_min_rx,
2132 'local_addr': local_addr,
2133 'peer_addr': peer_addr,
2134 'is_ipv6': is_ipv6,
2135 'detect_mult': detect_mult,
2136 })
2137
Klement Sekerab17dd962017-01-09 07:43:48 +01002138 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2139 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2140 is_delayed=False):
2141 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002142 {
2143 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002144 'local_addr': local_addr,
2145 'peer_addr': peer_addr,
2146 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002147 'is_delayed': 1 if is_delayed else 0,
2148 'bfd_key_id': bfd_key_id,
2149 'conf_key_id': conf_key_id,
2150 })
2151
2152 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2153 is_ipv6=0, is_delayed=False):
2154 return self.api(self.papi.bfd_udp_auth_deactivate,
2155 {
2156 'sw_if_index': sw_if_index,
2157 'local_addr': local_addr,
2158 'peer_addr': peer_addr,
2159 'is_ipv6': is_ipv6,
2160 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002161 })
2162
2163 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2164 return self.api(self.papi.bfd_udp_del,
2165 {
2166 'sw_if_index': sw_if_index,
2167 'local_addr': local_addr,
2168 'peer_addr': peer_addr,
2169 'is_ipv6': is_ipv6,
2170 })
2171
2172 def bfd_udp_session_dump(self):
2173 return self.api(self.papi.bfd_udp_session_dump, {})
2174
Klement Sekerab17dd962017-01-09 07:43:48 +01002175 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2176 peer_addr, is_ipv6=0):
2177 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002178 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002179 'sw_if_index': sw_if_index,
2180 'local_addr': local_addr,
2181 'peer_addr': peer_addr,
2182 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002183 })
2184
2185 def want_bfd_events(self, enable_disable=1):
2186 return self.api(self.papi.want_bfd_events, {
2187 'enable_disable': enable_disable,
2188 'pid': os.getpid(),
2189 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002190
Klement Sekerab17dd962017-01-09 07:43:48 +01002191 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2192 return self.api(self.papi.bfd_auth_set_key, {
2193 'conf_key_id': conf_key_id,
2194 'auth_type': auth_type,
2195 'key': key,
2196 'key_len': len(key),
2197 })
2198
2199 def bfd_auth_del_key(self, conf_key_id):
2200 return self.api(self.papi.bfd_auth_del_key, {
2201 'conf_key_id': conf_key_id,
2202 })
2203
2204 def bfd_auth_keys_dump(self):
2205 return self.api(self.papi.bfd_auth_keys_dump, {})
2206
Klement Sekera239790f2017-02-16 10:53:53 +01002207 def bfd_udp_set_echo_source(self, sw_if_index):
2208 return self.api(self.papi.bfd_udp_set_echo_source,
2209 {'sw_if_index': sw_if_index})
2210
Klement Sekera73884482017-02-23 09:26:30 +01002211 def bfd_udp_del_echo_source(self):
2212 return self.api(self.papi.bfd_udp_del_echo_source, {})
2213
Steve Shin7957d6e2016-12-19 09:24:50 -08002214 def classify_add_del_table(
2215 self,
2216 is_add,
2217 mask,
2218 match_n_vectors=1,
2219 table_index=0xFFFFFFFF,
2220 nbuckets=2,
2221 memory_size=2097152,
2222 skip_n_vectors=0,
2223 next_table_index=0xFFFFFFFF,
2224 miss_next_index=0xFFFFFFFF,
2225 current_data_flag=0,
2226 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002227 """
2228 :param is_add:
2229 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002230 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002231 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002232 :param nbuckets: (Default value = 2)
2233 :param memory_size: (Default value = 2097152)
2234 :param skip_n_vectors: (Default value = 0)
2235 :param next_table_index: (Default value = 0xFFFFFFFF)
2236 :param miss_next_index: (Default value = 0xFFFFFFFF)
2237 :param current_data_flag: (Default value = 0)
2238 :param current_data_offset: (Default value = 0)
2239 """
2240
Juraj Sloboda75282452018-06-12 14:20:49 +02002241 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2242 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002243 return self.api(
2244 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002245 {'is_add': is_add,
2246 'table_index': table_index,
2247 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002248 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002249 'skip_n_vectors': skip_n_vectors,
2250 'match_n_vectors': match_n_vectors,
2251 'next_table_index': next_table_index,
2252 'miss_next_index': miss_next_index,
2253 'current_data_flag': current_data_flag,
2254 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002255 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002256 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002257
2258 def classify_add_del_session(
2259 self,
2260 is_add,
2261 table_index,
2262 match,
2263 opaque_index=0xFFFFFFFF,
2264 hit_next_index=0xFFFFFFFF,
2265 advance=0,
2266 action=0,
2267 metadata=0):
2268 """
2269 :param is_add:
2270 :param table_index:
2271 :param match:
2272 :param opaque_index: (Default value = 0xFFFFFFFF)
2273 :param hit_next_index: (Default value = 0xFFFFFFFF)
2274 :param advance: (Default value = 0)
2275 :param action: (Default value = 0)
2276 :param metadata: (Default value = 0)
2277 """
2278
Juraj Sloboda75282452018-06-12 14:20:49 +02002279 match_len = ((len(match) - 1) / 16 + 1) * 16
2280 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002281 return self.api(
2282 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002283 {'is_add': is_add,
2284 'table_index': table_index,
2285 'hit_next_index': hit_next_index,
2286 'opaque_index': opaque_index,
2287 'advance': advance,
2288 'action': action,
2289 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002290 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002291 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002292
2293 def input_acl_set_interface(
2294 self,
2295 is_add,
2296 sw_if_index,
2297 ip4_table_index=0xFFFFFFFF,
2298 ip6_table_index=0xFFFFFFFF,
2299 l2_table_index=0xFFFFFFFF):
2300 """
2301 :param is_add:
2302 :param sw_if_index:
2303 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2304 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2305 :param l2_table_index: (Default value = 0xFFFFFFFF)
2306 """
2307
2308 return self.api(
2309 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002310 {'sw_if_index': sw_if_index,
2311 'ip4_table_index': ip4_table_index,
2312 'ip6_table_index': ip6_table_index,
2313 'l2_table_index': l2_table_index,
2314 'is_add': is_add})
2315
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002316 def output_acl_set_interface(
2317 self,
2318 is_add,
2319 sw_if_index,
2320 ip4_table_index=0xFFFFFFFF,
2321 ip6_table_index=0xFFFFFFFF,
2322 l2_table_index=0xFFFFFFFF):
2323 """
2324 :param is_add:
2325 :param sw_if_index:
2326 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2327 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2328 :param l2_table_index: (Default value = 0xFFFFFFFF)
2329 """
2330
2331 return self.api(
2332 self.papi.output_acl_set_interface,
2333 {'sw_if_index': sw_if_index,
2334 'ip4_table_index': ip4_table_index,
2335 'ip6_table_index': ip6_table_index,
2336 'l2_table_index': l2_table_index,
2337 'is_add': is_add})
2338
Klement Sekera77fabdb2017-01-02 07:46:14 +01002339 def set_ipfix_exporter(
2340 self,
2341 collector_address,
2342 src_address,
2343 path_mtu,
2344 template_interval,
2345 vrf_id=0,
2346 collector_port=4739,
2347 udp_checksum=0):
2348 return self.api(
2349 self.papi.set_ipfix_exporter,
2350 {
2351 'collector_address': collector_address,
2352 'collector_port': collector_port,
2353 'src_address': src_address,
2354 'vrf_id': vrf_id,
2355 'path_mtu': path_mtu,
2356 'template_interval': template_interval,
2357 'udp_checksum': udp_checksum,
2358 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002359
2360 def dhcp_proxy_config(self,
2361 dhcp_server,
2362 dhcp_src_address,
2363 rx_table_id=0,
2364 server_table_id=0,
2365 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002366 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002367 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002368 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002369 {
2370 'rx_vrf_id': rx_table_id,
2371 'server_vrf_id': server_table_id,
2372 'is_ipv6': is_ipv6,
2373 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002374 'dhcp_server': dhcp_server,
2375 'dhcp_src_address': dhcp_src_address,
2376 })
2377
2378 def dhcp_proxy_set_vss(self,
2379 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002380 vss_type=255,
2381 vpn_ascii_id="",
2382 oui=0,
2383 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002384 is_add=1,
2385 is_ip6=0):
2386 return self.api(
2387 self.papi.dhcp_proxy_set_vss,
2388 {
2389 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002390 'vss_type': vss_type,
2391 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002392 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002393 'vpn_index': vpn_index,
2394 'is_add': is_add,
2395 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002396 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002397
Neale Rannsdaff1782018-05-16 04:12:18 -07002398 def dhcp_client_dump(self):
2399 return self.api(self.papi.dhcp_client_dump, {})
2400
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002401 def dhcp_client(self,
2402 sw_if_index,
2403 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002404 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002405 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002406 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002407 want_dhcp_events=0):
2408 return self.api(
2409 self.papi.dhcp_client_config,
2410 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002411 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002412 'client': {
2413 'sw_if_index': sw_if_index,
2414 'hostname': hostname,
2415 'id': client_id,
2416 'want_dhcp_event': want_dhcp_events,
2417 'set_broadcast_flag': set_broadcast_flag,
2418 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002419 })
2420
Neale Ranns32e1c012016-11-22 17:07:28 +00002421 def ip_mroute_add_del(self,
2422 src_address,
2423 grp_address,
2424 grp_address_length,
2425 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002426 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002427 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002428 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002429 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002430 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002431 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002432 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002433 is_add=1,
2434 is_ipv6=0,
2435 is_local=0):
2436 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002437 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002438 """
2439 return self.api(
2440 self.papi.ip_mroute_add_del,
2441 {'next_hop_sw_if_index': next_hop_sw_if_index,
2442 'entry_flags': e_flags,
2443 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002444 'table_id': table_id,
2445 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002446 'is_add': is_add,
2447 'is_ipv6': is_ipv6,
2448 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002449 'bier_imp': bier_imp,
2450 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002451 'grp_address_length': grp_address_length,
2452 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002453 'src_address': src_address,
2454 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002455
2456 def mfib_signal_dump(self):
2457 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002458
2459 def ip_mfib_dump(self):
2460 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002461
Neale Rannsd792d9c2017-10-21 10:53:20 -07002462 def ip6_mfib_dump(self):
2463 return self.api(self.papi.ip6_mfib_dump, {})
2464
Filip Tehlar770e89e2017-01-31 10:39:16 +01002465 def lisp_enable_disable(self, is_enabled):
2466 return self.api(
2467 self.papi.lisp_enable_disable,
2468 {
2469 'is_en': is_enabled,
2470 })
2471
2472 def lisp_locator_set(self,
2473 ls_name,
2474 is_add=1):
2475 return self.api(
2476 self.papi.lisp_add_del_locator_set,
2477 {
2478 'is_add': is_add,
2479 'locator_set_name': ls_name
2480 })
2481
2482 def lisp_locator_set_dump(self):
2483 return self.api(self.papi.lisp_locator_set_dump, {})
2484
2485 def lisp_locator(self,
2486 ls_name,
2487 sw_if_index,
2488 priority=1,
2489 weight=1,
2490 is_add=1):
2491 return self.api(
2492 self.papi.lisp_add_del_locator,
2493 {
2494 'is_add': is_add,
2495 'locator_set_name': ls_name,
2496 'sw_if_index': sw_if_index,
2497 'priority': priority,
2498 'weight': weight
2499 })
2500
2501 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2502 return self.api(
2503 self.papi.lisp_locator_dump,
2504 {
2505 'is_index_set': is_index_set,
2506 'ls_name': ls_name,
2507 'ls_index': ls_index,
2508 })
2509
2510 def lisp_local_mapping(self,
2511 ls_name,
2512 eid_type,
2513 eid,
2514 prefix_len,
2515 vni=0,
2516 key_id=0,
2517 key="",
2518 is_add=1):
2519 return self.api(
2520 self.papi.lisp_add_del_local_eid,
2521 {
2522 'locator_set_name': ls_name,
2523 'is_add': is_add,
2524 'eid_type': eid_type,
2525 'eid': eid,
2526 'prefix_len': prefix_len,
2527 'vni': vni,
2528 'key_id': key_id,
2529 'key': key
2530 })
2531
2532 def lisp_eid_table_dump(self,
2533 eid_set=0,
2534 prefix_length=0,
2535 vni=0,
2536 eid_type=0,
2537 eid=None,
2538 filter_opt=0):
2539 return self.api(
2540 self.papi.lisp_eid_table_dump,
2541 {
2542 'eid_set': eid_set,
2543 'prefix_length': prefix_length,
2544 'vni': vni,
2545 'eid_type': eid_type,
2546 'eid': eid,
2547 'filter': filter_opt,
2548 })
2549
2550 def lisp_remote_mapping(self,
2551 eid_type,
2552 eid,
2553 eid_prefix_len=0,
2554 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002555 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002556 rlocs_num=0,
2557 is_src_dst=0,
2558 is_add=1):
2559 return self.api(
2560 self.papi.lisp_add_del_remote_mapping,
2561 {
2562 'is_add': is_add,
2563 'eid_type': eid_type,
2564 'eid': eid,
2565 'eid_len': eid_prefix_len,
2566 'rloc_num': rlocs_num,
2567 'rlocs': rlocs,
2568 'vni': vni,
2569 'is_src_dst': is_src_dst,
2570 })
2571
2572 def lisp_adjacency(self,
2573 leid,
2574 reid,
2575 leid_len,
2576 reid_len,
2577 eid_type,
2578 is_add=1,
2579 vni=0):
2580 return self.api(
2581 self.papi.lisp_add_del_adjacency,
2582 {
2583 'is_add': is_add,
2584 'vni': vni,
2585 'eid_type': eid_type,
2586 'leid': leid,
2587 'reid': reid,
2588 'leid_len': leid_len,
2589 'reid_len': reid_len,
2590 })
2591
2592 def lisp_adjacencies_get(self, vni=0):
2593 return self.api(
2594 self.papi.lisp_adjacencies_get,
2595 {
2596 'vni': vni
2597 })
Neale Ranns80823802017-02-20 18:23:41 -08002598
2599 def map_add_domain(self,
2600 ip6_prefix,
2601 ip6_prefix_len,
2602 ip6_src,
2603 ip6_src_prefix_len,
2604 ip4_prefix,
2605 ip4_prefix_len,
2606 ea_bits_len=0,
2607 psid_offset=0,
2608 psid_length=0,
2609 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002610 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002611 mtu=1280):
2612 return self.api(
2613 self.papi.map_add_domain,
2614 {
2615 'ip6_prefix': ip6_prefix,
2616 'ip6_prefix_len': ip6_prefix_len,
2617 'ip4_prefix': ip4_prefix,
2618 'ip4_prefix_len': ip4_prefix_len,
2619 'ip6_src': ip6_src,
2620 'ip6_src_prefix_len': ip6_src_prefix_len,
2621 'ea_bits_len': ea_bits_len,
2622 'psid_offset': psid_offset,
2623 'psid_length': psid_length,
2624 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002625 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002626 'mtu': mtu
2627 })
Hongjun Nief486b12017-04-12 19:21:16 +08002628
2629 def gtpu_add_del_tunnel(
2630 self,
2631 src_addr,
2632 dst_addr,
2633 is_add=1,
2634 is_ipv6=0,
2635 mcast_sw_if_index=0xFFFFFFFF,
2636 encap_vrf_id=0,
2637 decap_next_index=0xFFFFFFFF,
2638 teid=0):
2639 """
2640
2641 :param is_add: (Default value = 1)
2642 :param is_ipv6: (Default value = 0)
2643 :param src_addr:
2644 :param dst_addr:
2645 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2646 :param encap_vrf_id: (Default value = 0)
2647 :param decap_next_index: (Default value = 0xFFFFFFFF)
2648 :param teid: (Default value = 0)
2649
2650 """
2651 return self.api(self.papi.gtpu_add_del_tunnel,
2652 {'is_add': is_add,
2653 'is_ipv6': is_ipv6,
2654 'src_address': src_addr,
2655 'dst_address': dst_addr,
2656 'mcast_sw_if_index': mcast_sw_if_index,
2657 'encap_vrf_id': encap_vrf_id,
2658 'decap_next_index': decap_next_index,
2659 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002660
2661 def vxlan_gpe_add_del_tunnel(
2662 self,
2663 src_addr,
2664 dst_addr,
2665 mcast_sw_if_index=0xFFFFFFFF,
2666 is_add=1,
2667 is_ipv6=0,
2668 encap_vrf_id=0,
2669 decap_vrf_id=0,
2670 protocol=3,
2671 vni=0):
2672 """
2673
2674 :param local:
2675 :param remote:
2676 :param is_add: (Default value = 1)
2677 :param is_ipv6: (Default value = 0)
2678 :param encap_vrf_id: (Default value = 0)
2679 :param decap_vrf_id: (Default value = 0)
2680 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2681 :param protocol: (Default value = 3)
2682 :param vni: (Default value = 0)
2683
2684 """
2685 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2686 {'is_add': is_add,
2687 'is_ipv6': is_ipv6,
2688 'local': src_addr,
2689 'remote': dst_addr,
2690 'mcast_sw_if_index': mcast_sw_if_index,
2691 'encap_vrf_id': encap_vrf_id,
2692 'decap_vrf_id': decap_vrf_id,
2693 'protocol': protocol,
2694 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002695
2696 def pppoe_add_del_session(
2697 self,
2698 client_ip,
2699 client_mac,
2700 session_id=0,
2701 is_add=1,
2702 is_ipv6=0,
2703 decap_vrf_id=0):
2704 """
2705
2706 :param is_add: (Default value = 1)
2707 :param is_ipv6: (Default value = 0)
2708 :param client_ip:
2709 :param session_id: (Default value = 0)
2710 :param client_mac:
2711 :param decap_vrf_id: (Default value = 0)
2712
2713 """
2714 return self.api(self.papi.pppoe_add_del_session,
2715 {'is_add': is_add,
2716 'is_ipv6': is_ipv6,
2717 'session_id': session_id,
2718 'client_ip': client_ip,
2719 'decap_vrf_id': decap_vrf_id,
2720 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002721
Neale Ranns7c922dc2018-08-30 06:12:27 -07002722 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2723 return self.api(self.papi.sr_mpls_policy_add,
2724 {'bsid': bsid,
2725 'weight': weight,
2726 'type': type,
2727 'n_segments': len(segments),
2728 'segments': segments})
2729
2730 def sr_mpls_policy_del(self, bsid):
2731 return self.api(self.papi.sr_mpls_policy_del,
2732 {'bsid': bsid})
2733
Kris Michielsen91074432017-06-22 13:00:20 +02002734 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002735 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002736 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002737 nh_addr4,
2738 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002739 is_del=0,
2740 end_psp=0,
2741 sw_if_index=0xFFFFFFFF,
2742 vlan_index=0,
2743 fib_table=0,
2744 ):
2745 """ Add/del IPv6 SR local-SID.
2746
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002747 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002748 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2749 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002750 :param nh_addr4:
2751 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002752 :param is_del: (Default value = 0)
2753 :param end_psp: (Default value = 0)
2754 :param sw_if_index: (Default value = 0xFFFFFFFF)
2755 :param vlan_index: (Default value = 0)
2756 :param fib_table: (Default value = 0)
2757 """
2758 return self.api(
2759 self.papi.sr_localsid_add_del,
2760 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002761 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002762 'end_psp': end_psp,
2763 'behavior': behavior,
2764 'sw_if_index': sw_if_index,
2765 'vlan_index': vlan_index,
2766 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002767 'nh_addr4': nh_addr4,
2768 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002769 }
2770 )
2771
2772 def sr_policy_add(
2773 self,
2774 bsid_addr,
2775 weight=1,
2776 is_encap=1,
2777 type=0,
2778 fib_table=0,
2779 n_segments=0,
2780 segments=[]):
2781 """
2782 :param bsid_addr: bindingSID of the SR Policy
2783 :param weight: weight of the sid list. optional. (default: 1)
2784 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2785 (default: Encap)
2786 :param type: type/behavior of the SR policy. (default or spray) \
2787 (default: default)
2788 :param fib_table: VRF where to install the FIB entry for the BSID \
2789 (default: 0)
2790 :param n_segments: number of segments \
2791 (default: 0)
2792 :param segments: a vector of IPv6 address composing the segment list \
2793 (default: [])
2794 """
2795 return self.api(
2796 self.papi.sr_policy_add,
2797 {'bsid_addr': bsid_addr,
2798 'weight': weight,
2799 'is_encap': is_encap,
2800 'type': type,
2801 'fib_table': fib_table,
2802 'n_segments': n_segments,
2803 'segments': segments
2804 }
2805 )
2806
2807 def sr_policy_del(
2808 self,
2809 bsid_addr,
2810 sr_policy_index=0):
2811 """
2812 :param bsid: bindingSID of the SR Policy
2813 :param sr_policy_index: index of the sr policy (default: 0)
2814 """
2815 return self.api(
2816 self.papi.sr_policy_del,
2817 {'bsid_addr': bsid_addr,
2818 'sr_policy_index': sr_policy_index
2819 })
2820
2821 def sr_steering_add_del(
2822 self,
2823 is_del,
2824 bsid_addr,
2825 sr_policy_index,
2826 table_id,
2827 prefix_addr,
2828 mask_width,
2829 sw_if_index,
2830 traffic_type):
2831 """
2832 Steer traffic L2 and L3 traffic through a given SR policy
2833
2834 :param is_del: delete or add
2835 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2836 :param sr_policy: is the index of the SR Policy (alt to bsid)
2837 :param table_id: is the VRF where to install the FIB entry for the BSID
2838 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2839 :param mask_width: is the mask for L3 traffic type
2840 :param sw_if_index: is the incoming interface for L2 traffic
2841 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2842 """
2843 return self.api(
2844 self.papi.sr_steering_add_del,
2845 {'is_del': is_del,
2846 'bsid_addr': bsid_addr,
2847 'sr_policy_index': sr_policy_index,
2848 'table_id': table_id,
2849 'prefix_addr': prefix_addr,
2850 'mask_width': mask_width,
2851 'sw_if_index': sw_if_index,
2852 'traffic_type': traffic_type
2853 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002854
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002855 def acl_add_replace(self, acl_index, r, tag='',
2856 expected_retval=0):
2857 """Add/replace an ACL
2858 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2859 :param acl_rule r: ACL rules array.
2860 :param str tag: symbolic tag (description) for this ACL.
2861 :param int count: number of rules.
2862 """
2863 return self.api(self.papi.acl_add_replace,
2864 {'acl_index': acl_index,
2865 'r': r,
2866 'count': len(r),
2867 'tag': tag},
2868 expected_retval=expected_retval)
2869
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002870 def acl_del(self, acl_index, expected_retval=0):
2871 """
2872
2873 :param acl_index:
2874 :return:
2875 """
2876 return self.api(self.papi.acl_del,
2877 {'acl_index': acl_index},
2878 expected_retval=expected_retval)
2879
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002880 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2881 expected_retval=0):
2882 return self.api(self.papi.acl_interface_set_acl_list,
2883 {'sw_if_index': sw_if_index,
2884 'count': len(acls),
2885 'n_input': n_input,
2886 'acls': acls},
2887 expected_retval=expected_retval)
2888
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002889 def acl_interface_set_etype_whitelist(self, sw_if_index,
2890 n_input, whitelist,
2891 expected_retval=0):
2892 return self.api(self.papi.acl_interface_set_etype_whitelist,
2893 {'sw_if_index': sw_if_index,
2894 'count': len(whitelist),
2895 'n_input': n_input,
2896 'whitelist': whitelist},
2897 expected_retval=expected_retval)
2898
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002899 def acl_interface_add_del(self,
2900 sw_if_index,
2901 acl_index,
2902 is_add=1):
2903 """ Add/Delete ACL to/from interface
2904
2905 :param sw_if_index:
2906 :param acl_index:
2907 :param is_add: (Default value = 1)
2908 """
2909
2910 return self.api(self.papi.acl_interface_add_del,
2911 {'is_add': is_add,
2912 'is_input': 1,
2913 'sw_if_index': sw_if_index,
2914 'acl_index': acl_index})
2915
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002916 def acl_dump(self, acl_index, expected_retval=0):
2917 return self.api(self.papi.acl_dump,
2918 {'acl_index': acl_index},
2919 expected_retval=expected_retval)
2920
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002921 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2922 expected_retval=0):
2923 return self.api(self.papi.acl_interface_list_dump,
2924 {'sw_if_index': sw_if_index},
2925 expected_retval=expected_retval)
2926
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002927 def macip_acl_add(self, rules, tag=""):
2928 """ Add MACIP acl
2929
2930 :param rules: list of rules for given acl
2931 :param tag: acl tag
2932 """
2933
2934 return self.api(self.papi.macip_acl_add,
2935 {'r': rules,
2936 'count': len(rules),
2937 'tag': tag})
2938
Pavel Kotucek932f7412017-09-07 14:44:52 +02002939 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2940 """ Add MACIP acl
2941
2942 :param rules: list of rules for given acl
2943 :param tag: acl tag
2944 """
2945
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002946 return self.api(self.papi.macip_acl_add_replace,
2947 {'acl_index': acl_index,
2948 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002949 'count': len(rules),
2950 'tag': tag})
2951
2952 def macip_acl_del(self, acl_index):
2953 """
2954
2955 :param acl_index:
2956 :return:
2957 """
2958 return self.api(self.papi.macip_acl_del,
2959 {'acl_index': acl_index})
2960
2961 def macip_acl_interface_add_del(self,
2962 sw_if_index,
2963 acl_index,
2964 is_add=1):
2965 """ Add MACIP acl to interface
2966
2967 :param sw_if_index:
2968 :param acl_index:
2969 :param is_add: (Default value = 1)
2970 """
2971
2972 return self.api(self.papi.macip_acl_interface_add_del,
2973 {'is_add': is_add,
2974 'sw_if_index': sw_if_index,
2975 'acl_index': acl_index})
2976
2977 def macip_acl_interface_get(self):
2978 """ Return interface acls dump
2979 """
2980 return self.api(
2981 self.papi.macip_acl_interface_get, {})
2982
2983 def macip_acl_dump(self, acl_index=4294967295):
2984 """ Return MACIP acl dump
2985 """
2986
2987 return self.api(
2988 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002989
2990 def policer_add_del(self,
2991 name,
2992 cir,
2993 eir,
2994 cb,
2995 eb,
2996 is_add=1,
2997 rate_type=0,
2998 round_type=0,
2999 ptype=0,
3000 color_aware=0,
3001 conform_action_type=1,
3002 conform_dscp=0,
3003 exceed_action_type=0,
3004 exceed_dscp=0,
3005 violate_action_type=0,
3006 violate_dscp=0):
3007 return self.api(self.papi.policer_add_del,
3008 {'name': name,
3009 'cir': cir,
3010 'eir': eir,
3011 'cb': cb,
3012 'eb': eb,
3013 'is_add': is_add,
3014 'rate_type': rate_type,
3015 'round_type': round_type,
3016 'type': ptype,
3017 'color_aware': color_aware,
3018 'conform_action_type': conform_action_type,
3019 'conform_dscp': conform_dscp,
3020 'exceed_action_type': exceed_action_type,
3021 'exceed_dscp': exceed_dscp,
3022 'violate_action_type': violate_action_type,
3023 'violate_dscp': violate_dscp})
3024
3025 def ip_punt_police(self,
3026 policer_index,
3027 is_ip6=0,
3028 is_add=1):
3029 return self.api(self.papi.ip_punt_police,
3030 {'policer_index': policer_index,
3031 'is_add': is_add,
3032 'is_ip6': is_ip6})
3033
3034 def ip_punt_redirect(self,
3035 rx_sw_if_index,
3036 tx_sw_if_index,
3037 nh,
3038 is_ip6=0,
3039 is_add=1):
3040 return self.api(self.papi.ip_punt_redirect,
3041 {'rx_sw_if_index': rx_sw_if_index,
3042 'tx_sw_if_index': tx_sw_if_index,
3043 'nh': nh,
3044 'is_add': is_add,
3045 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003046
3047 def bier_table_add_del(self,
3048 bti,
3049 mpls_label,
3050 is_add=1):
3051 """ BIER Table add/del """
3052 return self.api(
3053 self.papi.bier_table_add_del,
3054 {'bt_tbl_id': {"bt_set": bti.set_id,
3055 "bt_sub_domain": bti.sub_domain_id,
3056 "bt_hdr_len_id": bti.hdr_len_id},
3057 'bt_label': mpls_label,
3058 'bt_is_add': is_add})
3059
3060 def bier_table_dump(self):
3061 return self.api(self.papi.bier_table_dump, {})
3062
3063 def bier_route_add_del(self,
3064 bti,
3065 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003066 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003067 is_add=1):
3068 """ BIER Route add/del """
3069 return self.api(
3070 self.papi.bier_route_add_del,
3071 {'br_tbl_id': {"bt_set": bti.set_id,
3072 "bt_sub_domain": bti.sub_domain_id,
3073 "bt_hdr_len_id": bti.hdr_len_id},
3074 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003075 'br_n_paths': len(paths),
3076 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003077 'br_is_add': is_add})
3078
3079 def bier_route_dump(self, bti):
3080 return self.api(
3081 self.papi.bier_route_dump,
3082 {'br_tbl_id': {"bt_set": bti.set_id,
3083 "bt_sub_domain": bti.sub_domain_id,
3084 "bt_hdr_len_id": bti.hdr_len_id}})
3085
3086 def bier_imp_add(self,
3087 bti,
3088 src,
3089 ibytes,
3090 is_add=1):
3091 """ BIER Imposition Add """
3092 return self.api(
3093 self.papi.bier_imp_add,
3094 {'bi_tbl_id': {"bt_set": bti.set_id,
3095 "bt_sub_domain": bti.sub_domain_id,
3096 "bt_hdr_len_id": bti.hdr_len_id},
3097 'bi_src': src,
3098 'bi_n_bytes': len(ibytes),
3099 'bi_bytes': ibytes})
3100
3101 def bier_imp_del(self, bi_index):
3102 """ BIER Imposition del """
3103 return self.api(
3104 self.papi.bier_imp_del,
3105 {'bi_index': bi_index})
3106
3107 def bier_imp_dump(self):
3108 return self.api(self.papi.bier_imp_dump, {})
3109
3110 def bier_disp_table_add_del(self,
3111 bdti,
3112 is_add=1):
3113 """ BIER Disposition Table add/del """
3114 return self.api(
3115 self.papi.bier_disp_table_add_del,
3116 {'bdt_tbl_id': bdti,
3117 'bdt_is_add': is_add})
3118
3119 def bier_disp_table_dump(self):
3120 return self.api(self.papi.bier_disp_table_dump, {})
3121
3122 def bier_disp_entry_add_del(self,
3123 bdti,
3124 bp,
3125 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003126 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003127 next_hop,
3128 next_hop_tbl_id=0,
3129 next_hop_rpf_id=~0,
3130 next_hop_is_ip4=1,
3131 is_add=1):
3132 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003133 lstack = []
3134 while (len(lstack) < 16):
3135 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003136 return self.api(
3137 self.papi.bier_disp_entry_add_del,
3138 {'bde_tbl_id': bdti,
3139 'bde_bp': bp,
3140 'bde_payload_proto': payload_proto,
3141 'bde_n_paths': 1,
3142 'bde_paths': [{'next_hop': next_hop,
3143 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003144 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003145 'rpf_id': next_hop_rpf_id,
3146 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003147 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003148 'bde_is_add': is_add})
3149
3150 def bier_disp_entry_dump(self, bdti):
3151 return self.api(
3152 self.papi.bier_disp_entry_dump,
3153 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003154
3155 def add_node_next(self, node_name, next_name):
3156 """ Set the next node for a given node request
3157
3158 :param node_name:
3159 :param next_name:
3160 """
3161 return self.api(self.papi.add_node_next,
3162 {'node_name': node_name,
3163 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003164
3165 def session_enable_disable(self, is_enabled):
3166 return self.api(
3167 self.papi.session_enable_disable,
3168 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003169
3170 def ipsec_spd_add_del(self, spd_id, is_add=1):
3171 """ SPD add/del - Wrapper to add or del ipsec SPD
3172 Sample CLI : 'ipsec spd add 1'
3173
3174 :param spd_id - SPD ID to be created in the vpp . mandatory
3175 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3176 optional
3177 :returns: reply from the API
3178 """
3179 return self.api(
3180 self.papi.ipsec_spd_add_del, {
3181 'spd_id': spd_id, 'is_add': is_add})
3182
3183 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3184 """ IPSEC interface SPD add/del - \
3185 Wrapper to associate/disassociate SPD to interface in VPP
3186 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3187
3188 :param spd_id - SPD ID to associate with the interface . mandatory
3189 :param sw_if_index - Interface Index which needs to ipsec \
3190 association mandatory
3191 :param is_add - add(1) or del(0) association with interface \
3192 (Default 1 - add) . optional
3193 :returns: reply from the API
3194 """
3195 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003196 self.papi.ipsec_interface_add_del_spd,
3197 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003198
3199 def ipsec_sad_add_del_entry(self,
3200 sad_id,
3201 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003202 integrity_algorithm,
3203 integrity_key,
3204 crypto_algorithm,
3205 crypto_key,
3206 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003207 tunnel_src_address='',
3208 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003209 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003210 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003211 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003212 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003213 :param sad_id: security association ID
3214 :param spi: security param index of the SA in decimal
3215 :param integrity_algorithm:
3216 :param integrity_key:
3217 :param crypto_algorithm:
3218 :param crypto_key:
3219 :param protocol: AH(0) or ESP(1) protocol
3220 :param tunnel_src_address: tunnel mode outer src address
3221 :param tunnel_dst_address: tunnel mode outer dst address
3222 :param is_add:
3223 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003224 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3225 crypto and ipsec algorithms
3226 """
3227 return self.api(
3228 self.papi.ipsec_sad_add_del_entry,
3229 {'sad_id': sad_id,
3230 'spi': spi,
3231 'tunnel_src_address': tunnel_src_address,
3232 'tunnel_dst_address': tunnel_dst_address,
3233 'protocol': protocol,
3234 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003235 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003236 'integrity_key': integrity_key,
3237 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003238 'crypto_key_length': len(crypto_key) if crypto_key is not None
3239 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003240 'crypto_key': crypto_key,
3241 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003242 'is_tunnel': is_tunnel,
3243 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003244
3245 def ipsec_spd_add_del_entry(self,
3246 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003247 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003248 local_address_start,
3249 local_address_stop,
3250 remote_address_start,
3251 remote_address_stop,
3252 local_port_start=0,
3253 local_port_stop=65535,
3254 remote_port_start=0,
3255 remote_port_stop=65535,
3256 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003257 policy=0,
3258 priority=100,
3259 is_outbound=1,
3260 is_add=1,
3261 is_ip_any=0):
3262 """ IPSEC policy SPD add/del -
3263 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003264 :param spd_id: SPD ID for the policy
3265 :param local_address_start: local-ip-range start address
3266 :param local_address_stop : local-ip-range stop address
3267 :param remote_address_start: remote-ip-range start address
3268 :param remote_address_stop : remote-ip-range stop address
3269 :param local_port_start: (Default value = 0)
3270 :param local_port_stop: (Default value = 65535)
3271 :param remote_port_start: (Default value = 0)
3272 :param remote_port_stop: (Default value = 65535)
3273 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3274 :param sa_id: Security Association ID for mapping it to SPD
3275 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3276 (Default value = 0)
3277 :param priority: value for the spd action (Default value = 100)
3278 :param is_outbound: flag for inbound(0) or outbound(1)
3279 (Default value = 1)
3280 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003281 """
3282 return self.api(
3283 self.papi.ipsec_spd_add_del_entry,
3284 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003285 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003286 'local_address_start': local_address_start,
3287 'local_address_stop': local_address_stop,
3288 'remote_address_start': remote_address_start,
3289 'remote_address_stop': remote_address_stop,
3290 'local_port_start': local_port_start,
3291 'local_port_stop': local_port_stop,
3292 'remote_port_start': remote_port_start,
3293 'remote_port_stop': remote_port_stop,
3294 'is_add': is_add,
3295 'protocol': protocol,
3296 'policy': policy,
3297 'priority': priority,
3298 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003299 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003300
Klement Sekera31da2e32018-06-24 22:49:55 +02003301 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3302 remote_spi, crypto_alg, local_crypto_key,
3303 remote_crypto_key, integ_alg, local_integ_key,
3304 remote_integ_key, is_add=1, esn=0,
3305 anti_replay=1, renumber=0, show_instance=0):
3306 return self.api(
3307 self.papi.ipsec_tunnel_if_add_del,
3308 {'local_ip': local_ip, 'remote_ip': remote_ip,
3309 'local_spi': local_spi, 'remote_spi': remote_spi,
3310 'crypto_alg': crypto_alg,
3311 'local_crypto_key_len': len(local_crypto_key),
3312 'local_crypto_key': local_crypto_key,
3313 'remote_crypto_key_len': len(remote_crypto_key),
3314 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3315 'local_integ_key_len': len(local_integ_key),
3316 'local_integ_key': local_integ_key,
3317 'remote_integ_key_len': len(remote_integ_key),
3318 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3319 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3320 'show_instance': show_instance
3321 })
3322
Florin Corasb795bd02017-12-14 11:30:48 -08003323 def app_namespace_add(self,
3324 namespace_id,
3325 ip4_fib_id=0,
3326 ip6_fib_id=0,
3327 sw_if_index=0xFFFFFFFF,
3328 secret=0):
3329 return self.api(
3330 self.papi.app_namespace_add_del,
3331 {'secret': secret,
3332 'sw_if_index': sw_if_index,
3333 'ip4_fib_id': ip4_fib_id,
3334 'ip6_fib_id': ip6_fib_id,
3335 'namespace_id': namespace_id,
3336 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003337
3338 def punt_socket_register(self, l4_port, pathname, header_version=1,
3339 is_ip4=1, l4_protocol=0x11):
3340 """ Punt to socket """
3341 return self.api(self.papi.punt_socket_register,
3342 {'is_ip4': is_ip4,
3343 'l4_protocol': l4_protocol,
3344 'l4_port': l4_port,
3345 'pathname': pathname,
3346 'header_version': header_version})
3347
3348 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3349 expire_walk_interval_ms, is_ip6=0):
3350 """ Set IP reassembly parameters """
3351 return self.api(self.papi.ip_reassembly_set,
3352 {'is_ip6': is_ip6,
3353 'timeout_ms': timeout_ms,
3354 'expire_walk_interval_ms': expire_walk_interval_ms,
3355 'max_reassemblies': max_reassemblies})
3356
3357 def ip_reassembly_get(self, is_ip6=0):
3358 """ Get IP reassembly parameters """
3359 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003360
Klement Sekera4c533132018-02-22 11:41:12 +01003361 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3362 enable_ip6=False):
3363 """ Enable/disable IP reassembly """
3364 return self.api(self.papi.ip_reassembly_enable_disable,
3365 {'sw_if_index': sw_if_index,
3366 'enable_ip4': 1 if enable_ip4 else 0,
3367 'enable_ip6': 1 if enable_ip6 else 0,
3368 })
3369
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003370 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3371 """ GBP endpoint Add/Del """
3372 return self.api(self.papi.gbp_endpoint_add_del,
3373 {'is_add': is_add,
3374 'endpoint': {
3375 'is_ip6': is_ip6,
3376 'sw_if_index': sw_if_index,
3377 'address': addr,
3378 'epg_id': epg}})
3379
3380 def gbp_endpoint_dump(self):
3381 """ GBP endpoint Dump """
3382 return self.api(self.papi.gbp_endpoint_dump, {})
3383
Neale Ranns25b04942018-04-04 09:34:50 -07003384 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3385 ip4_rd,
3386 ip6_rd,
3387 uplink_sw_if_index):
3388 """ GBP endpoint group Add/Del """
3389 return self.api(self.papi.gbp_endpoint_group_add_del,
3390 {'is_add': is_add,
3391 'epg': {
3392 'uplink_sw_if_index': uplink_sw_if_index,
3393 'bd_id': bd,
3394 'ip4_table_id': ip4_rd,
3395 'ip6_table_id': ip6_rd,
3396 'epg_id': epg}})
3397
3398 def gbp_endpoint_group_dump(self):
3399 """ GBP endpoint group Dump """
3400 return self.api(self.papi.gbp_endpoint_group_dump, {})
3401
3402 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3403 """ GBP recirc Add/Del """
3404 return self.api(self.papi.gbp_recirc_add_del,
3405 {'is_add': is_add,
3406 'recirc': {
3407 'is_ext': is_ext,
3408 'sw_if_index': sw_if_index,
3409 'epg_id': epg}})
3410
3411 def gbp_recirc_dump(self):
3412 """ GBP recirc Dump """
3413 return self.api(self.papi.gbp_recirc_dump, {})
3414
3415 def gbp_subnet_add_del(self, is_add, table_id,
3416 is_internal,
3417 addr, addr_len,
3418 sw_if_index=0xffffffff,
3419 epg_id=0xffffffff,
3420 is_ip6=False):
3421 """ GBP Subnet Add/Del """
3422 return self.api(self.papi.gbp_subnet_add_del,
3423 {'is_add': is_add,
3424 'subnet': {
3425 'is_internal': is_internal,
3426 'is_ip6': is_ip6,
3427 'sw_if_index': sw_if_index,
3428 'epg_id': epg_id,
3429 'address': addr,
3430 'address_length': addr_len,
3431 'table_id': table_id}})
3432
3433 def gbp_subnet_dump(self):
3434 """ GBP Subnet Dump """
3435 return self.api(self.papi.gbp_subnet_dump, {})
3436
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003437 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3438 """ GBP contract Add/Del """
3439 return self.api(self.papi.gbp_contract_add_del,
3440 {'is_add': is_add,
3441 'contract': {
3442 'acl_index': acl_index,
3443 'src_epg': src_epg,
3444 'dst_epg': dst_epg}})
3445
3446 def gbp_contract_dump(self):
3447 """ GBP contract Dump """
3448 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003449
Neale Ranns61502112018-08-22 00:21:14 -07003450 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3451 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003452 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003453 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003454 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003455 {'ip4_table_id': ip4_table_id,
3456 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003457 'ip6_prefix': ip6_prefix,
3458 'ip6_prefix_len': ip6_prefix_len,
3459 'ip4_prefix': ip4_prefix,
3460 'ip4_prefix_len': ip4_prefix_len,
3461 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003462 'security_check': security_check})
3463
Ole Troan298c6952018-03-08 12:30:43 +01003464 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003465 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003466 return self.api(self.papi.ipip_6rd_del_tunnel,
3467 {'sw_if_index': sw_if_index})
3468
3469 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003470 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003471 """ IPIP tunnel Add/Del """
3472 return self.api(self.papi.ipip_add_tunnel,
3473 {'is_ipv6': is_ipv6,
3474 'instance': instance,
3475 'src_address': src_address,
3476 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003477 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003478 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003479
3480 def ipip_del_tunnel(self, sw_if_index):
3481 """ IPIP tunnel Delete """
3482 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003483 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003484
3485 def qos_egress_map_update(self, id, outputs):
3486 """ QOS egress map update """
3487 return self.api(self.papi.qos_egress_map_update,
3488 {'map_id': id,
3489 'rows': outputs})
3490
3491 def qos_egress_map_delete(self, id):
3492 """ QOS egress map delete """
3493 return self.api(self.papi.qos_egress_map_delete,
3494 {'map_id': id})
3495
3496 def qos_mark_enable_disable(self, sw_if_index,
3497 output_source,
3498 map_id,
3499 enable):
3500 """ QOS Mark Enable/Disable """
3501 return self.api(self.papi.qos_mark_enable_disable,
3502 {'map_id': map_id,
3503 'sw_if_index': sw_if_index,
3504 'output_source': output_source,
3505 'enable': enable})
3506
3507 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3508 """ IP QoS recording Enble/Disable """
3509 return self.api(self.papi.qos_record_enable_disable,
3510 {'sw_if_index': sw_if_index,
3511 'input_source': input_source,
3512 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003513
Neale Ranns947ea622018-06-07 23:48:20 -07003514 def igmp_enable_disable(self, sw_if_index, enable, host):
3515 """ Enable/disable IGMP on a given interface """
3516 return self.api(self.papi.igmp_enable_disable,
3517 {'enable': enable,
3518 'mode': host,
3519 'sw_if_index': sw_if_index})
3520
3521 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003522 """ Listen for new (S,G) on specified interface
3523
3524 :param enable: add/del
3525 :param sw_if_index: interface sw index
3526 :param saddr: source ip4 addr
3527 :param gaddr: group ip4 addr
3528 """
3529 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003530 {
3531 'group':
3532 {
3533 'filter': filter,
3534 'sw_if_index': sw_if_index,
3535 'n_srcs': len(saddrs),
3536 'saddrs': saddrs,
3537 'gaddr':
3538 {
3539 'address': gaddr
3540 }
3541 }
3542 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003543
3544 def igmp_dump(self, sw_if_index=None):
3545 """ Dump all (S,G) interface configurations """
3546 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003547 sw_if_index = 0xffffffff
3548 return self.api(self.papi.igmp_dump,
3549 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003550
3551 def igmp_clear_interface(self, sw_if_index):
3552 """ Remove all (S,G)s from specified interface
3553 doesn't send IGMP report!
3554 """
3555 return self.api(
3556 self.papi.igmp_clear_interface, {
3557 'sw_if_index': sw_if_index})
3558
3559 def want_igmp_events(self, enable=1):
3560 return self.api(self.papi.want_igmp_events, {'enable': enable,
3561 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003562
3563 def bond_create(
3564 self,
3565 mode,
3566 lb,
3567 use_custom_mac,
3568 mac_address=''):
3569 """
3570 :param mode: mode
3571 :param lb: load balance
3572 :param use_custom_mac: use custom mac
3573 :param mac_address: mac address
3574 """
3575 return self.api(
3576 self.papi.bond_create,
3577 {'mode': mode,
3578 'lb': lb,
3579 'use_custom_mac': use_custom_mac,
3580 'mac_address': mac_address
3581 })
3582
3583 def bond_delete(
3584 self,
3585 sw_if_index):
3586 """
3587 :param sw_if_index: interface the operation is applied to
3588 """
3589 return self.api(self.papi.bond_delete,
3590 {'sw_if_index': sw_if_index})
3591
3592 def bond_enslave(
3593 self,
3594 sw_if_index,
3595 bond_sw_if_index,
3596 is_passive,
3597 is_long_timeout):
3598 """
3599 :param sw_if_index: slave sw_if_index
3600 :param bond_sw_if_index: bond sw_if_index
3601 :param is_passive: is passive lacp speaker
3602 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3603 """
3604 return self.api(
3605 self.papi.bond_enslave,
3606 {'sw_if_index': sw_if_index,
3607 'bond_sw_if_index': bond_sw_if_index,
3608 'is_passive': is_passive,
3609 'is_long_timeout': is_long_timeout
3610 })
3611
3612 def bond_detach_slave(
3613 self,
3614 sw_if_index):
3615 """
3616 :param sw_if_index: slave interface the operation is applied to
3617 """
3618 return self.api(self.papi.bond_detach_slave,
3619 {'sw_if_index': sw_if_index})
3620
3621 def sw_interface_slave_dump(
3622 self,
3623 sw_if_index):
3624 """
3625 :param sw_if_index: bond sw_if_index
3626 """
3627 return self.api(self.papi.sw_interface_slave_dump,
3628 {'sw_if_index': sw_if_index})
3629
3630 def sw_interface_bond_dump(
3631 self):
3632 """
3633
3634 """
3635 return self.api(self.papi.sw_interface_bond_dump,
3636 {})
Stevene8fa6202017-08-30 14:36:45 -07003637
3638 def create_vhost_user_if(
3639 self,
3640 is_server,
3641 sock_filename,
3642 renumber,
3643 custom_dev_instance,
3644 use_custom_mac,
3645 mac_address,
3646 tag=''):
3647 """
3648 :param is_server: is server
3649 :param sock_filename: socket name
3650 :param renumber: renumber
3651 :param custom_dev_instance: custom dev instance
3652 :param use_custom_mac: use custom mac
3653 :param mac_address: mac address
3654 :param tag: tag (default ''
3655 """
3656 return self.api(
3657 self.papi.create_vhost_user_if,
3658 {'is_server': is_server,
3659 'sock_filename': sock_filename,
3660 'renumber': renumber,
3661 'custom_dev_instance': custom_dev_instance,
3662 'use_custom_mac': use_custom_mac,
3663 'mac_address': mac_address,
3664 'tag': tag
3665 })
3666
3667 def delete_vhost_user_if(
3668 self,
3669 sw_if_index):
3670 """
3671 :param sw_if_index: interface the operation is applied to
3672 """
3673 return self.api(self.papi.delete_vhost_user_if,
3674 {'sw_if_index': sw_if_index, })
3675
3676 def sw_interface_vhost_user_dump(
3677 self):
3678 """
3679
3680 """
3681 return self.api(self.papi.sw_interface_vhost_user_dump,
3682 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003683
3684 def abf_policy_add_del(self, is_add, policy):
3685 return self.api(
3686 self.papi.abf_policy_add_del,
3687 {'is_add': is_add,
3688 'policy': policy})
3689
3690 def abf_itf_attach_add_del(self, is_add, attach):
3691 return self.api(
3692 self.papi.abf_itf_attach_add_del,
3693 {'is_add': is_add,
3694 'attach': attach})
3695
3696 def abf_policy_dump(self):
3697 return self.api(
3698 self.papi.abf_policy_dump, {})
3699
3700 def abf_itf_attach_dump(self):
3701 return self.api(
3702 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003703
3704 def pipe_create(self, is_specified, user_instance):
3705 return self.api(self.papi.pipe_create,
3706 {'is_specified': is_specified,
3707 'user_instance': user_instance})
3708
3709 def pipe_delete(self, parent_sw_if_index):
3710 return self.api(self.papi.pipe_delete,
3711 {'parent_sw_if_index': parent_sw_if_index})
3712
3713 def pipe_dump(self):
3714 return self.api(self.papi.pipe_dump, {})