blob: 6ea1d2f3b3a2e875eaf4357d4d266ce326c47498 [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 Ranns8fe8cc22016-11-01 10:05:08 +0000278 def sw_interface_enable_disable_mpls(self, sw_if_index,
279 is_enable=1):
280 """
281 Enable/Disable MPLS on the interface
282 :param sw_if_index:
283 :param is_enable: (Default value = 1)
284
285 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100286 return self.api(self.papi.sw_interface_set_mpls_enable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200287 {'sw_if_index': sw_if_index,
288 'enable': is_enable})
Neale Ranns8fe8cc22016-11-01 10:05:08 +0000289
Jan Gelety057bb8c2016-12-20 17:32:45 +0100290 def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
Ole Troan7e3a8752016-12-05 10:27:09 +0100291 return self.api(self.papi.sw_interface_ip6nd_ra_config,
Jan Gelety057bb8c2016-12-20 17:32:45 +0100292 {'sw_if_index': sw_if_index,
293 'suppress': suppress})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200294
Neale Ranns227038a2017-04-21 01:07:59 -0700295 def set_ip_flow_hash(self,
296 table_id,
297 src=1,
298 dst=1,
299 sport=1,
300 dport=1,
301 proto=1,
302 reverse=0,
303 is_ip6=0):
304 return self.api(self.papi.set_ip_flow_hash,
305 {'vrf_id': table_id,
306 'src': src,
307 'dst': dst,
308 'dport': dport,
309 'sport': sport,
310 'proto': proto,
311 'reverse': reverse,
312 'is_ipv6': is_ip6})
313
Neale Ranns3f844d02017-02-18 00:03:54 -0800314 def ip6_nd_proxy(self, address, sw_if_index, is_del=0):
315 return self.api(self.papi.ip6nd_proxy_add_del,
316 {'address': address,
317 'sw_if_index': sw_if_index,
318 'is_del': is_del})
319
Neale Ranns75152282017-01-09 01:00:45 -0800320 def ip6_sw_interface_ra_config(self, sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000321 no,
Neale Ranns75152282017-01-09 01:00:45 -0800322 suppress,
Neale Ranns32e1c012016-11-22 17:07:28 +0000323 send_unicast):
Neale Ranns75152282017-01-09 01:00:45 -0800324 return self.api(self.papi.sw_interface_ip6nd_ra_config,
325 {'sw_if_index': sw_if_index,
Neale Ranns32e1c012016-11-22 17:07:28 +0000326 'is_no': no,
Klement Sekerada505f62017-01-04 12:58:53 +0100327 'suppress': suppress,
328 'send_unicast': send_unicast})
Neale Ranns75152282017-01-09 01:00:45 -0800329
Neale Ranns87df12d2017-02-18 08:16:41 -0800330 def ip6_sw_interface_ra_prefix(self,
331 sw_if_index,
332 address,
333 address_length,
334 use_default=0,
335 no_advertise=0,
336 off_link=0,
337 no_autoconfig=0,
338 no_onlink=0,
339 is_no=0,
340 val_lifetime=0xffffffff,
341 pref_lifetime=0xffffffff):
342 return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
343 {'sw_if_index': sw_if_index,
344 'address': address,
345 'address_length': address_length,
346 'use_default': use_default,
347 'no_advertise': no_advertise,
348 'off_link': off_link,
349 'no_autoconfig': no_autoconfig,
350 'no_onlink': no_onlink,
351 'is_no': is_no,
352 'val_lifetime': val_lifetime,
353 'pref_lifetime': pref_lifetime})
354
Neale Ranns75152282017-01-09 01:00:45 -0800355 def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
356 """
357 Enable/Disable An interface for IPv6
358 """
359 return self.api(self.papi.sw_interface_ip6_enable_disable,
360 {'sw_if_index': sw_if_index,
361 'enable': enable})
362
Klement Sekeraf62ae122016-10-11 11:47:09 +0200363 def vxlan_add_del_tunnel(
364 self,
365 src_addr,
366 dst_addr,
Eyal Baric5b13602016-11-24 19:42:43 +0200367 mcast_sw_if_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200368 is_add=1,
369 is_ipv6=0,
370 encap_vrf_id=0,
371 decap_next_index=0xFFFFFFFF,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600372 vni=0,
373 instance=0xFFFFFFFF):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200374 """
375
376 :param dst_addr:
377 :param src_addr:
378 :param is_add: (Default value = 1)
379 :param is_ipv6: (Default value = 0)
380 :param encap_vrf_id: (Default value = 0)
381 :param decap_next_index: (Default value = 0xFFFFFFFF)
Eyal Baric5b13602016-11-24 19:42:43 +0200382 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200383 :param vni: (Default value = 0)
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600384 :param instance: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200385
386 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100387 return self.api(self.papi.vxlan_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200388 {'is_add': is_add,
389 'is_ipv6': is_ipv6,
390 'src_address': src_addr,
391 'dst_address': dst_addr,
392 'mcast_sw_if_index': mcast_sw_if_index,
393 'encap_vrf_id': encap_vrf_id,
394 'decap_next_index': decap_next_index,
Jon Loeliger3d460bd2018-02-01 16:36:12 -0600395 'vni': vni,
396 'instance': instance})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200397
Marco Varleseb598f1d2017-09-19 14:25:28 +0200398 def geneve_add_del_tunnel(
399 self,
400 local_addr,
401 remote_addr,
402 mcast_sw_if_index=0xFFFFFFFF,
403 is_add=1,
404 is_ipv6=0,
405 encap_vrf_id=0,
406 decap_next_index=0xFFFFFFFF,
407 vni=0):
408 """
409
410 :param remote_addr:
411 :param local_addr:
412 :param is_add: (Default value = 1)
413 :param is_ipv6: (Default value = 0)
414 :param encap_vrf_id: (Default value = 0)
415 :param decap_next_index: (Default value = 0xFFFFFFFF)
416 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
417 :param vni: (Default value = 0)
418
419 """
420 return self.api(self.papi.geneve_add_del_tunnel,
421 {'is_add': is_add,
422 'is_ipv6': is_ipv6,
423 'local_address': local_addr,
424 'remote_address': remote_addr,
425 'mcast_sw_if_index': mcast_sw_if_index,
426 'encap_vrf_id': encap_vrf_id,
427 'decap_next_index': decap_next_index,
428 'vni': vni})
429
Jan4af521d2016-11-15 17:05:00 +0100430 def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
431 learn=1, arp_term=0, is_add=1):
432 """Create/delete bridge domain.
433
434 :param int bd_id: Bridge domain index.
435 :param int flood: Enable/disable bcast/mcast flooding in the BD.
436 (Default value = 1)
437 :param int uu_flood: Enable/disable unknown unicast flood in the BD.
438 (Default value = 1)
439 :param int forward: Enable/disable forwarding on all interfaces in
440 the BD. (Default value = 1)
441 :param int learn: Enable/disable learning on all interfaces in the BD.
442 (Default value = 1)
443 :param int arp_term: Enable/disable arp termination in the BD.
444 (Default value = 1)
445 :param int is_add: Add or delete flag. (Default value = 1)
446 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100447 return self.api(self.papi.bridge_domain_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200448 {'bd_id': bd_id,
449 'flood': flood,
450 'uu_flood': uu_flood,
451 'forward': forward,
452 'learn': learn,
453 'arp_term': arp_term,
454 'is_add': is_add})
Jan4af521d2016-11-15 17:05:00 +0100455
Eyal Baric86e5922017-07-02 18:33:16 +0300456 def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1):
457 return self.api(self.papi.bd_ip_mac_add_del,
458 {'bd_id': bd_id,
459 'is_add': is_add,
460 'is_ipv6': is_ipv6,
461 'ip_address': ip,
462 'mac_address': mac})
463
Eyal Bari20197482017-09-13 12:29:08 +0300464 def want_ip4_arp_events(self, enable_disable=1, address=0):
465 return self.api(self.papi.want_ip4_arp_events,
466 {'enable_disable': enable_disable,
467 'address': address,
468 'pid': os.getpid(), })
469
Eyal Baric125ecc2017-09-20 11:29:17 +0300470 def want_ip6_nd_events(self, enable_disable=1, address=0):
471 return self.api(self.papi.want_ip6_nd_events,
472 {'enable_disable': enable_disable,
473 'address': address,
474 'pid': os.getpid(), })
475
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100476 def want_ip6_ra_events(self, enable_disable=1):
477 return self.api(self.papi.want_ip6_ra_events,
478 {'enable_disable': enable_disable,
479 'pid': os.getpid(), })
480
481 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
482 mrc=0, mrd=0):
483 return self.api(self.papi.ip6nd_send_router_solicitation,
484 {'irt': irt,
485 'mrt': mrt,
486 'mrc': mrc,
487 'mrd': mrd,
488 'sw_if_index': sw_if_index})
489
Juraj Slobodac0374232018-02-01 15:18:49 +0100490 def ip6_nd_address_autoconfig(self, sw_if_index, enable,
491 install_default_routes):
492 return self.api(self.papi.ip6_nd_address_autoconfig,
493 {'sw_if_index': sw_if_index,
494 'enable': enable,
495 'install_default_routes': install_default_routes})
496
Eyal Bari24db0ec2017-09-27 21:43:51 +0300497 def want_macs_learn_events(self, enable_disable=1, scan_delay=0,
498 max_macs_in_event=0, learn_limit=0):
499 return self.api(self.papi.want_l2_macs_events,
500 {'enable_disable': enable_disable,
501 'scan_delay': scan_delay,
502 'max_macs_in_event': max_macs_in_event,
503 'learn_limit': learn_limit,
504 'pid': os.getpid(), })
505
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200506 def want_dhcp6_reply_events(self, enable_disable=1):
507 return self.api(self.papi.want_dhcp6_reply_events,
508 {'enable_disable': enable_disable,
509 'pid': os.getpid()})
510
Juraj Sloboda81119e82018-05-25 14:02:20 +0200511 def want_dhcp6_pd_reply_events(self, enable_disable=1):
512 return self.api(self.papi.want_dhcp6_pd_reply_events,
513 {'enable_disable': enable_disable,
514 'pid': os.getpid()})
515
516 def dhcp6_clients_enable_disable(self, enable=1):
517 return self.api(self.papi.dhcp6_clients_enable_disable,
518 {'enable': enable})
519
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200520 def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2,
521 addresses, server_index=0xFFFFFFFF,
522 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
523 ):
524 return self.api(self.papi.dhcp6_send_client_message,
525 {'sw_if_index': sw_if_index,
526 'server_index': server_index,
527 'irt': irt,
528 'mrt': mrt,
529 'mrc': mrc,
530 'mrd': mrd,
531 'stop': stop,
532 'msg_type': msg_type,
533 'T1': T1,
534 'T2': T2,
535 'n_addresses': len(addresses),
536 'addresses': addresses})
537
Juraj Sloboda81119e82018-05-25 14:02:20 +0200538 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
539 prefixes, server_index=0xFFFFFFFF,
540 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
541 ):
542 return self.api(self.papi.dhcp6_pd_send_client_message,
543 {'sw_if_index': sw_if_index,
544 'server_index': server_index,
545 'irt': irt,
546 'mrt': mrt,
547 'mrc': mrc,
548 'mrd': mrd,
549 'stop': stop,
550 'msg_type': msg_type,
551 'T1': T1,
552 'T2': T2,
553 'n_prefixes': len(prefixes),
554 'prefixes': prefixes})
555
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200556 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
557 enable=1):
558 return self.api(self.papi.dhcp6_client_enable_disable,
559 {'sw_if_index': sw_if_index,
560 'enable': enable})
561
Juraj Sloboda81119e82018-05-25 14:02:20 +0200562 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
563 enable=1):
564 return self.api(self.papi.dhcp6_pd_client_enable_disable,
565 {'sw_if_index': sw_if_index,
566 'prefix_group': prefix_group,
567 'enable': enable})
568
569 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
570 prefix_length, prefix_group,
571 is_add=1):
572 return self.api(self.papi.ip6_add_del_address_using_prefix,
573 {'sw_if_index': sw_if_index,
574 'prefix_group': prefix_group,
575 'address': address,
576 'prefix_length': prefix_length,
577 'is_add': is_add})
578
Jan4af521d2016-11-15 17:05:00 +0100579 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
580 filter_mac=0, bvi_mac=0):
581 """Create/delete L2 FIB entry.
582
583 :param str mac: MAC address to create FIB entry for.
584 :param int bd_id: Bridge domain index.
585 :param int sw_if_index: Software interface index of the interface.
586 :param int is_add: Add or delete flag. (Default value = 1)
587 :param int static_mac: Set to 1 to create static MAC entry.
588 (Default value = 0)
589 :param int filter_mac: Set to 1 to drop packet that's source or
590 destination MAC address contains defined MAC address.
591 (Default value = 0)
592 :param int bvi_mac: Set to 1 to create entry that points to BVI
593 interface. (Default value = 0)
594 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100595 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200596 {'mac': self._convert_mac(mac),
597 'bd_id': bd_id,
598 'sw_if_index': sw_if_index,
599 'is_add': is_add,
600 'static_mac': static_mac,
601 'filter_mac': filter_mac,
602 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100603
Eyal Bari93b503e2017-05-15 10:13:15 +0300604 def l2fib_flush_int(self, sw_if_index):
605 """Flush L2 FIB entries for sw_if_index.
606
607 :param int sw_if_index: Software interface index of the interface.
608 """
609 return self.api(self.papi.l2fib_flush_int,
610 {'sw_if_index': sw_if_index})
611
612 def l2fib_flush_bd(self, bd_id):
613 """Flush L2 FIB entries for bd_id.
614
615 :param int sw_if_index: Bridge Domain id.
616 """
617 return self.api(self.papi.l2fib_flush_bd,
618 {'bd_id': bd_id})
619
620 def l2fib_flush_all(self):
621 """Flush all L2 FIB.
622 """
623 return self.api(self.papi.l2fib_flush_all, {})
624
Klement Sekeraf62ae122016-10-11 11:47:09 +0200625 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
626 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100627 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200628
Jan4af521d2016-11-15 17:05:00 +0100629 :param int sw_if_index: Software interface index of the interface.
630 :param int bd_id: Bridge domain index.
631 :param int shg: Split-horizon group index. (Default value = 0)
632 :param int bvi: Set interface as a bridge group virtual interface.
633 (Default value = 0)
634 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200635 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100636 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200637 {'rx_sw_if_index': sw_if_index,
638 'bd_id': bd_id,
639 'shg': shg,
640 'bvi': bvi,
641 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200642
Jan00dad122016-11-29 10:04:53 +0100643 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400644 """Enable/disable required feature of the bridge domain with defined
645 ID.
Jan00dad122016-11-29 10:04:53 +0100646
647 :param int bd_id: Bridge domain ID.
648 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
649 :param int feature_bitmap: Bitmap value of the feature to be set:
650 - learn (1 << 0),
651 - forward (1 << 1),
652 - flood (1 << 2),
653 - uu-flood (1 << 3) or
654 - arp-term (1 << 4).
655 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100656 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200657 {'bd_id': bd_id,
658 'is_set': is_set,
659 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100660
661 def bridge_domain_dump(self, bd_id=0):
662 """
663
664 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
665 existing bridge domains returned)
666 :return: Dictionary of bridge domain(s) data.
667 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100668 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200669 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100670
Klement Sekeraf62ae122016-10-11 11:47:09 +0200671 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
672 enable):
673 """Create or delete unidirectional cross-connect from Tx interface to
674 Rx interface.
675
Jan4af521d2016-11-15 17:05:00 +0100676 :param int rx_sw_if_index: Software interface index of Rx interface.
677 :param int tx_sw_if_index: Software interface index of Tx interface.
678 :param int enable: Create cross-connect if equal to 1, delete
679 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200680
681 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100682 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200683 {'rx_sw_if_index': rx_sw_if_index,
684 'tx_sw_if_index': tx_sw_if_index,
685 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200686
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200687 def sw_interface_set_l2_tag_rewrite(
688 self,
689 sw_if_index,
690 vtr_oper,
691 push=0,
692 tag1=0,
693 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000694 """L2 interface vlan tag rewrite configure request
695 :param client_index - opaque cookie to identify the sender
696 :param context - sender context, to match reply w/ request
697 :param sw_if_index - interface the operation is applied to
698 :param vtr_op - Choose from l2_vtr_op_t enum values
699 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
700 :param tag1 - Needed for any push or translate vtr op
701 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
702
703 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100704 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200705 {'sw_if_index': sw_if_index,
706 'vtr_op': vtr_oper,
707 'push_dot1q': push,
708 'tag1': tag1,
709 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000710
Neale Ranns55d03782017-10-21 06:34:22 -0700711 def sw_interface_set_l2_emulation(
712 self,
713 sw_if_index,
714 enable=1):
715 """L2 Emulation
716 :param sw_if_index - interface the operation is applied to
717
718 """
719 return self.api(self.papi.l2_emulation,
720 {'sw_if_index': sw_if_index,
721 'enable': enable})
722
Neale Ranns1855b8e2018-07-11 10:31:26 -0700723 def sw_interface_set_ip_directed_broadcast(
724 self,
725 sw_if_index,
726 enable=1):
727 """IP Directed broadcast
728 :param sw_if_index - interface the operation is applied to
729
730 """
731 return self.api(self.papi.sw_interface_set_ip_directed_broadcast,
732 {'sw_if_index': sw_if_index,
733 'enable': enable})
734
Neale Rannsa07bd702017-08-07 07:53:49 -0700735 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200736 """
737
738 :param admin_up_down:
739 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200740
741 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100742 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200743 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700744 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200745
Ole Troand7231612018-06-07 10:17:57 +0200746 def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]):
Neale Rannsffd78d12018-02-09 06:05:16 -0800747 """
748 :param sw_if_index:
749 :param mtu:
750
751 """
752 return self.api(self.papi.sw_interface_set_mtu,
753 {'sw_if_index': sw_if_index,
754 'mtu': mtu})
755
Neale Ranns25b04942018-04-04 09:34:50 -0700756 def sw_interface_set_promiscuous(self, sw_if_index, enable):
757 """
758 :param sw_if_index:
759 :param enable:
760
761 """
762 return self.api(self.papi.sw_interface_set_promiscuous,
763 {'sw_if_index': sw_if_index,
764 'enable': enable})
765
Neale Rannsc819fc62018-02-16 02:44:05 -0800766 def sw_interface_set_mac_address(self, sw_if_index, mac):
767 return self.api(self.papi.sw_interface_set_mac_address,
768 {'sw_if_index': sw_if_index,
769 'mac_address': mac})
770
Klement Sekeraf62ae122016-10-11 11:47:09 +0200771 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
772 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
773 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
774 """Create subinterface
775 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
776
777 :param sub_id: param inner_vlan:
778 :param sw_if_index:
779 :param outer_vlan:
780 :param inner_vlan:
781 :param no_tags: (Default value = 0)
782 :param one_tag: (Default value = 0)
783 :param two_tags: (Default value = 0)
784 :param dot1ad: (Default value = 0)
785 :param exact_match: (Default value = 0)
786 :param default_sub: (Default value = 0)
787 :param outer_vlan_id_any: (Default value = 0)
788 :param inner_vlan_id_any: (Default value = 0)
789
790 """
791 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100792 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200793 {'sw_if_index': sw_if_index,
794 'sub_id': sub_id,
795 'no_tags': no_tags,
796 'one_tag': one_tag,
797 'two_tags': two_tags,
798 'dot1ad': dot1ad,
799 'exact_match': exact_match,
800 'default_sub': default_sub,
801 'outer_vlan_id_any': outer_vlan_id_any,
802 'inner_vlan_id_any': inner_vlan_id_any,
803 'outer_vlan_id': outer_vlan,
804 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200805
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200806 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
807 """Create p2p ethernet subinterface
808
809 :param sw_if_index: main (parent) interface
810 :param remote_mac: client (remote) mac address
811
812 """
813 return self.api(
814 self.papi.p2p_ethernet_add,
815 {'parent_if_index': sw_if_index,
816 'remote_mac': remote_mac,
817 'subif_id': subif_id})
818
Neale Ranns177bbdc2016-11-15 09:46:51 +0000819 def delete_subif(self, sw_if_index):
820 """Delete subinterface
821
822 :param sw_if_index:
823 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100824 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200825 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000826
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200827 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
828 """Delete p2p ethernet subinterface
829
830 :param sw_if_index: main (parent) interface
831 :param remote_mac: client (remote) mac address
832
833 """
834 return self.api(
835 self.papi.p2p_ethernet_del,
836 {'parent_if_index': sw_if_index,
837 'remote_mac': remote_mac})
838
Klement Sekeraf62ae122016-10-11 11:47:09 +0200839 def create_vlan_subif(self, sw_if_index, vlan):
840 """
841
842 :param vlan:
843 :param sw_if_index:
844
845 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100846 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200847 {'sw_if_index': sw_if_index,
848 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200849
Matej Klotton0178d522016-11-04 11:11:44 +0100850 def create_loopback(self, mac=''):
851 """
852
853 :param mac: (Optional)
854 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100855 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200856 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100857
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100858 def delete_loopback(self, sw_if_index):
859 return self.api(self.papi.delete_loopback,
860 {'sw_if_index': sw_if_index, })
861
Neale Ranns15002542017-09-10 04:39:11 -0700862 def ip_table_add_del(self,
863 table_id,
864 is_add=1,
865 is_ipv6=0):
866 """
867
868 :param table_id
869 :param is_add: (Default value = 1)
870 :param is_ipv6: (Default value = 0)
871
872 """
873
874 return self.api(
875 self.papi.ip_table_add_del,
876 {'table_id': table_id,
877 'is_add': is_add,
878 'is_ipv6': is_ipv6})
879
Klement Sekeraf62ae122016-10-11 11:47:09 +0200880 def ip_add_del_route(
881 self,
882 dst_address,
883 dst_address_length,
884 next_hop_address,
885 next_hop_sw_if_index=0xFFFFFFFF,
886 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200887 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000888 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200889 next_hop_n_out_labels=0,
890 next_hop_out_label_stack=[],
891 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800892 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000893 is_resolve_host=0,
894 is_resolve_attached=0,
895 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200896 is_add=1,
897 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200898 is_unreach=0,
899 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200900 is_ipv6=0,
901 is_local=0,
902 is_classify=0,
903 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800904 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800905 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200906 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200907 """
908
909 :param dst_address_length:
910 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
911 :param dst_address:
912 :param next_hop_address:
913 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
914 :param vrf_id: (Default value = 0)
915 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200916 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200917 :param is_add: (Default value = 1)
918 :param is_drop: (Default value = 0)
919 :param is_ipv6: (Default value = 0)
920 :param is_local: (Default value = 0)
921 :param is_classify: (Default value = 0)
922 :param is_multipath: (Default value = 0)
923 :param is_resolve_host: (Default value = 0)
924 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800925 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700926 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200927 :param next_hop_weight: (Default value = 1)
928
929 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000930
Klement Sekeraf62ae122016-10-11 11:47:09 +0200931 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100932 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200933 {'next_hop_sw_if_index': next_hop_sw_if_index,
934 'table_id': table_id,
935 'classify_table_index': classify_table_index,
936 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200937 'is_add': is_add,
938 'is_drop': is_drop,
939 'is_unreach': is_unreach,
940 'is_prohibit': is_prohibit,
941 'is_ipv6': is_ipv6,
942 'is_local': is_local,
943 'is_classify': is_classify,
944 'is_multipath': is_multipath,
945 'is_resolve_host': is_resolve_host,
946 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800947 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700948 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800949 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200950 'next_hop_weight': next_hop_weight,
951 'dst_address_length': dst_address_length,
952 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800953 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200954 'next_hop_address': next_hop_address,
955 'next_hop_n_out_labels': next_hop_n_out_labels,
956 'next_hop_via_label': next_hop_via_label,
957 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100958
Matej Klotton16a14cd2016-12-07 15:09:13 +0100959 def ip_fib_dump(self):
960 return self.api(self.papi.ip_fib_dump, {})
961
Jan Gelety057bb8c2016-12-20 17:32:45 +0100962 def ip6_fib_dump(self):
963 return self.api(self.papi.ip6_fib_dump, {})
964
Matej Klotton0178d522016-11-04 11:11:44 +0100965 def ip_neighbor_add_del(self,
966 sw_if_index,
967 mac_address,
968 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100969 is_add=1,
970 is_ipv6=0,
971 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800972 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100973 ):
974 """ Add neighbor MAC to IPv4 or IPv6 address.
975
976 :param sw_if_index:
977 :param mac_address:
978 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100979 :param is_add: (Default value = 1)
980 :param is_ipv6: (Default value = 0)
981 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800982 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100983 """
984
985 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100986 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800987 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200988 'is_add': is_add,
989 'is_ipv6': is_ipv6,
990 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800991 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200992 'mac_address': mac_address,
993 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100994 }
Matej Klotton0178d522016-11-04 11:11:44 +0100995 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100996
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800997 def ip_neighbor_dump(self,
998 sw_if_index,
999 is_ipv6=0):
1000 """ Return IP neighbor dump.
1001
1002 :param sw_if_index:
1003 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1004 """
1005
1006 return self.api(
1007 self.papi.ip_neighbor_dump,
1008 {'is_ipv6': is_ipv6,
1009 'sw_if_index': sw_if_index
1010 }
1011 )
1012
1013 def proxy_arp_add_del(self,
1014 low_address,
1015 hi_address,
1016 vrf_id=0,
1017 is_add=1):
1018 """ Config Proxy Arp Range.
1019
1020 :param low_address: Start address in the rnage to Proxy for
1021 :param hi_address: End address in the rnage to Proxy for
1022 :param vrf_id: The VRF/table in which to proxy
1023 """
1024
1025 return self.api(
1026 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -07001027 {'proxy':
1028 {
1029 'vrf_id': vrf_id,
1030 'low_address': low_address,
1031 'hi_address': hi_address,
1032 },
1033 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -08001034
1035 def proxy_arp_intfc_enable_disable(self,
1036 sw_if_index,
1037 is_enable=1):
1038 """ Enable/Disable an interface for proxy ARP requests
1039
1040 :param sw_if_index: Interface
1041 :param enable_disable: Enable/Disable
1042 """
1043
1044 return self.api(
1045 self.papi.proxy_arp_intfc_enable_disable,
1046 {'sw_if_index': sw_if_index,
1047 'enable_disable': is_enable
1048 }
1049 )
1050
Jane546d3b2016-12-08 13:10:03 +01001051 def reset_vrf(self,
1052 vrf_id,
1053 is_ipv6=0,
1054 ):
1055 """ Reset VRF (remove all routes etc.) request.
1056
1057 :param int vrf_id: ID of the FIB table / VRF to reset.
1058 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1059 """
1060
1061 return self.api(
1062 self.papi.reset_vrf,
1063 {'vrf_id': vrf_id,
1064 'is_ipv6': is_ipv6,
1065 }
1066 )
1067
1068 def reset_fib(self,
1069 vrf_id,
1070 is_ipv6=0,
1071 ):
1072 """ Reset VRF (remove all routes etc.) request.
1073
1074 :param int vrf_id: ID of the FIB table / VRF to reset.
1075 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1076 """
1077
1078 return self.api(
1079 self.papi.reset_fib,
1080 {'vrf_id': vrf_id,
1081 'is_ipv6': is_ipv6,
1082 }
1083 )
1084
1085 def ip_dump(self,
1086 is_ipv6=0,
1087 ):
1088 """ Return IP dump.
1089
1090 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1091 """
1092
1093 return self.api(
1094 self.papi.ip_dump,
1095 {'is_ipv6': is_ipv6,
1096 }
1097 )
1098
Klement Sekera7bb873a2016-11-18 07:38:42 +01001099 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001100 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001101 """
1102
1103 :param sw_if_index_from:
1104 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001105 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001106 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001107 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001108 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001109 {'sw_if_index_from': sw_if_index_from,
1110 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001111 'state': state,
1112 'is_l2': is_l2,
1113 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001114
1115 def gre_tunnel_add_del(self,
1116 src_address,
1117 dst_address,
1118 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001119 tunnel_type=0,
1120 instance=0xFFFFFFFF,
1121 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001122 is_add=1,
1123 is_ip6=0):
1124 """ Add a GRE tunnel
1125
1126 :param src_address:
1127 :param dst_address:
1128 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001129 :param tunnel_type: (Default value = 0)
1130 :param instance: (Default value = 0xFFFFFFFF)
1131 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001132 :param is_add: (Default value = 1)
1133 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001134 """
1135
1136 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001137 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001138 {'is_add': is_add,
1139 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001140 'tunnel_type': tunnel_type,
1141 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001142 'src_address': src_address,
1143 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001144 'outer_fib_id': outer_fib_id,
1145 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001146 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001147
Neale Ranns810086d2017-11-05 16:26:46 -08001148 def udp_encap_add_del(self,
1149 id,
1150 src_ip,
1151 dst_ip,
1152 src_port,
1153 dst_port,
1154 table_id=0,
1155 is_add=1,
1156 is_ip6=0):
1157 """ Add a GRE tunnel
1158 :param id: user provided ID
1159 :param src_ip:
1160 :param dst_ip:
1161 :param src_port:
1162 :param dst_port:
1163 :param outer_fib_id: (Default value = 0)
1164 :param is_add: (Default value = 1)
1165 :param is_ipv6: (Default value = 0)
1166 """
1167
1168 return self.api(
1169 self.papi.udp_encap_add_del,
1170 {'id': id,
1171 'is_add': is_add,
1172 'is_ip6': is_ip6,
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 def udp_encap_dump(self):
1181 return self.api(self.papi.udp_encap_dump, {})
1182
Neale Ranns43b1f442018-03-20 01:47:35 -07001183 def want_udp_encap_stats(self, enable=1):
1184 return self.api(self.papi.want_udp_encap_stats,
1185 {'enable': enable,
1186 'pid': os.getpid()})
1187
Neale Ranns5a8123b2017-01-26 01:18:23 -08001188 def mpls_fib_dump(self):
1189 return self.api(self.papi.mpls_fib_dump, {})
1190
Neale Ranns15002542017-09-10 04:39:11 -07001191 def mpls_table_add_del(
1192 self,
1193 table_id,
1194 is_add=1):
1195 """
1196
1197 :param table_id
1198 :param is_add: (Default value = 1)
1199
1200 """
1201
1202 return self.api(
1203 self.papi.mpls_table_add_del,
1204 {'mt_table_id': table_id,
1205 'mt_is_add': is_add})
1206
Neale Rannsad422ed2016-11-02 14:20:04 +00001207 def mpls_route_add_del(
1208 self,
1209 label,
1210 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001211 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001212 next_hop_address,
1213 next_hop_sw_if_index=0xFFFFFFFF,
1214 table_id=0,
1215 next_hop_table_id=0,
1216 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001217 next_hop_n_out_labels=0,
1218 next_hop_out_label_stack=[],
1219 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001220 is_resolve_host=0,
1221 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001222 is_interface_rx=0,
1223 is_rpf_id=0,
1224 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001225 is_add=1,
1226 is_drop=0,
1227 is_multipath=0,
1228 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001229 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001230 """
1231
1232 :param dst_address_length:
1233 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1234 :param dst_address:
1235 :param next_hop_address:
1236 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1237 :param vrf_id: (Default value = 0)
1238 :param lookup_in_vrf: (Default value = 0)
1239 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001240 :param is_add: (Default value = 1)
1241 :param is_drop: (Default value = 0)
1242 :param is_ipv6: (Default value = 0)
1243 :param is_local: (Default value = 0)
1244 :param is_classify: (Default value = 0)
1245 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001246 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001247 :param is_resolve_host: (Default value = 0)
1248 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001249 :param next_hop_weight: (Default value = 1)
1250
1251 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001252 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001253 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001254 {'mr_label': label,
1255 'mr_eos': eos,
1256 'mr_table_id': table_id,
1257 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001258 'mr_is_add': is_add,
1259 'mr_is_classify': is_classify,
1260 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001261 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001262 'mr_is_resolve_host': is_resolve_host,
1263 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001264 'mr_is_interface_rx': is_interface_rx,
1265 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001266 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001267 'mr_next_hop_weight': next_hop_weight,
1268 'mr_next_hop': next_hop_address,
1269 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1270 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1271 'mr_next_hop_table_id': next_hop_table_id,
1272 'mr_next_hop_via_label': next_hop_via_label,
1273 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001274
1275 def mpls_ip_bind_unbind(
1276 self,
1277 label,
1278 dst_address,
1279 dst_address_length,
1280 table_id=0,
1281 ip_table_id=0,
1282 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001283 is_bind=1):
1284 """
1285 """
1286 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001287 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001288 {'mb_mpls_table_id': table_id,
1289 'mb_label': label,
1290 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001291 'mb_is_bind': is_bind,
1292 'mb_is_ip4': is_ip4,
1293 'mb_address_length': dst_address_length,
1294 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001295
1296 def mpls_tunnel_add_del(
1297 self,
1298 tun_sw_if_index,
1299 next_hop_proto_is_ip4,
1300 next_hop_address,
1301 next_hop_sw_if_index=0xFFFFFFFF,
1302 next_hop_table_id=0,
1303 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001304 next_hop_n_out_labels=0,
1305 next_hop_out_label_stack=[],
1306 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001307 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001308 l2_only=0,
1309 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001310 """
1311
1312 :param dst_address_length:
1313 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1314 :param dst_address:
1315 :param next_hop_address:
1316 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1317 :param vrf_id: (Default value = 0)
1318 :param lookup_in_vrf: (Default value = 0)
1319 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001320 :param is_add: (Default value = 1)
1321 :param is_drop: (Default value = 0)
1322 :param is_ipv6: (Default value = 0)
1323 :param is_local: (Default value = 0)
1324 :param is_classify: (Default value = 0)
1325 :param is_multipath: (Default value = 0)
1326 :param is_resolve_host: (Default value = 0)
1327 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001328 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001329 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001330
1331 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001332 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001333 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001334 {'mt_sw_if_index': tun_sw_if_index,
1335 'mt_is_add': is_add,
1336 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001337 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001338 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1339 'mt_next_hop_weight': next_hop_weight,
1340 'mt_next_hop': next_hop_address,
1341 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1342 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1343 'mt_next_hop_table_id': next_hop_table_id,
1344 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001345
Matus Fabian2ba92e32017-08-21 07:05:03 -07001346 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001347 self,
1348 sw_if_index,
1349 is_inside=1,
1350 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001351 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001352
1353 :param sw_if_index: Software index of the interface
1354 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1355 :param is_add: 1 if add, 0 if delete (Default value = 1)
1356 """
1357 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001358 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001359 {'is_add': is_add,
1360 'is_inside': is_inside,
1361 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001362
Matus Fabian2ba92e32017-08-21 07:05:03 -07001363 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001364 self,
1365 sw_if_index,
1366 is_inside=1,
1367 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001368 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001369
1370 :param sw_if_index: Software index of the interface
1371 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1372 :param is_add: 1 if add, 0 if delete (Default value = 1)
1373 """
1374 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001375 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001376 {'is_add': is_add,
1377 'is_inside': is_inside,
1378 'sw_if_index': sw_if_index})
1379
Matus Fabian2ba92e32017-08-21 07:05:03 -07001380 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001381 self,
1382 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001383 external_ip=0,
1384 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001385 local_port=0,
1386 external_port=0,
1387 addr_only=1,
1388 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001389 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001390 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001391 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001392 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001393 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001394 is_add=1):
1395 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001396
1397 :param local_ip: Local IP address
1398 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001399 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001400 :param local_port: Local port number (Default value = 0)
1401 :param external_port: External port number (Default value = 0)
1402 :param addr_only: 1 if address only mapping, 0 if address and port
1403 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001404 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001405 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001406 :param self_twice_nat: 1 if translate external host address and port
1407 whenever external host address equals
1408 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001409 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001410 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001411 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001412 """
1413 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001414 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001415 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001416 'addr_only': addr_only,
1417 'local_ip_address': local_ip,
1418 'external_ip_address': external_ip,
1419 'local_port': local_port,
1420 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001421 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001422 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001423 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001424 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001425 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001426 'out2in_only': out2in_only,
1427 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001428
Matus Fabianab7a8052017-11-28 04:29:41 -08001429 def nat44_add_del_identity_mapping(
1430 self,
1431 ip='0',
1432 sw_if_index=0xFFFFFFFF,
1433 port=0,
1434 addr_only=1,
1435 vrf_id=0,
1436 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001437 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001438 is_add=1):
1439 """Add/delete NAT44 identity mapping
1440
1441 :param ip: IP address (Default value = 0)
1442 :param sw_if_index: Interface instead of IP address
1443 :param port: Port number (Default value = 0)
1444 :param addr_only: 1 if address only mapping, 0 if address and port
1445 :param vrf_id: VRF ID
1446 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001447 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001448 :param is_add: 1 if add, 0 if delete (Default value = 1)
1449 """
1450 return self.api(
1451 self.papi.nat44_add_del_identity_mapping,
1452 {'is_add': is_add,
1453 'addr_only': addr_only,
1454 'ip_address': ip,
1455 'port': port,
1456 'sw_if_index': sw_if_index,
1457 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001458 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001459 'protocol': protocol})
1460
Matus Fabian2ba92e32017-08-21 07:05:03 -07001461 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001462 self,
1463 first_ip_address,
1464 last_ip_address,
1465 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001466 vrf_id=0xFFFFFFFF,
1467 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001468 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001469
1470 :param first_ip_address: First IP address
1471 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001472 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001473 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001474 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001475 """
1476 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001477 self.papi.nat44_add_del_address_range,
1478 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001479 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001480 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001481 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001482 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001483
Matus Fabian2ba92e32017-08-21 07:05:03 -07001484 def nat44_address_dump(self):
1485 """Dump NAT44 addresses
1486 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001487 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001488 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001489
Matus Fabian2ba92e32017-08-21 07:05:03 -07001490 def nat44_interface_dump(self):
1491 """Dump interfaces with NAT44 feature
1492 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001493 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001494 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001495
Matus Fabian2ba92e32017-08-21 07:05:03 -07001496 def nat44_interface_output_feature_dump(self):
1497 """Dump interfaces with NAT44 output feature
1498 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001499 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001500 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001501
Matus Fabian2ba92e32017-08-21 07:05:03 -07001502 def nat44_static_mapping_dump(self):
1503 """Dump NAT44 static mappings
1504 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001505 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001506 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001507
Matus Fabianab7a8052017-11-28 04:29:41 -08001508 def nat44_identity_mapping_dump(self):
1509 """Dump NAT44 identity mappings
1510 :return: Dictionary of NAT44 identity mappings
1511 """
1512 return self.api(self.papi.nat44_identity_mapping_dump, {})
1513
Matus Fabian2ba92e32017-08-21 07:05:03 -07001514 def nat_show_config(self):
1515 """Show NAT plugin config
1516 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001517 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001518 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001519
Matus Fabian2ba92e32017-08-21 07:05:03 -07001520 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001521 self,
1522 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001523 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001524 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001525 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001526
1527 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001528 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001529 :param is_add: 1 if add, 0 if delete (Default value = 1)
1530 """
Matus Fabianb932d262017-12-18 05:38:24 -08001531 return self.api(
1532 self.papi.nat44_add_del_interface_addr,
1533 {'is_add': is_add,
1534 'sw_if_index': sw_if_index,
1535 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001536
Matus Fabian2ba92e32017-08-21 07:05:03 -07001537 def nat44_interface_addr_dump(self):
1538 """Dump NAT44 addresses interfaces
1539 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001540 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001541 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001542
Matus Fabian2ba92e32017-08-21 07:05:03 -07001543 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001544 self,
1545 domain_id=1,
1546 src_port=4739,
1547 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001548 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001549
1550 :param domain_id: Observation domain ID (Default value = 1)
1551 :param src_port: Source port number (Default value = 4739)
1552 :param enable: 1 if enable, 0 if disable (Default value = 1)
1553 """
1554 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001555 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001556 {'domain_id': domain_id,
1557 'src_port': src_port,
1558 'enable': enable})
1559
Matus Fabian2ba92e32017-08-21 07:05:03 -07001560 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001561 self,
1562 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001563 vrf_id):
1564 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001565
1566 :param ip_address: ip adress of the user to be dumped
1567 :param cpu_index: cpu_index on which the user is
1568 :param vrf_id: VRF ID
1569 :return: Dictionary of S-NAT sessions
1570 """
1571 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001572 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001573 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001574 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001575
Matus Fabian2ba92e32017-08-21 07:05:03 -07001576 def nat44_user_dump(self):
1577 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001578
Matus Fabian2ba92e32017-08-21 07:05:03 -07001579 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001580 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001581 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001582
Matus Fabian704018c2017-09-04 02:17:18 -07001583 def nat44_add_del_lb_static_mapping(
1584 self,
1585 external_addr,
1586 external_port,
1587 protocol,
1588 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001589 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001590 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001591 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001592 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001593 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001594 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001595 is_add=1):
1596 """Add/delete NAT44 load balancing static mapping
1597
Matus Fabianb932d262017-12-18 05:38:24 -08001598 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001599 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001600 :param is_add - 1 if add, 0 if delete
1601 """
1602 return self.api(
1603 self.papi.nat44_add_del_lb_static_mapping,
1604 {'is_add': is_add,
1605 'external_addr': external_addr,
1606 'external_port': external_port,
1607 'protocol': protocol,
1608 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001609 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001610 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001611 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001612 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001613 'local_num': local_num,
1614 'locals': locals})
1615
1616 def nat44_lb_static_mapping_dump(self):
1617 """Dump NAT44 load balancing static mappings
1618
1619 :return: Dictionary of NAT44 load balancing static mapping
1620 """
1621 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1622
Matus Fabian5ba86f72017-10-26 03:37:38 -07001623 def nat44_del_session(
1624 self,
1625 addr,
1626 port,
1627 protocol,
1628 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001629 is_in=1,
1630 ext_host_address=None,
1631 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001632 """Delete NAT44 session
1633
1634 :param addr: IPv4 address
1635 :param por: port number
1636 :param protocol: IP protocol number
1637 :param vrf_id: VRF ID
1638 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001639 :param ext_host_address: external host IPv4 address
1640 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001641 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001642 if ext_host_address is None:
1643 return self.api(
1644 self.papi.nat44_del_session,
1645 {'address': addr,
1646 'port': port,
1647 'protocol': protocol,
1648 'vrf_id': vrf_id,
1649 'is_in': is_in})
1650 else:
1651 return self.api(
1652 self.papi.nat44_del_session,
1653 {'address': addr,
1654 'port': port,
1655 'protocol': protocol,
1656 'vrf_id': vrf_id,
1657 'is_in': is_in,
1658 'ext_host_valid': 1,
1659 'ext_host_address': ext_host_address,
1660 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001661
Juraj Sloboda7b929792017-11-23 13:20:48 +01001662 def nat44_forwarding_enable_disable(
1663 self,
1664 enable):
1665 """Enable/disable forwarding for NAT44
1666
1667 :param enable: 1 for enable, 0 for disable
1668 """
1669 return self.api(
1670 self.papi.nat44_forwarding_enable_disable,
1671 {'enable': enable})
1672
Matus Fabianefcd1e92017-08-15 06:59:19 -07001673 def nat_set_reass(
1674 self,
1675 timeout=2,
1676 max_reass=1024,
1677 max_frag=5,
1678 drop_frag=0,
1679 is_ip6=0):
1680 """Set NAT virtual fragmentation reassembly
1681
1682 :param timeout: reassembly timeout (Default 2sec)
1683 :param max_reass: maximum concurrent reassemblies (Default 1024)
1684 :param max_frag: maximum fragmets per reassembly (Default 5)
1685 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1686 :param is_ip6: 1 if IPv6, 0 if IPv4
1687 """
1688 return self.api(
1689 self.papi.nat_set_reass,
1690 {'timeout': timeout,
1691 'max_reass': max_reass,
1692 'max_frag': max_frag,
1693 'drop_frag': drop_frag,
1694 'is_ip6': is_ip6})
1695
1696 def nat_get_reass(self):
1697 """Get NAT virtual fragmentation reassembly configuration
1698
1699 :return: NAT virtual fragmentation reassembly configuration
1700 """
1701 return self.api(self.papi.nat_get_reass, {})
1702
1703 def nat_reass_dump(self):
1704 """Dump NAT virtual fragmentation reassemblies
1705
1706 :return: Dictionary of NAT virtual fragmentation reassemblies
1707 """
1708 return self.api(self.papi.nat_reass_dump, {})
1709
Matus Fabian2ba92e32017-08-21 07:05:03 -07001710 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001711 self,
1712 in_addr,
1713 in_plen,
1714 out_addr,
1715 out_plen,
1716 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001717 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001718
1719 :param is_add - 1 if add, 0 if delete
1720 :param in_addr - inside IP address
1721 :param in_plen - inside IP address prefix length
1722 :param out_addr - outside IP address
1723 :param out_plen - outside IP address prefix length
1724 """
1725 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001726 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001727 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001728 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001729 'in_addr': in_addr,
1730 'in_plen': in_plen,
1731 'out_addr': out_addr,
1732 'out_plen': out_plen})
1733
Matus Fabian2ba92e32017-08-21 07:05:03 -07001734 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001735 self,
1736 in_addr):
1737 """Get outside address and port range from inside address
1738
1739 :param in_addr - inside IP address
1740 """
1741 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001742 self.papi.nat_det_forward,
1743 {'in_addr': in_addr,
1744 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001745
Matus Fabian2ba92e32017-08-21 07:05:03 -07001746 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001747 self,
1748 out_addr,
1749 out_port):
1750 """Get inside address from outside address and port
1751
1752 :param out_addr - outside IP address
1753 :param out_port - outside port
1754 """
1755 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001756 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001757 {'out_addr': out_addr,
1758 'out_port': out_port})
1759
Matus Fabian2ba92e32017-08-21 07:05:03 -07001760 def nat_det_map_dump(self):
1761 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001762
Matus Fabian2ba92e32017-08-21 07:05:03 -07001763 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001764 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001765 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001766
Matus Fabian2ba92e32017-08-21 07:05:03 -07001767 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001768 self,
1769 udp=300,
1770 tcp_established=7440,
1771 tcp_transitory=240,
1772 icmp=60):
1773 """Set values of timeouts for deterministic NAT (in seconds)
1774
1775 :param udp - UDP timeout (Default value = 300)
1776 :param tcp_established - TCP established timeout (Default value = 7440)
1777 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1778 :param icmp - ICMP timeout (Default value = 60)
1779 """
1780 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001781 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001782 {'udp': udp,
1783 'tcp_established': tcp_established,
1784 'tcp_transitory': tcp_transitory,
1785 'icmp': icmp})
1786
Matus Fabian2ba92e32017-08-21 07:05:03 -07001787 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001788 """Get values of timeouts for deterministic NAT
1789
1790 :return: Timeouts for deterministic NAT (in seconds)
1791 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001792 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001793
Matus Fabian2ba92e32017-08-21 07:05:03 -07001794 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001795 self,
1796 out_addr,
1797 out_port,
1798 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001799 ext_port):
1800 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001801
1802 :param out_addr - outside IP address
1803 :param out_port - outside port
1804 :param ext_addr - external host IP address
1805 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001806 """
1807 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001808 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001809 {'out_addr': out_addr,
1810 'out_port': out_port,
1811 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001812 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001813
Matus Fabian2ba92e32017-08-21 07:05:03 -07001814 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001815 self,
1816 in_addr,
1817 in_port,
1818 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001819 ext_port):
1820 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001821
1822 :param in_addr - inside IP address
1823 :param in_port - inside port
1824 :param ext_addr - external host IP address
1825 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001826 """
1827 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001828 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001829 {'in_addr': in_addr,
1830 'in_port': in_port,
1831 'ext_addr': ext_addr,
1832 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001833 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001834
Matus Fabian2ba92e32017-08-21 07:05:03 -07001835 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001836 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001837 user_addr):
1838 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001839
1840 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001841 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001842 """
1843 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001844 self.papi.nat_det_session_dump,
1845 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001846 'user_addr': user_addr})
1847
Matus Fabian06596c52017-06-06 04:53:28 -07001848 def nat64_add_del_pool_addr_range(
1849 self,
1850 start_addr,
1851 end_addr,
1852 vrf_id=0xFFFFFFFF,
1853 is_add=1):
1854 """Add/del address range to NAT64 pool
1855
1856 :param start_addr: First IP address
1857 :param end_addr: Last IP address
1858 :param vrf_id: VRF id for the address range
1859 :param is_add: 1 if add, 0 if delete (Default value = 1)
1860 """
1861 return self.api(
1862 self.papi.nat64_add_del_pool_addr_range,
1863 {'start_addr': start_addr,
1864 'end_addr': end_addr,
1865 'vrf_id': vrf_id,
1866 'is_add': is_add})
1867
1868 def nat64_pool_addr_dump(self):
1869 """Dump NAT64 pool addresses
1870 :return: Dictionary of NAT64 pool addresses
1871 """
1872 return self.api(self.papi.nat64_pool_addr_dump, {})
1873
1874 def nat64_add_del_interface(
1875 self,
1876 sw_if_index,
1877 is_inside=1,
1878 is_add=1):
1879 """Enable/disable NAT64 feature on the interface
1880 :param sw_if_index: Index of the interface
1881 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1882 :param is_add: 1 if add, 0 if delete (Default value = 1)
1883 """
1884 return self.api(
1885 self.papi.nat64_add_del_interface,
1886 {'sw_if_index': sw_if_index,
1887 'is_inside': is_inside,
1888 'is_add': is_add})
1889
1890 def nat64_interface_dump(self):
1891 """Dump interfaces with NAT64 feature
1892 :return: Dictionary of interfaces with NAT64 feature
1893 """
1894 return self.api(self.papi.nat64_interface_dump, {})
1895
1896 def nat64_add_del_static_bib(
1897 self,
1898 in_ip,
1899 out_ip,
1900 in_port,
1901 out_port,
1902 protocol,
1903 vrf_id=0,
1904 is_add=1):
1905 """Add/delete S-NAT static BIB entry
1906
1907 :param in_ip: Inside IPv6 address
1908 :param out_ip: Outside IPv4 address
1909 :param in_port: Inside port number
1910 :param out_port: Outside port number
1911 :param protocol: IP protocol
1912 :param vrf_id: VRF ID (Default value = 0)
1913 :param is_add: 1 if add, 0 if delete (Default value = 1)
1914 """
1915 return self.api(
1916 self.papi.nat64_add_del_static_bib,
1917 {'i_addr': in_ip,
1918 'o_addr': out_ip,
1919 'i_port': in_port,
1920 'o_port': out_port,
1921 'vrf_id': vrf_id,
1922 'proto': protocol,
1923 'is_add': is_add})
1924
Matus Fabianab9a59c2017-08-16 05:37:36 -07001925 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001926 """Dump NAT64 BIB
1927
Matus Fabianab9a59c2017-08-16 05:37:36 -07001928 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001929 :returns: Dictionary of NAT64 BIB entries
1930 """
1931 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1932
1933 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1934 tcp_incoming_syn=6):
1935 """Set values of timeouts for NAT64 (in seconds)
1936
Matus Fabian428dc912017-06-21 06:15:18 -07001937 :param udpi: UDP timeout (Default value = 300)
1938 :param icmp: ICMP timeout (Default value = 60)
1939 :param tcp_trans: TCP transitory timeout (Default value = 240)
1940 :param tcp_est: TCP established timeout (Default value = 7440)
1941 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001942 """
1943 return self.api(
1944 self.papi.nat64_set_timeouts,
1945 {'udp': udp,
1946 'icmp': icmp,
1947 'tcp_trans': tcp_trans,
1948 'tcp_est': tcp_est,
1949 'tcp_incoming_syn': tcp_incoming_syn})
1950
1951 def nat64_get_timeouts(self):
1952 """Get values of timeouts for NAT64
1953
1954 :return: Timeouts for NAT64 (in seconds)
1955 """
1956 return self.api(self.papi.nat64_get_timeouts, {})
1957
Matus Fabianab9a59c2017-08-16 05:37:36 -07001958 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001959 """Dump NAT64 session table
1960
Matus Fabianab9a59c2017-08-16 05:37:36 -07001961 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001962 :returns: Dictionary of NAT64 sesstion table entries
1963 """
1964 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1965
Matus Fabian428dc912017-06-21 06:15:18 -07001966 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1967 """Add/del NAT64 prefix
1968
1969 :param prefix: NAT64 prefix
1970 :param plen: NAT64 prefix length
1971 :param vrf_id: VRF id of tenant (Default 0)
1972 :param is_add: 1 if add, 0 if delete (Default value = 1)
1973 """
1974 return self.api(
1975 self.papi.nat64_add_del_prefix,
1976 {'prefix': prefix,
1977 'prefix_len': plen,
1978 'vrf_id': vrf_id,
1979 'is_add': is_add})
1980
1981 def nat64_prefix_dump(self):
1982 """Dump NAT64 prefix
1983
1984 :returns: Dictionary of NAT64 prefixes
1985 """
1986 return self.api(self.papi.nat64_prefix_dump, {})
1987
Matus Fabian0938dcf2017-11-08 01:59:38 -08001988 def nat64_add_interface_addr(
1989 self,
1990 sw_if_index,
1991 is_add=1):
1992 """Add/del NAT64 address from interface
1993
1994 :param sw_if_index: Software index of the interface
1995 :param is_add: 1 if add, 0 if delete (Default value = 1)
1996 """
1997 return self.api(self.papi.nat64_add_del_interface_addr,
1998 {'is_add': is_add, 'sw_if_index': sw_if_index})
1999
Matus Fabian8ebe6252017-11-06 05:04:53 -08002000 def dslite_set_aftr_addr(self, ip6, ip4):
2001 """Set DS-Lite AFTR addresses
2002
2003 :param ip4: IPv4 address
2004 :param ip6: IPv6 address
2005 """
2006 return self.api(
2007 self.papi.dslite_set_aftr_addr,
2008 {'ip4_addr': ip4,
2009 'ip6_addr': ip6})
2010
Juraj Slobodac5c6a332018-01-09 16:08:32 +01002011 def dslite_set_b4_addr(self, ip6, ip4):
2012 """Set DS-Lite B4 IPv6 address
2013
2014 :param ip4: IPv4 address
2015 :param ip6: IPv6 address
2016 """
2017 return self.api(
2018 self.papi.dslite_set_b4_addr,
2019 {'ip4_addr': ip4,
2020 'ip6_addr': ip6})
2021
Matus Fabian8ebe6252017-11-06 05:04:53 -08002022 def dslite_add_del_pool_addr_range(
2023 self,
2024 start_addr,
2025 end_addr,
2026 is_add=1):
2027 """Add/del address range to DS-Lite pool
2028
2029 :param start_addr: First IP address
2030 :param end_addr: Last IP address
2031 :param is_add: 1 if add, 0 if delete (Default value = 1)
2032 """
2033 return self.api(
2034 self.papi.dslite_add_del_pool_addr_range,
2035 {'start_addr': start_addr,
2036 'end_addr': end_addr,
2037 'is_add': is_add})
2038
Matus Fabianf2a23cc2018-01-22 03:41:53 -08002039 def nat66_add_del_interface(
2040 self,
2041 sw_if_index,
2042 is_inside=1,
2043 is_add=1):
2044 """Enable/disable NAT66 feature on the interface
2045 :param sw_if_index: Index of the interface
2046 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2047 :param is_add: 1 if add, 0 if delete (Default value = 1)
2048 """
2049 return self.api(
2050 self.papi.nat66_add_del_interface,
2051 {'sw_if_index': sw_if_index,
2052 'is_inside': is_inside,
2053 'is_add': is_add})
2054
2055 def nat66_add_del_static_mapping(
2056 self,
2057 in_ip,
2058 out_ip,
2059 vrf_id=0,
2060 is_add=1):
2061 """Add/delete NAT66 static mapping
2062
2063 :param in_ip: Inside IPv6 address
2064 :param out_ip: Outside IPv6 address
2065 :param vrf_id: VRF ID (Default value = 0)
2066 :param is_add: 1 if add, 0 if delete (Default value = 1)
2067 """
2068 return self.api(
2069 self.papi.nat66_add_del_static_mapping,
2070 {'local_ip_address': in_ip,
2071 'external_ip_address': out_ip,
2072 'vrf_id': vrf_id,
2073 'is_add': is_add})
2074
2075 def nat66_interface_dump(self):
2076 """Dump interfaces with NAT66 feature
2077 :return: Dictionary of interfaces with NAT66 feature
2078 """
2079 return self.api(self.papi.nat66_interface_dump, {})
2080
2081 def nat66_static_mapping_dump(self):
2082 """Dump NAT66 static mappings
2083 :return: Dictionary of NAT66 static mappings
2084 """
2085 return self.api(self.papi.nat66_static_mapping_dump, {})
2086
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002087 def control_ping(self):
2088 self.api(self.papi.control_ping)
2089
2090 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002091 detect_mult, local_addr, peer_addr, is_ipv6=0,
2092 bfd_key_id=None, conf_key_id=None):
2093 if bfd_key_id is None:
2094 return self.api(self.papi.bfd_udp_add,
2095 {
2096 'sw_if_index': sw_if_index,
2097 'desired_min_tx': desired_min_tx,
2098 'required_min_rx': required_min_rx,
2099 'local_addr': local_addr,
2100 'peer_addr': peer_addr,
2101 'is_ipv6': is_ipv6,
2102 'detect_mult': detect_mult,
2103 })
2104 else:
2105 return self.api(self.papi.bfd_udp_add,
2106 {
2107 'sw_if_index': sw_if_index,
2108 'desired_min_tx': desired_min_tx,
2109 'required_min_rx': required_min_rx,
2110 'local_addr': local_addr,
2111 'peer_addr': peer_addr,
2112 'is_ipv6': is_ipv6,
2113 'detect_mult': detect_mult,
2114 'is_authenticated': 1,
2115 'bfd_key_id': bfd_key_id,
2116 'conf_key_id': conf_key_id,
2117 })
2118
Klement Sekeraa57a9702017-02-02 06:58:07 +01002119 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2120 detect_mult, local_addr, peer_addr, is_ipv6=0):
2121 return self.api(self.papi.bfd_udp_mod,
2122 {
2123 'sw_if_index': sw_if_index,
2124 'desired_min_tx': desired_min_tx,
2125 'required_min_rx': required_min_rx,
2126 'local_addr': local_addr,
2127 'peer_addr': peer_addr,
2128 'is_ipv6': is_ipv6,
2129 'detect_mult': detect_mult,
2130 })
2131
Klement Sekerab17dd962017-01-09 07:43:48 +01002132 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2133 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2134 is_delayed=False):
2135 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002136 {
2137 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002138 'local_addr': local_addr,
2139 'peer_addr': peer_addr,
2140 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002141 'is_delayed': 1 if is_delayed else 0,
2142 'bfd_key_id': bfd_key_id,
2143 'conf_key_id': conf_key_id,
2144 })
2145
2146 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2147 is_ipv6=0, is_delayed=False):
2148 return self.api(self.papi.bfd_udp_auth_deactivate,
2149 {
2150 'sw_if_index': sw_if_index,
2151 'local_addr': local_addr,
2152 'peer_addr': peer_addr,
2153 'is_ipv6': is_ipv6,
2154 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002155 })
2156
2157 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2158 return self.api(self.papi.bfd_udp_del,
2159 {
2160 'sw_if_index': sw_if_index,
2161 'local_addr': local_addr,
2162 'peer_addr': peer_addr,
2163 'is_ipv6': is_ipv6,
2164 })
2165
2166 def bfd_udp_session_dump(self):
2167 return self.api(self.papi.bfd_udp_session_dump, {})
2168
Klement Sekerab17dd962017-01-09 07:43:48 +01002169 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2170 peer_addr, is_ipv6=0):
2171 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002172 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002173 'sw_if_index': sw_if_index,
2174 'local_addr': local_addr,
2175 'peer_addr': peer_addr,
2176 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002177 })
2178
2179 def want_bfd_events(self, enable_disable=1):
2180 return self.api(self.papi.want_bfd_events, {
2181 'enable_disable': enable_disable,
2182 'pid': os.getpid(),
2183 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002184
Klement Sekerab17dd962017-01-09 07:43:48 +01002185 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2186 return self.api(self.papi.bfd_auth_set_key, {
2187 'conf_key_id': conf_key_id,
2188 'auth_type': auth_type,
2189 'key': key,
2190 'key_len': len(key),
2191 })
2192
2193 def bfd_auth_del_key(self, conf_key_id):
2194 return self.api(self.papi.bfd_auth_del_key, {
2195 'conf_key_id': conf_key_id,
2196 })
2197
2198 def bfd_auth_keys_dump(self):
2199 return self.api(self.papi.bfd_auth_keys_dump, {})
2200
Klement Sekera239790f2017-02-16 10:53:53 +01002201 def bfd_udp_set_echo_source(self, sw_if_index):
2202 return self.api(self.papi.bfd_udp_set_echo_source,
2203 {'sw_if_index': sw_if_index})
2204
Klement Sekera73884482017-02-23 09:26:30 +01002205 def bfd_udp_del_echo_source(self):
2206 return self.api(self.papi.bfd_udp_del_echo_source, {})
2207
Steve Shin7957d6e2016-12-19 09:24:50 -08002208 def classify_add_del_table(
2209 self,
2210 is_add,
2211 mask,
2212 match_n_vectors=1,
2213 table_index=0xFFFFFFFF,
2214 nbuckets=2,
2215 memory_size=2097152,
2216 skip_n_vectors=0,
2217 next_table_index=0xFFFFFFFF,
2218 miss_next_index=0xFFFFFFFF,
2219 current_data_flag=0,
2220 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002221 """
2222 :param is_add:
2223 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002224 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002225 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002226 :param nbuckets: (Default value = 2)
2227 :param memory_size: (Default value = 2097152)
2228 :param skip_n_vectors: (Default value = 0)
2229 :param next_table_index: (Default value = 0xFFFFFFFF)
2230 :param miss_next_index: (Default value = 0xFFFFFFFF)
2231 :param current_data_flag: (Default value = 0)
2232 :param current_data_offset: (Default value = 0)
2233 """
2234
2235 return self.api(
2236 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002237 {'is_add': is_add,
2238 'table_index': table_index,
2239 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002240 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002241 'skip_n_vectors': skip_n_vectors,
2242 'match_n_vectors': match_n_vectors,
2243 'next_table_index': next_table_index,
2244 'miss_next_index': miss_next_index,
2245 'current_data_flag': current_data_flag,
2246 'current_data_offset': current_data_offset,
2247 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002248
2249 def classify_add_del_session(
2250 self,
2251 is_add,
2252 table_index,
2253 match,
2254 opaque_index=0xFFFFFFFF,
2255 hit_next_index=0xFFFFFFFF,
2256 advance=0,
2257 action=0,
2258 metadata=0):
2259 """
2260 :param is_add:
2261 :param table_index:
2262 :param match:
2263 :param opaque_index: (Default value = 0xFFFFFFFF)
2264 :param hit_next_index: (Default value = 0xFFFFFFFF)
2265 :param advance: (Default value = 0)
2266 :param action: (Default value = 0)
2267 :param metadata: (Default value = 0)
2268 """
2269
2270 return self.api(
2271 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002272 {'is_add': is_add,
2273 'table_index': table_index,
2274 'hit_next_index': hit_next_index,
2275 'opaque_index': opaque_index,
2276 'advance': advance,
2277 'action': action,
2278 'metadata': metadata,
2279 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002280
2281 def input_acl_set_interface(
2282 self,
2283 is_add,
2284 sw_if_index,
2285 ip4_table_index=0xFFFFFFFF,
2286 ip6_table_index=0xFFFFFFFF,
2287 l2_table_index=0xFFFFFFFF):
2288 """
2289 :param is_add:
2290 :param sw_if_index:
2291 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2292 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2293 :param l2_table_index: (Default value = 0xFFFFFFFF)
2294 """
2295
2296 return self.api(
2297 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002298 {'sw_if_index': sw_if_index,
2299 'ip4_table_index': ip4_table_index,
2300 'ip6_table_index': ip6_table_index,
2301 'l2_table_index': l2_table_index,
2302 'is_add': is_add})
2303
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002304 def output_acl_set_interface(
2305 self,
2306 is_add,
2307 sw_if_index,
2308 ip4_table_index=0xFFFFFFFF,
2309 ip6_table_index=0xFFFFFFFF,
2310 l2_table_index=0xFFFFFFFF):
2311 """
2312 :param is_add:
2313 :param sw_if_index:
2314 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2315 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2316 :param l2_table_index: (Default value = 0xFFFFFFFF)
2317 """
2318
2319 return self.api(
2320 self.papi.output_acl_set_interface,
2321 {'sw_if_index': sw_if_index,
2322 'ip4_table_index': ip4_table_index,
2323 'ip6_table_index': ip6_table_index,
2324 'l2_table_index': l2_table_index,
2325 'is_add': is_add})
2326
Klement Sekera77fabdb2017-01-02 07:46:14 +01002327 def set_ipfix_exporter(
2328 self,
2329 collector_address,
2330 src_address,
2331 path_mtu,
2332 template_interval,
2333 vrf_id=0,
2334 collector_port=4739,
2335 udp_checksum=0):
2336 return self.api(
2337 self.papi.set_ipfix_exporter,
2338 {
2339 'collector_address': collector_address,
2340 'collector_port': collector_port,
2341 'src_address': src_address,
2342 'vrf_id': vrf_id,
2343 'path_mtu': path_mtu,
2344 'template_interval': template_interval,
2345 'udp_checksum': udp_checksum,
2346 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002347
2348 def dhcp_proxy_config(self,
2349 dhcp_server,
2350 dhcp_src_address,
2351 rx_table_id=0,
2352 server_table_id=0,
2353 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002354 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002355 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002356 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002357 {
2358 'rx_vrf_id': rx_table_id,
2359 'server_vrf_id': server_table_id,
2360 'is_ipv6': is_ipv6,
2361 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002362 'dhcp_server': dhcp_server,
2363 'dhcp_src_address': dhcp_src_address,
2364 })
2365
2366 def dhcp_proxy_set_vss(self,
2367 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002368 vss_type=255,
2369 vpn_ascii_id="",
2370 oui=0,
2371 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002372 is_add=1,
2373 is_ip6=0):
2374 return self.api(
2375 self.papi.dhcp_proxy_set_vss,
2376 {
2377 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002378 'vss_type': vss_type,
2379 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002380 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002381 'vpn_index': vpn_index,
2382 'is_add': is_add,
2383 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002384 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002385
Neale Rannsdaff1782018-05-16 04:12:18 -07002386 def dhcp_client_dump(self):
2387 return self.api(self.papi.dhcp_client_dump, {})
2388
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002389 def dhcp_client(self,
2390 sw_if_index,
2391 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002392 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002393 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002394 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002395 want_dhcp_events=0):
2396 return self.api(
2397 self.papi.dhcp_client_config,
2398 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002399 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002400 'client': {
2401 'sw_if_index': sw_if_index,
2402 'hostname': hostname,
2403 'id': client_id,
2404 'want_dhcp_event': want_dhcp_events,
2405 'set_broadcast_flag': set_broadcast_flag,
2406 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002407 })
2408
Neale Ranns32e1c012016-11-22 17:07:28 +00002409 def ip_mroute_add_del(self,
2410 src_address,
2411 grp_address,
2412 grp_address_length,
2413 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002414 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002415 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002416 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002417 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002418 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002419 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002420 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002421 is_add=1,
2422 is_ipv6=0,
2423 is_local=0):
2424 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002425 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002426 """
2427 return self.api(
2428 self.papi.ip_mroute_add_del,
2429 {'next_hop_sw_if_index': next_hop_sw_if_index,
2430 'entry_flags': e_flags,
2431 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002432 'table_id': table_id,
2433 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002434 'is_add': is_add,
2435 'is_ipv6': is_ipv6,
2436 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002437 'bier_imp': bier_imp,
2438 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002439 'grp_address_length': grp_address_length,
2440 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002441 'src_address': src_address,
2442 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002443
2444 def mfib_signal_dump(self):
2445 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002446
2447 def ip_mfib_dump(self):
2448 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002449
Neale Rannsd792d9c2017-10-21 10:53:20 -07002450 def ip6_mfib_dump(self):
2451 return self.api(self.papi.ip6_mfib_dump, {})
2452
Filip Tehlar770e89e2017-01-31 10:39:16 +01002453 def lisp_enable_disable(self, is_enabled):
2454 return self.api(
2455 self.papi.lisp_enable_disable,
2456 {
2457 'is_en': is_enabled,
2458 })
2459
2460 def lisp_locator_set(self,
2461 ls_name,
2462 is_add=1):
2463 return self.api(
2464 self.papi.lisp_add_del_locator_set,
2465 {
2466 'is_add': is_add,
2467 'locator_set_name': ls_name
2468 })
2469
2470 def lisp_locator_set_dump(self):
2471 return self.api(self.papi.lisp_locator_set_dump, {})
2472
2473 def lisp_locator(self,
2474 ls_name,
2475 sw_if_index,
2476 priority=1,
2477 weight=1,
2478 is_add=1):
2479 return self.api(
2480 self.papi.lisp_add_del_locator,
2481 {
2482 'is_add': is_add,
2483 'locator_set_name': ls_name,
2484 'sw_if_index': sw_if_index,
2485 'priority': priority,
2486 'weight': weight
2487 })
2488
2489 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2490 return self.api(
2491 self.papi.lisp_locator_dump,
2492 {
2493 'is_index_set': is_index_set,
2494 'ls_name': ls_name,
2495 'ls_index': ls_index,
2496 })
2497
2498 def lisp_local_mapping(self,
2499 ls_name,
2500 eid_type,
2501 eid,
2502 prefix_len,
2503 vni=0,
2504 key_id=0,
2505 key="",
2506 is_add=1):
2507 return self.api(
2508 self.papi.lisp_add_del_local_eid,
2509 {
2510 'locator_set_name': ls_name,
2511 'is_add': is_add,
2512 'eid_type': eid_type,
2513 'eid': eid,
2514 'prefix_len': prefix_len,
2515 'vni': vni,
2516 'key_id': key_id,
2517 'key': key
2518 })
2519
2520 def lisp_eid_table_dump(self,
2521 eid_set=0,
2522 prefix_length=0,
2523 vni=0,
2524 eid_type=0,
2525 eid=None,
2526 filter_opt=0):
2527 return self.api(
2528 self.papi.lisp_eid_table_dump,
2529 {
2530 'eid_set': eid_set,
2531 'prefix_length': prefix_length,
2532 'vni': vni,
2533 'eid_type': eid_type,
2534 'eid': eid,
2535 'filter': filter_opt,
2536 })
2537
2538 def lisp_remote_mapping(self,
2539 eid_type,
2540 eid,
2541 eid_prefix_len=0,
2542 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002543 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002544 rlocs_num=0,
2545 is_src_dst=0,
2546 is_add=1):
2547 return self.api(
2548 self.papi.lisp_add_del_remote_mapping,
2549 {
2550 'is_add': is_add,
2551 'eid_type': eid_type,
2552 'eid': eid,
2553 'eid_len': eid_prefix_len,
2554 'rloc_num': rlocs_num,
2555 'rlocs': rlocs,
2556 'vni': vni,
2557 'is_src_dst': is_src_dst,
2558 })
2559
2560 def lisp_adjacency(self,
2561 leid,
2562 reid,
2563 leid_len,
2564 reid_len,
2565 eid_type,
2566 is_add=1,
2567 vni=0):
2568 return self.api(
2569 self.papi.lisp_add_del_adjacency,
2570 {
2571 'is_add': is_add,
2572 'vni': vni,
2573 'eid_type': eid_type,
2574 'leid': leid,
2575 'reid': reid,
2576 'leid_len': leid_len,
2577 'reid_len': reid_len,
2578 })
2579
2580 def lisp_adjacencies_get(self, vni=0):
2581 return self.api(
2582 self.papi.lisp_adjacencies_get,
2583 {
2584 'vni': vni
2585 })
Neale Ranns80823802017-02-20 18:23:41 -08002586
2587 def map_add_domain(self,
2588 ip6_prefix,
2589 ip6_prefix_len,
2590 ip6_src,
2591 ip6_src_prefix_len,
2592 ip4_prefix,
2593 ip4_prefix_len,
2594 ea_bits_len=0,
2595 psid_offset=0,
2596 psid_length=0,
2597 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002598 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002599 mtu=1280):
2600 return self.api(
2601 self.papi.map_add_domain,
2602 {
2603 'ip6_prefix': ip6_prefix,
2604 'ip6_prefix_len': ip6_prefix_len,
2605 'ip4_prefix': ip4_prefix,
2606 'ip4_prefix_len': ip4_prefix_len,
2607 'ip6_src': ip6_src,
2608 'ip6_src_prefix_len': ip6_src_prefix_len,
2609 'ea_bits_len': ea_bits_len,
2610 'psid_offset': psid_offset,
2611 'psid_length': psid_length,
2612 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002613 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002614 'mtu': mtu
2615 })
Hongjun Nief486b12017-04-12 19:21:16 +08002616
2617 def gtpu_add_del_tunnel(
2618 self,
2619 src_addr,
2620 dst_addr,
2621 is_add=1,
2622 is_ipv6=0,
2623 mcast_sw_if_index=0xFFFFFFFF,
2624 encap_vrf_id=0,
2625 decap_next_index=0xFFFFFFFF,
2626 teid=0):
2627 """
2628
2629 :param is_add: (Default value = 1)
2630 :param is_ipv6: (Default value = 0)
2631 :param src_addr:
2632 :param dst_addr:
2633 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2634 :param encap_vrf_id: (Default value = 0)
2635 :param decap_next_index: (Default value = 0xFFFFFFFF)
2636 :param teid: (Default value = 0)
2637
2638 """
2639 return self.api(self.papi.gtpu_add_del_tunnel,
2640 {'is_add': is_add,
2641 'is_ipv6': is_ipv6,
2642 'src_address': src_addr,
2643 'dst_address': dst_addr,
2644 'mcast_sw_if_index': mcast_sw_if_index,
2645 'encap_vrf_id': encap_vrf_id,
2646 'decap_next_index': decap_next_index,
2647 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002648
2649 def vxlan_gpe_add_del_tunnel(
2650 self,
2651 src_addr,
2652 dst_addr,
2653 mcast_sw_if_index=0xFFFFFFFF,
2654 is_add=1,
2655 is_ipv6=0,
2656 encap_vrf_id=0,
2657 decap_vrf_id=0,
2658 protocol=3,
2659 vni=0):
2660 """
2661
2662 :param local:
2663 :param remote:
2664 :param is_add: (Default value = 1)
2665 :param is_ipv6: (Default value = 0)
2666 :param encap_vrf_id: (Default value = 0)
2667 :param decap_vrf_id: (Default value = 0)
2668 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2669 :param protocol: (Default value = 3)
2670 :param vni: (Default value = 0)
2671
2672 """
2673 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2674 {'is_add': is_add,
2675 'is_ipv6': is_ipv6,
2676 'local': src_addr,
2677 'remote': dst_addr,
2678 'mcast_sw_if_index': mcast_sw_if_index,
2679 'encap_vrf_id': encap_vrf_id,
2680 'decap_vrf_id': decap_vrf_id,
2681 'protocol': protocol,
2682 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002683
2684 def pppoe_add_del_session(
2685 self,
2686 client_ip,
2687 client_mac,
2688 session_id=0,
2689 is_add=1,
2690 is_ipv6=0,
2691 decap_vrf_id=0):
2692 """
2693
2694 :param is_add: (Default value = 1)
2695 :param is_ipv6: (Default value = 0)
2696 :param client_ip:
2697 :param session_id: (Default value = 0)
2698 :param client_mac:
2699 :param decap_vrf_id: (Default value = 0)
2700
2701 """
2702 return self.api(self.papi.pppoe_add_del_session,
2703 {'is_add': is_add,
2704 'is_ipv6': is_ipv6,
2705 'session_id': session_id,
2706 'client_ip': client_ip,
2707 'decap_vrf_id': decap_vrf_id,
2708 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002709
2710 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002711 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002712 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002713 nh_addr4,
2714 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02002715 is_del=0,
2716 end_psp=0,
2717 sw_if_index=0xFFFFFFFF,
2718 vlan_index=0,
2719 fib_table=0,
2720 ):
2721 """ Add/del IPv6 SR local-SID.
2722
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002723 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02002724 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2725 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002726 :param nh_addr4:
2727 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02002728 :param is_del: (Default value = 0)
2729 :param end_psp: (Default value = 0)
2730 :param sw_if_index: (Default value = 0xFFFFFFFF)
2731 :param vlan_index: (Default value = 0)
2732 :param fib_table: (Default value = 0)
2733 """
2734 return self.api(
2735 self.papi.sr_localsid_add_del,
2736 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002737 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02002738 'end_psp': end_psp,
2739 'behavior': behavior,
2740 'sw_if_index': sw_if_index,
2741 'vlan_index': vlan_index,
2742 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02002743 'nh_addr4': nh_addr4,
2744 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02002745 }
2746 )
2747
2748 def sr_policy_add(
2749 self,
2750 bsid_addr,
2751 weight=1,
2752 is_encap=1,
2753 type=0,
2754 fib_table=0,
2755 n_segments=0,
2756 segments=[]):
2757 """
2758 :param bsid_addr: bindingSID of the SR Policy
2759 :param weight: weight of the sid list. optional. (default: 1)
2760 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2761 (default: Encap)
2762 :param type: type/behavior of the SR policy. (default or spray) \
2763 (default: default)
2764 :param fib_table: VRF where to install the FIB entry for the BSID \
2765 (default: 0)
2766 :param n_segments: number of segments \
2767 (default: 0)
2768 :param segments: a vector of IPv6 address composing the segment list \
2769 (default: [])
2770 """
2771 return self.api(
2772 self.papi.sr_policy_add,
2773 {'bsid_addr': bsid_addr,
2774 'weight': weight,
2775 'is_encap': is_encap,
2776 'type': type,
2777 'fib_table': fib_table,
2778 'n_segments': n_segments,
2779 'segments': segments
2780 }
2781 )
2782
2783 def sr_policy_del(
2784 self,
2785 bsid_addr,
2786 sr_policy_index=0):
2787 """
2788 :param bsid: bindingSID of the SR Policy
2789 :param sr_policy_index: index of the sr policy (default: 0)
2790 """
2791 return self.api(
2792 self.papi.sr_policy_del,
2793 {'bsid_addr': bsid_addr,
2794 'sr_policy_index': sr_policy_index
2795 })
2796
2797 def sr_steering_add_del(
2798 self,
2799 is_del,
2800 bsid_addr,
2801 sr_policy_index,
2802 table_id,
2803 prefix_addr,
2804 mask_width,
2805 sw_if_index,
2806 traffic_type):
2807 """
2808 Steer traffic L2 and L3 traffic through a given SR policy
2809
2810 :param is_del: delete or add
2811 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2812 :param sr_policy: is the index of the SR Policy (alt to bsid)
2813 :param table_id: is the VRF where to install the FIB entry for the BSID
2814 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2815 :param mask_width: is the mask for L3 traffic type
2816 :param sw_if_index: is the incoming interface for L2 traffic
2817 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2818 """
2819 return self.api(
2820 self.papi.sr_steering_add_del,
2821 {'is_del': is_del,
2822 'bsid_addr': bsid_addr,
2823 'sr_policy_index': sr_policy_index,
2824 'table_id': table_id,
2825 'prefix_addr': prefix_addr,
2826 'mask_width': mask_width,
2827 'sw_if_index': sw_if_index,
2828 'traffic_type': traffic_type
2829 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002830
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002831 def acl_add_replace(self, acl_index, r, tag='',
2832 expected_retval=0):
2833 """Add/replace an ACL
2834 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2835 :param acl_rule r: ACL rules array.
2836 :param str tag: symbolic tag (description) for this ACL.
2837 :param int count: number of rules.
2838 """
2839 return self.api(self.papi.acl_add_replace,
2840 {'acl_index': acl_index,
2841 'r': r,
2842 'count': len(r),
2843 'tag': tag},
2844 expected_retval=expected_retval)
2845
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002846 def acl_del(self, acl_index, expected_retval=0):
2847 """
2848
2849 :param acl_index:
2850 :return:
2851 """
2852 return self.api(self.papi.acl_del,
2853 {'acl_index': acl_index},
2854 expected_retval=expected_retval)
2855
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002856 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2857 expected_retval=0):
2858 return self.api(self.papi.acl_interface_set_acl_list,
2859 {'sw_if_index': sw_if_index,
2860 'count': len(acls),
2861 'n_input': n_input,
2862 'acls': acls},
2863 expected_retval=expected_retval)
2864
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002865 def acl_interface_set_etype_whitelist(self, sw_if_index,
2866 n_input, whitelist,
2867 expected_retval=0):
2868 return self.api(self.papi.acl_interface_set_etype_whitelist,
2869 {'sw_if_index': sw_if_index,
2870 'count': len(whitelist),
2871 'n_input': n_input,
2872 'whitelist': whitelist},
2873 expected_retval=expected_retval)
2874
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002875 def acl_interface_add_del(self,
2876 sw_if_index,
2877 acl_index,
2878 is_add=1):
2879 """ Add/Delete ACL to/from interface
2880
2881 :param sw_if_index:
2882 :param acl_index:
2883 :param is_add: (Default value = 1)
2884 """
2885
2886 return self.api(self.papi.acl_interface_add_del,
2887 {'is_add': is_add,
2888 'is_input': 1,
2889 'sw_if_index': sw_if_index,
2890 'acl_index': acl_index})
2891
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002892 def acl_dump(self, acl_index, expected_retval=0):
2893 return self.api(self.papi.acl_dump,
2894 {'acl_index': acl_index},
2895 expected_retval=expected_retval)
2896
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002897 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2898 expected_retval=0):
2899 return self.api(self.papi.acl_interface_list_dump,
2900 {'sw_if_index': sw_if_index},
2901 expected_retval=expected_retval)
2902
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002903 def macip_acl_add(self, rules, tag=""):
2904 """ Add MACIP acl
2905
2906 :param rules: list of rules for given acl
2907 :param tag: acl tag
2908 """
2909
2910 return self.api(self.papi.macip_acl_add,
2911 {'r': rules,
2912 'count': len(rules),
2913 'tag': tag})
2914
Pavel Kotucek932f7412017-09-07 14:44:52 +02002915 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2916 """ Add MACIP acl
2917
2918 :param rules: list of rules for given acl
2919 :param tag: acl tag
2920 """
2921
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002922 return self.api(self.papi.macip_acl_add_replace,
2923 {'acl_index': acl_index,
2924 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002925 'count': len(rules),
2926 'tag': tag})
2927
2928 def macip_acl_del(self, acl_index):
2929 """
2930
2931 :param acl_index:
2932 :return:
2933 """
2934 return self.api(self.papi.macip_acl_del,
2935 {'acl_index': acl_index})
2936
2937 def macip_acl_interface_add_del(self,
2938 sw_if_index,
2939 acl_index,
2940 is_add=1):
2941 """ Add MACIP acl to interface
2942
2943 :param sw_if_index:
2944 :param acl_index:
2945 :param is_add: (Default value = 1)
2946 """
2947
2948 return self.api(self.papi.macip_acl_interface_add_del,
2949 {'is_add': is_add,
2950 'sw_if_index': sw_if_index,
2951 'acl_index': acl_index})
2952
2953 def macip_acl_interface_get(self):
2954 """ Return interface acls dump
2955 """
2956 return self.api(
2957 self.papi.macip_acl_interface_get, {})
2958
2959 def macip_acl_dump(self, acl_index=4294967295):
2960 """ Return MACIP acl dump
2961 """
2962
2963 return self.api(
2964 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002965
2966 def policer_add_del(self,
2967 name,
2968 cir,
2969 eir,
2970 cb,
2971 eb,
2972 is_add=1,
2973 rate_type=0,
2974 round_type=0,
2975 ptype=0,
2976 color_aware=0,
2977 conform_action_type=1,
2978 conform_dscp=0,
2979 exceed_action_type=0,
2980 exceed_dscp=0,
2981 violate_action_type=0,
2982 violate_dscp=0):
2983 return self.api(self.papi.policer_add_del,
2984 {'name': name,
2985 'cir': cir,
2986 'eir': eir,
2987 'cb': cb,
2988 'eb': eb,
2989 'is_add': is_add,
2990 'rate_type': rate_type,
2991 'round_type': round_type,
2992 'type': ptype,
2993 'color_aware': color_aware,
2994 'conform_action_type': conform_action_type,
2995 'conform_dscp': conform_dscp,
2996 'exceed_action_type': exceed_action_type,
2997 'exceed_dscp': exceed_dscp,
2998 'violate_action_type': violate_action_type,
2999 'violate_dscp': violate_dscp})
3000
3001 def ip_punt_police(self,
3002 policer_index,
3003 is_ip6=0,
3004 is_add=1):
3005 return self.api(self.papi.ip_punt_police,
3006 {'policer_index': policer_index,
3007 'is_add': is_add,
3008 'is_ip6': is_ip6})
3009
3010 def ip_punt_redirect(self,
3011 rx_sw_if_index,
3012 tx_sw_if_index,
3013 nh,
3014 is_ip6=0,
3015 is_add=1):
3016 return self.api(self.papi.ip_punt_redirect,
3017 {'rx_sw_if_index': rx_sw_if_index,
3018 'tx_sw_if_index': tx_sw_if_index,
3019 'nh': nh,
3020 'is_add': is_add,
3021 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003022
3023 def bier_table_add_del(self,
3024 bti,
3025 mpls_label,
3026 is_add=1):
3027 """ BIER Table add/del """
3028 return self.api(
3029 self.papi.bier_table_add_del,
3030 {'bt_tbl_id': {"bt_set": bti.set_id,
3031 "bt_sub_domain": bti.sub_domain_id,
3032 "bt_hdr_len_id": bti.hdr_len_id},
3033 'bt_label': mpls_label,
3034 'bt_is_add': is_add})
3035
3036 def bier_table_dump(self):
3037 return self.api(self.papi.bier_table_dump, {})
3038
3039 def bier_route_add_del(self,
3040 bti,
3041 bp,
Neale Ranns91286372017-12-05 13:24:04 -08003042 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003043 is_add=1):
3044 """ BIER Route add/del """
3045 return self.api(
3046 self.papi.bier_route_add_del,
3047 {'br_tbl_id': {"bt_set": bti.set_id,
3048 "bt_sub_domain": bti.sub_domain_id,
3049 "bt_hdr_len_id": bti.hdr_len_id},
3050 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003051 'br_n_paths': len(paths),
3052 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003053 'br_is_add': is_add})
3054
3055 def bier_route_dump(self, bti):
3056 return self.api(
3057 self.papi.bier_route_dump,
3058 {'br_tbl_id': {"bt_set": bti.set_id,
3059 "bt_sub_domain": bti.sub_domain_id,
3060 "bt_hdr_len_id": bti.hdr_len_id}})
3061
3062 def bier_imp_add(self,
3063 bti,
3064 src,
3065 ibytes,
3066 is_add=1):
3067 """ BIER Imposition Add """
3068 return self.api(
3069 self.papi.bier_imp_add,
3070 {'bi_tbl_id': {"bt_set": bti.set_id,
3071 "bt_sub_domain": bti.sub_domain_id,
3072 "bt_hdr_len_id": bti.hdr_len_id},
3073 'bi_src': src,
3074 'bi_n_bytes': len(ibytes),
3075 'bi_bytes': ibytes})
3076
3077 def bier_imp_del(self, bi_index):
3078 """ BIER Imposition del """
3079 return self.api(
3080 self.papi.bier_imp_del,
3081 {'bi_index': bi_index})
3082
3083 def bier_imp_dump(self):
3084 return self.api(self.papi.bier_imp_dump, {})
3085
3086 def bier_disp_table_add_del(self,
3087 bdti,
3088 is_add=1):
3089 """ BIER Disposition Table add/del """
3090 return self.api(
3091 self.papi.bier_disp_table_add_del,
3092 {'bdt_tbl_id': bdti,
3093 'bdt_is_add': is_add})
3094
3095 def bier_disp_table_dump(self):
3096 return self.api(self.papi.bier_disp_table_dump, {})
3097
3098 def bier_disp_entry_add_del(self,
3099 bdti,
3100 bp,
3101 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003102 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003103 next_hop,
3104 next_hop_tbl_id=0,
3105 next_hop_rpf_id=~0,
3106 next_hop_is_ip4=1,
3107 is_add=1):
3108 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003109 lstack = []
3110 while (len(lstack) < 16):
3111 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003112 return self.api(
3113 self.papi.bier_disp_entry_add_del,
3114 {'bde_tbl_id': bdti,
3115 'bde_bp': bp,
3116 'bde_payload_proto': payload_proto,
3117 'bde_n_paths': 1,
3118 'bde_paths': [{'next_hop': next_hop,
3119 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003120 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003121 'rpf_id': next_hop_rpf_id,
3122 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003123 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003124 'bde_is_add': is_add})
3125
3126 def bier_disp_entry_dump(self, bdti):
3127 return self.api(
3128 self.papi.bier_disp_entry_dump,
3129 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003130
3131 def add_node_next(self, node_name, next_name):
3132 """ Set the next node for a given node request
3133
3134 :param node_name:
3135 :param next_name:
3136 """
3137 return self.api(self.papi.add_node_next,
3138 {'node_name': node_name,
3139 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003140
3141 def session_enable_disable(self, is_enabled):
3142 return self.api(
3143 self.papi.session_enable_disable,
3144 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003145
3146 def ipsec_spd_add_del(self, spd_id, is_add=1):
3147 """ SPD add/del - Wrapper to add or del ipsec SPD
3148 Sample CLI : 'ipsec spd add 1'
3149
3150 :param spd_id - SPD ID to be created in the vpp . mandatory
3151 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3152 optional
3153 :returns: reply from the API
3154 """
3155 return self.api(
3156 self.papi.ipsec_spd_add_del, {
3157 'spd_id': spd_id, 'is_add': is_add})
3158
3159 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3160 """ IPSEC interface SPD add/del - \
3161 Wrapper to associate/disassociate SPD to interface in VPP
3162 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3163
3164 :param spd_id - SPD ID to associate with the interface . mandatory
3165 :param sw_if_index - Interface Index which needs to ipsec \
3166 association mandatory
3167 :param is_add - add(1) or del(0) association with interface \
3168 (Default 1 - add) . optional
3169 :returns: reply from the API
3170 """
3171 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003172 self.papi.ipsec_interface_add_del_spd,
3173 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003174
3175 def ipsec_sad_add_del_entry(self,
3176 sad_id,
3177 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02003178 integrity_algorithm,
3179 integrity_key,
3180 crypto_algorithm,
3181 crypto_key,
3182 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003183 tunnel_src_address='',
3184 tunnel_dst_address='',
Ole Troane0d2bd62018-06-22 22:36:46 +02003185 is_tunnel=1,
Klement Sekera31da2e32018-06-24 22:49:55 +02003186 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003187 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003188 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02003189 :param sad_id: security association ID
3190 :param spi: security param index of the SA in decimal
3191 :param integrity_algorithm:
3192 :param integrity_key:
3193 :param crypto_algorithm:
3194 :param crypto_key:
3195 :param protocol: AH(0) or ESP(1) protocol
3196 :param tunnel_src_address: tunnel mode outer src address
3197 :param tunnel_dst_address: tunnel mode outer dst address
3198 :param is_add:
3199 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08003200 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3201 crypto and ipsec algorithms
3202 """
3203 return self.api(
3204 self.papi.ipsec_sad_add_del_entry,
3205 {'sad_id': sad_id,
3206 'spi': spi,
3207 'tunnel_src_address': tunnel_src_address,
3208 'tunnel_dst_address': tunnel_dst_address,
3209 'protocol': protocol,
3210 'integrity_algorithm': integrity_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003211 'integrity_key_length': len(integrity_key),
“mystarrocks”23f0c452017-12-11 07:11:51 -08003212 'integrity_key': integrity_key,
3213 'crypto_algorithm': crypto_algorithm,
Klement Sekera31da2e32018-06-24 22:49:55 +02003214 'crypto_key_length': len(crypto_key) if crypto_key is not None
3215 else 0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003216 'crypto_key': crypto_key,
3217 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003218 'is_tunnel': is_tunnel,
3219 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003220
3221 def ipsec_spd_add_del_entry(self,
3222 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003223 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003224 local_address_start,
3225 local_address_stop,
3226 remote_address_start,
3227 remote_address_stop,
3228 local_port_start=0,
3229 local_port_stop=65535,
3230 remote_port_start=0,
3231 remote_port_stop=65535,
3232 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003233 policy=0,
3234 priority=100,
3235 is_outbound=1,
3236 is_add=1,
3237 is_ip_any=0):
3238 """ IPSEC policy SPD add/del -
3239 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02003240 :param spd_id: SPD ID for the policy
3241 :param local_address_start: local-ip-range start address
3242 :param local_address_stop : local-ip-range stop address
3243 :param remote_address_start: remote-ip-range start address
3244 :param remote_address_stop : remote-ip-range stop address
3245 :param local_port_start: (Default value = 0)
3246 :param local_port_stop: (Default value = 65535)
3247 :param remote_port_start: (Default value = 0)
3248 :param remote_port_stop: (Default value = 65535)
3249 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
3250 :param sa_id: Security Association ID for mapping it to SPD
3251 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
3252 (Default value = 0)
3253 :param priority: value for the spd action (Default value = 100)
3254 :param is_outbound: flag for inbound(0) or outbound(1)
3255 (Default value = 1)
3256 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08003257 """
3258 return self.api(
3259 self.papi.ipsec_spd_add_del_entry,
3260 {'spd_id': spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02003261 'sa_id': sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003262 'local_address_start': local_address_start,
3263 'local_address_stop': local_address_stop,
3264 'remote_address_start': remote_address_start,
3265 'remote_address_stop': remote_address_stop,
3266 'local_port_start': local_port_start,
3267 'local_port_stop': local_port_stop,
3268 'remote_port_start': remote_port_start,
3269 'remote_port_stop': remote_port_stop,
3270 'is_add': is_add,
3271 'protocol': protocol,
3272 'policy': policy,
3273 'priority': priority,
3274 'is_outbound': is_outbound,
“mystarrocks”23f0c452017-12-11 07:11:51 -08003275 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003276
Klement Sekera31da2e32018-06-24 22:49:55 +02003277 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
3278 remote_spi, crypto_alg, local_crypto_key,
3279 remote_crypto_key, integ_alg, local_integ_key,
3280 remote_integ_key, is_add=1, esn=0,
3281 anti_replay=1, renumber=0, show_instance=0):
3282 return self.api(
3283 self.papi.ipsec_tunnel_if_add_del,
3284 {'local_ip': local_ip, 'remote_ip': remote_ip,
3285 'local_spi': local_spi, 'remote_spi': remote_spi,
3286 'crypto_alg': crypto_alg,
3287 'local_crypto_key_len': len(local_crypto_key),
3288 'local_crypto_key': local_crypto_key,
3289 'remote_crypto_key_len': len(remote_crypto_key),
3290 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg,
3291 'local_integ_key_len': len(local_integ_key),
3292 'local_integ_key': local_integ_key,
3293 'remote_integ_key_len': len(remote_integ_key),
3294 'remote_integ_key': remote_integ_key, 'is_add': is_add,
3295 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber,
3296 'show_instance': show_instance
3297 })
3298
Florin Corasb795bd02017-12-14 11:30:48 -08003299 def app_namespace_add(self,
3300 namespace_id,
3301 ip4_fib_id=0,
3302 ip6_fib_id=0,
3303 sw_if_index=0xFFFFFFFF,
3304 secret=0):
3305 return self.api(
3306 self.papi.app_namespace_add_del,
3307 {'secret': secret,
3308 'sw_if_index': sw_if_index,
3309 'ip4_fib_id': ip4_fib_id,
3310 'ip6_fib_id': ip6_fib_id,
3311 'namespace_id': namespace_id,
3312 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003313
3314 def punt_socket_register(self, l4_port, pathname, header_version=1,
3315 is_ip4=1, l4_protocol=0x11):
3316 """ Punt to socket """
3317 return self.api(self.papi.punt_socket_register,
3318 {'is_ip4': is_ip4,
3319 'l4_protocol': l4_protocol,
3320 'l4_port': l4_port,
3321 'pathname': pathname,
3322 'header_version': header_version})
3323
3324 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3325 expire_walk_interval_ms, is_ip6=0):
3326 """ Set IP reassembly parameters """
3327 return self.api(self.papi.ip_reassembly_set,
3328 {'is_ip6': is_ip6,
3329 'timeout_ms': timeout_ms,
3330 'expire_walk_interval_ms': expire_walk_interval_ms,
3331 'max_reassemblies': max_reassemblies})
3332
3333 def ip_reassembly_get(self, is_ip6=0):
3334 """ Get IP reassembly parameters """
3335 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003336
Klement Sekera4c533132018-02-22 11:41:12 +01003337 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3338 enable_ip6=False):
3339 """ Enable/disable IP reassembly """
3340 return self.api(self.papi.ip_reassembly_enable_disable,
3341 {'sw_if_index': sw_if_index,
3342 'enable_ip4': 1 if enable_ip4 else 0,
3343 'enable_ip6': 1 if enable_ip6 else 0,
3344 })
3345
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003346 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3347 """ GBP endpoint Add/Del """
3348 return self.api(self.papi.gbp_endpoint_add_del,
3349 {'is_add': is_add,
3350 'endpoint': {
3351 'is_ip6': is_ip6,
3352 'sw_if_index': sw_if_index,
3353 'address': addr,
3354 'epg_id': epg}})
3355
3356 def gbp_endpoint_dump(self):
3357 """ GBP endpoint Dump """
3358 return self.api(self.papi.gbp_endpoint_dump, {})
3359
Neale Ranns25b04942018-04-04 09:34:50 -07003360 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3361 ip4_rd,
3362 ip6_rd,
3363 uplink_sw_if_index):
3364 """ GBP endpoint group Add/Del """
3365 return self.api(self.papi.gbp_endpoint_group_add_del,
3366 {'is_add': is_add,
3367 'epg': {
3368 'uplink_sw_if_index': uplink_sw_if_index,
3369 'bd_id': bd,
3370 'ip4_table_id': ip4_rd,
3371 'ip6_table_id': ip6_rd,
3372 'epg_id': epg}})
3373
3374 def gbp_endpoint_group_dump(self):
3375 """ GBP endpoint group Dump """
3376 return self.api(self.papi.gbp_endpoint_group_dump, {})
3377
3378 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3379 """ GBP recirc Add/Del """
3380 return self.api(self.papi.gbp_recirc_add_del,
3381 {'is_add': is_add,
3382 'recirc': {
3383 'is_ext': is_ext,
3384 'sw_if_index': sw_if_index,
3385 'epg_id': epg}})
3386
3387 def gbp_recirc_dump(self):
3388 """ GBP recirc Dump """
3389 return self.api(self.papi.gbp_recirc_dump, {})
3390
3391 def gbp_subnet_add_del(self, is_add, table_id,
3392 is_internal,
3393 addr, addr_len,
3394 sw_if_index=0xffffffff,
3395 epg_id=0xffffffff,
3396 is_ip6=False):
3397 """ GBP Subnet Add/Del """
3398 return self.api(self.papi.gbp_subnet_add_del,
3399 {'is_add': is_add,
3400 'subnet': {
3401 'is_internal': is_internal,
3402 'is_ip6': is_ip6,
3403 'sw_if_index': sw_if_index,
3404 'epg_id': epg_id,
3405 'address': addr,
3406 'address_length': addr_len,
3407 'table_id': table_id}})
3408
3409 def gbp_subnet_dump(self):
3410 """ GBP Subnet Dump """
3411 return self.api(self.papi.gbp_subnet_dump, {})
3412
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003413 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3414 """ GBP contract Add/Del """
3415 return self.api(self.papi.gbp_contract_add_del,
3416 {'is_add': is_add,
3417 'contract': {
3418 'acl_index': acl_index,
3419 'src_epg': src_epg,
3420 'dst_epg': dst_epg}})
3421
3422 def gbp_contract_dump(self):
3423 """ GBP contract Dump """
3424 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003425
Ole Troan298c6952018-03-08 12:30:43 +01003426 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3427 ip4_prefix, ip4_prefix_len, ip4_src,
3428 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003429 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003430 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003431 {'fib_index': fib_index,
3432 'ip6_prefix': ip6_prefix,
3433 'ip6_prefix_len': ip6_prefix_len,
3434 'ip4_prefix': ip4_prefix,
3435 'ip4_prefix_len': ip4_prefix_len,
3436 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003437 'security_check': security_check})
3438
Ole Troan298c6952018-03-08 12:30:43 +01003439 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003440 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003441 return self.api(self.papi.ipip_6rd_del_tunnel,
3442 {'sw_if_index': sw_if_index})
3443
3444 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Ole Troand57f6362018-05-24 13:21:43 +02003445 instance=0xFFFFFFFF, fib_index=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003446 """ IPIP tunnel Add/Del """
3447 return self.api(self.papi.ipip_add_tunnel,
3448 {'is_ipv6': is_ipv6,
3449 'instance': instance,
3450 'src_address': src_address,
3451 'dst_address': dst_address,
Ole Troand57f6362018-05-24 13:21:43 +02003452 'fib_index': fib_index,
3453 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003454
3455 def ipip_del_tunnel(self, sw_if_index):
3456 """ IPIP tunnel Delete """
3457 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003458 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003459
3460 def qos_egress_map_update(self, id, outputs):
3461 """ QOS egress map update """
3462 return self.api(self.papi.qos_egress_map_update,
3463 {'map_id': id,
3464 'rows': outputs})
3465
3466 def qos_egress_map_delete(self, id):
3467 """ QOS egress map delete """
3468 return self.api(self.papi.qos_egress_map_delete,
3469 {'map_id': id})
3470
3471 def qos_mark_enable_disable(self, sw_if_index,
3472 output_source,
3473 map_id,
3474 enable):
3475 """ QOS Mark Enable/Disable """
3476 return self.api(self.papi.qos_mark_enable_disable,
3477 {'map_id': map_id,
3478 'sw_if_index': sw_if_index,
3479 'output_source': output_source,
3480 'enable': enable})
3481
3482 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3483 """ IP QoS recording Enble/Disable """
3484 return self.api(self.papi.qos_record_enable_disable,
3485 {'sw_if_index': sw_if_index,
3486 'input_source': input_source,
3487 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003488
Neale Ranns947ea622018-06-07 23:48:20 -07003489 def igmp_enable_disable(self, sw_if_index, enable, host):
3490 """ Enable/disable IGMP on a given interface """
3491 return self.api(self.papi.igmp_enable_disable,
3492 {'enable': enable,
3493 'mode': host,
3494 'sw_if_index': sw_if_index})
3495
3496 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003497 """ Listen for new (S,G) on specified interface
3498
3499 :param enable: add/del
3500 :param sw_if_index: interface sw index
3501 :param saddr: source ip4 addr
3502 :param gaddr: group ip4 addr
3503 """
3504 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07003505 {
3506 'group':
3507 {
3508 'filter': filter,
3509 'sw_if_index': sw_if_index,
3510 'n_srcs': len(saddrs),
3511 'saddrs': saddrs,
3512 'gaddr':
3513 {
3514 'address': gaddr
3515 }
3516 }
3517 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003518
3519 def igmp_dump(self, sw_if_index=None):
3520 """ Dump all (S,G) interface configurations """
3521 if sw_if_index is None:
Neale Ranns947ea622018-06-07 23:48:20 -07003522 sw_if_index = 0xffffffff
3523 return self.api(self.papi.igmp_dump,
3524 {'sw_if_index': sw_if_index})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003525
3526 def igmp_clear_interface(self, sw_if_index):
3527 """ Remove all (S,G)s from specified interface
3528 doesn't send IGMP report!
3529 """
3530 return self.api(
3531 self.papi.igmp_clear_interface, {
3532 'sw_if_index': sw_if_index})
3533
3534 def want_igmp_events(self, enable=1):
3535 return self.api(self.papi.want_igmp_events, {'enable': enable,
3536 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003537
3538 def bond_create(
3539 self,
3540 mode,
3541 lb,
3542 use_custom_mac,
3543 mac_address=''):
3544 """
3545 :param mode: mode
3546 :param lb: load balance
3547 :param use_custom_mac: use custom mac
3548 :param mac_address: mac address
3549 """
3550 return self.api(
3551 self.papi.bond_create,
3552 {'mode': mode,
3553 'lb': lb,
3554 'use_custom_mac': use_custom_mac,
3555 'mac_address': mac_address
3556 })
3557
3558 def bond_delete(
3559 self,
3560 sw_if_index):
3561 """
3562 :param sw_if_index: interface the operation is applied to
3563 """
3564 return self.api(self.papi.bond_delete,
3565 {'sw_if_index': sw_if_index})
3566
3567 def bond_enslave(
3568 self,
3569 sw_if_index,
3570 bond_sw_if_index,
3571 is_passive,
3572 is_long_timeout):
3573 """
3574 :param sw_if_index: slave sw_if_index
3575 :param bond_sw_if_index: bond sw_if_index
3576 :param is_passive: is passive lacp speaker
3577 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3578 """
3579 return self.api(
3580 self.papi.bond_enslave,
3581 {'sw_if_index': sw_if_index,
3582 'bond_sw_if_index': bond_sw_if_index,
3583 'is_passive': is_passive,
3584 'is_long_timeout': is_long_timeout
3585 })
3586
3587 def bond_detach_slave(
3588 self,
3589 sw_if_index):
3590 """
3591 :param sw_if_index: slave interface the operation is applied to
3592 """
3593 return self.api(self.papi.bond_detach_slave,
3594 {'sw_if_index': sw_if_index})
3595
3596 def sw_interface_slave_dump(
3597 self,
3598 sw_if_index):
3599 """
3600 :param sw_if_index: bond sw_if_index
3601 """
3602 return self.api(self.papi.sw_interface_slave_dump,
3603 {'sw_if_index': sw_if_index})
3604
3605 def sw_interface_bond_dump(
3606 self):
3607 """
3608
3609 """
3610 return self.api(self.papi.sw_interface_bond_dump,
3611 {})
Stevene8fa6202017-08-30 14:36:45 -07003612
3613 def create_vhost_user_if(
3614 self,
3615 is_server,
3616 sock_filename,
3617 renumber,
3618 custom_dev_instance,
3619 use_custom_mac,
3620 mac_address,
3621 tag=''):
3622 """
3623 :param is_server: is server
3624 :param sock_filename: socket name
3625 :param renumber: renumber
3626 :param custom_dev_instance: custom dev instance
3627 :param use_custom_mac: use custom mac
3628 :param mac_address: mac address
3629 :param tag: tag (default ''
3630 """
3631 return self.api(
3632 self.papi.create_vhost_user_if,
3633 {'is_server': is_server,
3634 'sock_filename': sock_filename,
3635 'renumber': renumber,
3636 'custom_dev_instance': custom_dev_instance,
3637 'use_custom_mac': use_custom_mac,
3638 'mac_address': mac_address,
3639 'tag': tag
3640 })
3641
3642 def delete_vhost_user_if(
3643 self,
3644 sw_if_index):
3645 """
3646 :param sw_if_index: interface the operation is applied to
3647 """
3648 return self.api(self.papi.delete_vhost_user_if,
3649 {'sw_if_index': sw_if_index, })
3650
3651 def sw_interface_vhost_user_dump(
3652 self):
3653 """
3654
3655 """
3656 return self.api(self.papi.sw_interface_vhost_user_dump,
3657 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003658
3659 def abf_policy_add_del(self, is_add, policy):
3660 return self.api(
3661 self.papi.abf_policy_add_del,
3662 {'is_add': is_add,
3663 'policy': policy})
3664
3665 def abf_itf_attach_add_del(self, is_add, attach):
3666 return self.api(
3667 self.papi.abf_itf_attach_add_del,
3668 {'is_add': is_add,
3669 'attach': attach})
3670
3671 def abf_policy_dump(self):
3672 return self.api(
3673 self.papi.abf_policy_dump, {})
3674
3675 def abf_itf_attach_dump(self):
3676 return self.api(
3677 self.papi.abf_itf_attach_dump, {})
Neale Ranns17ff3c12018-07-04 10:24:24 -07003678
3679 def pipe_create(self, is_specified, user_instance):
3680 return self.api(self.papi.pipe_create,
3681 {'is_specified': is_specified,
3682 'user_instance': user_instance})
3683
3684 def pipe_delete(self, parent_sw_if_index):
3685 return self.api(self.papi.pipe_delete,
3686 {'parent_sw_if_index': parent_sw_if_index})
3687
3688 def pipe_dump(self):
3689 return self.api(self.papi.pipe_dump, {})