blob: 4fdd94ba35149f6da63385f5678f3c26b4c45cff [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
Jan4af521d2016-11-15 17:05:00 +0100506 def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
507 filter_mac=0, bvi_mac=0):
508 """Create/delete L2 FIB entry.
509
510 :param str mac: MAC address to create FIB entry for.
511 :param int bd_id: Bridge domain index.
512 :param int sw_if_index: Software interface index of the interface.
513 :param int is_add: Add or delete flag. (Default value = 1)
514 :param int static_mac: Set to 1 to create static MAC entry.
515 (Default value = 0)
516 :param int filter_mac: Set to 1 to drop packet that's source or
517 destination MAC address contains defined MAC address.
518 (Default value = 0)
519 :param int bvi_mac: Set to 1 to create entry that points to BVI
520 interface. (Default value = 0)
521 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100522 return self.api(self.papi.l2fib_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200523 {'mac': self._convert_mac(mac),
524 'bd_id': bd_id,
525 'sw_if_index': sw_if_index,
526 'is_add': is_add,
527 'static_mac': static_mac,
528 'filter_mac': filter_mac,
529 'bvi_mac': bvi_mac})
Jan4af521d2016-11-15 17:05:00 +0100530
Eyal Bari93b503e2017-05-15 10:13:15 +0300531 def l2fib_flush_int(self, sw_if_index):
532 """Flush L2 FIB entries for sw_if_index.
533
534 :param int sw_if_index: Software interface index of the interface.
535 """
536 return self.api(self.papi.l2fib_flush_int,
537 {'sw_if_index': sw_if_index})
538
539 def l2fib_flush_bd(self, bd_id):
540 """Flush L2 FIB entries for bd_id.
541
542 :param int sw_if_index: Bridge Domain id.
543 """
544 return self.api(self.papi.l2fib_flush_bd,
545 {'bd_id': bd_id})
546
547 def l2fib_flush_all(self):
548 """Flush all L2 FIB.
549 """
550 return self.api(self.papi.l2fib_flush_all, {})
551
Klement Sekeraf62ae122016-10-11 11:47:09 +0200552 def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
553 shg=0, bvi=0, enable=1):
Jan4af521d2016-11-15 17:05:00 +0100554 """Add/remove interface to/from bridge domain.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200555
Jan4af521d2016-11-15 17:05:00 +0100556 :param int sw_if_index: Software interface index of the interface.
557 :param int bd_id: Bridge domain index.
558 :param int shg: Split-horizon group index. (Default value = 0)
559 :param int bvi: Set interface as a bridge group virtual interface.
560 (Default value = 0)
561 :param int enable: Add or remove interface. (Default value = 1)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200562 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100563 return self.api(self.papi.sw_interface_set_l2_bridge,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200564 {'rx_sw_if_index': sw_if_index,
565 'bd_id': bd_id,
566 'shg': shg,
567 'bvi': bvi,
568 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200569
Jan00dad122016-11-29 10:04:53 +0100570 def bridge_flags(self, bd_id, is_set, feature_bitmap):
571 """Enable/disable required feature of the bridge domain with defined ID.
572
573 :param int bd_id: Bridge domain ID.
574 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
575 :param int feature_bitmap: Bitmap value of the feature to be set:
576 - learn (1 << 0),
577 - forward (1 << 1),
578 - flood (1 << 2),
579 - uu-flood (1 << 3) or
580 - arp-term (1 << 4).
581 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100582 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200583 {'bd_id': bd_id,
584 'is_set': is_set,
585 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100586
587 def bridge_domain_dump(self, bd_id=0):
588 """
589
590 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
591 existing bridge domains returned)
592 :return: Dictionary of bridge domain(s) data.
593 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100594 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200595 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100596
Klement Sekeraf62ae122016-10-11 11:47:09 +0200597 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
598 enable):
599 """Create or delete unidirectional cross-connect from Tx interface to
600 Rx interface.
601
Jan4af521d2016-11-15 17:05:00 +0100602 :param int rx_sw_if_index: Software interface index of Rx interface.
603 :param int tx_sw_if_index: Software interface index of Tx interface.
604 :param int enable: Create cross-connect if equal to 1, delete
605 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200606
607 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100608 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200609 {'rx_sw_if_index': rx_sw_if_index,
610 'tx_sw_if_index': tx_sw_if_index,
611 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200612
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200613 def sw_interface_set_l2_tag_rewrite(
614 self,
615 sw_if_index,
616 vtr_oper,
617 push=0,
618 tag1=0,
619 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000620 """L2 interface vlan tag rewrite configure request
621 :param client_index - opaque cookie to identify the sender
622 :param context - sender context, to match reply w/ request
623 :param sw_if_index - interface the operation is applied to
624 :param vtr_op - Choose from l2_vtr_op_t enum values
625 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
626 :param tag1 - Needed for any push or translate vtr op
627 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
628
629 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100630 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200631 {'sw_if_index': sw_if_index,
632 'vtr_op': vtr_oper,
633 'push_dot1q': push,
634 'tag1': tag1,
635 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000636
Neale Ranns55d03782017-10-21 06:34:22 -0700637 def sw_interface_set_l2_emulation(
638 self,
639 sw_if_index,
640 enable=1):
641 """L2 Emulation
642 :param sw_if_index - interface the operation is applied to
643
644 """
645 return self.api(self.papi.l2_emulation,
646 {'sw_if_index': sw_if_index,
647 'enable': enable})
648
Neale Rannsa07bd702017-08-07 07:53:49 -0700649 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200650 """
651
652 :param admin_up_down:
653 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200654
655 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100656 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200657 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700658 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200659
Neale Rannsffd78d12018-02-09 06:05:16 -0800660 def sw_interface_set_mtu(self, sw_if_index, mtu):
661 """
662 :param sw_if_index:
663 :param mtu:
664
665 """
666 return self.api(self.papi.sw_interface_set_mtu,
667 {'sw_if_index': sw_if_index,
668 'mtu': mtu})
669
Neale Rannsc819fc62018-02-16 02:44:05 -0800670 def sw_interface_set_mac_address(self, sw_if_index, mac):
671 return self.api(self.papi.sw_interface_set_mac_address,
672 {'sw_if_index': sw_if_index,
673 'mac_address': mac})
674
Klement Sekeraf62ae122016-10-11 11:47:09 +0200675 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
676 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
677 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
678 """Create subinterface
679 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
680
681 :param sub_id: param inner_vlan:
682 :param sw_if_index:
683 :param outer_vlan:
684 :param inner_vlan:
685 :param no_tags: (Default value = 0)
686 :param one_tag: (Default value = 0)
687 :param two_tags: (Default value = 0)
688 :param dot1ad: (Default value = 0)
689 :param exact_match: (Default value = 0)
690 :param default_sub: (Default value = 0)
691 :param outer_vlan_id_any: (Default value = 0)
692 :param inner_vlan_id_any: (Default value = 0)
693
694 """
695 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100696 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200697 {'sw_if_index': sw_if_index,
698 'sub_id': sub_id,
699 'no_tags': no_tags,
700 'one_tag': one_tag,
701 'two_tags': two_tags,
702 'dot1ad': dot1ad,
703 'exact_match': exact_match,
704 'default_sub': default_sub,
705 'outer_vlan_id_any': outer_vlan_id_any,
706 'inner_vlan_id_any': inner_vlan_id_any,
707 'outer_vlan_id': outer_vlan,
708 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200709
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200710 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
711 """Create p2p ethernet subinterface
712
713 :param sw_if_index: main (parent) interface
714 :param remote_mac: client (remote) mac address
715
716 """
717 return self.api(
718 self.papi.p2p_ethernet_add,
719 {'parent_if_index': sw_if_index,
720 'remote_mac': remote_mac,
721 'subif_id': subif_id})
722
Neale Ranns177bbdc2016-11-15 09:46:51 +0000723 def delete_subif(self, sw_if_index):
724 """Delete subinterface
725
726 :param sw_if_index:
727 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100728 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200729 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000730
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200731 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
732 """Delete p2p ethernet subinterface
733
734 :param sw_if_index: main (parent) interface
735 :param remote_mac: client (remote) mac address
736
737 """
738 return self.api(
739 self.papi.p2p_ethernet_del,
740 {'parent_if_index': sw_if_index,
741 'remote_mac': remote_mac})
742
Klement Sekeraf62ae122016-10-11 11:47:09 +0200743 def create_vlan_subif(self, sw_if_index, vlan):
744 """
745
746 :param vlan:
747 :param sw_if_index:
748
749 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100750 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200751 {'sw_if_index': sw_if_index,
752 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200753
Matej Klotton0178d522016-11-04 11:11:44 +0100754 def create_loopback(self, mac=''):
755 """
756
757 :param mac: (Optional)
758 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100759 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200760 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100761
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100762 def delete_loopback(self, sw_if_index):
763 return self.api(self.papi.delete_loopback,
764 {'sw_if_index': sw_if_index, })
765
Neale Ranns15002542017-09-10 04:39:11 -0700766 def ip_table_add_del(self,
767 table_id,
768 is_add=1,
769 is_ipv6=0):
770 """
771
772 :param table_id
773 :param is_add: (Default value = 1)
774 :param is_ipv6: (Default value = 0)
775
776 """
777
778 return self.api(
779 self.papi.ip_table_add_del,
780 {'table_id': table_id,
781 'is_add': is_add,
782 'is_ipv6': is_ipv6})
783
Klement Sekeraf62ae122016-10-11 11:47:09 +0200784 def ip_add_del_route(
785 self,
786 dst_address,
787 dst_address_length,
788 next_hop_address,
789 next_hop_sw_if_index=0xFFFFFFFF,
790 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200791 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000792 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200793 next_hop_n_out_labels=0,
794 next_hop_out_label_stack=[],
795 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800796 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000797 is_resolve_host=0,
798 is_resolve_attached=0,
799 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200800 is_add=1,
801 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200802 is_unreach=0,
803 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200804 is_ipv6=0,
805 is_local=0,
806 is_classify=0,
807 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800808 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800809 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200810 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200811 """
812
813 :param dst_address_length:
814 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
815 :param dst_address:
816 :param next_hop_address:
817 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
818 :param vrf_id: (Default value = 0)
819 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200820 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200821 :param is_add: (Default value = 1)
822 :param is_drop: (Default value = 0)
823 :param is_ipv6: (Default value = 0)
824 :param is_local: (Default value = 0)
825 :param is_classify: (Default value = 0)
826 :param is_multipath: (Default value = 0)
827 :param is_resolve_host: (Default value = 0)
828 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800829 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700830 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200831 :param next_hop_weight: (Default value = 1)
832
833 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000834
Klement Sekeraf62ae122016-10-11 11:47:09 +0200835 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100836 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200837 {'next_hop_sw_if_index': next_hop_sw_if_index,
838 'table_id': table_id,
839 'classify_table_index': classify_table_index,
840 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200841 'is_add': is_add,
842 'is_drop': is_drop,
843 'is_unreach': is_unreach,
844 'is_prohibit': is_prohibit,
845 'is_ipv6': is_ipv6,
846 'is_local': is_local,
847 'is_classify': is_classify,
848 'is_multipath': is_multipath,
849 'is_resolve_host': is_resolve_host,
850 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800851 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700852 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800853 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200854 'next_hop_weight': next_hop_weight,
855 'dst_address_length': dst_address_length,
856 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800857 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200858 'next_hop_address': next_hop_address,
859 'next_hop_n_out_labels': next_hop_n_out_labels,
860 'next_hop_via_label': next_hop_via_label,
861 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100862
Matej Klotton16a14cd2016-12-07 15:09:13 +0100863 def ip_fib_dump(self):
864 return self.api(self.papi.ip_fib_dump, {})
865
Jan Gelety057bb8c2016-12-20 17:32:45 +0100866 def ip6_fib_dump(self):
867 return self.api(self.papi.ip6_fib_dump, {})
868
Matej Klotton0178d522016-11-04 11:11:44 +0100869 def ip_neighbor_add_del(self,
870 sw_if_index,
871 mac_address,
872 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100873 is_add=1,
874 is_ipv6=0,
875 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800876 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100877 ):
878 """ Add neighbor MAC to IPv4 or IPv6 address.
879
880 :param sw_if_index:
881 :param mac_address:
882 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100883 :param is_add: (Default value = 1)
884 :param is_ipv6: (Default value = 0)
885 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800886 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100887 """
888
889 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100890 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800891 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200892 'is_add': is_add,
893 'is_ipv6': is_ipv6,
894 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800895 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200896 'mac_address': mac_address,
897 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100898 }
Matej Klotton0178d522016-11-04 11:11:44 +0100899 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100900
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800901 def ip_neighbor_dump(self,
902 sw_if_index,
903 is_ipv6=0):
904 """ Return IP neighbor dump.
905
906 :param sw_if_index:
907 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
908 """
909
910 return self.api(
911 self.papi.ip_neighbor_dump,
912 {'is_ipv6': is_ipv6,
913 'sw_if_index': sw_if_index
914 }
915 )
916
917 def proxy_arp_add_del(self,
918 low_address,
919 hi_address,
920 vrf_id=0,
921 is_add=1):
922 """ Config Proxy Arp Range.
923
924 :param low_address: Start address in the rnage to Proxy for
925 :param hi_address: End address in the rnage to Proxy for
926 :param vrf_id: The VRF/table in which to proxy
927 """
928
929 return self.api(
930 self.papi.proxy_arp_add_del,
931 {'vrf_id': vrf_id,
932 'is_add': is_add,
933 'low_address': low_address,
934 'hi_address': hi_address,
935 }
936 )
937
938 def proxy_arp_intfc_enable_disable(self,
939 sw_if_index,
940 is_enable=1):
941 """ Enable/Disable an interface for proxy ARP requests
942
943 :param sw_if_index: Interface
944 :param enable_disable: Enable/Disable
945 """
946
947 return self.api(
948 self.papi.proxy_arp_intfc_enable_disable,
949 {'sw_if_index': sw_if_index,
950 'enable_disable': is_enable
951 }
952 )
953
Jane546d3b2016-12-08 13:10:03 +0100954 def reset_vrf(self,
955 vrf_id,
956 is_ipv6=0,
957 ):
958 """ Reset VRF (remove all routes etc.) request.
959
960 :param int vrf_id: ID of the FIB table / VRF to reset.
961 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
962 """
963
964 return self.api(
965 self.papi.reset_vrf,
966 {'vrf_id': vrf_id,
967 'is_ipv6': is_ipv6,
968 }
969 )
970
971 def reset_fib(self,
972 vrf_id,
973 is_ipv6=0,
974 ):
975 """ Reset VRF (remove all routes etc.) request.
976
977 :param int vrf_id: ID of the FIB table / VRF to reset.
978 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
979 """
980
981 return self.api(
982 self.papi.reset_fib,
983 {'vrf_id': vrf_id,
984 'is_ipv6': is_ipv6,
985 }
986 )
987
988 def ip_dump(self,
989 is_ipv6=0,
990 ):
991 """ Return IP dump.
992
993 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
994 """
995
996 return self.api(
997 self.papi.ip_dump,
998 {'is_ipv6': is_ipv6,
999 }
1000 )
1001
Klement Sekera7bb873a2016-11-18 07:38:42 +01001002 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001003 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001004 """
1005
1006 :param sw_if_index_from:
1007 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001008 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001009 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001010 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001011 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001012 {'sw_if_index_from': sw_if_index_from,
1013 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001014 'state': state,
1015 'is_l2': is_l2,
1016 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001017
1018 def gre_tunnel_add_del(self,
1019 src_address,
1020 dst_address,
1021 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001022 tunnel_type=0,
1023 instance=0xFFFFFFFF,
1024 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001025 is_add=1,
1026 is_ip6=0):
1027 """ Add a GRE tunnel
1028
1029 :param src_address:
1030 :param dst_address:
1031 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001032 :param tunnel_type: (Default value = 0)
1033 :param instance: (Default value = 0xFFFFFFFF)
1034 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001035 :param is_add: (Default value = 1)
1036 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001037 """
1038
1039 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001040 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001041 {'is_add': is_add,
1042 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001043 'tunnel_type': tunnel_type,
1044 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001045 'src_address': src_address,
1046 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001047 'outer_fib_id': outer_fib_id,
1048 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001049 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001050
Neale Ranns810086d2017-11-05 16:26:46 -08001051 def udp_encap_add_del(self,
1052 id,
1053 src_ip,
1054 dst_ip,
1055 src_port,
1056 dst_port,
1057 table_id=0,
1058 is_add=1,
1059 is_ip6=0):
1060 """ Add a GRE tunnel
1061 :param id: user provided ID
1062 :param src_ip:
1063 :param dst_ip:
1064 :param src_port:
1065 :param dst_port:
1066 :param outer_fib_id: (Default value = 0)
1067 :param is_add: (Default value = 1)
1068 :param is_ipv6: (Default value = 0)
1069 """
1070
1071 return self.api(
1072 self.papi.udp_encap_add_del,
1073 {'id': id,
1074 'is_add': is_add,
1075 'is_ip6': is_ip6,
1076 'src_ip': src_ip,
1077 'dst_ip': dst_ip,
1078 'src_port': src_port,
1079 'dst_port': dst_port,
1080 'table_id': table_id}
1081 )
1082
1083 def udp_encap_dump(self):
1084 return self.api(self.papi.udp_encap_dump, {})
1085
Neale Ranns43b1f442018-03-20 01:47:35 -07001086 def want_udp_encap_stats(self, enable=1):
1087 return self.api(self.papi.want_udp_encap_stats,
1088 {'enable': enable,
1089 'pid': os.getpid()})
1090
Neale Ranns5a8123b2017-01-26 01:18:23 -08001091 def mpls_fib_dump(self):
1092 return self.api(self.papi.mpls_fib_dump, {})
1093
Neale Ranns15002542017-09-10 04:39:11 -07001094 def mpls_table_add_del(
1095 self,
1096 table_id,
1097 is_add=1):
1098 """
1099
1100 :param table_id
1101 :param is_add: (Default value = 1)
1102
1103 """
1104
1105 return self.api(
1106 self.papi.mpls_table_add_del,
1107 {'mt_table_id': table_id,
1108 'mt_is_add': is_add})
1109
Neale Rannsad422ed2016-11-02 14:20:04 +00001110 def mpls_route_add_del(
1111 self,
1112 label,
1113 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001114 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001115 next_hop_address,
1116 next_hop_sw_if_index=0xFFFFFFFF,
1117 table_id=0,
1118 next_hop_table_id=0,
1119 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001120 next_hop_n_out_labels=0,
1121 next_hop_out_label_stack=[],
1122 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001123 is_resolve_host=0,
1124 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001125 is_interface_rx=0,
1126 is_rpf_id=0,
1127 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001128 is_add=1,
1129 is_drop=0,
1130 is_multipath=0,
1131 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001132 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001133 """
1134
1135 :param dst_address_length:
1136 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1137 :param dst_address:
1138 :param next_hop_address:
1139 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1140 :param vrf_id: (Default value = 0)
1141 :param lookup_in_vrf: (Default value = 0)
1142 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001143 :param is_add: (Default value = 1)
1144 :param is_drop: (Default value = 0)
1145 :param is_ipv6: (Default value = 0)
1146 :param is_local: (Default value = 0)
1147 :param is_classify: (Default value = 0)
1148 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001149 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001150 :param is_resolve_host: (Default value = 0)
1151 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001152 :param next_hop_weight: (Default value = 1)
1153
1154 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001155 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001156 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001157 {'mr_label': label,
1158 'mr_eos': eos,
1159 'mr_table_id': table_id,
1160 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001161 'mr_is_add': is_add,
1162 'mr_is_classify': is_classify,
1163 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001164 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001165 'mr_is_resolve_host': is_resolve_host,
1166 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001167 'mr_is_interface_rx': is_interface_rx,
1168 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001169 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001170 'mr_next_hop_weight': next_hop_weight,
1171 'mr_next_hop': next_hop_address,
1172 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1173 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1174 'mr_next_hop_table_id': next_hop_table_id,
1175 'mr_next_hop_via_label': next_hop_via_label,
1176 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001177
1178 def mpls_ip_bind_unbind(
1179 self,
1180 label,
1181 dst_address,
1182 dst_address_length,
1183 table_id=0,
1184 ip_table_id=0,
1185 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001186 is_bind=1):
1187 """
1188 """
1189 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001190 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001191 {'mb_mpls_table_id': table_id,
1192 'mb_label': label,
1193 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001194 'mb_is_bind': is_bind,
1195 'mb_is_ip4': is_ip4,
1196 'mb_address_length': dst_address_length,
1197 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001198
1199 def mpls_tunnel_add_del(
1200 self,
1201 tun_sw_if_index,
1202 next_hop_proto_is_ip4,
1203 next_hop_address,
1204 next_hop_sw_if_index=0xFFFFFFFF,
1205 next_hop_table_id=0,
1206 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001207 next_hop_n_out_labels=0,
1208 next_hop_out_label_stack=[],
1209 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001210 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001211 l2_only=0,
1212 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001213 """
1214
1215 :param dst_address_length:
1216 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1217 :param dst_address:
1218 :param next_hop_address:
1219 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1220 :param vrf_id: (Default value = 0)
1221 :param lookup_in_vrf: (Default value = 0)
1222 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001223 :param is_add: (Default value = 1)
1224 :param is_drop: (Default value = 0)
1225 :param is_ipv6: (Default value = 0)
1226 :param is_local: (Default value = 0)
1227 :param is_classify: (Default value = 0)
1228 :param is_multipath: (Default value = 0)
1229 :param is_resolve_host: (Default value = 0)
1230 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001231 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001232 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001233
1234 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001235 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001236 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001237 {'mt_sw_if_index': tun_sw_if_index,
1238 'mt_is_add': is_add,
1239 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001240 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001241 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1242 'mt_next_hop_weight': next_hop_weight,
1243 'mt_next_hop': next_hop_address,
1244 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1245 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1246 'mt_next_hop_table_id': next_hop_table_id,
1247 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001248
Matus Fabian2ba92e32017-08-21 07:05:03 -07001249 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001250 self,
1251 sw_if_index,
1252 is_inside=1,
1253 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001254 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001255
1256 :param sw_if_index: Software index of the interface
1257 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1258 :param is_add: 1 if add, 0 if delete (Default value = 1)
1259 """
1260 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001261 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001262 {'is_add': is_add,
1263 'is_inside': is_inside,
1264 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001265
Matus Fabian2ba92e32017-08-21 07:05:03 -07001266 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001267 self,
1268 sw_if_index,
1269 is_inside=1,
1270 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001271 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001272
1273 :param sw_if_index: Software index of the interface
1274 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1275 :param is_add: 1 if add, 0 if delete (Default value = 1)
1276 """
1277 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001278 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001279 {'is_add': is_add,
1280 'is_inside': is_inside,
1281 'sw_if_index': sw_if_index})
1282
Matus Fabian2ba92e32017-08-21 07:05:03 -07001283 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001284 self,
1285 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001286 external_ip=0,
1287 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001288 local_port=0,
1289 external_port=0,
1290 addr_only=1,
1291 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001292 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001293 twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001294 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001295 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001296 is_add=1):
1297 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001298
1299 :param local_ip: Local IP address
1300 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001301 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001302 :param local_port: Local port number (Default value = 0)
1303 :param external_port: External port number (Default value = 0)
1304 :param addr_only: 1 if address only mapping, 0 if address and port
1305 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001306 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001307 :param twice_nat: 1 if translate external host address and port
Matus Fabiane82488f2018-01-18 03:38:45 -08001308 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001309 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001310 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001311 """
1312 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001313 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001314 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001315 'addr_only': addr_only,
1316 'local_ip_address': local_ip,
1317 'external_ip_address': external_ip,
1318 'local_port': local_port,
1319 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001320 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001321 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001322 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001323 'twice_nat': twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001324 'out2in_only': out2in_only,
1325 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001326
Matus Fabianab7a8052017-11-28 04:29:41 -08001327 def nat44_add_del_identity_mapping(
1328 self,
1329 ip='0',
1330 sw_if_index=0xFFFFFFFF,
1331 port=0,
1332 addr_only=1,
1333 vrf_id=0,
1334 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001335 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001336 is_add=1):
1337 """Add/delete NAT44 identity mapping
1338
1339 :param ip: IP address (Default value = 0)
1340 :param sw_if_index: Interface instead of IP address
1341 :param port: Port number (Default value = 0)
1342 :param addr_only: 1 if address only mapping, 0 if address and port
1343 :param vrf_id: VRF ID
1344 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001345 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001346 :param is_add: 1 if add, 0 if delete (Default value = 1)
1347 """
1348 return self.api(
1349 self.papi.nat44_add_del_identity_mapping,
1350 {'is_add': is_add,
1351 'addr_only': addr_only,
1352 'ip_address': ip,
1353 'port': port,
1354 'sw_if_index': sw_if_index,
1355 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001356 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001357 'protocol': protocol})
1358
Matus Fabian2ba92e32017-08-21 07:05:03 -07001359 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001360 self,
1361 first_ip_address,
1362 last_ip_address,
1363 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001364 vrf_id=0xFFFFFFFF,
1365 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001366 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001367
1368 :param first_ip_address: First IP address
1369 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001370 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001371 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001372 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001373 """
1374 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001375 self.papi.nat44_add_del_address_range,
1376 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001377 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001378 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001379 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001380 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001381
Matus Fabian2ba92e32017-08-21 07:05:03 -07001382 def nat44_address_dump(self):
1383 """Dump NAT44 addresses
1384 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001385 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001387
Matus Fabian2ba92e32017-08-21 07:05:03 -07001388 def nat44_interface_dump(self):
1389 """Dump interfaces with NAT44 feature
1390 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001391 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001392 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001393
Matus Fabian2ba92e32017-08-21 07:05:03 -07001394 def nat44_interface_output_feature_dump(self):
1395 """Dump interfaces with NAT44 output feature
1396 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001397 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001398 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001399
Matus Fabian2ba92e32017-08-21 07:05:03 -07001400 def nat44_static_mapping_dump(self):
1401 """Dump NAT44 static mappings
1402 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001403 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001404 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001405
Matus Fabianab7a8052017-11-28 04:29:41 -08001406 def nat44_identity_mapping_dump(self):
1407 """Dump NAT44 identity mappings
1408 :return: Dictionary of NAT44 identity mappings
1409 """
1410 return self.api(self.papi.nat44_identity_mapping_dump, {})
1411
Matus Fabian2ba92e32017-08-21 07:05:03 -07001412 def nat_show_config(self):
1413 """Show NAT plugin config
1414 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001415 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001416 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001417
Matus Fabian2ba92e32017-08-21 07:05:03 -07001418 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001419 self,
1420 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001421 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001422 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001423 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001424
1425 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001426 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001427 :param is_add: 1 if add, 0 if delete (Default value = 1)
1428 """
Matus Fabianb932d262017-12-18 05:38:24 -08001429 return self.api(
1430 self.papi.nat44_add_del_interface_addr,
1431 {'is_add': is_add,
1432 'sw_if_index': sw_if_index,
1433 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001434
Matus Fabian2ba92e32017-08-21 07:05:03 -07001435 def nat44_interface_addr_dump(self):
1436 """Dump NAT44 addresses interfaces
1437 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001438 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001439 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001440
Matus Fabian2ba92e32017-08-21 07:05:03 -07001441 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001442 self,
1443 domain_id=1,
1444 src_port=4739,
1445 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001446 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001447
1448 :param domain_id: Observation domain ID (Default value = 1)
1449 :param src_port: Source port number (Default value = 4739)
1450 :param enable: 1 if enable, 0 if disable (Default value = 1)
1451 """
1452 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001453 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001454 {'domain_id': domain_id,
1455 'src_port': src_port,
1456 'enable': enable})
1457
Matus Fabian2ba92e32017-08-21 07:05:03 -07001458 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001459 self,
1460 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001461 vrf_id):
1462 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001463
1464 :param ip_address: ip adress of the user to be dumped
1465 :param cpu_index: cpu_index on which the user is
1466 :param vrf_id: VRF ID
1467 :return: Dictionary of S-NAT sessions
1468 """
1469 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001470 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001471 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001472 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001473
Matus Fabian2ba92e32017-08-21 07:05:03 -07001474 def nat44_user_dump(self):
1475 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001476
Matus Fabian2ba92e32017-08-21 07:05:03 -07001477 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001478 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001479 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001480
Matus Fabian704018c2017-09-04 02:17:18 -07001481 def nat44_add_del_lb_static_mapping(
1482 self,
1483 external_addr,
1484 external_port,
1485 protocol,
1486 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001487 twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001488 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001489 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001490 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001491 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001492 is_add=1):
1493 """Add/delete NAT44 load balancing static mapping
1494
Matus Fabianb932d262017-12-18 05:38:24 -08001495 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001496 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001497 :param is_add - 1 if add, 0 if delete
1498 """
1499 return self.api(
1500 self.papi.nat44_add_del_lb_static_mapping,
1501 {'is_add': is_add,
1502 'external_addr': external_addr,
1503 'external_port': external_port,
1504 'protocol': protocol,
1505 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001506 'twice_nat': twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001507 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001508 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001509 'local_num': local_num,
1510 'locals': locals})
1511
1512 def nat44_lb_static_mapping_dump(self):
1513 """Dump NAT44 load balancing static mappings
1514
1515 :return: Dictionary of NAT44 load balancing static mapping
1516 """
1517 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1518
Matus Fabian5ba86f72017-10-26 03:37:38 -07001519 def nat44_del_session(
1520 self,
1521 addr,
1522 port,
1523 protocol,
1524 vrf_id=0,
1525 is_in=1):
1526 """Delete NAT44 session
1527
1528 :param addr: IPv4 address
1529 :param por: port number
1530 :param protocol: IP protocol number
1531 :param vrf_id: VRF ID
1532 :param is_in: 1 if inside network addres and port pari, 0 if outside
1533 """
1534 return self.api(
1535 self.papi.nat44_del_session,
1536 {'address': addr,
1537 'port': port,
1538 'protocol': protocol,
1539 'vrf_id': vrf_id,
1540 'is_in': is_in})
1541
Juraj Sloboda7b929792017-11-23 13:20:48 +01001542 def nat44_forwarding_enable_disable(
1543 self,
1544 enable):
1545 """Enable/disable forwarding for NAT44
1546
1547 :param enable: 1 for enable, 0 for disable
1548 """
1549 return self.api(
1550 self.papi.nat44_forwarding_enable_disable,
1551 {'enable': enable})
1552
Matus Fabianefcd1e92017-08-15 06:59:19 -07001553 def nat_set_reass(
1554 self,
1555 timeout=2,
1556 max_reass=1024,
1557 max_frag=5,
1558 drop_frag=0,
1559 is_ip6=0):
1560 """Set NAT virtual fragmentation reassembly
1561
1562 :param timeout: reassembly timeout (Default 2sec)
1563 :param max_reass: maximum concurrent reassemblies (Default 1024)
1564 :param max_frag: maximum fragmets per reassembly (Default 5)
1565 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1566 :param is_ip6: 1 if IPv6, 0 if IPv4
1567 """
1568 return self.api(
1569 self.papi.nat_set_reass,
1570 {'timeout': timeout,
1571 'max_reass': max_reass,
1572 'max_frag': max_frag,
1573 'drop_frag': drop_frag,
1574 'is_ip6': is_ip6})
1575
1576 def nat_get_reass(self):
1577 """Get NAT virtual fragmentation reassembly configuration
1578
1579 :return: NAT virtual fragmentation reassembly configuration
1580 """
1581 return self.api(self.papi.nat_get_reass, {})
1582
1583 def nat_reass_dump(self):
1584 """Dump NAT virtual fragmentation reassemblies
1585
1586 :return: Dictionary of NAT virtual fragmentation reassemblies
1587 """
1588 return self.api(self.papi.nat_reass_dump, {})
1589
Matus Fabian2ba92e32017-08-21 07:05:03 -07001590 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001591 self,
1592 in_addr,
1593 in_plen,
1594 out_addr,
1595 out_plen,
1596 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001597 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001598
1599 :param is_add - 1 if add, 0 if delete
1600 :param in_addr - inside IP address
1601 :param in_plen - inside IP address prefix length
1602 :param out_addr - outside IP address
1603 :param out_plen - outside IP address prefix length
1604 """
1605 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001606 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001607 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001608 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001609 'in_addr': in_addr,
1610 'in_plen': in_plen,
1611 'out_addr': out_addr,
1612 'out_plen': out_plen})
1613
Matus Fabian2ba92e32017-08-21 07:05:03 -07001614 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001615 self,
1616 in_addr):
1617 """Get outside address and port range from inside address
1618
1619 :param in_addr - inside IP address
1620 """
1621 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001622 self.papi.nat_det_forward,
1623 {'in_addr': in_addr,
1624 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001625
Matus Fabian2ba92e32017-08-21 07:05:03 -07001626 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001627 self,
1628 out_addr,
1629 out_port):
1630 """Get inside address from outside address and port
1631
1632 :param out_addr - outside IP address
1633 :param out_port - outside port
1634 """
1635 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001636 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001637 {'out_addr': out_addr,
1638 'out_port': out_port})
1639
Matus Fabian2ba92e32017-08-21 07:05:03 -07001640 def nat_det_map_dump(self):
1641 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001642
Matus Fabian2ba92e32017-08-21 07:05:03 -07001643 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001644 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001645 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001646
Matus Fabian2ba92e32017-08-21 07:05:03 -07001647 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001648 self,
1649 udp=300,
1650 tcp_established=7440,
1651 tcp_transitory=240,
1652 icmp=60):
1653 """Set values of timeouts for deterministic NAT (in seconds)
1654
1655 :param udp - UDP timeout (Default value = 300)
1656 :param tcp_established - TCP established timeout (Default value = 7440)
1657 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1658 :param icmp - ICMP timeout (Default value = 60)
1659 """
1660 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001661 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001662 {'udp': udp,
1663 'tcp_established': tcp_established,
1664 'tcp_transitory': tcp_transitory,
1665 'icmp': icmp})
1666
Matus Fabian2ba92e32017-08-21 07:05:03 -07001667 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001668 """Get values of timeouts for deterministic NAT
1669
1670 :return: Timeouts for deterministic NAT (in seconds)
1671 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001672 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001673
Matus Fabian2ba92e32017-08-21 07:05:03 -07001674 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001675 self,
1676 out_addr,
1677 out_port,
1678 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001679 ext_port):
1680 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001681
1682 :param out_addr - outside IP address
1683 :param out_port - outside port
1684 :param ext_addr - external host IP address
1685 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001686 """
1687 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001688 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001689 {'out_addr': out_addr,
1690 'out_port': out_port,
1691 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001692 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001693
Matus Fabian2ba92e32017-08-21 07:05:03 -07001694 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001695 self,
1696 in_addr,
1697 in_port,
1698 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001699 ext_port):
1700 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001701
1702 :param in_addr - inside IP address
1703 :param in_port - inside port
1704 :param ext_addr - external host IP address
1705 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001706 """
1707 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001708 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001709 {'in_addr': in_addr,
1710 'in_port': in_port,
1711 'ext_addr': ext_addr,
1712 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001713 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001714
Matus Fabian2ba92e32017-08-21 07:05:03 -07001715 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001716 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001717 user_addr):
1718 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001719
1720 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001721 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001722 """
1723 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001724 self.papi.nat_det_session_dump,
1725 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001726 'user_addr': user_addr})
1727
Matus Fabian06596c52017-06-06 04:53:28 -07001728 def nat64_add_del_pool_addr_range(
1729 self,
1730 start_addr,
1731 end_addr,
1732 vrf_id=0xFFFFFFFF,
1733 is_add=1):
1734 """Add/del address range to NAT64 pool
1735
1736 :param start_addr: First IP address
1737 :param end_addr: Last IP address
1738 :param vrf_id: VRF id for the address range
1739 :param is_add: 1 if add, 0 if delete (Default value = 1)
1740 """
1741 return self.api(
1742 self.papi.nat64_add_del_pool_addr_range,
1743 {'start_addr': start_addr,
1744 'end_addr': end_addr,
1745 'vrf_id': vrf_id,
1746 'is_add': is_add})
1747
1748 def nat64_pool_addr_dump(self):
1749 """Dump NAT64 pool addresses
1750 :return: Dictionary of NAT64 pool addresses
1751 """
1752 return self.api(self.papi.nat64_pool_addr_dump, {})
1753
1754 def nat64_add_del_interface(
1755 self,
1756 sw_if_index,
1757 is_inside=1,
1758 is_add=1):
1759 """Enable/disable NAT64 feature on the interface
1760 :param sw_if_index: Index of the interface
1761 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1762 :param is_add: 1 if add, 0 if delete (Default value = 1)
1763 """
1764 return self.api(
1765 self.papi.nat64_add_del_interface,
1766 {'sw_if_index': sw_if_index,
1767 'is_inside': is_inside,
1768 'is_add': is_add})
1769
1770 def nat64_interface_dump(self):
1771 """Dump interfaces with NAT64 feature
1772 :return: Dictionary of interfaces with NAT64 feature
1773 """
1774 return self.api(self.papi.nat64_interface_dump, {})
1775
1776 def nat64_add_del_static_bib(
1777 self,
1778 in_ip,
1779 out_ip,
1780 in_port,
1781 out_port,
1782 protocol,
1783 vrf_id=0,
1784 is_add=1):
1785 """Add/delete S-NAT static BIB entry
1786
1787 :param in_ip: Inside IPv6 address
1788 :param out_ip: Outside IPv4 address
1789 :param in_port: Inside port number
1790 :param out_port: Outside port number
1791 :param protocol: IP protocol
1792 :param vrf_id: VRF ID (Default value = 0)
1793 :param is_add: 1 if add, 0 if delete (Default value = 1)
1794 """
1795 return self.api(
1796 self.papi.nat64_add_del_static_bib,
1797 {'i_addr': in_ip,
1798 'o_addr': out_ip,
1799 'i_port': in_port,
1800 'o_port': out_port,
1801 'vrf_id': vrf_id,
1802 'proto': protocol,
1803 'is_add': is_add})
1804
Matus Fabianab9a59c2017-08-16 05:37:36 -07001805 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001806 """Dump NAT64 BIB
1807
Matus Fabianab9a59c2017-08-16 05:37:36 -07001808 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001809 :returns: Dictionary of NAT64 BIB entries
1810 """
1811 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1812
1813 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1814 tcp_incoming_syn=6):
1815 """Set values of timeouts for NAT64 (in seconds)
1816
Matus Fabian428dc912017-06-21 06:15:18 -07001817 :param udpi: UDP timeout (Default value = 300)
1818 :param icmp: ICMP timeout (Default value = 60)
1819 :param tcp_trans: TCP transitory timeout (Default value = 240)
1820 :param tcp_est: TCP established timeout (Default value = 7440)
1821 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001822 """
1823 return self.api(
1824 self.papi.nat64_set_timeouts,
1825 {'udp': udp,
1826 'icmp': icmp,
1827 'tcp_trans': tcp_trans,
1828 'tcp_est': tcp_est,
1829 'tcp_incoming_syn': tcp_incoming_syn})
1830
1831 def nat64_get_timeouts(self):
1832 """Get values of timeouts for NAT64
1833
1834 :return: Timeouts for NAT64 (in seconds)
1835 """
1836 return self.api(self.papi.nat64_get_timeouts, {})
1837
Matus Fabianab9a59c2017-08-16 05:37:36 -07001838 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001839 """Dump NAT64 session table
1840
Matus Fabianab9a59c2017-08-16 05:37:36 -07001841 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001842 :returns: Dictionary of NAT64 sesstion table entries
1843 """
1844 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1845
Matus Fabian428dc912017-06-21 06:15:18 -07001846 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1847 """Add/del NAT64 prefix
1848
1849 :param prefix: NAT64 prefix
1850 :param plen: NAT64 prefix length
1851 :param vrf_id: VRF id of tenant (Default 0)
1852 :param is_add: 1 if add, 0 if delete (Default value = 1)
1853 """
1854 return self.api(
1855 self.papi.nat64_add_del_prefix,
1856 {'prefix': prefix,
1857 'prefix_len': plen,
1858 'vrf_id': vrf_id,
1859 'is_add': is_add})
1860
1861 def nat64_prefix_dump(self):
1862 """Dump NAT64 prefix
1863
1864 :returns: Dictionary of NAT64 prefixes
1865 """
1866 return self.api(self.papi.nat64_prefix_dump, {})
1867
Matus Fabian0938dcf2017-11-08 01:59:38 -08001868 def nat64_add_interface_addr(
1869 self,
1870 sw_if_index,
1871 is_add=1):
1872 """Add/del NAT64 address from interface
1873
1874 :param sw_if_index: Software index of the interface
1875 :param is_add: 1 if add, 0 if delete (Default value = 1)
1876 """
1877 return self.api(self.papi.nat64_add_del_interface_addr,
1878 {'is_add': is_add, 'sw_if_index': sw_if_index})
1879
Matus Fabian8ebe6252017-11-06 05:04:53 -08001880 def dslite_set_aftr_addr(self, ip6, ip4):
1881 """Set DS-Lite AFTR addresses
1882
1883 :param ip4: IPv4 address
1884 :param ip6: IPv6 address
1885 """
1886 return self.api(
1887 self.papi.dslite_set_aftr_addr,
1888 {'ip4_addr': ip4,
1889 'ip6_addr': ip6})
1890
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001891 def dslite_set_b4_addr(self, ip6, ip4):
1892 """Set DS-Lite B4 IPv6 address
1893
1894 :param ip4: IPv4 address
1895 :param ip6: IPv6 address
1896 """
1897 return self.api(
1898 self.papi.dslite_set_b4_addr,
1899 {'ip4_addr': ip4,
1900 'ip6_addr': ip6})
1901
Matus Fabian8ebe6252017-11-06 05:04:53 -08001902 def dslite_add_del_pool_addr_range(
1903 self,
1904 start_addr,
1905 end_addr,
1906 is_add=1):
1907 """Add/del address range to DS-Lite pool
1908
1909 :param start_addr: First IP address
1910 :param end_addr: Last IP address
1911 :param is_add: 1 if add, 0 if delete (Default value = 1)
1912 """
1913 return self.api(
1914 self.papi.dslite_add_del_pool_addr_range,
1915 {'start_addr': start_addr,
1916 'end_addr': end_addr,
1917 'is_add': is_add})
1918
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001919 def nat66_add_del_interface(
1920 self,
1921 sw_if_index,
1922 is_inside=1,
1923 is_add=1):
1924 """Enable/disable NAT66 feature on the interface
1925 :param sw_if_index: Index of the interface
1926 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1927 :param is_add: 1 if add, 0 if delete (Default value = 1)
1928 """
1929 return self.api(
1930 self.papi.nat66_add_del_interface,
1931 {'sw_if_index': sw_if_index,
1932 'is_inside': is_inside,
1933 'is_add': is_add})
1934
1935 def nat66_add_del_static_mapping(
1936 self,
1937 in_ip,
1938 out_ip,
1939 vrf_id=0,
1940 is_add=1):
1941 """Add/delete NAT66 static mapping
1942
1943 :param in_ip: Inside IPv6 address
1944 :param out_ip: Outside IPv6 address
1945 :param vrf_id: VRF ID (Default value = 0)
1946 :param is_add: 1 if add, 0 if delete (Default value = 1)
1947 """
1948 return self.api(
1949 self.papi.nat66_add_del_static_mapping,
1950 {'local_ip_address': in_ip,
1951 'external_ip_address': out_ip,
1952 'vrf_id': vrf_id,
1953 'is_add': is_add})
1954
1955 def nat66_interface_dump(self):
1956 """Dump interfaces with NAT66 feature
1957 :return: Dictionary of interfaces with NAT66 feature
1958 """
1959 return self.api(self.papi.nat66_interface_dump, {})
1960
1961 def nat66_static_mapping_dump(self):
1962 """Dump NAT66 static mappings
1963 :return: Dictionary of NAT66 static mappings
1964 """
1965 return self.api(self.papi.nat66_static_mapping_dump, {})
1966
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001967 def control_ping(self):
1968 self.api(self.papi.control_ping)
1969
1970 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001971 detect_mult, local_addr, peer_addr, is_ipv6=0,
1972 bfd_key_id=None, conf_key_id=None):
1973 if bfd_key_id is None:
1974 return self.api(self.papi.bfd_udp_add,
1975 {
1976 'sw_if_index': sw_if_index,
1977 'desired_min_tx': desired_min_tx,
1978 'required_min_rx': required_min_rx,
1979 'local_addr': local_addr,
1980 'peer_addr': peer_addr,
1981 'is_ipv6': is_ipv6,
1982 'detect_mult': detect_mult,
1983 })
1984 else:
1985 return self.api(self.papi.bfd_udp_add,
1986 {
1987 'sw_if_index': sw_if_index,
1988 'desired_min_tx': desired_min_tx,
1989 'required_min_rx': required_min_rx,
1990 'local_addr': local_addr,
1991 'peer_addr': peer_addr,
1992 'is_ipv6': is_ipv6,
1993 'detect_mult': detect_mult,
1994 'is_authenticated': 1,
1995 'bfd_key_id': bfd_key_id,
1996 'conf_key_id': conf_key_id,
1997 })
1998
Klement Sekeraa57a9702017-02-02 06:58:07 +01001999 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2000 detect_mult, local_addr, peer_addr, is_ipv6=0):
2001 return self.api(self.papi.bfd_udp_mod,
2002 {
2003 'sw_if_index': sw_if_index,
2004 'desired_min_tx': desired_min_tx,
2005 'required_min_rx': required_min_rx,
2006 'local_addr': local_addr,
2007 'peer_addr': peer_addr,
2008 'is_ipv6': is_ipv6,
2009 'detect_mult': detect_mult,
2010 })
2011
Klement Sekerab17dd962017-01-09 07:43:48 +01002012 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2013 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2014 is_delayed=False):
2015 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002016 {
2017 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002018 'local_addr': local_addr,
2019 'peer_addr': peer_addr,
2020 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002021 'is_delayed': 1 if is_delayed else 0,
2022 'bfd_key_id': bfd_key_id,
2023 'conf_key_id': conf_key_id,
2024 })
2025
2026 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2027 is_ipv6=0, is_delayed=False):
2028 return self.api(self.papi.bfd_udp_auth_deactivate,
2029 {
2030 'sw_if_index': sw_if_index,
2031 'local_addr': local_addr,
2032 'peer_addr': peer_addr,
2033 'is_ipv6': is_ipv6,
2034 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002035 })
2036
2037 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2038 return self.api(self.papi.bfd_udp_del,
2039 {
2040 'sw_if_index': sw_if_index,
2041 'local_addr': local_addr,
2042 'peer_addr': peer_addr,
2043 'is_ipv6': is_ipv6,
2044 })
2045
2046 def bfd_udp_session_dump(self):
2047 return self.api(self.papi.bfd_udp_session_dump, {})
2048
Klement Sekerab17dd962017-01-09 07:43:48 +01002049 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2050 peer_addr, is_ipv6=0):
2051 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002052 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002053 'sw_if_index': sw_if_index,
2054 'local_addr': local_addr,
2055 'peer_addr': peer_addr,
2056 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002057 })
2058
2059 def want_bfd_events(self, enable_disable=1):
2060 return self.api(self.papi.want_bfd_events, {
2061 'enable_disable': enable_disable,
2062 'pid': os.getpid(),
2063 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002064
Klement Sekerab17dd962017-01-09 07:43:48 +01002065 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2066 return self.api(self.papi.bfd_auth_set_key, {
2067 'conf_key_id': conf_key_id,
2068 'auth_type': auth_type,
2069 'key': key,
2070 'key_len': len(key),
2071 })
2072
2073 def bfd_auth_del_key(self, conf_key_id):
2074 return self.api(self.papi.bfd_auth_del_key, {
2075 'conf_key_id': conf_key_id,
2076 })
2077
2078 def bfd_auth_keys_dump(self):
2079 return self.api(self.papi.bfd_auth_keys_dump, {})
2080
Klement Sekera239790f2017-02-16 10:53:53 +01002081 def bfd_udp_set_echo_source(self, sw_if_index):
2082 return self.api(self.papi.bfd_udp_set_echo_source,
2083 {'sw_if_index': sw_if_index})
2084
Klement Sekera73884482017-02-23 09:26:30 +01002085 def bfd_udp_del_echo_source(self):
2086 return self.api(self.papi.bfd_udp_del_echo_source, {})
2087
Steve Shin7957d6e2016-12-19 09:24:50 -08002088 def classify_add_del_table(
2089 self,
2090 is_add,
2091 mask,
2092 match_n_vectors=1,
2093 table_index=0xFFFFFFFF,
2094 nbuckets=2,
2095 memory_size=2097152,
2096 skip_n_vectors=0,
2097 next_table_index=0xFFFFFFFF,
2098 miss_next_index=0xFFFFFFFF,
2099 current_data_flag=0,
2100 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002101 """
2102 :param is_add:
2103 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002104 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002105 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002106 :param nbuckets: (Default value = 2)
2107 :param memory_size: (Default value = 2097152)
2108 :param skip_n_vectors: (Default value = 0)
2109 :param next_table_index: (Default value = 0xFFFFFFFF)
2110 :param miss_next_index: (Default value = 0xFFFFFFFF)
2111 :param current_data_flag: (Default value = 0)
2112 :param current_data_offset: (Default value = 0)
2113 """
2114
2115 return self.api(
2116 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002117 {'is_add': is_add,
2118 'table_index': table_index,
2119 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002120 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002121 'skip_n_vectors': skip_n_vectors,
2122 'match_n_vectors': match_n_vectors,
2123 'next_table_index': next_table_index,
2124 'miss_next_index': miss_next_index,
2125 'current_data_flag': current_data_flag,
2126 'current_data_offset': current_data_offset,
2127 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002128
2129 def classify_add_del_session(
2130 self,
2131 is_add,
2132 table_index,
2133 match,
2134 opaque_index=0xFFFFFFFF,
2135 hit_next_index=0xFFFFFFFF,
2136 advance=0,
2137 action=0,
2138 metadata=0):
2139 """
2140 :param is_add:
2141 :param table_index:
2142 :param match:
2143 :param opaque_index: (Default value = 0xFFFFFFFF)
2144 :param hit_next_index: (Default value = 0xFFFFFFFF)
2145 :param advance: (Default value = 0)
2146 :param action: (Default value = 0)
2147 :param metadata: (Default value = 0)
2148 """
2149
2150 return self.api(
2151 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002152 {'is_add': is_add,
2153 'table_index': table_index,
2154 'hit_next_index': hit_next_index,
2155 'opaque_index': opaque_index,
2156 'advance': advance,
2157 'action': action,
2158 'metadata': metadata,
2159 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002160
2161 def input_acl_set_interface(
2162 self,
2163 is_add,
2164 sw_if_index,
2165 ip4_table_index=0xFFFFFFFF,
2166 ip6_table_index=0xFFFFFFFF,
2167 l2_table_index=0xFFFFFFFF):
2168 """
2169 :param is_add:
2170 :param sw_if_index:
2171 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2172 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2173 :param l2_table_index: (Default value = 0xFFFFFFFF)
2174 """
2175
2176 return self.api(
2177 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002178 {'sw_if_index': sw_if_index,
2179 'ip4_table_index': ip4_table_index,
2180 'ip6_table_index': ip6_table_index,
2181 'l2_table_index': l2_table_index,
2182 'is_add': is_add})
2183
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002184 def output_acl_set_interface(
2185 self,
2186 is_add,
2187 sw_if_index,
2188 ip4_table_index=0xFFFFFFFF,
2189 ip6_table_index=0xFFFFFFFF,
2190 l2_table_index=0xFFFFFFFF):
2191 """
2192 :param is_add:
2193 :param sw_if_index:
2194 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2195 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2196 :param l2_table_index: (Default value = 0xFFFFFFFF)
2197 """
2198
2199 return self.api(
2200 self.papi.output_acl_set_interface,
2201 {'sw_if_index': sw_if_index,
2202 'ip4_table_index': ip4_table_index,
2203 'ip6_table_index': ip6_table_index,
2204 'l2_table_index': l2_table_index,
2205 'is_add': is_add})
2206
Klement Sekera77fabdb2017-01-02 07:46:14 +01002207 def set_ipfix_exporter(
2208 self,
2209 collector_address,
2210 src_address,
2211 path_mtu,
2212 template_interval,
2213 vrf_id=0,
2214 collector_port=4739,
2215 udp_checksum=0):
2216 return self.api(
2217 self.papi.set_ipfix_exporter,
2218 {
2219 'collector_address': collector_address,
2220 'collector_port': collector_port,
2221 'src_address': src_address,
2222 'vrf_id': vrf_id,
2223 'path_mtu': path_mtu,
2224 'template_interval': template_interval,
2225 'udp_checksum': udp_checksum,
2226 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002227
2228 def dhcp_proxy_config(self,
2229 dhcp_server,
2230 dhcp_src_address,
2231 rx_table_id=0,
2232 server_table_id=0,
2233 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002234 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002235 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002236 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002237 {
2238 'rx_vrf_id': rx_table_id,
2239 'server_vrf_id': server_table_id,
2240 'is_ipv6': is_ipv6,
2241 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002242 'dhcp_server': dhcp_server,
2243 'dhcp_src_address': dhcp_src_address,
2244 })
2245
2246 def dhcp_proxy_set_vss(self,
2247 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002248 vss_type=255,
2249 vpn_ascii_id="",
2250 oui=0,
2251 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002252 is_add=1,
2253 is_ip6=0):
2254 return self.api(
2255 self.papi.dhcp_proxy_set_vss,
2256 {
2257 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002258 'vss_type': vss_type,
2259 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002260 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002261 'vpn_index': vpn_index,
2262 'is_add': is_add,
2263 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002264 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002265
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002266 def dhcp_client(self,
2267 sw_if_index,
2268 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002269 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002270 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002271 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002272 want_dhcp_events=0):
2273 return self.api(
2274 self.papi.dhcp_client_config,
2275 {
2276 'sw_if_index': sw_if_index,
2277 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002278 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002279 'is_add': is_add,
2280 'want_dhcp_event': want_dhcp_events,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002281 'set_broadcast_flag': set_broadcast_flag,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002282 'pid': os.getpid(),
2283 })
2284
Neale Ranns32e1c012016-11-22 17:07:28 +00002285 def ip_mroute_add_del(self,
2286 src_address,
2287 grp_address,
2288 grp_address_length,
2289 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002290 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002291 next_hop_sw_if_index,
2292 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002293 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002294 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002295 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002296 is_add=1,
2297 is_ipv6=0,
2298 is_local=0):
2299 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002300 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002301 """
2302 return self.api(
2303 self.papi.ip_mroute_add_del,
2304 {'next_hop_sw_if_index': next_hop_sw_if_index,
2305 'entry_flags': e_flags,
2306 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002307 'table_id': table_id,
2308 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002309 'is_add': is_add,
2310 'is_ipv6': is_ipv6,
2311 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002312 'bier_imp': bier_imp,
2313 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002314 'grp_address_length': grp_address_length,
2315 'grp_address': grp_address,
2316 'src_address': src_address})
2317
2318 def mfib_signal_dump(self):
2319 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002320
2321 def ip_mfib_dump(self):
2322 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002323
Neale Rannsd792d9c2017-10-21 10:53:20 -07002324 def ip6_mfib_dump(self):
2325 return self.api(self.papi.ip6_mfib_dump, {})
2326
Filip Tehlar770e89e2017-01-31 10:39:16 +01002327 def lisp_enable_disable(self, is_enabled):
2328 return self.api(
2329 self.papi.lisp_enable_disable,
2330 {
2331 'is_en': is_enabled,
2332 })
2333
2334 def lisp_locator_set(self,
2335 ls_name,
2336 is_add=1):
2337 return self.api(
2338 self.papi.lisp_add_del_locator_set,
2339 {
2340 'is_add': is_add,
2341 'locator_set_name': ls_name
2342 })
2343
2344 def lisp_locator_set_dump(self):
2345 return self.api(self.papi.lisp_locator_set_dump, {})
2346
2347 def lisp_locator(self,
2348 ls_name,
2349 sw_if_index,
2350 priority=1,
2351 weight=1,
2352 is_add=1):
2353 return self.api(
2354 self.papi.lisp_add_del_locator,
2355 {
2356 'is_add': is_add,
2357 'locator_set_name': ls_name,
2358 'sw_if_index': sw_if_index,
2359 'priority': priority,
2360 'weight': weight
2361 })
2362
2363 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2364 return self.api(
2365 self.papi.lisp_locator_dump,
2366 {
2367 'is_index_set': is_index_set,
2368 'ls_name': ls_name,
2369 'ls_index': ls_index,
2370 })
2371
2372 def lisp_local_mapping(self,
2373 ls_name,
2374 eid_type,
2375 eid,
2376 prefix_len,
2377 vni=0,
2378 key_id=0,
2379 key="",
2380 is_add=1):
2381 return self.api(
2382 self.papi.lisp_add_del_local_eid,
2383 {
2384 'locator_set_name': ls_name,
2385 'is_add': is_add,
2386 'eid_type': eid_type,
2387 'eid': eid,
2388 'prefix_len': prefix_len,
2389 'vni': vni,
2390 'key_id': key_id,
2391 'key': key
2392 })
2393
2394 def lisp_eid_table_dump(self,
2395 eid_set=0,
2396 prefix_length=0,
2397 vni=0,
2398 eid_type=0,
2399 eid=None,
2400 filter_opt=0):
2401 return self.api(
2402 self.papi.lisp_eid_table_dump,
2403 {
2404 'eid_set': eid_set,
2405 'prefix_length': prefix_length,
2406 'vni': vni,
2407 'eid_type': eid_type,
2408 'eid': eid,
2409 'filter': filter_opt,
2410 })
2411
2412 def lisp_remote_mapping(self,
2413 eid_type,
2414 eid,
2415 eid_prefix_len=0,
2416 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002417 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002418 rlocs_num=0,
2419 is_src_dst=0,
2420 is_add=1):
2421 return self.api(
2422 self.papi.lisp_add_del_remote_mapping,
2423 {
2424 'is_add': is_add,
2425 'eid_type': eid_type,
2426 'eid': eid,
2427 'eid_len': eid_prefix_len,
2428 'rloc_num': rlocs_num,
2429 'rlocs': rlocs,
2430 'vni': vni,
2431 'is_src_dst': is_src_dst,
2432 })
2433
2434 def lisp_adjacency(self,
2435 leid,
2436 reid,
2437 leid_len,
2438 reid_len,
2439 eid_type,
2440 is_add=1,
2441 vni=0):
2442 return self.api(
2443 self.papi.lisp_add_del_adjacency,
2444 {
2445 'is_add': is_add,
2446 'vni': vni,
2447 'eid_type': eid_type,
2448 'leid': leid,
2449 'reid': reid,
2450 'leid_len': leid_len,
2451 'reid_len': reid_len,
2452 })
2453
2454 def lisp_adjacencies_get(self, vni=0):
2455 return self.api(
2456 self.papi.lisp_adjacencies_get,
2457 {
2458 'vni': vni
2459 })
Neale Ranns80823802017-02-20 18:23:41 -08002460
2461 def map_add_domain(self,
2462 ip6_prefix,
2463 ip6_prefix_len,
2464 ip6_src,
2465 ip6_src_prefix_len,
2466 ip4_prefix,
2467 ip4_prefix_len,
2468 ea_bits_len=0,
2469 psid_offset=0,
2470 psid_length=0,
2471 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002472 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002473 mtu=1280):
2474 return self.api(
2475 self.papi.map_add_domain,
2476 {
2477 'ip6_prefix': ip6_prefix,
2478 'ip6_prefix_len': ip6_prefix_len,
2479 'ip4_prefix': ip4_prefix,
2480 'ip4_prefix_len': ip4_prefix_len,
2481 'ip6_src': ip6_src,
2482 'ip6_src_prefix_len': ip6_src_prefix_len,
2483 'ea_bits_len': ea_bits_len,
2484 'psid_offset': psid_offset,
2485 'psid_length': psid_length,
2486 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002487 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002488 'mtu': mtu
2489 })
Hongjun Nief486b12017-04-12 19:21:16 +08002490
2491 def gtpu_add_del_tunnel(
2492 self,
2493 src_addr,
2494 dst_addr,
2495 is_add=1,
2496 is_ipv6=0,
2497 mcast_sw_if_index=0xFFFFFFFF,
2498 encap_vrf_id=0,
2499 decap_next_index=0xFFFFFFFF,
2500 teid=0):
2501 """
2502
2503 :param is_add: (Default value = 1)
2504 :param is_ipv6: (Default value = 0)
2505 :param src_addr:
2506 :param dst_addr:
2507 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2508 :param encap_vrf_id: (Default value = 0)
2509 :param decap_next_index: (Default value = 0xFFFFFFFF)
2510 :param teid: (Default value = 0)
2511
2512 """
2513 return self.api(self.papi.gtpu_add_del_tunnel,
2514 {'is_add': is_add,
2515 'is_ipv6': is_ipv6,
2516 'src_address': src_addr,
2517 'dst_address': dst_addr,
2518 'mcast_sw_if_index': mcast_sw_if_index,
2519 'encap_vrf_id': encap_vrf_id,
2520 'decap_next_index': decap_next_index,
2521 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002522
2523 def vxlan_gpe_add_del_tunnel(
2524 self,
2525 src_addr,
2526 dst_addr,
2527 mcast_sw_if_index=0xFFFFFFFF,
2528 is_add=1,
2529 is_ipv6=0,
2530 encap_vrf_id=0,
2531 decap_vrf_id=0,
2532 protocol=3,
2533 vni=0):
2534 """
2535
2536 :param local:
2537 :param remote:
2538 :param is_add: (Default value = 1)
2539 :param is_ipv6: (Default value = 0)
2540 :param encap_vrf_id: (Default value = 0)
2541 :param decap_vrf_id: (Default value = 0)
2542 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2543 :param protocol: (Default value = 3)
2544 :param vni: (Default value = 0)
2545
2546 """
2547 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2548 {'is_add': is_add,
2549 'is_ipv6': is_ipv6,
2550 'local': src_addr,
2551 'remote': dst_addr,
2552 'mcast_sw_if_index': mcast_sw_if_index,
2553 'encap_vrf_id': encap_vrf_id,
2554 'decap_vrf_id': decap_vrf_id,
2555 'protocol': protocol,
2556 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002557
2558 def pppoe_add_del_session(
2559 self,
2560 client_ip,
2561 client_mac,
2562 session_id=0,
2563 is_add=1,
2564 is_ipv6=0,
2565 decap_vrf_id=0):
2566 """
2567
2568 :param is_add: (Default value = 1)
2569 :param is_ipv6: (Default value = 0)
2570 :param client_ip:
2571 :param session_id: (Default value = 0)
2572 :param client_mac:
2573 :param decap_vrf_id: (Default value = 0)
2574
2575 """
2576 return self.api(self.papi.pppoe_add_del_session,
2577 {'is_add': is_add,
2578 'is_ipv6': is_ipv6,
2579 'session_id': session_id,
2580 'client_ip': client_ip,
2581 'decap_vrf_id': decap_vrf_id,
2582 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002583
2584 def sr_localsid_add_del(self,
2585 localsid_addr,
2586 behavior,
2587 nh_addr,
2588 is_del=0,
2589 end_psp=0,
2590 sw_if_index=0xFFFFFFFF,
2591 vlan_index=0,
2592 fib_table=0,
2593 ):
2594 """ Add/del IPv6 SR local-SID.
2595
2596 :param localsid_addr:
2597 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2598 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2599 :param nh_addr:
2600 :param is_del: (Default value = 0)
2601 :param end_psp: (Default value = 0)
2602 :param sw_if_index: (Default value = 0xFFFFFFFF)
2603 :param vlan_index: (Default value = 0)
2604 :param fib_table: (Default value = 0)
2605 """
2606 return self.api(
2607 self.papi.sr_localsid_add_del,
2608 {'is_del': is_del,
2609 'localsid_addr': localsid_addr,
2610 'end_psp': end_psp,
2611 'behavior': behavior,
2612 'sw_if_index': sw_if_index,
2613 'vlan_index': vlan_index,
2614 'fib_table': fib_table,
2615 'nh_addr': nh_addr
2616 }
2617 )
2618
2619 def sr_policy_add(
2620 self,
2621 bsid_addr,
2622 weight=1,
2623 is_encap=1,
2624 type=0,
2625 fib_table=0,
2626 n_segments=0,
2627 segments=[]):
2628 """
2629 :param bsid_addr: bindingSID of the SR Policy
2630 :param weight: weight of the sid list. optional. (default: 1)
2631 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2632 (default: Encap)
2633 :param type: type/behavior of the SR policy. (default or spray) \
2634 (default: default)
2635 :param fib_table: VRF where to install the FIB entry for the BSID \
2636 (default: 0)
2637 :param n_segments: number of segments \
2638 (default: 0)
2639 :param segments: a vector of IPv6 address composing the segment list \
2640 (default: [])
2641 """
2642 return self.api(
2643 self.papi.sr_policy_add,
2644 {'bsid_addr': bsid_addr,
2645 'weight': weight,
2646 'is_encap': is_encap,
2647 'type': type,
2648 'fib_table': fib_table,
2649 'n_segments': n_segments,
2650 'segments': segments
2651 }
2652 )
2653
2654 def sr_policy_del(
2655 self,
2656 bsid_addr,
2657 sr_policy_index=0):
2658 """
2659 :param bsid: bindingSID of the SR Policy
2660 :param sr_policy_index: index of the sr policy (default: 0)
2661 """
2662 return self.api(
2663 self.papi.sr_policy_del,
2664 {'bsid_addr': bsid_addr,
2665 'sr_policy_index': sr_policy_index
2666 })
2667
2668 def sr_steering_add_del(
2669 self,
2670 is_del,
2671 bsid_addr,
2672 sr_policy_index,
2673 table_id,
2674 prefix_addr,
2675 mask_width,
2676 sw_if_index,
2677 traffic_type):
2678 """
2679 Steer traffic L2 and L3 traffic through a given SR policy
2680
2681 :param is_del: delete or add
2682 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2683 :param sr_policy: is the index of the SR Policy (alt to bsid)
2684 :param table_id: is the VRF where to install the FIB entry for the BSID
2685 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2686 :param mask_width: is the mask for L3 traffic type
2687 :param sw_if_index: is the incoming interface for L2 traffic
2688 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2689 """
2690 return self.api(
2691 self.papi.sr_steering_add_del,
2692 {'is_del': is_del,
2693 'bsid_addr': bsid_addr,
2694 'sr_policy_index': sr_policy_index,
2695 'table_id': table_id,
2696 'prefix_addr': prefix_addr,
2697 'mask_width': mask_width,
2698 'sw_if_index': sw_if_index,
2699 'traffic_type': traffic_type
2700 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002701
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002702 def acl_add_replace(self, acl_index, r, tag='',
2703 expected_retval=0):
2704 """Add/replace an ACL
2705 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2706 :param acl_rule r: ACL rules array.
2707 :param str tag: symbolic tag (description) for this ACL.
2708 :param int count: number of rules.
2709 """
2710 return self.api(self.papi.acl_add_replace,
2711 {'acl_index': acl_index,
2712 'r': r,
2713 'count': len(r),
2714 'tag': tag},
2715 expected_retval=expected_retval)
2716
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002717 def acl_del(self, acl_index, expected_retval=0):
2718 """
2719
2720 :param acl_index:
2721 :return:
2722 """
2723 return self.api(self.papi.acl_del,
2724 {'acl_index': acl_index},
2725 expected_retval=expected_retval)
2726
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002727 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2728 expected_retval=0):
2729 return self.api(self.papi.acl_interface_set_acl_list,
2730 {'sw_if_index': sw_if_index,
2731 'count': len(acls),
2732 'n_input': n_input,
2733 'acls': acls},
2734 expected_retval=expected_retval)
2735
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002736 def acl_interface_set_etype_whitelist(self, sw_if_index,
2737 n_input, whitelist,
2738 expected_retval=0):
2739 return self.api(self.papi.acl_interface_set_etype_whitelist,
2740 {'sw_if_index': sw_if_index,
2741 'count': len(whitelist),
2742 'n_input': n_input,
2743 'whitelist': whitelist},
2744 expected_retval=expected_retval)
2745
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002746 def acl_interface_add_del(self,
2747 sw_if_index,
2748 acl_index,
2749 is_add=1):
2750 """ Add/Delete ACL to/from interface
2751
2752 :param sw_if_index:
2753 :param acl_index:
2754 :param is_add: (Default value = 1)
2755 """
2756
2757 return self.api(self.papi.acl_interface_add_del,
2758 {'is_add': is_add,
2759 'is_input': 1,
2760 'sw_if_index': sw_if_index,
2761 'acl_index': acl_index})
2762
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002763 def acl_dump(self, acl_index, expected_retval=0):
2764 return self.api(self.papi.acl_dump,
2765 {'acl_index': acl_index},
2766 expected_retval=expected_retval)
2767
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002768 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2769 expected_retval=0):
2770 return self.api(self.papi.acl_interface_list_dump,
2771 {'sw_if_index': sw_if_index},
2772 expected_retval=expected_retval)
2773
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002774 def macip_acl_add(self, rules, tag=""):
2775 """ Add MACIP acl
2776
2777 :param rules: list of rules for given acl
2778 :param tag: acl tag
2779 """
2780
2781 return self.api(self.papi.macip_acl_add,
2782 {'r': rules,
2783 'count': len(rules),
2784 'tag': tag})
2785
Pavel Kotucek932f7412017-09-07 14:44:52 +02002786 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2787 """ Add MACIP acl
2788
2789 :param rules: list of rules for given acl
2790 :param tag: acl tag
2791 """
2792
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002793 return self.api(self.papi.macip_acl_add_replace,
2794 {'acl_index': acl_index,
2795 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002796 'count': len(rules),
2797 'tag': tag})
2798
2799 def macip_acl_del(self, acl_index):
2800 """
2801
2802 :param acl_index:
2803 :return:
2804 """
2805 return self.api(self.papi.macip_acl_del,
2806 {'acl_index': acl_index})
2807
2808 def macip_acl_interface_add_del(self,
2809 sw_if_index,
2810 acl_index,
2811 is_add=1):
2812 """ Add MACIP acl to interface
2813
2814 :param sw_if_index:
2815 :param acl_index:
2816 :param is_add: (Default value = 1)
2817 """
2818
2819 return self.api(self.papi.macip_acl_interface_add_del,
2820 {'is_add': is_add,
2821 'sw_if_index': sw_if_index,
2822 'acl_index': acl_index})
2823
2824 def macip_acl_interface_get(self):
2825 """ Return interface acls dump
2826 """
2827 return self.api(
2828 self.papi.macip_acl_interface_get, {})
2829
2830 def macip_acl_dump(self, acl_index=4294967295):
2831 """ Return MACIP acl dump
2832 """
2833
2834 return self.api(
2835 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002836
2837 def policer_add_del(self,
2838 name,
2839 cir,
2840 eir,
2841 cb,
2842 eb,
2843 is_add=1,
2844 rate_type=0,
2845 round_type=0,
2846 ptype=0,
2847 color_aware=0,
2848 conform_action_type=1,
2849 conform_dscp=0,
2850 exceed_action_type=0,
2851 exceed_dscp=0,
2852 violate_action_type=0,
2853 violate_dscp=0):
2854 return self.api(self.papi.policer_add_del,
2855 {'name': name,
2856 'cir': cir,
2857 'eir': eir,
2858 'cb': cb,
2859 'eb': eb,
2860 'is_add': is_add,
2861 'rate_type': rate_type,
2862 'round_type': round_type,
2863 'type': ptype,
2864 'color_aware': color_aware,
2865 'conform_action_type': conform_action_type,
2866 'conform_dscp': conform_dscp,
2867 'exceed_action_type': exceed_action_type,
2868 'exceed_dscp': exceed_dscp,
2869 'violate_action_type': violate_action_type,
2870 'violate_dscp': violate_dscp})
2871
2872 def ip_punt_police(self,
2873 policer_index,
2874 is_ip6=0,
2875 is_add=1):
2876 return self.api(self.papi.ip_punt_police,
2877 {'policer_index': policer_index,
2878 'is_add': is_add,
2879 'is_ip6': is_ip6})
2880
2881 def ip_punt_redirect(self,
2882 rx_sw_if_index,
2883 tx_sw_if_index,
2884 nh,
2885 is_ip6=0,
2886 is_add=1):
2887 return self.api(self.papi.ip_punt_redirect,
2888 {'rx_sw_if_index': rx_sw_if_index,
2889 'tx_sw_if_index': tx_sw_if_index,
2890 'nh': nh,
2891 'is_add': is_add,
2892 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002893
2894 def bier_table_add_del(self,
2895 bti,
2896 mpls_label,
2897 is_add=1):
2898 """ BIER Table add/del """
2899 return self.api(
2900 self.papi.bier_table_add_del,
2901 {'bt_tbl_id': {"bt_set": bti.set_id,
2902 "bt_sub_domain": bti.sub_domain_id,
2903 "bt_hdr_len_id": bti.hdr_len_id},
2904 'bt_label': mpls_label,
2905 'bt_is_add': is_add})
2906
2907 def bier_table_dump(self):
2908 return self.api(self.papi.bier_table_dump, {})
2909
2910 def bier_route_add_del(self,
2911 bti,
2912 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002913 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002914 is_add=1):
2915 """ BIER Route add/del """
2916 return self.api(
2917 self.papi.bier_route_add_del,
2918 {'br_tbl_id': {"bt_set": bti.set_id,
2919 "bt_sub_domain": bti.sub_domain_id,
2920 "bt_hdr_len_id": bti.hdr_len_id},
2921 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002922 'br_n_paths': len(paths),
2923 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002924 'br_is_add': is_add})
2925
2926 def bier_route_dump(self, bti):
2927 return self.api(
2928 self.papi.bier_route_dump,
2929 {'br_tbl_id': {"bt_set": bti.set_id,
2930 "bt_sub_domain": bti.sub_domain_id,
2931 "bt_hdr_len_id": bti.hdr_len_id}})
2932
2933 def bier_imp_add(self,
2934 bti,
2935 src,
2936 ibytes,
2937 is_add=1):
2938 """ BIER Imposition Add """
2939 return self.api(
2940 self.papi.bier_imp_add,
2941 {'bi_tbl_id': {"bt_set": bti.set_id,
2942 "bt_sub_domain": bti.sub_domain_id,
2943 "bt_hdr_len_id": bti.hdr_len_id},
2944 'bi_src': src,
2945 'bi_n_bytes': len(ibytes),
2946 'bi_bytes': ibytes})
2947
2948 def bier_imp_del(self, bi_index):
2949 """ BIER Imposition del """
2950 return self.api(
2951 self.papi.bier_imp_del,
2952 {'bi_index': bi_index})
2953
2954 def bier_imp_dump(self):
2955 return self.api(self.papi.bier_imp_dump, {})
2956
2957 def bier_disp_table_add_del(self,
2958 bdti,
2959 is_add=1):
2960 """ BIER Disposition Table add/del """
2961 return self.api(
2962 self.papi.bier_disp_table_add_del,
2963 {'bdt_tbl_id': bdti,
2964 'bdt_is_add': is_add})
2965
2966 def bier_disp_table_dump(self):
2967 return self.api(self.papi.bier_disp_table_dump, {})
2968
2969 def bier_disp_entry_add_del(self,
2970 bdti,
2971 bp,
2972 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002973 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002974 next_hop,
2975 next_hop_tbl_id=0,
2976 next_hop_rpf_id=~0,
2977 next_hop_is_ip4=1,
2978 is_add=1):
2979 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002980 lstack = []
2981 while (len(lstack) < 16):
2982 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002983 return self.api(
2984 self.papi.bier_disp_entry_add_del,
2985 {'bde_tbl_id': bdti,
2986 'bde_bp': bp,
2987 'bde_payload_proto': payload_proto,
2988 'bde_n_paths': 1,
2989 'bde_paths': [{'next_hop': next_hop,
2990 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002991 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002992 'rpf_id': next_hop_rpf_id,
2993 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002994 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002995 'bde_is_add': is_add})
2996
2997 def bier_disp_entry_dump(self, bdti):
2998 return self.api(
2999 self.papi.bier_disp_entry_dump,
3000 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003001
3002 def add_node_next(self, node_name, next_name):
3003 """ Set the next node for a given node request
3004
3005 :param node_name:
3006 :param next_name:
3007 """
3008 return self.api(self.papi.add_node_next,
3009 {'node_name': node_name,
3010 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003011
3012 def session_enable_disable(self, is_enabled):
3013 return self.api(
3014 self.papi.session_enable_disable,
3015 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003016
3017 def ipsec_spd_add_del(self, spd_id, is_add=1):
3018 """ SPD add/del - Wrapper to add or del ipsec SPD
3019 Sample CLI : 'ipsec spd add 1'
3020
3021 :param spd_id - SPD ID to be created in the vpp . mandatory
3022 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3023 optional
3024 :returns: reply from the API
3025 """
3026 return self.api(
3027 self.papi.ipsec_spd_add_del, {
3028 'spd_id': spd_id, 'is_add': is_add})
3029
3030 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3031 """ IPSEC interface SPD add/del - \
3032 Wrapper to associate/disassociate SPD to interface in VPP
3033 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3034
3035 :param spd_id - SPD ID to associate with the interface . mandatory
3036 :param sw_if_index - Interface Index which needs to ipsec \
3037 association mandatory
3038 :param is_add - add(1) or del(0) association with interface \
3039 (Default 1 - add) . optional
3040 :returns: reply from the API
3041 """
3042 return self.api(
3043 self.papi.ipsec_interface_add_del_spd, {
3044 'spd_id': spd_id,
3045 'sw_if_index': sw_if_index, 'is_add': is_add})
3046
3047 def ipsec_sad_add_del_entry(self,
3048 sad_id,
3049 spi,
3050 tunnel_src_address='',
3051 tunnel_dst_address='',
3052 protocol=0,
3053 integrity_algorithm=2,
3054 integrity_key_length=0,
3055 integrity_key='C91KUR9GYMm5GfkEvNjX',
3056 crypto_algorithm=1,
3057 crypto_key_length=0,
3058 crypto_key='JPjyOWBeVEQiMe7h',
3059 is_add=1,
3060 is_tunnel=1):
3061 """ IPSEC SA add/del
3062 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
3063 crypto-key 4a506a794f574265564551694d653768 \
3064 crypto-alg aes-cbc-128 \
3065 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3066 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3067 tunnel-dst 192.168.100.2'
3068 Sample CLI : 'ipsec sa add 20 spi 2001 \
3069 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3070 integ-alg sha1-96'
3071
3072 :param sad_id - Security Association ID to be \
3073 created or deleted. mandatory
3074 :param spi - security param index of the SA in decimal. mandatory
3075 :param tunnel_src_address - incase of tunnel mode outer src address .\
3076 mandatory for tunnel mode
3077 :param tunnel_dst_address - incase of transport mode \
3078 outer dst address. mandatory for tunnel mode
3079 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3080 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3081 optional **
3082 :param integrity_key - value in string \
3083 (Default C91KUR9GYMm5GfkEvNjX).optional
3084 :param integrity_key_length - length of the key string in bytes\
3085 (Default 0 - integrity disabled). optional
3086 :param crypto_algorithm - value range 1-11 Default \
3087 (1- AES_CBC_128).optional **
3088 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3089 :param crypto_key_length - length of the key string in bytes\
3090 (Default 0 - crypto disabled). optional
3091 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3092 optional
3093 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3094 (Default 1 - tunnel). optional
3095 :returns: reply from the API
3096 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3097 crypto and ipsec algorithms
3098 """
3099 return self.api(
3100 self.papi.ipsec_sad_add_del_entry,
3101 {'sad_id': sad_id,
3102 'spi': spi,
3103 'tunnel_src_address': tunnel_src_address,
3104 'tunnel_dst_address': tunnel_dst_address,
3105 'protocol': protocol,
3106 'integrity_algorithm': integrity_algorithm,
3107 'integrity_key_length': integrity_key_length,
3108 'integrity_key': integrity_key,
3109 'crypto_algorithm': crypto_algorithm,
3110 'crypto_key_length': crypto_key_length,
3111 'crypto_key': crypto_key,
3112 'is_add': is_add,
3113 'is_tunnel': is_tunnel})
3114
3115 def ipsec_spd_add_del_entry(self,
3116 spd_id,
3117 local_address_start,
3118 local_address_stop,
3119 remote_address_start,
3120 remote_address_stop,
3121 local_port_start=0,
3122 local_port_stop=65535,
3123 remote_port_start=0,
3124 remote_port_stop=65535,
3125 protocol=0,
3126 sa_id=10,
3127 policy=0,
3128 priority=100,
3129 is_outbound=1,
3130 is_add=1,
3131 is_ip_any=0):
3132 """ IPSEC policy SPD add/del -
3133 Wrapper to configure ipsec SPD policy entries in VPP
3134 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3135 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3136 remote-ip-range 192.168.3.3 - 192.168.3.3'
3137
3138 :param spd_id - SPD ID for the policy . mandatory
3139 :param local_address_start - local-ip-range start address . mandatory
3140 :param local_address_stop - local-ip-range stop address . mandatory
3141 :param remote_address_start - remote-ip-range start address . mandatory
3142 :param remote_address_stop - remote-ip-range stop address . mandatory
3143 :param local_port_start - (Default 0) . optional
3144 :param local_port_stop - (Default 65535). optional
3145 :param remote_port_start - (Default 0). optional
3146 :param remote_port_stop - (Default 65535). optional
3147 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3148 optional
3149 :param sa_id - Security Association ID for mapping it to SPD
3150 (default 10). optional
3151 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3152 (Default 0 - bypass). optional
3153 :param priotity - value for the spd action (Default 100). optional
3154 :param is_outbound - flag for inbound(0) or outbound(1)
3155 (Default 1 - outbound). optional
3156 :param is_add flag - for addition(1) or deletion(0) of the spd
3157 (Default 1 - addtion). optional
3158 :returns: reply from the API
3159 """
3160 return self.api(
3161 self.papi.ipsec_spd_add_del_entry,
3162 {'spd_id': spd_id,
3163 'local_address_start': local_address_start,
3164 'local_address_stop': local_address_stop,
3165 'remote_address_start': remote_address_start,
3166 'remote_address_stop': remote_address_stop,
3167 'local_port_start': local_port_start,
3168 'local_port_stop': local_port_stop,
3169 'remote_port_start': remote_port_start,
3170 'remote_port_stop': remote_port_stop,
3171 'is_add': is_add,
3172 'protocol': protocol,
3173 'policy': policy,
3174 'priority': priority,
3175 'is_outbound': is_outbound,
3176 'sa_id': sa_id,
3177 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003178
3179 def app_namespace_add(self,
3180 namespace_id,
3181 ip4_fib_id=0,
3182 ip6_fib_id=0,
3183 sw_if_index=0xFFFFFFFF,
3184 secret=0):
3185 return self.api(
3186 self.papi.app_namespace_add_del,
3187 {'secret': secret,
3188 'sw_if_index': sw_if_index,
3189 'ip4_fib_id': ip4_fib_id,
3190 'ip6_fib_id': ip6_fib_id,
3191 'namespace_id': namespace_id,
3192 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003193
3194 def punt_socket_register(self, l4_port, pathname, header_version=1,
3195 is_ip4=1, l4_protocol=0x11):
3196 """ Punt to socket """
3197 return self.api(self.papi.punt_socket_register,
3198 {'is_ip4': is_ip4,
3199 'l4_protocol': l4_protocol,
3200 'l4_port': l4_port,
3201 'pathname': pathname,
3202 'header_version': header_version})
3203
3204 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3205 expire_walk_interval_ms, is_ip6=0):
3206 """ Set IP reassembly parameters """
3207 return self.api(self.papi.ip_reassembly_set,
3208 {'is_ip6': is_ip6,
3209 'timeout_ms': timeout_ms,
3210 'expire_walk_interval_ms': expire_walk_interval_ms,
3211 'max_reassemblies': max_reassemblies})
3212
3213 def ip_reassembly_get(self, is_ip6=0):
3214 """ Get IP reassembly parameters """
3215 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003216
Klement Sekera4c533132018-02-22 11:41:12 +01003217 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3218 enable_ip6=False):
3219 """ Enable/disable IP reassembly """
3220 return self.api(self.papi.ip_reassembly_enable_disable,
3221 {'sw_if_index': sw_if_index,
3222 'enable_ip4': 1 if enable_ip4 else 0,
3223 'enable_ip6': 1 if enable_ip6 else 0,
3224 })
3225
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003226 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3227 """ GBP endpoint Add/Del """
3228 return self.api(self.papi.gbp_endpoint_add_del,
3229 {'is_add': is_add,
3230 'endpoint': {
3231 'is_ip6': is_ip6,
3232 'sw_if_index': sw_if_index,
3233 'address': addr,
3234 'epg_id': epg}})
3235
3236 def gbp_endpoint_dump(self):
3237 """ GBP endpoint Dump """
3238 return self.api(self.papi.gbp_endpoint_dump, {})
3239
3240 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3241 """ GBP contract Add/Del """
3242 return self.api(self.papi.gbp_contract_add_del,
3243 {'is_add': is_add,
3244 'contract': {
3245 'acl_index': acl_index,
3246 'src_epg': src_epg,
3247 'dst_epg': dst_epg}})
3248
3249 def gbp_contract_dump(self):
3250 """ GBP contract Dump """
3251 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003252
Ole Troan298c6952018-03-08 12:30:43 +01003253 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3254 ip4_prefix, ip4_prefix_len, ip4_src,
3255 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003256 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003257 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003258 {'fib_index': fib_index,
3259 'ip6_prefix': ip6_prefix,
3260 'ip6_prefix_len': ip6_prefix_len,
3261 'ip4_prefix': ip4_prefix,
3262 'ip4_prefix_len': ip4_prefix_len,
3263 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003264 'security_check': security_check})
3265
Ole Troan298c6952018-03-08 12:30:43 +01003266 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003267 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003268 return self.api(self.papi.ipip_6rd_del_tunnel,
3269 {'sw_if_index': sw_if_index})
3270
3271 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
3272 instance=0xFFFFFFFF, fib_index=0):
3273 """ IPIP tunnel Add/Del """
3274 return self.api(self.papi.ipip_add_tunnel,
3275 {'is_ipv6': is_ipv6,
3276 'instance': instance,
3277 'src_address': src_address,
3278 'dst_address': dst_address,
3279 'fib_index': fib_index})
3280
3281 def ipip_del_tunnel(self, sw_if_index):
3282 """ IPIP tunnel Delete """
3283 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003284 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003285
3286 def qos_egress_map_update(self, id, outputs):
3287 """ QOS egress map update """
3288 return self.api(self.papi.qos_egress_map_update,
3289 {'map_id': id,
3290 'rows': outputs})
3291
3292 def qos_egress_map_delete(self, id):
3293 """ QOS egress map delete """
3294 return self.api(self.papi.qos_egress_map_delete,
3295 {'map_id': id})
3296
3297 def qos_mark_enable_disable(self, sw_if_index,
3298 output_source,
3299 map_id,
3300 enable):
3301 """ QOS Mark Enable/Disable """
3302 return self.api(self.papi.qos_mark_enable_disable,
3303 {'map_id': map_id,
3304 'sw_if_index': sw_if_index,
3305 'output_source': output_source,
3306 'enable': enable})
3307
3308 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3309 """ IP QoS recording Enble/Disable """
3310 return self.api(self.papi.qos_record_enable_disable,
3311 {'sw_if_index': sw_if_index,
3312 'input_source': input_source,
3313 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003314
3315 def igmp_listen(self, enable, sw_if_index, saddr, gaddr):
3316 """ Listen for new (S,G) on specified interface
3317
3318 :param enable: add/del
3319 :param sw_if_index: interface sw index
3320 :param saddr: source ip4 addr
3321 :param gaddr: group ip4 addr
3322 """
3323 return self.api(self.papi.igmp_listen,
3324 {'enable': enable,
3325 'sw_if_index': sw_if_index,
3326 'saddr': saddr,
3327 'gaddr': gaddr})
3328
3329 def igmp_dump(self, sw_if_index=None):
3330 """ Dump all (S,G) interface configurations """
3331 if sw_if_index is None:
3332 dump_all = 1
3333 sw_if_index = 0
3334 else:
3335 dump_all = 0
3336 return self.api(self.papi.igmp_dump, {'sw_if_index': sw_if_index,
3337 'dump_all': dump_all})
3338
3339 def igmp_clear_interface(self, sw_if_index):
3340 """ Remove all (S,G)s from specified interface
3341 doesn't send IGMP report!
3342 """
3343 return self.api(
3344 self.papi.igmp_clear_interface, {
3345 'sw_if_index': sw_if_index})
3346
3347 def want_igmp_events(self, enable=1):
3348 return self.api(self.papi.want_igmp_events, {'enable': enable,
3349 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003350
3351 def bond_create(
3352 self,
3353 mode,
3354 lb,
3355 use_custom_mac,
3356 mac_address=''):
3357 """
3358 :param mode: mode
3359 :param lb: load balance
3360 :param use_custom_mac: use custom mac
3361 :param mac_address: mac address
3362 """
3363 return self.api(
3364 self.papi.bond_create,
3365 {'mode': mode,
3366 'lb': lb,
3367 'use_custom_mac': use_custom_mac,
3368 'mac_address': mac_address
3369 })
3370
3371 def bond_delete(
3372 self,
3373 sw_if_index):
3374 """
3375 :param sw_if_index: interface the operation is applied to
3376 """
3377 return self.api(self.papi.bond_delete,
3378 {'sw_if_index': sw_if_index})
3379
3380 def bond_enslave(
3381 self,
3382 sw_if_index,
3383 bond_sw_if_index,
3384 is_passive,
3385 is_long_timeout):
3386 """
3387 :param sw_if_index: slave sw_if_index
3388 :param bond_sw_if_index: bond sw_if_index
3389 :param is_passive: is passive lacp speaker
3390 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3391 """
3392 return self.api(
3393 self.papi.bond_enslave,
3394 {'sw_if_index': sw_if_index,
3395 'bond_sw_if_index': bond_sw_if_index,
3396 'is_passive': is_passive,
3397 'is_long_timeout': is_long_timeout
3398 })
3399
3400 def bond_detach_slave(
3401 self,
3402 sw_if_index):
3403 """
3404 :param sw_if_index: slave interface the operation is applied to
3405 """
3406 return self.api(self.papi.bond_detach_slave,
3407 {'sw_if_index': sw_if_index})
3408
3409 def sw_interface_slave_dump(
3410 self,
3411 sw_if_index):
3412 """
3413 :param sw_if_index: bond sw_if_index
3414 """
3415 return self.api(self.papi.sw_interface_slave_dump,
3416 {'sw_if_index': sw_if_index})
3417
3418 def sw_interface_bond_dump(
3419 self):
3420 """
3421
3422 """
3423 return self.api(self.papi.sw_interface_bond_dump,
3424 {})