blob: 9a3a9741ed98e69ff49724b890666c1d63c3b7c4 [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 Fabian5d28c7a2018-09-04 03:55:45 -07001800 def nat_set_addr_and_port_alloc_alg(
1801 self,
1802 alg=0,
1803 psid_offset=0,
1804 psid_length=0,
1805 psid=0,
1806 start_port=0,
1807 end_port=0):
1808 """Set address and port assignment algorithm
1809
1810 :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range
1811 :param psid_offset: number of offset bits (valid only for MAP-E alg)
1812 :param psid_length: length of PSID (valid only for MAP-E alg)
1813 :param psid: Port Set Identifier value (valid only for MAP-E alg)
1814 :param start_port: beginning of the port range
1815 :param end_port: end of the port range
1816 """
1817 return self.api(
1818 self.papi.nat_set_addr_and_port_alloc_alg,
1819 {'alg': alg,
1820 'psid_offset': psid_offset,
1821 'psid_length': psid_length,
1822 'psid': psid,
1823 'start_port': start_port,
1824 'end_port': end_port})
1825
1826 def nat_get_addr_and_port_alloc_alg(self):
1827 """Get address and port assignment algorithm"""
1828 return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {})
1829
Matus Fabian2ba92e32017-08-21 07:05:03 -07001830 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001831 self,
1832 out_addr,
1833 out_port,
1834 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001835 ext_port):
1836 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001837
1838 :param out_addr - outside IP address
1839 :param out_port - outside port
1840 :param ext_addr - external host IP address
1841 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001842 """
1843 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001844 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001845 {'out_addr': out_addr,
1846 'out_port': out_port,
1847 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001848 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001849
Matus Fabian2ba92e32017-08-21 07:05:03 -07001850 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001851 self,
1852 in_addr,
1853 in_port,
1854 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001855 ext_port):
1856 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001857
1858 :param in_addr - inside IP address
1859 :param in_port - inside port
1860 :param ext_addr - external host IP address
1861 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001862 """
1863 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001864 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001865 {'in_addr': in_addr,
1866 'in_port': in_port,
1867 'ext_addr': ext_addr,
1868 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001869 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001870
Matus Fabian2ba92e32017-08-21 07:05:03 -07001871 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001872 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001873 user_addr):
1874 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001875
1876 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001877 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001878 """
1879 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001880 self.papi.nat_det_session_dump,
1881 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001882 'user_addr': user_addr})
1883
Matus Fabian06596c52017-06-06 04:53:28 -07001884 def nat64_add_del_pool_addr_range(
1885 self,
1886 start_addr,
1887 end_addr,
1888 vrf_id=0xFFFFFFFF,
1889 is_add=1):
1890 """Add/del address range to NAT64 pool
1891
1892 :param start_addr: First IP address
1893 :param end_addr: Last IP address
1894 :param vrf_id: VRF id for the address range
1895 :param is_add: 1 if add, 0 if delete (Default value = 1)
1896 """
1897 return self.api(
1898 self.papi.nat64_add_del_pool_addr_range,
1899 {'start_addr': start_addr,
1900 'end_addr': end_addr,
1901 'vrf_id': vrf_id,
1902 'is_add': is_add})
1903
1904 def nat64_pool_addr_dump(self):
1905 """Dump NAT64 pool addresses
1906 :return: Dictionary of NAT64 pool addresses
1907 """
1908 return self.api(self.papi.nat64_pool_addr_dump, {})
1909
1910 def nat64_add_del_interface(
1911 self,
1912 sw_if_index,
1913 is_inside=1,
1914 is_add=1):
1915 """Enable/disable NAT64 feature on the interface
1916 :param sw_if_index: Index of the interface
1917 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1918 :param is_add: 1 if add, 0 if delete (Default value = 1)
1919 """
1920 return self.api(
1921 self.papi.nat64_add_del_interface,
1922 {'sw_if_index': sw_if_index,
1923 'is_inside': is_inside,
1924 'is_add': is_add})
1925
1926 def nat64_interface_dump(self):
1927 """Dump interfaces with NAT64 feature
1928 :return: Dictionary of interfaces with NAT64 feature
1929 """
1930 return self.api(self.papi.nat64_interface_dump, {})
1931
1932 def nat64_add_del_static_bib(
1933 self,
1934 in_ip,
1935 out_ip,
1936 in_port,
1937 out_port,
1938 protocol,
1939 vrf_id=0,
1940 is_add=1):
1941 """Add/delete S-NAT static BIB entry
1942
1943 :param in_ip: Inside IPv6 address
1944 :param out_ip: Outside IPv4 address
1945 :param in_port: Inside port number
1946 :param out_port: Outside port number
1947 :param protocol: IP protocol
1948 :param vrf_id: VRF ID (Default value = 0)
1949 :param is_add: 1 if add, 0 if delete (Default value = 1)
1950 """
1951 return self.api(
1952 self.papi.nat64_add_del_static_bib,
1953 {'i_addr': in_ip,
1954 'o_addr': out_ip,
1955 'i_port': in_port,
1956 'o_port': out_port,
1957 'vrf_id': vrf_id,
1958 'proto': protocol,
1959 'is_add': is_add})
1960
Matus Fabianab9a59c2017-08-16 05:37:36 -07001961 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001962 """Dump NAT64 BIB
1963
Matus Fabianab9a59c2017-08-16 05:37:36 -07001964 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001965 :returns: Dictionary of NAT64 BIB entries
1966 """
1967 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1968
1969 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1970 tcp_incoming_syn=6):
1971 """Set values of timeouts for NAT64 (in seconds)
1972
Matus Fabian428dc912017-06-21 06:15:18 -07001973 :param udpi: UDP timeout (Default value = 300)
1974 :param icmp: ICMP timeout (Default value = 60)
1975 :param tcp_trans: TCP transitory timeout (Default value = 240)
1976 :param tcp_est: TCP established timeout (Default value = 7440)
1977 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001978 """
1979 return self.api(
1980 self.papi.nat64_set_timeouts,
1981 {'udp': udp,
1982 'icmp': icmp,
1983 'tcp_trans': tcp_trans,
1984 'tcp_est': tcp_est,
1985 'tcp_incoming_syn': tcp_incoming_syn})
1986
1987 def nat64_get_timeouts(self):
1988 """Get values of timeouts for NAT64
1989
1990 :return: Timeouts for NAT64 (in seconds)
1991 """
1992 return self.api(self.papi.nat64_get_timeouts, {})
1993
Matus Fabianab9a59c2017-08-16 05:37:36 -07001994 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001995 """Dump NAT64 session table
1996
Matus Fabianab9a59c2017-08-16 05:37:36 -07001997 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001998 :returns: Dictionary of NAT64 sesstion table entries
1999 """
2000 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
2001
Matus Fabian428dc912017-06-21 06:15:18 -07002002 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
2003 """Add/del NAT64 prefix
2004
2005 :param prefix: NAT64 prefix
2006 :param plen: NAT64 prefix length
2007 :param vrf_id: VRF id of tenant (Default 0)
2008 :param is_add: 1 if add, 0 if delete (Default value = 1)
2009 """
2010 return self.api(
2011 self.papi.nat64_add_del_prefix,
2012 {'prefix': prefix,
2013 'prefix_len': plen,
2014 'vrf_id': vrf_id,
2015 'is_add': is_add})
2016
2017 def nat64_prefix_dump(self):
2018 """Dump NAT64 prefix
2019
2020 :returns: Dictionary of NAT64 prefixes
2021 """
2022 return self.api(self.papi.nat64_prefix_dump, {})
2023
Matus Fabian0938dcf2017-11-08 01:59:38 -08002024 def nat64_add_interface_addr(
2025 self,
2026 sw_if_index,
2027 is_add=1):
2028 """Add/del NAT64 address from interface
2029
2030 :param sw_if_index: Software index of the interface
2031 :param is_add: 1 if add, 0 if delete (Default value = 1)
2032 """
2033 return self.api(self.papi.nat64_add_del_interface_addr,
2034 {'is_add': is_add, 'sw_if_index': sw_if_index})
2035
Matus Fabian8ebe6252017-11-06 05:04:53 -08002036 def dslite_set_aftr_addr(self, ip6, ip4):
2037 """Set DS-Lite AFTR addresses
2038
2039 :param ip4: IPv4 address
2040 :param ip6: IPv6 address
2041 """
2042 return self.api(
2043 self.papi.dslite_set_aftr_addr,
2044 {'ip4_addr': ip4,
2045 'ip6_addr': ip6})
2046
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002047 def dslite_set_b4_addr(self, ip6, ip4):
2048 """Set DS-Lite B4 IPv6 address
2049
2050 :param ip4: IPv4 address
2051 :param ip6: IPv6 address
2052 """
2053 return self.api(
2054 self.papi.dslite_set_b4_addr,
2055 {'ip4_addr': ip4,
2056 'ip6_addr': ip6})
2057
Matus Fabian8ebe6252017-11-06 05:04:53 -08002058 def dslite_add_del_pool_addr_range(
2059 self,
2060 start_addr,
2061 end_addr,
2062 is_add=1):
2063 """Add/del address range to DS-Lite pool
2064
2065 :param start_addr: First IP address
2066 :param end_addr: Last IP address
2067 :param is_add: 1 if add, 0 if delete (Default value = 1)
2068 """
2069 return self.api(
2070 self.papi.dslite_add_del_pool_addr_range,
2071 {'start_addr': start_addr,
2072 'end_addr': end_addr,
2073 'is_add': is_add})
2074
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002075 def nat66_add_del_interface(
2076 self,
2077 sw_if_index,
2078 is_inside=1,
2079 is_add=1):
2080 """Enable/disable NAT66 feature on the interface
2081 :param sw_if_index: Index of the interface
2082 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2083 :param is_add: 1 if add, 0 if delete (Default value = 1)
2084 """
2085 return self.api(
2086 self.papi.nat66_add_del_interface,
2087 {'sw_if_index': sw_if_index,
2088 'is_inside': is_inside,
2089 'is_add': is_add})
2090
2091 def nat66_add_del_static_mapping(
2092 self,
2093 in_ip,
2094 out_ip,
2095 vrf_id=0,
2096 is_add=1):
2097 """Add/delete NAT66 static mapping
2098
2099 :param in_ip: Inside IPv6 address
2100 :param out_ip: Outside IPv6 address
2101 :param vrf_id: VRF ID (Default value = 0)
2102 :param is_add: 1 if add, 0 if delete (Default value = 1)
2103 """
2104 return self.api(
2105 self.papi.nat66_add_del_static_mapping,
2106 {'local_ip_address': in_ip,
2107 'external_ip_address': out_ip,
2108 'vrf_id': vrf_id,
2109 'is_add': is_add})
2110
2111 def nat66_interface_dump(self):
2112 """Dump interfaces with NAT66 feature
2113 :return: Dictionary of interfaces with NAT66 feature
2114 """
2115 return self.api(self.papi.nat66_interface_dump, {})
2116
2117 def nat66_static_mapping_dump(self):
2118 """Dump NAT66 static mappings
2119 :return: Dictionary of NAT66 static mappings
2120 """
2121 return self.api(self.papi.nat66_static_mapping_dump, {})
2122
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002123 def control_ping(self):
2124 self.api(self.papi.control_ping)
2125
2126 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002127 detect_mult, local_addr, peer_addr, is_ipv6=0,
2128 bfd_key_id=None, conf_key_id=None):
2129 if bfd_key_id is None:
2130 return self.api(self.papi.bfd_udp_add,
2131 {
2132 'sw_if_index': sw_if_index,
2133 'desired_min_tx': desired_min_tx,
2134 'required_min_rx': required_min_rx,
2135 'local_addr': local_addr,
2136 'peer_addr': peer_addr,
2137 'is_ipv6': is_ipv6,
2138 'detect_mult': detect_mult,
2139 })
2140 else:
2141 return self.api(self.papi.bfd_udp_add,
2142 {
2143 'sw_if_index': sw_if_index,
2144 'desired_min_tx': desired_min_tx,
2145 'required_min_rx': required_min_rx,
2146 'local_addr': local_addr,
2147 'peer_addr': peer_addr,
2148 'is_ipv6': is_ipv6,
2149 'detect_mult': detect_mult,
2150 'is_authenticated': 1,
2151 'bfd_key_id': bfd_key_id,
2152 'conf_key_id': conf_key_id,
2153 })
2154
Klement Sekeraa57a9702017-02-02 06:58:07 +01002155 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2156 detect_mult, local_addr, peer_addr, is_ipv6=0):
2157 return self.api(self.papi.bfd_udp_mod,
2158 {
2159 'sw_if_index': sw_if_index,
2160 'desired_min_tx': desired_min_tx,
2161 'required_min_rx': required_min_rx,
2162 'local_addr': local_addr,
2163 'peer_addr': peer_addr,
2164 'is_ipv6': is_ipv6,
2165 'detect_mult': detect_mult,
2166 })
2167
Klement Sekerab17dd962017-01-09 07:43:48 +01002168 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2169 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2170 is_delayed=False):
2171 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002172 {
2173 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002174 'local_addr': local_addr,
2175 'peer_addr': peer_addr,
2176 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002177 'is_delayed': 1 if is_delayed else 0,
2178 'bfd_key_id': bfd_key_id,
2179 'conf_key_id': conf_key_id,
2180 })
2181
2182 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2183 is_ipv6=0, is_delayed=False):
2184 return self.api(self.papi.bfd_udp_auth_deactivate,
2185 {
2186 'sw_if_index': sw_if_index,
2187 'local_addr': local_addr,
2188 'peer_addr': peer_addr,
2189 'is_ipv6': is_ipv6,
2190 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002191 })
2192
2193 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2194 return self.api(self.papi.bfd_udp_del,
2195 {
2196 'sw_if_index': sw_if_index,
2197 'local_addr': local_addr,
2198 'peer_addr': peer_addr,
2199 'is_ipv6': is_ipv6,
2200 })
2201
2202 def bfd_udp_session_dump(self):
2203 return self.api(self.papi.bfd_udp_session_dump, {})
2204
Klement Sekerab17dd962017-01-09 07:43:48 +01002205 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2206 peer_addr, is_ipv6=0):
2207 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002208 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002209 'sw_if_index': sw_if_index,
2210 'local_addr': local_addr,
2211 'peer_addr': peer_addr,
2212 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002213 })
2214
2215 def want_bfd_events(self, enable_disable=1):
2216 return self.api(self.papi.want_bfd_events, {
2217 'enable_disable': enable_disable,
2218 'pid': os.getpid(),
2219 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002220
Klement Sekerab17dd962017-01-09 07:43:48 +01002221 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2222 return self.api(self.papi.bfd_auth_set_key, {
2223 'conf_key_id': conf_key_id,
2224 'auth_type': auth_type,
2225 'key': key,
2226 'key_len': len(key),
2227 })
2228
2229 def bfd_auth_del_key(self, conf_key_id):
2230 return self.api(self.papi.bfd_auth_del_key, {
2231 'conf_key_id': conf_key_id,
2232 })
2233
2234 def bfd_auth_keys_dump(self):
2235 return self.api(self.papi.bfd_auth_keys_dump, {})
2236
Klement Sekera239790f2017-02-16 10:53:53 +01002237 def bfd_udp_set_echo_source(self, sw_if_index):
2238 return self.api(self.papi.bfd_udp_set_echo_source,
2239 {'sw_if_index': sw_if_index})
2240
Klement Sekera73884482017-02-23 09:26:30 +01002241 def bfd_udp_del_echo_source(self):
2242 return self.api(self.papi.bfd_udp_del_echo_source, {})
2243
Steve Shin7957d6e2016-12-19 09:24:50 -08002244 def classify_add_del_table(
2245 self,
2246 is_add,
2247 mask,
2248 match_n_vectors=1,
2249 table_index=0xFFFFFFFF,
2250 nbuckets=2,
2251 memory_size=2097152,
2252 skip_n_vectors=0,
2253 next_table_index=0xFFFFFFFF,
2254 miss_next_index=0xFFFFFFFF,
2255 current_data_flag=0,
2256 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002257 """
2258 :param is_add:
2259 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002260 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002261 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002262 :param nbuckets: (Default value = 2)
2263 :param memory_size: (Default value = 2097152)
2264 :param skip_n_vectors: (Default value = 0)
2265 :param next_table_index: (Default value = 0xFFFFFFFF)
2266 :param miss_next_index: (Default value = 0xFFFFFFFF)
2267 :param current_data_flag: (Default value = 0)
2268 :param current_data_offset: (Default value = 0)
2269 """
2270
Juraj Sloboda75282452018-06-12 14:20:49 +02002271 mask_len = ((len(mask) - 1) / 16 + 1) * 16
2272 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08002273 return self.api(
2274 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002275 {'is_add': is_add,
2276 'table_index': table_index,
2277 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002278 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002279 'skip_n_vectors': skip_n_vectors,
2280 'match_n_vectors': match_n_vectors,
2281 'next_table_index': next_table_index,
2282 'miss_next_index': miss_next_index,
2283 'current_data_flag': current_data_flag,
2284 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02002285 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002286 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002287
2288 def classify_add_del_session(
2289 self,
2290 is_add,
2291 table_index,
2292 match,
2293 opaque_index=0xFFFFFFFF,
2294 hit_next_index=0xFFFFFFFF,
2295 advance=0,
2296 action=0,
2297 metadata=0):
2298 """
2299 :param is_add:
2300 :param table_index:
2301 :param match:
2302 :param opaque_index: (Default value = 0xFFFFFFFF)
2303 :param hit_next_index: (Default value = 0xFFFFFFFF)
2304 :param advance: (Default value = 0)
2305 :param action: (Default value = 0)
2306 :param metadata: (Default value = 0)
2307 """
2308
Juraj Sloboda75282452018-06-12 14:20:49 +02002309 match_len = ((len(match) - 1) / 16 + 1) * 16
2310 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08002311 return self.api(
2312 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002313 {'is_add': is_add,
2314 'table_index': table_index,
2315 'hit_next_index': hit_next_index,
2316 'opaque_index': opaque_index,
2317 'advance': advance,
2318 'action': action,
2319 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02002320 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002321 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002322
2323 def input_acl_set_interface(
2324 self,
2325 is_add,
2326 sw_if_index,
2327 ip4_table_index=0xFFFFFFFF,
2328 ip6_table_index=0xFFFFFFFF,
2329 l2_table_index=0xFFFFFFFF):
2330 """
2331 :param is_add:
2332 :param sw_if_index:
2333 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2334 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2335 :param l2_table_index: (Default value = 0xFFFFFFFF)
2336 """
2337
2338 return self.api(
2339 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002340 {'sw_if_index': sw_if_index,
2341 'ip4_table_index': ip4_table_index,
2342 'ip6_table_index': ip6_table_index,
2343 'l2_table_index': l2_table_index,
2344 'is_add': is_add})
2345
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002346 def output_acl_set_interface(
2347 self,
2348 is_add,
2349 sw_if_index,
2350 ip4_table_index=0xFFFFFFFF,
2351 ip6_table_index=0xFFFFFFFF,
2352 l2_table_index=0xFFFFFFFF):
2353 """
2354 :param is_add:
2355 :param sw_if_index:
2356 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2357 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2358 :param l2_table_index: (Default value = 0xFFFFFFFF)
2359 """
2360
2361 return self.api(
2362 self.papi.output_acl_set_interface,
2363 {'sw_if_index': sw_if_index,
2364 'ip4_table_index': ip4_table_index,
2365 'ip6_table_index': ip6_table_index,
2366 'l2_table_index': l2_table_index,
2367 'is_add': is_add})
2368
Klement Sekera77fabdb2017-01-02 07:46:14 +01002369 def set_ipfix_exporter(
2370 self,
2371 collector_address,
2372 src_address,
2373 path_mtu,
2374 template_interval,
2375 vrf_id=0,
2376 collector_port=4739,
2377 udp_checksum=0):
2378 return self.api(
2379 self.papi.set_ipfix_exporter,
2380 {
2381 'collector_address': collector_address,
2382 'collector_port': collector_port,
2383 'src_address': src_address,
2384 'vrf_id': vrf_id,
2385 'path_mtu': path_mtu,
2386 'template_interval': template_interval,
2387 'udp_checksum': udp_checksum,
2388 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002389
2390 def dhcp_proxy_config(self,
2391 dhcp_server,
2392 dhcp_src_address,
2393 rx_table_id=0,
2394 server_table_id=0,
2395 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002396 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002397 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002398 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002399 {
2400 'rx_vrf_id': rx_table_id,
2401 'server_vrf_id': server_table_id,
2402 'is_ipv6': is_ipv6,
2403 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002404 'dhcp_server': dhcp_server,
2405 'dhcp_src_address': dhcp_src_address,
2406 })
2407
2408 def dhcp_proxy_set_vss(self,
2409 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002410 vss_type=255,
2411 vpn_ascii_id="",
2412 oui=0,
2413 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002414 is_add=1,
2415 is_ip6=0):
2416 return self.api(
2417 self.papi.dhcp_proxy_set_vss,
2418 {
2419 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002420 'vss_type': vss_type,
2421 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002422 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002423 'vpn_index': vpn_index,
2424 'is_add': is_add,
2425 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002426 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002427
Neale Rannsdaff1782018-05-16 04:12:18 -07002428 def dhcp_client_dump(self):
2429 return self.api(self.papi.dhcp_client_dump, {})
2430
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002431 def dhcp_client(self,
2432 sw_if_index,
2433 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002434 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002435 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002436 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002437 want_dhcp_events=0):
2438 return self.api(
2439 self.papi.dhcp_client_config,
2440 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002441 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002442 'client': {
2443 'sw_if_index': sw_if_index,
2444 'hostname': hostname,
2445 'id': client_id,
2446 'want_dhcp_event': want_dhcp_events,
2447 'set_broadcast_flag': set_broadcast_flag,
2448 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002449 })
2450
Neale Ranns32e1c012016-11-22 17:07:28 +00002451 def ip_mroute_add_del(self,
2452 src_address,
2453 grp_address,
2454 grp_address_length,
2455 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002456 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002457 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002458 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002459 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002460 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002461 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002462 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002463 is_add=1,
2464 is_ipv6=0,
2465 is_local=0):
2466 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002467 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002468 """
2469 return self.api(
2470 self.papi.ip_mroute_add_del,
2471 {'next_hop_sw_if_index': next_hop_sw_if_index,
2472 'entry_flags': e_flags,
2473 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002474 'table_id': table_id,
2475 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002476 'is_add': is_add,
2477 'is_ipv6': is_ipv6,
2478 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002479 'bier_imp': bier_imp,
2480 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002481 'grp_address_length': grp_address_length,
2482 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002483 'src_address': src_address,
2484 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002485
2486 def mfib_signal_dump(self):
2487 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002488
2489 def ip_mfib_dump(self):
2490 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002491
Neale Rannsd792d9c2017-10-21 10:53:20 -07002492 def ip6_mfib_dump(self):
2493 return self.api(self.papi.ip6_mfib_dump, {})
2494
Filip Tehlar770e89e2017-01-31 10:39:16 +01002495 def lisp_enable_disable(self, is_enabled):
2496 return self.api(
2497 self.papi.lisp_enable_disable,
2498 {
2499 'is_en': is_enabled,
2500 })
2501
2502 def lisp_locator_set(self,
2503 ls_name,
2504 is_add=1):
2505 return self.api(
2506 self.papi.lisp_add_del_locator_set,
2507 {
2508 'is_add': is_add,
2509 'locator_set_name': ls_name
2510 })
2511
2512 def lisp_locator_set_dump(self):
2513 return self.api(self.papi.lisp_locator_set_dump, {})
2514
2515 def lisp_locator(self,
2516 ls_name,
2517 sw_if_index,
2518 priority=1,
2519 weight=1,
2520 is_add=1):
2521 return self.api(
2522 self.papi.lisp_add_del_locator,
2523 {
2524 'is_add': is_add,
2525 'locator_set_name': ls_name,
2526 'sw_if_index': sw_if_index,
2527 'priority': priority,
2528 'weight': weight
2529 })
2530
2531 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2532 return self.api(
2533 self.papi.lisp_locator_dump,
2534 {
2535 'is_index_set': is_index_set,
2536 'ls_name': ls_name,
2537 'ls_index': ls_index,
2538 })
2539
2540 def lisp_local_mapping(self,
2541 ls_name,
2542 eid_type,
2543 eid,
2544 prefix_len,
2545 vni=0,
2546 key_id=0,
2547 key="",
2548 is_add=1):
2549 return self.api(
2550 self.papi.lisp_add_del_local_eid,
2551 {
2552 'locator_set_name': ls_name,
2553 'is_add': is_add,
2554 'eid_type': eid_type,
2555 'eid': eid,
2556 'prefix_len': prefix_len,
2557 'vni': vni,
2558 'key_id': key_id,
2559 'key': key
2560 })
2561
2562 def lisp_eid_table_dump(self,
2563 eid_set=0,
2564 prefix_length=0,
2565 vni=0,
2566 eid_type=0,
2567 eid=None,
2568 filter_opt=0):
2569 return self.api(
2570 self.papi.lisp_eid_table_dump,
2571 {
2572 'eid_set': eid_set,
2573 'prefix_length': prefix_length,
2574 'vni': vni,
2575 'eid_type': eid_type,
2576 'eid': eid,
2577 'filter': filter_opt,
2578 })
2579
2580 def lisp_remote_mapping(self,
2581 eid_type,
2582 eid,
2583 eid_prefix_len=0,
2584 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002585 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002586 rlocs_num=0,
2587 is_src_dst=0,
2588 is_add=1):
2589 return self.api(
2590 self.papi.lisp_add_del_remote_mapping,
2591 {
2592 'is_add': is_add,
2593 'eid_type': eid_type,
2594 'eid': eid,
2595 'eid_len': eid_prefix_len,
2596 'rloc_num': rlocs_num,
2597 'rlocs': rlocs,
2598 'vni': vni,
2599 'is_src_dst': is_src_dst,
2600 })
2601
2602 def lisp_adjacency(self,
2603 leid,
2604 reid,
2605 leid_len,
2606 reid_len,
2607 eid_type,
2608 is_add=1,
2609 vni=0):
2610 return self.api(
2611 self.papi.lisp_add_del_adjacency,
2612 {
2613 'is_add': is_add,
2614 'vni': vni,
2615 'eid_type': eid_type,
2616 'leid': leid,
2617 'reid': reid,
2618 'leid_len': leid_len,
2619 'reid_len': reid_len,
2620 })
2621
2622 def lisp_adjacencies_get(self, vni=0):
2623 return self.api(
2624 self.papi.lisp_adjacencies_get,
2625 {
2626 'vni': vni
2627 })
Neale Ranns80823802017-02-20 18:23:41 -08002628
2629 def map_add_domain(self,
2630 ip6_prefix,
2631 ip6_prefix_len,
2632 ip6_src,
2633 ip6_src_prefix_len,
2634 ip4_prefix,
2635 ip4_prefix_len,
2636 ea_bits_len=0,
2637 psid_offset=0,
2638 psid_length=0,
2639 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002640 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002641 mtu=1280):
2642 return self.api(
2643 self.papi.map_add_domain,
2644 {
2645 'ip6_prefix': ip6_prefix,
2646 'ip6_prefix_len': ip6_prefix_len,
2647 'ip4_prefix': ip4_prefix,
2648 'ip4_prefix_len': ip4_prefix_len,
2649 'ip6_src': ip6_src,
2650 'ip6_src_prefix_len': ip6_src_prefix_len,
2651 'ea_bits_len': ea_bits_len,
2652 'psid_offset': psid_offset,
2653 'psid_length': psid_length,
2654 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002655 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002656 'mtu': mtu
2657 })
Hongjun Nief486b12017-04-12 19:21:16 +08002658
2659 def gtpu_add_del_tunnel(
2660 self,
2661 src_addr,
2662 dst_addr,
2663 is_add=1,
2664 is_ipv6=0,
2665 mcast_sw_if_index=0xFFFFFFFF,
2666 encap_vrf_id=0,
2667 decap_next_index=0xFFFFFFFF,
2668 teid=0):
2669 """
2670
2671 :param is_add: (Default value = 1)
2672 :param is_ipv6: (Default value = 0)
2673 :param src_addr:
2674 :param dst_addr:
2675 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2676 :param encap_vrf_id: (Default value = 0)
2677 :param decap_next_index: (Default value = 0xFFFFFFFF)
2678 :param teid: (Default value = 0)
2679
2680 """
2681 return self.api(self.papi.gtpu_add_del_tunnel,
2682 {'is_add': is_add,
2683 'is_ipv6': is_ipv6,
2684 'src_address': src_addr,
2685 'dst_address': dst_addr,
2686 'mcast_sw_if_index': mcast_sw_if_index,
2687 'encap_vrf_id': encap_vrf_id,
2688 'decap_next_index': decap_next_index,
2689 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002690
2691 def vxlan_gpe_add_del_tunnel(
2692 self,
2693 src_addr,
2694 dst_addr,
2695 mcast_sw_if_index=0xFFFFFFFF,
2696 is_add=1,
2697 is_ipv6=0,
2698 encap_vrf_id=0,
2699 decap_vrf_id=0,
2700 protocol=3,
2701 vni=0):
2702 """
2703
2704 :param local:
2705 :param remote:
2706 :param is_add: (Default value = 1)
2707 :param is_ipv6: (Default value = 0)
2708 :param encap_vrf_id: (Default value = 0)
2709 :param decap_vrf_id: (Default value = 0)
2710 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2711 :param protocol: (Default value = 3)
2712 :param vni: (Default value = 0)
2713
2714 """
2715 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2716 {'is_add': is_add,
2717 'is_ipv6': is_ipv6,
2718 'local': src_addr,
2719 'remote': dst_addr,
2720 'mcast_sw_if_index': mcast_sw_if_index,
2721 'encap_vrf_id': encap_vrf_id,
2722 'decap_vrf_id': decap_vrf_id,
2723 'protocol': protocol,
2724 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002725
2726 def pppoe_add_del_session(
2727 self,
2728 client_ip,
2729 client_mac,
2730 session_id=0,
2731 is_add=1,
2732 is_ipv6=0,
2733 decap_vrf_id=0):
2734 """
2735
2736 :param is_add: (Default value = 1)
2737 :param is_ipv6: (Default value = 0)
2738 :param client_ip:
2739 :param session_id: (Default value = 0)
2740 :param client_mac:
2741 :param decap_vrf_id: (Default value = 0)
2742
2743 """
2744 return self.api(self.papi.pppoe_add_del_session,
2745 {'is_add': is_add,
2746 'is_ipv6': is_ipv6,
2747 'session_id': session_id,
2748 'client_ip': client_ip,
2749 'decap_vrf_id': decap_vrf_id,
2750 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002751
Neale Ranns7c922dc2018-08-30 06:12:27 -07002752 def sr_mpls_policy_add(self, bsid, weight, type, segments):
2753 return self.api(self.papi.sr_mpls_policy_add,
2754 {'bsid': bsid,
2755 'weight': weight,
2756 'type': type,
2757 'n_segments': len(segments),
2758 'segments': segments})
2759
2760 def sr_mpls_policy_del(self, bsid):
2761 return self.api(self.papi.sr_mpls_policy_del,
2762 {'bsid': bsid})
2763
Kris Michielsen91074432017-06-22 13:00:20 +02002764 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002765 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002766 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002767 nh_addr4,
2768 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002769 is_del=0,
2770 end_psp=0,
2771 sw_if_index=0xFFFFFFFF,
2772 vlan_index=0,
2773 fib_table=0,
2774 ):
2775 """ Add/del IPv6 SR local-SID.
2776
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002777 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002778 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2779 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002780 :param nh_addr4:
2781 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002782 :param is_del: (Default value = 0)
2783 :param end_psp: (Default value = 0)
2784 :param sw_if_index: (Default value = 0xFFFFFFFF)
2785 :param vlan_index: (Default value = 0)
2786 :param fib_table: (Default value = 0)
2787 """
2788 return self.api(
2789 self.papi.sr_localsid_add_del,
2790 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002791 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002792 'end_psp': end_psp,
2793 'behavior': behavior,
2794 'sw_if_index': sw_if_index,
2795 'vlan_index': vlan_index,
2796 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002797 'nh_addr4': nh_addr4,
2798 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002799 }
2800 )
2801
2802 def sr_policy_add(
2803 self,
2804 bsid_addr,
2805 weight=1,
2806 is_encap=1,
2807 type=0,
2808 fib_table=0,
2809 n_segments=0,
2810 segments=[]):
2811 """
2812 :param bsid_addr: bindingSID of the SR Policy
2813 :param weight: weight of the sid list. optional. (default: 1)
2814 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2815 (default: Encap)
2816 :param type: type/behavior of the SR policy. (default or spray) \
2817 (default: default)
2818 :param fib_table: VRF where to install the FIB entry for the BSID \
2819 (default: 0)
2820 :param n_segments: number of segments \
2821 (default: 0)
2822 :param segments: a vector of IPv6 address composing the segment list \
2823 (default: [])
2824 """
2825 return self.api(
2826 self.papi.sr_policy_add,
2827 {'bsid_addr': bsid_addr,
2828 'weight': weight,
2829 'is_encap': is_encap,
2830 'type': type,
2831 'fib_table': fib_table,
2832 'n_segments': n_segments,
2833 'segments': segments
2834 }
2835 )
2836
2837 def sr_policy_del(
2838 self,
2839 bsid_addr,
2840 sr_policy_index=0):
2841 """
2842 :param bsid: bindingSID of the SR Policy
2843 :param sr_policy_index: index of the sr policy (default: 0)
2844 """
2845 return self.api(
2846 self.papi.sr_policy_del,
2847 {'bsid_addr': bsid_addr,
2848 'sr_policy_index': sr_policy_index
2849 })
2850
2851 def sr_steering_add_del(
2852 self,
2853 is_del,
2854 bsid_addr,
2855 sr_policy_index,
2856 table_id,
2857 prefix_addr,
2858 mask_width,
2859 sw_if_index,
2860 traffic_type):
2861 """
2862 Steer traffic L2 and L3 traffic through a given SR policy
2863
2864 :param is_del: delete or add
2865 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2866 :param sr_policy: is the index of the SR Policy (alt to bsid)
2867 :param table_id: is the VRF where to install the FIB entry for the BSID
2868 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2869 :param mask_width: is the mask for L3 traffic type
2870 :param sw_if_index: is the incoming interface for L2 traffic
2871 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2872 """
2873 return self.api(
2874 self.papi.sr_steering_add_del,
2875 {'is_del': is_del,
2876 'bsid_addr': bsid_addr,
2877 'sr_policy_index': sr_policy_index,
2878 'table_id': table_id,
2879 'prefix_addr': prefix_addr,
2880 'mask_width': mask_width,
2881 'sw_if_index': sw_if_index,
2882 'traffic_type': traffic_type
2883 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002884
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002885 def acl_add_replace(self, acl_index, r, tag='',
2886 expected_retval=0):
2887 """Add/replace an ACL
2888 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2889 :param acl_rule r: ACL rules array.
2890 :param str tag: symbolic tag (description) for this ACL.
2891 :param int count: number of rules.
2892 """
2893 return self.api(self.papi.acl_add_replace,
2894 {'acl_index': acl_index,
2895 'r': r,
2896 'count': len(r),
2897 'tag': tag},
2898 expected_retval=expected_retval)
2899
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002900 def acl_del(self, acl_index, expected_retval=0):
2901 """
2902
2903 :param acl_index:
2904 :return:
2905 """
2906 return self.api(self.papi.acl_del,
2907 {'acl_index': acl_index},
2908 expected_retval=expected_retval)
2909
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002910 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2911 expected_retval=0):
2912 return self.api(self.papi.acl_interface_set_acl_list,
2913 {'sw_if_index': sw_if_index,
2914 'count': len(acls),
2915 'n_input': n_input,
2916 'acls': acls},
2917 expected_retval=expected_retval)
2918
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002919 def acl_interface_set_etype_whitelist(self, sw_if_index,
2920 n_input, whitelist,
2921 expected_retval=0):
2922 return self.api(self.papi.acl_interface_set_etype_whitelist,
2923 {'sw_if_index': sw_if_index,
2924 'count': len(whitelist),
2925 'n_input': n_input,
2926 'whitelist': whitelist},
2927 expected_retval=expected_retval)
2928
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002929 def acl_interface_add_del(self,
2930 sw_if_index,
2931 acl_index,
2932 is_add=1):
2933 """ Add/Delete ACL to/from interface
2934
2935 :param sw_if_index:
2936 :param acl_index:
2937 :param is_add: (Default value = 1)
2938 """
2939
2940 return self.api(self.papi.acl_interface_add_del,
2941 {'is_add': is_add,
2942 'is_input': 1,
2943 'sw_if_index': sw_if_index,
2944 'acl_index': acl_index})
2945
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002946 def acl_dump(self, acl_index, expected_retval=0):
2947 return self.api(self.papi.acl_dump,
2948 {'acl_index': acl_index},
2949 expected_retval=expected_retval)
2950
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002951 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2952 expected_retval=0):
2953 return self.api(self.papi.acl_interface_list_dump,
2954 {'sw_if_index': sw_if_index},
2955 expected_retval=expected_retval)
2956
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002957 def macip_acl_add(self, rules, tag=""):
2958 """ Add MACIP acl
2959
2960 :param rules: list of rules for given acl
2961 :param tag: acl tag
2962 """
2963
2964 return self.api(self.papi.macip_acl_add,
2965 {'r': rules,
2966 'count': len(rules),
2967 'tag': tag})
2968
Pavel Kotucek932f7412017-09-07 14:44:52 +02002969 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2970 """ Add MACIP acl
2971
2972 :param rules: list of rules for given acl
2973 :param tag: acl tag
2974 """
2975
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002976 return self.api(self.papi.macip_acl_add_replace,
2977 {'acl_index': acl_index,
2978 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002979 'count': len(rules),
2980 'tag': tag})
2981
2982 def macip_acl_del(self, acl_index):
2983 """
2984
2985 :param acl_index:
2986 :return:
2987 """
2988 return self.api(self.papi.macip_acl_del,
2989 {'acl_index': acl_index})
2990
2991 def macip_acl_interface_add_del(self,
2992 sw_if_index,
2993 acl_index,
2994 is_add=1):
2995 """ Add MACIP acl to interface
2996
2997 :param sw_if_index:
2998 :param acl_index:
2999 :param is_add: (Default value = 1)
3000 """
3001
3002 return self.api(self.papi.macip_acl_interface_add_del,
3003 {'is_add': is_add,
3004 'sw_if_index': sw_if_index,
3005 'acl_index': acl_index})
3006
3007 def macip_acl_interface_get(self):
3008 """ Return interface acls dump
3009 """
3010 return self.api(
3011 self.papi.macip_acl_interface_get, {})
3012
3013 def macip_acl_dump(self, acl_index=4294967295):
3014 """ Return MACIP acl dump
3015 """
3016
3017 return self.api(
3018 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07003019
3020 def policer_add_del(self,
3021 name,
3022 cir,
3023 eir,
3024 cb,
3025 eb,
3026 is_add=1,
3027 rate_type=0,
3028 round_type=0,
3029 ptype=0,
3030 color_aware=0,
3031 conform_action_type=1,
3032 conform_dscp=0,
3033 exceed_action_type=0,
3034 exceed_dscp=0,
3035 violate_action_type=0,
3036 violate_dscp=0):
3037 return self.api(self.papi.policer_add_del,
3038 {'name': name,
3039 'cir': cir,
3040 'eir': eir,
3041 'cb': cb,
3042 'eb': eb,
3043 'is_add': is_add,
3044 'rate_type': rate_type,
3045 'round_type': round_type,
3046 'type': ptype,
3047 'color_aware': color_aware,
3048 'conform_action_type': conform_action_type,
3049 'conform_dscp': conform_dscp,
3050 'exceed_action_type': exceed_action_type,
3051 'exceed_dscp': exceed_dscp,
3052 'violate_action_type': violate_action_type,
3053 'violate_dscp': violate_dscp})
3054
3055 def ip_punt_police(self,
3056 policer_index,
3057 is_ip6=0,
3058 is_add=1):
3059 return self.api(self.papi.ip_punt_police,
3060 {'policer_index': policer_index,
3061 'is_add': is_add,
3062 'is_ip6': is_ip6})
3063
3064 def ip_punt_redirect(self,
3065 rx_sw_if_index,
3066 tx_sw_if_index,
3067 nh,
3068 is_ip6=0,
3069 is_add=1):
3070 return self.api(self.papi.ip_punt_redirect,
3071 {'rx_sw_if_index': rx_sw_if_index,
3072 'tx_sw_if_index': tx_sw_if_index,
3073 'nh': nh,
3074 'is_add': is_add,
3075 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003076
3077 def bier_table_add_del(self,
3078 bti,
3079 mpls_label,
3080 is_add=1):
3081 """ BIER Table add/del """
3082 return self.api(
3083 self.papi.bier_table_add_del,
3084 {'bt_tbl_id': {"bt_set": bti.set_id,
3085 "bt_sub_domain": bti.sub_domain_id,
3086 "bt_hdr_len_id": bti.hdr_len_id},
3087 'bt_label': mpls_label,
3088 'bt_is_add': is_add})
3089
3090 def bier_table_dump(self):
3091 return self.api(self.papi.bier_table_dump, {})
3092
3093 def bier_route_add_del(self,
3094 bti,
3095 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003096 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003097 is_add=1):
3098 """ BIER Route add/del """
3099 return self.api(
3100 self.papi.bier_route_add_del,
3101 {'br_tbl_id': {"bt_set": bti.set_id,
3102 "bt_sub_domain": bti.sub_domain_id,
3103 "bt_hdr_len_id": bti.hdr_len_id},
3104 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003105 'br_n_paths': len(paths),
3106 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003107 'br_is_add': is_add})
3108
3109 def bier_route_dump(self, bti):
3110 return self.api(
3111 self.papi.bier_route_dump,
3112 {'br_tbl_id': {"bt_set": bti.set_id,
3113 "bt_sub_domain": bti.sub_domain_id,
3114 "bt_hdr_len_id": bti.hdr_len_id}})
3115
3116 def bier_imp_add(self,
3117 bti,
3118 src,
3119 ibytes,
3120 is_add=1):
3121 """ BIER Imposition Add """
3122 return self.api(
3123 self.papi.bier_imp_add,
3124 {'bi_tbl_id': {"bt_set": bti.set_id,
3125 "bt_sub_domain": bti.sub_domain_id,
3126 "bt_hdr_len_id": bti.hdr_len_id},
3127 'bi_src': src,
3128 'bi_n_bytes': len(ibytes),
3129 'bi_bytes': ibytes})
3130
3131 def bier_imp_del(self, bi_index):
3132 """ BIER Imposition del """
3133 return self.api(
3134 self.papi.bier_imp_del,
3135 {'bi_index': bi_index})
3136
3137 def bier_imp_dump(self):
3138 return self.api(self.papi.bier_imp_dump, {})
3139
3140 def bier_disp_table_add_del(self,
3141 bdti,
3142 is_add=1):
3143 """ BIER Disposition Table add/del """
3144 return self.api(
3145 self.papi.bier_disp_table_add_del,
3146 {'bdt_tbl_id': bdti,
3147 'bdt_is_add': is_add})
3148
3149 def bier_disp_table_dump(self):
3150 return self.api(self.papi.bier_disp_table_dump, {})
3151
3152 def bier_disp_entry_add_del(self,
3153 bdti,
3154 bp,
3155 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003156 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003157 next_hop,
3158 next_hop_tbl_id=0,
3159 next_hop_rpf_id=~0,
3160 next_hop_is_ip4=1,
3161 is_add=1):
3162 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003163 lstack = []
3164 while (len(lstack) < 16):
3165 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003166 return self.api(
3167 self.papi.bier_disp_entry_add_del,
3168 {'bde_tbl_id': bdti,
3169 'bde_bp': bp,
3170 'bde_payload_proto': payload_proto,
3171 'bde_n_paths': 1,
3172 'bde_paths': [{'next_hop': next_hop,
3173 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003174 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003175 'rpf_id': next_hop_rpf_id,
3176 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003177 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003178 'bde_is_add': is_add})
3179
3180 def bier_disp_entry_dump(self, bdti):
3181 return self.api(
3182 self.papi.bier_disp_entry_dump,
3183 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003184
3185 def add_node_next(self, node_name, next_name):
3186 """ Set the next node for a given node request
3187
3188 :param node_name:
3189 :param next_name:
3190 """
3191 return self.api(self.papi.add_node_next,
3192 {'node_name': node_name,
3193 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003194
3195 def session_enable_disable(self, is_enabled):
3196 return self.api(
3197 self.papi.session_enable_disable,
3198 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003199
3200 def ipsec_spd_add_del(self, spd_id, is_add=1):
3201 """ SPD add/del - Wrapper to add or del ipsec SPD
3202 Sample CLI : 'ipsec spd add 1'
3203
3204 :param spd_id - SPD ID to be created in the vpp . mandatory
3205 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3206 optional
3207 :returns: reply from the API
3208 """
3209 return self.api(
3210 self.papi.ipsec_spd_add_del, {
3211 'spd_id': spd_id, 'is_add': is_add})
3212
3213 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3214 """ IPSEC interface SPD add/del - \
3215 Wrapper to associate/disassociate SPD to interface in VPP
3216 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3217
3218 :param spd_id - SPD ID to associate with the interface . mandatory
3219 :param sw_if_index - Interface Index which needs to ipsec \
3220 association mandatory
3221 :param is_add - add(1) or del(0) association with interface \
3222 (Default 1 - add) . optional
3223 :returns: reply from the API
3224 """
3225 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003226 self.papi.ipsec_interface_add_del_spd,
3227 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003228
3229 def ipsec_sad_add_del_entry(self,
3230 sad_id,
3231 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003232 integrity_algorithm,
3233 integrity_key,
3234 crypto_algorithm,
3235 crypto_key,
3236 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003237 tunnel_src_address='',
3238 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003239 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003240 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003241 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003242 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003243 :param sad_id: security association ID
3244 :param spi: security param index of the SA in decimal
3245 :param integrity_algorithm:
3246 :param integrity_key:
3247 :param crypto_algorithm:
3248 :param crypto_key:
3249 :param protocol: AH(0) or ESP(1) protocol
3250 :param tunnel_src_address: tunnel mode outer src address
3251 :param tunnel_dst_address: tunnel mode outer dst address
3252 :param is_add:
3253 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003254 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3255 crypto and ipsec algorithms
3256 """
3257 return self.api(
3258 self.papi.ipsec_sad_add_del_entry,
3259 {'sad_id': sad_id,
3260 'spi': spi,
3261 'tunnel_src_address': tunnel_src_address,
3262 'tunnel_dst_address': tunnel_dst_address,
3263 'protocol': protocol,
3264 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003265 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003266 'integrity_key': integrity_key,
3267 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003268 'crypto_key_length': len(crypto_key) if crypto_key is not None
3269 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003270 'crypto_key': crypto_key,
3271 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003272 'is_tunnel': is_tunnel,
3273 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003274
3275 def ipsec_spd_add_del_entry(self,
3276 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003277 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003278 local_address_start,
3279 local_address_stop,
3280 remote_address_start,
3281 remote_address_stop,
3282 local_port_start=0,
3283 local_port_stop=65535,
3284 remote_port_start=0,
3285 remote_port_stop=65535,
3286 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003287 policy=0,
3288 priority=100,
3289 is_outbound=1,
3290 is_add=1,
3291 is_ip_any=0):
3292 """ IPSEC policy SPD add/del -
3293 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003294 :param spd_id: SPD ID for the policy
3295 :param local_address_start: local-ip-range start address
3296 :param local_address_stop : local-ip-range stop address
3297 :param remote_address_start: remote-ip-range start address
3298 :param remote_address_stop : remote-ip-range stop address
3299 :param local_port_start: (Default value = 0)
3300 :param local_port_stop: (Default value = 65535)
3301 :param remote_port_start: (Default value = 0)
3302 :param remote_port_stop: (Default value = 65535)
3303 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3304 :param sa_id: Security Association ID for mapping it to SPD
3305 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3306 (Default value = 0)
3307 :param priority: value for the spd action (Default value = 100)
3308 :param is_outbound: flag for inbound(0) or outbound(1)
3309 (Default value = 1)
3310 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003311 """
3312 return self.api(
3313 self.papi.ipsec_spd_add_del_entry,
3314 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003315 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003316 'local_address_start': local_address_start,
3317 'local_address_stop': local_address_stop,
3318 'remote_address_start': remote_address_start,
3319 'remote_address_stop': remote_address_stop,
3320 'local_port_start': local_port_start,
3321 'local_port_stop': local_port_stop,
3322 'remote_port_start': remote_port_start,
3323 'remote_port_stop': remote_port_stop,
3324 'is_add': is_add,
3325 'protocol': protocol,
3326 'policy': policy,
3327 'priority': priority,
3328 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003329 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003330
Klement Sekera31da2e32018-06-24 22:49:55 +02003331 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3332 remote_spi, crypto_alg, local_crypto_key,
3333 remote_crypto_key, integ_alg, local_integ_key,
3334 remote_integ_key, is_add=1, esn=0,
3335 anti_replay=1, renumber=0, show_instance=0):
3336 return self.api(
3337 self.papi.ipsec_tunnel_if_add_del,
3338 {'local_ip': local_ip, 'remote_ip': remote_ip,
3339 'local_spi': local_spi, 'remote_spi': remote_spi,
3340 'crypto_alg': crypto_alg,
3341 'local_crypto_key_len': len(local_crypto_key),
3342 'local_crypto_key': local_crypto_key,
3343 'remote_crypto_key_len': len(remote_crypto_key),
3344 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3345 'local_integ_key_len': len(local_integ_key),
3346 'local_integ_key': local_integ_key,
3347 'remote_integ_key_len': len(remote_integ_key),
3348 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3349 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3350 'show_instance': show_instance
3351 })
3352
Florin Corasb795bd02017-12-14 11:30:48 -08003353 def app_namespace_add(self,
3354 namespace_id,
3355 ip4_fib_id=0,
3356 ip6_fib_id=0,
3357 sw_if_index=0xFFFFFFFF,
3358 secret=0):
3359 return self.api(
3360 self.papi.app_namespace_add_del,
3361 {'secret': secret,
3362 'sw_if_index': sw_if_index,
3363 'ip4_fib_id': ip4_fib_id,
3364 'ip6_fib_id': ip6_fib_id,
3365 'namespace_id': namespace_id,
3366 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003367
3368 def punt_socket_register(self, l4_port, pathname, header_version=1,
3369 is_ip4=1, l4_protocol=0x11):
3370 """ Punt to socket """
3371 return self.api(self.papi.punt_socket_register,
3372 {'is_ip4': is_ip4,
3373 'l4_protocol': l4_protocol,
3374 'l4_port': l4_port,
3375 'pathname': pathname,
3376 'header_version': header_version})
3377
3378 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3379 expire_walk_interval_ms, is_ip6=0):
3380 """ Set IP reassembly parameters """
3381 return self.api(self.papi.ip_reassembly_set,
3382 {'is_ip6': is_ip6,
3383 'timeout_ms': timeout_ms,
3384 'expire_walk_interval_ms': expire_walk_interval_ms,
3385 'max_reassemblies': max_reassemblies})
3386
3387 def ip_reassembly_get(self, is_ip6=0):
3388 """ Get IP reassembly parameters """
3389 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003390
Klement Sekera4c533132018-02-22 11:41:12 +01003391 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3392 enable_ip6=False):
3393 """ Enable/disable IP reassembly """
3394 return self.api(self.papi.ip_reassembly_enable_disable,
3395 {'sw_if_index': sw_if_index,
3396 'enable_ip4': 1 if enable_ip4 else 0,
3397 'enable_ip6': 1 if enable_ip6 else 0,
3398 })
3399
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003400 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3401 """ GBP endpoint Add/Del """
3402 return self.api(self.papi.gbp_endpoint_add_del,
3403 {'is_add': is_add,
3404 'endpoint': {
3405 'is_ip6': is_ip6,
3406 'sw_if_index': sw_if_index,
3407 'address': addr,
3408 'epg_id': epg}})
3409
3410 def gbp_endpoint_dump(self):
3411 """ GBP endpoint Dump """
3412 return self.api(self.papi.gbp_endpoint_dump, {})
3413
Neale Ranns25b04942018-04-04 09:34:50 -07003414 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3415 ip4_rd,
3416 ip6_rd,
3417 uplink_sw_if_index):
3418 """ GBP endpoint group Add/Del """
3419 return self.api(self.papi.gbp_endpoint_group_add_del,
3420 {'is_add': is_add,
3421 'epg': {
3422 'uplink_sw_if_index': uplink_sw_if_index,
3423 'bd_id': bd,
3424 'ip4_table_id': ip4_rd,
3425 'ip6_table_id': ip6_rd,
3426 'epg_id': epg}})
3427
3428 def gbp_endpoint_group_dump(self):
3429 """ GBP endpoint group Dump """
3430 return self.api(self.papi.gbp_endpoint_group_dump, {})
3431
3432 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3433 """ GBP recirc Add/Del """
3434 return self.api(self.papi.gbp_recirc_add_del,
3435 {'is_add': is_add,
3436 'recirc': {
3437 'is_ext': is_ext,
3438 'sw_if_index': sw_if_index,
3439 'epg_id': epg}})
3440
3441 def gbp_recirc_dump(self):
3442 """ GBP recirc Dump """
3443 return self.api(self.papi.gbp_recirc_dump, {})
3444
3445 def gbp_subnet_add_del(self, is_add, table_id,
3446 is_internal,
3447 addr, addr_len,
3448 sw_if_index=0xffffffff,
3449 epg_id=0xffffffff,
3450 is_ip6=False):
3451 """ GBP Subnet Add/Del """
3452 return self.api(self.papi.gbp_subnet_add_del,
3453 {'is_add': is_add,
3454 'subnet': {
3455 'is_internal': is_internal,
3456 'is_ip6': is_ip6,
3457 'sw_if_index': sw_if_index,
3458 'epg_id': epg_id,
3459 'address': addr,
3460 'address_length': addr_len,
3461 'table_id': table_id}})
3462
3463 def gbp_subnet_dump(self):
3464 """ GBP Subnet Dump """
3465 return self.api(self.papi.gbp_subnet_dump, {})
3466
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003467 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3468 """ GBP contract Add/Del """
3469 return self.api(self.papi.gbp_contract_add_del,
3470 {'is_add': is_add,
3471 'contract': {
3472 'acl_index': acl_index,
3473 'src_epg': src_epg,
3474 'dst_epg': dst_epg}})
3475
3476 def gbp_contract_dump(self):
3477 """ GBP contract Dump """
3478 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003479
Neale Ranns61502112018-08-22 00:21:14 -07003480 def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len,
3481 ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src,
Ole Troan298c6952018-03-08 12:30:43 +01003482 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003483 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003484 return self.api(self.papi.ipip_6rd_add_tunnel,
Neale Ranns61502112018-08-22 00:21:14 -07003485 {'ip4_table_id': ip4_table_id,
3486 'ip6_table_id': ip6_table_id,
Ole Troan6ee40512018-02-12 18:14:39 +01003487 'ip6_prefix': ip6_prefix,
3488 'ip6_prefix_len': ip6_prefix_len,
3489 'ip4_prefix': ip4_prefix,
3490 'ip4_prefix_len': ip4_prefix_len,
3491 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003492 'security_check': security_check})
3493
Ole Troan298c6952018-03-08 12:30:43 +01003494 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003495 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003496 return self.api(self.papi.ipip_6rd_del_tunnel,
3497 {'sw_if_index': sw_if_index})
3498
3499 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Neale Ranns61502112018-08-22 00:21:14 -07003500 instance=0xFFFFFFFF, table_id=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003501 """ IPIP tunnel Add/Del """
3502 return self.api(self.papi.ipip_add_tunnel,
3503 {'is_ipv6': is_ipv6,
3504 'instance': instance,
3505 'src_address': src_address,
3506 'dst_address': dst_address,
Neale Ranns61502112018-08-22 00:21:14 -07003507 'table_id': table_id,
Ole Troand57f6362018-05-24 13:21:43 +02003508 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003509
3510 def ipip_del_tunnel(self, sw_if_index):
3511 """ IPIP tunnel Delete """
3512 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003513 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003514
3515 def qos_egress_map_update(self, id, outputs):
3516 """ QOS egress map update """
3517 return self.api(self.papi.qos_egress_map_update,
3518 {'map_id': id,
3519 'rows': outputs})
3520
3521 def qos_egress_map_delete(self, id):
3522 """ QOS egress map delete """
3523 return self.api(self.papi.qos_egress_map_delete,
3524 {'map_id': id})
3525
3526 def qos_mark_enable_disable(self, sw_if_index,
3527 output_source,
3528 map_id,
3529 enable):
3530 """ QOS Mark Enable/Disable """
3531 return self.api(self.papi.qos_mark_enable_disable,
3532 {'map_id': map_id,
3533 'sw_if_index': sw_if_index,
3534 'output_source': output_source,
3535 'enable': enable})
3536
3537 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3538 """ IP QoS recording Enble/Disable """
3539 return self.api(self.papi.qos_record_enable_disable,
3540 {'sw_if_index': sw_if_index,
3541 'input_source': input_source,
3542 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003543
Neale Ranns947ea622018-06-07 23:48:20 -07003544 def igmp_enable_disable(self, sw_if_index, enable, host):
3545 """ Enable/disable IGMP on a given interface """
3546 return self.api(self.papi.igmp_enable_disable,
3547 {'enable': enable,
3548 'mode': host,
3549 'sw_if_index': sw_if_index})
3550
3551 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003552 """ Listen for new (S,G) on specified interface
3553
3554 :param enable: add/del
3555 :param sw_if_index: interface sw index
3556 :param saddr: source ip4 addr
3557 :param gaddr: group ip4 addr
3558 """
3559 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003560 {
3561 'group':
3562 {
3563 'filter': filter,
3564 'sw_if_index': sw_if_index,
3565 'n_srcs': len(saddrs),
3566 'saddrs': saddrs,
3567 'gaddr':
3568 {
3569 'address': gaddr
3570 }
3571 }
3572 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003573
3574 def igmp_dump(self, sw_if_index=None):
3575 """ Dump all (S,G) interface configurations """
3576 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003577 sw_if_index = 0xffffffff
3578 return self.api(self.papi.igmp_dump,
3579 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003580
3581 def igmp_clear_interface(self, sw_if_index):
3582 """ Remove all (S,G)s from specified interface
3583 doesn't send IGMP report!
3584 """
3585 return self.api(
3586 self.papi.igmp_clear_interface, {
3587 'sw_if_index': sw_if_index})
3588
3589 def want_igmp_events(self, enable=1):
3590 return self.api(self.papi.want_igmp_events, {'enable': enable,
3591 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003592
3593 def bond_create(
3594 self,
3595 mode,
3596 lb,
3597 use_custom_mac,
3598 mac_address=''):
3599 """
3600 :param mode: mode
3601 :param lb: load balance
3602 :param use_custom_mac: use custom mac
3603 :param mac_address: mac address
3604 """
3605 return self.api(
3606 self.papi.bond_create,
3607 {'mode': mode,
3608 'lb': lb,
3609 'use_custom_mac': use_custom_mac,
3610 'mac_address': mac_address
3611 })
3612
3613 def bond_delete(
3614 self,
3615 sw_if_index):
3616 """
3617 :param sw_if_index: interface the operation is applied to
3618 """
3619 return self.api(self.papi.bond_delete,
3620 {'sw_if_index': sw_if_index})
3621
3622 def bond_enslave(
3623 self,
3624 sw_if_index,
3625 bond_sw_if_index,
3626 is_passive,
3627 is_long_timeout):
3628 """
3629 :param sw_if_index: slave sw_if_index
3630 :param bond_sw_if_index: bond sw_if_index
3631 :param is_passive: is passive lacp speaker
3632 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3633 """
3634 return self.api(
3635 self.papi.bond_enslave,
3636 {'sw_if_index': sw_if_index,
3637 'bond_sw_if_index': bond_sw_if_index,
3638 'is_passive': is_passive,
3639 'is_long_timeout': is_long_timeout
3640 })
3641
3642 def bond_detach_slave(
3643 self,
3644 sw_if_index):
3645 """
3646 :param sw_if_index: slave interface the operation is applied to
3647 """
3648 return self.api(self.papi.bond_detach_slave,
3649 {'sw_if_index': sw_if_index})
3650
3651 def sw_interface_slave_dump(
3652 self,
3653 sw_if_index):
3654 """
3655 :param sw_if_index: bond sw_if_index
3656 """
3657 return self.api(self.papi.sw_interface_slave_dump,
3658 {'sw_if_index': sw_if_index})
3659
3660 def sw_interface_bond_dump(
3661 self):
3662 """
3663
3664 """
3665 return self.api(self.papi.sw_interface_bond_dump,
3666 {})
Stevene8fa6202017-08-30 14:36:45 -07003667
3668 def create_vhost_user_if(
3669 self,
3670 is_server,
3671 sock_filename,
3672 renumber,
3673 custom_dev_instance,
3674 use_custom_mac,
3675 mac_address,
3676 tag=''):
3677 """
3678 :param is_server: is server
3679 :param sock_filename: socket name
3680 :param renumber: renumber
3681 :param custom_dev_instance: custom dev instance
3682 :param use_custom_mac: use custom mac
3683 :param mac_address: mac address
3684 :param tag: tag (default ''
3685 """
3686 return self.api(
3687 self.papi.create_vhost_user_if,
3688 {'is_server': is_server,
3689 'sock_filename': sock_filename,
3690 'renumber': renumber,
3691 'custom_dev_instance': custom_dev_instance,
3692 'use_custom_mac': use_custom_mac,
3693 'mac_address': mac_address,
3694 'tag': tag
3695 })
3696
3697 def delete_vhost_user_if(
3698 self,
3699 sw_if_index):
3700 """
3701 :param sw_if_index: interface the operation is applied to
3702 """
3703 return self.api(self.papi.delete_vhost_user_if,
3704 {'sw_if_index': sw_if_index, })
3705
3706 def sw_interface_vhost_user_dump(
3707 self):
3708 """
3709
3710 """
3711 return self.api(self.papi.sw_interface_vhost_user_dump,
3712 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003713
3714 def abf_policy_add_del(self, is_add, policy):
3715 return self.api(
3716 self.papi.abf_policy_add_del,
3717 {'is_add': is_add,
3718 'policy': policy})
3719
3720 def abf_itf_attach_add_del(self, is_add, attach):
3721 return self.api(
3722 self.papi.abf_itf_attach_add_del,
3723 {'is_add': is_add,
3724 'attach': attach})
3725
3726 def abf_policy_dump(self):
3727 return self.api(
3728 self.papi.abf_policy_dump, {})
3729
3730 def abf_itf_attach_dump(self):
3731 return self.api(
3732 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003733
3734 def pipe_create(self, is_specified, user_instance):
3735 return self.api(self.papi.pipe_create,
3736 {'is_specified': is_specified,
3737 'user_instance': user_instance})
3738
3739 def pipe_delete(self, parent_sw_if_index):
3740 return self.api(self.papi.pipe_delete,
3741 {'parent_sw_if_index': parent_sw_if_index})
3742
3743 def pipe_dump(self):
3744 return self.api(self.papi.pipe_dump, {})