blob: 6804b4cfe4a6a8275c172fb6189ea29923b6d856 [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):
Chris Luked0421942018-04-10 15:19:54 -0400571 """Enable/disable required feature of the bridge domain with defined
572 ID.
Jan00dad122016-11-29 10:04:53 +0100573
574 :param int bd_id: Bridge domain ID.
575 :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
576 :param int feature_bitmap: Bitmap value of the feature to be set:
577 - learn (1 << 0),
578 - forward (1 << 1),
579 - flood (1 << 2),
580 - uu-flood (1 << 3) or
581 - arp-term (1 << 4).
582 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100583 return self.api(self.papi.bridge_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200584 {'bd_id': bd_id,
585 'is_set': is_set,
586 'feature_bitmap': feature_bitmap})
Jan00dad122016-11-29 10:04:53 +0100587
588 def bridge_domain_dump(self, bd_id=0):
589 """
590
591 :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
592 existing bridge domains returned)
593 :return: Dictionary of bridge domain(s) data.
594 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100595 return self.api(self.papi.bridge_domain_dump,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200596 {'bd_id': bd_id})
Jan00dad122016-11-29 10:04:53 +0100597
Klement Sekeraf62ae122016-10-11 11:47:09 +0200598 def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
599 enable):
600 """Create or delete unidirectional cross-connect from Tx interface to
601 Rx interface.
602
Jan4af521d2016-11-15 17:05:00 +0100603 :param int rx_sw_if_index: Software interface index of Rx interface.
604 :param int tx_sw_if_index: Software interface index of Tx interface.
605 :param int enable: Create cross-connect if equal to 1, delete
606 cross-connect if equal to 0.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200607
608 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100609 return self.api(self.papi.sw_interface_set_l2_xconnect,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200610 {'rx_sw_if_index': rx_sw_if_index,
611 'tx_sw_if_index': tx_sw_if_index,
612 'enable': enable})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200613
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200614 def sw_interface_set_l2_tag_rewrite(
615 self,
616 sw_if_index,
617 vtr_oper,
618 push=0,
619 tag1=0,
620 tag2=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000621 """L2 interface vlan tag rewrite configure request
622 :param client_index - opaque cookie to identify the sender
623 :param context - sender context, to match reply w/ request
624 :param sw_if_index - interface the operation is applied to
625 :param vtr_op - Choose from l2_vtr_op_t enum values
626 :param push_dot1q - first pushed flag dot1q id set, else dot1ad
627 :param tag1 - Needed for any push or translate vtr op
628 :param tag2 - Needed for any push 2 or translate x-2 vtr ops
629
630 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100631 return self.api(self.papi.l2_interface_vlan_tag_rewrite,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200632 {'sw_if_index': sw_if_index,
633 'vtr_op': vtr_oper,
634 'push_dot1q': push,
635 'tag1': tag1,
636 'tag2': tag2})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000637
Neale Ranns55d03782017-10-21 06:34:22 -0700638 def sw_interface_set_l2_emulation(
639 self,
640 sw_if_index,
641 enable=1):
642 """L2 Emulation
643 :param sw_if_index - interface the operation is applied to
644
645 """
646 return self.api(self.papi.l2_emulation,
647 {'sw_if_index': sw_if_index,
648 'enable': enable})
649
Neale Rannsa07bd702017-08-07 07:53:49 -0700650 def sw_interface_set_flags(self, sw_if_index, admin_up_down):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200651 """
652
653 :param admin_up_down:
654 :param sw_if_index:
Klement Sekeraf62ae122016-10-11 11:47:09 +0200655
656 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100657 return self.api(self.papi.sw_interface_set_flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200658 {'sw_if_index': sw_if_index,
Neale Rannsa07bd702017-08-07 07:53:49 -0700659 'admin_up_down': admin_up_down})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200660
Neale Rannsffd78d12018-02-09 06:05:16 -0800661 def sw_interface_set_mtu(self, sw_if_index, mtu):
662 """
663 :param sw_if_index:
664 :param mtu:
665
666 """
667 return self.api(self.papi.sw_interface_set_mtu,
668 {'sw_if_index': sw_if_index,
669 'mtu': mtu})
670
Neale Ranns25b04942018-04-04 09:34:50 -0700671 def sw_interface_set_promiscuous(self, sw_if_index, enable):
672 """
673 :param sw_if_index:
674 :param enable:
675
676 """
677 return self.api(self.papi.sw_interface_set_promiscuous,
678 {'sw_if_index': sw_if_index,
679 'enable': enable})
680
Neale Rannsc819fc62018-02-16 02:44:05 -0800681 def sw_interface_set_mac_address(self, sw_if_index, mac):
682 return self.api(self.papi.sw_interface_set_mac_address,
683 {'sw_if_index': sw_if_index,
684 'mac_address': mac})
685
Klement Sekeraf62ae122016-10-11 11:47:09 +0200686 def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
687 no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
688 default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
689 """Create subinterface
690 from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
691
692 :param sub_id: param inner_vlan:
693 :param sw_if_index:
694 :param outer_vlan:
695 :param inner_vlan:
696 :param no_tags: (Default value = 0)
697 :param one_tag: (Default value = 0)
698 :param two_tags: (Default value = 0)
699 :param dot1ad: (Default value = 0)
700 :param exact_match: (Default value = 0)
701 :param default_sub: (Default value = 0)
702 :param outer_vlan_id_any: (Default value = 0)
703 :param inner_vlan_id_any: (Default value = 0)
704
705 """
706 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100707 self.papi.create_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200708 {'sw_if_index': sw_if_index,
709 'sub_id': sub_id,
710 'no_tags': no_tags,
711 'one_tag': one_tag,
712 'two_tags': two_tags,
713 'dot1ad': dot1ad,
714 'exact_match': exact_match,
715 'default_sub': default_sub,
716 'outer_vlan_id_any': outer_vlan_id_any,
717 'inner_vlan_id_any': inner_vlan_id_any,
718 'outer_vlan_id': outer_vlan,
719 'inner_vlan_id': inner_vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200720
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200721 def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id):
722 """Create p2p ethernet subinterface
723
724 :param sw_if_index: main (parent) interface
725 :param remote_mac: client (remote) mac address
726
727 """
728 return self.api(
729 self.papi.p2p_ethernet_add,
730 {'parent_if_index': sw_if_index,
731 'remote_mac': remote_mac,
732 'subif_id': subif_id})
733
Neale Ranns177bbdc2016-11-15 09:46:51 +0000734 def delete_subif(self, sw_if_index):
735 """Delete subinterface
736
737 :param sw_if_index:
738 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100739 return self.api(self.papi.delete_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200740 {'sw_if_index': sw_if_index})
Neale Ranns177bbdc2016-11-15 09:46:51 +0000741
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200742 def delete_p2pethernet_subif(self, sw_if_index, remote_mac):
743 """Delete p2p ethernet subinterface
744
745 :param sw_if_index: main (parent) interface
746 :param remote_mac: client (remote) mac address
747
748 """
749 return self.api(
750 self.papi.p2p_ethernet_del,
751 {'parent_if_index': sw_if_index,
752 'remote_mac': remote_mac})
753
Klement Sekeraf62ae122016-10-11 11:47:09 +0200754 def create_vlan_subif(self, sw_if_index, vlan):
755 """
756
757 :param vlan:
758 :param sw_if_index:
759
760 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100761 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200762 {'sw_if_index': sw_if_index,
763 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200764
Matej Klotton0178d522016-11-04 11:11:44 +0100765 def create_loopback(self, mac=''):
766 """
767
768 :param mac: (Optional)
769 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100770 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200771 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100772
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100773 def delete_loopback(self, sw_if_index):
774 return self.api(self.papi.delete_loopback,
775 {'sw_if_index': sw_if_index, })
776
Neale Ranns15002542017-09-10 04:39:11 -0700777 def ip_table_add_del(self,
778 table_id,
779 is_add=1,
780 is_ipv6=0):
781 """
782
783 :param table_id
784 :param is_add: (Default value = 1)
785 :param is_ipv6: (Default value = 0)
786
787 """
788
789 return self.api(
790 self.papi.ip_table_add_del,
791 {'table_id': table_id,
792 'is_add': is_add,
793 'is_ipv6': is_ipv6})
794
Klement Sekeraf62ae122016-10-11 11:47:09 +0200795 def ip_add_del_route(
796 self,
797 dst_address,
798 dst_address_length,
799 next_hop_address,
800 next_hop_sw_if_index=0xFFFFFFFF,
801 table_id=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200802 next_hop_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000803 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200804 next_hop_n_out_labels=0,
805 next_hop_out_label_stack=[],
806 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Ranns810086d2017-11-05 16:26:46 -0800807 next_hop_id=0xFFFFFFFF,
Neale Rannsad422ed2016-11-02 14:20:04 +0000808 is_resolve_host=0,
809 is_resolve_attached=0,
810 classify_table_index=0xFFFFFFFF,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200811 is_add=1,
812 is_drop=0,
Juraj Sloboda86a2c572016-10-27 10:44:25 +0200813 is_unreach=0,
814 is_prohibit=0,
Klement Sekeraf62ae122016-10-11 11:47:09 +0200815 is_ipv6=0,
816 is_local=0,
817 is_classify=0,
818 is_multipath=0,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800819 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800820 is_udp_encap=0,
Marek Gradzki0164a062017-10-13 10:22:59 +0200821 is_source_lookup=0):
Klement Sekeraf62ae122016-10-11 11:47:09 +0200822 """
823
824 :param dst_address_length:
825 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
826 :param dst_address:
827 :param next_hop_address:
828 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
829 :param vrf_id: (Default value = 0)
830 :param lookup_in_vrf: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200831 :param classify_table_index: (Default value = 0xFFFFFFFF)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200832 :param is_add: (Default value = 1)
833 :param is_drop: (Default value = 0)
834 :param is_ipv6: (Default value = 0)
835 :param is_local: (Default value = 0)
836 :param is_classify: (Default value = 0)
837 :param is_multipath: (Default value = 0)
838 :param is_resolve_host: (Default value = 0)
839 :param is_resolve_attached: (Default value = 0)
Neale Rannsf068c3e2018-01-03 04:18:48 -0800840 :param is_dvr: (Default value = 0)
Neale Ranns054c03a2017-10-13 05:15:07 -0700841 :param is_source_lookup: (Default value = 0)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200842 :param next_hop_weight: (Default value = 1)
843
844 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000845
Klement Sekeraf62ae122016-10-11 11:47:09 +0200846 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100847 self.papi.ip_add_del_route,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200848 {'next_hop_sw_if_index': next_hop_sw_if_index,
849 'table_id': table_id,
850 'classify_table_index': classify_table_index,
851 'next_hop_table_id': next_hop_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200852 'is_add': is_add,
853 'is_drop': is_drop,
854 'is_unreach': is_unreach,
855 'is_prohibit': is_prohibit,
856 'is_ipv6': is_ipv6,
857 'is_local': is_local,
858 'is_classify': is_classify,
859 'is_multipath': is_multipath,
860 'is_resolve_host': is_resolve_host,
861 'is_resolve_attached': is_resolve_attached,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800862 'is_dvr': is_dvr,
Neale Ranns054c03a2017-10-13 05:15:07 -0700863 'is_source_lookup': is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800864 'is_udp_encap': is_udp_encap,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200865 'next_hop_weight': next_hop_weight,
866 'dst_address_length': dst_address_length,
867 'dst_address': dst_address,
Neale Ranns810086d2017-11-05 16:26:46 -0800868 'next_hop_id': next_hop_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200869 'next_hop_address': next_hop_address,
870 'next_hop_n_out_labels': next_hop_n_out_labels,
871 'next_hop_via_label': next_hop_via_label,
872 'next_hop_out_label_stack': next_hop_out_label_stack})
Matej Klotton0178d522016-11-04 11:11:44 +0100873
Matej Klotton16a14cd2016-12-07 15:09:13 +0100874 def ip_fib_dump(self):
875 return self.api(self.papi.ip_fib_dump, {})
876
Jan Gelety057bb8c2016-12-20 17:32:45 +0100877 def ip6_fib_dump(self):
878 return self.api(self.papi.ip6_fib_dump, {})
879
Matej Klotton0178d522016-11-04 11:11:44 +0100880 def ip_neighbor_add_del(self,
881 sw_if_index,
882 mac_address,
883 dst_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100884 is_add=1,
885 is_ipv6=0,
886 is_static=0,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800887 is_no_adj_fib=0,
Matej Klotton0178d522016-11-04 11:11:44 +0100888 ):
889 """ Add neighbor MAC to IPv4 or IPv6 address.
890
891 :param sw_if_index:
892 :param mac_address:
893 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100894 :param is_add: (Default value = 1)
895 :param is_ipv6: (Default value = 0)
896 :param is_static: (Default value = 0)
Neale Rannsb3b2de72017-03-08 05:17:22 -0800897 :param is_no_adj_fib: (Default value = 0)
Matej Klotton0178d522016-11-04 11:11:44 +0100898 """
899
900 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100901 self.papi.ip_neighbor_add_del,
Neale Rannsbaf2e902017-02-25 04:20:00 -0800902 {'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200903 'is_add': is_add,
904 'is_ipv6': is_ipv6,
905 'is_static': is_static,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800906 'is_no_adj_fib': is_no_adj_fib,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200907 'mac_address': mac_address,
908 'dst_address': dst_address
Ole Troan7e3a8752016-12-05 10:27:09 +0100909 }
Matej Klotton0178d522016-11-04 11:11:44 +0100910 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100911
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800912 def ip_neighbor_dump(self,
913 sw_if_index,
914 is_ipv6=0):
915 """ Return IP neighbor dump.
916
917 :param sw_if_index:
918 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
919 """
920
921 return self.api(
922 self.papi.ip_neighbor_dump,
923 {'is_ipv6': is_ipv6,
924 'sw_if_index': sw_if_index
925 }
926 )
927
928 def proxy_arp_add_del(self,
929 low_address,
930 hi_address,
931 vrf_id=0,
932 is_add=1):
933 """ Config Proxy Arp Range.
934
935 :param low_address: Start address in the rnage to Proxy for
936 :param hi_address: End address in the rnage to Proxy for
937 :param vrf_id: The VRF/table in which to proxy
938 """
939
940 return self.api(
941 self.papi.proxy_arp_add_del,
942 {'vrf_id': vrf_id,
943 'is_add': is_add,
944 'low_address': low_address,
945 'hi_address': hi_address,
946 }
947 )
948
949 def proxy_arp_intfc_enable_disable(self,
950 sw_if_index,
951 is_enable=1):
952 """ Enable/Disable an interface for proxy ARP requests
953
954 :param sw_if_index: Interface
955 :param enable_disable: Enable/Disable
956 """
957
958 return self.api(
959 self.papi.proxy_arp_intfc_enable_disable,
960 {'sw_if_index': sw_if_index,
961 'enable_disable': is_enable
962 }
963 )
964
Jane546d3b2016-12-08 13:10:03 +0100965 def reset_vrf(self,
966 vrf_id,
967 is_ipv6=0,
968 ):
969 """ Reset VRF (remove all routes etc.) request.
970
971 :param int vrf_id: ID of the FIB table / VRF to reset.
972 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
973 """
974
975 return self.api(
976 self.papi.reset_vrf,
977 {'vrf_id': vrf_id,
978 'is_ipv6': is_ipv6,
979 }
980 )
981
982 def reset_fib(self,
983 vrf_id,
984 is_ipv6=0,
985 ):
986 """ Reset VRF (remove all routes etc.) request.
987
988 :param int vrf_id: ID of the FIB table / VRF to reset.
989 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
990 """
991
992 return self.api(
993 self.papi.reset_fib,
994 {'vrf_id': vrf_id,
995 'is_ipv6': is_ipv6,
996 }
997 )
998
999 def ip_dump(self,
1000 is_ipv6=0,
1001 ):
1002 """ Return IP dump.
1003
1004 :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
1005 """
1006
1007 return self.api(
1008 self.papi.ip_dump,
1009 {'is_ipv6': is_ipv6,
1010 }
1011 )
1012
Klement Sekera7bb873a2016-11-18 07:38:42 +01001013 def sw_interface_span_enable_disable(
Eyal Bari001fd402017-07-16 09:34:53 +03001014 self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001015 """
1016
1017 :param sw_if_index_from:
1018 :param sw_if_index_to:
Matej Klottondeb69842016-12-09 15:05:46 +01001019 :param state:
Eyal Bari001fd402017-07-16 09:34:53 +03001020 :param is_l2:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001021 """
Ole Troan7e3a8752016-12-05 10:27:09 +01001022 return self.api(self.papi.sw_interface_span_enable_disable,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001023 {'sw_if_index_from': sw_if_index_from,
1024 'sw_if_index_to': sw_if_index_to,
Eyal Bari001fd402017-07-16 09:34:53 +03001025 'state': state,
1026 'is_l2': is_l2,
1027 })
Neale Ranns177bbdc2016-11-15 09:46:51 +00001028
1029 def gre_tunnel_add_del(self,
1030 src_address,
1031 dst_address,
1032 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -05001033 tunnel_type=0,
1034 instance=0xFFFFFFFF,
1035 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +00001036 is_add=1,
1037 is_ip6=0):
1038 """ Add a GRE tunnel
1039
1040 :param src_address:
1041 :param dst_address:
1042 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -05001043 :param tunnel_type: (Default value = 0)
1044 :param instance: (Default value = 0xFFFFFFFF)
1045 :param session_id: (Defalt value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001046 :param is_add: (Default value = 1)
1047 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +00001048 """
1049
1050 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001051 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001052 {'is_add': is_add,
1053 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -05001054 'tunnel_type': tunnel_type,
1055 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001056 'src_address': src_address,
1057 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -05001058 'outer_fib_id': outer_fib_id,
1059 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +00001060 )
Neale Rannsad422ed2016-11-02 14:20:04 +00001061
Neale Ranns810086d2017-11-05 16:26:46 -08001062 def udp_encap_add_del(self,
1063 id,
1064 src_ip,
1065 dst_ip,
1066 src_port,
1067 dst_port,
1068 table_id=0,
1069 is_add=1,
1070 is_ip6=0):
1071 """ Add a GRE tunnel
1072 :param id: user provided ID
1073 :param src_ip:
1074 :param dst_ip:
1075 :param src_port:
1076 :param dst_port:
1077 :param outer_fib_id: (Default value = 0)
1078 :param is_add: (Default value = 1)
1079 :param is_ipv6: (Default value = 0)
1080 """
1081
1082 return self.api(
1083 self.papi.udp_encap_add_del,
1084 {'id': id,
1085 'is_add': is_add,
1086 'is_ip6': is_ip6,
1087 'src_ip': src_ip,
1088 'dst_ip': dst_ip,
1089 'src_port': src_port,
1090 'dst_port': dst_port,
1091 'table_id': table_id}
1092 )
1093
1094 def udp_encap_dump(self):
1095 return self.api(self.papi.udp_encap_dump, {})
1096
Neale Ranns43b1f442018-03-20 01:47:35 -07001097 def want_udp_encap_stats(self, enable=1):
1098 return self.api(self.papi.want_udp_encap_stats,
1099 {'enable': enable,
1100 'pid': os.getpid()})
1101
Neale Ranns5a8123b2017-01-26 01:18:23 -08001102 def mpls_fib_dump(self):
1103 return self.api(self.papi.mpls_fib_dump, {})
1104
Neale Ranns15002542017-09-10 04:39:11 -07001105 def mpls_table_add_del(
1106 self,
1107 table_id,
1108 is_add=1):
1109 """
1110
1111 :param table_id
1112 :param is_add: (Default value = 1)
1113
1114 """
1115
1116 return self.api(
1117 self.papi.mpls_table_add_del,
1118 {'mt_table_id': table_id,
1119 'mt_is_add': is_add})
1120
Neale Rannsad422ed2016-11-02 14:20:04 +00001121 def mpls_route_add_del(
1122 self,
1123 label,
1124 eos,
Neale Rannsda78f952017-05-24 09:15:43 -07001125 next_hop_proto,
Neale Rannsad422ed2016-11-02 14:20:04 +00001126 next_hop_address,
1127 next_hop_sw_if_index=0xFFFFFFFF,
1128 table_id=0,
1129 next_hop_table_id=0,
1130 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001131 next_hop_n_out_labels=0,
1132 next_hop_out_label_stack=[],
1133 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001134 is_resolve_host=0,
1135 is_resolve_attached=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001136 is_interface_rx=0,
1137 is_rpf_id=0,
1138 is_multicast=0,
Neale Rannsad422ed2016-11-02 14:20:04 +00001139 is_add=1,
1140 is_drop=0,
1141 is_multipath=0,
1142 classify_table_index=0xFFFFFFFF,
Marek Gradzki0164a062017-10-13 10:22:59 +02001143 is_classify=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001144 """
1145
1146 :param dst_address_length:
1147 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1148 :param dst_address:
1149 :param next_hop_address:
1150 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1151 :param vrf_id: (Default value = 0)
1152 :param lookup_in_vrf: (Default value = 0)
1153 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001154 :param is_add: (Default value = 1)
1155 :param is_drop: (Default value = 0)
1156 :param is_ipv6: (Default value = 0)
1157 :param is_local: (Default value = 0)
1158 :param is_classify: (Default value = 0)
1159 :param is_multipath: (Default value = 0)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001160 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001161 :param is_resolve_host: (Default value = 0)
1162 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001163 :param next_hop_weight: (Default value = 1)
1164
1165 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001166 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001167 self.papi.mpls_route_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001168 {'mr_label': label,
1169 'mr_eos': eos,
1170 'mr_table_id': table_id,
1171 'mr_classify_table_index': classify_table_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001172 'mr_is_add': is_add,
1173 'mr_is_classify': is_classify,
1174 'mr_is_multipath': is_multipath,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001175 'mr_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001176 'mr_is_resolve_host': is_resolve_host,
1177 'mr_is_resolve_attached': is_resolve_attached,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001178 'mr_is_interface_rx': is_interface_rx,
1179 'mr_is_rpf_id': is_rpf_id,
Neale Rannsda78f952017-05-24 09:15:43 -07001180 'mr_next_hop_proto': next_hop_proto,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001181 'mr_next_hop_weight': next_hop_weight,
1182 'mr_next_hop': next_hop_address,
1183 'mr_next_hop_n_out_labels': next_hop_n_out_labels,
1184 'mr_next_hop_sw_if_index': next_hop_sw_if_index,
1185 'mr_next_hop_table_id': next_hop_table_id,
1186 'mr_next_hop_via_label': next_hop_via_label,
1187 'mr_next_hop_out_label_stack': next_hop_out_label_stack})
Neale Rannsad422ed2016-11-02 14:20:04 +00001188
1189 def mpls_ip_bind_unbind(
1190 self,
1191 label,
1192 dst_address,
1193 dst_address_length,
1194 table_id=0,
1195 ip_table_id=0,
1196 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +00001197 is_bind=1):
1198 """
1199 """
1200 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001201 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001202 {'mb_mpls_table_id': table_id,
1203 'mb_label': label,
1204 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001205 'mb_is_bind': is_bind,
1206 'mb_is_ip4': is_ip4,
1207 'mb_address_length': dst_address_length,
1208 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +00001209
1210 def mpls_tunnel_add_del(
1211 self,
1212 tun_sw_if_index,
1213 next_hop_proto_is_ip4,
1214 next_hop_address,
1215 next_hop_sw_if_index=0xFFFFFFFF,
1216 next_hop_table_id=0,
1217 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001218 next_hop_n_out_labels=0,
1219 next_hop_out_label_stack=[],
1220 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +00001221 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001222 l2_only=0,
1223 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +00001224 """
1225
1226 :param dst_address_length:
1227 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1228 :param dst_address:
1229 :param next_hop_address:
1230 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
1231 :param vrf_id: (Default value = 0)
1232 :param lookup_in_vrf: (Default value = 0)
1233 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +00001234 :param is_add: (Default value = 1)
1235 :param is_drop: (Default value = 0)
1236 :param is_ipv6: (Default value = 0)
1237 :param is_local: (Default value = 0)
1238 :param is_classify: (Default value = 0)
1239 :param is_multipath: (Default value = 0)
1240 :param is_resolve_host: (Default value = 0)
1241 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001242 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001243 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +00001244
1245 """
Neale Rannsad422ed2016-11-02 14:20:04 +00001246 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +01001247 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001248 {'mt_sw_if_index': tun_sw_if_index,
1249 'mt_is_add': is_add,
1250 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001251 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001252 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
1253 'mt_next_hop_weight': next_hop_weight,
1254 'mt_next_hop': next_hop_address,
1255 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
1256 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
1257 'mt_next_hop_table_id': next_hop_table_id,
1258 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -08001259
Matus Fabian2ba92e32017-08-21 07:05:03 -07001260 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -08001261 self,
1262 sw_if_index,
1263 is_inside=1,
1264 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001265 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -08001266
1267 :param sw_if_index: Software index of the interface
1268 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1269 :param is_add: 1 if add, 0 if delete (Default value = 1)
1270 """
1271 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001272 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001273 {'is_add': is_add,
1274 'is_inside': is_inside,
1275 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -08001276
Matus Fabian2ba92e32017-08-21 07:05:03 -07001277 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -07001278 self,
1279 sw_if_index,
1280 is_inside=1,
1281 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001282 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -07001283
1284 :param sw_if_index: Software index of the interface
1285 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1286 :param is_add: 1 if add, 0 if delete (Default value = 1)
1287 """
1288 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001289 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -07001290 {'is_add': is_add,
1291 'is_inside': is_inside,
1292 'sw_if_index': sw_if_index})
1293
Matus Fabian2ba92e32017-08-21 07:05:03 -07001294 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -08001295 self,
1296 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -08001297 external_ip=0,
1298 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -08001299 local_port=0,
1300 external_port=0,
1301 addr_only=1,
1302 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -08001303 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001304 twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -08001305 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001306 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -07001307 is_add=1):
1308 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -08001309
1310 :param local_ip: Local IP address
1311 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -08001312 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -08001313 :param local_port: Local port number (Default value = 0)
1314 :param external_port: External port number (Default value = 0)
1315 :param addr_only: 1 if address only mapping, 0 if address and port
1316 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -08001317 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -08001318 :param twice_nat: 1 if translate external host address and port
Matus Fabiane82488f2018-01-18 03:38:45 -08001319 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -08001320 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -08001321 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001322 """
1323 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001324 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001325 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001326 'addr_only': addr_only,
1327 'local_ip_address': local_ip,
1328 'external_ip_address': external_ip,
1329 'local_port': local_port,
1330 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -08001331 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -08001332 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001333 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -08001334 'twice_nat': twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -08001335 'out2in_only': out2in_only,
1336 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -08001337
Matus Fabianab7a8052017-11-28 04:29:41 -08001338 def nat44_add_del_identity_mapping(
1339 self,
1340 ip='0',
1341 sw_if_index=0xFFFFFFFF,
1342 port=0,
1343 addr_only=1,
1344 vrf_id=0,
1345 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001346 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -08001347 is_add=1):
1348 """Add/delete NAT44 identity mapping
1349
1350 :param ip: IP address (Default value = 0)
1351 :param sw_if_index: Interface instead of IP address
1352 :param port: Port number (Default value = 0)
1353 :param addr_only: 1 if address only mapping, 0 if address and port
1354 :param vrf_id: VRF ID
1355 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -08001356 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -08001357 :param is_add: 1 if add, 0 if delete (Default value = 1)
1358 """
1359 return self.api(
1360 self.papi.nat44_add_del_identity_mapping,
1361 {'is_add': is_add,
1362 'addr_only': addr_only,
1363 'ip_address': ip,
1364 'port': port,
1365 'sw_if_index': sw_if_index,
1366 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -08001367 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -08001368 'protocol': protocol})
1369
Matus Fabian2ba92e32017-08-21 07:05:03 -07001370 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -08001371 self,
1372 first_ip_address,
1373 last_ip_address,
1374 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -08001375 vrf_id=0xFFFFFFFF,
1376 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001377 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -08001378
1379 :param first_ip_address: First IP address
1380 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001381 :param vrf_id: VRF id for the address range
Matus Fabianb932d262017-12-18 05:38:24 -08001382 :param twice_nat: twice NAT address for extenal hosts
Matus Fabiande886752016-12-07 03:38:19 -08001383 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -08001384 """
1385 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001386 self.papi.nat44_add_del_address_range,
1387 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001388 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -08001389 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001390 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001391 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -08001392
Matus Fabian2ba92e32017-08-21 07:05:03 -07001393 def nat44_address_dump(self):
1394 """Dump NAT44 addresses
1395 :return: Dictionary of NAT44 addresses
Matus Fabiande886752016-12-07 03:38:19 -08001396 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001397 return self.api(self.papi.nat44_address_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001398
Matus Fabian2ba92e32017-08-21 07:05:03 -07001399 def nat44_interface_dump(self):
1400 """Dump interfaces with NAT44 feature
1401 :return: Dictionary of interfaces with NAT44 feature
Matus Fabiande886752016-12-07 03:38:19 -08001402 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001403 return self.api(self.papi.nat44_interface_dump, {})
Matus Fabiande886752016-12-07 03:38:19 -08001404
Matus Fabian2ba92e32017-08-21 07:05:03 -07001405 def nat44_interface_output_feature_dump(self):
1406 """Dump interfaces with NAT44 output feature
1407 :return: Dictionary of interfaces with NAT44 output feature
Matus Fabian93d84c92017-07-19 08:06:01 -07001408 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001409 return self.api(self.papi.nat44_interface_output_feature_dump, {})
Matus Fabian93d84c92017-07-19 08:06:01 -07001410
Matus Fabian2ba92e32017-08-21 07:05:03 -07001411 def nat44_static_mapping_dump(self):
1412 """Dump NAT44 static mappings
1413 :return: Dictionary of NAT44 static mappings
Matus Fabiande886752016-12-07 03:38:19 -08001414 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001415 return self.api(self.papi.nat44_static_mapping_dump, {})
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001416
Matus Fabianab7a8052017-11-28 04:29:41 -08001417 def nat44_identity_mapping_dump(self):
1418 """Dump NAT44 identity mappings
1419 :return: Dictionary of NAT44 identity mappings
1420 """
1421 return self.api(self.papi.nat44_identity_mapping_dump, {})
1422
Matus Fabian2ba92e32017-08-21 07:05:03 -07001423 def nat_show_config(self):
1424 """Show NAT plugin config
1425 :return: NAT plugin config parameters
Matus Fabian9902fcd2016-12-21 23:58:46 -08001426 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001427 return self.api(self.papi.nat_show_config, {})
Matus Fabian9902fcd2016-12-21 23:58:46 -08001428
Matus Fabian2ba92e32017-08-21 07:05:03 -07001429 def nat44_add_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -08001430 self,
1431 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -08001432 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -08001433 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001434 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -08001435
1436 :param sw_if_index: Software index of the interface
Matus Fabianb932d262017-12-18 05:38:24 -08001437 :param twice_nat: twice NAT address for extenal hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -08001438 :param is_add: 1 if add, 0 if delete (Default value = 1)
1439 """
Matus Fabianb932d262017-12-18 05:38:24 -08001440 return self.api(
1441 self.papi.nat44_add_del_interface_addr,
1442 {'is_add': is_add,
1443 'sw_if_index': sw_if_index,
1444 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001445
Matus Fabian2ba92e32017-08-21 07:05:03 -07001446 def nat44_interface_addr_dump(self):
1447 """Dump NAT44 addresses interfaces
1448 :return: Dictionary of NAT44 addresses interfaces
Matus Fabian8bf68e82017-01-12 04:24:35 -08001449 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001450 return self.api(self.papi.nat44_interface_addr_dump, {})
Matus Fabian8bf68e82017-01-12 04:24:35 -08001451
Matus Fabian2ba92e32017-08-21 07:05:03 -07001452 def nat_ipfix(
Matus Fabianeea28d72017-01-13 04:15:54 -08001453 self,
1454 domain_id=1,
1455 src_port=4739,
1456 enable=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001457 """Enable/disable NAT IPFIX logging
Matus Fabianeea28d72017-01-13 04:15:54 -08001458
1459 :param domain_id: Observation domain ID (Default value = 1)
1460 :param src_port: Source port number (Default value = 4739)
1461 :param enable: 1 if enable, 0 if disable (Default value = 1)
1462 """
1463 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001464 self.papi.nat_ipfix_enable_disable,
Matus Fabianeea28d72017-01-13 04:15:54 -08001465 {'domain_id': domain_id,
1466 'src_port': src_port,
1467 'enable': enable})
1468
Matus Fabian2ba92e32017-08-21 07:05:03 -07001469 def nat44_user_session_dump(
magalik23caa882017-02-08 23:25:45 -08001470 self,
1471 ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001472 vrf_id):
1473 """Dump NAT44 user's sessions
magalik23caa882017-02-08 23:25:45 -08001474
1475 :param ip_address: ip adress of the user to be dumped
1476 :param cpu_index: cpu_index on which the user is
1477 :param vrf_id: VRF ID
1478 :return: Dictionary of S-NAT sessions
1479 """
1480 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001481 self.papi.nat44_user_session_dump,
magalik23caa882017-02-08 23:25:45 -08001482 {'ip_address': ip_address,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001483 'vrf_id': vrf_id})
magalik23caa882017-02-08 23:25:45 -08001484
Matus Fabian2ba92e32017-08-21 07:05:03 -07001485 def nat44_user_dump(self):
1486 """Dump NAT44 users
magalik23caa882017-02-08 23:25:45 -08001487
Matus Fabian2ba92e32017-08-21 07:05:03 -07001488 :return: Dictionary of NAT44 users
magalik23caa882017-02-08 23:25:45 -08001489 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001490 return self.api(self.papi.nat44_user_dump, {})
magalik23caa882017-02-08 23:25:45 -08001491
Matus Fabian704018c2017-09-04 02:17:18 -07001492 def nat44_add_del_lb_static_mapping(
1493 self,
1494 external_addr,
1495 external_port,
1496 protocol,
1497 vrf_id=0,
Matus Fabianb932d262017-12-18 05:38:24 -08001498 twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001499 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -08001500 tag='',
Matus Fabian704018c2017-09-04 02:17:18 -07001501 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +02001502 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -07001503 is_add=1):
1504 """Add/delete NAT44 load balancing static mapping
1505
Matus Fabianb932d262017-12-18 05:38:24 -08001506 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -08001507 :param tag: Opaque string tag
Matus Fabian704018c2017-09-04 02:17:18 -07001508 :param is_add - 1 if add, 0 if delete
1509 """
1510 return self.api(
1511 self.papi.nat44_add_del_lb_static_mapping,
1512 {'is_add': is_add,
1513 'external_addr': external_addr,
1514 'external_port': external_port,
1515 'protocol': protocol,
1516 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -08001517 'twice_nat': twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -08001518 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -08001519 'tag': tag,
Matus Fabian704018c2017-09-04 02:17:18 -07001520 'local_num': local_num,
1521 'locals': locals})
1522
1523 def nat44_lb_static_mapping_dump(self):
1524 """Dump NAT44 load balancing static mappings
1525
1526 :return: Dictionary of NAT44 load balancing static mapping
1527 """
1528 return self.api(self.papi.nat44_lb_static_mapping_dump, {})
1529
Matus Fabian5ba86f72017-10-26 03:37:38 -07001530 def nat44_del_session(
1531 self,
1532 addr,
1533 port,
1534 protocol,
1535 vrf_id=0,
1536 is_in=1):
1537 """Delete NAT44 session
1538
1539 :param addr: IPv4 address
1540 :param por: port number
1541 :param protocol: IP protocol number
1542 :param vrf_id: VRF ID
1543 :param is_in: 1 if inside network addres and port pari, 0 if outside
1544 """
1545 return self.api(
1546 self.papi.nat44_del_session,
1547 {'address': addr,
1548 'port': port,
1549 'protocol': protocol,
1550 'vrf_id': vrf_id,
1551 'is_in': is_in})
1552
Juraj Sloboda7b929792017-11-23 13:20:48 +01001553 def nat44_forwarding_enable_disable(
1554 self,
1555 enable):
1556 """Enable/disable forwarding for NAT44
1557
1558 :param enable: 1 for enable, 0 for disable
1559 """
1560 return self.api(
1561 self.papi.nat44_forwarding_enable_disable,
1562 {'enable': enable})
1563
Matus Fabianefcd1e92017-08-15 06:59:19 -07001564 def nat_set_reass(
1565 self,
1566 timeout=2,
1567 max_reass=1024,
1568 max_frag=5,
1569 drop_frag=0,
1570 is_ip6=0):
1571 """Set NAT virtual fragmentation reassembly
1572
1573 :param timeout: reassembly timeout (Default 2sec)
1574 :param max_reass: maximum concurrent reassemblies (Default 1024)
1575 :param max_frag: maximum fragmets per reassembly (Default 5)
1576 :param drop_frag: if 0 translate fragments, otherwise drop fragments
1577 :param is_ip6: 1 if IPv6, 0 if IPv4
1578 """
1579 return self.api(
1580 self.papi.nat_set_reass,
1581 {'timeout': timeout,
1582 'max_reass': max_reass,
1583 'max_frag': max_frag,
1584 'drop_frag': drop_frag,
1585 'is_ip6': is_ip6})
1586
1587 def nat_get_reass(self):
1588 """Get NAT virtual fragmentation reassembly configuration
1589
1590 :return: NAT virtual fragmentation reassembly configuration
1591 """
1592 return self.api(self.papi.nat_get_reass, {})
1593
1594 def nat_reass_dump(self):
1595 """Dump NAT virtual fragmentation reassemblies
1596
1597 :return: Dictionary of NAT virtual fragmentation reassemblies
1598 """
1599 return self.api(self.papi.nat_reass_dump, {})
1600
Matus Fabian2ba92e32017-08-21 07:05:03 -07001601 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001602 self,
1603 in_addr,
1604 in_plen,
1605 out_addr,
1606 out_plen,
1607 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001608 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001609
1610 :param is_add - 1 if add, 0 if delete
1611 :param in_addr - inside IP address
1612 :param in_plen - inside IP address prefix length
1613 :param out_addr - outside IP address
1614 :param out_plen - outside IP address prefix length
1615 """
1616 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001617 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001618 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001619 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001620 'in_addr': in_addr,
1621 'in_plen': in_plen,
1622 'out_addr': out_addr,
1623 'out_plen': out_plen})
1624
Matus Fabian2ba92e32017-08-21 07:05:03 -07001625 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001626 self,
1627 in_addr):
1628 """Get outside address and port range from inside address
1629
1630 :param in_addr - inside IP address
1631 """
1632 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001633 self.papi.nat_det_forward,
1634 {'in_addr': in_addr,
1635 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001636
Matus Fabian2ba92e32017-08-21 07:05:03 -07001637 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001638 self,
1639 out_addr,
1640 out_port):
1641 """Get inside address from outside address and port
1642
1643 :param out_addr - outside IP address
1644 :param out_port - outside port
1645 """
1646 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001647 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001648 {'out_addr': out_addr,
1649 'out_port': out_port})
1650
Matus Fabian2ba92e32017-08-21 07:05:03 -07001651 def nat_det_map_dump(self):
1652 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001653
Matus Fabian2ba92e32017-08-21 07:05:03 -07001654 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001655 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001656 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001657
Matus Fabian2ba92e32017-08-21 07:05:03 -07001658 def nat_det_set_timeouts(
Matus Fabian6a0946f2017-04-12 03:36:13 -07001659 self,
1660 udp=300,
1661 tcp_established=7440,
1662 tcp_transitory=240,
1663 icmp=60):
1664 """Set values of timeouts for deterministic NAT (in seconds)
1665
1666 :param udp - UDP timeout (Default value = 300)
1667 :param tcp_established - TCP established timeout (Default value = 7440)
1668 :param tcp_transitory - TCP transitory timeout (Default value = 240)
1669 :param icmp - ICMP timeout (Default value = 60)
1670 """
1671 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001672 self.papi.nat_det_set_timeouts,
Matus Fabian6a0946f2017-04-12 03:36:13 -07001673 {'udp': udp,
1674 'tcp_established': tcp_established,
1675 'tcp_transitory': tcp_transitory,
1676 'icmp': icmp})
1677
Matus Fabian2ba92e32017-08-21 07:05:03 -07001678 def nat_det_get_timeouts(self):
Matus Fabian6a0946f2017-04-12 03:36:13 -07001679 """Get values of timeouts for deterministic NAT
1680
1681 :return: Timeouts for deterministic NAT (in seconds)
1682 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001683 return self.api(self.papi.nat_det_get_timeouts, {})
Matus Fabian6a0946f2017-04-12 03:36:13 -07001684
Matus Fabian2ba92e32017-08-21 07:05:03 -07001685 def nat_det_close_session_out(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001686 self,
1687 out_addr,
1688 out_port,
1689 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001690 ext_port):
1691 """Close deterministic NAT session using outside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001692
1693 :param out_addr - outside IP address
1694 :param out_port - outside port
1695 :param ext_addr - external host IP address
1696 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001697 """
1698 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001699 self.papi.nat_det_close_session_out,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001700 {'out_addr': out_addr,
1701 'out_port': out_port,
1702 'ext_addr': ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001703 'ext_port': ext_port})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001704
Matus Fabian2ba92e32017-08-21 07:05:03 -07001705 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001706 self,
1707 in_addr,
1708 in_port,
1709 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001710 ext_port):
1711 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001712
1713 :param in_addr - inside IP address
1714 :param in_port - inside port
1715 :param ext_addr - external host IP address
1716 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001717 """
1718 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001719 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001720 {'in_addr': in_addr,
1721 'in_port': in_port,
1722 'ext_addr': ext_addr,
1723 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001724 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001725
Matus Fabian2ba92e32017-08-21 07:05:03 -07001726 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001727 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001728 user_addr):
1729 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001730
1731 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001732 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001733 """
1734 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001735 self.papi.nat_det_session_dump,
1736 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001737 'user_addr': user_addr})
1738
Matus Fabian06596c52017-06-06 04:53:28 -07001739 def nat64_add_del_pool_addr_range(
1740 self,
1741 start_addr,
1742 end_addr,
1743 vrf_id=0xFFFFFFFF,
1744 is_add=1):
1745 """Add/del address range to NAT64 pool
1746
1747 :param start_addr: First IP address
1748 :param end_addr: Last IP address
1749 :param vrf_id: VRF id for the address range
1750 :param is_add: 1 if add, 0 if delete (Default value = 1)
1751 """
1752 return self.api(
1753 self.papi.nat64_add_del_pool_addr_range,
1754 {'start_addr': start_addr,
1755 'end_addr': end_addr,
1756 'vrf_id': vrf_id,
1757 'is_add': is_add})
1758
1759 def nat64_pool_addr_dump(self):
1760 """Dump NAT64 pool addresses
1761 :return: Dictionary of NAT64 pool addresses
1762 """
1763 return self.api(self.papi.nat64_pool_addr_dump, {})
1764
1765 def nat64_add_del_interface(
1766 self,
1767 sw_if_index,
1768 is_inside=1,
1769 is_add=1):
1770 """Enable/disable NAT64 feature on the interface
1771 :param sw_if_index: Index of the interface
1772 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1773 :param is_add: 1 if add, 0 if delete (Default value = 1)
1774 """
1775 return self.api(
1776 self.papi.nat64_add_del_interface,
1777 {'sw_if_index': sw_if_index,
1778 'is_inside': is_inside,
1779 'is_add': is_add})
1780
1781 def nat64_interface_dump(self):
1782 """Dump interfaces with NAT64 feature
1783 :return: Dictionary of interfaces with NAT64 feature
1784 """
1785 return self.api(self.papi.nat64_interface_dump, {})
1786
1787 def nat64_add_del_static_bib(
1788 self,
1789 in_ip,
1790 out_ip,
1791 in_port,
1792 out_port,
1793 protocol,
1794 vrf_id=0,
1795 is_add=1):
1796 """Add/delete S-NAT static BIB entry
1797
1798 :param in_ip: Inside IPv6 address
1799 :param out_ip: Outside IPv4 address
1800 :param in_port: Inside port number
1801 :param out_port: Outside port number
1802 :param protocol: IP protocol
1803 :param vrf_id: VRF ID (Default value = 0)
1804 :param is_add: 1 if add, 0 if delete (Default value = 1)
1805 """
1806 return self.api(
1807 self.papi.nat64_add_del_static_bib,
1808 {'i_addr': in_ip,
1809 'o_addr': out_ip,
1810 'i_port': in_port,
1811 'o_port': out_port,
1812 'vrf_id': vrf_id,
1813 'proto': protocol,
1814 'is_add': is_add})
1815
Matus Fabianab9a59c2017-08-16 05:37:36 -07001816 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001817 """Dump NAT64 BIB
1818
Matus Fabianab9a59c2017-08-16 05:37:36 -07001819 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001820 :returns: Dictionary of NAT64 BIB entries
1821 """
1822 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1823
1824 def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440,
1825 tcp_incoming_syn=6):
1826 """Set values of timeouts for NAT64 (in seconds)
1827
Matus Fabian428dc912017-06-21 06:15:18 -07001828 :param udpi: UDP timeout (Default value = 300)
1829 :param icmp: ICMP timeout (Default value = 60)
1830 :param tcp_trans: TCP transitory timeout (Default value = 240)
1831 :param tcp_est: TCP established timeout (Default value = 7440)
1832 :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6)
Matus Fabian06596c52017-06-06 04:53:28 -07001833 """
1834 return self.api(
1835 self.papi.nat64_set_timeouts,
1836 {'udp': udp,
1837 'icmp': icmp,
1838 'tcp_trans': tcp_trans,
1839 'tcp_est': tcp_est,
1840 'tcp_incoming_syn': tcp_incoming_syn})
1841
1842 def nat64_get_timeouts(self):
1843 """Get values of timeouts for NAT64
1844
1845 :return: Timeouts for NAT64 (in seconds)
1846 """
1847 return self.api(self.papi.nat64_get_timeouts, {})
1848
Matus Fabianab9a59c2017-08-16 05:37:36 -07001849 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001850 """Dump NAT64 session table
1851
Matus Fabianab9a59c2017-08-16 05:37:36 -07001852 :param protocol: IP protocol (Default value = 255, all STs)
Matus Fabian06596c52017-06-06 04:53:28 -07001853 :returns: Dictionary of NAT64 sesstion table entries
1854 """
1855 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1856
Matus Fabian428dc912017-06-21 06:15:18 -07001857 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1858 """Add/del NAT64 prefix
1859
1860 :param prefix: NAT64 prefix
1861 :param plen: NAT64 prefix length
1862 :param vrf_id: VRF id of tenant (Default 0)
1863 :param is_add: 1 if add, 0 if delete (Default value = 1)
1864 """
1865 return self.api(
1866 self.papi.nat64_add_del_prefix,
1867 {'prefix': prefix,
1868 'prefix_len': plen,
1869 'vrf_id': vrf_id,
1870 'is_add': is_add})
1871
1872 def nat64_prefix_dump(self):
1873 """Dump NAT64 prefix
1874
1875 :returns: Dictionary of NAT64 prefixes
1876 """
1877 return self.api(self.papi.nat64_prefix_dump, {})
1878
Matus Fabian0938dcf2017-11-08 01:59:38 -08001879 def nat64_add_interface_addr(
1880 self,
1881 sw_if_index,
1882 is_add=1):
1883 """Add/del NAT64 address from interface
1884
1885 :param sw_if_index: Software index of the interface
1886 :param is_add: 1 if add, 0 if delete (Default value = 1)
1887 """
1888 return self.api(self.papi.nat64_add_del_interface_addr,
1889 {'is_add': is_add, 'sw_if_index': sw_if_index})
1890
Matus Fabian8ebe6252017-11-06 05:04:53 -08001891 def dslite_set_aftr_addr(self, ip6, ip4):
1892 """Set DS-Lite AFTR addresses
1893
1894 :param ip4: IPv4 address
1895 :param ip6: IPv6 address
1896 """
1897 return self.api(
1898 self.papi.dslite_set_aftr_addr,
1899 {'ip4_addr': ip4,
1900 'ip6_addr': ip6})
1901
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001902 def dslite_set_b4_addr(self, ip6, ip4):
1903 """Set DS-Lite B4 IPv6 address
1904
1905 :param ip4: IPv4 address
1906 :param ip6: IPv6 address
1907 """
1908 return self.api(
1909 self.papi.dslite_set_b4_addr,
1910 {'ip4_addr': ip4,
1911 'ip6_addr': ip6})
1912
Matus Fabian8ebe6252017-11-06 05:04:53 -08001913 def dslite_add_del_pool_addr_range(
1914 self,
1915 start_addr,
1916 end_addr,
1917 is_add=1):
1918 """Add/del address range to DS-Lite pool
1919
1920 :param start_addr: First IP address
1921 :param end_addr: Last IP address
1922 :param is_add: 1 if add, 0 if delete (Default value = 1)
1923 """
1924 return self.api(
1925 self.papi.dslite_add_del_pool_addr_range,
1926 {'start_addr': start_addr,
1927 'end_addr': end_addr,
1928 'is_add': is_add})
1929
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001930 def nat66_add_del_interface(
1931 self,
1932 sw_if_index,
1933 is_inside=1,
1934 is_add=1):
1935 """Enable/disable NAT66 feature on the interface
1936 :param sw_if_index: Index of the interface
1937 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1938 :param is_add: 1 if add, 0 if delete (Default value = 1)
1939 """
1940 return self.api(
1941 self.papi.nat66_add_del_interface,
1942 {'sw_if_index': sw_if_index,
1943 'is_inside': is_inside,
1944 'is_add': is_add})
1945
1946 def nat66_add_del_static_mapping(
1947 self,
1948 in_ip,
1949 out_ip,
1950 vrf_id=0,
1951 is_add=1):
1952 """Add/delete NAT66 static mapping
1953
1954 :param in_ip: Inside IPv6 address
1955 :param out_ip: Outside IPv6 address
1956 :param vrf_id: VRF ID (Default value = 0)
1957 :param is_add: 1 if add, 0 if delete (Default value = 1)
1958 """
1959 return self.api(
1960 self.papi.nat66_add_del_static_mapping,
1961 {'local_ip_address': in_ip,
1962 'external_ip_address': out_ip,
1963 'vrf_id': vrf_id,
1964 'is_add': is_add})
1965
1966 def nat66_interface_dump(self):
1967 """Dump interfaces with NAT66 feature
1968 :return: Dictionary of interfaces with NAT66 feature
1969 """
1970 return self.api(self.papi.nat66_interface_dump, {})
1971
1972 def nat66_static_mapping_dump(self):
1973 """Dump NAT66 static mappings
1974 :return: Dictionary of NAT66 static mappings
1975 """
1976 return self.api(self.papi.nat66_static_mapping_dump, {})
1977
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001978 def control_ping(self):
1979 self.api(self.papi.control_ping)
1980
1981 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001982 detect_mult, local_addr, peer_addr, is_ipv6=0,
1983 bfd_key_id=None, conf_key_id=None):
1984 if bfd_key_id is None:
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 })
1995 else:
1996 return self.api(self.papi.bfd_udp_add,
1997 {
1998 'sw_if_index': sw_if_index,
1999 'desired_min_tx': desired_min_tx,
2000 'required_min_rx': required_min_rx,
2001 'local_addr': local_addr,
2002 'peer_addr': peer_addr,
2003 'is_ipv6': is_ipv6,
2004 'detect_mult': detect_mult,
2005 'is_authenticated': 1,
2006 'bfd_key_id': bfd_key_id,
2007 'conf_key_id': conf_key_id,
2008 })
2009
Klement Sekeraa57a9702017-02-02 06:58:07 +01002010 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
2011 detect_mult, local_addr, peer_addr, is_ipv6=0):
2012 return self.api(self.papi.bfd_udp_mod,
2013 {
2014 'sw_if_index': sw_if_index,
2015 'desired_min_tx': desired_min_tx,
2016 'required_min_rx': required_min_rx,
2017 'local_addr': local_addr,
2018 'peer_addr': peer_addr,
2019 'is_ipv6': is_ipv6,
2020 'detect_mult': detect_mult,
2021 })
2022
Klement Sekerab17dd962017-01-09 07:43:48 +01002023 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
2024 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
2025 is_delayed=False):
2026 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002027 {
2028 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002029 'local_addr': local_addr,
2030 'peer_addr': peer_addr,
2031 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01002032 'is_delayed': 1 if is_delayed else 0,
2033 'bfd_key_id': bfd_key_id,
2034 'conf_key_id': conf_key_id,
2035 })
2036
2037 def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
2038 is_ipv6=0, is_delayed=False):
2039 return self.api(self.papi.bfd_udp_auth_deactivate,
2040 {
2041 'sw_if_index': sw_if_index,
2042 'local_addr': local_addr,
2043 'peer_addr': peer_addr,
2044 'is_ipv6': is_ipv6,
2045 'is_delayed': 1 if is_delayed else 0,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002046 })
2047
2048 def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
2049 return self.api(self.papi.bfd_udp_del,
2050 {
2051 'sw_if_index': sw_if_index,
2052 'local_addr': local_addr,
2053 'peer_addr': peer_addr,
2054 'is_ipv6': is_ipv6,
2055 })
2056
2057 def bfd_udp_session_dump(self):
2058 return self.api(self.papi.bfd_udp_session_dump, {})
2059
Klement Sekerab17dd962017-01-09 07:43:48 +01002060 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
2061 peer_addr, is_ipv6=0):
2062 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002063 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01002064 'sw_if_index': sw_if_index,
2065 'local_addr': local_addr,
2066 'peer_addr': peer_addr,
2067 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02002068 })
2069
2070 def want_bfd_events(self, enable_disable=1):
2071 return self.api(self.papi.want_bfd_events, {
2072 'enable_disable': enable_disable,
2073 'pid': os.getpid(),
2074 })
Steve Shin7957d6e2016-12-19 09:24:50 -08002075
Klement Sekerab17dd962017-01-09 07:43:48 +01002076 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
2077 return self.api(self.papi.bfd_auth_set_key, {
2078 'conf_key_id': conf_key_id,
2079 'auth_type': auth_type,
2080 'key': key,
2081 'key_len': len(key),
2082 })
2083
2084 def bfd_auth_del_key(self, conf_key_id):
2085 return self.api(self.papi.bfd_auth_del_key, {
2086 'conf_key_id': conf_key_id,
2087 })
2088
2089 def bfd_auth_keys_dump(self):
2090 return self.api(self.papi.bfd_auth_keys_dump, {})
2091
Klement Sekera239790f2017-02-16 10:53:53 +01002092 def bfd_udp_set_echo_source(self, sw_if_index):
2093 return self.api(self.papi.bfd_udp_set_echo_source,
2094 {'sw_if_index': sw_if_index})
2095
Klement Sekera73884482017-02-23 09:26:30 +01002096 def bfd_udp_del_echo_source(self):
2097 return self.api(self.papi.bfd_udp_del_echo_source, {})
2098
Steve Shin7957d6e2016-12-19 09:24:50 -08002099 def classify_add_del_table(
2100 self,
2101 is_add,
2102 mask,
2103 match_n_vectors=1,
2104 table_index=0xFFFFFFFF,
2105 nbuckets=2,
2106 memory_size=2097152,
2107 skip_n_vectors=0,
2108 next_table_index=0xFFFFFFFF,
2109 miss_next_index=0xFFFFFFFF,
2110 current_data_flag=0,
2111 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08002112 """
2113 :param is_add:
2114 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01002115 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01002116 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08002117 :param nbuckets: (Default value = 2)
2118 :param memory_size: (Default value = 2097152)
2119 :param skip_n_vectors: (Default value = 0)
2120 :param next_table_index: (Default value = 0xFFFFFFFF)
2121 :param miss_next_index: (Default value = 0xFFFFFFFF)
2122 :param current_data_flag: (Default value = 0)
2123 :param current_data_offset: (Default value = 0)
2124 """
2125
2126 return self.api(
2127 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002128 {'is_add': is_add,
2129 'table_index': table_index,
2130 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08002131 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002132 'skip_n_vectors': skip_n_vectors,
2133 'match_n_vectors': match_n_vectors,
2134 'next_table_index': next_table_index,
2135 'miss_next_index': miss_next_index,
2136 'current_data_flag': current_data_flag,
2137 'current_data_offset': current_data_offset,
2138 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08002139
2140 def classify_add_del_session(
2141 self,
2142 is_add,
2143 table_index,
2144 match,
2145 opaque_index=0xFFFFFFFF,
2146 hit_next_index=0xFFFFFFFF,
2147 advance=0,
2148 action=0,
2149 metadata=0):
2150 """
2151 :param is_add:
2152 :param table_index:
2153 :param match:
2154 :param opaque_index: (Default value = 0xFFFFFFFF)
2155 :param hit_next_index: (Default value = 0xFFFFFFFF)
2156 :param advance: (Default value = 0)
2157 :param action: (Default value = 0)
2158 :param metadata: (Default value = 0)
2159 """
2160
2161 return self.api(
2162 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002163 {'is_add': is_add,
2164 'table_index': table_index,
2165 'hit_next_index': hit_next_index,
2166 'opaque_index': opaque_index,
2167 'advance': advance,
2168 'action': action,
2169 'metadata': metadata,
2170 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08002171
2172 def input_acl_set_interface(
2173 self,
2174 is_add,
2175 sw_if_index,
2176 ip4_table_index=0xFFFFFFFF,
2177 ip6_table_index=0xFFFFFFFF,
2178 l2_table_index=0xFFFFFFFF):
2179 """
2180 :param is_add:
2181 :param sw_if_index:
2182 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2183 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2184 :param l2_table_index: (Default value = 0xFFFFFFFF)
2185 """
2186
2187 return self.api(
2188 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01002189 {'sw_if_index': sw_if_index,
2190 'ip4_table_index': ip4_table_index,
2191 'ip6_table_index': ip6_table_index,
2192 'l2_table_index': l2_table_index,
2193 'is_add': is_add})
2194
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002195 def output_acl_set_interface(
2196 self,
2197 is_add,
2198 sw_if_index,
2199 ip4_table_index=0xFFFFFFFF,
2200 ip6_table_index=0xFFFFFFFF,
2201 l2_table_index=0xFFFFFFFF):
2202 """
2203 :param is_add:
2204 :param sw_if_index:
2205 :param ip4_table_index: (Default value = 0xFFFFFFFF)
2206 :param ip6_table_index: (Default value = 0xFFFFFFFF)
2207 :param l2_table_index: (Default value = 0xFFFFFFFF)
2208 """
2209
2210 return self.api(
2211 self.papi.output_acl_set_interface,
2212 {'sw_if_index': sw_if_index,
2213 'ip4_table_index': ip4_table_index,
2214 'ip6_table_index': ip6_table_index,
2215 'l2_table_index': l2_table_index,
2216 'is_add': is_add})
2217
Klement Sekera77fabdb2017-01-02 07:46:14 +01002218 def set_ipfix_exporter(
2219 self,
2220 collector_address,
2221 src_address,
2222 path_mtu,
2223 template_interval,
2224 vrf_id=0,
2225 collector_port=4739,
2226 udp_checksum=0):
2227 return self.api(
2228 self.papi.set_ipfix_exporter,
2229 {
2230 'collector_address': collector_address,
2231 'collector_port': collector_port,
2232 'src_address': src_address,
2233 'vrf_id': vrf_id,
2234 'path_mtu': path_mtu,
2235 'template_interval': template_interval,
2236 'udp_checksum': udp_checksum,
2237 })
Neale Rannsfca0c242017-01-13 07:57:46 -08002238
2239 def dhcp_proxy_config(self,
2240 dhcp_server,
2241 dhcp_src_address,
2242 rx_table_id=0,
2243 server_table_id=0,
2244 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08002245 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08002246 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08002247 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08002248 {
2249 'rx_vrf_id': rx_table_id,
2250 'server_vrf_id': server_table_id,
2251 'is_ipv6': is_ipv6,
2252 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08002253 'dhcp_server': dhcp_server,
2254 'dhcp_src_address': dhcp_src_address,
2255 })
2256
2257 def dhcp_proxy_set_vss(self,
2258 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002259 vss_type=255,
2260 vpn_ascii_id="",
2261 oui=0,
2262 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08002263 is_add=1,
2264 is_ip6=0):
2265 return self.api(
2266 self.papi.dhcp_proxy_set_vss,
2267 {
2268 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05002269 'vss_type': vss_type,
2270 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08002271 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05002272 'vpn_index': vpn_index,
2273 'is_add': is_add,
2274 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08002275 })
Neale Ranns32e1c012016-11-22 17:07:28 +00002276
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002277 def dhcp_client(self,
2278 sw_if_index,
2279 hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002280 client_id='',
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002281 is_add=1,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002282 set_broadcast_flag=1,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002283 want_dhcp_events=0):
2284 return self.api(
2285 self.papi.dhcp_client_config,
2286 {
2287 'sw_if_index': sw_if_index,
2288 'hostname': hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -07002289 'client_id': client_id,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002290 'is_add': is_add,
2291 'want_dhcp_event': want_dhcp_events,
Neale Ranns54c6dc42018-01-17 10:29:10 -08002292 'set_broadcast_flag': set_broadcast_flag,
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07002293 'pid': os.getpid(),
2294 })
2295
Neale Ranns32e1c012016-11-22 17:07:28 +00002296 def ip_mroute_add_del(self,
2297 src_address,
2298 grp_address,
2299 grp_address_length,
2300 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002301 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002302 next_hop_sw_if_index,
2303 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002304 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002305 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002306 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00002307 is_add=1,
2308 is_ipv6=0,
2309 is_local=0):
2310 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07002311 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00002312 """
2313 return self.api(
2314 self.papi.ip_mroute_add_del,
2315 {'next_hop_sw_if_index': next_hop_sw_if_index,
2316 'entry_flags': e_flags,
2317 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08002318 'table_id': table_id,
2319 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00002320 'is_add': is_add,
2321 'is_ipv6': is_ipv6,
2322 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002323 'bier_imp': bier_imp,
2324 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00002325 'grp_address_length': grp_address_length,
2326 'grp_address': grp_address,
2327 'src_address': src_address})
2328
2329 def mfib_signal_dump(self):
2330 return self.api(self.papi.mfib_signal_dump, {})
Neale Ranns5a8123b2017-01-26 01:18:23 -08002331
2332 def ip_mfib_dump(self):
2333 return self.api(self.papi.ip_mfib_dump, {})
Filip Tehlar770e89e2017-01-31 10:39:16 +01002334
Neale Rannsd792d9c2017-10-21 10:53:20 -07002335 def ip6_mfib_dump(self):
2336 return self.api(self.papi.ip6_mfib_dump, {})
2337
Filip Tehlar770e89e2017-01-31 10:39:16 +01002338 def lisp_enable_disable(self, is_enabled):
2339 return self.api(
2340 self.papi.lisp_enable_disable,
2341 {
2342 'is_en': is_enabled,
2343 })
2344
2345 def lisp_locator_set(self,
2346 ls_name,
2347 is_add=1):
2348 return self.api(
2349 self.papi.lisp_add_del_locator_set,
2350 {
2351 'is_add': is_add,
2352 'locator_set_name': ls_name
2353 })
2354
2355 def lisp_locator_set_dump(self):
2356 return self.api(self.papi.lisp_locator_set_dump, {})
2357
2358 def lisp_locator(self,
2359 ls_name,
2360 sw_if_index,
2361 priority=1,
2362 weight=1,
2363 is_add=1):
2364 return self.api(
2365 self.papi.lisp_add_del_locator,
2366 {
2367 'is_add': is_add,
2368 'locator_set_name': ls_name,
2369 'sw_if_index': sw_if_index,
2370 'priority': priority,
2371 'weight': weight
2372 })
2373
2374 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
2375 return self.api(
2376 self.papi.lisp_locator_dump,
2377 {
2378 'is_index_set': is_index_set,
2379 'ls_name': ls_name,
2380 'ls_index': ls_index,
2381 })
2382
2383 def lisp_local_mapping(self,
2384 ls_name,
2385 eid_type,
2386 eid,
2387 prefix_len,
2388 vni=0,
2389 key_id=0,
2390 key="",
2391 is_add=1):
2392 return self.api(
2393 self.papi.lisp_add_del_local_eid,
2394 {
2395 'locator_set_name': ls_name,
2396 'is_add': is_add,
2397 'eid_type': eid_type,
2398 'eid': eid,
2399 'prefix_len': prefix_len,
2400 'vni': vni,
2401 'key_id': key_id,
2402 'key': key
2403 })
2404
2405 def lisp_eid_table_dump(self,
2406 eid_set=0,
2407 prefix_length=0,
2408 vni=0,
2409 eid_type=0,
2410 eid=None,
2411 filter_opt=0):
2412 return self.api(
2413 self.papi.lisp_eid_table_dump,
2414 {
2415 'eid_set': eid_set,
2416 'prefix_length': prefix_length,
2417 'vni': vni,
2418 'eid_type': eid_type,
2419 'eid': eid,
2420 'filter': filter_opt,
2421 })
2422
2423 def lisp_remote_mapping(self,
2424 eid_type,
2425 eid,
2426 eid_prefix_len=0,
2427 vni=0,
Ole Troan895b6e82017-10-20 13:28:20 +02002428 rlocs=[],
Filip Tehlar770e89e2017-01-31 10:39:16 +01002429 rlocs_num=0,
2430 is_src_dst=0,
2431 is_add=1):
2432 return self.api(
2433 self.papi.lisp_add_del_remote_mapping,
2434 {
2435 'is_add': is_add,
2436 'eid_type': eid_type,
2437 'eid': eid,
2438 'eid_len': eid_prefix_len,
2439 'rloc_num': rlocs_num,
2440 'rlocs': rlocs,
2441 'vni': vni,
2442 'is_src_dst': is_src_dst,
2443 })
2444
2445 def lisp_adjacency(self,
2446 leid,
2447 reid,
2448 leid_len,
2449 reid_len,
2450 eid_type,
2451 is_add=1,
2452 vni=0):
2453 return self.api(
2454 self.papi.lisp_add_del_adjacency,
2455 {
2456 'is_add': is_add,
2457 'vni': vni,
2458 'eid_type': eid_type,
2459 'leid': leid,
2460 'reid': reid,
2461 'leid_len': leid_len,
2462 'reid_len': reid_len,
2463 })
2464
2465 def lisp_adjacencies_get(self, vni=0):
2466 return self.api(
2467 self.papi.lisp_adjacencies_get,
2468 {
2469 'vni': vni
2470 })
Neale Ranns80823802017-02-20 18:23:41 -08002471
2472 def map_add_domain(self,
2473 ip6_prefix,
2474 ip6_prefix_len,
2475 ip6_src,
2476 ip6_src_prefix_len,
2477 ip4_prefix,
2478 ip4_prefix_len,
2479 ea_bits_len=0,
2480 psid_offset=0,
2481 psid_length=0,
2482 is_translation=0,
Juraj Slobodacba69362017-12-19 02:09:32 +01002483 is_rfc6052=0,
Neale Ranns80823802017-02-20 18:23:41 -08002484 mtu=1280):
2485 return self.api(
2486 self.papi.map_add_domain,
2487 {
2488 'ip6_prefix': ip6_prefix,
2489 'ip6_prefix_len': ip6_prefix_len,
2490 'ip4_prefix': ip4_prefix,
2491 'ip4_prefix_len': ip4_prefix_len,
2492 'ip6_src': ip6_src,
2493 'ip6_src_prefix_len': ip6_src_prefix_len,
2494 'ea_bits_len': ea_bits_len,
2495 'psid_offset': psid_offset,
2496 'psid_length': psid_length,
2497 'is_translation': is_translation,
Juraj Slobodacba69362017-12-19 02:09:32 +01002498 'is_rfc6052': is_rfc6052,
Neale Ranns80823802017-02-20 18:23:41 -08002499 'mtu': mtu
2500 })
Hongjun Nief486b12017-04-12 19:21:16 +08002501
2502 def gtpu_add_del_tunnel(
2503 self,
2504 src_addr,
2505 dst_addr,
2506 is_add=1,
2507 is_ipv6=0,
2508 mcast_sw_if_index=0xFFFFFFFF,
2509 encap_vrf_id=0,
2510 decap_next_index=0xFFFFFFFF,
2511 teid=0):
2512 """
2513
2514 :param is_add: (Default value = 1)
2515 :param is_ipv6: (Default value = 0)
2516 :param src_addr:
2517 :param dst_addr:
2518 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2519 :param encap_vrf_id: (Default value = 0)
2520 :param decap_next_index: (Default value = 0xFFFFFFFF)
2521 :param teid: (Default value = 0)
2522
2523 """
2524 return self.api(self.papi.gtpu_add_del_tunnel,
2525 {'is_add': is_add,
2526 'is_ipv6': is_ipv6,
2527 'src_address': src_addr,
2528 'dst_address': dst_addr,
2529 'mcast_sw_if_index': mcast_sw_if_index,
2530 'encap_vrf_id': encap_vrf_id,
2531 'decap_next_index': decap_next_index,
2532 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08002533
2534 def vxlan_gpe_add_del_tunnel(
2535 self,
2536 src_addr,
2537 dst_addr,
2538 mcast_sw_if_index=0xFFFFFFFF,
2539 is_add=1,
2540 is_ipv6=0,
2541 encap_vrf_id=0,
2542 decap_vrf_id=0,
2543 protocol=3,
2544 vni=0):
2545 """
2546
2547 :param local:
2548 :param remote:
2549 :param is_add: (Default value = 1)
2550 :param is_ipv6: (Default value = 0)
2551 :param encap_vrf_id: (Default value = 0)
2552 :param decap_vrf_id: (Default value = 0)
2553 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
2554 :param protocol: (Default value = 3)
2555 :param vni: (Default value = 0)
2556
2557 """
2558 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
2559 {'is_add': is_add,
2560 'is_ipv6': is_ipv6,
2561 'local': src_addr,
2562 'remote': dst_addr,
2563 'mcast_sw_if_index': mcast_sw_if_index,
2564 'encap_vrf_id': encap_vrf_id,
2565 'decap_vrf_id': decap_vrf_id,
2566 'protocol': protocol,
2567 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08002568
2569 def pppoe_add_del_session(
2570 self,
2571 client_ip,
2572 client_mac,
2573 session_id=0,
2574 is_add=1,
2575 is_ipv6=0,
2576 decap_vrf_id=0):
2577 """
2578
2579 :param is_add: (Default value = 1)
2580 :param is_ipv6: (Default value = 0)
2581 :param client_ip:
2582 :param session_id: (Default value = 0)
2583 :param client_mac:
2584 :param decap_vrf_id: (Default value = 0)
2585
2586 """
2587 return self.api(self.papi.pppoe_add_del_session,
2588 {'is_add': is_add,
2589 'is_ipv6': is_ipv6,
2590 'session_id': session_id,
2591 'client_ip': client_ip,
2592 'decap_vrf_id': decap_vrf_id,
2593 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02002594
2595 def sr_localsid_add_del(self,
2596 localsid_addr,
2597 behavior,
2598 nh_addr,
2599 is_del=0,
2600 end_psp=0,
2601 sw_if_index=0xFFFFFFFF,
2602 vlan_index=0,
2603 fib_table=0,
2604 ):
2605 """ Add/del IPv6 SR local-SID.
2606
2607 :param localsid_addr:
2608 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
2609 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
2610 :param nh_addr:
2611 :param is_del: (Default value = 0)
2612 :param end_psp: (Default value = 0)
2613 :param sw_if_index: (Default value = 0xFFFFFFFF)
2614 :param vlan_index: (Default value = 0)
2615 :param fib_table: (Default value = 0)
2616 """
2617 return self.api(
2618 self.papi.sr_localsid_add_del,
2619 {'is_del': is_del,
2620 'localsid_addr': localsid_addr,
2621 'end_psp': end_psp,
2622 'behavior': behavior,
2623 'sw_if_index': sw_if_index,
2624 'vlan_index': vlan_index,
2625 'fib_table': fib_table,
2626 'nh_addr': nh_addr
2627 }
2628 )
2629
2630 def sr_policy_add(
2631 self,
2632 bsid_addr,
2633 weight=1,
2634 is_encap=1,
2635 type=0,
2636 fib_table=0,
2637 n_segments=0,
2638 segments=[]):
2639 """
2640 :param bsid_addr: bindingSID of the SR Policy
2641 :param weight: weight of the sid list. optional. (default: 1)
2642 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
2643 (default: Encap)
2644 :param type: type/behavior of the SR policy. (default or spray) \
2645 (default: default)
2646 :param fib_table: VRF where to install the FIB entry for the BSID \
2647 (default: 0)
2648 :param n_segments: number of segments \
2649 (default: 0)
2650 :param segments: a vector of IPv6 address composing the segment list \
2651 (default: [])
2652 """
2653 return self.api(
2654 self.papi.sr_policy_add,
2655 {'bsid_addr': bsid_addr,
2656 'weight': weight,
2657 'is_encap': is_encap,
2658 'type': type,
2659 'fib_table': fib_table,
2660 'n_segments': n_segments,
2661 'segments': segments
2662 }
2663 )
2664
2665 def sr_policy_del(
2666 self,
2667 bsid_addr,
2668 sr_policy_index=0):
2669 """
2670 :param bsid: bindingSID of the SR Policy
2671 :param sr_policy_index: index of the sr policy (default: 0)
2672 """
2673 return self.api(
2674 self.papi.sr_policy_del,
2675 {'bsid_addr': bsid_addr,
2676 'sr_policy_index': sr_policy_index
2677 })
2678
2679 def sr_steering_add_del(
2680 self,
2681 is_del,
2682 bsid_addr,
2683 sr_policy_index,
2684 table_id,
2685 prefix_addr,
2686 mask_width,
2687 sw_if_index,
2688 traffic_type):
2689 """
2690 Steer traffic L2 and L3 traffic through a given SR policy
2691
2692 :param is_del: delete or add
2693 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2694 :param sr_policy: is the index of the SR Policy (alt to bsid)
2695 :param table_id: is the VRF where to install the FIB entry for the BSID
2696 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2697 :param mask_width: is the mask for L3 traffic type
2698 :param sw_if_index: is the incoming interface for L2 traffic
2699 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2700 """
2701 return self.api(
2702 self.papi.sr_steering_add_del,
2703 {'is_del': is_del,
2704 'bsid_addr': bsid_addr,
2705 'sr_policy_index': sr_policy_index,
2706 'table_id': table_id,
2707 'prefix_addr': prefix_addr,
2708 'mask_width': mask_width,
2709 'sw_if_index': sw_if_index,
2710 'traffic_type': traffic_type
2711 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002712
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002713 def acl_add_replace(self, acl_index, r, tag='',
2714 expected_retval=0):
2715 """Add/replace an ACL
2716 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2717 :param acl_rule r: ACL rules array.
2718 :param str tag: symbolic tag (description) for this ACL.
2719 :param int count: number of rules.
2720 """
2721 return self.api(self.papi.acl_add_replace,
2722 {'acl_index': acl_index,
2723 'r': r,
2724 'count': len(r),
2725 'tag': tag},
2726 expected_retval=expected_retval)
2727
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002728 def acl_del(self, acl_index, expected_retval=0):
2729 """
2730
2731 :param acl_index:
2732 :return:
2733 """
2734 return self.api(self.papi.acl_del,
2735 {'acl_index': acl_index},
2736 expected_retval=expected_retval)
2737
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002738 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2739 expected_retval=0):
2740 return self.api(self.papi.acl_interface_set_acl_list,
2741 {'sw_if_index': sw_if_index,
2742 'count': len(acls),
2743 'n_input': n_input,
2744 'acls': acls},
2745 expected_retval=expected_retval)
2746
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002747 def acl_interface_set_etype_whitelist(self, sw_if_index,
2748 n_input, whitelist,
2749 expected_retval=0):
2750 return self.api(self.papi.acl_interface_set_etype_whitelist,
2751 {'sw_if_index': sw_if_index,
2752 'count': len(whitelist),
2753 'n_input': n_input,
2754 'whitelist': whitelist},
2755 expected_retval=expected_retval)
2756
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002757 def acl_interface_add_del(self,
2758 sw_if_index,
2759 acl_index,
2760 is_add=1):
2761 """ Add/Delete ACL to/from interface
2762
2763 :param sw_if_index:
2764 :param acl_index:
2765 :param is_add: (Default value = 1)
2766 """
2767
2768 return self.api(self.papi.acl_interface_add_del,
2769 {'is_add': is_add,
2770 'is_input': 1,
2771 'sw_if_index': sw_if_index,
2772 'acl_index': acl_index})
2773
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002774 def acl_dump(self, acl_index, expected_retval=0):
2775 return self.api(self.papi.acl_dump,
2776 {'acl_index': acl_index},
2777 expected_retval=expected_retval)
2778
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002779 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2780 expected_retval=0):
2781 return self.api(self.papi.acl_interface_list_dump,
2782 {'sw_if_index': sw_if_index},
2783 expected_retval=expected_retval)
2784
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002785 def macip_acl_add(self, rules, tag=""):
2786 """ Add MACIP acl
2787
2788 :param rules: list of rules for given acl
2789 :param tag: acl tag
2790 """
2791
2792 return self.api(self.papi.macip_acl_add,
2793 {'r': rules,
2794 'count': len(rules),
2795 'tag': tag})
2796
Pavel Kotucek932f7412017-09-07 14:44:52 +02002797 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2798 """ Add MACIP acl
2799
2800 :param rules: list of rules for given acl
2801 :param tag: acl tag
2802 """
2803
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002804 return self.api(self.papi.macip_acl_add_replace,
2805 {'acl_index': acl_index,
2806 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002807 'count': len(rules),
2808 'tag': tag})
2809
2810 def macip_acl_del(self, acl_index):
2811 """
2812
2813 :param acl_index:
2814 :return:
2815 """
2816 return self.api(self.papi.macip_acl_del,
2817 {'acl_index': acl_index})
2818
2819 def macip_acl_interface_add_del(self,
2820 sw_if_index,
2821 acl_index,
2822 is_add=1):
2823 """ Add MACIP acl to interface
2824
2825 :param sw_if_index:
2826 :param acl_index:
2827 :param is_add: (Default value = 1)
2828 """
2829
2830 return self.api(self.papi.macip_acl_interface_add_del,
2831 {'is_add': is_add,
2832 'sw_if_index': sw_if_index,
2833 'acl_index': acl_index})
2834
2835 def macip_acl_interface_get(self):
2836 """ Return interface acls dump
2837 """
2838 return self.api(
2839 self.papi.macip_acl_interface_get, {})
2840
2841 def macip_acl_dump(self, acl_index=4294967295):
2842 """ Return MACIP acl dump
2843 """
2844
2845 return self.api(
2846 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002847
2848 def policer_add_del(self,
2849 name,
2850 cir,
2851 eir,
2852 cb,
2853 eb,
2854 is_add=1,
2855 rate_type=0,
2856 round_type=0,
2857 ptype=0,
2858 color_aware=0,
2859 conform_action_type=1,
2860 conform_dscp=0,
2861 exceed_action_type=0,
2862 exceed_dscp=0,
2863 violate_action_type=0,
2864 violate_dscp=0):
2865 return self.api(self.papi.policer_add_del,
2866 {'name': name,
2867 'cir': cir,
2868 'eir': eir,
2869 'cb': cb,
2870 'eb': eb,
2871 'is_add': is_add,
2872 'rate_type': rate_type,
2873 'round_type': round_type,
2874 'type': ptype,
2875 'color_aware': color_aware,
2876 'conform_action_type': conform_action_type,
2877 'conform_dscp': conform_dscp,
2878 'exceed_action_type': exceed_action_type,
2879 'exceed_dscp': exceed_dscp,
2880 'violate_action_type': violate_action_type,
2881 'violate_dscp': violate_dscp})
2882
2883 def ip_punt_police(self,
2884 policer_index,
2885 is_ip6=0,
2886 is_add=1):
2887 return self.api(self.papi.ip_punt_police,
2888 {'policer_index': policer_index,
2889 'is_add': is_add,
2890 'is_ip6': is_ip6})
2891
2892 def ip_punt_redirect(self,
2893 rx_sw_if_index,
2894 tx_sw_if_index,
2895 nh,
2896 is_ip6=0,
2897 is_add=1):
2898 return self.api(self.papi.ip_punt_redirect,
2899 {'rx_sw_if_index': rx_sw_if_index,
2900 'tx_sw_if_index': tx_sw_if_index,
2901 'nh': nh,
2902 'is_add': is_add,
2903 'is_ip6': is_ip6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002904
2905 def bier_table_add_del(self,
2906 bti,
2907 mpls_label,
2908 is_add=1):
2909 """ BIER Table add/del """
2910 return self.api(
2911 self.papi.bier_table_add_del,
2912 {'bt_tbl_id': {"bt_set": bti.set_id,
2913 "bt_sub_domain": bti.sub_domain_id,
2914 "bt_hdr_len_id": bti.hdr_len_id},
2915 'bt_label': mpls_label,
2916 'bt_is_add': is_add})
2917
2918 def bier_table_dump(self):
2919 return self.api(self.papi.bier_table_dump, {})
2920
2921 def bier_route_add_del(self,
2922 bti,
2923 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002924 paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002925 is_add=1):
2926 """ BIER Route add/del """
2927 return self.api(
2928 self.papi.bier_route_add_del,
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 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002933 'br_n_paths': len(paths),
2934 'br_paths': paths,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002935 'br_is_add': is_add})
2936
2937 def bier_route_dump(self, bti):
2938 return self.api(
2939 self.papi.bier_route_dump,
2940 {'br_tbl_id': {"bt_set": bti.set_id,
2941 "bt_sub_domain": bti.sub_domain_id,
2942 "bt_hdr_len_id": bti.hdr_len_id}})
2943
2944 def bier_imp_add(self,
2945 bti,
2946 src,
2947 ibytes,
2948 is_add=1):
2949 """ BIER Imposition Add """
2950 return self.api(
2951 self.papi.bier_imp_add,
2952 {'bi_tbl_id': {"bt_set": bti.set_id,
2953 "bt_sub_domain": bti.sub_domain_id,
2954 "bt_hdr_len_id": bti.hdr_len_id},
2955 'bi_src': src,
2956 'bi_n_bytes': len(ibytes),
2957 'bi_bytes': ibytes})
2958
2959 def bier_imp_del(self, bi_index):
2960 """ BIER Imposition del """
2961 return self.api(
2962 self.papi.bier_imp_del,
2963 {'bi_index': bi_index})
2964
2965 def bier_imp_dump(self):
2966 return self.api(self.papi.bier_imp_dump, {})
2967
2968 def bier_disp_table_add_del(self,
2969 bdti,
2970 is_add=1):
2971 """ BIER Disposition Table add/del """
2972 return self.api(
2973 self.papi.bier_disp_table_add_del,
2974 {'bdt_tbl_id': bdti,
2975 'bdt_is_add': is_add})
2976
2977 def bier_disp_table_dump(self):
2978 return self.api(self.papi.bier_disp_table_dump, {})
2979
2980 def bier_disp_entry_add_del(self,
2981 bdti,
2982 bp,
2983 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002984 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002985 next_hop,
2986 next_hop_tbl_id=0,
2987 next_hop_rpf_id=~0,
2988 next_hop_is_ip4=1,
2989 is_add=1):
2990 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002991 lstack = []
2992 while (len(lstack) < 16):
2993 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002994 return self.api(
2995 self.papi.bier_disp_entry_add_del,
2996 {'bde_tbl_id': bdti,
2997 'bde_bp': bp,
2998 'bde_payload_proto': payload_proto,
2999 'bde_n_paths': 1,
3000 'bde_paths': [{'next_hop': next_hop,
3001 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08003002 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07003003 'rpf_id': next_hop_rpf_id,
3004 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08003005 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07003006 'bde_is_add': is_add})
3007
3008 def bier_disp_entry_dump(self, bdti):
3009 return self.api(
3010 self.papi.bier_disp_entry_dump,
3011 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02003012
3013 def add_node_next(self, node_name, next_name):
3014 """ Set the next node for a given node request
3015
3016 :param node_name:
3017 :param next_name:
3018 """
3019 return self.api(self.papi.add_node_next,
3020 {'node_name': node_name,
3021 'next_name': next_name})
Florin Coras3ea6ce22017-12-11 09:09:05 -08003022
3023 def session_enable_disable(self, is_enabled):
3024 return self.api(
3025 self.papi.session_enable_disable,
3026 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08003027
3028 def ipsec_spd_add_del(self, spd_id, is_add=1):
3029 """ SPD add/del - Wrapper to add or del ipsec SPD
3030 Sample CLI : 'ipsec spd add 1'
3031
3032 :param spd_id - SPD ID to be created in the vpp . mandatory
3033 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
3034 optional
3035 :returns: reply from the API
3036 """
3037 return self.api(
3038 self.papi.ipsec_spd_add_del, {
3039 'spd_id': spd_id, 'is_add': is_add})
3040
3041 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
3042 """ IPSEC interface SPD add/del - \
3043 Wrapper to associate/disassociate SPD to interface in VPP
3044 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
3045
3046 :param spd_id - SPD ID to associate with the interface . mandatory
3047 :param sw_if_index - Interface Index which needs to ipsec \
3048 association mandatory
3049 :param is_add - add(1) or del(0) association with interface \
3050 (Default 1 - add) . optional
3051 :returns: reply from the API
3052 """
3053 return self.api(
3054 self.papi.ipsec_interface_add_del_spd, {
3055 'spd_id': spd_id,
3056 'sw_if_index': sw_if_index, 'is_add': is_add})
3057
3058 def ipsec_sad_add_del_entry(self,
3059 sad_id,
3060 spi,
3061 tunnel_src_address='',
3062 tunnel_dst_address='',
3063 protocol=0,
3064 integrity_algorithm=2,
3065 integrity_key_length=0,
3066 integrity_key='C91KUR9GYMm5GfkEvNjX',
3067 crypto_algorithm=1,
3068 crypto_key_length=0,
3069 crypto_key='JPjyOWBeVEQiMe7h',
3070 is_add=1,
3071 is_tunnel=1):
3072 """ IPSEC SA add/del
3073 Sample CLI : 'ipsec sa add 10 spi 1001 esp \
3074 crypto-key 4a506a794f574265564551694d653768 \
3075 crypto-alg aes-cbc-128 \
3076 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3077 integ-alg sha1-96 tunnel-src 192.168.100.3 \
3078 tunnel-dst 192.168.100.2'
3079 Sample CLI : 'ipsec sa add 20 spi 2001 \
3080 integ-key 4339314b55523947594d6d3547666b45764e6a58 \
3081 integ-alg sha1-96'
3082
3083 :param sad_id - Security Association ID to be \
3084 created or deleted. mandatory
3085 :param spi - security param index of the SA in decimal. mandatory
3086 :param tunnel_src_address - incase of tunnel mode outer src address .\
3087 mandatory for tunnel mode
3088 :param tunnel_dst_address - incase of transport mode \
3089 outer dst address. mandatory for tunnel mode
3090 :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional
3091 :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\
3092 optional **
3093 :param integrity_key - value in string \
3094 (Default C91KUR9GYMm5GfkEvNjX).optional
3095 :param integrity_key_length - length of the key string in bytes\
3096 (Default 0 - integrity disabled). optional
3097 :param crypto_algorithm - value range 1-11 Default \
3098 (1- AES_CBC_128).optional **
3099 :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional
3100 :param crypto_key_length - length of the key string in bytes\
3101 (Default 0 - crypto disabled). optional
3102 :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\
3103 optional
3104 :param is_tunnel - tunnel mode (1) or transport mode(0) \
3105 (Default 1 - tunnel). optional
3106 :returns: reply from the API
3107 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
3108 crypto and ipsec algorithms
3109 """
3110 return self.api(
3111 self.papi.ipsec_sad_add_del_entry,
3112 {'sad_id': sad_id,
3113 'spi': spi,
3114 'tunnel_src_address': tunnel_src_address,
3115 'tunnel_dst_address': tunnel_dst_address,
3116 'protocol': protocol,
3117 'integrity_algorithm': integrity_algorithm,
3118 'integrity_key_length': integrity_key_length,
3119 'integrity_key': integrity_key,
3120 'crypto_algorithm': crypto_algorithm,
3121 'crypto_key_length': crypto_key_length,
3122 'crypto_key': crypto_key,
3123 'is_add': is_add,
3124 'is_tunnel': is_tunnel})
3125
3126 def ipsec_spd_add_del_entry(self,
3127 spd_id,
3128 local_address_start,
3129 local_address_stop,
3130 remote_address_start,
3131 remote_address_stop,
3132 local_port_start=0,
3133 local_port_stop=65535,
3134 remote_port_start=0,
3135 remote_port_stop=65535,
3136 protocol=0,
3137 sa_id=10,
3138 policy=0,
3139 priority=100,
3140 is_outbound=1,
3141 is_add=1,
3142 is_ip_any=0):
3143 """ IPSEC policy SPD add/del -
3144 Wrapper to configure ipsec SPD policy entries in VPP
3145 Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \
3146 protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \
3147 remote-ip-range 192.168.3.3 - 192.168.3.3'
3148
3149 :param spd_id - SPD ID for the policy . mandatory
3150 :param local_address_start - local-ip-range start address . mandatory
3151 :param local_address_stop - local-ip-range stop address . mandatory
3152 :param remote_address_start - remote-ip-range start address . mandatory
3153 :param remote_address_stop - remote-ip-range stop address . mandatory
3154 :param local_port_start - (Default 0) . optional
3155 :param local_port_stop - (Default 65535). optional
3156 :param remote_port_start - (Default 0). optional
3157 :param remote_port_stop - (Default 65535). optional
3158 :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any).
3159 optional
3160 :param sa_id - Security Association ID for mapping it to SPD
3161 (default 10). optional
3162 :param policy - bypass(0), discard(1), resolve(2) or protect(3)action
3163 (Default 0 - bypass). optional
3164 :param priotity - value for the spd action (Default 100). optional
3165 :param is_outbound - flag for inbound(0) or outbound(1)
3166 (Default 1 - outbound). optional
3167 :param is_add flag - for addition(1) or deletion(0) of the spd
3168 (Default 1 - addtion). optional
3169 :returns: reply from the API
3170 """
3171 return self.api(
3172 self.papi.ipsec_spd_add_del_entry,
3173 {'spd_id': spd_id,
3174 'local_address_start': local_address_start,
3175 'local_address_stop': local_address_stop,
3176 'remote_address_start': remote_address_start,
3177 'remote_address_stop': remote_address_stop,
3178 'local_port_start': local_port_start,
3179 'local_port_stop': local_port_stop,
3180 'remote_port_start': remote_port_start,
3181 'remote_port_stop': remote_port_stop,
3182 'is_add': is_add,
3183 'protocol': protocol,
3184 'policy': policy,
3185 'priority': priority,
3186 'is_outbound': is_outbound,
3187 'sa_id': sa_id,
3188 'is_ip_any': is_ip_any})
Florin Corasb795bd02017-12-14 11:30:48 -08003189
3190 def app_namespace_add(self,
3191 namespace_id,
3192 ip4_fib_id=0,
3193 ip6_fib_id=0,
3194 sw_if_index=0xFFFFFFFF,
3195 secret=0):
3196 return self.api(
3197 self.papi.app_namespace_add_del,
3198 {'secret': secret,
3199 'sw_if_index': sw_if_index,
3200 'ip4_fib_id': ip4_fib_id,
3201 'ip6_fib_id': ip6_fib_id,
3202 'namespace_id': namespace_id,
3203 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02003204
3205 def punt_socket_register(self, l4_port, pathname, header_version=1,
3206 is_ip4=1, l4_protocol=0x11):
3207 """ Punt to socket """
3208 return self.api(self.papi.punt_socket_register,
3209 {'is_ip4': is_ip4,
3210 'l4_protocol': l4_protocol,
3211 'l4_port': l4_port,
3212 'pathname': pathname,
3213 'header_version': header_version})
3214
3215 def ip_reassembly_set(self, timeout_ms, max_reassemblies,
3216 expire_walk_interval_ms, is_ip6=0):
3217 """ Set IP reassembly parameters """
3218 return self.api(self.papi.ip_reassembly_set,
3219 {'is_ip6': is_ip6,
3220 'timeout_ms': timeout_ms,
3221 'expire_walk_interval_ms': expire_walk_interval_ms,
3222 'max_reassemblies': max_reassemblies})
3223
3224 def ip_reassembly_get(self, is_ip6=0):
3225 """ Get IP reassembly parameters """
3226 return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003227
Klement Sekera4c533132018-02-22 11:41:12 +01003228 def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
3229 enable_ip6=False):
3230 """ Enable/disable IP reassembly """
3231 return self.api(self.papi.ip_reassembly_enable_disable,
3232 {'sw_if_index': sw_if_index,
3233 'enable_ip4': 1 if enable_ip4 else 0,
3234 'enable_ip6': 1 if enable_ip6 else 0,
3235 })
3236
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003237 def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
3238 """ GBP endpoint Add/Del """
3239 return self.api(self.papi.gbp_endpoint_add_del,
3240 {'is_add': is_add,
3241 'endpoint': {
3242 'is_ip6': is_ip6,
3243 'sw_if_index': sw_if_index,
3244 'address': addr,
3245 'epg_id': epg}})
3246
3247 def gbp_endpoint_dump(self):
3248 """ GBP endpoint Dump """
3249 return self.api(self.papi.gbp_endpoint_dump, {})
3250
Neale Ranns25b04942018-04-04 09:34:50 -07003251 def gbp_endpoint_group_add_del(self, is_add, epg, bd,
3252 ip4_rd,
3253 ip6_rd,
3254 uplink_sw_if_index):
3255 """ GBP endpoint group Add/Del """
3256 return self.api(self.papi.gbp_endpoint_group_add_del,
3257 {'is_add': is_add,
3258 'epg': {
3259 'uplink_sw_if_index': uplink_sw_if_index,
3260 'bd_id': bd,
3261 'ip4_table_id': ip4_rd,
3262 'ip6_table_id': ip6_rd,
3263 'epg_id': epg}})
3264
3265 def gbp_endpoint_group_dump(self):
3266 """ GBP endpoint group Dump """
3267 return self.api(self.papi.gbp_endpoint_group_dump, {})
3268
3269 def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext):
3270 """ GBP recirc Add/Del """
3271 return self.api(self.papi.gbp_recirc_add_del,
3272 {'is_add': is_add,
3273 'recirc': {
3274 'is_ext': is_ext,
3275 'sw_if_index': sw_if_index,
3276 'epg_id': epg}})
3277
3278 def gbp_recirc_dump(self):
3279 """ GBP recirc Dump """
3280 return self.api(self.papi.gbp_recirc_dump, {})
3281
3282 def gbp_subnet_add_del(self, is_add, table_id,
3283 is_internal,
3284 addr, addr_len,
3285 sw_if_index=0xffffffff,
3286 epg_id=0xffffffff,
3287 is_ip6=False):
3288 """ GBP Subnet Add/Del """
3289 return self.api(self.papi.gbp_subnet_add_del,
3290 {'is_add': is_add,
3291 'subnet': {
3292 'is_internal': is_internal,
3293 'is_ip6': is_ip6,
3294 'sw_if_index': sw_if_index,
3295 'epg_id': epg_id,
3296 'address': addr,
3297 'address_length': addr_len,
3298 'table_id': table_id}})
3299
3300 def gbp_subnet_dump(self):
3301 """ GBP Subnet Dump """
3302 return self.api(self.papi.gbp_subnet_dump, {})
3303
Neale Rannsbc27d1b2018-02-05 01:13:38 -08003304 def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index):
3305 """ GBP contract Add/Del """
3306 return self.api(self.papi.gbp_contract_add_del,
3307 {'is_add': is_add,
3308 'contract': {
3309 'acl_index': acl_index,
3310 'src_epg': src_epg,
3311 'dst_epg': dst_epg}})
3312
3313 def gbp_contract_dump(self):
3314 """ GBP contract Dump """
3315 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01003316
Ole Troan298c6952018-03-08 12:30:43 +01003317 def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len,
3318 ip4_prefix, ip4_prefix_len, ip4_src,
3319 security_check):
Ole Troan6ee40512018-02-12 18:14:39 +01003320 """ 6RD tunnel Add """
Ole Troan298c6952018-03-08 12:30:43 +01003321 return self.api(self.papi.ipip_6rd_add_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003322 {'fib_index': fib_index,
3323 'ip6_prefix': ip6_prefix,
3324 'ip6_prefix_len': ip6_prefix_len,
3325 'ip4_prefix': ip4_prefix,
3326 'ip4_prefix_len': ip4_prefix_len,
3327 'ip4_src': ip4_src,
Ole Troan6ee40512018-02-12 18:14:39 +01003328 'security_check': security_check})
3329
Ole Troan298c6952018-03-08 12:30:43 +01003330 def ipip_6rd_del_tunnel(self, sw_if_index):
Ole Troan6ee40512018-02-12 18:14:39 +01003331 """ 6RD tunnel Delete """
Ole Troan298c6952018-03-08 12:30:43 +01003332 return self.api(self.papi.ipip_6rd_del_tunnel,
3333 {'sw_if_index': sw_if_index})
3334
3335 def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1,
3336 instance=0xFFFFFFFF, fib_index=0):
3337 """ IPIP tunnel Add/Del """
3338 return self.api(self.papi.ipip_add_tunnel,
3339 {'is_ipv6': is_ipv6,
3340 'instance': instance,
3341 'src_address': src_address,
3342 'dst_address': dst_address,
3343 'fib_index': fib_index})
3344
3345 def ipip_del_tunnel(self, sw_if_index):
3346 """ IPIP tunnel Delete """
3347 return self.api(self.papi.ipip_del_tunnel,
Ole Troan6ee40512018-02-12 18:14:39 +01003348 {'sw_if_index': sw_if_index})
Neale Ranns039cbfe2018-02-27 03:45:38 -08003349
3350 def qos_egress_map_update(self, id, outputs):
3351 """ QOS egress map update """
3352 return self.api(self.papi.qos_egress_map_update,
3353 {'map_id': id,
3354 'rows': outputs})
3355
3356 def qos_egress_map_delete(self, id):
3357 """ QOS egress map delete """
3358 return self.api(self.papi.qos_egress_map_delete,
3359 {'map_id': id})
3360
3361 def qos_mark_enable_disable(self, sw_if_index,
3362 output_source,
3363 map_id,
3364 enable):
3365 """ QOS Mark Enable/Disable """
3366 return self.api(self.papi.qos_mark_enable_disable,
3367 {'map_id': map_id,
3368 'sw_if_index': sw_if_index,
3369 'output_source': output_source,
3370 'enable': enable})
3371
3372 def qos_record_enable_disable(self, sw_if_index, input_source, enable):
3373 """ IP QoS recording Enble/Disable """
3374 return self.api(self.papi.qos_record_enable_disable,
3375 {'sw_if_index': sw_if_index,
3376 'input_source': input_source,
3377 'enable': enable})
Jakub Grajciar7b867a82017-12-08 16:28:42 +01003378
3379 def igmp_listen(self, enable, sw_if_index, saddr, gaddr):
3380 """ Listen for new (S,G) on specified interface
3381
3382 :param enable: add/del
3383 :param sw_if_index: interface sw index
3384 :param saddr: source ip4 addr
3385 :param gaddr: group ip4 addr
3386 """
3387 return self.api(self.papi.igmp_listen,
3388 {'enable': enable,
3389 'sw_if_index': sw_if_index,
3390 'saddr': saddr,
3391 'gaddr': gaddr})
3392
3393 def igmp_dump(self, sw_if_index=None):
3394 """ Dump all (S,G) interface configurations """
3395 if sw_if_index is None:
3396 dump_all = 1
3397 sw_if_index = 0
3398 else:
3399 dump_all = 0
3400 return self.api(self.papi.igmp_dump, {'sw_if_index': sw_if_index,
3401 'dump_all': dump_all})
3402
3403 def igmp_clear_interface(self, sw_if_index):
3404 """ Remove all (S,G)s from specified interface
3405 doesn't send IGMP report!
3406 """
3407 return self.api(
3408 self.papi.igmp_clear_interface, {
3409 'sw_if_index': sw_if_index})
3410
3411 def want_igmp_events(self, enable=1):
3412 return self.api(self.papi.want_igmp_events, {'enable': enable,
3413 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08003414
3415 def bond_create(
3416 self,
3417 mode,
3418 lb,
3419 use_custom_mac,
3420 mac_address=''):
3421 """
3422 :param mode: mode
3423 :param lb: load balance
3424 :param use_custom_mac: use custom mac
3425 :param mac_address: mac address
3426 """
3427 return self.api(
3428 self.papi.bond_create,
3429 {'mode': mode,
3430 'lb': lb,
3431 'use_custom_mac': use_custom_mac,
3432 'mac_address': mac_address
3433 })
3434
3435 def bond_delete(
3436 self,
3437 sw_if_index):
3438 """
3439 :param sw_if_index: interface the operation is applied to
3440 """
3441 return self.api(self.papi.bond_delete,
3442 {'sw_if_index': sw_if_index})
3443
3444 def bond_enslave(
3445 self,
3446 sw_if_index,
3447 bond_sw_if_index,
3448 is_passive,
3449 is_long_timeout):
3450 """
3451 :param sw_if_index: slave sw_if_index
3452 :param bond_sw_if_index: bond sw_if_index
3453 :param is_passive: is passive lacp speaker
3454 :param is_long_time: 90 seconds timeout instead of 3 seconds timeout
3455 """
3456 return self.api(
3457 self.papi.bond_enslave,
3458 {'sw_if_index': sw_if_index,
3459 'bond_sw_if_index': bond_sw_if_index,
3460 'is_passive': is_passive,
3461 'is_long_timeout': is_long_timeout
3462 })
3463
3464 def bond_detach_slave(
3465 self,
3466 sw_if_index):
3467 """
3468 :param sw_if_index: slave interface the operation is applied to
3469 """
3470 return self.api(self.papi.bond_detach_slave,
3471 {'sw_if_index': sw_if_index})
3472
3473 def sw_interface_slave_dump(
3474 self,
3475 sw_if_index):
3476 """
3477 :param sw_if_index: bond sw_if_index
3478 """
3479 return self.api(self.papi.sw_interface_slave_dump,
3480 {'sw_if_index': sw_if_index})
3481
3482 def sw_interface_bond_dump(
3483 self):
3484 """
3485
3486 """
3487 return self.api(self.papi.sw_interface_bond_dump,
3488 {})
Stevene8fa6202017-08-30 14:36:45 -07003489
3490 def create_vhost_user_if(
3491 self,
3492 is_server,
3493 sock_filename,
3494 renumber,
3495 custom_dev_instance,
3496 use_custom_mac,
3497 mac_address,
3498 tag=''):
3499 """
3500 :param is_server: is server
3501 :param sock_filename: socket name
3502 :param renumber: renumber
3503 :param custom_dev_instance: custom dev instance
3504 :param use_custom_mac: use custom mac
3505 :param mac_address: mac address
3506 :param tag: tag (default ''
3507 """
3508 return self.api(
3509 self.papi.create_vhost_user_if,
3510 {'is_server': is_server,
3511 'sock_filename': sock_filename,
3512 'renumber': renumber,
3513 'custom_dev_instance': custom_dev_instance,
3514 'use_custom_mac': use_custom_mac,
3515 'mac_address': mac_address,
3516 'tag': tag
3517 })
3518
3519 def delete_vhost_user_if(
3520 self,
3521 sw_if_index):
3522 """
3523 :param sw_if_index: interface the operation is applied to
3524 """
3525 return self.api(self.papi.delete_vhost_user_if,
3526 {'sw_if_index': sw_if_index, })
3527
3528 def sw_interface_vhost_user_dump(
3529 self):
3530 """
3531
3532 """
3533 return self.api(self.papi.sw_interface_vhost_user_dump,
3534 {})
Andrew Yourtchenko669d07d2017-11-17 14:38:18 +01003535
3536 def abf_policy_add_del(self, is_add, policy):
3537 return self.api(
3538 self.papi.abf_policy_add_del,
3539 {'is_add': is_add,
3540 'policy': policy})
3541
3542 def abf_itf_attach_add_del(self, is_add, attach):
3543 return self.api(
3544 self.papi.abf_itf_attach_add_del,
3545 {'is_add': is_add,
3546 'attach': attach})
3547
3548 def abf_policy_dump(self):
3549 return self.api(
3550 self.papi.abf_policy_dump, {})
3551
3552 def abf_itf_attach_dump(self):
3553 return self.api(
3554 self.papi.abf_itf_attach_dump, {})