blob: 1a09d8c5e21c47ed35858c60b8487185eff25cc3 [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 Troan3cc49712017-03-08 12:02:24 +010073 self.vpp = VPP(jsonfiles, logger=test_class.logger)
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 Sloboda81119e82018-05-25 14:02:20 +0200506 def want_dhcp6_pd_reply_events(self, enable_disable=1):
507 return self.api(self.papi.want_dhcp6_pd_reply_events,
508 {'enable_disable': enable_disable,
509 'pid': os.getpid()})
510
511 def dhcp6_clients_enable_disable(self, enable=1):
512 return self.api(self.papi.dhcp6_clients_enable_disable,
513 {'enable': enable})
514
515 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
516 prefixes, server_index=0xFFFFFFFF,
517 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
518 ):
519 return self.api(self.papi.dhcp6_pd_send_client_message,
520 {'sw_if_index': sw_if_index,
521 'server_index': server_index,
522 'irt': irt,
523 'mrt': mrt,
524 'mrc': mrc,
525 'mrd': mrd,
526 'stop': stop,
527 'msg_type': msg_type,
528 'T1': T1,
529 'T2': T2,
530 'n_prefixes': len(prefixes),
531 'prefixes': prefixes})
532
533 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
534 enable=1):
535 return self.api(self.papi.dhcp6_pd_client_enable_disable,
536 {'sw_if_index': sw_if_index,
537 'prefix_group': prefix_group,
538 'enable': enable})
539
540 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
541 prefix_length, prefix_group,
542 is_add=1):
543 return self.api(self.papi.ip6_add_del_address_using_prefix,
544 {'sw_if_index': sw_if_index,
545 'prefix_group': prefix_group,
546 'address': address,
547 'prefix_length': prefix_length,
548 'is_add': is_add})
549
Jan4af521d2016-11-15 17:05:00 +0100550 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
551 filter_mac=0, bvi_mac=0):
552 """Create/delete L2 FIB entry.
553
554 :param str mac: MAC address to create FIB entry for.
555 :param int bd_id: Bridge domain index.
556 :param int sw_if_index: Software interface index of the interface.
557 :param int is_add: Add or delete flag. (Default value = 1)
558 :param int static_mac: Set to 1 to create static MAC entry.
559 (Default value = 0)
560 :param int filter_mac: Set to 1 to drop packet that's source or
561 destination MAC address contains defined MAC address.
562 (Default value = 0)
563 :param int bvi_mac: Set to 1 to create entry that points to BVI
564 interface. (Default value = 0)
565 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100566 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200567 {'mac': self._convert_mac(mac),
568 'bd_id': bd_id,
569 'sw_if_index': sw_if_index,
570 'is_add': is_add,
571 'static_mac': static_mac,
572 'filter_mac': filter_mac,
573 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100574
Eyal Bari93b503e2017-05-15 10:13:15 +0300575 def l2fib_flush_int(self, sw_if_index):
576 """Flush L2 FIB entries for sw_if_index.
577
578 :param int sw_if_index: Software interface index of the interface.
579 """
580 return self.api(self.papi.l2fib_flush_int,
581 {'sw_if_index': sw_if_index})
582
583 def l2fib_flush_bd(self, bd_id):
584 """Flush L2 FIB entries for bd_id.
585
586 :param int sw_if_index: Bridge Domain id.
587 """
588 return self.api(self.papi.l2fib_flush_bd,
589 {'bd_id': bd_id})
590
591 def l2fib_flush_all(self):
592 """Flush all L2 FIB.
593 """
594 return self.api(self.papi.l2fib_flush_all, {})
595
Klement Sekeraf62ae122016-10-11 11:47:09 +0200596 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
597 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100598 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200599
Jan4af521d2016-11-15 17:05:00 +0100600 :param int sw_if_index: Software interface index of the interface.
601 :param int bd_id: Bridge domain index.
602 :param int shg: Split-horizon group index. (Default value = 0)
603 :param int bvi: Set interface as a bridge group virtual interface.
604 (Default value = 0)
605 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200606 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100607 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200608 {'rx_sw_if_index': sw_if_index,
609 'bd_id': bd_id,
610 'shg': shg,
611 'bvi': bvi,
612 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200613
Jan00dad122016-11-29 10:04:53 +0100614 def bridge_flags(self, bd_id, is_set, feature_bitmap):
Chris Luked0421942018-04-10 15:19:54 -0400615 """Enable/disable required feature of the bridge domain with defined
616 ID.
Jan00dad122016-11-29 10:04:53 +0100617
618 :param int bd_id: Bridge domain ID.
619 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
620 :param int feature_bitmap: Bitmap value of the feature to be set:
621 - learn (1 << 0),
622 - forward (1 << 1),
623 - flood (1 << 2),
624 - uu-flood (1 << 3) or
625 - arp-term (1 << 4).
626 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100627 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200628 {'bd_id': bd_id,
629 'is_set': is_set,
630 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100631
632 def bridge_domain_dump(self, bd_id=0):
633 """
634
635 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
636 existing bridge domains returned)
637 :return: Dictionary of bridge domain(s) data.
638 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100639 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200640 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100641
Klement Sekeraf62ae122016-10-11 11:47:09 +0200642 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
643 enable):
644 """Create or delete unidirectional cross-connect from Tx interface to
645 Rx interface.
646
Jan4af521d2016-11-15 17:05:00 +0100647 :param int rx_sw_if_index: Software interface index of Rx interface.
648 :param int tx_sw_if_index: Software interface index of Tx interface.
649 :param int enable: Create cross-connect if equal to 1, delete
650 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200651
652 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100653 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200654 {'rx_sw_if_index': rx_sw_if_index,
655 'tx_sw_if_index': tx_sw_if_index,
656 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200657
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200658 def sw_interface_set_l2_tag_rewrite(
659 self,
660 sw_if_index,
661 vtr_oper,
662 push=0,
663 tag1=0,
664 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000665 """L2 interface vlan tag rewrite configure request
666 :param client_index - opaque cookie to identify the sender
667 :param context - sender context, to match reply w/ request
668 :param sw_if_index - interface the operation is applied to
669 :param vtr_op - Choose from l2_vtr_op_t enum values
670 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
671 :param tag1 - Needed for any push or translate vtr op
672 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
673
674 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100675 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200676 {'sw_if_index': sw_if_index,
677 'vtr_op': vtr_oper,
678 'push_dot1q': push,
679 'tag1': tag1,
680 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000681
Neale Ranns55d03782017-10-21 06:34:22 -0700682 def sw_interface_set_l2_emulation(
683 self,
684 sw_if_index,
685 enable=1):
686 """L2 Emulation
687 :param sw_if_index - interface the operation is applied to
688
689 """
690 return self.api(self.papi.l2_emulation,
691 {'sw_if_index': sw_if_index,
692 'enable': enable})
693
Neale Rannsa07bd702017-08-07 07:53:49 -0700694 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200695 """
696
697 :param admin_up_down:
698 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200699
700 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100701 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200702 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700703 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200704
Neale Rannsffd78d12018-02-09 06:05:16 -0800705 def sw_interface_set_mtu(self, sw_if_index, mtu):
706 """
707 :param sw_if_index:
708 :param mtu:
709
710 """
711 return self.api(self.papi.sw_interface_set_mtu,
712 {'sw_if_index': sw_if_index,
713 'mtu': mtu})
714
Neale Ranns25b04942018-04-04 09:34:50 -0700715 def sw_interface_set_promiscuous(self, sw_if_index, enable):
716 """
717 :param sw_if_index:
718 :param enable:
719
720 """
721 return self.api(self.papi.sw_interface_set_promiscuous,
722 {'sw_if_index': sw_if_index,
723 'enable': enable})
724
Neale Rannsc819fc62018-02-16 02:44:05 -0800725 def sw_interface_set_mac_address(self, sw_if_index, mac):
726 return self.api(self.papi.sw_interface_set_mac_address,
727 {'sw_if_index': sw_if_index,
728 'mac_address': mac})
729
Klement Sekeraf62ae122016-10-11 11:47:09 +0200730 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
731 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
732 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
733 """Create subinterface
734 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
735
736 :param sub_id: param inner_vlan:
737 :param sw_if_index:
738 :param outer_vlan:
739 :param inner_vlan:
740 :param no_tags: (Default value = 0)
741 :param one_tag: (Default value = 0)
742 :param two_tags: (Default value = 0)
743 :param dot1ad: (Default value = 0)
744 :param exact_match: (Default value = 0)
745 :param default_sub: (Default value = 0)
746 :param outer_vlan_id_any: (Default value = 0)
747 :param inner_vlan_id_any: (Default value = 0)
748
749 """
750 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100751 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200752 {'sw_if_index': sw_if_index,
753 'sub_id': sub_id,
754 'no_tags': no_tags,
755 'one_tag': one_tag,
756 'two_tags': two_tags,
757 'dot1ad': dot1ad,
758 'exact_match': exact_match,
759 'default_sub': default_sub,
760 'outer_vlan_id_any': outer_vlan_id_any,
761 'inner_vlan_id_any': inner_vlan_id_any,
762 'outer_vlan_id': outer_vlan,
763 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200764
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200765 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
766 """Create p2p ethernet subinterface
767
768 :param sw_if_index: main (parent) interface
769 :param remote_mac: client (remote) mac address
770
771 """
772 return self.api(
773 self.papi.p2p_ethernet_add,
774 {'parent_if_index': sw_if_index,
775 'remote_mac': remote_mac,
776 'subif_id': subif_id})
777
Neale Ranns177bbdc2016-11-15 09:46:51 +0000778 def delete_subif(self, sw_if_index):
779 """Delete subinterface
780
781 :param sw_if_index:
782 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100783 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200784 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000785
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200786 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
787 """Delete p2p ethernet subinterface
788
789 :param sw_if_index: main (parent) interface
790 :param remote_mac: client (remote) mac address
791
792 """
793 return self.api(
794 self.papi.p2p_ethernet_del,
795 {'parent_if_index': sw_if_index,
796 'remote_mac': remote_mac})
797
Klement Sekeraf62ae122016-10-11 11:47:09 +0200798 def create_vlan_subif(self, sw_if_index, vlan):
799 """
800
801 :param vlan:
802 :param sw_if_index:
803
804 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100805 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200806 {'sw_if_index': sw_if_index,
807 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200808
Matej Klotton0178d522016-11-04 11:11:44 +0100809 def create_loopback(self, mac=''):
810 """
811
812 :param mac: (Optional)
813 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100814 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200815 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100816
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100817 def delete_loopback(self, sw_if_index):
818 return self.api(self.papi.delete_loopback,
819 {'sw_if_index': sw_if_index, })
820
Neale Ranns15002542017-09-10 04:39:11 -0700821 def ip_table_add_del(self,
822 table_id,
823 is_add=1,
824 is_ipv6=0):
825 """
826
827 :param table_id
828 :param is_add: (Default value = 1)
829 :param is_ipv6: (Default value = 0)
830
831 """
832
833 return self.api(
834 self.papi.ip_table_add_del,
835 {'table_id': table_id,
836 'is_add': is_add,
837 'is_ipv6': is_ipv6})
838
Klement Sekeraf62ae122016-10-11 11:47:09 +0200839 def ip_add_del_route(
840 self,
841 dst_address,
842 dst_address_length,
843 next_hop_address,
844 next_hop_sw_if_index=0xFFFFFFFF,
845 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200846 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000847 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200848 next_hop_n_out_labels=0,
849 next_hop_out_label_stack=[],
850 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800851 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000852 is_resolve_host=0,
853 is_resolve_attached=0,
854 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200855 is_add=1,
856 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200857 is_unreach=0,
858 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200859 is_ipv6=0,
860 is_local=0,
861 is_classify=0,
862 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800863 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800864 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200865 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200866 """
867
868 :param dst_address_length:
869 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
870 :param dst_address:
871 :param next_hop_address:
872 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
873 :param vrf_id: (Default value = 0)
874 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200875 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200876 :param is_add: (Default value = 1)
877 :param is_drop: (Default value = 0)
878 :param is_ipv6: (Default value = 0)
879 :param is_local: (Default value = 0)
880 :param is_classify: (Default value = 0)
881 :param is_multipath: (Default value = 0)
882 :param is_resolve_host: (Default value = 0)
883 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800884 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700885 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200886 :param next_hop_weight: (Default value = 1)
887
888 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000889
Klement Sekeraf62ae122016-10-11 11:47:09 +0200890 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100891 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200892 {'next_hop_sw_if_index': next_hop_sw_if_index,
893 'table_id': table_id,
894 'classify_table_index': classify_table_index,
895 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200896 'is_add': is_add,
897 'is_drop': is_drop,
898 'is_unreach': is_unreach,
899 'is_prohibit': is_prohibit,
900 'is_ipv6': is_ipv6,
901 'is_local': is_local,
902 'is_classify': is_classify,
903 'is_multipath': is_multipath,
904 'is_resolve_host': is_resolve_host,
905 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800906 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700907 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800908 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200909 'next_hop_weight': next_hop_weight,
910 'dst_address_length': dst_address_length,
911 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800912 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200913 'next_hop_address': next_hop_address,
914 'next_hop_n_out_labels': next_hop_n_out_labels,
915 'next_hop_via_label': next_hop_via_label,
916 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100917
Matej Klotton16a14cd2016-12-07 15:09:13 +0100918 def ip_fib_dump(self):
919 return self.api(self.papi.ip_fib_dump, {})
920
Jan Gelety057bb8c2016-12-20 17:32:45 +0100921 def ip6_fib_dump(self):
922 return self.api(self.papi.ip6_fib_dump, {})
923
Matej Klotton0178d522016-11-04 11:11:44 +0100924 def ip_neighbor_add_del(self,
925 sw_if_index,
926 mac_address,
927 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100928 is_add=1,
929 is_ipv6=0,
930 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800931 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100932 ):
933 """ Add neighbor MAC to IPv4 or IPv6 address.
934
935 :param sw_if_index:
936 :param mac_address:
937 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100938 :param is_add: (Default value = 1)
939 :param is_ipv6: (Default value = 0)
940 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800941 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100942 """
943
944 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100945 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800946 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200947 'is_add': is_add,
948 'is_ipv6': is_ipv6,
949 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800950 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200951 'mac_address': mac_address,
952 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100953 }
Matej Klotton0178d522016-11-04 11:11:44 +0100954 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100955
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800956 def ip_neighbor_dump(self,
957 sw_if_index,
958 is_ipv6=0):
959 """ Return IP neighbor dump.
960
961 :param sw_if_index:
962 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
963 """
964
965 return self.api(
966 self.papi.ip_neighbor_dump,
967 {'is_ipv6': is_ipv6,
968 'sw_if_index': sw_if_index
969 }
970 )
971
972 def proxy_arp_add_del(self,
973 low_address,
974 hi_address,
975 vrf_id=0,
976 is_add=1):
977 """ Config Proxy Arp Range.
978
979 :param low_address: Start address in the rnage to Proxy for
980 :param hi_address: End address in the rnage to Proxy for
981 :param vrf_id: The VRF/table in which to proxy
982 """
983
984 return self.api(
985 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700986 {'proxy':
987 {
988 'vrf_id': vrf_id,
989 'low_address': low_address,
990 'hi_address': hi_address,
991 },
992 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800993
994 def proxy_arp_intfc_enable_disable(self,
995 sw_if_index,
996 is_enable=1):
997 """ Enable/Disable an interface for proxy ARP requests
998
999 :param sw_if_index: Interface
1000 :param enable_disable: Enable/Disable
1001 """
1002
1003 return self.api(
1004 self.papi.proxy_arp_intfc_enable_disable,
1005 {'sw_if_index': sw_if_index,
1006 'enable_disable': is_enable
1007 }
1008 )
1009
Jane546d3b2016-12-08 13:10:03 +01001010 def reset_vrf(self,
1011 vrf_id,
1012 is_ipv6=0,
1013 ):
1014 """ Reset VRF (remove all routes etc.) request.
1015
1016 :param int vrf_id: ID of the FIB table / VRF to reset.
1017 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1018 """
1019
1020 return self.api(
1021 self.papi.reset_vrf,
1022 {'vrf_id': vrf_id,
1023 'is_ipv6': is_ipv6,
1024 }
1025 )
1026
1027 def reset_fib(self,
1028 vrf_id,
1029 is_ipv6=0,
1030 ):
1031 """ Reset VRF (remove all routes etc.) request.
1032
1033 :param int vrf_id: ID of the FIB table / VRF to reset.
1034 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1035 """
1036
1037 return self.api(
1038 self.papi.reset_fib,
1039 {'vrf_id': vrf_id,
1040 'is_ipv6': is_ipv6,
1041 }
1042 )
1043
1044 def ip_dump(self,
1045 is_ipv6=0,
1046 ):
1047 """ Return IP dump.
1048
1049 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1050 """
1051
1052 return self.api(
1053 self.papi.ip_dump,
1054 {'is_ipv6': is_ipv6,
1055 }
1056 )
1057
Klement Sekera7bb873a2016-11-18 07:38:42 +01001058 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001059 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001060 """
1061
1062 :param sw_if_index_from:
1063 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001064 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001065 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001066 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001067 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001068 {'sw_if_index_from': sw_if_index_from,
1069 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001070 'state': state,
1071 'is_l2': is_l2,
1072 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001073
1074 def gre_tunnel_add_del(self,
1075 src_address,
1076 dst_address,
1077 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001078 tunnel_type=0,
1079 instance=0xFFFFFFFF,
1080 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001081 is_add=1,
1082 is_ip6=0):
1083 """ Add a GRE tunnel
1084
1085 :param src_address:
1086 :param dst_address:
1087 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001088 :param tunnel_type: (Default value = 0)
1089 :param instance: (Default value = 0xFFFFFFFF)
1090 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001091 :param is_add: (Default value = 1)
1092 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001093 """
1094
1095 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001096 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001097 {'is_add': is_add,
1098 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001099 'tunnel_type': tunnel_type,
1100 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001101 'src_address': src_address,
1102 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001103 'outer_fib_id': outer_fib_id,
1104 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001105 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001106
Neale Ranns810086d2017-11-05 16:26:46 -08001107 def udp_encap_add_del(self,
1108 id,
1109 src_ip,
1110 dst_ip,
1111 src_port,
1112 dst_port,
1113 table_id=0,
1114 is_add=1,
1115 is_ip6=0):
1116 """ Add a GRE tunnel
1117 :param id: user provided ID
1118 :param src_ip:
1119 :param dst_ip:
1120 :param src_port:
1121 :param dst_port:
1122 :param outer_fib_id: (Default value = 0)
1123 :param is_add: (Default value = 1)
1124 :param is_ipv6: (Default value = 0)
1125 """
1126
1127 return self.api(
1128 self.papi.udp_encap_add_del,
1129 {'id': id,
1130 'is_add': is_add,
1131 'is_ip6': is_ip6,
1132 'src_ip': src_ip,
1133 'dst_ip': dst_ip,
1134 'src_port': src_port,
1135 'dst_port': dst_port,
1136 'table_id': table_id}
1137 )
1138
1139 def udp_encap_dump(self):
1140 return self.api(self.papi.udp_encap_dump, {})
1141
Neale Ranns43b1f442018-03-20 01:47:35 -07001142 def want_udp_encap_stats(self, enable=1):
1143 return self.api(self.papi.want_udp_encap_stats,
1144 {'enable': enable,
1145 'pid': os.getpid()})
1146
Neale Ranns5a8123b2017-01-26 01:18:23 -08001147 def mpls_fib_dump(self):
1148 return self.api(self.papi.mpls_fib_dump, {})
1149
Neale Ranns15002542017-09-10 04:39:11 -07001150 def mpls_table_add_del(
1151 self,
1152 table_id,
1153 is_add=1):
1154 """
1155
1156 :param table_id
1157 :param is_add: (Default value = 1)
1158
1159 """
1160
1161 return self.api(
1162 self.papi.mpls_table_add_del,
1163 {'mt_table_id': table_id,
1164 'mt_is_add': is_add})
1165
Neale Rannsad422ed2016-11-02 14:20:04 +00001166 def mpls_route_add_del(
1167 self,
1168 label,
1169 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001170 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001171 next_hop_address,
1172 next_hop_sw_if_index=0xFFFFFFFF,
1173 table_id=0,
1174 next_hop_table_id=0,
1175 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001176 next_hop_n_out_labels=0,
1177 next_hop_out_label_stack=[],
1178 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001179 is_resolve_host=0,
1180 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001181 is_interface_rx=0,
1182 is_rpf_id=0,
1183 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001184 is_add=1,
1185 is_drop=0,
1186 is_multipath=0,
1187 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001188 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001189 """
1190
1191 :param dst_address_length:
1192 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1193 :param dst_address:
1194 :param next_hop_address:
1195 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1196 :param vrf_id: (Default value = 0)
1197 :param lookup_in_vrf: (Default value = 0)
1198 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001199 :param is_add: (Default value = 1)
1200 :param is_drop: (Default value = 0)
1201 :param is_ipv6: (Default value = 0)
1202 :param is_local: (Default value = 0)
1203 :param is_classify: (Default value = 0)
1204 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001205 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001206 :param is_resolve_host: (Default value = 0)
1207 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001208 :param next_hop_weight: (Default value = 1)
1209
1210 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001211 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001212 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001213 {'mr_label': label,
1214 'mr_eos': eos,
1215 'mr_table_id': table_id,
1216 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001217 'mr_is_add': is_add,
1218 'mr_is_classify': is_classify,
1219 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001220 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001221 'mr_is_resolve_host': is_resolve_host,
1222 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001223 'mr_is_interface_rx': is_interface_rx,
1224 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001225 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001226 'mr_next_hop_weight': next_hop_weight,
1227 'mr_next_hop': next_hop_address,
1228 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1229 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1230 'mr_next_hop_table_id': next_hop_table_id,
1231 'mr_next_hop_via_label': next_hop_via_label,
1232 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001233
1234 def mpls_ip_bind_unbind(
1235 self,
1236 label,
1237 dst_address,
1238 dst_address_length,
1239 table_id=0,
1240 ip_table_id=0,
1241 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001242 is_bind=1):
1243 """
1244 """
1245 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001246 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001247 {'mb_mpls_table_id': table_id,
1248 'mb_label': label,
1249 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001250 'mb_is_bind': is_bind,
1251 'mb_is_ip4': is_ip4,
1252 'mb_address_length': dst_address_length,
1253 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001254
1255 def mpls_tunnel_add_del(
1256 self,
1257 tun_sw_if_index,
1258 next_hop_proto_is_ip4,
1259 next_hop_address,
1260 next_hop_sw_if_index=0xFFFFFFFF,
1261 next_hop_table_id=0,
1262 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001263 next_hop_n_out_labels=0,
1264 next_hop_out_label_stack=[],
1265 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001266 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001267 l2_only=0,
1268 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001269 """
1270
1271 :param dst_address_length:
1272 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1273 :param dst_address:
1274 :param next_hop_address:
1275 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1276 :param vrf_id: (Default value = 0)
1277 :param lookup_in_vrf: (Default value = 0)
1278 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001279 :param is_add: (Default value = 1)
1280 :param is_drop: (Default value = 0)
1281 :param is_ipv6: (Default value = 0)
1282 :param is_local: (Default value = 0)
1283 :param is_classify: (Default value = 0)
1284 :param is_multipath: (Default value = 0)
1285 :param is_resolve_host: (Default value = 0)
1286 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001287 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001288 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001289
1290 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001291 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001292 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001293 {'mt_sw_if_index': tun_sw_if_index,
1294 'mt_is_add': is_add,
1295 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001296 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001297 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1298 'mt_next_hop_weight': next_hop_weight,
1299 'mt_next_hop': next_hop_address,
1300 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1301 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1302 'mt_next_hop_table_id': next_hop_table_id,
1303 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001304
Matus Fabian2ba92e32017-08-21 07:05:03 -07001305 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001306 self,
1307 sw_if_index,
1308 is_inside=1,
1309 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001310 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001311
1312 :param sw_if_index: Software index of the interface
1313 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1314 :param is_add: 1 if add, 0 if delete (Default value = 1)
1315 """
1316 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001317 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001318 {'is_add': is_add,
1319 'is_inside': is_inside,
1320 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001321
Matus Fabian2ba92e32017-08-21 07:05:03 -07001322 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001323 self,
1324 sw_if_index,
1325 is_inside=1,
1326 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001327 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001328
1329 :param sw_if_index: Software index of the interface
1330 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1331 :param is_add: 1 if add, 0 if delete (Default value = 1)
1332 """
1333 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001334 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001335 {'is_add': is_add,
1336 'is_inside': is_inside,
1337 'sw_if_index': sw_if_index})
1338
Matus Fabian2ba92e32017-08-21 07:05:03 -07001339 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001340 self,
1341 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001342 external_ip=0,
1343 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001344 local_port=0,
1345 external_port=0,
1346 addr_only=1,
1347 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001348 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001349 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001350 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001351 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001352 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001353 is_add=1):
1354 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001355
1356 :param local_ip: Local IP address
1357 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001358 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001359 :param local_port: Local port number (Default value = 0)
1360 :param external_port: External port number (Default value = 0)
1361 :param addr_only: 1 if address only mapping, 0 if address and port
1362 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001363 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001364 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001365 :param self_twice_nat: 1 if translate external host address and port
1366 whenever external host address equals
1367 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -08001368 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001369 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001370 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001371 """
1372 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001373 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001374 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001375 'addr_only': addr_only,
1376 'local_ip_address': local_ip,
1377 'external_ip_address': external_ip,
1378 'local_port': local_port,
1379 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001380 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001381 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001382 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001383 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001384 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001385 'out2in_only': out2in_only,
1386 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001387
Matus Fabianab7a8052017-11-28 04:29:41 -08001388 def nat44_add_del_identity_mapping(
1389 self,
1390 ip='0',
1391 sw_if_index=0xFFFFFFFF,
1392 port=0,
1393 addr_only=1,
1394 vrf_id=0,
1395 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001396 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001397 is_add=1):
1398 """Add/delete NAT44 identity mapping
1399
1400 :param ip: IP address (Default value = 0)
1401 :param sw_if_index: Interface instead of IP address
1402 :param port: Port number (Default value = 0)
1403 :param addr_only: 1 if address only mapping, 0 if address and port
1404 :param vrf_id: VRF ID
1405 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001406 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001407 :param is_add: 1 if add, 0 if delete (Default value = 1)
1408 """
1409 return self.api(
1410 self.papi.nat44_add_del_identity_mapping,
1411 {'is_add': is_add,
1412 'addr_only': addr_only,
1413 'ip_address': ip,
1414 'port': port,
1415 'sw_if_index': sw_if_index,
1416 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001417 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001418 'protocol': protocol})
1419
Matus Fabian2ba92e32017-08-21 07:05:03 -07001420 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001421 self,
1422 first_ip_address,
1423 last_ip_address,
1424 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001425 vrf_id=0xFFFFFFFF,
1426 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001427 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001428
1429 :param first_ip_address: First IP address
1430 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001431 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001432 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001433 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001434 """
1435 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001436 self.papi.nat44_add_del_address_range,
1437 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001438 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001439 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001440 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001441 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001442
Matus Fabian2ba92e32017-08-21 07:05:03 -07001443 def nat44_address_dump(self):
1444 """Dump NAT44 addresses
1445 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001446 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001447 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001448
Matus Fabian2ba92e32017-08-21 07:05:03 -07001449 def nat44_interface_dump(self):
1450 """Dump interfaces with NAT44 feature
1451 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001452 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001453 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001454
Matus Fabian2ba92e32017-08-21 07:05:03 -07001455 def nat44_interface_output_feature_dump(self):
1456 """Dump interfaces with NAT44 output feature
1457 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001458 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001459 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001460
Matus Fabian2ba92e32017-08-21 07:05:03 -07001461 def nat44_static_mapping_dump(self):
1462 """Dump NAT44 static mappings
1463 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001464 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001465 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001466
Matus Fabianab7a8052017-11-28 04:29:41 -08001467 def nat44_identity_mapping_dump(self):
1468 """Dump NAT44 identity mappings
1469 :return: Dictionary of NAT44 identity mappings
1470 """
1471 return self.api(self.papi.nat44_identity_mapping_dump, {})
1472
Matus Fabian2ba92e32017-08-21 07:05:03 -07001473 def nat_show_config(self):
1474 """Show NAT plugin config
1475 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001476 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001477 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001478
Matus Fabian2ba92e32017-08-21 07:05:03 -07001479 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001480 self,
1481 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001482 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001483 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001484 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001485
1486 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001487 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001488 :param is_add: 1 if add, 0 if delete (Default value = 1)
1489 """
Matus Fabianb932d262017-12-18 05:38:24 -08001490 return self.api(
1491 self.papi.nat44_add_del_interface_addr,
1492 {'is_add': is_add,
1493 'sw_if_index': sw_if_index,
1494 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001495
Matus Fabian2ba92e32017-08-21 07:05:03 -07001496 def nat44_interface_addr_dump(self):
1497 """Dump NAT44 addresses interfaces
1498 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001499 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001500 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001501
Matus Fabian2ba92e32017-08-21 07:05:03 -07001502 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001503 self,
1504 domain_id=1,
1505 src_port=4739,
1506 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001507 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001508
1509 :param domain_id: Observation domain ID (Default value = 1)
1510 :param src_port: Source port number (Default value = 4739)
1511 :param enable: 1 if enable, 0 if disable (Default value = 1)
1512 """
1513 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001514 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001515 {'domain_id': domain_id,
1516 'src_port': src_port,
1517 'enable': enable})
1518
Matus Fabian2ba92e32017-08-21 07:05:03 -07001519 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001520 self,
1521 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001522 vrf_id):
1523 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001524
1525 :param ip_address: ip adress of the user to be dumped
1526 :param cpu_index: cpu_index on which the user is
1527 :param vrf_id: VRF ID
1528 :return: Dictionary of S-NAT sessions
1529 """
1530 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001531 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001532 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001533 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001534
Matus Fabian2ba92e32017-08-21 07:05:03 -07001535 def nat44_user_dump(self):
1536 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001537
Matus Fabian2ba92e32017-08-21 07:05:03 -07001538 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001539 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001540 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001541
Matus Fabian704018c2017-09-04 02:17:18 -07001542 def nat44_add_del_lb_static_mapping(
1543 self,
1544 external_addr,
1545 external_port,
1546 protocol,
1547 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001548 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001549 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001550 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001551 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001552 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001553 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001554 is_add=1):
1555 """Add/delete NAT44 load balancing static mapping
1556
Matus Fabianb932d262017-12-18 05:38:24 -08001557 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001558 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001559 :param is_add - 1 if add, 0 if delete
1560 """
1561 return self.api(
1562 self.papi.nat44_add_del_lb_static_mapping,
1563 {'is_add': is_add,
1564 'external_addr': external_addr,
1565 'external_port': external_port,
1566 'protocol': protocol,
1567 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001568 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +02001569 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001570 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001571 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001572 'local_num': local_num,
1573 'locals': locals})
1574
1575 def nat44_lb_static_mapping_dump(self):
1576 """Dump NAT44 load balancing static mappings
1577
1578 :return: Dictionary of NAT44 load balancing static mapping
1579 """
1580 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1581
Matus Fabian5ba86f72017-10-26 03:37:38 -07001582 def nat44_del_session(
1583 self,
1584 addr,
1585 port,
1586 protocol,
1587 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -07001588 is_in=1,
1589 ext_host_address=None,
1590 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -07001591 """Delete NAT44 session
1592
1593 :param addr: IPv4 address
1594 :param por: port number
1595 :param protocol: IP protocol number
1596 :param vrf_id: VRF ID
1597 :param is_in: 1 if inside network addres and port pari, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001598 :param ext_host_address: external host IPv4 address
1599 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001600 """
Matus Fabian70a26ac2018-05-14 06:20:28 -07001601 if ext_host_address is None:
1602 return self.api(
1603 self.papi.nat44_del_session,
1604 {'address': addr,
1605 'port': port,
1606 'protocol': protocol,
1607 'vrf_id': vrf_id,
1608 'is_in': is_in})
1609 else:
1610 return self.api(
1611 self.papi.nat44_del_session,
1612 {'address': addr,
1613 'port': port,
1614 'protocol': protocol,
1615 'vrf_id': vrf_id,
1616 'is_in': is_in,
1617 'ext_host_valid': 1,
1618 'ext_host_address': ext_host_address,
1619 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001620
Juraj Sloboda7b929792017-11-23 13:20:48 +01001621 def nat44_forwarding_enable_disable(
1622 self,
1623 enable):
1624 """Enable/disable forwarding for NAT44
1625
1626 :param enable: 1 for enable, 0 for disable
1627 """
1628 return self.api(
1629 self.papi.nat44_forwarding_enable_disable,
1630 {'enable': enable})
1631
Matus Fabianefcd1e92017-08-15 06:59:19 -07001632 def nat_set_reass(
1633 self,
1634 timeout=2,
1635 max_reass=1024,
1636 max_frag=5,
1637 drop_frag=0,
1638 is_ip6=0):
1639 """Set NAT virtual fragmentation reassembly
1640
1641 :param timeout: reassembly timeout (Default 2sec)
1642 :param max_reass: maximum concurrent reassemblies (Default 1024)
1643 :param max_frag: maximum fragmets per reassembly (Default 5)
1644 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1645 :param is_ip6: 1 if IPv6, 0 if IPv4
1646 """
1647 return self.api(
1648 self.papi.nat_set_reass,
1649 {'timeout': timeout,
1650 'max_reass': max_reass,
1651 'max_frag': max_frag,
1652 'drop_frag': drop_frag,
1653 'is_ip6': is_ip6})
1654
1655 def nat_get_reass(self):
1656 """Get NAT virtual fragmentation reassembly configuration
1657
1658 :return: NAT virtual fragmentation reassembly configuration
1659 """
1660 return self.api(self.papi.nat_get_reass, {})
1661
1662 def nat_reass_dump(self):
1663 """Dump NAT virtual fragmentation reassemblies
1664
1665 :return: Dictionary of NAT virtual fragmentation reassemblies
1666 """
1667 return self.api(self.papi.nat_reass_dump, {})
1668
Matus Fabian2ba92e32017-08-21 07:05:03 -07001669 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001670 self,
1671 in_addr,
1672 in_plen,
1673 out_addr,
1674 out_plen,
1675 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001676 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001677
1678 :param is_add - 1 if add, 0 if delete
1679 :param in_addr - inside IP address
1680 :param in_plen - inside IP address prefix length
1681 :param out_addr - outside IP address
1682 :param out_plen - outside IP address prefix length
1683 """
1684 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001685 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001686 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001687 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001688 'in_addr': in_addr,
1689 'in_plen': in_plen,
1690 'out_addr': out_addr,
1691 'out_plen': out_plen})
1692
Matus Fabian2ba92e32017-08-21 07:05:03 -07001693 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001694 self,
1695 in_addr):
1696 """Get outside address and port range from inside address
1697
1698 :param in_addr - inside IP address
1699 """
1700 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001701 self.papi.nat_det_forward,
1702 {'in_addr': in_addr,
1703 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001704
Matus Fabian2ba92e32017-08-21 07:05:03 -07001705 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001706 self,
1707 out_addr,
1708 out_port):
1709 """Get inside address from outside address and port
1710
1711 :param out_addr - outside IP address
1712 :param out_port - outside port
1713 """
1714 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001715 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001716 {'out_addr': out_addr,
1717 'out_port': out_port})
1718
Matus Fabian2ba92e32017-08-21 07:05:03 -07001719 def nat_det_map_dump(self):
1720 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001721
Matus Fabian2ba92e32017-08-21 07:05:03 -07001722 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001723 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001724 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001725
Matus Fabian2ba92e32017-08-21 07:05:03 -07001726 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001727 self,
1728 udp=300,
1729 tcp_established=7440,
1730 tcp_transitory=240,
1731 icmp=60):
1732 """Set values of timeouts for deterministic NAT (in seconds)
1733
1734 :param udp - UDP timeout (Default value = 300)
1735 :param tcp_established - TCP established timeout (Default value = 7440)
1736 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1737 :param icmp - ICMP timeout (Default value = 60)
1738 """
1739 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001740 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001741 {'udp': udp,
1742 'tcp_established': tcp_established,
1743 'tcp_transitory': tcp_transitory,
1744 'icmp': icmp})
1745
Matus Fabian2ba92e32017-08-21 07:05:03 -07001746 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001747 """Get values of timeouts for deterministic NAT
1748
1749 :return: Timeouts for deterministic NAT (in seconds)
1750 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001751 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001752
Matus Fabian2ba92e32017-08-21 07:05:03 -07001753 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001754 self,
1755 out_addr,
1756 out_port,
1757 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001758 ext_port):
1759 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001760
1761 :param out_addr - outside IP address
1762 :param out_port - outside port
1763 :param ext_addr - external host IP address
1764 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001765 """
1766 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001767 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001768 {'out_addr': out_addr,
1769 'out_port': out_port,
1770 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001771 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001772
Matus Fabian2ba92e32017-08-21 07:05:03 -07001773 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001774 self,
1775 in_addr,
1776 in_port,
1777 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001778 ext_port):
1779 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001780
1781 :param in_addr - inside IP address
1782 :param in_port - inside port
1783 :param ext_addr - external host IP address
1784 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001785 """
1786 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001787 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001788 {'in_addr': in_addr,
1789 'in_port': in_port,
1790 'ext_addr': ext_addr,
1791 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001792 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001793
Matus Fabian2ba92e32017-08-21 07:05:03 -07001794 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001795 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001796 user_addr):
1797 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001798
1799 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001800 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001801 """
1802 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001803 self.papi.nat_det_session_dump,
1804 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001805 'user_addr': user_addr})
1806
Matus Fabian06596c52017-06-06 04:53:28 -07001807 def nat64_add_del_pool_addr_range(
1808 self,
1809 start_addr,
1810 end_addr,
1811 vrf_id=0xFFFFFFFF,
1812 is_add=1):
1813 """Add/del address range to NAT64 pool
1814
1815 :param start_addr: First IP address
1816 :param end_addr: Last IP address
1817 :param vrf_id: VRF id for the address range
1818 :param is_add: 1 if add, 0 if delete (Default value = 1)
1819 """
1820 return self.api(
1821 self.papi.nat64_add_del_pool_addr_range,
1822 {'start_addr': start_addr,
1823 'end_addr': end_addr,
1824 'vrf_id': vrf_id,
1825 'is_add': is_add})
1826
1827 def nat64_pool_addr_dump(self):
1828 """Dump NAT64 pool addresses
1829 :return: Dictionary of NAT64 pool addresses
1830 """
1831 return self.api(self.papi.nat64_pool_addr_dump, {})
1832
1833 def nat64_add_del_interface(
1834 self,
1835 sw_if_index,
1836 is_inside=1,
1837 is_add=1):
1838 """Enable/disable NAT64 feature on the interface
1839 :param sw_if_index: Index of the interface
1840 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1841 :param is_add: 1 if add, 0 if delete (Default value = 1)
1842 """
1843 return self.api(
1844 self.papi.nat64_add_del_interface,
1845 {'sw_if_index': sw_if_index,
1846 'is_inside': is_inside,
1847 'is_add': is_add})
1848
1849 def nat64_interface_dump(self):
1850 """Dump interfaces with NAT64 feature
1851 :return: Dictionary of interfaces with NAT64 feature
1852 """
1853 return self.api(self.papi.nat64_interface_dump, {})
1854
1855 def nat64_add_del_static_bib(
1856 self,
1857 in_ip,
1858 out_ip,
1859 in_port,
1860 out_port,
1861 protocol,
1862 vrf_id=0,
1863 is_add=1):
1864 """Add/delete S-NAT static BIB entry
1865
1866 :param in_ip: Inside IPv6 address
1867 :param out_ip: Outside IPv4 address
1868 :param in_port: Inside port number
1869 :param out_port: Outside port number
1870 :param protocol: IP protocol
1871 :param vrf_id: VRF ID (Default value = 0)
1872 :param is_add: 1 if add, 0 if delete (Default value = 1)
1873 """
1874 return self.api(
1875 self.papi.nat64_add_del_static_bib,
1876 {'i_addr': in_ip,
1877 'o_addr': out_ip,
1878 'i_port': in_port,
1879 'o_port': out_port,
1880 'vrf_id': vrf_id,
1881 'proto': protocol,
1882 'is_add': is_add})
1883
Matus Fabianab9a59c2017-08-16 05:37:36 -07001884 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001885 """Dump NAT64 BIB
1886
Matus Fabianab9a59c2017-08-16 05:37:36 -07001887 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001888 :returns: Dictionary of NAT64 BIB entries
1889 """
1890 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1891
1892 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1893 tcp_incoming_syn=6):
1894 """Set values of timeouts for NAT64 (in seconds)
1895
Matus Fabian428dc912017-06-21 06:15:18 -07001896 :param udpi: UDP timeout (Default value = 300)
1897 :param icmp: ICMP timeout (Default value = 60)
1898 :param tcp_trans: TCP transitory timeout (Default value = 240)
1899 :param tcp_est: TCP established timeout (Default value = 7440)
1900 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001901 """
1902 return self.api(
1903 self.papi.nat64_set_timeouts,
1904 {'udp': udp,
1905 'icmp': icmp,
1906 'tcp_trans': tcp_trans,
1907 'tcp_est': tcp_est,
1908 'tcp_incoming_syn': tcp_incoming_syn})
1909
1910 def nat64_get_timeouts(self):
1911 """Get values of timeouts for NAT64
1912
1913 :return: Timeouts for NAT64 (in seconds)
1914 """
1915 return self.api(self.papi.nat64_get_timeouts, {})
1916
Matus Fabianab9a59c2017-08-16 05:37:36 -07001917 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001918 """Dump NAT64 session table
1919
Matus Fabianab9a59c2017-08-16 05:37:36 -07001920 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001921 :returns: Dictionary of NAT64 sesstion table entries
1922 """
1923 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1924
Matus Fabian428dc912017-06-21 06:15:18 -07001925 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1926 """Add/del NAT64 prefix
1927
1928 :param prefix: NAT64 prefix
1929 :param plen: NAT64 prefix length
1930 :param vrf_id: VRF id of tenant (Default 0)
1931 :param is_add: 1 if add, 0 if delete (Default value = 1)
1932 """
1933 return self.api(
1934 self.papi.nat64_add_del_prefix,
1935 {'prefix': prefix,
1936 'prefix_len': plen,
1937 'vrf_id': vrf_id,
1938 'is_add': is_add})
1939
1940 def nat64_prefix_dump(self):
1941 """Dump NAT64 prefix
1942
1943 :returns: Dictionary of NAT64 prefixes
1944 """
1945 return self.api(self.papi.nat64_prefix_dump, {})
1946
Matus Fabian0938dcf2017-11-08 01:59:38 -08001947 def nat64_add_interface_addr(
1948 self,
1949 sw_if_index,
1950 is_add=1):
1951 """Add/del NAT64 address from interface
1952
1953 :param sw_if_index: Software index of the interface
1954 :param is_add: 1 if add, 0 if delete (Default value = 1)
1955 """
1956 return self.api(self.papi.nat64_add_del_interface_addr,
1957 {'is_add': is_add, 'sw_if_index': sw_if_index})
1958
Matus Fabian8ebe6252017-11-06 05:04:53 -08001959 def dslite_set_aftr_addr(self, ip6, ip4):
1960 """Set DS-Lite AFTR addresses
1961
1962 :param ip4: IPv4 address
1963 :param ip6: IPv6 address
1964 """
1965 return self.api(
1966 self.papi.dslite_set_aftr_addr,
1967 {'ip4_addr': ip4,
1968 'ip6_addr': ip6})
1969
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001970 def dslite_set_b4_addr(self, ip6, ip4):
1971 """Set DS-Lite B4 IPv6 address
1972
1973 :param ip4: IPv4 address
1974 :param ip6: IPv6 address
1975 """
1976 return self.api(
1977 self.papi.dslite_set_b4_addr,
1978 {'ip4_addr': ip4,
1979 'ip6_addr': ip6})
1980
Matus Fabian8ebe6252017-11-06 05:04:53 -08001981 def dslite_add_del_pool_addr_range(
1982 self,
1983 start_addr,
1984 end_addr,
1985 is_add=1):
1986 """Add/del address range to DS-Lite pool
1987
1988 :param start_addr: First IP address
1989 :param end_addr: Last IP address
1990 :param is_add: 1 if add, 0 if delete (Default value = 1)
1991 """
1992 return self.api(
1993 self.papi.dslite_add_del_pool_addr_range,
1994 {'start_addr': start_addr,
1995 'end_addr': end_addr,
1996 'is_add': is_add})
1997
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001998 def nat66_add_del_interface(
1999 self,
2000 sw_if_index,
2001 is_inside=1,
2002 is_add=1):
2003 """Enable/disable NAT66 feature on the interface
2004 :param sw_if_index: Index of the interface
2005 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
2006 :param is_add: 1 if add, 0 if delete (Default value = 1)
2007 """
2008 return self.api(
2009 self.papi.nat66_add_del_interface,
2010 {'sw_if_index': sw_if_index,
2011 'is_inside': is_inside,
2012 'is_add': is_add})
2013
2014 def nat66_add_del_static_mapping(
2015 self,
2016 in_ip,
2017 out_ip,
2018 vrf_id=0,
2019 is_add=1):
2020 """Add/delete NAT66 static mapping
2021
2022 :param in_ip: Inside IPv6 address
2023 :param out_ip: Outside IPv6 address
2024 :param vrf_id: VRF ID (Default value = 0)
2025 :param is_add: 1 if add, 0 if delete (Default value = 1)
2026 """
2027 return self.api(
2028 self.papi.nat66_add_del_static_mapping,
2029 {'local_ip_address': in_ip,
2030 'external_ip_address': out_ip,
2031 'vrf_id': vrf_id,
2032 'is_add': is_add})
2033
2034 def nat66_interface_dump(self):
2035 """Dump interfaces with NAT66 feature
2036 :return: Dictionary of interfaces with NAT66 feature
2037 """
2038 return self.api(self.papi.nat66_interface_dump, {})
2039
2040 def nat66_static_mapping_dump(self):
2041 """Dump NAT66 static mappings
2042 :return: Dictionary of NAT66 static mappings
2043 """
2044 return self.api(self.papi.nat66_static_mapping_dump, {})
2045
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002046 def control_ping(self):
2047 self.api(self.papi.control_ping)
2048
2049 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01002050 detect_mult, local_addr, peer_addr, is_ipv6=0,
2051 bfd_key_id=None, conf_key_id=None):
2052 if bfd_key_id is None:
2053 return self.api(self.papi.bfd_udp_add,
2054 {
2055 'sw_if_index': sw_if_index,
2056 'desired_min_tx': desired_min_tx,
2057 'required_min_rx': required_min_rx,
2058 'local_addr': local_addr,
2059 'peer_addr': peer_addr,
2060 'is_ipv6': is_ipv6,
2061 'detect_mult': detect_mult,
2062 })
2063 else:
2064 return self.api(self.papi.bfd_udp_add,
2065 {
2066 'sw_if_index': sw_if_index,
2067 'desired_min_tx': desired_min_tx,
2068 'required_min_rx': required_min_rx,
2069 'local_addr': local_addr,
2070 'peer_addr': peer_addr,
2071 'is_ipv6': is_ipv6,
2072 'detect_mult': detect_mult,
2073 'is_authenticated': 1,
2074 'bfd_key_id': bfd_key_id,
2075 'conf_key_id': conf_key_id,
2076 })
2077
Klement Sekeraa57a9702017-02-02 06:58:07 +01002078 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2079 detect_mult, local_addr, peer_addr, is_ipv6=0):
2080 return self.api(self.papi.bfd_udp_mod,
2081 {
2082 'sw_if_index': sw_if_index,
2083 'desired_min_tx': desired_min_tx,
2084 'required_min_rx': required_min_rx,
2085 'local_addr': local_addr,
2086 'peer_addr': peer_addr,
2087 'is_ipv6': is_ipv6,
2088 'detect_mult': detect_mult,
2089 })
2090
Klement Sekerab17dd962017-01-09 07:43:48 +01002091 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2092 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2093 is_delayed=False):
2094 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002095 {
2096 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002097 'local_addr': local_addr,
2098 'peer_addr': peer_addr,
2099 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002100 'is_delayed': 1 if is_delayed else 0,
2101 'bfd_key_id': bfd_key_id,
2102 'conf_key_id': conf_key_id,
2103 })
2104
2105 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2106 is_ipv6=0, is_delayed=False):
2107 return self.api(self.papi.bfd_udp_auth_deactivate,
2108 {
2109 'sw_if_index': sw_if_index,
2110 'local_addr': local_addr,
2111 'peer_addr': peer_addr,
2112 'is_ipv6': is_ipv6,
2113 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002114 })
2115
2116 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2117 return self.api(self.papi.bfd_udp_del,
2118 {
2119 'sw_if_index': sw_if_index,
2120 'local_addr': local_addr,
2121 'peer_addr': peer_addr,
2122 'is_ipv6': is_ipv6,
2123 })
2124
2125 def bfd_udp_session_dump(self):
2126 return self.api(self.papi.bfd_udp_session_dump, {})
2127
Klement Sekerab17dd962017-01-09 07:43:48 +01002128 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2129 peer_addr, is_ipv6=0):
2130 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002131 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002132 'sw_if_index': sw_if_index,
2133 'local_addr': local_addr,
2134 'peer_addr': peer_addr,
2135 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002136 })
2137
2138 def want_bfd_events(self, enable_disable=1):
2139 return self.api(self.papi.want_bfd_events, {
2140 'enable_disable': enable_disable,
2141 'pid': os.getpid(),
2142 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002143
Klement Sekerab17dd962017-01-09 07:43:48 +01002144 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2145 return self.api(self.papi.bfd_auth_set_key, {
2146 'conf_key_id': conf_key_id,
2147 'auth_type': auth_type,
2148 'key': key,
2149 'key_len': len(key),
2150 })
2151
2152 def bfd_auth_del_key(self, conf_key_id):
2153 return self.api(self.papi.bfd_auth_del_key, {
2154 'conf_key_id': conf_key_id,
2155 })
2156
2157 def bfd_auth_keys_dump(self):
2158 return self.api(self.papi.bfd_auth_keys_dump, {})
2159
Klement Sekera239790f2017-02-16 10:53:53 +01002160 def bfd_udp_set_echo_source(self, sw_if_index):
2161 return self.api(self.papi.bfd_udp_set_echo_source,
2162 {'sw_if_index': sw_if_index})
2163
Klement Sekera73884482017-02-23 09:26:30 +01002164 def bfd_udp_del_echo_source(self):
2165 return self.api(self.papi.bfd_udp_del_echo_source, {})
2166
Steve Shin7957d6e2016-12-19 09:24:50 -08002167 def classify_add_del_table(
2168 self,
2169 is_add,
2170 mask,
2171 match_n_vectors=1,
2172 table_index=0xFFFFFFFF,
2173 nbuckets=2,
2174 memory_size=2097152,
2175 skip_n_vectors=0,
2176 next_table_index=0xFFFFFFFF,
2177 miss_next_index=0xFFFFFFFF,
2178 current_data_flag=0,
2179 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002180 """
2181 :param is_add:
2182 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002183 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002184 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002185 :param nbuckets: (Default value = 2)
2186 :param memory_size: (Default value = 2097152)
2187 :param skip_n_vectors: (Default value = 0)
2188 :param next_table_index: (Default value = 0xFFFFFFFF)
2189 :param miss_next_index: (Default value = 0xFFFFFFFF)
2190 :param current_data_flag: (Default value = 0)
2191 :param current_data_offset: (Default value = 0)
2192 """
2193
2194 return self.api(
2195 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002196 {'is_add': is_add,
2197 'table_index': table_index,
2198 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002199 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002200 'skip_n_vectors': skip_n_vectors,
2201 'match_n_vectors': match_n_vectors,
2202 'next_table_index': next_table_index,
2203 'miss_next_index': miss_next_index,
2204 'current_data_flag': current_data_flag,
2205 'current_data_offset': current_data_offset,
2206 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002207
2208 def classify_add_del_session(
2209 self,
2210 is_add,
2211 table_index,
2212 match,
2213 opaque_index=0xFFFFFFFF,
2214 hit_next_index=0xFFFFFFFF,
2215 advance=0,
2216 action=0,
2217 metadata=0):
2218 """
2219 :param is_add:
2220 :param table_index:
2221 :param match:
2222 :param opaque_index: (Default value = 0xFFFFFFFF)
2223 :param hit_next_index: (Default value = 0xFFFFFFFF)
2224 :param advance: (Default value = 0)
2225 :param action: (Default value = 0)
2226 :param metadata: (Default value = 0)
2227 """
2228
2229 return self.api(
2230 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002231 {'is_add': is_add,
2232 'table_index': table_index,
2233 'hit_next_index': hit_next_index,
2234 'opaque_index': opaque_index,
2235 'advance': advance,
2236 'action': action,
2237 'metadata': metadata,
2238 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002239
2240 def input_acl_set_interface(
2241 self,
2242 is_add,
2243 sw_if_index,
2244 ip4_table_index=0xFFFFFFFF,
2245 ip6_table_index=0xFFFFFFFF,
2246 l2_table_index=0xFFFFFFFF):
2247 """
2248 :param is_add:
2249 :param sw_if_index:
2250 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2251 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2252 :param l2_table_index: (Default value = 0xFFFFFFFF)
2253 """
2254
2255 return self.api(
2256 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002257 {'sw_if_index': sw_if_index,
2258 'ip4_table_index': ip4_table_index,
2259 'ip6_table_index': ip6_table_index,
2260 'l2_table_index': l2_table_index,
2261 'is_add': is_add})
2262
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002263 def output_acl_set_interface(
2264 self,
2265 is_add,
2266 sw_if_index,
2267 ip4_table_index=0xFFFFFFFF,
2268 ip6_table_index=0xFFFFFFFF,
2269 l2_table_index=0xFFFFFFFF):
2270 """
2271 :param is_add:
2272 :param sw_if_index:
2273 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2274 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2275 :param l2_table_index: (Default value = 0xFFFFFFFF)
2276 """
2277
2278 return self.api(
2279 self.papi.output_acl_set_interface,
2280 {'sw_if_index': sw_if_index,
2281 'ip4_table_index': ip4_table_index,
2282 'ip6_table_index': ip6_table_index,
2283 'l2_table_index': l2_table_index,
2284 'is_add': is_add})
2285
Klement Sekera77fabdb2017-01-02 07:46:14 +01002286 def set_ipfix_exporter(
2287 self,
2288 collector_address,
2289 src_address,
2290 path_mtu,
2291 template_interval,
2292 vrf_id=0,
2293 collector_port=4739,
2294 udp_checksum=0):
2295 return self.api(
2296 self.papi.set_ipfix_exporter,
2297 {
2298 'collector_address': collector_address,
2299 'collector_port': collector_port,
2300 'src_address': src_address,
2301 'vrf_id': vrf_id,
2302 'path_mtu': path_mtu,
2303 'template_interval': template_interval,
2304 'udp_checksum': udp_checksum,
2305 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002306
2307 def dhcp_proxy_config(self,
2308 dhcp_server,
2309 dhcp_src_address,
2310 rx_table_id=0,
2311 server_table_id=0,
2312 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002313 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002314 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002315 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002316 {
2317 'rx_vrf_id': rx_table_id,
2318 'server_vrf_id': server_table_id,
2319 'is_ipv6': is_ipv6,
2320 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002321 'dhcp_server': dhcp_server,
2322 'dhcp_src_address': dhcp_src_address,
2323 })
2324
2325 def dhcp_proxy_set_vss(self,
2326 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002327 vss_type=255,
2328 vpn_ascii_id="",
2329 oui=0,
2330 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002331 is_add=1,
2332 is_ip6=0):
2333 return self.api(
2334 self.papi.dhcp_proxy_set_vss,
2335 {
2336 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002337 'vss_type': vss_type,
2338 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002339 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002340 'vpn_index': vpn_index,
2341 'is_add': is_add,
2342 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002343 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002344
Neale Rannsdaff1782018-05-16 04:12:18 -07002345 def dhcp_client_dump(self):
2346 return self.api(self.papi.dhcp_client_dump, {})
2347
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002348 def dhcp_client(self,
2349 sw_if_index,
2350 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002351 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002352 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002353 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002354 want_dhcp_events=0):
2355 return self.api(
2356 self.papi.dhcp_client_config,
2357 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002358 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07002359 'client': {
2360 'sw_if_index': sw_if_index,
2361 'hostname': hostname,
2362 'id': client_id,
2363 'want_dhcp_event': want_dhcp_events,
2364 'set_broadcast_flag': set_broadcast_flag,
2365 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002366 })
2367
Neale Ranns32e1c012016-11-22 17:07:28 +00002368 def ip_mroute_add_del(self,
2369 src_address,
2370 grp_address,
2371 grp_address_length,
2372 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002373 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002374 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07002375 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00002376 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002377 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002378 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002379 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002380 is_add=1,
2381 is_ipv6=0,
2382 is_local=0):
2383 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002384 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002385 """
2386 return self.api(
2387 self.papi.ip_mroute_add_del,
2388 {'next_hop_sw_if_index': next_hop_sw_if_index,
2389 'entry_flags': e_flags,
2390 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002391 'table_id': table_id,
2392 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002393 'is_add': is_add,
2394 'is_ipv6': is_ipv6,
2395 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002396 'bier_imp': bier_imp,
2397 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002398 'grp_address_length': grp_address_length,
2399 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07002400 'src_address': src_address,
2401 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00002402
2403 def mfib_signal_dump(self):
2404 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002405
2406 def ip_mfib_dump(self):
2407 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002408
Neale Rannsd792d9c2017-10-21 10:53:20 -07002409 def ip6_mfib_dump(self):
2410 return self.api(self.papi.ip6_mfib_dump, {})
2411
Filip Tehlar770e89e2017-01-31 10:39:16 +01002412 def lisp_enable_disable(self, is_enabled):
2413 return self.api(
2414 self.papi.lisp_enable_disable,
2415 {
2416 'is_en': is_enabled,
2417 })
2418
2419 def lisp_locator_set(self,
2420 ls_name,
2421 is_add=1):
2422 return self.api(
2423 self.papi.lisp_add_del_locator_set,
2424 {
2425 'is_add': is_add,
2426 'locator_set_name': ls_name
2427 })
2428
2429 def lisp_locator_set_dump(self):
2430 return self.api(self.papi.lisp_locator_set_dump, {})
2431
2432 def lisp_locator(self,
2433 ls_name,
2434 sw_if_index,
2435 priority=1,
2436 weight=1,
2437 is_add=1):
2438 return self.api(
2439 self.papi.lisp_add_del_locator,
2440 {
2441 'is_add': is_add,
2442 'locator_set_name': ls_name,
2443 'sw_if_index': sw_if_index,
2444 'priority': priority,
2445 'weight': weight
2446 })
2447
2448 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2449 return self.api(
2450 self.papi.lisp_locator_dump,
2451 {
2452 'is_index_set': is_index_set,
2453 'ls_name': ls_name,
2454 'ls_index': ls_index,
2455 })
2456
2457 def lisp_local_mapping(self,
2458 ls_name,
2459 eid_type,
2460 eid,
2461 prefix_len,
2462 vni=0,
2463 key_id=0,
2464 key="",
2465 is_add=1):
2466 return self.api(
2467 self.papi.lisp_add_del_local_eid,
2468 {
2469 'locator_set_name': ls_name,
2470 'is_add': is_add,
2471 'eid_type': eid_type,
2472 'eid': eid,
2473 'prefix_len': prefix_len,
2474 'vni': vni,
2475 'key_id': key_id,
2476 'key': key
2477 })
2478
2479 def lisp_eid_table_dump(self,
2480 eid_set=0,
2481 prefix_length=0,
2482 vni=0,
2483 eid_type=0,
2484 eid=None,
2485 filter_opt=0):
2486 return self.api(
2487 self.papi.lisp_eid_table_dump,
2488 {
2489 'eid_set': eid_set,
2490 'prefix_length': prefix_length,
2491 'vni': vni,
2492 'eid_type': eid_type,
2493 'eid': eid,
2494 'filter': filter_opt,
2495 })
2496
2497 def lisp_remote_mapping(self,
2498 eid_type,
2499 eid,
2500 eid_prefix_len=0,
2501 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002502 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002503 rlocs_num=0,
2504 is_src_dst=0,
2505 is_add=1):
2506 return self.api(
2507 self.papi.lisp_add_del_remote_mapping,
2508 {
2509 'is_add': is_add,
2510 'eid_type': eid_type,
2511 'eid': eid,
2512 'eid_len': eid_prefix_len,
2513 'rloc_num': rlocs_num,
2514 'rlocs': rlocs,
2515 'vni': vni,
2516 'is_src_dst': is_src_dst,
2517 })
2518
2519 def lisp_adjacency(self,
2520 leid,
2521 reid,
2522 leid_len,
2523 reid_len,
2524 eid_type,
2525 is_add=1,
2526 vni=0):
2527 return self.api(
2528 self.papi.lisp_add_del_adjacency,
2529 {
2530 'is_add': is_add,
2531 'vni': vni,
2532 'eid_type': eid_type,
2533 'leid': leid,
2534 'reid': reid,
2535 'leid_len': leid_len,
2536 'reid_len': reid_len,
2537 })
2538
2539 def lisp_adjacencies_get(self, vni=0):
2540 return self.api(
2541 self.papi.lisp_adjacencies_get,
2542 {
2543 'vni': vni
2544 })
Neale Ranns80823802017-02-20 18:23:41 -08002545
2546 def map_add_domain(self,
2547 ip6_prefix,
2548 ip6_prefix_len,
2549 ip6_src,
2550 ip6_src_prefix_len,
2551 ip4_prefix,
2552 ip4_prefix_len,
2553 ea_bits_len=0,
2554 psid_offset=0,
2555 psid_length=0,
2556 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002557 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002558 mtu=1280):
2559 return self.api(
2560 self.papi.map_add_domain,
2561 {
2562 'ip6_prefix': ip6_prefix,
2563 'ip6_prefix_len': ip6_prefix_len,
2564 'ip4_prefix': ip4_prefix,
2565 'ip4_prefix_len': ip4_prefix_len,
2566 'ip6_src': ip6_src,
2567 'ip6_src_prefix_len': ip6_src_prefix_len,
2568 'ea_bits_len': ea_bits_len,
2569 'psid_offset': psid_offset,
2570 'psid_length': psid_length,
2571 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002572 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002573 'mtu': mtu
2574 })
Hongjun Nief486b12017-04-12 19:21:16 +08002575
2576 def gtpu_add_del_tunnel(
2577 self,
2578 src_addr,
2579 dst_addr,
2580 is_add=1,
2581 is_ipv6=0,
2582 mcast_sw_if_index=0xFFFFFFFF,
2583 encap_vrf_id=0,
2584 decap_next_index=0xFFFFFFFF,
2585 teid=0):
2586 """
2587
2588 :param is_add: (Default value = 1)
2589 :param is_ipv6: (Default value = 0)
2590 :param src_addr:
2591 :param dst_addr:
2592 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2593 :param encap_vrf_id: (Default value = 0)
2594 :param decap_next_index: (Default value = 0xFFFFFFFF)
2595 :param teid: (Default value = 0)
2596
2597 """
2598 return self.api(self.papi.gtpu_add_del_tunnel,
2599 {'is_add': is_add,
2600 'is_ipv6': is_ipv6,
2601 'src_address': src_addr,
2602 'dst_address': dst_addr,
2603 'mcast_sw_if_index': mcast_sw_if_index,
2604 'encap_vrf_id': encap_vrf_id,
2605 'decap_next_index': decap_next_index,
2606 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002607
2608 def vxlan_gpe_add_del_tunnel(
2609 self,
2610 src_addr,
2611 dst_addr,
2612 mcast_sw_if_index=0xFFFFFFFF,
2613 is_add=1,
2614 is_ipv6=0,
2615 encap_vrf_id=0,
2616 decap_vrf_id=0,
2617 protocol=3,
2618 vni=0):
2619 """
2620
2621 :param local:
2622 :param remote:
2623 :param is_add: (Default value = 1)
2624 :param is_ipv6: (Default value = 0)
2625 :param encap_vrf_id: (Default value = 0)
2626 :param decap_vrf_id: (Default value = 0)
2627 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2628 :param protocol: (Default value = 3)
2629 :param vni: (Default value = 0)
2630
2631 """
2632 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2633 {'is_add': is_add,
2634 'is_ipv6': is_ipv6,
2635 'local': src_addr,
2636 'remote': dst_addr,
2637 'mcast_sw_if_index': mcast_sw_if_index,
2638 'encap_vrf_id': encap_vrf_id,
2639 'decap_vrf_id': decap_vrf_id,
2640 'protocol': protocol,
2641 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002642
2643 def pppoe_add_del_session(
2644 self,
2645 client_ip,
2646 client_mac,
2647 session_id=0,
2648 is_add=1,
2649 is_ipv6=0,
2650 decap_vrf_id=0):
2651 """
2652
2653 :param is_add: (Default value = 1)
2654 :param is_ipv6: (Default value = 0)
2655 :param client_ip:
2656 :param session_id: (Default value = 0)
2657 :param client_mac:
2658 :param decap_vrf_id: (Default value = 0)
2659
2660 """
2661 return self.api(self.papi.pppoe_add_del_session,
2662 {'is_add': is_add,
2663 'is_ipv6': is_ipv6,
2664 'session_id': session_id,
2665 'client_ip': client_ip,
2666 'decap_vrf_id': decap_vrf_id,
2667 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002668
2669 def sr_localsid_add_del(self,
2670 localsid_addr,
2671 behavior,
2672 nh_addr,
2673 is_del=0,
2674 end_psp=0,
2675 sw_if_index=0xFFFFFFFF,
2676 vlan_index=0,
2677 fib_table=0,
2678 ):
2679 """ Add/del IPv6 SR local-SID.
2680
2681 :param localsid_addr:
2682 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2683 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2684 :param nh_addr:
2685 :param is_del: (Default value = 0)
2686 :param end_psp: (Default value = 0)
2687 :param sw_if_index: (Default value = 0xFFFFFFFF)
2688 :param vlan_index: (Default value = 0)
2689 :param fib_table: (Default value = 0)
2690 """
2691 return self.api(
2692 self.papi.sr_localsid_add_del,
2693 {'is_del': is_del,
2694 'localsid_addr': localsid_addr,
2695 'end_psp': end_psp,
2696 'behavior': behavior,
2697 'sw_if_index': sw_if_index,
2698 'vlan_index': vlan_index,
2699 'fib_table': fib_table,
2700 'nh_addr': nh_addr
2701 }
2702 )
2703
2704 def sr_policy_add(
2705 self,
2706 bsid_addr,
2707 weight=1,
2708 is_encap=1,
2709 type=0,
2710 fib_table=0,
2711 n_segments=0,
2712 segments=[]):
2713 """
2714 :param bsid_addr: bindingSID of the SR Policy
2715 :param weight: weight of the sid list. optional. (default: 1)
2716 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2717 (default: Encap)
2718 :param type: type/behavior of the SR policy. (default or spray) \
2719 (default: default)
2720 :param fib_table: VRF where to install the FIB entry for the BSID \
2721 (default: 0)
2722 :param n_segments: number of segments \
2723 (default: 0)
2724 :param segments: a vector of IPv6 address composing the segment list \
2725 (default: [])
2726 """
2727 return self.api(
2728 self.papi.sr_policy_add,
2729 {'bsid_addr': bsid_addr,
2730 'weight': weight,
2731 'is_encap': is_encap,
2732 'type': type,
2733 'fib_table': fib_table,
2734 'n_segments': n_segments,
2735 'segments': segments
2736 }
2737 )
2738
2739 def sr_policy_del(
2740 self,
2741 bsid_addr,
2742 sr_policy_index=0):
2743 """
2744 :param bsid: bindingSID of the SR Policy
2745 :param sr_policy_index: index of the sr policy (default: 0)
2746 """
2747 return self.api(
2748 self.papi.sr_policy_del,
2749 {'bsid_addr': bsid_addr,
2750 'sr_policy_index': sr_policy_index
2751 })
2752
2753 def sr_steering_add_del(
2754 self,
2755 is_del,
2756 bsid_addr,
2757 sr_policy_index,
2758 table_id,
2759 prefix_addr,
2760 mask_width,
2761 sw_if_index,
2762 traffic_type):
2763 """
2764 Steer traffic L2 and L3 traffic through a given SR policy
2765
2766 :param is_del: delete or add
2767 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2768 :param sr_policy: is the index of the SR Policy (alt to bsid)
2769 :param table_id: is the VRF where to install the FIB entry for the BSID
2770 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2771 :param mask_width: is the mask for L3 traffic type
2772 :param sw_if_index: is the incoming interface for L2 traffic
2773 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2774 """
2775 return self.api(
2776 self.papi.sr_steering_add_del,
2777 {'is_del': is_del,
2778 'bsid_addr': bsid_addr,
2779 'sr_policy_index': sr_policy_index,
2780 'table_id': table_id,
2781 'prefix_addr': prefix_addr,
2782 'mask_width': mask_width,
2783 'sw_if_index': sw_if_index,
2784 'traffic_type': traffic_type
2785 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002786
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002787 def acl_add_replace(self, acl_index, r, tag='',
2788 expected_retval=0):
2789 """Add/replace an ACL
2790 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2791 :param acl_rule r: ACL rules array.
2792 :param str tag: symbolic tag (description) for this ACL.
2793 :param int count: number of rules.
2794 """
2795 return self.api(self.papi.acl_add_replace,
2796 {'acl_index': acl_index,
2797 'r': r,
2798 'count': len(r),
2799 'tag': tag},
2800 expected_retval=expected_retval)
2801
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002802 def acl_del(self, acl_index, expected_retval=0):
2803 """
2804
2805 :param acl_index:
2806 :return:
2807 """
2808 return self.api(self.papi.acl_del,
2809 {'acl_index': acl_index},
2810 expected_retval=expected_retval)
2811
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002812 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2813 expected_retval=0):
2814 return self.api(self.papi.acl_interface_set_acl_list,
2815 {'sw_if_index': sw_if_index,
2816 'count': len(acls),
2817 'n_input': n_input,
2818 'acls': acls},
2819 expected_retval=expected_retval)
2820
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002821 def acl_interface_set_etype_whitelist(self, sw_if_index,
2822 n_input, whitelist,
2823 expected_retval=0):
2824 return self.api(self.papi.acl_interface_set_etype_whitelist,
2825 {'sw_if_index': sw_if_index,
2826 'count': len(whitelist),
2827 'n_input': n_input,
2828 'whitelist': whitelist},
2829 expected_retval=expected_retval)
2830
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002831 def acl_interface_add_del(self,
2832 sw_if_index,
2833 acl_index,
2834 is_add=1):
2835 """ Add/Delete ACL to/from interface
2836
2837 :param sw_if_index:
2838 :param acl_index:
2839 :param is_add: (Default value = 1)
2840 """
2841
2842 return self.api(self.papi.acl_interface_add_del,
2843 {'is_add': is_add,
2844 'is_input': 1,
2845 'sw_if_index': sw_if_index,
2846 'acl_index': acl_index})
2847
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002848 def acl_dump(self, acl_index, expected_retval=0):
2849 return self.api(self.papi.acl_dump,
2850 {'acl_index': acl_index},
2851 expected_retval=expected_retval)
2852
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002853 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2854 expected_retval=0):
2855 return self.api(self.papi.acl_interface_list_dump,
2856 {'sw_if_index': sw_if_index},
2857 expected_retval=expected_retval)
2858
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002859 def macip_acl_add(self, rules, tag=""):
2860 """ Add MACIP acl
2861
2862 :param rules: list of rules for given acl
2863 :param tag: acl tag
2864 """
2865
2866 return self.api(self.papi.macip_acl_add,
2867 {'r': rules,
2868 'count': len(rules),
2869 'tag': tag})
2870
Pavel Kotucek932f7412017-09-07 14:44:52 +02002871 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2872 """ Add MACIP acl
2873
2874 :param rules: list of rules for given acl
2875 :param tag: acl tag
2876 """
2877
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002878 return self.api(self.papi.macip_acl_add_replace,
2879 {'acl_index': acl_index,
2880 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002881 'count': len(rules),
2882 'tag': tag})
2883
2884 def macip_acl_del(self, acl_index):
2885 """
2886
2887 :param acl_index:
2888 :return:
2889 """
2890 return self.api(self.papi.macip_acl_del,
2891 {'acl_index': acl_index})
2892
2893 def macip_acl_interface_add_del(self,
2894 sw_if_index,
2895 acl_index,
2896 is_add=1):
2897 """ Add MACIP acl to interface
2898
2899 :param sw_if_index:
2900 :param acl_index:
2901 :param is_add: (Default value = 1)
2902 """
2903
2904 return self.api(self.papi.macip_acl_interface_add_del,
2905 {'is_add': is_add,
2906 'sw_if_index': sw_if_index,
2907 'acl_index': acl_index})
2908
2909 def macip_acl_interface_get(self):
2910 """ Return interface acls dump
2911 """
2912 return self.api(
2913 self.papi.macip_acl_interface_get, {})
2914
2915 def macip_acl_dump(self, acl_index=4294967295):
2916 """ Return MACIP acl dump
2917 """
2918
2919 return self.api(
2920 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002921
2922 def policer_add_del(self,
2923 name,
2924 cir,
2925 eir,
2926 cb,
2927 eb,
2928 is_add=1,
2929 rate_type=0,
2930 round_type=0,
2931 ptype=0,
2932 color_aware=0,
2933 conform_action_type=1,
2934 conform_dscp=0,
2935 exceed_action_type=0,
2936 exceed_dscp=0,
2937 violate_action_type=0,
2938 violate_dscp=0):
2939 return self.api(self.papi.policer_add_del,
2940 {'name': name,
2941 'cir': cir,
2942 'eir': eir,
2943 'cb': cb,
2944 'eb': eb,
2945 'is_add': is_add,
2946 'rate_type': rate_type,
2947 'round_type': round_type,
2948 'type': ptype,
2949 'color_aware': color_aware,
2950 'conform_action_type': conform_action_type,
2951 'conform_dscp': conform_dscp,
2952 'exceed_action_type': exceed_action_type,
2953 'exceed_dscp': exceed_dscp,
2954 'violate_action_type': violate_action_type,
2955 'violate_dscp': violate_dscp})
2956
2957 def ip_punt_police(self,
2958 policer_index,
2959 is_ip6=0,
2960 is_add=1):
2961 return self.api(self.papi.ip_punt_police,
2962 {'policer_index': policer_index,
2963 'is_add': is_add,
2964 'is_ip6': is_ip6})
2965
2966 def ip_punt_redirect(self,
2967 rx_sw_if_index,
2968 tx_sw_if_index,
2969 nh,
2970 is_ip6=0,
2971 is_add=1):
2972 return self.api(self.papi.ip_punt_redirect,
2973 {'rx_sw_if_index': rx_sw_if_index,
2974 'tx_sw_if_index': tx_sw_if_index,
2975 'nh': nh,
2976 'is_add': is_add,
2977 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002978
2979 def bier_table_add_del(self,
2980 bti,
2981 mpls_label,
2982 is_add=1):
2983 """ BIER Table add/del """
2984 return self.api(
2985 self.papi.bier_table_add_del,
2986 {'bt_tbl_id': {"bt_set": bti.set_id,
2987 "bt_sub_domain": bti.sub_domain_id,
2988 "bt_hdr_len_id": bti.hdr_len_id},
2989 'bt_label': mpls_label,
2990 'bt_is_add': is_add})
2991
2992 def bier_table_dump(self):
2993 return self.api(self.papi.bier_table_dump, {})
2994
2995 def bier_route_add_del(self,
2996 bti,
2997 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002998 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002999 is_add=1):
3000 """ BIER Route add/del """
3001 return self.api(
3002 self.papi.bier_route_add_del,
3003 {'br_tbl_id': {"bt_set": bti.set_id,
3004 "bt_sub_domain": bti.sub_domain_id,
3005 "bt_hdr_len_id": bti.hdr_len_id},
3006 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08003007 'br_n_paths': len(paths),
3008 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003009 'br_is_add': is_add})
3010
3011 def bier_route_dump(self, bti):
3012 return self.api(
3013 self.papi.bier_route_dump,
3014 {'br_tbl_id': {"bt_set": bti.set_id,
3015 "bt_sub_domain": bti.sub_domain_id,
3016 "bt_hdr_len_id": bti.hdr_len_id}})
3017
3018 def bier_imp_add(self,
3019 bti,
3020 src,
3021 ibytes,
3022 is_add=1):
3023 """ BIER Imposition Add """
3024 return self.api(
3025 self.papi.bier_imp_add,
3026 {'bi_tbl_id': {"bt_set": bti.set_id,
3027 "bt_sub_domain": bti.sub_domain_id,
3028 "bt_hdr_len_id": bti.hdr_len_id},
3029 'bi_src': src,
3030 'bi_n_bytes': len(ibytes),
3031 'bi_bytes': ibytes})
3032
3033 def bier_imp_del(self, bi_index):
3034 """ BIER Imposition del """
3035 return self.api(
3036 self.papi.bier_imp_del,
3037 {'bi_index': bi_index})
3038
3039 def bier_imp_dump(self):
3040 return self.api(self.papi.bier_imp_dump, {})
3041
3042 def bier_disp_table_add_del(self,
3043 bdti,
3044 is_add=1):
3045 """ BIER Disposition Table add/del """
3046 return self.api(
3047 self.papi.bier_disp_table_add_del,
3048 {'bdt_tbl_id': bdti,
3049 'bdt_is_add': is_add})
3050
3051 def bier_disp_table_dump(self):
3052 return self.api(self.papi.bier_disp_table_dump, {})
3053
3054 def bier_disp_entry_add_del(self,
3055 bdti,
3056 bp,
3057 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08003058 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003059 next_hop,
3060 next_hop_tbl_id=0,
3061 next_hop_rpf_id=~0,
3062 next_hop_is_ip4=1,
3063 is_add=1):
3064 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08003065 lstack = []
3066 while (len(lstack) < 16):
3067 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07003068 return self.api(
3069 self.papi.bier_disp_entry_add_del,
3070 {'bde_tbl_id': bdti,
3071 'bde_bp': bp,
3072 'bde_payload_proto': payload_proto,
3073 'bde_n_paths': 1,
3074 'bde_paths': [{'next_hop': next_hop,
3075 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003076 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003077 'rpf_id': next_hop_rpf_id,
3078 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003079 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003080 'bde_is_add': is_add})
3081
3082 def bier_disp_entry_dump(self, bdti):
3083 return self.api(
3084 self.papi.bier_disp_entry_dump,
3085 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003086
3087 def add_node_next(self, node_name, next_name):
3088 """ Set the next node for a given node request
3089
3090 :param node_name:
3091 :param next_name:
3092 """
3093 return self.api(self.papi.add_node_next,
3094 {'node_name': node_name,
3095 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003096
3097 def session_enable_disable(self, is_enabled):
3098 return self.api(
3099 self.papi.session_enable_disable,
3100 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003101
3102 def ipsec_spd_add_del(self, spd_id, is_add=1):
3103 """ SPD add/del - Wrapper to add or del ipsec SPD
3104 Sample CLI : 'ipsec spd add 1'
3105
3106 :param spd_id - SPD ID to be created in the vpp . mandatory
3107 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3108 optional
3109 :returns: reply from the API
3110 """
3111 return self.api(
3112 self.papi.ipsec_spd_add_del, {
3113 'spd_id': spd_id, 'is_add': is_add})
3114
3115 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3116 """ IPSEC interface SPD add/del - \
3117 Wrapper to associate/disassociate SPD to interface in VPP
3118 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3119
3120 :param spd_id - SPD ID to associate with the interface . mandatory
3121 :param sw_if_index - Interface Index which needs to ipsec \
3122 association mandatory
3123 :param is_add - add(1) or del(0) association with interface \
3124 (Default 1 - add) . optional
3125 :returns: reply from the API
3126 """
3127 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02003128 self.papi.ipsec_interface_add_del_spd,
3129 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003130
3131 def ipsec_sad_add_del_entry(self,
3132 sad_id,
3133 spi,
3134 tunnel_src_address='',
3135 tunnel_dst_address='',
3136 protocol=0,
3137 integrity_algorithm=2,
3138 integrity_key_length=0,
3139 integrity_key='C91KUR9GYMm5GfkEvNjX',
3140 crypto_algorithm=1,
3141 crypto_key_length=0,
3142 crypto_key='JPjyOWBeVEQiMe7h',
3143 is_add=1,
Klement Sekera4b089f22018-04-17 18:04:57 +02003144 is_tunnel=1,
3145 udp_encap=0):
“mystarrocks”23f0c452017-12-11 07:11:51 -08003146 """ IPSEC SA add/del
3147 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
3148 crypto-key 4a506a794f574265564551694d653768 \
3149 crypto-alg aes-cbc-128 \
3150 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3151 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3152 tunnel-dst 192.168.100.2'
3153 Sample CLI : 'ipsec sa add 20 spi 2001 \
3154 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3155 integ-alg sha1-96'
3156
3157 :param sad_id - Security Association ID to be \
3158 created or deleted. mandatory
3159 :param spi - security param index of the SA in decimal. mandatory
3160 :param tunnel_src_address - incase of tunnel mode outer src address .\
3161 mandatory for tunnel mode
3162 :param tunnel_dst_address - incase of transport mode \
3163 outer dst address. mandatory for tunnel mode
3164 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3165 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3166 optional **
3167 :param integrity_key - value in string \
3168 (Default C91KUR9GYMm5GfkEvNjX).optional
3169 :param integrity_key_length - length of the key string in bytes\
3170 (Default 0 - integrity disabled). optional
3171 :param crypto_algorithm - value range 1-11 Default \
3172 (1- AES_CBC_128).optional **
3173 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3174 :param crypto_key_length - length of the key string in bytes\
3175 (Default 0 - crypto disabled). optional
3176 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3177 optional
3178 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3179 (Default 1 - tunnel). optional
3180 :returns: reply from the API
3181 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3182 crypto and ipsec algorithms
3183 """
3184 return self.api(
3185 self.papi.ipsec_sad_add_del_entry,
3186 {'sad_id': sad_id,
3187 'spi': spi,
3188 'tunnel_src_address': tunnel_src_address,
3189 'tunnel_dst_address': tunnel_dst_address,
3190 'protocol': protocol,
3191 'integrity_algorithm': integrity_algorithm,
3192 'integrity_key_length': integrity_key_length,
3193 'integrity_key': integrity_key,
3194 'crypto_algorithm': crypto_algorithm,
3195 'crypto_key_length': crypto_key_length,
3196 'crypto_key': crypto_key,
3197 'is_add': is_add,
Klement Sekera4b089f22018-04-17 18:04:57 +02003198 'is_tunnel': is_tunnel,
3199 'udp_encap': udp_encap})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003200
3201 def ipsec_spd_add_del_entry(self,
3202 spd_id,
3203 local_address_start,
3204 local_address_stop,
3205 remote_address_start,
3206 remote_address_stop,
3207 local_port_start=0,
3208 local_port_stop=65535,
3209 remote_port_start=0,
3210 remote_port_stop=65535,
3211 protocol=0,
3212 sa_id=10,
3213 policy=0,
3214 priority=100,
3215 is_outbound=1,
3216 is_add=1,
3217 is_ip_any=0):
3218 """ IPSEC policy SPD add/del -
3219 Wrapper to configure ipsec SPD policy entries in VPP
3220 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3221 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3222 remote-ip-range 192.168.3.3 - 192.168.3.3'
3223
3224 :param spd_id - SPD ID for the policy . mandatory
3225 :param local_address_start - local-ip-range start address . mandatory
3226 :param local_address_stop - local-ip-range stop address . mandatory
3227 :param remote_address_start - remote-ip-range start address . mandatory
3228 :param remote_address_stop - remote-ip-range stop address . mandatory
3229 :param local_port_start - (Default 0) . optional
3230 :param local_port_stop - (Default 65535). optional
3231 :param remote_port_start - (Default 0). optional
3232 :param remote_port_stop - (Default 65535). optional
3233 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3234 optional
3235 :param sa_id - Security Association ID for mapping it to SPD
3236 (default 10). optional
3237 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3238 (Default 0 - bypass). optional
3239 :param priotity - value for the spd action (Default 100). optional
3240 :param is_outbound - flag for inbound(0) or outbound(1)
3241 (Default 1 - outbound). optional
3242 :param is_add flag - for addition(1) or deletion(0) of the spd
3243 (Default 1 - addtion). optional
3244 :returns: reply from the API
3245 """
3246 return self.api(
3247 self.papi.ipsec_spd_add_del_entry,
3248 {'spd_id': spd_id,
3249 'local_address_start': local_address_start,
3250 'local_address_stop': local_address_stop,
3251 'remote_address_start': remote_address_start,
3252 'remote_address_stop': remote_address_stop,
3253 'local_port_start': local_port_start,
3254 'local_port_stop': local_port_stop,
3255 'remote_port_start': remote_port_start,
3256 'remote_port_stop': remote_port_stop,
3257 'is_add': is_add,
3258 'protocol': protocol,
3259 'policy': policy,
3260 'priority': priority,
3261 'is_outbound': is_outbound,
3262 'sa_id': sa_id,
3263 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003264
3265 def app_namespace_add(self,
3266 namespace_id,
3267 ip4_fib_id=0,
3268 ip6_fib_id=0,
3269 sw_if_index=0xFFFFFFFF,
3270 secret=0):
3271 return self.api(
3272 self.papi.app_namespace_add_del,
3273 {'secret': secret,
3274 'sw_if_index': sw_if_index,
3275 'ip4_fib_id': ip4_fib_id,
3276 'ip6_fib_id': ip6_fib_id,
3277 'namespace_id': namespace_id,
3278 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003279
3280 def punt_socket_register(self, l4_port, pathname, header_version=1,
3281 is_ip4=1, l4_protocol=0x11):
3282 """ Punt to socket """
3283 return self.api(self.papi.punt_socket_register,
3284 {'is_ip4': is_ip4,
3285 'l4_protocol': l4_protocol,
3286 'l4_port': l4_port,
3287 'pathname': pathname,
3288 'header_version': header_version})
3289
3290 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3291 expire_walk_interval_ms, is_ip6=0):
3292 """ Set IP reassembly parameters """
3293 return self.api(self.papi.ip_reassembly_set,
3294 {'is_ip6': is_ip6,
3295 'timeout_ms': timeout_ms,
3296 'expire_walk_interval_ms': expire_walk_interval_ms,
3297 'max_reassemblies': max_reassemblies})
3298
3299 def ip_reassembly_get(self, is_ip6=0):
3300 """ Get IP reassembly parameters """
3301 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003302
Klement Sekera4c533132018-02-22 11:41:12 +01003303 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3304 enable_ip6=False):
3305 """ Enable/disable IP reassembly """
3306 return self.api(self.papi.ip_reassembly_enable_disable,
3307 {'sw_if_index': sw_if_index,
3308 'enable_ip4': 1 if enable_ip4 else 0,
3309 'enable_ip6': 1 if enable_ip6 else 0,
3310 })
3311
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003312 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3313 """ GBP endpoint Add/Del """
3314 return self.api(self.papi.gbp_endpoint_add_del,
3315 {'is_add': is_add,
3316 'endpoint': {
3317 'is_ip6': is_ip6,
3318 'sw_if_index': sw_if_index,
3319 'address': addr,
3320 'epg_id': epg}})
3321
3322 def gbp_endpoint_dump(self):
3323 """ GBP endpoint Dump """
3324 return self.api(self.papi.gbp_endpoint_dump, {})
3325
Neale Ranns25b04942018-04-04 09:34:50 -07003326 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3327 ip4_rd,
3328 ip6_rd,
3329 uplink_sw_if_index):
3330 """ GBP endpoint group Add/Del """
3331 return self.api(self.papi.gbp_endpoint_group_add_del,
3332 {'is_add': is_add,
3333 'epg': {
3334 'uplink_sw_if_index': uplink_sw_if_index,
3335 'bd_id': bd,
3336 'ip4_table_id': ip4_rd,
3337 'ip6_table_id': ip6_rd,
3338 'epg_id': epg}})
3339
3340 def gbp_endpoint_group_dump(self):
3341 """ GBP endpoint group Dump """
3342 return self.api(self.papi.gbp_endpoint_group_dump, {})
3343
3344 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3345 """ GBP recirc Add/Del """
3346 return self.api(self.papi.gbp_recirc_add_del,
3347 {'is_add': is_add,
3348 'recirc': {
3349 'is_ext': is_ext,
3350 'sw_if_index': sw_if_index,
3351 'epg_id': epg}})
3352
3353 def gbp_recirc_dump(self):
3354 """ GBP recirc Dump """
3355 return self.api(self.papi.gbp_recirc_dump, {})
3356
3357 def gbp_subnet_add_del(self, is_add, table_id,
3358 is_internal,
3359 addr, addr_len,
3360 sw_if_index=0xffffffff,
3361 epg_id=0xffffffff,
3362 is_ip6=False):
3363 """ GBP Subnet Add/Del """
3364 return self.api(self.papi.gbp_subnet_add_del,
3365 {'is_add': is_add,
3366 'subnet': {
3367 'is_internal': is_internal,
3368 'is_ip6': is_ip6,
3369 'sw_if_index': sw_if_index,
3370 'epg_id': epg_id,
3371 'address': addr,
3372 'address_length': addr_len,
3373 'table_id': table_id}})
3374
3375 def gbp_subnet_dump(self):
3376 """ GBP Subnet Dump """
3377 return self.api(self.papi.gbp_subnet_dump, {})
3378
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003379 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3380 """ GBP contract Add/Del """
3381 return self.api(self.papi.gbp_contract_add_del,
3382 {'is_add': is_add,
3383 'contract': {
3384 'acl_index': acl_index,
3385 'src_epg': src_epg,
3386 'dst_epg': dst_epg}})
3387
3388 def gbp_contract_dump(self):
3389 """ GBP contract Dump """
3390 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003391
Ole Troan298c6952018-03-08 12:30:43 +01003392 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3393 ip4_prefix, ip4_prefix_len, ip4_src,
3394 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003395 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003396 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003397 {'fib_index': fib_index,
3398 'ip6_prefix': ip6_prefix,
3399 'ip6_prefix_len': ip6_prefix_len,
3400 'ip4_prefix': ip4_prefix,
3401 'ip4_prefix_len': ip4_prefix_len,
3402 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003403 'security_check': security_check})
3404
Ole Troan298c6952018-03-08 12:30:43 +01003405 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003406 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003407 return self.api(self.papi.ipip_6rd_del_tunnel,
3408 {'sw_if_index': sw_if_index})
3409
3410 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
Ole Troand57f6362018-05-24 13:21:43 +02003411 instance=0xFFFFFFFF, fib_index=0, tc_tos=0):
Ole Troan298c6952018-03-08 12:30:43 +01003412 """ IPIP tunnel Add/Del """
3413 return self.api(self.papi.ipip_add_tunnel,
3414 {'is_ipv6': is_ipv6,
3415 'instance': instance,
3416 'src_address': src_address,
3417 'dst_address': dst_address,
Ole Troand57f6362018-05-24 13:21:43 +02003418 'fib_index': fib_index,
3419 'tc_tos': tc_tos})
Ole Troan298c6952018-03-08 12:30:43 +01003420
3421 def ipip_del_tunnel(self, sw_if_index):
3422 """ IPIP tunnel Delete """
3423 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003424 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003425
3426 def qos_egress_map_update(self, id, outputs):
3427 """ QOS egress map update """
3428 return self.api(self.papi.qos_egress_map_update,
3429 {'map_id': id,
3430 'rows': outputs})
3431
3432 def qos_egress_map_delete(self, id):
3433 """ QOS egress map delete """
3434 return self.api(self.papi.qos_egress_map_delete,
3435 {'map_id': id})
3436
3437 def qos_mark_enable_disable(self, sw_if_index,
3438 output_source,
3439 map_id,
3440 enable):
3441 """ QOS Mark Enable/Disable """
3442 return self.api(self.papi.qos_mark_enable_disable,
3443 {'map_id': map_id,
3444 'sw_if_index': sw_if_index,
3445 'output_source': output_source,
3446 'enable': enable})
3447
3448 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3449 """ IP QoS recording Enble/Disable """
3450 return self.api(self.papi.qos_record_enable_disable,
3451 {'sw_if_index': sw_if_index,
3452 'input_source': input_source,
3453 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003454
3455 def igmp_listen(self, enable, sw_if_index, saddr, gaddr):
3456 """ Listen for new (S,G) on specified interface
3457
3458 :param enable: add/del
3459 :param sw_if_index: interface sw index
3460 :param saddr: source ip4 addr
3461 :param gaddr: group ip4 addr
3462 """
3463 return self.api(self.papi.igmp_listen,
3464 {'enable': enable,
3465 'sw_if_index': sw_if_index,
3466 'saddr': saddr,
3467 'gaddr': gaddr})
3468
3469 def igmp_dump(self, sw_if_index=None):
3470 """ Dump all (S,G) interface configurations """
3471 if sw_if_index is None:
3472 dump_all = 1
3473 sw_if_index = 0
3474 else:
3475 dump_all = 0
3476 return self.api(self.papi.igmp_dump, {'sw_if_index': sw_if_index,
3477 'dump_all': dump_all})
3478
3479 def igmp_clear_interface(self, sw_if_index):
3480 """ Remove all (S,G)s from specified interface
3481 doesn't send IGMP report!
3482 """
3483 return self.api(
3484 self.papi.igmp_clear_interface, {
3485 'sw_if_index': sw_if_index})
3486
3487 def want_igmp_events(self, enable=1):
3488 return self.api(self.papi.want_igmp_events, {'enable': enable,
3489 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003490
3491 def bond_create(
3492 self,
3493 mode,
3494 lb,
3495 use_custom_mac,
3496 mac_address=''):
3497 """
3498 :param mode: mode
3499 :param lb: load balance
3500 :param use_custom_mac: use custom mac
3501 :param mac_address: mac address
3502 """
3503 return self.api(
3504 self.papi.bond_create,
3505 {'mode': mode,
3506 'lb': lb,
3507 'use_custom_mac': use_custom_mac,
3508 'mac_address': mac_address
3509 })
3510
3511 def bond_delete(
3512 self,
3513 sw_if_index):
3514 """
3515 :param sw_if_index: interface the operation is applied to
3516 """
3517 return self.api(self.papi.bond_delete,
3518 {'sw_if_index': sw_if_index})
3519
3520 def bond_enslave(
3521 self,
3522 sw_if_index,
3523 bond_sw_if_index,
3524 is_passive,
3525 is_long_timeout):
3526 """
3527 :param sw_if_index: slave sw_if_index
3528 :param bond_sw_if_index: bond sw_if_index
3529 :param is_passive: is passive lacp speaker
3530 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3531 """
3532 return self.api(
3533 self.papi.bond_enslave,
3534 {'sw_if_index': sw_if_index,
3535 'bond_sw_if_index': bond_sw_if_index,
3536 'is_passive': is_passive,
3537 'is_long_timeout': is_long_timeout
3538 })
3539
3540 def bond_detach_slave(
3541 self,
3542 sw_if_index):
3543 """
3544 :param sw_if_index: slave interface the operation is applied to
3545 """
3546 return self.api(self.papi.bond_detach_slave,
3547 {'sw_if_index': sw_if_index})
3548
3549 def sw_interface_slave_dump(
3550 self,
3551 sw_if_index):
3552 """
3553 :param sw_if_index: bond sw_if_index
3554 """
3555 return self.api(self.papi.sw_interface_slave_dump,
3556 {'sw_if_index': sw_if_index})
3557
3558 def sw_interface_bond_dump(
3559 self):
3560 """
3561
3562 """
3563 return self.api(self.papi.sw_interface_bond_dump,
3564 {})
Stevene8fa6202017-08-30 14:36:45 -07003565
3566 def create_vhost_user_if(
3567 self,
3568 is_server,
3569 sock_filename,
3570 renumber,
3571 custom_dev_instance,
3572 use_custom_mac,
3573 mac_address,
3574 tag=''):
3575 """
3576 :param is_server: is server
3577 :param sock_filename: socket name
3578 :param renumber: renumber
3579 :param custom_dev_instance: custom dev instance
3580 :param use_custom_mac: use custom mac
3581 :param mac_address: mac address
3582 :param tag: tag (default ''
3583 """
3584 return self.api(
3585 self.papi.create_vhost_user_if,
3586 {'is_server': is_server,
3587 'sock_filename': sock_filename,
3588 'renumber': renumber,
3589 'custom_dev_instance': custom_dev_instance,
3590 'use_custom_mac': use_custom_mac,
3591 'mac_address': mac_address,
3592 'tag': tag
3593 })
3594
3595 def delete_vhost_user_if(
3596 self,
3597 sw_if_index):
3598 """
3599 :param sw_if_index: interface the operation is applied to
3600 """
3601 return self.api(self.papi.delete_vhost_user_if,
3602 {'sw_if_index': sw_if_index, })
3603
3604 def sw_interface_vhost_user_dump(
3605 self):
3606 """
3607
3608 """
3609 return self.api(self.papi.sw_interface_vhost_user_dump,
3610 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003611
3612 def abf_policy_add_del(self, is_add, policy):
3613 return self.api(
3614 self.papi.abf_policy_add_del,
3615 {'is_add': is_add,
3616 'policy': policy})
3617
3618 def abf_itf_attach_add_del(self, is_add, attach):
3619 return self.api(
3620 self.papi.abf_itf_attach_add_del,
3621 {'is_add': is_add,
3622 'attach': attach})
3623
3624 def abf_policy_dump(self):
3625 return self.api(
3626 self.papi.abf_policy_dump, {})
3627
3628 def abf_itf_attach_dump(self):
3629 return self.api(
3630 self.papi.abf_itf_attach_dump, {})